证书校验不通过时,输出证书信息。
This commit is contained in:
@@ -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().
|
||||
|
||||
Reference in New Issue
Block a user