Skip to content

Instantly share code, notes, and snippets.

@sleevi
Last active June 23, 2020 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleevi/6d4c702d0e613cc2e53e3f0d7645ad66 to your computer and use it in GitHub Desktop.
Save sleevi/6d4c702d0e613cc2e53e3f0d7645ad66 to your computer and use it in GitHub Desktop.
Computing Mozilla Trusted CAs

What this is

Absolutely terrible SQL queries against crt.sh to generate the links and nodes of the Mozilla Trusted CA Certificate graph.

How to use it

It's SQL, it should be obvious ;)

You can connect to https://crt.sh via psql using the following:

 psql -h crt.sh -p 5432 -U guest certwatch

From there, you'll want to make sure your JSON output doesn't have the leading/trailing junk added, and so for a single session, you'll need to run both \t on and \pset format unaligned to turn those off.

SELECT
array_to_json(array_agg(row_to_json(t)))
FROM (
SELECT
ca.ID,
ca.NAME
FROM
ca
INNER JOIN ca_trust_purpose AS ca_t_p
ON ca_t_p.CA_ID = ca.ID
WHERE
ca_t_p.TRUST_CONTEXT_ID = 5
AND ca_t_p.TRUST_PURPOSE_ID = 1
AND ca_t_p.IS_TIME_VALID
AND NOT(ca_t_p.ALL_CHAINS_REVOKED_IN_SALESFORCE OR ca_t_p.ALL_CHAINS_REVOKED_VIA_ONECRL)
) t \g nodes.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment