我的代码主要基于 boost ssl 示例客户端,但是我已经使它完全同步,但是 boost 中的示例仍然会做同样的事情。
加载 server.pem 后sslContext.load_verify_file("server.pem");
我尝试加载客户端密钥和 crt 以供服务器验证,用于双向握手。
context_.use_private_key_file("client.key",boost::asio::ssl::context_base::file_format::pem); // also tried use_rsa_private_key_file
context_.use_certificate_file("client.crt",boost::asio::ssl::context_base::file_format::pem);
当调用 use_private_key_file 或 use_rsa_private_key_file 时,当我输入密码时,程序会终止。为什么是这样?- 我的密码是正确的,我已经检查过了openssl rsa -check -in client.key
构造函数将是 boost 示例的唯一更改,这就是我将其用于正常 SSL 握手的方式。
server(boost::asio::io_service& io_service, unsigned short port)
: io_service_(io_service),
acceptor_(io_service,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)),
context_(boost::asio::ssl::context::sslv23)
{
context_.load_verify_file("server.pem");
start_accept();
}
用于两次握手。
server(boost::asio::io_service& io_service, unsigned short port)
: io_service_(io_service),
acceptor_(io_service,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)),
context_(boost::asio::ssl::context::sslv23)
{
context_.load_verify_file("server.pem");
context_.use_private_key_file("client.key",boost::asio::ssl::context_base::file_format::pem); // also tried use_rsa_private_key_file
context_.use_certificate_file("client.crt",boost::asio::ssl::context_base::file_format::pem);
start_accept();
}