c - Read certificate files from memory instead of a file using OpenSSL -


i have server listen on https using openssl. this, have provide certificate use. however, current implementation uses filename provided openssl api.

i want certificate information read memory, don't have ship certificate file opening. tried google, didn't come options.

is possible? if so, how read certificate files memory instead of file using openssl?


edit: following moved comments question.

// current void start_server() {     const char *filename = "cert_and_key.pem";     set_server_ssl_file(filename); } set_server_ssl_file(const char *filename) {     //initialize context     ssl_ctx_use_certificate_file(ctx, pem, ssl_filetype_pem);      ssl_ctx_use_privatekey_file(ctx, pem, ssl_filetype_pem); }  //required void start_server() {     const char *cert = "--begin certificate--............";     const char *key = "--begin rsa private key--.......";     set_server_ssl_options(cert, key); } set_server_ssl_options(const char *cert, const char *key) {     //implementation required } 

the following code did job me:

  ssl_ctx *ctx; x509 *cert = null; rsa *rsa = null; bio *cbio, *kbio; const char *cert_buffer = ""; const char *key_buffer = "";  cbio = bio_new_mem_buf((void*)cert_buffer, -1); cert = pem_read_bio_x509(cbio, null, 0, null); assert(cert != null); ssl_ctx_use_certificate(ctx, cert);  kbio = bio_new_mem_buf((void*)key_buffer, -1); rsa = pem_read_bio_rsaprivatekey(kbio, null, 0, null); assert(rsa != null); ssl_ctx_use_rsaprivatekey(ctx, rsa); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -