证书校验不通过时,输出证书信息。

This commit is contained in:
zhengchao
2018-10-23 13:35:32 +08:00
committed by 陆秋文
parent 613d23437c
commit c53641bc27
4 changed files with 51 additions and 10 deletions

View File

@@ -1062,6 +1062,27 @@ errout:
return -1;
}
char* ssl_X509_print_name(X509_NAME* name)
{
//ref: https://kahdev.wordpress.com/2008/11/23/a-certificates-name-issuer-and-its-keyusage/
// Set up a BIO to put the name line into.
BIO *name_Bio = BIO_new(BIO_s_mem());
// Now, put the name line into the BIO.
X509_NAME_print_ex(name_Bio, name, 0, XN_FLAG_ONELINE);
// Obtain a reference to the data and copy out
// just the length of the data.
char *data_start = NULL;
char *name_string = NULL;
long nameLength = BIO_get_mem_data(name_Bio, &data_start);
name_string = ALLOC(char, nameLength + 1);
memset(name_string, 0, nameLength + 1);
memcpy(name_string, data_start, nameLength);
BIO_vfree(name_Bio);
return name_string;
}
/*
* Returns the result of ssl_key_identifier_sha1() as hex characters with or
* without colons in a newly allocated string.
@@ -1080,12 +1101,21 @@ char * ssl_key_identifier(EVP_PKEY * key, int colons)
* Returns the one-line representation of the subject DN in a newly allocated
* string which must be freed by the caller.
*/
char *
ssl_x509_subject(X509 * crt)
char * ssl_x509_subject(const X509 * crt)
{
return X509_NAME_oneline(X509_get_subject_name(crt), NULL, 0);
return ssl_X509_print_name(X509_get_subject_name(crt));
}
/*
* Returns the one-line representation of the issuer in a newly allocated
* string which must be freed by the caller.
*/
char * ssl_x509_issuer(const X509 * crt)
{
return ssl_X509_print_name(X509_get_issuer_name(crt));
}
/*
* Parse the common name from the subject distinguished name.
* Returns string allocated using malloc(), caller must free().