简体   繁体   中英

Exception when trying to get data from SSL certificate

I am trying to decode a certificate my server is sending for each of the objects I enroll. I am trying to get the serial and the validity date for the objects. I have my certificate stored in a std::string called certStr and the code I have is:

OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();

BIO* input(BIO_new(BIO_s_mem()));
BIO_puts(input, certStr.c_str());

// Create an openssl certificate from the BIO
X509* cert(PEM_read_bio_X509(input, NULL, NULL, NULL));

// Create a BIO to hold info from the cert
BIO* output_bio(BIO_new(BIO_s_mem()));

ASN1_INTEGER* bs = X509_get_serialNumber(cert);

and I am getting an exception

EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000008

with that last X509_get_serialNumber function. Do you know what could I be doing wrong? I am pretty new to OpenSSL, so I may have done something stupid that I am not realizing. I am also following this and this code snippets that supposedly do what I am trying to do.

Okay, I found the problem. The server is passing me a PKCS7 certificate, not a PEM certificate, so first I will have to extract the cert from the PKCS7 and then parse the certificate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM