The following command prints the SHA1 Fingerprint of the host mentioned
openssl s_client -connect hostname:port | openssl x509 -fingerprint -noout
To do the same action to be done using c++, I am using ssl API
#include"openssl/ssl.h"
#include"openssl/bio.h"
#include "openssl/err.h"
#include<iostream>
using namespace std;
int main()
{
SSL_CTX * ctx = SSL_CTX_new(SSLv23_client_method());
SSL * ssl;
BIO * bio;
SSL_library_init();
bio = BIO_new_ssl_connect(ctx);
BIO_set_conn_hostname(bio, "hostname:port");//Correct hostname and port is used
if(BIO_do_connect(bio) <= 0)
{
cout << "success";
}
BIO_get_ssl(bio, & ssl);
X509 *x509 = NULL;
x509 = SSL_get_certificate( ssl );//Crashing point
return 1;
}
The Application crashes in
x509 = SSL_get_certificate( ssl );
Any Idea why it crashes?