简体   繁体   English

OpenSSL ssl_accept() 错误 5

[英]OpenSSL ssl_accept() error 5

I have scoured Stack Overflow and the internet, but I have been unable to locate an answer to why ssl_accept() keeps returning:我已经搜索了 Stack Overflow 和互联网,但我一直无法找到为什么 ssl_accept() 不断返回的答案:

[DEBUG] SSL_accept() : Failed with return 0
[DEBUG]     SSL_get_error() returned : 5
[DEBUG]     Error string : error:00000005:lib(0):func(0):DH lib
[DEBUG]     WSAGetLastError() returned : 0
[DEBUG]     GetLastError() returned : 0
[DEBUG]     ERR_get_error() returned : 0

Edit: Out of interest ssl_accept() returns 0, defined as (accordingly to the scant and unhelpful OpenSSL documentation): "The TLS/SSL handshake was not successful but was shut down controlled and by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the return value ret to find out the reason."编辑:出于兴趣 ssl_accept() 返回 0,定义为(根据缺乏和无用的 OpenSSL 文档):“TLS/SSL 握手未成功,但已被 TLS/SSL 协议的规范控制和关闭。调用SSL_get_error() 与返回值 ret 找出原因。”

Below is the snippet of the server side, could I be barking up the wrong tree and this issue be caused by client code?下面是服务器端的片段,我可能会吠错树,这个问题是由客户端代码引起的吗?

    client = accept( server, (sockaddr*) &clientsockaddrin, &len );

    SSL* ssl = SSL_new( ctx );

    SSL_set_fd( ssl, client );

    std::cout << "+--------------------------------------------------+"
              << std::endl;

    int r = SSL_accept( ssl );

    if ( r != 1 ) 
    {
        int err_SSL_get_error = SSL_get_error( ssl, r);
        int err_GetLastError = GetLastError();
        int err_WSAGetLastError = WSAGetLastError();
        int err_ERR_get_error = ERR_get_error();

        std::cout << "[DEBUG] SSL_accept() : Failed with return " 
                  << r << std::endl;
        std::cout << "[DEBUG]     SSL_get_error() returned : "
                  << err_SSL_get_error << std::endl;
        std::cout << "[DEBUG]     Error string : "
                  << ERR_error_string( err_SSL_get_error, NULL ) 
                  << std::endl;
        std::cout << "[DEBUG]     WSAGetLastError() returned : "
                  << err_WSAGetLastError << std::endl;
        std::cout << "[DEBUG]     GetLastError() returned : "
                  << err_GetLastError << std::endl;
        std::cout << "[DEBUG]     ERR_get_error() returned : "
                  << err_ERR_get_error << std::endl;
        std::cout << "+--------------------------------------------------+"
                  << std::endl;
        break;
    }

Appreciate your assistance as this is driving me mad :(感谢您的帮助,因为这让我发疯:(

[DEBUG] Error string : error:00000005:lib(0):func(0):DH lib [DEBUG] 错误字符串:error:00000005:lib(0):func(0):DH lib

The error happened during the Diffie-Hellman Key Exchange, eg where the peers tried to generate the keys for the connection.该错误发生在 Diffie-Hellman 密钥交换期间,例如,对等方尝试为连接生成密钥。 There might be several reasons for this, like invalid DH parameters given on the server side.这可能有多种原因,例如服务器端给出的 DH 参数无效。 With the your current code it is hard to see where the error actually is, but I guess is somewhere in setting up your ctx, so maybe should show the relevant parts of the code.使用您当前的代码很难看出错误实际上在哪里,但我猜是在设置 ctx 的某个地方,所以也许应该显示代码的相关部分。

This is not a Diffie-Hellman library issue.这不是 Diffie-Hellman 库问题。
The reason you are getting the你得到的原因

error:00000005:lib(0):func(0):DH lib错误:00000005:lib(0):func(0):DH lib

is that you passed in the SSL_get_error() error code to ERR_error_string() which you should not do.是您将SSL_get_error()错误代码传递给ERR_error_string()您不应该这样做。

ERR_error_string() is only used on error codes from ERR_get_error() . ERR_error_string()仅用于来自ERR_get_error()错误代码。
See the help page for SSL_get_error() to know what the error means.请参阅SSL_get_error()的帮助页面以了解错误的含义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM