Signed-off-by: Jakub Jelen <jjelen@xxxxxxxxxx> Reviewed-by: Robert Relyea <rrelyea@xxxxxxxxxx> --- tests/common.c | 19 ++++++++++++++++--- tests/common.h | 2 ++ tests/libcacard.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/common.c b/tests/common.c index 1f01e54..839c42b 100644 --- a/tests/common.c +++ b/tests/common.c @@ -57,7 +57,8 @@ void select_coid_bad(VReader *reader, unsigned char *coid) } -void select_aid(VReader *reader, unsigned char *aid, unsigned int aid_len) +int select_aid_response(VReader *reader, unsigned char *aid, + unsigned int aid_len, int response) { VReaderStatus status; int dwRecvLength = APDUBufSize; @@ -77,8 +78,20 @@ void select_aid(VReader *reader, unsigned char *aid, unsigned int aid_len) selfile, selfile_len, pbRecvBuffer, &dwRecvLength); g_assert_cmpint(status, ==, VREADER_OK); - g_assert_cmphex(pbRecvBuffer[dwRecvLength-2], ==, VCARD7816_SW1_SUCCESS); - g_assert_cmphex(pbRecvBuffer[dwRecvLength-1], ==, 0x00); + if (response) { + /* we expect some response bytes */ + g_assert_cmphex(pbRecvBuffer[dwRecvLength-2], ==, VCARD7816_SW1_RESPONSE_BYTES); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-1], >, 0); + } else { + g_assert_cmphex(pbRecvBuffer[dwRecvLength-2], ==, VCARD7816_SW1_SUCCESS); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-1], ==, 0x00); + } + return pbRecvBuffer[dwRecvLength-2]; +} + +void select_aid(VReader *reader, unsigned char *aid, unsigned int aid_len) +{ + (void) select_aid_response(reader, aid, aid_len, 0); } void get_properties_coid(VReader *reader, const unsigned char coid[2], diff --git a/tests/common.h b/tests/common.h index 21144a1..c02ea6b 100644 --- a/tests/common.h +++ b/tests/common.h @@ -27,6 +27,8 @@ enum { void select_coid_good(VReader *reader, unsigned char *coid); void select_coid_bad(VReader *reader, unsigned char *coid); +int select_aid_response(VReader *reader, unsigned char *aid, + unsigned int aid_len, int response); void select_aid(VReader *reader, unsigned char *aid, unsigned int aid_len); void select_applet(VReader *reader, int type); diff --git a/tests/libcacard.c b/tests/libcacard.c index c4bffba..b340038 100644 --- a/tests/libcacard.c +++ b/tests/libcacard.c @@ -545,6 +545,39 @@ static void test_select_coid(void) vreader_free(reader); /* get by id ref */ } +static void test_gp_applet(void) +{ + int dwRecvLength = APDUBufSize; + VReaderStatus status; + uint8_t pbRecvBuffer[APDUBufSize]; + uint8_t gp_aid[] = { + 0xA0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00 + }; + uint8_t getresp[] = { + /* Get Response (max we can get) */ + 0x00, 0xc0, 0x00, 0x00, 0x00 + }; + VReader *reader = vreader_get_reader_by_id(0); + + /* select GP and wait for the response bytes */ + select_aid_response(reader, gp_aid, sizeof(gp_aid), 1); + + /* read the response from the card */ + dwRecvLength = APDUBufSize; + status = vreader_xfr_bytes(reader, + getresp, sizeof(getresp), + pbRecvBuffer, &dwRecvLength); + g_assert_cmpint(status, ==, VREADER_OK); + g_assert_cmpint(dwRecvLength, >, 2); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-2], ==, VCARD7816_SW1_SUCCESS); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-1], ==, 0x00); + + /* We made sure the selection of other applets does not return anything + * in select_aid() + */ + + vreader_free(reader); /* get by id ref */ +} int main(int argc, char *argv[]) { int ret; @@ -566,6 +599,7 @@ int main(int argc, char *argv[]) g_test_add_func("/libcacard/login", test_login); g_test_add_func("/libcacard/sign", test_sign); g_test_add_func("/libcacard/empty-applets", test_empty_applets); + g_test_add_func("/libcacard/gp-applet", test_gp_applet); g_test_add_func("/libcacard/remove", test_remove); ret = g_test_run(); -- 2.17.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel