Skip to content

Implement X.509, PKCS#12 and PKCS#8 for ML-KEM - #132768

Closed
vcsjones wants to merge 8 commits into
dotnet:mainfrom
vcsjones:pkcs8-export-mlkem
Closed

Implement X.509, PKCS#12 and PKCS#8 for ML-KEM#132768
vcsjones wants to merge 8 commits into
dotnet:mainfrom
vcsjones:pkcs8-export-mlkem

Conversation

@vcsjones

Copy link
Copy Markdown
Member

Windows now supports encrypted exports for ML-KEM PKCS#8, as well as PKCS#12. Let's remove our work around and enable the tests.

The changes and implementation here are more or less a straight port of ML-DSA's.

vcsjones and others added 5 commits August 25, 2026 16:42
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wire the Microsoft.Bcl.Cryptography .NET Framework certificate accessors, retain platform support gating, and align the private-key association tests with the PKCS#8 contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 enables Windows support for ML-KEM X.509 private key association and key export scenarios (PKCS#8 and PKCS#12), and updates tests to run on Windows when ML-KEM is supported.

Changes:

  • Enable Windows certificate private-key association for ML-KEM (GetMLKemPrivateKey/CopyWithPrivateKey) using CNG and PKCS#8 import/export paths.
  • Add ML-KEM Windows implementation plumbing to create ephemeral CNG keys and support encrypted-only export scenarios.
  • Remove the Windows-exclusion test gate and update/expand ML-KEM X.509/PKCS#12 test coverage accordingly.
Show a summary per file
File Description
src/libraries/System.Security.Cryptography/tests/X509Certificates/X509Certificate2PemTests.cs Run ML-KEM PEM load tests based on MLKem.IsSupported (includes Windows).
src/libraries/System.Security.Cryptography/tests/X509Certificates/PfxTests.cs Run ML-KEM PKCS#12/PFX import tests based on MLKem.IsSupported.
src/libraries/System.Security.Cryptography/tests/X509Certificates/ExportTests.cs Run ML-KEM PKCS#12 roundtrip export test based on MLKem.IsSupported.
src/libraries/System.Security.Cryptography/tests/X509Certificates/CertTests.cs Enable ML-KEM CopyWithPrivateKey/ExportPrivate tests on Windows.
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificatePal.Windows.PrivateKey.cs Implement ML-KEM private key retrieval and CopyWithPrivateKey on Windows.
src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj Include new ML-KEM CNG creation helper source file.
src/libraries/Microsoft.Bcl.Cryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateKeyAccessors.cs Add Windows-only implementations for ML-KEM key accessors outside NET / NETSTANDARD.
src/libraries/Microsoft.Bcl.Cryptography/src/Microsoft.Bcl.Cryptography.csproj Include new ML-KEM CNG creation helper source file.
src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/CertificateCreation/PrivateKeyAssociationTests.Shared.cs Update ML-KEM certificate association assertions to validate functional decapsulation.
src/libraries/Common/tests/System/Security/Cryptography/PlatformSupport.cs Remove IsPqcMLKemX509Supported (Windows exclusion) gate.
src/libraries/Common/tests/System/Security/Cryptography/MLKemCngTests.Windows.cs Adjust ML-KEM CNG tests for PKCS#8 behavior and expected Windows error codes.
src/libraries/Common/tests/System/Security/Cryptography/MLKemBaseTests.cs Centralize “export PKCS#8 from public key” assertions via a virtual helper.
src/libraries/Common/src/System/Security/Cryptography/X509Certificates/CertificateHelpers.Windows.cs Add ML-KEM CopyWithPrivateKey implementation on Windows, including CNG/PKCS#8 import fallback.
src/libraries/Common/src/System/Security/Cryptography/MLKemImplementation.CreateCng.cs New helper to create an ephemeral CngKey from MLKemImplementation key material.
src/libraries/Common/src/System/Security/Cryptography/MLKemCng.Windows.cs Implement PKCS#8 import and support encrypted-only export workflows for ML-KEM keys.
src/libraries/Common/src/System/Security/Cryptography/MLDsaCng.Windows.cs Reuse shared Helpers.TrimAndTrack utility.
src/libraries/Common/src/System/Security/Cryptography/Helpers.cs Add shared TrimAndTrack helper for safe trimming/clearing of key material arrays.

Review details

  • Files reviewed: 17/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 26, 2026 14:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings August 27, 2026 11:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@vcsjones vcsjones added the NO-REVIEW Experimental/testing PR, do NOT review it label Aug 27, 2026
@vcsjones
vcsjones temporarily deployed to copilot-pat-pool August 27, 2026 20:11 — with GitHub Actions Inactive
Copilot AI review requested due to automatic review settings August 27, 2026 20:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Lite
Findings: None

@vcsjones

Copy link
Copy Markdown
Member Author

Seems like our CI images have not had ML-KEM flow down through servicing yet. Will Re-open when I get better information about PKCS#8 exports from ncrypt.

@vcsjones vcsjones closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Security NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants