-
Notifications
You must be signed in to change notification settings - Fork 803
GIDS Decipher fix for TPM #1881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It is OK for the TPM chip. Better for the GIDS applet. An error is shown but I don't know if it is related to the applet or the driver |
|
Here is the instructions sent by OpenSC => failed Here are the instructions sent by certutil -scinfo In summary, OpenSC send then 260 + 8 = 268 bytes |
|
The failure looks like the You can test by changing the opensc.conf to something like this: If the restriction is for the card, we can force it. Or if it can be read from the card, we can use what the card says. |
|
Note that GIDS docx says: "If the commands are to be sent without secure messaging, the length of block shall be set to a maximum of 0xFF = 255 bytes." So it should have worked. |
|
So problem is the additional byte whose value is 0 at the start of the APDU. Not the way it is chained |
|
I looked at this again. I don't thing it is a max_send_size. Microsoft Virtual Smart Card with TPM with PI byte (00) and chaining 255 + 16 = 257 returned "6D 00". A different failure which the PR will then try without the PI, sending 255 + 15 = 256 bytes. The failure in #1881 (comment) has the PI byte (00) and chaining 255 + 16 = 257. with status error "67 00" = Le wrong length. But first chain returns 90 00 and second APDU returns the "67 00". Certutil sends no PI byte and chains 240 + 10 = 256 and it works. So I don't think the max_send_size is an issue So each implementation handled the error differently. The PR only retries without the PI, if the first APDU chain failed with "6D 00" Is there any implementation that may expect a PI byte? I can change the PR to never send the PI in that case or change to try without PI first then What do you think? |
|
I think the minidriver does handle both chaining and extended APDU and that the implementation is different. A bug. |
|
@vletoux Please try the new artifacts. They do not send a PI byte for Decipher. |
|
Tested both 1024 & 2048 keys on both TPM and GIDS card |
src/libopensc/card-gids.c
Outdated
|
|
||
| /* for testing ... */ | ||
| if (card->flags & 0x00010000) { | ||
| card->caps = SC_CARD_CAP_APDU_EXT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong indentation
src/libopensc/card-gids.c
Outdated
|
|
||
| sbuf[0] = 0; /* padding indicator byte, 0x00 = No further indication */ | ||
| memcpy(sbuf + 1, crgram, crgram_len); | ||
| apdu.data = sbuf + 1; /* Skip padding indication not needed unless SM */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I see right that you add the padding indcator byte here and than not use it in the APDU?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, The GIDS docx talks about the PI being present, but the Microsoft "Virtual Smart Card (and @vletoux applet) will not work if the PI is present in decipher. iso7816-4 hints that it may be optional. The GIDS docx says PI is needed if Secure Messaging is being used but the driver does not currently support SM.
The gids_decipher was copied from iso7816.c which always adds a PI of 0x00.
I left the code in case we ever add SM to the driver. debug logs show certutil does not use SM. and only works if the PI is not present.
I could just have easily not allocated the sbuf and used something like: apdu.data = crgram;
Suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know anything about GIDS, but if it is just more code (copied from ISO), which is not used, I would rather see it simplified without the needless allocations and copying. If the SM will be implemented some time, adding the padding indicator will probably be least work.
|
So the only difference between the current behavior is to not send the padding indicator, right? That's strange, because Generic Identity Device Specification Version 2.0 says you should send the Data to be deciphered (Pl || cryptogram) (I'd guess they meant a capital I instead of a small ell). Maybe Windows already adds the padding indicator, did you test PKCS#11 as well? (the debug flags should be removed before merging.) |
|
Just realized that Vincent's output above indicates that Windows' default implementation does not send the padding indicator... However, @vletoux, your GIDSApplet does expect the padding indicator... That's everything very strange |
|
This is the first byte of the final APDU. Not the first byte of the content sent inside the APDU. |
|
As a side note, GIDS docx says both extended APDU and chaining must be supported, and will indicate in the EF.ATR in tag "Card capabilities tag". But the driver does test the EF.ATR. The GIDS docx has a lot that is not implemented in the current driver. It appears to me decipher command has never worked with the driver so this PR gets that part working. |
|
The testing I have been I can do is using Microsoft "virtual Smart Card" with a TPM on Windows 10. `certutil -v -scinfo will verifying the key by deciphering some data using the Microsoft minidriver. |
|
I see, thanks for the clearification. Please add a comment to note the difference between specification and implementation regarding the padding indicator, remove the testing flag and simplify your code as requested by Jakub. If done, this PR is good to be merged. |
GIDS decipher APDU fails with status '65 00' or '67 00' if "Padding Indication" byte is present. Debug logs of Microsoft certutil -v -scinfo using Microsoft drivers show that for a decipher, the "Padding Indication" is not present. It maybe needed if Secure Messaging is added later. Extended APDU is turned off as this may not be supported on some cards. Chaining is used used instead, it works on all cards. RAW RSA is turned off, it is supported. Tested with pkcs11-tool on Windows 10 with a TPM 2.0 module. On branch gids-decipher Changes to be committed: modified: src/libopensc/card-gids.c Date: Tue Dec 3 18:08:32 2019 -0600 interactive rebase in progress; onto 01678e8 Last commands done (3 commands done): squash c968d0d GIDS No Padding Indication Byte squash 0fa940fc Take 3 No commands remaining. You are currently rebasing branch 'gids-decipher' on '01678e87'.
c968d0d to
fd1330d
Compare
Fixes #1866
If GIDS decipher APDU fails with status '65 00' it will be retried without the leading "Padding Indication" byte. This is done by a new gids_decipher routine was created based in the iso7816.c version.
Extended APDU is turned off as this may not be supported on some cards. Chaining is used instead, as it is supported on all cards.
Some
card->flagsare defined in case there are issues with extended or max_send_size.Tested with
pkcs11-tool --test --loginon Windows 10 with a TPM 2.0 module via "Microsoft Virtual Smart Card".On branch gids-decipher
Changes to be committed:
modified: src/libopensc/card-gids.c
Checklist