I am getting remote certificate mismatch
error for a few cases from a peer and I am unable to track the issues from server side.
After doing int ret = SSL_accept(ssl)
, is there a way that I can get the certificate name and its details from server (C++ binary) during SSL handshake and print that?
Is there any SSL API that I can use?
You can use SSL_get_certificate()
with the SSL session structure (which is returned in the SSL_accept()
) to retrieve the X509 structure that owns the certificate served to the client.
Later you can extract with some X509 specific functions the CN of the certificate:
X509_NAME_oneline(X509_get_subject_name(certificate), buf, 256);
This would be a naive approach since one cert can handle different CN's, but, it could be enough for your problem.