阅读证书文件从存储器中,而不是文件的OpenSSL [英] Read Certificate files from memory instead of file OpenSSL

查看:239
本文介绍了阅读证书文件从存储器中,而不是文件的OpenSSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有会听上使用OpenSSL HTTPS的服务器。对于这一点,我必须提供使用证书。然而,目前的实现使用要提供给OpenSSL的API的一个文件名。我想从内存读取的证书信息,这样我就不必船舶证书文件打开。我试图谷歌,但没有拿出任何选项。
是有可能吗?
是否有任何样本/教程已经可以在WEB上,我可以办理什么手续?
任何其他指针/帮助。

I have a server which would listen on HTTPS using OpenSSL. For this, I have to provide the certificate to use. However, the current implementation uses a filename to be provided to OpenSSL API. I want the cert information to be read from memory, so that I don't have to ship the certificate file opening. I tried to google, but didn't come up with any options. Is is possible? Are there any samples/tutorials already available on WEB which I can go through? Any other pointers/help.

PS:在code是用C

PS: The code is written in C.

推荐答案

以下code做的工作对我来说:

The following code did the job for 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);

这篇关于阅读证书文件从存储器中,而不是文件的OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆