Skip to content

Instantly share code, notes, and snippets.

@sleevi
Created June 23, 2020 02:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleevi/81d80c6f60def81cba6442e6948a4b98 to your computer and use it in GitHub Desktop.
Save sleevi/81d80c6f60def81cba6442e6948a4b98 to your computer and use it in GitHub Desktop.
Useful scripts for crt.sh path hacking
SELECT DISTINCT
ca.ID,
(coalesce(ca.NUM_ISSUED[1],0) - coalesce(ca.NUM_EXPIRED[1], 0)) as unexpired,
COUNT(DISTINCT c.ISSUER_CA_ID) as paths,
ca.NAME
FROM
ca
INNER JOIN ca_certificate AS ca_c
ON ca.ID = ca_c.CA_ID
INNER JOIN certificate AS c
ON ca_c.CERTIFICATE_ID = c.ID
INNER JOIN ca_trust_purpose AS ca_t_p
ON ca.ID = ca_t_p.CA_ID
WHERE
-- Only unexpired certs
x509_notAfter(c.CERTIFICATE) > NOW()
-- Where the CA is trusted by Mozilla, for TLS
AND ca_t_p.TRUST_CONTEXT_ID = 5
AND ca_t_p.TRUST_PURPOSE_ID = 1
-- And excluding those revoked via CRLs (which CRLSet is a proxy for)
-- Notably, this intentionally includes CAs that have been revoked by
-- Mozilla's OneCRL.
AND NOT ca_t_p.ALL_CHAINS_REVOKED_VIA_CRLSET
GROUP BY
ca.ID
HAVING
-- With at least two different issuers
COUNT(DISTINCT c.ISSUER_CA_ID) >= 2
ORDER BY
unexpired DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment