Closed GabrielWQS closed 8 months ago
By the way, this type of test was done in the following issues #249 and dotnet rep 92798
When you run p11tool
you are giving the --provider
option. If the SoftHSM provider is properly installed (with a p11-kit module file) then you shouldn't need to do that. What does p11-kit list-modules
or p11tool --list-tokens
say?
If you haven't got things installed correctly, that could explain why the engine doesn't find them.
Unable to load module (null)
Looking closer, it looks like you built your own engine and maybe it couldn't find the p11-kit-proxy.so default module when you built it, so it can't even load that? Install p11-kit before configuring and building libp11.
Without including the --provider
option still worked:
/ # p11tool --login --generate-rsa --bits 2048 --label test-key
warning: no --outfile was specified and the generated public key will be printed on screen.
Generating an RSA key...
Token 'Partition' with URL 'pkcs11:model=SoftHSM%20v2;manufacturer=SoftHSM%20project;serial=53f1c2f2e0e38334;token=Partition' requires user PIN
Enter PIN:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsxGmffDwMdcdS+p5XsUP
lZ2WUTvu+DZlf9sw+bFzoLH9H1dVzXnbjv+YeDcF8azQ9wEiNBQU6/T8cDL8Yc5M
SWtx6u56mVO09EnZ1sp7kLFDg4SBnBPO+UAthr6thm2i35LxMpe78eWNqQUrYj+o
WOWdMDeXFxeRYIgAsZwhMGbkYYpcoU8AAjAgrX6MnBySVLIftghQviARTLmSwQG2
9qUqaKKTCZd6DTvQ1D79RmCyCAMAydJmWTOXLsV/nsrxZIbP6cNPtY4VBFrP3hEn
FlNu72r2nHGhtWa+9eRbXlpaOZl40XL0b0eu+QLEUekf8izuRlEvh587D7U5qHEe
2QIDAQAB
-----END PUBLIC KEY-----
/ # p11tool --login --set-pin=1111 --list-all
Object 0:
URL: pkcs11:model=SoftHSM%20v2;manufacturer=SoftHSM%20project;serial=53f1c2f2e0e38334;token=Partition;id=%47%8E%C6%51%7A%7E%20%85%07%D7%6E%DA%5A%55%B1%F1%DB%52%9F%5D;object=test-key;type=private
Type: Private key (RSA-2048)
Label: test-key
Flags: CKA_WRAP/UNWRAP; CKA_PRIVATE; CKA_NEVER_EXTRACTABLE; CKA_SENSITIVE;
ID: 47:8e:c6:51:7a:7e:20:85:07:d7:6e:da:5a:55:b1:f1:db:52:9f:5d
Object 1:
URL: pkcs11:model=SoftHSM%20v2;manufacturer=SoftHSM%20project;serial=53f1c2f2e0e38334;token=Partition;id=%47%8E%C6%51%7A%7E%20%85%07%D7%6E%DA%5A%55%B1%F1%DB%52%9F%5D;object=test-key;type=public
Type: Public key (RSA-2048)
Label: test-key
Flags: CKA_WRAP/UNWRAP;
ID: 47:8e:c6:51:7a:7e:20:85:07:d7:6e:da:5a:55:b1:f1:db:52:9f:5d
And executing the commands the return was:
/ # p11-kit list-modules
softhsm2: /usr/lib/softhsm/libsofthsm2.so
library-description: Implementation of PKCS11
library-manufacturer: SoftHSM
library-version: 2.6
token: Partition
manufacturer: SoftHSM project
model: SoftHSM v2
serial-number: 53f1c2f2e0e38334
hardware-version: 2.6
firmware-version: 2.6
flags:
rng
login-required
user-pin-initialized
restore-key-not-needed
token-initialized
token:
manufacturer: SoftHSM project
model: SoftHSM v2
serial-number:
hardware-version: 2.6
firmware-version: 2.6
flags:
rng
login-required
restore-key-not-needed
so-pin-locked
so-pin-to-be-changed
/ # p11tool --list-tokens
Token 0:
URL: pkcs11:model=SoftHSM%20v2;manufacturer=SoftHSM%20project;serial=53f1c2f2e0e38334;token=Partition
Label: Partition
Type: Generic token
Flags: RNG, Requires login
Manufacturer: SoftHSM project
Model: SoftHSM v2
Serial: 53f1c2f2e0e38334
Module: /usr/lib/softhsm/libsofthsm2.so
Looking closer, it looks like you built your own engine and maybe it couldn't find the p11-kit-proxy.so default module when you built it, so it can't even load that? Install p11-kit before configuring and building libp11.
Actually I haven't created any engine, I just intend to use OpenSSL itself to ensure that everything is configured correctly. Wouldn't just configuring openssl.cnf
be enough base on README?
I also added the installation of p11-kit in the image, but the result was the same.
Actually I haven't created any engine, I just intend to use OpenSSL itself to ensure that everything is configured correctly.
But... you showed a transcript from where you built libp11 and installed it, and now you have /usr/local/lib/engines-1.1/libpkcs11.so
Is that not the engine that you're using when it reports:
Unable to load module (null)
I believe that (null)
is where it should have detected the location of p11-kit-proxy.so
at build time, but didn't because p11-kit wasn't present when you (or your distribution) built the engine.
The p11-kit
package does not contain the p11-kit-proxy.so
... this is only present in the p11-kit-dev
. I also adjusted the path to to /usr/local/lib/engines-1.1/pkcs11.so
inside the openssl.cnf
and it worked.
Thank you!
Hello,
I need to perform an HTTP communication with mTLS in dotnet8 and the private key must be present in a HSM.
In a Unix environment, dotnet8 should be able to access the key handle through the interface available here.
Initially, I am conducting some tests in a Docker environment using Alpine 3.18 + SoftHSM2 + OpenSSL + libp11, however, operations with the private key are not working.
My dockerfile
Running the image, I executed the following commands to create the key pair and confirm the configuration:
However, in a test with the private key the following error is returned:
What am I missing?