Skip to content

Load macOS Key Vault certs as Exportable only so private key survives…#5259

Merged
DrewScoggins merged 1 commit into
mainfrom
anscoggi/macos-certhelper-private-key-export
Jul 10, 2026
Merged

Load macOS Key Vault certs as Exportable only so private key survives…#5259
DrewScoggins merged 1 commit into
mainfrom
anscoggi/macos-certhelper-private-key-export

Conversation

@DrewScoggins

Copy link
Copy Markdown
Member

… export

On macOS, loading the Key Vault PKCS#12 with PersistKeySet imports the private key into the login Keychain, which cannot export the private key back out. That produced public-only PFX exports (~half the expected size) with no private key, breaking both the file-backed cert store and the base64 certs written to stdout.

Select storage flags by OS: use Exportable only on macOS (no PersistKeySet) so the key stays in memory and can be exported to the file-backed store; keep Exportable | PersistKeySet on Windows/Linux.

… export

On macOS, loading the Key Vault PKCS#12 with PersistKeySet imports the private key into the login Keychain, which cannot export the private key back out. That produced public-only PFX exports (~half the expected size) with no private key, breaking both the file-backed cert store and the base64 certs written to stdout.

Select storage flags by OS: use Exportable only on macOS (no PersistKeySet) so the key stays in memory and can be exported to the file-backed store; keep Exportable | PersistKeySet on Windows/Linux.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 17: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.

Pull request overview

Adjusts how Key Vault–sourced PKCS#12 certificates are imported by CertHelper so macOS retains an exportable private key, enabling correct PFX re-export into the macOS file-backed cert store and base64 output.

Changes:

  • Selects X509KeyStorageFlags based on OS: macOS uses Exportable only; other OSes use Exportable | PersistKeySet.
  • Applies the selected flags consistently to both the NET9 X509CertificateLoader.LoadPkcs12 path and the pre-NET9 X509Certificate2 constructor path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@matouskozak matouskozak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the quick fix

@DrewScoggins DrewScoggins merged commit 8b6d426 into main Jul 10, 2026
4 of 76 checks passed
@DrewScoggins DrewScoggins deleted the anscoggi/macos-certhelper-private-key-export branch July 10, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants