Signed-off-by: Jakub Jelen <jjelen@xxxxxxxxxx> Reviewed-by: Robert Relyea <rrelyea@xxxxxxxxxx> --- tests/libcacard.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/tests/libcacard.c b/tests/libcacard.c index 650e2e7..ea9cee6 100644 --- a/tests/libcacard.c +++ b/tests/libcacard.c @@ -557,6 +557,74 @@ static void select_aid(VReader *reader, int type) g_assert_cmphex(pbRecvBuffer[1], ==, 0x00); } +static void do_login(VReader *reader) +{ + VReaderStatus status; + int dwRecvLength = APDUBufSize; + uint8_t pbRecvBuffer[APDUBufSize]; + uint8_t login[] = { + /* VERIFY [p1,p2=0 ] [Lc] [empty pin padded to 6 chars ] */ + 0x00, 0x20, 0x00, 0x00, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + }; + g_assert_nonnull(reader); + status = vreader_xfr_bytes(reader, + login, sizeof(login), + pbRecvBuffer, &dwRecvLength); + g_assert_cmpint(status, ==, VREADER_OK); + g_assert_cmphex(pbRecvBuffer[0], ==, VCARD7816_SW1_SUCCESS); + g_assert_cmphex(pbRecvBuffer[1], ==, 0x00); +} + +static void do_sign(VReader *reader) +{ + VReaderStatus status; + int dwRecvLength = APDUBufSize; + uint8_t pbRecvBuffer[APDUBufSize]; + uint8_t sign[] = { + /* VERIFY [p1,p2=0 ] [Lc ] [ 256 bytes of PKCS#1.5 padded data ... ] */ + 0x80, 0x42, 0x00, 0x00, 0x00, 0x01, 0x00, +0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xff, 0xff, 0x00, 0x64, 0x61, 0x74, 0x61, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x69, 0x67, 0x6e, 0x20, +0x28, 0x6d, 0x61, 0x78, 0x20, 0x31, 0x30, 0x30, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x29, 0x0a + }; + uint8_t getresp[] = { + /* Get Response (max we can get) */ + 0x00, 0xc0, 0x00, 0x00, 0x00 + }; + g_assert_nonnull(reader); + status = vreader_xfr_bytes(reader, + sign, sizeof(sign), + pbRecvBuffer, &dwRecvLength); + g_assert_cmpint(status, ==, VREADER_OK); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-2], ==, VCARD7816_SW1_RESPONSE_BYTES); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-1], ==, 0x00); + + + /* fetch the actual response */ + dwRecvLength = APDUBufSize; + status = vreader_xfr_bytes(reader, + getresp, sizeof(getresp), + pbRecvBuffer, &dwRecvLength); + g_assert_cmpint(status, ==, VREADER_OK); + g_assert_cmpint(dwRecvLength, ==, 258); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-2], ==, VCARD7816_SW1_SUCCESS); + g_assert_cmphex(pbRecvBuffer[dwRecvLength-1], ==, 0x00); + +} + static void test_cac_pki(void) { VReader *reader = vreader_get_reader_by_id(0); @@ -611,6 +679,35 @@ static void test_cac_aca(void) vreader_free(reader); /* get by id ref */ } +static void test_login(void) +{ + VReader *reader = vreader_get_reader_by_id(0); + + /* select the ACA */ + select_aid(reader, TEST_ACA); + + do_login(reader); + + vreader_free(reader); /* get by id ref */ +} + +static void test_sign(void) +{ + VReader *reader = vreader_get_reader_by_id(0); + + /* select the ACA */ + select_aid(reader, TEST_ACA); + + do_login(reader); + + /* select the PKI */ + select_aid(reader, TEST_PKI); + + do_sign(reader); + + vreader_free(reader); /* get by id ref */ +} + static void test_remove(void) { VReader *reader = vreader_get_reader_by_id(0); @@ -690,6 +787,8 @@ int main(int argc, char *argv[]) g_test_add_func("/libcacard/cac-ccc", test_cac_ccc); g_test_add_func("/libcacard/cac-aca", test_cac_aca); g_test_add_func("/libcacard/get-response", test_get_response); + g_test_add_func("/libcacard/login", test_login); + g_test_add_func("/libcacard/sign", test_sign); 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