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

问题描述

我目前正在制定一个RESTful API与升压ASIO。

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.

这是我放在code和出错位置:

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?

推荐答案

我喂未配置时,得到了同样的错误提高:: ASIO :: SSL ::背景对象提高:: ASIO :: SSL ::流对象的构造函数,然后用作接受的结果插口:

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.

和实际后接受价值336109761和消息<$ C $它连接和流程握手握手处理收到的boost ::系统::错误_ code C>没有共享密码。

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 ::背景,然后构造的boost ::支持ASIO :: SSL ::流吧:

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 ++升压ASIO错误:没有共享密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:26