Improve Mac OS Certificate Parsing to import PEM directly

Open
#660 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp
Domain
security

Research direction

Start in Lib/Collectors/CertificateCollector.cs around line 104 and trace the existing security call that generates PEM output. Check how the stored string is currently written and parsed, then compare the proposed flow with X509Certificate2.CreateFromPem. Done means Mac OS certificate PEM data is imported directly and each certificate is reported without writing an intermediate file.

Written by the indexing model from the issue text.

Description

enhancement good first issue

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:
https://github.com/microsoft/AttackSurfaceAnalyzer/blob/6cc160f5d43165fdc298c51efa41239afd554a9a/Lib/Collectors/CertificateCollector.cs#L104

Dominant language
C#
Stars
3k
Forks
294
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/AttackSurfaceAnalyzer

All issues in microsoft/AttackSurfaceAnalyzer

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.