Hen*_*rik 2 c++ ssl boost boost-asio
我目前正在使用 boost asio 设置一个 RESTful API。
通过 HTTP 从客户端连接工作正常。但是,如果我尝试通过 HTTPS 连接,我会在服务器端收到错误消息:“无共享密码”。该错误似乎来自 openssl 实现,但我不知道该怎么做。我的第一个猜测是没有设置密码算法,但我看不到在 asio 中如何做到这一点。
这是我在代码中放入的内容以及发生错误的位置:
auto acceptHandler = boost::bind(&self::onAccept, this, connection,
boost::asio::placeholders::error);
connection->async_accept(m_acceptor, acceptHandler);
m_sslContext.set_options(
context::default_workarounds | context::no_sslv2 | context::single_dh_use);
m_sslContext.use_certificate_file(filename, context::pem);
m_sslContext.use_private_key_file(filename, context::pem);
Run Code Online (Sandbox Code Playgroud)
任何人以前有过这个或得到它的工作?
小智 5
我遇到了同样的问题并通过这种方式解决了它。您必须为您的服务器生成一个私钥和一个证书文件。这是这样做的程序:
// Generate a new ssl private key :
$openssl genrsa -out privkey.pem 1024
// Create a certificate signing request using your new key
$openssl req -new -key privkey.pem -out certreq.csr
// Self-sign your CSR with your own private key:
$openssl x509 -req -days 3650 -in certreq.csr -signkey privkey.pem -out newcert.pem
// Install the signed certificate and private key for use by an ssl server
// This allows you to use a single file for certificate and private key
$( openssl x509 -in newcert.pem; cat privkey.pem ) > server.pem
// If you use a dh temp file :
$openssl dhparam -outform PEM -out dh512.pem 512
Run Code Online (Sandbox Code Playgroud)
然后,复制服务器执行目录中的server.pem和dh512.pem文件。
如果您使用 tmp dh 文件,则还必须添加这行代码 m_sslContext.use_tmp_dh_file("dh512.pem");
| 归档时间: |
|
| 查看次数: |
3155 次 |
| 最近记录: |