QtBase
v6.3.1
|
The QSslSocket class provides an SSL encrypted socket for both clients and servers. More...
#include <qsslsocket.h>
Public Slots | |
void | startClientEncryption () |
void | startServerEncryption () |
void | ignoreSslErrors () |
Public Slots inherited from QObject | |
void | deleteLater () |
Additional Inherited Members | |
Static Public Attributes inherited from QAbstractSocket | |
static constexpr auto | IPv4Protocol = QHostAddress::IPv4Protocol |
static constexpr auto | IPv6Protocol = QHostAddress::IPv6Protocol |
static constexpr auto | AnyIPProtocol = QHostAddress::AnyIPProtocol |
static constexpr auto | UnknownNetworkLayerProtocol = QHostAddress::UnknownNetworkLayerProtocol |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
Related Functions inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
\reentrant
\inmodule QtNetwork
QSslSocket establishes a secure, encrypted TCP connection you can use for transmitting encrypted data. It can operate in both client and server mode, and it supports modern TLS protocols, including TLS 1.3. By default, QSslSocket uses only TLS protocols which are considered to be secure (QSsl::SecureProtocols), but you can change the TLS protocol by calling setProtocol() as long as you do it before the handshake has started.
SSL encryption operates on top of the existing TCP stream after the socket enters the ConnectedState. There are two simple ways to establish a secure connection using QSslSocket: With an immediate SSL handshake, or with a delayed SSL handshake occurring after the connection has been established in unencrypted mode.
The most common way to use QSslSocket is to construct an object and start a secure connection by calling connectToHostEncrypted(). This method starts an immediate SSL handshake once the connection has been established.
As with a plain QTcpSocket, QSslSocket enters the HostLookupState, ConnectingState, and finally the ConnectedState, if the connection is successful. The handshake then starts automatically, and if it succeeds, the encrypted() signal is emitted to indicate the socket has entered the encrypted state and is ready for use.
Note that data can be written to the socket immediately after the return from connectToHostEncrypted() (i.e., before the encrypted() signal is emitted). The data is queued in QSslSocket until after the encrypted() signal is emitted.
An example of using the delayed SSL handshake to secure an existing connection is the case where an SSL server secures an incoming connection. Suppose you create an SSL server class as a subclass of QTcpServer. You would override QTcpServer::incomingConnection() with something like the example below, which first constructs an instance of QSslSocket and then calls setSocketDescriptor() to set the new socket's descriptor to the existing one passed in. It then initiates the SSL handshake by calling startServerEncryption().
If an error occurs, QSslSocket emits the sslErrors() signal. In this case, if no action is taken to ignore the error(s), the connection is dropped. To continue, despite the occurrence of an error, you can call ignoreSslErrors(), either from within this slot after the error occurs, or any time after construction of the QSslSocket and before the connection is attempted. This will allow QSslSocket to ignore the errors it encounters when establishing the identity of the peer. Ignoring errors during an SSL handshake should be used with caution, since a fundamental characteristic of secure connections is that they should be established with a successful handshake.
Once encrypted, you use QSslSocket as a regular QTcpSocket. When readyRead() is emitted, you can call read(), canReadLine() and readLine(), or getChar() to read decrypted data from QSslSocket's internal buffer, and you can call write() or putChar() to write data back to the peer. QSslSocket will automatically encrypt the written data for you, and emit encryptedBytesWritten() once the data has been written to the peer.
As a convenience, QSslSocket supports QTcpSocket's blocking functions waitForConnected(), waitForReadyRead(), waitForBytesWritten(), and waitForDisconnected(). It also provides waitForEncrypted(), which will block the calling thread until an encrypted connection has been established.
QSslSocket provides an extensive, easy-to-use API for handling cryptographic ciphers, private keys, and local, peer, and Certification Authority (CA) certificates. It also provides an API for handling errors that occur during the handshake phase.
The following features can also be customized:
\list
To extend the list of default CA certificates used by the SSL sockets during the SSL handshake you must update the default configuration, as in the snippet below:
For more information about ciphers and certificates, refer to QSslCipher and QSslCertificate.
This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (\l{http://www.openssl.org/}).
Definition at line 64 of file qsslsocket.h.
Describes the peer verification modes for QSslSocket. The default mode is AutoVerifyPeer, which selects an appropriate mode depending on the socket's QSocket::SslMode.
\value VerifyNone QSslSocket will not request a certificate from the peer. You can set this mode if you are not interested in the identity of the other side of the connection. The connection will still be encrypted, and your socket will still send its local certificate to the peer if it's requested.
\value QueryPeer QSslSocket will request a certificate from the peer, but does not require this certificate to be valid. This is useful when you want to display peer certificate details to the user without affecting the actual SSL handshake. This mode is the default for servers. Note: In Schannel this value acts the same as VerifyNone.
\value VerifyPeer QSslSocket will request a certificate from the peer during the SSL handshake phase, and requires that this certificate is valid. On failure, QSslSocket will emit the QSslSocket::sslErrors() signal. This mode is the default for clients.
\value AutoVerifyPeer QSslSocket will automatically use QueryPeer for server sockets and VerifyPeer for client sockets.
Enumerator | |
---|---|
VerifyNone | |
QueryPeer | |
VerifyPeer | |
AutoVerifyPeer |
Definition at line 75 of file qsslsocket.h.
enum QSslSocket::SslMode |
Describes the connection modes available for QSslSocket.
\value UnencryptedMode The socket is unencrypted. Its behavior is identical to QTcpSocket.
\value SslClientMode The socket is a client-side SSL socket. It is either already encrypted, or it is in the SSL handshake phase (see QSslSocket::isEncrypted()).
\value SslServerMode The socket is a server-side SSL socket. It is either already encrypted, or it is in the SSL handshake phase (see QSslSocket::isEncrypted()).
Enumerator | |
---|---|
UnencryptedMode | |
SslClientMode | |
SslServerMode |
Definition at line 69 of file qsslsocket.h.
Constructs a QSslSocket object. parent is passed to QObject's constructor. The new socket's \l {QSslCipher} {cipher} suite is set to the one returned by the static method defaultCiphers().
Definition at line 427 of file qsslsocket.cpp.
QSslSocket::~QSslSocket | ( | ) |
Destroys the QSslSocket.
Definition at line 441 of file qsslsocket.cpp.
|
static |
Definition at line 1580 of file qsslsocket.cpp.
|
signal |
QSslSocket emits this signal if an alert message was received from a peer. level tells if the alert was fatal or it was a warning. type is the code explaining why the alert was sent. When a textual description of the alert message is available, it is supplied in description.
|
signal |
QSslSocket emits this signal if an alert message was sent to a peer. level describes if it was a warning or a fatal error. type gives the code of the alert message. When a textual description of the alert message is available, it is supplied in description.
|
overridevirtual |
\reimp
Reimplemented from QIODevice.
Definition at line 919 of file qsslsocket.cpp.
Definition at line 1563 of file qsslsocket.cpp.
|
overridevirtual |
\reimp
Returns the number of decrypted bytes that are immediately available for reading.
Reimplemented from QAbstractSocket.
Definition at line 820 of file qsslsocket.cpp.
|
overridevirtual |
\reimp
Returns the number of unencrypted bytes that are waiting to be encrypted and written to the network.
Reimplemented from QAbstractSocket.
Definition at line 834 of file qsslsocket.cpp.
|
overridevirtual |
\reimp
Returns true
if you can read one while line (terminated by a single ASCII '\n' character) of decrypted characters; otherwise, false is returned.
Reimplemented from QIODevice.
Definition at line 877 of file qsslsocket.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractSocket.
Definition at line 888 of file qsslsocket.cpp.
void QAbstractSocket::connectToHost |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Attempts to make a connection to address on port port.
Definition at line 178 of file qabstractsocket.cpp.
void QAbstractSocket::connectToHost |
Attempts to make a connection to hostName on the given port. The protocol parameter can be used to specify which network protocol to use (eg. IPv4 or IPv6).
The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted and QAbstractSocket enters ConnectingState. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, QAbstractSocket enters ConnectedState and emits connected().
At any point, the socket can emit errorOccurred() to signal that an error occurred.
hostName may be an IP address in string form (e.g., "43.195.83.32"), or it may be a host name (e.g., "example.com"). QAbstractSocket will do a lookup only if required. port is in native byte order.
Definition at line 177 of file qabstractsocket.cpp.
|
overridevirtual |
Attempts to make a connection to hostName on the given port. The protocol parameter can be used to specify which network protocol to use (eg. IPv4 or IPv6).
The socket is opened in the given openMode and first enters HostLookupState, then performs a host name lookup of hostName. If the lookup succeeds, hostFound() is emitted and QAbstractSocket enters ConnectingState. It then attempts to connect to the address or addresses returned by the lookup. Finally, if a connection is established, QAbstractSocket enters ConnectedState and emits connected().
At any point, the socket can emit errorOccurred() to signal that an error occurred.
hostName may be an IP address in string form (e.g., "43.195.83.32"), or it may be a host name (e.g., "example.com"). QAbstractSocket will do a lookup only if required. port is in native byte order.
Reimplemented from QAbstractSocket.
Definition at line 1872 of file qsslsocket.cpp.
void QSslSocket::connectToHostEncrypted | ( | const QString & | hostName, |
quint16 | port, | ||
const QString & | sslPeerName, | ||
OpenMode | mode = ReadWrite , |
||
NetworkLayerProtocol | protocol = AnyIPProtocol |
||
) |
In addition to the original behaviour of connectToHostEncrypted, this overloaded method enables the usage of a different hostname (sslPeerName) for the certificate validation instead of the one used for the TCP connection (hostName).
Definition at line 551 of file qsslsocket.cpp.
void QSslSocket::connectToHostEncrypted | ( | const QString & | hostName, |
quint16 | port, | ||
OpenMode | mode = ReadWrite , |
||
NetworkLayerProtocol | protocol = AnyIPProtocol |
||
) |
Starts an encrypted connection to the device hostName on port, using mode as the \l OpenMode. This is equivalent to calling connectToHost() to establish the connection, followed by a call to startClientEncryption(). The protocol parameter can be used to specify which network protocol to use (eg. IPv4 or IPv6).
QSslSocket first enters the HostLookupState. Then, after entering either the event loop or one of the waitFor...() functions, it enters the ConnectingState, emits connected(), and then initiates the SSL client handshake. At each state change, QSslSocket emits signal stateChanged().
After initiating the SSL client handshake, if the identity of the peer can't be established, signal sslErrors() is emitted. If you want to ignore the errors and continue connecting, you must call ignoreSslErrors(), either from inside a slot function connected to the sslErrors() signal, or prior to entering encrypted mode. If ignoreSslErrors() is not called, the connection is dropped, signal disconnected() is emitted, and QSslSocket returns to the UnconnectedState.
If the SSL handshake is successful, QSslSocket emits encrypted().
The default for mode is \l ReadWrite.
If you want to create a QSslSocket on the server side of a connection, you should instead call startServerEncryption() upon receiving the incoming connection through QTcpServer.
Definition at line 513 of file qsslsocket.cpp.
void QSslSocket::continueInterruptedHandshake | ( | ) |
If an application wants to conclude a handshake even after receiving handshakeInterruptedOnError() signal, it must call this function. This call must be done from a slot function attached to the signal. The signal-slot connection must be direct.
Definition at line 1862 of file qsslsocket.cpp.
|
overridevirtual |
Attempts to close the socket. If there is pending data waiting to be written, QAbstractSocket will enter ClosingState and wait until all data has been written. Eventually, it will enter UnconnectedState and emit the disconnected() signal.
Reimplemented from QAbstractSocket.
Definition at line 1903 of file qsslsocket.cpp.
|
signal |
This signal is emitted when QSslSocket enters encrypted mode. After this signal has been emitted, QSslSocket::isEncrypted() will return true, and all further transmissions on the socket will be encrypted.
qint64 QSslSocket::encryptedBytesAvailable | ( | ) | const |
Returns the number of encrypted bytes that are awaiting decryption. Normally, this function will return 0 because QSslSocket decrypts its incoming data as soon as it can.
Definition at line 849 of file qsslsocket.cpp.
qint64 QSslSocket::encryptedBytesToWrite | ( | ) | const |
Returns the number of encrypted bytes that are waiting to be written to the network.
Definition at line 863 of file qsslsocket.cpp.
This signal is emitted when QSslSocket writes its encrypted data to the network. The written parameter contains the number of bytes that were successfully written.
QSslSocket emits this signal if a certificate verification error was found 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.
|
slot |
This slot tells QSslSocket to ignore errors during QSslSocket's handshake phase and continue connecting. If you want to continue with the connection even if errors occur during the handshake phase, then you must call this slot, either from a slot connected to sslErrors(), or before the handshake phase. If you don't call this slot, either in response to errors or before the handshake, the connection will be dropped after the sslErrors() signal has been emitted.
If there are no errors during the SSL handshake phase (i.e., the identity of the peer is established with no problems), QSslSocket will not emit the sslErrors() signal, and it is unnecessary to call this function.
Definition at line 1818 of file qsslsocket.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This method tells QSslSocket to ignore only the errors given in errors.
Multiple calls to this function will replace the list of errors that were passed in previous calls. You can clear the list of errors you want to ignore by calling this function with an empty list.
Definition at line 1845 of file qsslsocket.cpp.
|
static |
Definition at line 1664 of file qsslsocket.cpp.
|
static |
Definition at line 1677 of file qsslsocket.cpp.
bool QSslSocket::isEncrypted | ( | ) | const |
Returns true
if the socket is encrypted; otherwise, false is returned.
An encrypted socket encrypts all data that is written by calling write() or putChar() before the data is written to the network, and decrypts all incoming data as the data is received from the network, before you call read(), readLine() or getChar().
QSslSocket emits encrypted() when it enters encrypted mode.
You can call sessionCipher() to find which cryptographic cipher is used to encrypt and decrypt your data.
Definition at line 673 of file qsslsocket.cpp.
|
static |
Definition at line 1701 of file qsslsocket.cpp.
|
static |
Definition at line 1650 of file qsslsocket.cpp.
QSslCertificate QSslSocket::localCertificate | ( | ) | const |
Returns the socket's local \l {QSslCertificate} {certificate}, or an empty certificate if no local certificate has been assigned.
Definition at line 1090 of file qsslsocket.cpp.
QList< QSslCertificate > QSslSocket::localCertificateChain | ( | ) | const |
Returns the socket's local \l {QSslCertificate} {certificate} chain, or an empty list if no local certificates have been assigned.
Definition at line 1036 of file qsslsocket.cpp.
QSslSocket::SslMode QSslSocket::mode | ( | ) | const |
Returns the current mode for the socket; either UnencryptedMode, where QSslSocket behaves identially to QTcpSocket, or one of SslClientMode or SslServerMode, where the client is either negotiating or in encrypted mode.
When the mode changes, QSslSocket emits modeChanged()
Definition at line 652 of file qsslsocket.cpp.
|
signal |
This signal is emitted when QSslSocket changes from \l QSslSocket::UnencryptedMode to either \l QSslSocket::SslClientMode or \l QSslSocket::SslServerMode. mode is the new mode.
|
signal |
If TLS 1.3 protocol was negotiated during a handshake, QSslSocket emits this signal after receiving NewSessionTicket message. Session and session ticket's lifetime hint are updated in the socket's configuration. The session can be used for session resumption (and a shortened handshake) in future TLS connections.
QList< QOcspResponse > QSslSocket::ocspResponses | ( | ) | const |
This function returns Online Certificate Status Protocol responses that a server may send during a TLS handshake using OCSP stapling. The list is empty if no definitive response or no response at all was received.
Definition at line 1203 of file qsslsocket.cpp.
QSslCertificate QSslSocket::peerCertificate | ( | ) | const |
Returns the peer's digital certificate (i.e., the immediate certificate of the host you are connected to), or a null certificate, if the peer has not assigned a certificate.
The peer certificate is checked automatically during the handshake phase, so this function is normally used to fetch the certificate for display or for connection diagnostic purposes. It contains information about the peer, including its host name, the certificate issuer, and the peer's public key.
Because the peer certificate is set during the handshake phase, it is safe to access the peer certificate from a slot connected to the sslErrors() signal or the encrypted() signal.
If a null certificate is returned, it can mean the SSL handshake failed, or it can mean the host you are connected to doesn't have a certificate, or it can mean there is no connection.
If you want to check the peer's complete chain of certificates, use peerCertificateChain() to get them all at once.
Definition at line 1123 of file qsslsocket.cpp.
QList< QSslCertificate > QSslSocket::peerCertificateChain | ( | ) | const |
Returns the peer's chain of digital certificates, or an empty list of certificates.
Peer certificates are checked automatically during the handshake phase. This function is normally used to fetch certificates for display, or for performing connection diagnostics. Certificates contain information about the peer and the certificate issuers, including host name, issuer names, and issuer public keys.
The peer certificates are set in QSslSocket during the handshake phase, so it is safe to call this function from a slot connected to the sslErrors() signal or the encrypted() signal.
If an empty list is returned, it can mean the SSL handshake failed, or it can mean the host you are connected to doesn't have a certificate, or it can mean there is no connection.
If you want to get only the peer's immediate certificate, use peerCertificate().
Definition at line 1152 of file qsslsocket.cpp.
int QSslSocket::peerVerifyDepth | ( | ) | const |
Returns the maximum number of certificates in the peer's certificate chain to be checked during the SSL handshake phase, or 0 (the default) if no maximum depth has been set, indicating that the whole certificate chain should be checked.
The certificates are checked in issuing order, starting with the peer's own certificate, then its issuer's certificate, and so on.
Definition at line 757 of file qsslsocket.cpp.
QSslSocket can 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. The error is usually an indication that QSslSocket is 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, QSslSocket will proceed to emitting QSslSocket::sslErrors().
QSslSocket::PeerVerifyMode QSslSocket::peerVerifyMode | ( | ) | const |
Returns the socket's verify mode. This mode decides whether QSslSocket should request a certificate from the peer (i.e., the client requests a certificate from the server, or a server requesting a certificate from the client), and whether it should require that this certificate is valid.
The default mode is AutoVerifyPeer, which tells QSslSocket to use VerifyPeer for clients and QueryPeer for servers.
Definition at line 715 of file qsslsocket.cpp.
QString QSslSocket::peerVerifyName | ( | ) | const |
Returns the different hostname for the certificate validation, as set by setPeerVerifyName or by connectToHostEncrypted.
Definition at line 794 of file qsslsocket.cpp.
|
signal |
QSslSocket emits this signal when it negotiates a PSK ciphersuite, and therefore a PSK authentication is then required.
When using PSK, the client must send to the server 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 object according to their needs.
QSslKey QSslSocket::privateKey | ( | ) | const |
Returns this socket's private key.
Definition at line 1275 of file qsslsocket.cpp.
QSsl::SslProtocol QSslSocket::protocol | ( | ) | const |
Returns the socket's SSL protocol. By default, \l QSsl::SecureProtocols is used.
Definition at line 684 of file qsslsocket.cpp.
\reimp
Reimplemented from QAbstractSocket.
Definition at line 1947 of file qsslsocket.cpp.
|
overridevirtual |
\reimp
Continues data transfer on the socket after it has been paused. If "setPauseMode(QAbstractSocket::PauseOnSslErrors);" has been called on this socket and a sslErrors() signal is received, calling this method is necessary for the socket to continue.
Reimplemented from QAbstractSocket.
Definition at line 463 of file qsslsocket.cpp.
QSslCipher QSslSocket::sessionCipher | ( | ) | const |
Returns the socket's cryptographic \l {QSslCipher} {cipher}, or a null cipher if the connection isn't encrypted. The socket's cipher for the session is set during the handshake phase. The cipher is used to encrypt and decrypt data transmitted through the socket.
QSslSocket also provides functions for setting the ordered list of ciphers from which the handshake phase will eventually select the session cipher. This ordered list must be in place before the handshake phase begins.
Definition at line 1174 of file qsslsocket.cpp.
QSsl::SslProtocol QSslSocket::sessionProtocol | ( | ) | const |
Returns the socket's SSL/TLS protocol or UnknownProtocol if the connection isn't encrypted. The socket's protocol for the session is set during the handshake phase.
Definition at line 1188 of file qsslsocket.cpp.
Definition at line 1603 of file qsslsocket.cpp.
void QSslSocket::setLocalCertificate | ( | const QSslCertificate & | certificate | ) |
Sets the socket's local certificate to certificate. The local certificate is necessary if you need to confirm your identity to the peer. It is used together with the private key; if you set the local certificate, you must also set the private key.
The local certificate and private key are always necessary for server sockets, but are also rarely used by client sockets if the server requires the client to authenticate.
Definition at line 1061 of file qsslsocket.cpp.
void QSslSocket::setLocalCertificate | ( | const QString & | path, |
QSsl::EncodingFormat | format = QSsl::Pem |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the socket's local \l {QSslCertificate} {certificate} to the first one found in file path, which is parsed according to the specified format.
Definition at line 1075 of file qsslsocket.cpp.
void QSslSocket::setLocalCertificateChain | ( | const QList< QSslCertificate > & | localChain | ) |
Sets the certificate chain to be presented to the peer during the SSL handshake to be localChain.
Definition at line 1023 of file qsslsocket.cpp.
void QSslSocket::setPeerVerifyDepth | ( | int | depth | ) |
Sets the maximum number of certificates in the peer's certificate chain to be checked during the SSL handshake phase, to depth. Setting a depth of 0 means that no maximum depth is set, indicating that the whole certificate chain should be checked.
The certificates are checked in issuing order, starting with the peer's own certificate, then its issuer's certificate, and so on.
Definition at line 776 of file qsslsocket.cpp.
void QSslSocket::setPeerVerifyMode | ( | QSslSocket::PeerVerifyMode | mode | ) |
Sets the socket's verify mode to mode. This mode decides whether QSslSocket should request a certificate from the peer (i.e., the client requests a certificate from the server, or a server requesting a certificate from the client), and whether it should require that this certificate is valid.
The default mode is AutoVerifyPeer, which tells QSslSocket to use VerifyPeer for clients and QueryPeer for servers.
Setting this mode after encryption has started has no effect on the current connection.
Definition at line 738 of file qsslsocket.cpp.
Sets a different host name, given by hostName, for the certificate validation instead of the one used for the TCP connection.
Definition at line 808 of file qsslsocket.cpp.
Sets the socket's private \l {QSslKey} {key} to key. The private key and the local \l {QSslCertificate} {certificate} are used by clients and servers that must prove their identity to SSL peers.
Both the key and the local certificate are required if you are creating an SSL server socket. If you are creating an SSL client socket, the key and local certificate are required if your client must identify itself to an SSL server.
Definition at line 1224 of file qsslsocket.cpp.
void QSslSocket::setPrivateKey | ( | const QString & | fileName, |
QSsl::KeyAlgorithm | algorithm = QSsl::Rsa , |
||
QSsl::EncodingFormat | format = QSsl::Pem , |
||
const QByteArray & | passPhrase = QByteArray() |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Reads the string in file fileName and decodes it using a specified algorithm and encoding format to construct an \l {QSslKey} {SSL key}. If the encoded key is encrypted, passPhrase is used to decrypt it.
The socket's private key is set to the constructed key. The private key and the local \l {QSslCertificate} {certificate} are used by clients and servers that must prove their identity to SSL peers.
Both the key and the local certificate are required if you are creating an SSL server socket. If you are creating an SSL client socket, the key and local certificate are required if your client must identify itself to an SSL server.
Definition at line 1250 of file qsslsocket.cpp.
void QSslSocket::setProtocol | ( | QSsl::SslProtocol | protocol | ) |
Sets the socket's SSL protocol to protocol. This will affect the next initiated handshake; calling this function on an already-encrypted socket will not affect the socket's protocol.
Definition at line 695 of file qsslsocket.cpp.
Sets the size of QSslSocket's internal read buffer to be size bytes.
Reimplemented from QAbstractSocket.
Definition at line 932 of file qsslsocket.cpp.
|
overridevirtual |
Initializes QSslSocket with the native socket descriptor socketDescriptor. Returns true
if socketDescriptor is accepted as a valid socket descriptor; otherwise returns false
. The socket is opened in the mode specified by openMode, and enters the socket state specified by state.
Reimplemented from QAbstractSocket.
Definition at line 590 of file qsslsocket.cpp.
|
overridevirtual |
Reimplemented from QAbstractSocket.
Definition at line 620 of file qsslsocket.cpp.
void QSslSocket::setSslConfiguration | ( | const QSslConfiguration & | configuration | ) |
Sets the socket's SSL configuration to be the contents of configuration. This function sets the local certificate, the ciphers, the private key and the CA certificates to those stored in configuration.
It is not possible to set the SSL-state related fields.
Definition at line 980 of file qsslsocket.cpp.
|
overridevirtual |
Reimplemented from QAbstractSocket.
Definition at line 633 of file qsslsocket.cpp.
QSslConfiguration QSslSocket::sslConfiguration | ( | ) | const |
Returns the socket's SSL configuration state. The default SSL configuration of a socket is to use the default ciphers, default CA certificates, no local private key or certificate.
The SSL configuration also contains fields that can change with time without notice.
Definition at line 955 of file qsslsocket.cpp.
QSslSocket emits 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 that QSslSocket is 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 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 contains one or more errors that prevent QSslSocket from verifying the identity of the peer.
Returns a list of the last SSL errors that occurred. This is the same list as QSslSocket passes via the sslErrors() signal. If the connection has been encrypted with no errors, this function will return an empty list.
Definition at line 1480 of file qsslsocket.cpp.
|
static |
Definition at line 1532 of file qsslsocket.cpp.
|
static |
Definition at line 1547 of file qsslsocket.cpp.
|
static |
Definition at line 1504 of file qsslsocket.cpp.
|
static |
Definition at line 1518 of file qsslsocket.cpp.
|
slot |
Starts a delayed SSL handshake for a client connection. This function can be called when the socket is in the \l ConnectedState but still in the \l UnencryptedMode. If it is not yet connected, or if it is already encrypted, this function has no effect.
Clients that implement STARTTLS functionality often make use of delayed SSL handshakes. Most other clients can avoid calling this function directly by using connectToHostEncrypted() instead, which automatically performs the handshake.
Definition at line 1719 of file qsslsocket.cpp.
|
slot |
Starts a delayed SSL handshake for a server connection. This function can be called when the socket is in the \l ConnectedState but still in \l UnencryptedMode. If it is not connected or it is already encrypted, the function has no effect.
For server sockets, calling this function is the only way to initiate the SSL handshake. Most servers will call this function immediately upon receiving a connection, or as a result of having received a protocol-specific command to enter SSL mode (e.g, the server may respond to receiving the string "STARTTLS\\r\\n" by calling this function).
The most common way to implement an SSL server is to create a subclass of QTcpServer and reimplement QTcpServer::incomingConnection(). The returned socket descriptor is then passed to QSslSocket::setSocketDescriptor().
Definition at line 1770 of file qsslsocket.cpp.
|
static |
Definition at line 1689 of file qsslsocket.cpp.
|
static |
Definition at line 1638 of file qsslsocket.cpp.
|
static |
Returns true
if this platform supports SSL; otherwise, returns false. If the platform doesn't support SSL, the socket will fail in the connection phase.
Definition at line 1493 of file qsslsocket.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractSocket.
Definition at line 1396 of file qsslsocket.cpp.
|
overridevirtual |
Waits until the socket is connected, or msecs milliseconds, whichever happens first. If the connection has been established, this function returns true
; otherwise it returns false
.
Reimplemented from QAbstractSocket.
Definition at line 1288 of file qsslsocket.cpp.
|
overridevirtual |
Waits until the socket has disconnected or msecs milliseconds, whichever comes first. If the connection has been disconnected, this function returns true
; otherwise it returns false
.
Reimplemented from QAbstractSocket.
Definition at line 1427 of file qsslsocket.cpp.
bool QSslSocket::waitForEncrypted | ( | int | msecs = 30000 | ) |
Waits until the socket has completed the SSL handshake and has emitted encrypted(), or msecs milliseconds, whichever comes first. If encrypted() has been emitted, this function returns true; otherwise (e.g., the socket is disconnected, or the SSL handshake fails), false is returned.
The following example waits up to one second for the socket to be encrypted:
If msecs is -1, this function will not time out.
Definition at line 1317 of file qsslsocket.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractSocket.
Definition at line 1351 of file qsslsocket.cpp.
\reimp
Reimplemented from QAbstractSocket.
Definition at line 1972 of file qsslsocket.cpp.