【问题标题】:The error code of SSL_read function stucked meSSL_read 函数的错误代码卡住了我
【发布时间】:2021-06-17 12:31:21
【问题描述】:
sslread_result=SSL_read(ssl,...);
sslread_err=SSL_get_error(ssl,sslread_result);
if(sslread_err==SSL_ERROR_NONE) {
    //...
}
else if(sslread_err==SSL_ERROR_WANT_READ||sslread_err==SSL_ERROR_WANT_WRITE) {
    //...
}
else {
    printf("0x%08X:[ERROR!]-WSARecv-Decipher/SSL_read error:%d/%d\n",GetCurrentThreadId(),sslread_err,sslread_result);
    
    char err_msg[1024]="";
    printf("SSL read error(%d):%s\n%s\n%s\n",
           sslread_err,
           ERR_error_string(sslread_err,err_msg),
           err_msg,
           ERR_reason_error_string(sslread_err)); 

}

我使用 openssl 发送 https 请求并获得响应。不知怎的,它出了问题。错误输出是这样的(由函数printf打印):

0x00001E78:[错误!]-WSARecv-Decipher/SSL_read 错误:6/0 SSL 读取错误(6):error:00000006:lib(0):func(0):EVP lib 错误:00000006:lib(0):func(0):EVP lib EVP 库

这是什么意思? openssl的错误码0000006,错误字符串EVP lib

【问题讨论】:

    标签: c openssl


    【解决方案1】:

    从您的输出中,我可以看到 SSL_get_error() 返回值 6 - 实际上是 SSL_ERROR_ZERO_RETURN。手册页对此有这样的说法:

    SSL_ERROR_ZERO_RETURN
    
    The TLS/SSL peer has closed the connection for writing by sending the close_notify alert. No more data can be read. Note that SSL_ERROR_ZERO_RETURN does not necessarily indicate that the underlying transport has been closed.
    

    https://www.openssl.org/docs/man1.1.1/man3/SSL_get_error.html

    所以远程对等方彻底关闭了连接。

    不能将您的sslread_err 值传递给ERR_error_string。如您所见,这会给您一个不正确的错误消息。

    如果 SSL_get_error() 通过SSL_ERROR_SSL 指示致命错误,那么您可以使用ERR_get_error 获得有关该错误的更多详细信息。您可以将那个值传递给ERR_error_string。在此处查看ERR 函数的手册页:

    https://www.openssl.org/docs/man1.1.1/man3/ERR_get_error.html https://www.openssl.org/docs/man1.1.1/man3/ERR_error_string.html

    【讨论】:

      猜你喜欢
      • 2016-11-28
      • 2015-01-16
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 2018-04-06
      • 2018-02-15
      • 2018-05-13
      • 2023-03-30
      相关资源
      最近更新 更多