[PATCH libcacard 33/45] tests: Extend the hwtests with get_response

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jakub Jelen <jjelen@xxxxxxxxxx>
Reviewed-by: Robert Relyea <rrelyea@xxxxxxxxxx>
---
 tests/common.c    | 74 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/common.h    |  2 ++
 tests/hwtests.c   | 23 +++++++++++++++
 tests/libcacard.c | 46 -----------------------------
 4 files changed, 99 insertions(+), 46 deletions(-)

diff --git a/tests/common.c b/tests/common.c
index fdd44aa..d2567d6 100644
--- a/tests/common.c
+++ b/tests/common.c
@@ -488,6 +488,80 @@ void test_empty_applets(void)
     vreader_free(reader); /* get by id ref */
 }
 
+/*
+ * Check that access method without provided buffer returns valid
+ * SW and allow us to get the response with the following APDU
+ *
+ * opensc-tool -s 00A4040007A000000116DB00 -s 80520000020102 -s 00C0000002 \
+ *   -s 00520002020134 -s 00C0000034
+ */
+void test_get_response(void)
+{
+    VReader *reader = vreader_get_reader_by_id(0);
+    int dwRecvLength = APDUBufSize, dwLength;
+    VReaderStatus status;
+    uint8_t pbRecvBuffer[APDUBufSize];
+    uint8_t getresp[] = {
+        /* Get Response (max we can get) */
+        0x00, 0xc0, 0x00, 0x00, 0x00
+    };
+    uint8_t read_buffer[] = {
+        /*Read Buffer  OFFSET         TYPE LENGTH */
+        0x00, 0x52, 0x00, 0x00, 0x02, 0x01, 0x02 /* no L_e */
+    };
+
+    /* select CCC */
+    select_applet(reader, TEST_CCC);
+
+    /* read buffer without response buffer */
+    dwRecvLength = 2;
+    status = vreader_xfr_bytes(reader,
+                               read_buffer, sizeof(read_buffer),
+                               pbRecvBuffer, &dwRecvLength);
+    g_assert_cmpint(status, ==, VREADER_OK);
+    g_assert_cmpint(dwRecvLength, ==, 2);
+    g_assert_cmpint(pbRecvBuffer[0], ==, VCARD7816_SW1_RESPONSE_BYTES);
+    g_assert_cmpint(pbRecvBuffer[1], ==, 0x02);
+
+    /* fetch the actual response */
+    dwRecvLength = 4;
+    getresp[4] = 0x02;
+    status = vreader_xfr_bytes(reader,
+                               getresp, sizeof(getresp),
+                               pbRecvBuffer, &dwRecvLength);
+    g_assert_cmpint(status, ==, VREADER_OK);
+    g_assert_cmpint(dwRecvLength, ==, 4);
+    g_assert_cmphex(pbRecvBuffer[2], ==, VCARD7816_SW1_SUCCESS);
+    g_assert_cmphex(pbRecvBuffer[3], ==, 0x00);
+
+    /* the same with offset */
+    dwLength = (pbRecvBuffer[0] & 0xff) | ((pbRecvBuffer[1] << 8) & 0xff);
+    dwRecvLength = dwLength + 2;
+    read_buffer[3] = 0x02; // offset
+    read_buffer[6] = dwLength;
+    status = vreader_xfr_bytes(reader,
+                               read_buffer, sizeof(read_buffer),
+                               pbRecvBuffer, &dwRecvLength);
+    g_assert_cmpint(status, ==, VREADER_OK);
+    g_assert_cmpint(dwRecvLength, ==, 2);
+    g_assert_cmpint(pbRecvBuffer[0], ==, VCARD7816_SW1_RESPONSE_BYTES);
+    g_assert_cmpint(pbRecvBuffer[1], ==, dwLength);
+
+    /* fetch the actual response */
+    dwRecvLength = dwLength + 2;
+    getresp[4] = dwLength;
+    status = vreader_xfr_bytes(reader,
+                               getresp, sizeof(getresp),
+                               pbRecvBuffer, &dwRecvLength);
+    g_assert_cmpint(status, ==, VREADER_OK);
+    g_assert_cmpint(dwRecvLength, ==, dwLength + 2);
+    g_assert_cmphex(pbRecvBuffer[dwRecvLength-2], ==, VCARD7816_SW1_SUCCESS);
+    g_assert_cmphex(pbRecvBuffer[dwRecvLength-1], ==, 0x00);
+
+    g_assert_cmpint(dwLength, ==, 0x34);
+    vreader_free(reader); /* get by id ref */
+}
+
 int
 isHWTests(void)
 {
diff --git a/tests/common.h b/tests/common.h
index 4ba2619..871b013 100644
--- a/tests/common.h
+++ b/tests/common.h
@@ -36,6 +36,8 @@ void do_sign(VReader *reader);
 
 void test_empty_applets(void);
 
+void test_get_response(void);
+
 int isHWTests(void);
 void setHWTests(int);
 
diff --git a/tests/hwtests.c b/tests/hwtests.c
index be2c801..7b93441 100644
--- a/tests/hwtests.c
+++ b/tests/hwtests.c
@@ -103,6 +103,7 @@ static void test_list(void)
         if (vreader_card_is_present(r) == VREADER_OK) {
             cards++;
         }
+        vreader_free(r);
     }
     if (cards == 0) {
         g_test_skip("No physical card found");
@@ -149,6 +150,7 @@ static void test_passthrough_applets(void)
 
     /* Skip the HW tests without physical card */
     if (vreader_card_is_present(reader) != VREADER_OK) {
+        vreader_free(reader);
         g_test_skip("No physical card found");
         return;
     }
@@ -190,6 +192,7 @@ static void test_login(void)
 
     /* Skip the HW tests without physical card */
     if (vreader_card_is_present(reader) != VREADER_OK) {
+        vreader_free(reader);
         g_test_skip("No physical card found");
         return;
     }
@@ -208,6 +211,7 @@ static void test_sign(void)
 
     /* Skip the HW tests without physical card */
     if (vreader_card_is_present(reader) != VREADER_OK) {
+        vreader_free(reader);
         g_test_skip("No physical card found");
         return;
     }
@@ -241,9 +245,27 @@ static void test_empty_applets_hw(void) {
 
     vreader_free(reader); /* get by id ref */
 
+    /* run the actual test */
     test_empty_applets();
 }
 
+static void test_get_response_hw(void) {
+
+    VReader *reader = vreader_get_reader_by_id(0);
+
+    /* Skip the HW tests without physical card */
+    if (vreader_card_is_present(reader) != VREADER_OK) {
+        vreader_free(reader);
+        g_test_skip("No physical card found");
+        return;
+    }
+
+    vreader_free(reader); /* get by id ref */
+
+    /* run the actual test */
+    test_get_response();
+}
+
 int main(int argc, char *argv[])
 {
     int ret;
@@ -259,6 +281,7 @@ int main(int argc, char *argv[])
     g_test_add_func("/hw-tests/login", test_login);
     g_test_add_func("/hw-tests/sign", test_sign);
     g_test_add_func("/hw-tests/empty-applets", test_empty_applets_hw);
+    g_test_add_func("/hw-tests/get-response", test_get_response_hw);
 
     ret = g_test_run();
 
diff --git a/tests/libcacard.c b/tests/libcacard.c
index 63a41e6..5b5c8a5 100644
--- a/tests/libcacard.c
+++ b/tests/libcacard.c
@@ -505,52 +505,6 @@ static void test_remove(void)
     g_assert_null(reader);
 }
 
-/*
- * Check that access method without provided buffer returns valid
- * SW and allow us to get the response with the following APDU
- */
-static void test_get_response(void)
-{
-    VReader *reader = vreader_get_reader_by_id(0);
-    int dwRecvLength = APDUBufSize;
-    VReaderStatus status;
-    uint8_t pbRecvBuffer[APDUBufSize];
-    uint8_t getresp[] = {
-        /* Get Response (max we can get) */
-        0x00, 0xc0, 0x00, 0x00, 0x00
-    };
-    uint8_t read_buffer[] = {
-        /*Read Buffer  OFFSET         TYPE LENGTH */
-        0x80, 0x52, 0x00, 0x00, 0x02, 0x01, 0x02 /* no L_e */
-    };
-
-    /* select CCC */
-    select_applet(reader, TEST_CCC);
-
-    /* read buffer without response buffer */
-    dwRecvLength = 2;
-    read_buffer[5] = 0x01;
-    status = vreader_xfr_bytes(reader,
-                               read_buffer, sizeof(read_buffer),
-                               pbRecvBuffer, &dwRecvLength);
-    g_assert_cmpint(status, ==, VREADER_OK);
-    g_assert_cmpint(dwRecvLength, ==, 2);
-    g_assert_cmpint(pbRecvBuffer[0], ==, VCARD7816_SW1_RESPONSE_BYTES);
-    g_assert_cmpint(pbRecvBuffer[1], ==, 0x02);
-
-    /* fetch the actual response */
-    dwRecvLength = 4;
-    status = vreader_xfr_bytes(reader,
-                               getresp, sizeof(getresp),
-                               pbRecvBuffer, &dwRecvLength);
-    g_assert_cmpint(status, ==, VREADER_OK);
-    g_assert_cmpint(dwRecvLength, ==, 4);
-    g_assert_cmphex(pbRecvBuffer[2], ==, VCARD7816_SW1_SUCCESS);
-    g_assert_cmphex(pbRecvBuffer[3], ==, 0x00);
-
-    vreader_free(reader); /* get by id ref */
-}
-
 int main(int argc, char *argv[])
 {
     int ret;
-- 
2.17.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]