ssl - 调用 SSL_shutdown() 挂起,客户端仍处于 FIN_WAIT2 状态

标签 ssl

在我的 ActiveUpdate 模块(从服务器下载文件)中,如果服务器丢弃 FIN 包,关闭 OpenSSL 连接将挂起(等待超过 2 小时)。

SSL连接关闭伪代码

def  ssl_close():
if (!SSL_shutdown(m_ssl)):
    …
    shutdown(SSL_get_fd(m_ssl), SHUT_WR);
    SSL_shutdown(m_ssl)
    ...

挂起连接的 netstat 输出

tcp        0      0 192.168.133.135:52453   10.203.136.169:4122     FIN_WAIT2   off (0.00/0/0)

https://www.openssl.org/docs/ssl/SSL_shutdown.html

In order to complete the bidirectional shutdown handshake, SSL_shutdown() must be called again. If the underlying BIO is blocking, SSL_shutdown() will only return once the handshake step has been finished or an error occurred.

调用一次SSL_shutdown()不会挂起,对内存和连接资源有影响吗?

有没有超时机制来控制 OpenSSL 中的 SSL_shutdown(),或者更好的方法?

最佳答案

第一个 SSL_shutdown 将导致向对等方发送关闭警报,以向对等方发出不再有 SSL 数据到来的信号 - 类似于发送 FIN 或在普通套接字上执行关闭 SHUT_WR。第二个 SSL_shutdown 将等待,直到它收到来自对等方的关闭警报。

为确保套接字完全事件以便对等方发送 SSL 关闭警报并且您将收到它,我建议仅在第二次 SSL_shutdown 完成后关闭底层套接字。 IE。首先将套接字从 SSL 完全降级为普通套接字,然后关闭普通套接字。

关于ssl - 调用 SSL_shutdown() 挂起,客户端仍处于 FIN_WAIT2 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25050425/

相关文章:

android - 在 Android 设备中为 SSO 安装 SSL 证书

cakephp - 在 cakephp ssl 站点路由中重定向到 http 而不是 https

linux - Google Chrome 中的 ERR_INVALID_SIGNED_EXCHANGE 错误

security - 试图保护网站,但也保持主页(索引)页面公共(public) MCV5 asp.net 身份

apache - 除了 CORS 预检外,所有请求都需要客户端证书

PHP 检查 SSL 阻止 php 警告

通过代理的 Java HttpsURLConnection 在 wget 工作正常时无法工作

ubuntu - 默认 SSL 证书目录

缺少 PHP - SSL 证书 - Subdreamer

ruby - 如何获取 Ruby SSLContext 对象的 ssl_version