Repository navigation
Replace the deprecated X509Certificate2 constructor with X509CertificateLoader.LoadCertificate - #27965
Merged
Dongbo Wang (daxian-dbw) merged 1 commit intoSep 22, 2026
Conversation
…ficateLoader.LoadCertificate'
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes are a straightforward replacement of a deprecated API with an already-used alternative in the repo, with no evident behavioral regressions for the DER certificate byte inputs in these call sites.
Pull request overview
This PR updates certificate loading paths to avoid the deprecated X509Certificate2(byte[]) constructor by using X509CertificateLoader.LoadCertificate, aligning PowerShell’s security-related code with current .NET guidance.
Changes:
- Replace
new X509Certificate2(byte[])withX509CertificateLoader.LoadCertificate(byte[])in CMS recipient resolution, serialization rehydration, and CIM conversion. - Remove the
SYSLIB0057suppression pragmas now that the deprecated constructor is no longer used. - Minor refactor/documentation: switch PEM/CMS sigil fields to
constand add clarifying comments about the expected certificate encoding.
File summaries
| File | Description |
|---|---|
| src/System.Management.Automation/security/SecuritySupport.cs | Loads DER certificate bytes via X509CertificateLoader during CMS recipient resolution; sigil fields changed to const and comments added. |
| src/System.Management.Automation/engine/serialization.cs | Uses X509CertificateLoader.LoadCertificate when rehydrating X509Certificate2 from serialized RawData. |
| src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimConverter.cs | Uses X509CertificateLoader.LoadCertificate when converting CIM byte[] values into X509Certificate2. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Ilya (iSazonov)
approved these changes
Sep 4, 2026
Collaborator
|
I still see 16 SYSLIB0057 in the repo. |
Patrick Meinecke (SeeminglyScience)
approved these changes
Sep 22, 2026
Dongbo Wang (daxian-dbw)
merged commit Sep 22, 2026
0817ada
into
PowerShell:master
44 of 47 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Replace the deprecated
X509Certificate2constructor withX509CertificateLoader.LoadCertificatein PowerShell.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header