通過 TLS (傳輸層安全) 實現加密的安全 TCP 服務器。 更多...
| 頭: |
#include <QSslServer>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
|
| qmake: |
QT += network
|
| Since: | Qt 6.4 |
| 繼承: | QTcpServer |
| QSslServer (QObject * parent = nullptr) | |
| virtual | ~QSslServer () override |
| int | handshakeTimeout () const |
| void | setHandshakeTimeout (int timeout ) |
| void | setSslConfiguration (const QSslConfiguration & sslConfiguration ) |
| QSslConfiguration | sslConfiguration () const |
| void | alertReceived (QSslSocket * socket , QSsl::AlertLevel level , QSsl::AlertType type , const QString & 描述 ) |
| void | alertSent (QSslSocket * socket , QSsl::AlertLevel level , QSsl::AlertType type , const QString & 描述 ) |
| void | errorOccurred (QSslSocket * socket , QAbstractSocket::SocketError socketError ) |
| void | handshakeInterruptedOnError (QSslSocket * socket , const QSslError & error ) |
| void | peerVerifyError (QSslSocket * socket , const QSslError & error ) |
| void | preSharedKeyAuthenticationRequired (QSslSocket * socket , QSslPreSharedKeyAuthenticator * authenticator ) |
| void | sslErrors (QSslSocket * socket , const QList<QSslError> & errors ) |
| void | startedEncryptionHandshake (QSslSocket * socket ) |
| virtual void | incomingConnection (qintptr socket ) override |
Class to use in place of QTcpServer to implement TCP server using Transport Layer Security (TLS).
To configure the secure handshake settings, use the applicable setter functions on a QSslConfiguration object, and then use it as an argument to the setSslConfiguration () function. All following incoming connections handled will use these settings.
To start listening to incoming connections use the listen () function inherited from QTcpServer . Other settings can be configured by using the setter functions inherited from the QTcpServer 類。
Connect to the signals of this class to respond to the incoming connection attempts. They are the same as the signals on QSslSocket , but also passes a pointer to the socket in question.
When responding to the pendingConnectionAvailable () signal, use the nextPendingConnection () function to fetch the next incoming connection and take it out of the pending connection queue. The QSslSocket is a child of the QSslServer and will be deleted when the QSslServer is deleted. It is still a good idea to destroy the object explicitly when you are done with it, to avoid wasting memory.
另請參閱 QTcpServer , QSslConfiguration ,和 QSslSocket .
[explicit]
QSslServer::
QSslServer
(
QObject
*
parent
= nullptr)
構造新的 QSslServer 采用給定 parent .
[override virtual noexcept]
QSslServer::
~QSslServer
()
銷毀 QSslServer .
所有打開的連接都關閉。
[signal]
void
QSslServer::
alertReceived
(
QSslSocket
*
socket
,
QSsl::AlertLevel
level
,
QSsl::AlertType
type
, const
QString
&
描述
)
QSslServer emits this signal if an alert message was received by the socket from a peer. level 告訴警報是緻命的,還是警告。 type 是解釋為什麼發送警報的代碼。當警報消息的文本描可用時,它的供給是在 description .
注意: The signal is mostly for informational and debugging purposes and does not require any handling in the application. If the alert was fatal, underlying backend will handle it and close the connection.
注意: 並非所有後端都支持此功能。
另請參閱 alertSent (), QSsl::AlertLevel ,和 QSsl::AlertType .
[signal]
void
QSslServer::
alertSent
(
QSslSocket
*
socket
,
QSsl::AlertLevel
level
,
QSsl::AlertType
type
, const
QString
&
描述
)
QSslServer emits this signal if an alert message was sent from socket to a peer. level 描述它是警告,還是緻命錯誤。 type 給齣警報消息代碼。當警報消息的文本描述可用時,它的供給是在 description .
注意: 此信號主要是情報,且可以用於調試目的,通常,不要求來自應用程序的任何動作。
注意: 並非所有後端都支持此功能。
另請參閱 alertReceived (), QSsl::AlertLevel ,和 QSsl::AlertType .
[signal]
void
QSslServer::
errorOccurred
(
QSslSocket
*
socket
,
QAbstractSocket::SocketError
socketError
)
This signal is emitted after an error occurred during handshake. The socketError 參數描述齣現錯誤的類型。
The socket is automatically deleted after this signal is emitted if the socket handshake has not reached encrypted state. But if the socket is successfully encrypted, it is inserted into the QSslServer 's pending connections queue. When the user has called QTcpServer::nextPendingConnection () it is the user's responsibility to destroy the socket 或 socket will not be destroyed until the QSslServer object is destroyed. If an error occurs on a socket after it has been inserted into the pending connections queue, this signal will not be emitted, and the socket will not be removed or destroyed.
注意: 不可以使用 Qt::QueuedConnection when connecting to this signal, or the socket will have been already destroyed when the signal is handled.
另請參閱 QSslSocket::error () 和 errorString ().
[signal]
void
QSslServer::
handshakeInterruptedOnError
(
QSslSocket
*
socket
, const
QSslError
&
error
)
QSslServer emits this signal if a certificate verification error was found by socket and if early error reporting was enabled in QSslConfiguration . An application is expected to inspect the error and decide if it wants to continue the handshake, or abort it and send an alert message to the peer. The signal-slot connection must be direct.
另請參閱 QSslSocket::continueInterruptedHandshake (), sslErrors (),和 QSslConfiguration::setHandshakeMustInterruptOnError ().
Returns the currently configured handshake timeout.
另請參閱 setHandshakeTimeout ().
[override virtual protected]
void
QSslServer::
incomingConnection
(
qintptr
socket
)
重實現: QTcpServer::incomingConnection (qintptr socketDescriptor).
被調用,當新連接建立時。
轉換 socket 到 QSslSocket .
[signal]
void
QSslServer::
peerVerifyError
(
QSslSocket
*
socket
, const
QSslError
&
error
)
QSslServer 可以在 SSL 握手期間多次發射此信號,在建立加密之前,以指示當建立對等方的標識時有發生錯誤。 error 通常指示 socket 無法安全標識對等方。
此信號為您提供早期指示,當事情齣錯時。通過連接到此信號,可以手動選擇從連接槽內拆毀連接,在握手完成前。若不采取行動, QSslServer 將繼續進行以發射 sslErrors ().
另請參閱 sslErrors ().
[signal]
void
QSslServer::
preSharedKeyAuthenticationRequired
(
QSslSocket
*
socket
,
QSslPreSharedKeyAuthenticator
*
authenticator
)
QSslServer emits this signal when socket negotiates a PSK ciphersuite, and therefore PSK authentication is then required.
When using PSK, the server must supply a valid identity and a valid pre shared key, in order for the SSL handshake to continue. Applications can provide this information in a slot connected to this signal, by filling in the passed authenticator 對象根據需要。
注意: 忽略此信號或未能提供要求證書,將導緻握手失敗,因此連接將被中止。
注意: The authenticator object is owned by the socket and must not be deleted by the application.
另請參閱 QSslPreSharedKeyAuthenticator .
設置 timeout to use for all incoming handshakes, in milliseconds.
This is relevant in the scenario where a client, whether malicious or accidental, connects to the server but makes no attempt at communicating or initiating a handshake. QSslServer will then automatically end the connection after timeout milliseconds have elapsed.
By default the timeout is 5000 milliseconds (5 seconds).
注意: The underlying TLS framework may have their own timeout logic now or in the future, this function does not affect that.
注意: The timeout passed to this function will only apply to new connections. If a client is already connected it will use the timeout which was set when it connected.
另請參閱 handshakeTimeout ().
設置 sslConfiguration to use for all following incoming connections.
This must be called before listen () to ensure that the desired configuration was in use during all handshakes.
另請參閱 sslConfiguration () 和 QSslSocket::setSslConfiguration ().
返迴當前 SSL (安全套接字層) 配置。
另請參閱 setSslConfiguration ().
[signal]
void
QSslServer::
sslErrors
(
QSslSocket
*
socket
, const
QList
<
QSslError
> &
errors
)
QSslServer 發射此信號在 SSL 握手之後以指示當建立對等方標識時有發生一個或多個錯誤。錯誤通常指示 socket 無法安全地識彆對等方。除非采取任何行動,連接將被丟棄在此信號被發射之後。
If you want to continue connecting despite the errors that have occurred, you must call QSslSocket::ignoreSslErrors () from inside a slot connected to this signal. If you need to access the error list at a later point, you can call sslHandshakeErrors().
errors 包含一個或多個錯誤阻止 QSslSocket 驗證對等方身份。
注意: 不可以使用 Qt::QueuedConnection 當連接到此信號時,或調用 QSslSocket::ignoreSslErrors () 沒有起作用。
另請參閱 peerVerifyError ().
[signal]
void
QSslServer::
startedEncryptionHandshake
(
QSslSocket
*
socket
)
此信號發射,當客戶端連接到 socket ,初啓 TLS (傳輸層安全) 握手。