-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Description
I have an OpenSSL dynamic engine installed that manages keys on an HSM, but when I attempt to use a PFX to create an X509Certificate2 that uses that key, I am presented with an error:
Error occurred during a cryptographic operation.
HasPrivateKey on the X509Certificate2 returns True.
A sample stack trace is below:
Unhandled exception. System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.
at System.Security.Cryptography.RSAOpenSsl.TrySignHash(ReadOnlySpan1 hash, Span
1 destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, Boolean allocateSignature, Int32& bytesWritten, Byte[]& signature)
at System.Security.Cryptography.RSAOpenSsl.SignHash(Byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
at System.Security.Cryptography.RSAPKCS1SignatureFormatter.CreateSignature(Byte[] rgbHash)
...
Reproducing this error will be tricky unless you have access to an HSM. I am happy to volunteer the use of mine.
Configuration
~/.dotnet/dotnet --list-sdks
3.1.300 [/home/ec2-user/.dotnet/sdk]
Amazon Linux 2, x64
Is there a way to specify the engine that will be used by System.Security.Cryptography.OpenSsl through an appSetting, environment variable, etc? From my naive review of the code, it appears that the native interop EnsureOpenSslInitialized() method only calls OPENSSL_add_all_algorithms_conf().