【问题标题】:POCO: How to properly attach StreamSocket to SecureStreamSocket?POCO:如何正确地将 StreamSocket 附加到 SecureStreamSocket?
【发布时间】:2013-10-03 13:10:33
【问题描述】:

我尝试将连接的 StreamSocket 附加到 SecureStreamSocket:

class MyConnection : public TCPServerConnection {
  private:
    Context::Ptr m_pContext;
  public:
    MyConnection(const StreamSocket& socket, Context::Ptr pContext)
    : TCPServerConnection(socket),
      m_pContext(pContext)
    {
    }

    virtual void run() {
      SecureStreamSocket secureSock(SecureStreamSocket::attach(socket(), m_pContext));
      socket() = secureSock;
    }
}

但我有 SSLException:

SSL Exception [N4Poco3Net12SSLExceptionE]: error:140C5042:SSL routines:SSL_UNDEFINED_FUNCTION:called a function you should not call

已执行 SSL 库的初始化:

Poco::Net::initializeSSL(); // inside Application::initialize

SSL 初始化后的上下文初始化:

 Poco::Net::Context::Ptr pContext =
      new Poco::Net::Context(
          Poco::Net::Context::SERVER_USE,
          "server.key",
          "server.crt",
          "/path/to/certs/"
          );

【问题讨论】:

    标签: c++ ssl openssl poco-libraries


    【解决方案1】:

    我们可以这样重写 SecureStreamSocket::attach(...):

    SecureStreamSocket SecureStreamSocket::attach(const StreamSocket& streamSocket, Context::Ptr pContext)
    {
      SecureStreamSocketImpl* pImpl = new SecureStreamSocketImpl(static_cast<StreamSocketImpl*>streamSocket.impl()), pContext);
      SecureStreamSocket result(pImpl);
      if (pImpl->context()->isForServerUse())
          pImpl->acceptSSL();
      else
          pImpl->connectSSL();
      return result;
    }
    

    感谢this post。现在它适用于服务器和客户端。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-03
      • 2016-12-11
      相关资源
      最近更新 更多