Add PKCS#11 provider support for key generation - #682
Conversation
Signed-off-by: olszomal <Malgorzata.Olszowka@stunnel.org>
|
Reviewed at 683aeee against master (01c21ac). One blocking issue found: the advertised 1.
|
| Environment | Result |
|---|---|
GCC, OpenSSL 3.6.3, ./bootstrap && ./configure --enable-strict && make -j4 |
Passed on base and PR |
OpenSSL 3.6.3 + SoftHSM2, make check |
Base: 46 pass, 5 skip; PR: 47 pass, 5 skip |
Direct RSA openssl genpkey comparison |
Base: exit 1, 0 objects; PR: exit 1, 2 objects |
git diff --check |
Passed |
Not covered: OpenSSL 3.0/3.5/4.x, Windows, hardware HSMs, and PQ mechanisms unavailable in SoftHSM.
|
Ad 1. OpenSSL PR 32483 adds a Ad 2. (Minor)
The |
|
Thanks for the clarification. Ad 1. Agreed. The provider’s KEYMGMT generation succeeds; the failure occurs afterward when Ad 2. Returning the private-key object is appropriate. My concern is specifically that the exact I recommend preserving the pairing internally without changing the public API:
This would let the existing EC and raw-key construction paths use the exact generated public object while keeping Since I could not reproduce a mismatch with SoftHSM, I consider this non-blocking. With the first finding withdrawn, I have no blocking objections to this PR. |
|
Implemented the suggested fix by preserving the exact public-key handle returned by Generated private keys now use this handle when resolving the corresponding public object, with the existing |
|
Thanks. I reviewed Preserving the public handle is safe even after the generation session is returned to the pool. PKCS#11 v2.40 §3.4 states that an object handle is assigned “for that application’s sessions to use”; the usage guide also demonstrates a handle obtained through one session being used through another. Since these generated public keys are token objects, retaining the originating session is unnecessary. There is one remaining gap: I suggest acquiring a temporary session when |
Keep the public handle returned by C_GenerateKeyPair() to avoid ambiguous CKA_ID lookup for generated key pairs.
|
Updated as suggested and added a regression test for duplicate |
Pull Request Type
Related Issue
Closed #677
Current Behavior
The PKCS#11 provider does not implement KEYMGMT key generation, so keys cannot be generated on a token using
openssl genpkey.New Behavior
The provider implements KEYMGMT key generation for the supported PKCS#11 key types.
The target token and generated key attributes are selected using a PKCS#11 URI.
Scope of Changes
PKCS11_generate_key_ext()to return the generated private key.Testing
Additional Notes
License Declaration