<div dir="ltr"><span style="color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;font-size:15px;line-height:19.5px">I wrote this small program which takes as input X509 certificates, base64-encoded, parse them and build a certificate chain, which is eventually verified by </span><code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:pre-wrap;color:rgb(34,36,38);background-color:rgb(238,238,238)">x509_Verify_cert()</code><span style="color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;font-size:15px;line-height:19.5px">. The last certificate is added to the trusted store if it's self-signed, in order to avoid OpenSSL policy about self.signed certificates, as it's recommended in this </span><a href="https://zakird.com/2013/10/13/certificate-parsing-with-openssl/" rel="nofollow" style="margin:0px;padding:0px;border:0px;font-size:15px;text-decoration:none;color:rgb(0,89,153);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px">post</a><span style="color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;font-size:15px;line-height:19.5px">. The code is at this <a href="http://pastebin.com/2N2DSxbe">pastebin link</a>.</span><div><br></div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px">However, when I run this with a correct certificate chain (Facebook one, already tested with other libraries), I got error 7, certificate signature validation, at depth 1. The certificate chain is composed by server certificate, CA certificate and a self-signed root certificate, which is also in the trusted system store. Hence, it seems that the public key of the self-signed root certificate is not correctly used to verify the signature on the CA certificate. Moreover, I compile the same source but linking boringSSL crypto library instead of OpenSSL one, and everything works perfectly. Hence, my hyphotesis is that this is an OpenSSL issue found by Google and fixed in BoringSSL, but it has not been fixed in OpenSSL yet. So, I would like to know if I'm missing some steps in order to properly use <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(238,238,238)">x509_verify_cert()</code> method, or my hyphotesis about BoringSSL fixing could be appropriate.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px">Thank You,</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,'Helvetica Neue',Helvetica,sans-serif;line-height:19.5px">Nicholas</p></div></div>