【发布时间】:2021-06-04 13:33:37
【问题描述】:
我正在尝试弄清楚如何在 QTcpServer 中的 TLS 连接中为握手过程创建超时。
我在覆盖的incomingConnection 函数中尝试了类似的操作:
QSslSocket * const tlsSocket = static_cast<QSslSocket*>(socket);
connect(tlsSocket, &QSslSocket::encrypted, this, [this, tlsSocket](){ addPendingConnection(tlsSocket); });
tlsSocket->setLocalCertificate(m_serverCertificate);
tlsSocket->setPrivateKey(m_serverPrivateKey);
tlsSocket->setProtocol(QSsl::SecureProtocols);
tlsSocket->startServerEncryption();
// We will have a handshake timeout of 30 seconds
QTimer::singleShot(30*1000, this, [this, tlsSocket]() {
if(!tlsSocket->isEncrypted()) {
// If no handshake initialized from the client close the connection
delete tlsSocket;
}
});
但这似乎不起作用,因为我没有直接调用 addPendingConnection 函数(它在 slot/lamdba 中被调用,这似乎打破了 pendingConnection 链。
有人知道如何在 Qt 中实现这个超时吗?目前的问题是客户端可以打开与服务器的连接,但它永远不会响应 TLS 握手,这会导致无用的打开连接(即永远不会关闭)。
【问题讨论】:
标签: c++ qt ssl openssl qtcpserver