Created
September 10, 2010 21:13
-
-
Save dchest/574388 to your computer and use it in GitHub Desktop.
How to add a certificate from buffer in OpenSSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X509 *cert; | |
char *zCert; | |
BIO *mem; | |
zCert = // get your certificate text buffer here (C string with certificate in PEM format) | |
mem = BIO_new(BIO_s_mem()); | |
BIO_puts(mem, zCert); | |
cert = PEM_read_bio_X509(mem, NULL, 0, NULL); | |
free(zCert); | |
BIO_free(mem); | |
// set certificate to sslCtx | |
X509_STORE_add_cert(SSL_CTX_get_cert_store(sslCtx), cert); |
I believe that to prevent a memory leak you need X509_free(cert);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's indeed a good solution, I was not aware about it and was struggling to create store/stack from certificate chain.
Cheers!