从内存加载CA证书 [英] Loading CA certificate from memory

查看:66
本文介绍了从内存加载CA证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从内存而不是文件中加载CA证书.但是我在连接时不断出现握手错误.文件加载正常,内存加载失败.我想念什么?

I am trying to load CA certificate from memory instead of file. But I keep getting handshake error while connecting. The file loading works perfectly, memory loading fails. What am I missing?

std::ifstream file("message_server_ca.crt");
std::vector<char> fileContents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
boost::asio::const_buffer buffer(&fileContents.at(0),fileContents.size());

bool useFile = false;  // switch between file and memory loading.
boost::asio::ssl::context ctx(io_service, boost::asio::ssl::context::sslv23);
ctx.set_verify_mode(boost::asio::ssl::context::verify_peer);

if(useFile)
{
    // This works perfectly!
    ctx.load_verify_file("message_server_ca.crt");
}
else
{
    // This fails the handshake (asio.ssl:336134278)
    ctx.use_certificate(buffer,boost::asio::ssl::context_base::pem);
}

client c(io_service, ctx, iterator);
io_service.run();

推荐答案

您似乎想要

It appears that you want add_certificate_authority():

此功能用于从中添加一个受信任的证书颁发机构内存缓冲区.

This function is used to add one trusted certification authority from a memory buffer.

use_certificate() use_certificate_file()用于握手中显示的服务器或客户端证书,即用于测试的CA not 这些证书.

use_certificate() and use_certificate_file() are for the server or client certificate presented in the handshake, i.e. not the CA used to test those certificates.

这些函数( load_verify_file() add_certificate_authority())的名称不一致.我猜这是因为内存缓冲区版本是最近才添加的.

These functions (load_verify_file() and add_certificate_authority()) are not consistently named. I guess it is because the memory buffer versions were added relatively recently.

这篇关于从内存加载CA证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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