-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Error in ECDSA key selection #576
Comments
I now thing the error is related to not defining a unique CK_ID for each key. With PKCS11, CKA_KEY_TYPE=CKK_ECC keys, the private key CKA_CLASS=CKO_PRIVATE_KEY do not contain the public key. CKA_KEY_TYPE=CKK_ECC keys the public key CKA_CLASS=CKO_PUBLIC_KEY has the CKA_EC_POINT. In the following spy log of openssl req for key 1
Your setup and mine might be different, but suspect because it did not search for the label, The tests with RSA should find the public key, because both the private and public keys have the public key, so no need In mine the second CSR gets a different error because it will not try a pin against multiple tokens, as tokens usually have different pins and may lock it out.
|
Sorry, the explanation is beyond my understanding. For information, I forgot to mention it does work with Nitrokey HSM (v1). |
OK, here are some docs that may help. https://datatracker.ietf.org/doc/html/rfc7512 A "library" is usually a "module'.
What is the URI used in the It looks like the distros also use p11-kit which loads multiple PKCS11 modules from /usr/share/p11-kit/modules |
I do confirm Nitrokey uses opensc-pkcs11 ( Key is created by URI in openssl.cnf (for |
The serial= will help find the correct token from all the pkcs11 modules that are loaded by p11-kit But pkcs11:serial=XXXX;object=$NAME in https://docs.openssl.org/3.4/man5/config/ discribs the config file. The distro may have added entries for the how to load an engine The URI is meant to be be from the command line of the With the original problem, you were using So I still don't know what is failing now when you use the softhsm2 pkcs11 module. The URI and PKCS11 is split in to two parts, ones that find a token(s) then the attributes needed to find whatever you are looking for and return just one. I have been around with a script that starts with |
PKCS11 says: "The CKA_ID attribute is intended as a means of distinguishing multiple public-key/private-key pairs held by the same subject (whether stored in the same token or not)." But some tokens or applets on the token do not have a ways to a store a "label" or arbitrary data that could be used for a CKA_ID, but do have a way to have multiple keys and certificates. OpenPGP forces the use of 1, 2, 3 which are used for the CKA_ID. And as I said before EC keys sometimes need to find the the public key from the private key, and the CKA_ID is expected to be there even though PKCS11 goes on to say: " (Since the keys are distinguished by subject name as well as identifier, it is possible that keys for different subjects may have the same CKA_ID value without introducing any ambiguity.) Most smart cards have limitations which make it impossible to fully comply with PKCS11. |
I'm sorry, I responded too rapidly and I mixed environments. I use Test with my NitroKey HSMv1:
|
And I do confirm I purged SoftHSM tokens before each test. |
See: OpenSC/OpenSC#3326 Which fixes pkcs11-tool to format URI id= correctly when listing objects. pkcs11-tool expects Here is a script I have been using with OpenSSL (3.4.0), libp11 (master) and OpenSC (master) built from github. p11-kit is not used, and softhsm2 is from Ubuntu 24.04 (2.6.1-2.2ubuntu3). SPY is used between libp11 and softhsm2 for both |
On my laptop (Debian stable/testing):
I modified openssl and pkcs11-spy.so paths in the script to get them from system.
Do you reproduce the issue? Do you need my spy logs? |
All of this is showing:
So there are some assumptions and bugs in the above, but there are easy workarounds. When using a URI to use a single object, you need to provide enough info to only select one token, and then provide enough info to only find the one object on the token.
Works because the softhsm keys were created with a CKA_ID so (2.) and (4.) have a non default CKA_ID
This will fail because (4.) default CKA_ID with softhsm is 0 for every object and (2.) where libp11 will use CKA_ID and find the first public key (needed because EC is being used) with CKA_ID on the token (9.) In my script I had only one softhsm token, but softhsm can have many tokens and I was not using p11-kit. |
(New issue here after softhsm/SoftHSMv2#784)
On Debian testing, with:
Error with ECDSA key selected by label
Create and verify CSR
If key b is created before key a, b.csr is ok and a.csr is wrong.
There is no issue with RSA:2048 keys.
ASN.1 analysis
As I understand b.csr includes public key a.
OK when ECDSA key selected by ID
Creating and selecting keys with id (token reset)
01.csr and 02.csr are OK.
Stranger: OK when creating keys with ID and selecting them with label
01.csr and 02.csr are also OK.
The text was updated successfully, but these errors were encountered: