How to verify a certificate programmatically
OpenSSL 3.0 provides only one API for certificate verification. The API consists of functions starting with the X509_
prefix.
We are going to develop a small program that verifies the leaf certificate that we have just generated, similar to how openssl verify
does so.
Here are some relevant manual pages for the API that we are going to use:
$ man X509_STORE_new $ man X509_STORE_load_file $ man DEFINE_STACK_OF $ man PEM_read_x509 $ man X509_STORE_CTX_new $ man X509_verify_cert $ man X509_STORE_CTX_get_error $ man X509_free
Our program will take three command-line arguments:
- The name of the file containing trusted certificates
- The name of the file containing untrusted certificates
- The name of the file containing the target certificate that is going to be verified
Our high-level implementation plan will be as follows:
- Load trusted certificates.
- Load untrusted certificates.
- Load the target certificate...