alex/revocation-tracker

Handle CT precertificates

titanous opened this issue · 7 comments

If a crt.sh ID is submitted for a precertificate that matches an issued certificate in crt.sh, it should be substituted. If both IDs are submitted, only the issued certificate should be listed.

The two relevant queries:

SELECT position(E'\\x060a2b06010401d6790204030101ff' in certificate) ct_poison
FROM certificate
WHERE id = $1;

if ct_poison is greater than zero, it's likely a precert.

To find the corresponding issued certificate (if any):

SELECT c.id
FROM certificate pc
LEFT OUTER JOIN certificate c
ON (pc.id != c.id 
    AND pc.issuer_ca_id = c.issuer_ca_id 
    AND x509_serialNumber(pc.certificate) = x509_serialNumber(c.certificate))
WHERE pc.id = $1;
alex commented

Yeah, true, it can false positive. But all we need is a heuristic to trigger the second query.

alex commented

Hmm, I think the right way to structure this is:

Have fetch_details check if it's really a pre-cert; then do a second bulk lookup to replace pre-certs with their real ones.

Change _add_crtsh_ids to check already_tracked after fetch_details (to handle the substition correctly).

I filed crtsh/libx509pq#2 just in case we end up wanting a way to query for this.

alex commented

I've addressed crtsh/libx509pq#2. crt.sh now has an x509_hasExtension() function: first parameter is the cert (bytea); second parameter is the OID (either the dotted form, or the OpenSSL short or long name).