-
Notifications
You must be signed in to change notification settings - Fork 0
perf: parallelize trust verification and default to mozilla root store #183
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "fmt" | ||
| "log/slog" | ||
| "maps" | ||
| "runtime" | ||
| "slices" | ||
| "sort" | ||
| "sync" | ||
|
|
@@ -398,19 +399,61 @@ func (s *MemStore) ScanSummary(input ScanSummaryInput) ScanSummary { | |
| } | ||
| } | ||
|
|
||
| // Pre-compute trust status for all non-expired certs concurrently. | ||
| // Mozilla checks are pure Go and fast; system checks hit the macOS | ||
| // Security framework (SecTrustEvaluateWithError) which is slow. | ||
| // Run mozilla first, then only check system for certs mozilla didn't trust. | ||
| type trustStatus struct { | ||
| mozilla bool | ||
| system bool | ||
| } | ||
| now := time.Now() | ||
| for _, rec := range certs { | ||
| expired := now.After(rec.NotAfter) | ||
| mozillaTrusted := false | ||
| systemTrusted := false | ||
| if !expired { | ||
| if input.MozillaPool != nil { | ||
| mozillaTrusted = certkit.VerifyChainTrust(certkit.VerifyChainTrustInput{Cert: rec.Cert, Roots: input.MozillaPool, Intermediates: intermediatePool}) | ||
| trustResults := make([]trustStatus, len(certs)) | ||
| var wg sync.WaitGroup | ||
| if input.MozillaPool != nil { | ||
| for i, rec := range certs { | ||
| if now.After(rec.NotAfter) { | ||
| continue | ||
| } | ||
| if input.SystemPool != nil { | ||
| systemTrusted = certkit.VerifyChainTrust(certkit.VerifyChainTrustInput{Cert: rec.Cert, Roots: input.SystemPool, Intermediates: intermediatePool}) | ||
| wg.Add(1) | ||
| go func(idx int, cert *x509.Certificate) { | ||
| defer wg.Done() | ||
| trustResults[idx].mozilla = certkit.VerifyChainTrust(certkit.VerifyChainTrustInput{ | ||
| Cert: cert, | ||
| Roots: input.MozillaPool, | ||
| Intermediates: intermediatePool, | ||
| TrustStore: "mozilla", | ||
| }) | ||
|
Comment on lines
+418
to
+426
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In Useful? React with 👍 / 👎. |
||
| }(i, rec.Cert) | ||
| } | ||
| wg.Wait() | ||
| } | ||
| if input.SystemPool != nil { | ||
| sem := make(chan struct{}, runtime.NumCPU()) | ||
| for i, rec := range certs { | ||
| if now.After(rec.NotAfter) || trustResults[i].mozilla { | ||
| continue | ||
|
danielewood marked this conversation as resolved.
|
||
| } | ||
| wg.Add(1) | ||
| sem <- struct{}{} | ||
| go func(idx int, cert *x509.Certificate) { | ||
| defer wg.Done() | ||
| defer func() { <-sem }() | ||
| trustResults[idx].system = certkit.VerifyChainTrust(certkit.VerifyChainTrustInput{ | ||
| Cert: cert, | ||
| Roots: input.SystemPool, | ||
| Intermediates: intermediatePool, | ||
| TrustStore: "system", | ||
| }) | ||
| }(i, rec.Cert) | ||
| } | ||
| wg.Wait() | ||
|
danielewood marked this conversation as resolved.
|
||
| } | ||
|
|
||
| for i, rec := range certs { | ||
| expired := now.After(rec.NotAfter) | ||
| mozillaTrusted := trustResults[i].mozilla | ||
| systemTrusted := trustResults[i].system | ||
|
|
||
| switch rec.CertType { | ||
| case "root": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.