Reputation: 1764
I'm new to security so some of the terms might be used incorrectly:
SSL_connect
, the server should send back the entire certificate chain so that the authenticity of the server can be verified.I would like to view the certificates returned by the server to verify that I'm getting back the entire certificate chain. Here's what I've tried:
SSLv3_method
.SSL_CTX_set_verify
is set using SSL_VERIFY_NONE
.SSL_connect
I use SSL_get_peer_cert_chain
to get access to the certificate chain. Consider:
STACK_OF(X509)* certificateChain = SSL_get_peer_cert_chain(ssl);
while (char* stackCertificate = sk_pop(certificateChain))
{
X509* certificate = (X509*)stackCertificate;
}
Is this the correct way to get the certificate chain? Is my understanding of the situation correct? Is there perhaps a better way to do this?
Thank you for your time and contribution.
Upvotes: 2
Views: 913
Reputation: 1764
The following code snippet is based off code in s_client
:
SSL* ssl = ...;
STACK_OF(X509)* certCollection = SSL_get_peer_cert_chain(ssl);
for (size_t i = 0; i < sk_X509_num(certCollection); i++)
{
X509* cert = sk_X509_value(certCollection, i);
...
}
As far as I understand, an SSL session must have been created otherwise SSL_get_peer_cert_chain
will return null. Additionally I haven't found any evidence to contradict the list I noted in my question.
Perhaps an easier alternative would be to use the command line tool (downloaded from here):
openssl s_client -connect {server}:{port} -ssl3
Upvotes: 2