1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
void check_cert(SSL *ssl,char *host)
{
X509* peer;
char peer_CN[256];
if(SSL_get_verify_result(ssl) != X509_V_OK)
{
berr_exit("Certificate doesn't verify");
}
/* Check the cert chain. The chain length
is automatically checked by OpenSSL when
we set the verify depth in the ctx */
// Check the common name
peer = SSL_get_peer_certificate(ssl);
X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, peer_CN, 256);
host="10.102.13.114";
if(strcasecmp(peer_CN,host))
{
printf("%s\n ",peer_CN);
printf("%s\n",host);
err_exit("Common name doesn't match host name");
}
} |