【问题标题】:How to suppress "ERROR message: short read (SSL routines, SSL routines), value: 335544539"如何抑制“错误消息:短读(SSL 例程,SSL 例程),值:335544539”
【发布时间】:2022-03-13 01:32:32
【问题描述】:

参考: websocket_client_sync_ssl.cpp

// Read a message into our buffer
ws.read(buffer);

// Close the WebSocket connection
ws.close(websocket::close_code::normal);
    

根据我的测试,ws.close 会在下面发出警告:

错误消息:短读(SSL 例程、SSL 例程),值: 335544539

根据这篇帖子short read,可以在会话结束时安全地忽略此错误。我尝试了以下方法来抑制警告:

try
{
  boost::system::error_code close_ec;
  ws.close(websocket::close_code::normal, close_ec);
  if (close_ec)
  {
    std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;
  }
}
catch(...)
{

}
    

但是,ws.close 仍然会打印出警告消息。

问题> 有什么方法可以隐藏此消息?

【问题讨论】:

    标签: boost boost-beast-websocket


    【解决方案1】:

    但是,ws.close 仍然会打印出警告消息。

    你确定吗?看起来这只是来自这条线:

    std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;
    

    因此,您将检查 close_ec 的值并有条件地处理它:Short read error-Boost asio synchoronous https call

    另外,请注意,某些类型的“短读取”可能会构成安全错误。部分样本有very insightful comments about this

    // `net::ssl::error::stream_truncated`, also known as an SSL "short read",
    // indicates the peer closed the connection without performing the
    // required closing handshake (for example, Google does this to
    // improve performance). Generally this can be a security issue,
    // but if your communication protocol is self-terminated (as
    // it is with both HTTP and WebSocket) then you may simply
    // ignore the lack of close_notify:
    //
    // https://github.com/boostorg/beast/issues/38
    //
    // https://security.stackexchange.com/questions/91435/how-to-handle-a-malicious-ssl-tls-shutdown
    //
    // When a short read would cut off the end of an HTTP message,
    // Beast returns the error beast::http::error::partial_message.
    // Therefore, if we see a short read here, it has occurred
    // after the message has been completed, so it is safe to ignore it.
    
    if(ec == net::ssl::error::stream_truncated)
        ec = {};
    else if(ec)
        return;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-08
      • 2022-08-16
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      • 2021-10-25
      • 2019-12-12
      相关资源
      最近更新 更多