PySide6.QtNetwork.QSslServer¶
- class QSslServer¶
Implements an encrypted, secure TCP server over TLS.
Details
Class to use in place of
QTcpServerto implement TCP server using Transport Layer Security (TLS).To configure the secure handshake settings, use the applicable setter functions on a
QSslConfigurationobject, and then use it as an argument to thesetSslConfiguration()function. All following incoming connections handled will use these settings.To start listening to incoming connections use the
listen()function inherited fromQTcpServer. Other settings can be configured by using the setter functions inherited from theQTcpServerclass.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 thenextPendingConnection()function to fetch the next incoming connection and take it out of the pending connection queue. TheQSslSocketis a child of theQSslServerand will be deleted when theQSslServeris deleted. It is still a good idea to destroy the object explicitly when you are done with it, to avoid wasting memory.See also
Added in version 6.4.
Synopsis¶
Methods¶
def
__init__()
Signals¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Constructs a new
QSslServerwith the givenparent.- alertReceived(socket, level, type, description)¶
- Parameters:
socket –
QSslSocketlevel –
AlertLeveltype –
AlertTypedescription – str
QSslServeremits this signal if an alert message was received by thesocketfrom a peer.leveltells if the alert was fatal or it was a warning.typeis the code explaining why the alert was sent. When a textual description of the alert message is available, it is supplied indescription.Note
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(socket, level, type, description)¶
- Parameters:
socket –
QSslSocketlevel –
AlertLeveltype –
AlertTypedescription – str
QSslServeremits this signal if an alert message was sent fromsocketto a peer.leveldescribes if it was a warning or a fatal error.typegives the code of the alert message. When a textual description of the alert message is available, it is supplied indescription.Note
This signal is mostly informational and can be used for debugging purposes, normally it does not require any actions from the application.
- errorOccurred(socket, error)¶
- Parameters:
socket –
QSslSocketerror –
SocketError
This signal is emitted after an error occurred during handshake. The
socketErrorparameter describes the type of error that occurred.The
socketis automatically deleted after this signal is emitted if the socket handshake has not reached encrypted state. But if thesocketis successfully encrypted, it is inserted into theQSslServer‘s pending connections queue. When the user has callednextPendingConnection()it is the user’s responsibility to destroy thesocketor thesocketwill not be destroyed until theQSslServerobject is destroyed. If an error occurs on asocketafter it has been inserted into the pending connections queue, this signal will not be emitted, and thesocketwill not be removed or destroyed.Note
You cannot use Qt::QueuedConnection when connecting to this signal, or the
socketwill have been already destroyed when the signal is handled.See also
error()errorString()- handshakeInterruptedOnError(socket, error)¶
- Parameters:
socket –
QSslSocketerror –
QSslError
QSslServeremits this signal if a certificate verification error was found bysocketand if early error reporting was enabled inQSslConfiguration. An application is expected to inspect theerrorand 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.- handshakeTimeout()¶
- Return type:
int
Returns the currently configured handshake timeout.
See also
- peerVerifyError(socket, error)¶
- Parameters:
socket –
QSslSocketerror –
QSslError
QSslServercan emit this signal several times during the SSL handshake, before encryption has been established, to indicate that an error has occurred while establishing the identity of the peer. Theerroris usually an indication thatsocketis unable to securely identify the peer.This signal provides you with an early indication when something’s wrong. By connecting to this signal, you can manually choose to tear down the connection from inside the connected slot before the handshake has completed. If no action is taken,
QSslServerwill proceed to emittingsslErrors().See also
- Parameters:
socket –
QSslSocketauthenticator –
QSslPreSharedKeyAuthenticator
QSslServeremits this signal whensocketnegotiates 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
authenticatorobject according to their needs.Note
Ignoring this signal, or failing to provide the required credentials, will cause the handshake to fail, and therefore the connection to be aborted.
Note
The
authenticatorobject is owned by thesocketand must not be deleted by the application.See also
- setHandshakeTimeout(timeout)¶
- Parameters:
timeout – int
Sets the
timeoutto 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.
QSslServerwill then automatically end the connection aftertimeoutmilliseconds have elapsed.By default the timeout is 5000 milliseconds (5 seconds).
Note
The underlying TLS framework may have their own timeout logic now or in the future, this function does not affect that.
Note
The
timeoutpassed 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.See also
- setSslConfiguration(sslConfiguration)¶
- Parameters:
sslConfiguration –
QSslConfiguration
Sets the
sslConfigurationto use for all following incoming connections.This must be called before
listen()to ensure that the desired configuration was in use during all handshakes.See also
- sslConfiguration()¶
- Return type:
Returns the current ssl configuration.
See also
- sslErrors(socket, errors)¶
- Parameters:
socket –
QSslSocketerrors – .list of QSslError
QSslServeremits this signal after the SSL handshake to indicate that one or more errors have occurred while establishing the identity of the peer. The errors are usually an indication thatsocketis unable to securely identify the peer. Unless any action is taken, the connection will be dropped after this signal has been emitted.If you want to continue connecting despite the errors that have occurred, you must call
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().errorscontains one or more errors that preventQSslSocketfrom verifying the identity of the peer.Note
You cannot use Qt::QueuedConnection when connecting to this signal, or calling
ignoreSslErrors()will have no effect.See also
- startedEncryptionHandshake(socket)¶
- Parameters:
socket –
QSslSocket
This signal is emitted when the client, connected to
socket, initiates the TLS handshake.