-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
CLR IsEphemeral hinders use of some CNG Providers #71310
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsConsider this: CngKey.Create(
CngAlgorithm.Rsa,
null,
new CngKeyCreationParameters { Provider = CngProvider.MicrosoftPlatformCryptoProvider }); This will fail with: Unhandled exception. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Invalid flags specified. at System.Security.Cryptography.CngKey.set_IsEphemeral(Boolean value) at System.Security.Cryptography.CngKey.Create(CngAlgorithm algorithm, String keyName, CngKeyCreationParameters creationParameters) The Microsoft PCP / TPM provider, and likely other 3rd party CNG Providers, may not support custom properties. As the Lines 100 to 102 in 5877e8b
However, generating a key always tries to call the Lines 122 to 123 in 5877e8b
This makes using
|
I think the |
Since the set is private, the only differences between the set ignoring the error and the callers eating the exception is the latter allows break on exception to work, and has more code. A more reasonable change would probably be:
|
Yeah, unfortunately there is no easy work-around either. The CngKey() constructor that takes the provider and key handles is private. So I cannot implement my own Import method. And DeriveKeyMaterial() needs to be passed a CngKey. This simple .Net code becomes messy because everything has to be done using p/invoke calls to NCrypt.dll. CngKey ephKey = CngKey.Import(ephblob, CngKeyBlobFormat.EccPublicBlob, KspKeyController.KspProvider);
priv.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hmac;
priv.HmacKey = null;
byte[] prk = priv.DeriveKeyMaterial(ephKey); The really strange thing for me anyway, is that it works on Server 2012 R2. But fails in Win10, Server 2016, and Server 2019. This is with the "SafeNet Key Storage Provider". |
Consider this:
This will fail with:
The Microsoft PCP / TPM provider, and likely other 3rd party CNG Providers, may not support custom properties.
As the
get
forIsEphemeral
correctly calls out:runtime/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKey.StandardProperties.cs
Lines 100 to 102 in 5877e8b
However, generating a key always tries to call the
set
, and if it fails, throws an exception:runtime/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKey.StandardProperties.cs
Lines 122 to 123 in 5877e8b
This makes using
CngKey.Create
orCngKey.Import
with some providers difficult to work with.The text was updated successfully, but these errors were encountered: