Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsslsocket.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5#ifndef QSSLSOCKET_H
6#define QSSLSOCKET_H
7
8#include <QtNetwork/qtnetworkglobal.h>
9#include <QtCore/qlist.h>
10#ifndef QT_NO_SSL
11# include <QtNetwork/qtcpsocket.h>
12# include <QtNetwork/qsslerror.h>
13#endif
14
16
17
18#ifndef QT_NO_SSL
19
20class QDir;
21class QSslCipher;
22class QSslCertificate;
25class QOcspResponse;
26
28class Q_NETWORK_EXPORT QSslSocket : public QTcpSocket
29{
31 Q_MOC_INCLUDE(<QtNetwork/qsslpresharedkeyauthenticator.h>)
32public:
33 enum SslMode {
36 SslServerMode
37 };
38 Q_ENUM(SslMode)
39
46 Q_ENUM(PeerVerifyMode)
47
48 explicit QSslSocket(QObject *parent = nullptr);
50 void resume() override; // to continue after proxy authentication required, SSL errors etc.
51
52 // Autostarting the SSL client handshake.
53 void connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);
54 void connectToHostEncrypted(const QString &hostName, quint16 port, const QString &sslPeerName, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);
55 bool setSocketDescriptor(qintptr socketDescriptor, SocketState state = ConnectedState,
56 OpenMode openMode = ReadWrite) override;
57
59 void connectToHost(const QString &hostName, quint16 port, OpenMode openMode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol) override;
60 void disconnectFromHost() override;
61
62 virtual void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value) override;
63 virtual QVariant socketOption(QAbstractSocket::SocketOption option) override;
64
65 SslMode mode() const;
66 bool isEncrypted() const;
67
68 QSsl::SslProtocol protocol() const;
69 void setProtocol(QSsl::SslProtocol protocol);
70
71 QSslSocket::PeerVerifyMode peerVerifyMode() const;
72 void setPeerVerifyMode(QSslSocket::PeerVerifyMode mode);
73
74 int peerVerifyDepth() const;
75 void setPeerVerifyDepth(int depth);
76
77 QString peerVerifyName() const;
78 void setPeerVerifyName(const QString &hostName);
79
80 // From QIODevice
81 qint64 bytesAvailable() const override;
82 qint64 bytesToWrite() const override;
83 bool canReadLine() const override;
84 void close() override;
85 bool atEnd() const override;
86
87 // From QAbstractSocket:
88 void setReadBufferSize(qint64 size) override;
89
90 // Similar to QIODevice's:
91 qint64 encryptedBytesAvailable() const;
92 qint64 encryptedBytesToWrite() const;
93
94 // SSL configuration
95 QSslConfiguration sslConfiguration() const;
97
98 // Certificate & cipher accessors.
99 void setLocalCertificateChain(const QList<QSslCertificate> &localChain);
100 QList<QSslCertificate> localCertificateChain() const;
101
102 void setLocalCertificate(const QSslCertificate &certificate);
103 void setLocalCertificate(const QString &fileName, QSsl::EncodingFormat format = QSsl::Pem);
104 QSslCertificate localCertificate() const;
105 QSslCertificate peerCertificate() const;
106 QList<QSslCertificate> peerCertificateChain() const;
107 QSslCipher sessionCipher() const;
108 QSsl::SslProtocol sessionProtocol() const;
109 QList<QOcspResponse> ocspResponses() const;
110
111 // Private keys, for server sockets.
112 void setPrivateKey(const QSslKey &key);
113 void setPrivateKey(const QString &fileName, QSsl::KeyAlgorithm algorithm = QSsl::Rsa,
115 const QByteArray &passPhrase = QByteArray());
116 QSslKey privateKey() const;
117
118 bool waitForConnected(int msecs = 30000) override;
119 bool waitForEncrypted(int msecs = 30000);
120 bool waitForReadyRead(int msecs = 30000) override;
121 bool waitForBytesWritten(int msecs = 30000) override;
122 bool waitForDisconnected(int msecs = 30000) override;
123
124 QList<QSslError> sslHandshakeErrors() const;
125
126 static bool supportsSsl();
127 static long sslLibraryVersionNumber();
128 static QString sslLibraryVersionString();
129 static long sslLibraryBuildVersionNumber();
130 static QString sslLibraryBuildVersionString();
131
132 static QList<QString> availableBackends();
133 static QString activeBackend();
134 static bool setActiveBackend(const QString &backendName);
135 static QList<QSsl::SslProtocol> supportedProtocols(const QString &backendName = {});
136 static bool isProtocolSupported(QSsl::SslProtocol protocol, const QString &backendName = {});
137 static QList<QSsl::ImplementedClass> implementedClasses(const QString &backendName = {});
138 static bool isClassImplemented(QSsl::ImplementedClass cl, const QString &backendName = {});
139 static QList<QSsl::SupportedFeature> supportedFeatures(const QString &backendName = {});
140 static bool isFeatureSupported(QSsl::SupportedFeature feat, const QString &backendName = {});
141
142 void ignoreSslErrors(const QList<QSslError> &errors);
143 void continueInterruptedHandshake();
144
145public Q_SLOTS:
146 void startClientEncryption();
147 void startServerEncryption();
148 void ignoreSslErrors();
149
151 void encrypted();
153 void sslErrors(const QList<QSslError> &errors);
161
162protected:
163 qint64 readData(char *data, qint64 maxlen) override;
164 qint64 skipData(qint64 maxSize) override;
165 qint64 writeData(const char *data, qint64 len) override;
166
167private:
168 Q_DECLARE_PRIVATE(QSslSocket)
169 Q_DISABLE_COPY_MOVE(QSslSocket)
170
171 Q_PRIVATE_SLOT(d_func(), void _q_connectedSlot())
172 Q_PRIVATE_SLOT(d_func(), void _q_hostFoundSlot())
173 Q_PRIVATE_SLOT(d_func(), void _q_disconnectedSlot())
174 Q_PRIVATE_SLOT(d_func(), void _q_stateChangedSlot(QAbstractSocket::SocketState))
175 Q_PRIVATE_SLOT(d_func(), void _q_errorSlot(QAbstractSocket::SocketError))
176 Q_PRIVATE_SLOT(d_func(), void _q_readyReadSlot())
177 Q_PRIVATE_SLOT(d_func(), void _q_channelReadyReadSlot(int))
178 Q_PRIVATE_SLOT(d_func(), void _q_bytesWrittenSlot(qint64))
179 Q_PRIVATE_SLOT(d_func(), void _q_channelBytesWrittenSlot(int, qint64))
180 Q_PRIVATE_SLOT(d_func(), void _q_readChannelFinishedSlot())
181 Q_PRIVATE_SLOT(d_func(), void _q_flushWriteBuffer())
182 Q_PRIVATE_SLOT(d_func(), void _q_flushReadBuffer())
183 Q_PRIVATE_SLOT(d_func(), void _q_resumeImplementation())
184};
185
186#endif // QT_NO_SSL
187
189
190#endif
The QAbstractSocket class provides the base functionality common to all socket types.
SocketState
This enum describes the different states in which a socket can be.
SocketError
This enum describes the socket errors that can occur.
virtual void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite, NetworkLayerProtocol protocol=AnyIPProtocol)
Attempts to make a connection to hostName on the given port.
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qdir.h:20
\inmodule QtCore
Definition qobject.h:103
This class represents Online Certificate Status Protocol response.
The QSslCertificate class provides a convenient API for an X509 certificate.
The QSslCipher class represents an SSL cryptographic cipher.
Definition qsslcipher.h:22
The QSslConfiguration class holds the configuration and state of an SSL connection.
The QSslError class provides an SSL error.
Definition qsslerror.h:21
The QSslKey class provides an interface for private and public keys.
Definition qsslkey.h:23
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition qsslsocket.h:29
void sslErrors(const QList< QSslError > &errors)
QSslSocket emits this signal after the SSL handshake to indicate that one or more errors have occurre...
void encryptedBytesWritten(qint64 totalBytes)
void alertSent(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description)
QSslSocket emits this signal if an alert message was sent to a peer.
void peerVerifyError(const QSslError &error)
SslMode
Describes the connection modes available for QSslSocket.
Definition qsslsocket.h:33
@ UnencryptedMode
Definition qsslsocket.h:34
void newSessionTicketReceived()
void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator)
void encrypted()
This signal is emitted when QSslSocket enters encrypted mode.
void alertReceived(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description)
QSslSocket emits this signal if an alert message was received from a peer.
void handshakeInterruptedOnError(const QSslError &error)
QSslSocket emits this signal if a certificate verification error was found and if early error reporti...
void modeChanged(QSslSocket::SslMode newMode)
This signal is emitted when QSslSocket changes from \l QSslSocket::UnencryptedMode to either \l QSslS...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTcpSocket class provides a TCP socket.
Definition qtcpsocket.h:18
\inmodule QtCore
Definition qvariant.h:65
else opt state
[0]
SupportedFeature
Enumerates possible features that a TLS backend supports.
Definition qssl.h:144
ImplementedClass
Enumerates classes that a TLS backend implements.
Definition qssl.h:132
AlertLevel
Describes the level of an alert message.
Definition qssl.h:86
KeyAlgorithm
Describes the different key algorithms supported by QSslKey.
Definition qssl.h:34
@ Rsa
Definition qssl.h:36
EncodingFormat
Describes supported encoding formats for certificates and keys.
Definition qssl.h:28
@ Pem
Definition qssl.h:29
AlertType
Enumerates possible codes that an alert message can have.
Definition qssl.h:93
SslProtocol
Describes the protocol of the cipher.
Definition qssl.h:50
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLConfig config
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputPortEXT port
static QString backendName
static bool isEncrypted(const my_mach_header *header)
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum mode
GLenum GLuint GLint level
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLint GLsizei GLsizei GLenum format
GLuint GLenum option
GLenum GLsizei len
#define Q_ENUM(x)
#define Q_OBJECT
#define Q_SLOTS
#define Q_MOC_INCLUDE(...)
#define Q_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
unsigned short quint16
Definition qtypes.h:48
long long qint64
Definition qtypes.h:60
ptrdiff_t qintptr
Definition qtypes.h:166
future resume()
sock connectToHost(url.host(), url.port(80))
device waitForReadyRead(deadline)
void writeData(const QByteArray &data)
QByteArray readData()
reply ignoreSslErrors(expectedSslErrors)
socket disconnectFromHost()
[0]
config setProtocol(QSsl::TlsV1_2)
sslSocket setSslConfiguration(config)
socket connectToHostEncrypted("imap.example.com", 993)