Wrong result from GET RESPONSE

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Wrong result from GET RESPONSE

Peter Popovec
Hi,

There is not correctly working GET RESPONSE operation (T0 protocol). If card
signalizes more data to read as defined by max_recv_size, then APDU transport
fails, because it read only first part of returned data.


First wrong behaviour occur at git commit a0c008744608ff2a425a7062479dce3712add5ca:


Outgoing APDU data [   25 bytes] =====================================
00 2A 9E 9A 14 98 6C 9B AE 50 FC FE 19 D6 74 11 .*....l..P....t.
36 B9 CC D6 3B 17 B8 0B 56                      6...;...V
======================================================================
0x7f42b6822700 07:32:12.949 [opensc-pkcs11] reader-pcsc.c:190:pcsc_internal_transmit: called
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Incoming APDU data [    2 bytes] =====================================
61 00 a.
======================================================================
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:399:sc_single_transmit: returning with: 0 (Success)
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:443:sc_get_response: called
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:563:sc_transmit_apdu: called
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] card.c:394:sc_lock: called
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:530:sc_transmit: called
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:384:sc_single_transmit: called
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:389:sc_single_transmit: CLA:0, INS:C0, P1:0, P2:0, data(0) (nil)
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] reader-pcsc.c:260:pcsc_transmit: reader 'sim 00 00'
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Outgoing APDU data [    5 bytes] =====================================
00 C0 00 00 FF .....
======================================================================
0x7f42b6822700 07:32:13.095 [opensc-pkcs11] reader-pcsc.c:190:pcsc_internal_transmit: called
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Incoming APDU data [  257 bytes] =====================================
76 CF 79 C1 12 CF C9 53 BF EF 1B B1 1A D5 42 B2 v.y....S......B.
74 70 6C F3 A6 7E F6 A9 5C 9A A7 42 D5 FB 29 6E tpl..~..\..B..)n
F9 1C 36 65 13 1F 7C 3C 52 F3 2B 48 36 B3 AC F7 ..6e..|<R.+H6...
0B 42 43 23 94 12 AA 54 80 7B 32 66 79 0E 69 26 .BC#...T.{2fy.i&
7D F1 92 EB 8F 88 24 38 83 43 FE F3 24 A2 D4 B9 }.....$8.C..$...
78 1B 34 DC B6 F0 16 07 19 76 D1 5B CC B1 EF 7F x.4......v.[....
2C B2 43 59 F0 F6 77 FA 7C B0 3C 16 07 CD 91 7E ,.CY..w.|.<....~
93 04 A9 B6 EC 10 FB 8E 0B 3E 21 DB C7 FD BA 9D .........>!.....
48 C4 BD 22 15 30 23 F7 87 E2 F3 73 89 15 63 EC H..".0#....s..c.
AC F2 84 14 63 C1 52 A3 0C C5 2D 71 8B 29 EA CF ....c.R...-q.)..
F5 F5 6B EA 08 74 BC B1 B4 61 65 EE 95 B7 17 5E ..k..t...ae....^
A4 82 5A F7 9D DA 6C B4 F5 14 47 E6 FA 4D 23 68 ..Z...l...G..M#h
43 6D C7 EF 9A 09 56 23 B4 D3 DD A3 23 9E 3E F5 Cm....V#....#.>.
49 B9 00 DB 33 A0 E0 4C 65 66 1A AA A3 D8 48 47 I...3..Lef....HG
82 C7 10 73 0F CA B5 C6 77 46 73 6A 9D A3 C9 23 ...s....wFsj...#
C4 95 FD B7 46 9F EF BB 7F 06 B2 02 92 40 85 90 ....F........@..
00                                              .
======================================================================
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] apdu.c:399:sc_single_transmit: returning with: 0 (Success)
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] apdu.c:552:sc_transmit: returning with: 0 (Success)
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] card.c:434:sc_unlock: called
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] apdu.c:514:sc_get_response: returning with: 0 (Success)
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] apdu.c:552:sc_transmit: returning with: 0 (Success)
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] card.c:434:sc_unlock: called
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] card-myeid.c:851:myeid_compute_signature: returning with: 255
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] sec.c:58:sc_compute_signature: returning with: 255
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] card.c:434:sc_unlock: called
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] pkcs15-sec.c:439:sc_pkcs15_compute_signature: returning with: 255
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] card.c:434:sc_unlock: called
0x7f42b6822700 07:32:13.097 [opensc-pkcs11] reader-pcsc.c:574:pcsc_unlock: called
0x7f42b6822700 07:32:13.100 [opensc-pkcs11] framework-pkcs15.c:3603:pkcs15_prkey_sign: Sign complete. Result 255.
0x7f42b6822700 07:32:13.100 [opensc-pkcs11] mechanism.c:447:sc_pkcs11_signature_final: returning with: 0 (Success)
0x7f42b6822700 07:32:13.100 [opensc-pkcs11] mechanism.c:312:sc_pkcs11_sign_final: returning with: 0 (Success)
0x7f42b6822700 07:32:13.100 [opensc-pkcs11] pkcs11-object.c:697:C_Sign: C_Sign() = CKR_OK

Here only first 255 bytes of response are read, but card signalizes 256 bytes
to read ..  It seems this is problem:



$ git checkout a0c008744608ff2a425a7062479dce3712add5ca
$ git diff 14953f20759b9eec04f65d05d24c2791f76e8918
diff --git a/src/libopensc/apdu.c b/src/libopensc/apdu.c
index 451c706..c590395 100644
--- a/src/libopensc/apdu.c  
+++ b/src/libopensc/apdu.c  
@@ -504,7 +504,7 @@ sc_get_response(struct sc_card *card, struct sc_apdu
*apdu, size_t olen)
                        /* if the card has returned 0x9000 but we still
                         * expect data ask for more
                         * until we have read enough bytes */
                        le = minlen;
-       } while (rv != 0 || minlen != 0);
+       } while (rv != 0 && minlen != 0);
 
        /* we've read all data, let's return 0x9000 */
        apdu->resplen = buf - apdu->resp;


CORRECT RESULT from git commit 14953f20759b9eec04f65d05d24c2791f76e8918 :
Outgoing APDU data [   25 bytes] =====================================
00 2A 9E 9A 14 98 6C 9B AE 50 FC FE 19 D6 74 11 .*....l..P....t.
36 B9 CC D6 3B 17 B8 0B 56                      6...;...V
======================================================================
0x7f8bb8bae700 07:37:44.778 [opensc-pkcs11] reader-pcsc.c:190:pcsc_internal_transmit: called
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Incoming APDU data [    2 bytes] =====================================
61 00 a.
======================================================================
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:399:sc_single_transmit: returning with: 0 (Success)
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:443:sc_get_response: called
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:563:sc_transmit_apdu: called
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] card.c:394:sc_lock: called
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:530:sc_transmit: called
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:384:sc_single_transmit: called
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:389:sc_single_transmit: CLA:0, INS:C0, P1:0, P2:0, data(0) (nil)
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] reader-pcsc.c:260:pcsc_transmit: reader 'sim 00 00'
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Outgoing APDU data [    5 bytes] =====================================
00 C0 00 00 FF .....
======================================================================
0x7f8bb8bae700 07:37:44.889 [opensc-pkcs11] reader-pcsc.c:190:pcsc_internal_transmit: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Incoming APDU data [  257 bytes] =====================================
76 CF 79 C1 12 CF C9 53 BF EF 1B B1 1A D5 42 B2 v.y....S......B.
74 70 6C F3 A6 7E F6 A9 5C 9A A7 42 D5 FB 29 6E tpl..~..\..B..)n
F9 1C 36 65 13 1F 7C 3C 52 F3 2B 48 36 B3 AC F7 ..6e..|<R.+H6...
0B 42 43 23 94 12 AA 54 80 7B 32 66 79 0E 69 26 .BC#...T.{2fy.i&
7D F1 92 EB 8F 88 24 38 83 43 FE F3 24 A2 D4 B9 }.....$8.C..$...
78 1B 34 DC B6 F0 16 07 19 76 D1 5B CC B1 EF 7F x.4......v.[....
2C B2 43 59 F0 F6 77 FA 7C B0 3C 16 07 CD 91 7E ,.CY..w.|.<....~
93 04 A9 B6 EC 10 FB 8E 0B 3E 21 DB C7 FD BA 9D .........>!.....
48 C4 BD 22 15 30 23 F7 87 E2 F3 73 89 15 63 EC H..".0#....s..c.
AC F2 84 14 63 C1 52 A3 0C C5 2D 71 8B 29 EA CF ....c.R...-q.)..
F5 F5 6B EA 08 74 BC B1 B4 61 65 EE 95 B7 17 5E ..k..t...ae....^
A4 82 5A F7 9D DA 6C B4 F5 14 47 E6 FA 4D 23 68 ..Z...l...G..M#h
43 6D C7 EF 9A 09 56 23 B4 D3 DD A3 23 9E 3E F5 Cm....V#....#.>.
49 B9 00 DB 33 A0 E0 4C 65 66 1A AA A3 D8 48 47 I...3..Lef....HG
82 C7 10 73 0F CA B5 C6 77 46 73 6A 9D A3 C9 23 ...s....wFsj...#
C4 95 FD B7 46 9F EF BB 7F 06 B2 02 92 40 85 90 ....F........@..
00                                              .
======================================================================
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:399:sc_single_transmit: returning with: 0 (Success)
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:552:sc_transmit: returning with: 0 (Success)
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] card.c:434:sc_unlock: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:563:sc_transmit_apdu: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] card.c:394:sc_lock: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:530:sc_transmit: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:384:sc_single_transmit: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:389:sc_single_transmit: CLA:0, INS:C0, P1:0, P2:0, data(0) (nil)
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] reader-pcsc.c:260:pcsc_transmit: reader 'sim 00 00'
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Outgoing APDU data [    5 bytes] =====================================
00 C0 00 00 01 .....
======================================================================
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] reader-pcsc.c:190:pcsc_internal_transmit: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:187:sc_apdu_log:
Incoming APDU data [    3 bytes] =====================================
DB 90 00 ...
======================================================================
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:399:sc_single_transmit: returning with: 0 (Success)
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:552:sc_transmit: returning with: 0 (Success)
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] card.c:434:sc_unlock: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:514:sc_get_response: returning with: 0 (Success)
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] apdu.c:552:sc_transmit: returning with: 0 (Success)
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] card.c:434:sc_unlock: called
0x7f8bb8bae700 07:37:44.890 [opensc-pkcs11] card-myeid.c:851:myeid_compute_signature: returning with: 256



solution: revert commit a0c008744608ff2a425a7062479dce3712add5ca


Peter



------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________
Opensc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opensc-devel