-
Notifications
You must be signed in to change notification settings - Fork 5.2k
ML-DSA certificate accessors for M.B.C. #117907
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
ML-DSA certificate accessors for M.B.C. #117907
Conversation
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Outdated
Show resolved
Hide resolved
e2fa20a
to
83be960
Compare
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Outdated
Show resolved
Hide resolved
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Show resolved
Hide resolved
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Outdated
Show resolved
Hide resolved
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Outdated
Show resolved
Hide resolved
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Outdated
Show resolved
Hide resolved
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Outdated
Show resolved
Hide resolved
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds ML-DSA certificate accessor methods (GetPrivateKey
, GetPublicKey
, and CopyWithPrivateKey
) to Microsoft.Bcl.Cryptography, enabling support for ML-DSA certificates in environments where the full .NET 10+ API is not available. The implementation includes Windows-specific support with runtime compatibility checks for .NET Framework 4.6.2.
Key changes:
- Addition of ML-DSA certificate extension methods to
X509CertificateKeyAccessors
- Refactoring of existing Windows certificate helper code into shared components
- Runtime compatibility checks for
SafeNCryptKeyHandle
constructor availability on older frameworks
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
X509CertificateKeyAccessors.cs |
Adds ML-DSA GetPublicKey , GetPrivateKey , and CopyWithPrivateKey extension methods with platform-specific implementations |
CertificateHelpers.Windows.cs (Common) |
New shared helper class containing Windows-specific certificate operations extracted from existing code |
CertificateHelpers.Windows.cs (BCL) |
BCL-specific implementation with .NET Framework compatibility checks for SafeNCryptKeyHandle constructor |
CertificatePal.Windows.PrivateKey.cs |
Refactored to use shared certificate helpers, reducing code duplication |
PrivateKeyAssociationTests.Shared.cs |
Moved ML-DSA tests from main library to shared test location for reuse across projects |
*.csproj files |
Updated project files to include new shared components and reorganize file references |
Comments suppressed due to low confidence (1)
src/libraries/System.Security.Cryptography/tests/X509Certificates/CertificateCreation/PrivateKeyAssociationTests.cs:4
- The removal of this using statement may indicate that some tests or test utilities are no longer accessible, potentially reducing test coverage for ML-DSA functionality.
using System.Collections.Generic;
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting sad at how much code is moving into Common/src, but, oh well.
...raphy/src/System/Security/Cryptography/X509Certificates/CertificatePal.Windows.PrivateKey.cs
Show resolved
Hide resolved
...ryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved for API additions.
Adds
GetMLDsaPublicKey
,GetMLDsaPrivateKey
andCopyWithPrivateKey
extension methods forX509Certificate2
in Microsoft.Bcl.Cryptography.Note that
GetPrivateKey
requires theSafeNCryptKeyHandle
overload with 2 parameters to allow associating a key with a certificate. This is was introduced in .NETFramework 4.7.2. Instead of makingGetPrivateKey
unavailable in .NET Framework 4.6.2 and .NET Standard, we will do a runtime check for the constructor. This is to accommodate the common scenario of people targeting net462 or otherwise referencing the net462 version of the package, but actually running on net481.Contributes to #113502