c ++ Boost asio错误:无共享密码 [英] c++ Boost asio error: no shared cipher

查看:348
本文介绍了c ++ Boost asio错误:无共享密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用boost asio设置RESTful API。

I am currently setting a RESTful API with boost asio.

从客户端连接可以通过HTTP正常工作。但是如果我尝试通过HTTPS连接,我在服务器端得到一个错误:没有共享密码。
错误似乎来自openssl实现,但我不知道该怎么做。我的第一个猜测是没有密码算法被设置,但我不能看到如何在asio中这样做。

Connecting from a client works fine via HTTP. But if I try to connect via HTTPS I get an error on the server side: "no shared cipher". The error seems to come from the openssl implementation, but I have no idea what to make of it. My first guess would be that that no cypher algorithm is set, but I cannot see how this can be done in asio.

这是我在代码中,发生错误:

This is what I put in the code and where the error occurs:

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);

任何人曾经有过这个或者工作吗?

Anyone ever had this before or got it working?

推荐答案

当feed未配置时,我得到相同的错误 boost :: asio :: ssl :: context c> boost :: asio :: ssl :: stream 对象构造函数,然后用作接受的结果套接字:

I got same error when feed unconfigured boost::asio::ssl::context object to boost::asio::ssl::stream object constructor, which then used as resulted socket of accepting:

server()
    : m_acceptor(/*args*/)
    , m_context(boost::asio::ssl::context::tlsv1_server)
    , m_stream(m_io_service, m_context)
{
    // `m_context` configuring, BUT `m_stream` is unaffected
    m_acceptor.async_accept(m_stream.lowest_layer(), accept_result_handler);
}
// run somewhere `m_io_service.run()`, or other processor of `async` operations.

在实际接受连接并处理握手后,握手处理程序会收到 boost :: system :: error_code ,值为336109761,消息无共享密码

And after actual accept connection and process handshake on it the handshake handler receive boost::system::error_code with value 336109761 and message no shared cipher.

所以首先创建并配置 boost :: asio :: ssl :: context ,然后构造 boost :: asio :: ssl :: stream with it:

So first create and configure boost::asio::ssl::context and then construct boost::asio::ssl::stream with it:

typedef boost::asio::ip::tcp::socket socket_type;
typedef boost::asio::ssl::stream<socket_type> stream_type;

std::shared_ptr<stream_type> m_stream;

server()
    : m_acceptor(/*args*/)
    , m_context(boost::asio::ssl::context::tlsv1_server)
{
    // `m_context` configuring
    m_stream = std::make_shared<stream_type>(m_io_service, m_context);
    m_acceptor.async_accept(m_stream->lowest_layer(), accept_result_handler);
}

并且不要忘记为每个新连接创建新流,上下文可以同样。

And don't forget create new stream for each new connection, context can be the same.

这篇关于c ++ Boost asio错误:无共享密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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