Open GregDomzalski opened 3 months ago
@GregDomzalski @jennyf19 i think the overall this feature makes sense.
@brentschmaltz @jennyf19 Great! Would you like me to add the next level of detail mentioned in the issue template for feature requests? Or should we open the PR and go through any feedback there?
Summary
Microsoft.IdentityModel.Tokens
should expose extension points for customEcdhKeyExchangeProvider
implementations where the private key may not be available in memory. Providing these extensions would bringEcdhKeyExchangeProvider
in line with the other cryptographic providers within the library.Motivation and goals
The
Microsoft.IdentityModel.Tokens
library provides the ability for consumers to provide customSecurityKey
implementations and cryptographic providers. This is useful when one wants (or needs) to store private key material in a way that is otherwise inaccessible to the built-in .NET cryptographic libraries. This could be a key exposed through a 3rd party crypto library such as BouncyCastle, a secrets manager such as 1Password (or an SSH agent), or on a hardware backed device such as anHSM
.Yubico (CC: @JamieHankins @aafortner) is collaborating with a sister-team within Entra ID that requires the use of the ECDH functionality within the
Microsoft.IdentityModel.Tokens
library. One set of private keys used for key agreement is stored on Yubico's YubiHSM product. These are private keys are never available to the host computer that is executing theMicrosoft.IdentityModel.Tokens
library. This also implies that the actual ECDH key agreement operation must be performed on the YubiHSM.The current implementation of
EcdhKeyExchangeProvider
is currently not extensible. There are no override-able methods like there are on other*Provider
classes. The current implementation also assumes in-memory access to the private key which may not always be available in the case of custom implementations.This feature would allow for custom implementations of
EcdhKeyExchangeProvider
in a similar manner to how other providers (e.g.SignatureProvider
) allow for extension.A possible implementation has been created here: YubicoLabs azure-activedirectory-identitymodel-extensions-for-dotnet:ecdh-keyexchange-provider
In scope
DeriveKeyFromHash
step within theGenerateKdf
function.CreateEcdhKeyExchangeProvider
or similar toCryptoProviderFactory
to allow instantiation of custom provider implementations.EcdhKeyExchangeProvider
around access to private key material.EcdhKeyExchangeProvider
to useCryptoProviderFactory
instead of instantiating the provider directly.EcdhKeyExchangeProvider
in line with other crypto providersOut of scope
Risks / unknowns
EcdhKeyExchangeProvider
is an existing class with existing interface expectations. While I have a proposal that does not appear to cause any breaking API surface changes, it's always possible something has been missed.EcdhKeyExchangeProvider
is doing some verification which presently assumes access to the private key. The same checks could be implemented in a different way.IDisposable
and also have aRelease
mechanism throughCryptoProviderFactory.Release*Provider()
.EcdhKeyExchangeProvider
currently implements neither of these.IDisposable
would be a breaking API change. Adding aReleaseEcdhKeyExchangeProvider
method toCryptoProviderFactory
could provide a "lesser of two evils" approach to still allowing for resource cleanup. Since there is no built-in implementation of this method for this provider, there should be no behavior change. The built-in version can simply no-op.Examples
Extending EcdhKeyExchangeProvider: