-
Notifications
You must be signed in to change notification settings - Fork 186
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
pkcs11_get_ec() assumes DER encodig of pubkeys - fix proposed #79
Comments
Page 217 of the PKCS#11 v2.20 spec (28 June 2004), section 12.3.3, table 55 "Eliptic Curve Public Key Object Attributes":
Reportedly, some implementation do not comply with the standard. |
What PKCS#11 module are you using to access your CardOS v5.0 test card? The problem may be in the module, not in libp11. |
I think at least some cards (e.g., Yubikey) do return EC PK in DER. |
The issue is not what the card returns. The issue is what the PKCS#11 module returns, and does it meet teh PKCS#11 specs.. |
As just mentioned in the other thread #78, I'm using some (official) Card OS 5.3 middleware. It came to my surprise that PKCS#11 in this case requires an ASN.1 octet (DER) encoding, while for RSA key material this is not the case. I confirmed this from ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-30/pkcs-11v2-30m1-d7.pdf. Judging also from the discussion on Bugzilla there are several implementations that are non-compliant in the same way as my card. Thus, my proposal now is to handle both cases, like it as been decided for Mozilla/NSS.
I successfully tested this patch on a libEST client enrolling a EC cert for a private key on the card. I mentioned this issue to the CardOS team as well. BTW, also XCA, a nice graphical front-end to OpenSSL key&cert management functionality, simply assumes that there is no DER encoding. So this seems to be a pretty common mistake, and IMHO it would be of much help if libp11 handles it gracefully. |
I successfully used Thus I question whether this fix should apply to |
Good idea to try |
Do you perhaps need a working tokend? Can it be an issue with the "stock" (aka OpenSC/OpenSC.tokend) not dealing properly with your card? Do you see anything usable in |
In all of your reports, what woulf be very helpful is a OpenSC PKCS11_SPY trace (works with other PKCS#11 modules), or if using OpenSC the opensc-debug.log. For b oth types of traces see: |
Please open a CardOS 5.0 issue in https://github.com/OpenSC/OpenSC/issues The proposed solution, i.e. fallback to "plain" encoding, seems reasonable. I'm going to implement it. Currently, pkcs11_get_ec() does best-effort retrieval and it does not fail if it was unable to retrieve some data. Maybe we should enforce a more strict error checking. I appreciate your comments on this topic. |
@mtrojnar, thanks for swiftly taking over the workaround. @dengert and @mouse07410, thanks for the hints regarding tracing and using the cardos driver. I knew of PKCS11_SPY and I'm already heavily using it, but did not now how to increase the debug output level. Setting OPENSC_DEBUG=9 and using the OpenSC module prints lots of output, while not writing a opensc-debug.log file (unfortunately, I'm not on real Linux, but Cygwin) and I can't find anything like 'tokend' in the output or anywhere else in the OpenSC files. Looking at the debug trace, I can confirm that the cardos ("Siemens CardOS") driver is chosen. As recommended, I'll open issues for OpenSC regarding that cardos driver and CardOS 5.0, giving the respective traces there. |
Apparently due to some misconception,
pkcs11_get_ec()
assumes that the PCKS#11 device returnsEC_POINT
data of public keys in ASN.1 encoding. At least my CardOS v5.0 test card does not work this way, and I suspect that also other cards return plain binary data instead.In my fix given both as attachment: p11_ec_point_no_asn1.patch.txt and in my pull request #80
I improve error handling and disable that part of the code in
pkcs11_get_ec()
used to convert from ASN.1 (by using#ifdef PKCS11_EC_POINT_ASN1
).The text was updated successfully, but these errors were encountered: