Sha*_*ath 5 c++ boost openssl boost-asio
我正在尝试从内存而不是文件中加载 CA 证书。但是我在连接时不断收到握手错误。文件加载完美,内存加载失败。我错过了什么?
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();
Run Code Online (Sandbox Code Playgroud)
看来您想要add_certificate_authority()
:
该函数用于从内存缓冲区添加一个受信任的证书颁发机构。
use_certificate()
和use_certificate_file()
用于握手中提供的服务器或客户端证书,即不是用于测试这些证书的 CA。
这些函数 (load_verify_file()
和add_certificate_authority()
) 的命名不一致。我猜这是因为内存缓冲区版本是最近添加的。