-
Notifications
You must be signed in to change notification settings - Fork 42
Description
In response to OpenSC issue OpenSC/OpenSC#2242 by @jo-bitsch please see
OpenSC/OpenSC#2242 (comment)
This points out a problem in the response to the Select AID where the length of the tag is wrong,
61 81 4F is parsed as tag=61 len=4F with next tag as 06.
But the it looks like it should have been
61 81 81 with tag=61 len=81 and next tag =4F
And the interpretation "AC" by NIST approved Idemia card which supports sp800-73-4 Secure Messaging differs from PivApplet interpretation which also made the response larger then needed.
OpenSC/OpenSC#2242 deals with tag is not parsed correctly, but looking at the data in the response, the response is not constructed by PivApplet correctly.
Incoming APDU (133 bytes):
61 81 4F 06 00 00 10 00 01 00 79 0D 4F 0B A0 00 a.O.......y.O...
00 03 08 00 00 10 00 01 00 50 22 50 69 76 41 70 .........P"PivAp
70 6C 65 74 20 76 30 2E 38 2E 32 2D 64 65 76 2F plet v0.8.2-dev/
52 45 65 50 53 41 73 78 4C 72 61 44 58 5F 50 26 REePSAsxLraDX_P&
68 74 74 70 73 3A 2F 2F 67 69 74 68 75 62 2E 63 https://github.c
6F 6D 2F 61 72 65 6B 69 6E 61 74 68 2F 50 69 76 om/arekinath/Piv
41 70 70 6C 65 74 AC 1B 80 01 03 80 01 08 80 01 Applet..........
0A 80 01 0C 80 01 06 80 01 07 80 01 11 80 01 14 ................
06 01 00 90 00
Based on the name this appears to be a dev build, with a long name that caused the problem with the long tag.
It also pointed out current OpenSC card-piv.c can not handle the response if over 128 bytes.
But OpenSC/OpenSC#2053 could handle it.
Contributing to the problem is the length of the tag AC This is new in NIST sp800-74-4 and defined in Table 5. Which say just before table 5:
" A PIV Card Application may use a subset of the cryptographic algorithms defined in SP 800-78. Tag 0xAC encodes the cryptographic algorithms supported by the PIV Card Application. The encoding of tag 0xAC shall be as specified in Table 5. Each instance of tag 0x80 shall encapsulate one algorithm. The presence of algorithm identifier '27' or '2E' indicates that the corresponding cipher suite is supported by the PIV Card Application for secure messaging and that the PIV Card Application possesses a PIV Secure Messaging key of the appropriate size for the specified cipher suite. Tag 0xAC shall be present and indicate algorithm identifier 0x27 or 0x2E (but not both) when the PIV Card Application supports secure messaging."
PivApplet added 9 elements by adding "ALL" the algorithms supported by the card.
An Idemia NIST approved demo card that supports SM from sp800-74-4 only adds 2 elements:
AC 06 80 01 2E 06 01 00 i.e. is supports SM using 2E and a null OID.
sp800-73-3 does not define the "AC" tag.
It looks like Idemia interpreted table 5 to be added only when SM was supported as stated in bolded line above and did not report the standard required algorithms.
So if PivApplet can shorten the AC, or remove it or shorten comments by 2 bytes everything will work.