Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsslconfiguration.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2014 BlackBerry Limited. All rights reserved.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6/****************************************************************************
7**
8** In addition, as a special exception, the copyright holders listed above give
9** permission to link the code of its release of Qt with the OpenSSL project's
10** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the
11** same license as the original version), and distribute the linked executables.
12**
13** You must comply with the GNU General Public License version 2 in all
14** respects for all of the code used other than the "OpenSSL" code. If you
15** modify this file, you may extend this exception to your version of the file,
16** but you are not obligated to do so. If you do not wish to do so, delete
17** this exception statement from your version of this file.
18**
19****************************************************************************/
20
21#ifndef QSSLCONFIGURATION_H
22#define QSSLCONFIGURATION_H
23
24#include <QtNetwork/qtnetworkglobal.h>
25#include <QtCore/qmap.h>
26#include <QtCore/qshareddata.h>
27#include <QtNetwork/qsslsocket.h>
28#include <QtNetwork/qssl.h>
29
30#include <optional>
31
32#ifndef QT_NO_SSL
33
34QT_BEGIN_NAMESPACE
35
36class QSslCertificate;
37class QSslCipher;
38class QSslKey;
41class QSslDiffieHellmanParameters;
42
43class QSslConfigurationPrivate;
44class Q_NETWORK_EXPORT QSslConfiguration
45{
46public:
47 QSslConfiguration();
48 QSslConfiguration(const QSslConfiguration &other);
49 ~QSslConfiguration();
50 QSslConfiguration &operator=(QSslConfiguration &&other) noexcept { swap(other); return *this; }
51 QSslConfiguration &operator=(const QSslConfiguration &other);
52
53 void swap(QSslConfiguration &other) noexcept
54 { d.swap(other.d); }
55
56 bool operator==(const QSslConfiguration &other) const;
57 inline bool operator!=(const QSslConfiguration &other) const
58 { return !(*this == other); }
59
60 bool isNull() const;
61
62 QSsl::SslProtocol protocol() const;
63 void setProtocol(QSsl::SslProtocol protocol);
64
65 // Verification
66 QSslSocket::PeerVerifyMode peerVerifyMode() const;
67 void setPeerVerifyMode(QSslSocket::PeerVerifyMode mode);
68
69 int peerVerifyDepth() const;
70 void setPeerVerifyDepth(int depth);
71
72 // Certificate & cipher configuration
73 QList<QSslCertificate> localCertificateChain() const;
74 void setLocalCertificateChain(const QList<QSslCertificate> &localChain);
75
76 QSslCertificate localCertificate() const;
77 void setLocalCertificate(const QSslCertificate &certificate);
78
79 QSslCertificate peerCertificate() const;
80 QList<QSslCertificate> peerCertificateChain() const;
81 QSslCipher sessionCipher() const;
82 QSsl::SslProtocol sessionProtocol() const;
83
84 // Private keys, for server sockets
85 QSslKey privateKey() const;
86 void setPrivateKey(const QSslKey &key);
87
88 // Cipher settings
89 QList<QSslCipher> ciphers() const;
90 void setCiphers(const QList<QSslCipher> &ciphers);
91 void setCiphers(const QString &ciphers);
92 static QList<QSslCipher> supportedCiphers();
93
94 // Certificate Authority (CA) settings
95 QList<QSslCertificate> caCertificates() const;
96 void setCaCertificates(const QList<QSslCertificate> &certificates);
97 bool addCaCertificates(
98 const QString &path, QSsl::EncodingFormat format = QSsl::Pem,
99 QSslCertificate::PatternSyntax syntax = QSslCertificate::PatternSyntax::FixedString);
100 void addCaCertificate(const QSslCertificate &certificate);
101 void addCaCertificates(const QList<QSslCertificate> &certificates);
102
103 static QList<QSslCertificate> systemCaCertificates();
104
105 void setSslOption(QSsl::SslOption option, bool on);
106 bool testSslOption(QSsl::SslOption option) const;
107
108 QByteArray sessionTicket() const;
109 void setSessionTicket(const QByteArray &sessionTicket);
110 int sessionTicketLifeTimeHint() const;
111
112 QSslKey ephemeralServerKey() const;
113
114 // EC settings
115 QList<QSslEllipticCurve> ellipticCurves() const;
116 void setEllipticCurves(const QList<QSslEllipticCurve> &curves);
117 static QList<QSslEllipticCurve> supportedEllipticCurves();
118
119 QByteArray preSharedKeyIdentityHint() const;
120 void setPreSharedKeyIdentityHint(const QByteArray &hint);
121
122 QSslDiffieHellmanParameters diffieHellmanParameters() const;
123 void setDiffieHellmanParameters(const QSslDiffieHellmanParameters &dhparams);
124
125 QMap<QByteArray, QVariant> backendConfiguration() const;
126 void setBackendConfigurationOption(const QByteArray &name, const QVariant &value);
127 void setBackendConfiguration(const QMap<QByteArray, QVariant> &backendConfiguration = QMap<QByteArray, QVariant>());
128
129 static QSslConfiguration defaultConfiguration();
130 static void setDefaultConfiguration(const QSslConfiguration &configuration);
131
132#if QT_CONFIG(dtls) || defined(Q_QDOC)
133 bool dtlsCookieVerificationEnabled() const;
134 void setDtlsCookieVerificationEnabled(bool enable);
135
136 static QSslConfiguration defaultDtlsConfiguration();
137 static void setDefaultDtlsConfiguration(const QSslConfiguration &configuration);
138#endif // dtls
139
140 bool handshakeMustInterruptOnError() const;
141 void setHandshakeMustInterruptOnError(bool interrupt);
142
143 bool missingCertificateIsFatal() const;
144 void setMissingCertificateIsFatal(bool cannotRecover);
145
146 void setOcspStaplingEnabled(bool enable);
147 bool ocspStaplingEnabled() const;
148
149 enum NextProtocolNegotiationStatus {
150 NextProtocolNegotiationNone,
151 NextProtocolNegotiationNegotiated,
152 NextProtocolNegotiationUnsupported
153 };
154
155 void setAllowedNextProtocols(const QList<QByteArray> &protocols);
156 QList<QByteArray> allowedNextProtocols() const;
157
158 QByteArray nextNegotiatedProtocol() const;
159 NextProtocolNegotiationStatus nextProtocolNegotiationStatus() const;
160
161 static const char ALPNProtocolHTTP2[];
162 static const char NextProtocolHttp1_1[];
163
164 QList<QSslKeyingMaterial> keyingMaterial() const;
165 std::optional<QSslKeyingMaterial> keyingMaterial(const QSslKeyingMaterial &material) const;
166 void setKeyingMaterial(const QList<QSslKeyingMaterial> &keyMaterial);
167
168private:
169 friend class QSslSocket;
170 friend class QSslConfigurationPrivate;
171 friend class QSslContext;
172 friend class QTlsBackend;
173 QSslConfiguration(QSslConfigurationPrivate *dd);
174 QSharedDataPointer<QSslConfigurationPrivate> d;
175};
176
178
179QT_END_NAMESPACE
180
181QT_DECL_METATYPE_EXTERN(QSslConfiguration, Q_NETWORK_EXPORT)
182
183#endif // QT_NO_SSL
184
185#endif
QByteArray rawHeader(QAnyStringView headerName) const
QList< QNetworkCookie > NetworkCookieList
void setCookedHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
QList< QByteArray > rawHeadersKeys() const
QHttpHeaders headers() const
void setHeaders(QHttpHeaders &&newHeaders)
void setHeaders(const QHttpHeaders &newHeaders)
const RawHeadersList & allRawHeaders() const
void setHeader(QHttpHeaders::WellKnownHeader name, QByteArrayView value)
QList< RawHeaderPair > RawHeadersList
CookedHeadersMap cookedHeaders
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The QSslConfiguration class holds the configuration and state of an SSL connection.
Represents an elliptic curve for use by elliptic-curve cipher algorithms.
Describes exported keying material derived from a TLS session.
Combined button and popup list for selecting options.
static int name_to_month(const char *month_str)
static QStringList parseMatchImpl(QByteArrayView raw, T op)
static bool isSetCookie(QByteArrayView name)
static QList< QNetworkCookie > parseCookieHeader(QByteArrayView raw)
static int parseHeaderName(QByteArrayView headerName)
static std::optional< QNetworkRequest::KnownHeaders > toKnownHeader(QHttpHeaders::WellKnownHeader key)
static QVariant parseETag(QByteArrayView raw)
static QVariant parseHeaderValue(QNetworkRequest::KnownHeaders header, QByteArrayView value)
static QVariant parseHttpDate(QByteArrayView raw)
static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVariant &value)
static QByteArray makeCookieHeader(const QList< QNetworkCookie > &cookies, QNetworkCookie::RawForm type, QByteArrayView separator)
static QStringList parseIfMatch(QByteArrayView raw)
static QStringList parseIfNoneMatch(QByteArrayView raw)
static void setFromRawHeader(QHttpHeaders &headers, HeaderName header, QByteArrayView value)
static std::optional< QHttpHeaders::WellKnownHeader > toWellKnownHeader(QNetworkRequest::KnownHeaders key)
static constexpr HeaderPair knownHeadersArr[]