Validate digital certificate with ICP-Brasil [closed]

0

As we all know, it is possible to generate digital certificates on any computer. These certificates are valid, however, they do not belong to the ICP-Brasil certification chain.

How could this check be done using PHP?

I'm using the openssl_pkcs12_read and openssl_x509_parse functions to validate some data, such as the name of the certificate and the expiration date. Now I need to know if the certificate is valid in ICP-Brasil.

Has anyone ever gone through this? Do you know where I can find a light?

Thanks everyone!

    
asked by anonymous 26.01.2018 / 14:25

1 answer

1

You can start by looking at 2 certificate information, Issuer and AKI (Authority Key Identifer):

Issuer contains the name of the certificate authority that issued the certificate. To know the ICP-Brasil certifying authorities, you can consult on this site , which has the list of all CAs and their respective sites.

At each CA site, look for "repository" or "certificates" (or something like that), and download the certificates for each. So you'll know the exact names of each one.

Therefore, the issuer of your certificate ("Issuer" or "Issuer Name" field, depending on the API used) should be the same as the name ("Subject" field) of the CA certificate.

But the name alone is not enough, since there is nothing to prevent 2 certificates with the same name, but different CAs. Therefore, you should check the Authority Key Identifier extension (also called AKI).

In ICP-Brazil, it was defined that this extension contains the hash of the CA public key that issued the certificate, and this value is also in the CA certificate, but in the extension Subject Key Identifier (or SKI).

That is, the SKI of the CA certificate should have the same AKI value as the certificate you are verifying.

ICP-Brazil certificates have more than one "level" of hierarchy, so you should check the entire chain as well.

For example, an eCPF is usually issued by one of the accredited CAs (Serasa, Certisign, etc.). In turn, the certificates of these ACs were issued by the Federal Revenue Agency, which in turn was issued by Raip ICP-Brasil.

Ideally, you should validate the entire string, but usually the APIs already have methods that are ready to do so, provided you provide the chain certificates via configuration or parameters (and these can be downloaded by following the links in the CAs as explained above ). This varies depending on the API, but the general idea is that.

    
04.05.2018 / 19:38