1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtNetwork module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41/****************************************************************************
42**
43** In addition, as a special exception, the copyright holders listed above give
44** permission to link the code of its release of Qt with the OpenSSL project's
45** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the
46** same license as the original version), and distribute the linked executables.
47**
48** You must comply with the GNU General Public License version 2 in all
49** respects for all of the code used other than the "OpenSSL" code. If you
50** modify this file, you may extend this exception to your version of the file,
51** but you are not obligated to do so. If you do not wish to do so, delete
52** this exception statement from your version of this file.
53**
54****************************************************************************/
55
56#ifndef QSSLCONFIGURATION_H
57#define QSSLCONFIGURATION_H
58
59#include <QtNetwork/qtnetworkglobal.h>
60#include <QtCore/qmap.h>
61#include <QtCore/qshareddata.h>
62#include <QtNetwork/qsslsocket.h>
63#include <QtNetwork/qssl.h>
64
65#ifndef QT_NO_SSL
66
67QT_BEGIN_NAMESPACE
68
69class QSslCertificate;
70class QSslCipher;
71class QSslKey;
72class QSslEllipticCurve;
73class QSslDiffieHellmanParameters;
74
75namespace dtlsopenssl
76{
77class DtlsState;
78}
79
80class QSslConfigurationPrivate;
81class Q_NETWORK_EXPORT QSslConfiguration
82{
83public:
84 QSslConfiguration();
85 QSslConfiguration(const QSslConfiguration &other);
86 ~QSslConfiguration();
87 QSslConfiguration &operator=(QSslConfiguration &&other) noexcept { swap(other); return *this; }
88 QSslConfiguration &operator=(const QSslConfiguration &other);
89
90 void swap(QSslConfiguration &other) noexcept
91 { qSwap(d, other.d); }
92
93 bool operator==(const QSslConfiguration &other) const;
94 inline bool operator!=(const QSslConfiguration &other) const
95 { return !(*this == other); }
96
97 bool isNull() const;
98
99 QSsl::SslProtocol protocol() const;
100 void setProtocol(QSsl::SslProtocol protocol);
101
102 // Verification
103 QSslSocket::PeerVerifyMode peerVerifyMode() const;
104 void setPeerVerifyMode(QSslSocket::PeerVerifyMode mode);
105
106 int peerVerifyDepth() const;
107 void setPeerVerifyDepth(int depth);
108
109 // Certificate & cipher configuration
110 QList<QSslCertificate> localCertificateChain() const;
111 void setLocalCertificateChain(const QList<QSslCertificate> &localChain);
112
113 QSslCertificate localCertificate() const;
114 void setLocalCertificate(const QSslCertificate &certificate);
115
116 QSslCertificate peerCertificate() const;
117 QList<QSslCertificate> peerCertificateChain() const;
118 QSslCipher sessionCipher() const;
119 QSsl::SslProtocol sessionProtocol() const;
120
121 // Private keys, for server sockets
122 QSslKey privateKey() const;
123 void setPrivateKey(const QSslKey &key);
124
125 // Cipher settings
126 QList<QSslCipher> ciphers() const;
127 void setCiphers(const QList<QSslCipher> &ciphers);
128 void setCiphers(const QString &ciphers);
129 static QList<QSslCipher> supportedCiphers();
130
131 // Certificate Authority (CA) settings
132 QList<QSslCertificate> caCertificates() const;
133 void setCaCertificates(const QList<QSslCertificate> &certificates);
134 bool addCaCertificates(
135 const QString &path, QSsl::EncodingFormat format = QSsl::Pem,
136 QSslCertificate::PatternSyntax syntax = QSslCertificate::PatternSyntax::FixedString);
137 void addCaCertificate(const QSslCertificate &certificate);
138 void addCaCertificates(const QList<QSslCertificate> &certificates);
139
140 static QList<QSslCertificate> systemCaCertificates();
141
142 void setSslOption(QSsl::SslOption option, bool on);
143 bool testSslOption(QSsl::SslOption option) const;
144
145 QByteArray sessionTicket() const;
146 void setSessionTicket(const QByteArray &sessionTicket);
147 int sessionTicketLifeTimeHint() const;
148
149 QSslKey ephemeralServerKey() const;
150
151 // EC settings
152 QList<QSslEllipticCurve> ellipticCurves() const;
153 void setEllipticCurves(const QList<QSslEllipticCurve> &curves);
154 static QList<QSslEllipticCurve> supportedEllipticCurves();
155
156 QByteArray preSharedKeyIdentityHint() const;
157 void setPreSharedKeyIdentityHint(const QByteArray &hint);
158
159 QSslDiffieHellmanParameters diffieHellmanParameters() const;
160 void setDiffieHellmanParameters(const QSslDiffieHellmanParameters &dhparams);
161
162 QMap<QByteArray, QVariant> backendConfiguration() const;
163 void setBackendConfigurationOption(const QByteArray &name, const QVariant &value);
164 void setBackendConfiguration(const QMap<QByteArray, QVariant> &backendConfiguration = QMap<QByteArray, QVariant>());
165
166 static QSslConfiguration defaultConfiguration();
167 static void setDefaultConfiguration(const QSslConfiguration &configuration);
168
169#if QT_CONFIG(dtls) || defined(Q_CLANG_QDOC)
170 bool dtlsCookieVerificationEnabled() const;
171 void setDtlsCookieVerificationEnabled(bool enable);
172
173 static QSslConfiguration defaultDtlsConfiguration();
174 static void setDefaultDtlsConfiguration(const QSslConfiguration &configuration);
175#endif // dtls
176
177 bool handshakeMustInterruptOnError() const;
178 void setHandshakeMustInterruptOnError(bool interrupt);
179
180 bool missingCertificateIsFatal() const;
181 void setMissingCertificateIsFatal(bool cannotRecover);
182
183 void setOcspStaplingEnabled(bool enable);
184 bool ocspStaplingEnabled() const;
185
186 enum NextProtocolNegotiationStatus {
187 NextProtocolNegotiationNone,
188 NextProtocolNegotiationNegotiated,
189 NextProtocolNegotiationUnsupported
190 };
191
192 void setAllowedNextProtocols(const QList<QByteArray> &protocols);
193 QList<QByteArray> allowedNextProtocols() const;
194
195 QByteArray nextNegotiatedProtocol() const;
196 NextProtocolNegotiationStatus nextProtocolNegotiationStatus() const;
197
198 static const char ALPNProtocolHTTP2[];
199 static const char NextProtocolHttp1_1[];
200
201private:
202 friend class QSslSocket;
203 friend class QSslConfigurationPrivate;
204 friend class QSslSocketBackendPrivate;
205 friend class QSslContext;
206 friend class QDtlsBasePrivate;
207 friend class dtlsopenssl::DtlsState;
208 QSslConfiguration(QSslConfigurationPrivate *dd);
209 QSharedDataPointer<QSslConfigurationPrivate> d;
210};
211
212Q_DECLARE_SHARED(QSslConfiguration)
213
214QT_END_NAMESPACE
215
216Q_DECLARE_METATYPE(QSslConfiguration)
217
218#endif // QT_NO_SSL
219
220#endif
221