1

我尝试将连接的 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/"
          );
4

1 回答 1

0

我们可以这样重写 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;
}

感谢这篇文章。现在它适用于服务器和客户端。

于 2013-10-04T10:08:29.653 回答