简体   繁体   中英

OpenSSL - Convert X509* x509 to file-BIO* via memory

I am working with a ".cer" certificate file and my task is to push it to stack STACK_OF(X509_INFO) *sk;

I have converted the ".cer" to X509* ptr and now the issue I'm facing is on how to convert X509* ptr to BIO* stackbio since the method I'm using needs BIO* as a parameter to push to the stack.

sk = PEM_X509_INFO_read_bio(BIO* stackbio, sk, NULL, NULL);

Possibly the first step would to be convert X509* to BIO* . The function to do that is: int i2d_X509_bio(BIO *bp, X509 *x); . According to the docs https://linux.die.net/man/3/d2i_x509 :

i2d_X509_bio() is similar to i2d_X509() except it writes the encoding of the structure x to BIO bp and it returns 1 for success and 0 for failure.

Once you've got the BIO* containing the encoded certificate, you should be able to just push it on the stack https://wiki.openssl.org/index.php/STACK_API :

/* add value */
#define sk_BIO_insert(st, val, i)       SKM_sk_insert(BIO, (st), (val), (i))

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