Skip to content
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

Improve Mac OS Certificate Parsing to import PEM directly #660

Open
gfs opened this issue Aug 25, 2022 · 0 comments
Open

Improve Mac OS Certificate Parsing to import PEM directly #660

gfs opened this issue Aug 25, 2022 · 0 comments
Labels
enhancement New feature or request good first issue

Comments

@gfs
Copy link
Contributor

gfs commented Aug 25, 2022

The PEM exported by the Mac OS Keychain is all of the certificates base64 encoded and then stitched together with --- BEGIN CERTIFICATE --- and --- END CERTIFICATE --- blocks. After .NET 5 its possible to load a certificate from base64 encoded text with X509Certificate2.CreateFromPem

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate2.createfrompem?view=net-6.0

Proposed solution:

  1. Use existing security call to generate PEM.
  2. The result is already stored in a string - instead of writing out to a file, just split that string into chunks of base64 data, stripping out the headers.
  3. With each chunk call X509Certificate2.CreateFromPem
  4. Report the certificate

Code point to modify:

if (ExternalCommandRunner.RunExternalCommand("openssl", $"pkcs12 -export -nokeys -out {pkPath} -passout pass:pass -in {tmpPath}", out string _, out string _) == 0)

@gfs gfs added the enhancement New feature or request label Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue
Projects
None yet
Development

No branches or pull requests

1 participant