Search code examples
clinuxopensslgnu

Can I use the openssl lib to find my server certificate in a buffer containing a certificate chain


My C program receives a certificate chain from a server and stores it in a buffer (certs in DER format). Is it possible to find out where the leaf certificate is stored within this buffer and the length of it by using the openssl library?

I need this information to be able to calculate a checksum based only on the contents of the leaf certificate. Parsing certificate chains seems like a common task, so I suppose there should be support for it by the openssl library.


Solution

  • The solution to my question was to parse the buffer using d2i_x509() to find each certificate.