AIA: add PKCS#7 parser support for intermediate fetching
Context
Follow-up to #6137 (opt-in AIA certificate chain fetching).
The current AIA fetcher in lib/netext/aia.go handles intermediate certificates served as raw DER or PEM. Some public CAs — notably Sectigo, and older Verisign chains — serve their intermediates as PKCS#7 / CMS bundles (Content-Type: application/pkcs7-mime, extension .p7c). Those responses parse as neither DER nor PEM and are silently dropped, leaving the chain incomplete.
Current behaviour
Since #6137 landed, when an AIA response looks like PKCS#7 (by Content-Type or by ASN.1 signedData OID heuristic), we emit a Warn log so users can diagnose "AIA didn't work" for these chains. The intermediate is still not consumed.
What's needed
Add a PKCS#7 fallback after the DER/PEM attempts in fetchCertFromAIAURL:
- If DER parse fails
- If PEM decode fails
- New: Try PKCS#7 parse — extract certificate(s) from the CMS bundle and use them
Implementation notes
- Go's standard library does not include PKCS#7. A third-party dep is required —
go.mozilla.org/pkcs7(orgithub.com/mozilla-services/pkcs7) is the common choice. - Adding a dep needs a maintainer decision per
Dependencies.md. - Alternative: hand-roll a minimal ASN.1 parser for the signedData certificate set. More code but no dep.
Acceptance criteria
- PKCS#7 AIA responses parse successfully and the extracted intermediate is used for chain verification
- Cache still deduplicates fetches (currently keyed by URL)
- Existing tests still pass
- New test covers PKCS#7 happy path (real .p7c bundle → chain completes)
Related
- PR that introduced AIA fetching: #6137
- Review that flagged this: https://github.com/grafana/k6/pull/6137#issuecomment-4936053924
Source: grafana/k6