Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Aug 28, 2025

Backport of #119124 to release/10.0

/cc @bartonjs

Customer Impact

  • Customer reported
  • Found internally

When loading a PKCS#12/PFX that contains a key marked as belonging to a machine key-store, users/processes without administrator permissions on Windows can get a failure loading the file on .NET 10 when it succeeded on .NET 8.

Regression

  • Yes
  • No

This regression was introduced with X509CertificateLoader (#102167).

Windows CAPI RSA machine keys can be created by anyone on the computer, but Windows CNG RSA machine keys can only be created by administrators.

The administrator restriction does not apply to machine keys loaded as "ephemeral" keys, but test coverage incorrectly assumed that "ephemeral" and "persisted" had the same permissions model.

Testing

The fix was verified with a dedicated program that created PFXes with every known CAPI RSA CSP, alternated with machine keys and user keys, and imported them with all relevant X509KeyStorageFlags combinations. The program was run as an admin (everything worked before, and after) and a low-rights user (several tests failed before, succeeded after).

A simplified version of this verification program has been added to the test suite with this change.

Risk

Medium.

This change involves a mix of Windows documented material (the list of known CAPI CSPs),
generally accepted facts (MS_ENH_RSA_AES_PROV can load keys from all older RSA CSPs and offers more functionality),
and black-box observed behavior (the permissions differences between CAPI persisted, CNG persisted, and CNG ephemeral, and the behavior differences between PKCS12_PREFER_CNG_KSP and a key actually saying it should be loaded into CNG).

Test coverage says that known conditions are all in a same-or-better state, but it's difficult to state confidently that "unknown" conditions aren't abundant.

1) Windows exhibits different behaviors between no provider attribute with PKCS12_PREFER_CNG_KSP than with specifying the KSP, so always specify the KSP.

2) Let's stop messing with provider attributes on non-Windows, since this change is making them more expensive.

3) If PreserveStorageProvider is false, the key would go to a machine store, the user can't write to the CNG machine store, and the key is from a known CAPI provider, don't upgrade it to CNG.
@bartonjs bartonjs requested review from artl93 and vcsjones August 28, 2025 18:43
Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

Core scenario.

@dotnet-policy-service
Copy link
Contributor

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

@artl93 artl93 added the Servicing-approved Approved for servicing release label Aug 29, 2025
@artl93 artl93 enabled auto-merge (squash) August 29, 2025 18:38
@jeffhandley jeffhandley disabled auto-merge September 2, 2025 08:22
@jeffhandley
Copy link
Member

@artl93 Can you merge this with your release branch permissions please?

@jeffhandley jeffhandley added this to the 10.0.0 milestone Sep 2, 2025
@artl93 artl93 enabled auto-merge (squash) September 2, 2025 17:59
@artl93 artl93 disabled auto-merge September 2, 2025 18:56
@artl93 artl93 merged commit 8f771e6 into release/10.0 Sep 2, 2025
91 of 93 checks passed
@bartonjs bartonjs deleted the backport/pr-119124-to-release/10.0 branch September 2, 2025 21:01
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Security Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants