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.cpp
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#include "qssl_p.h"
9#include "qsslsocket.h"
10#include "qsslsocket_p.h"
11#include "qmutex.h"
12#include "qdebug.h"
13
15
16QT_IMPL_METATYPE_EXTERN(QSslConfiguration)
17
18const QSsl::SslOptions QSslConfigurationPrivate::defaultSslOptions = QSsl::SslOptionDisableEmptyFragments
19 |QSsl::SslOptionDisableLegacyRenegotiation
20 |QSsl::SslOptionDisableCompression
21 |QSsl::SslOptionDisableSessionPersistence;
22
23const char QSslConfiguration::ALPNProtocolHTTP2[] = "h2";
24const char QSslConfiguration::NextProtocolHttp1_1[] = "http/1.1";
25
26/*!
27 \class QSslConfiguration
28 \brief The QSslConfiguration class holds the configuration and state of an SSL connection.
29 \since 4.4
30
31 \reentrant
32 \inmodule QtNetwork
33 \ingroup network
34 \ingroup ssl
35 \ingroup shared
36
37 QSslConfiguration is used by Qt networking classes to relay
38 information about an open SSL connection and to allow the
39 application to control certain features of that connection.
40
41 The settings that QSslConfiguration currently supports are:
42
43 \list
44 \li The SSL/TLS protocol to be used
45 \li The certificate to be presented to the peer during connection
46 and its associated private key
47 \li The ciphers allowed to be used for encrypting the connection
48 \li The list of Certificate Authorities certificates that are
49 used to validate the peer's certificate
50 \endlist
51
52 These settings are applied only during the connection
53 handshake. Setting them after the connection has been established
54 has no effect.
55
56 The state that QSslConfiguration supports are:
57 \list
58 \li The certificate the peer presented during handshake, along
59 with the chain leading to a CA certificate
60 \li The cipher used to encrypt this session
61 \endlist
62
63 The state can only be obtained once the SSL connection starts, but
64 not necessarily before it's done. Some settings may change during
65 the course of the SSL connection without need to restart it (for
66 instance, the cipher can be changed over time).
67
68 State in QSslConfiguration objects cannot be changed.
69
70 QSslConfiguration can be used with QSslSocket and the Network
71 Access API.
72
73 Note that changing settings in QSslConfiguration is not enough to
74 change the settings in the related SSL connection. You must call
75 setSslConfiguration on a modified QSslConfiguration object to
76 achieve that. The following example illustrates how to change the
77 protocol to TLSv1_2 in a QSslSocket object:
78
79 \snippet code/src_network_ssl_qsslconfiguration.cpp 0
80
81 \sa QSsl::SslProtocol, QSslCertificate, QSslCipher, QSslKey,
82 QSslSocket, QNetworkAccessManager,
83 QSslSocket::sslConfiguration(), QSslSocket::setSslConfiguration()
84*/
85
86/*!
87 \enum QSslConfiguration::NextProtocolNegotiationStatus
88
89 Describes the status of the Next Protocol Negotiation (NPN) or
90 Application-Layer Protocol Negotiation (ALPN).
91
92 \value NextProtocolNegotiationNone No application protocol
93 has been negotiated (yet).
94
95 \value NextProtocolNegotiationNegotiated A next protocol
96 has been negotiated (see nextNegotiatedProtocol()).
97
98 \value NextProtocolNegotiationUnsupported The client and
99 server could not agree on a common next application protocol.
100*/
101
102/*!
103 \variable QSslConfiguration::NextProtocolHttp1_1
104 \brief The value used for negotiating HTTP 1.1 during the Next
105 Protocol Negotiation.
106*/
107
108/*!
109 \variable QSslConfiguration::ALPNProtocolHTTP2
110 \brief The value used for negotiating HTTP 2 during the Application-Layer
111 Protocol Negotiation.
112*/
113
114/*!
115 Constructs an empty SSL configuration. This configuration contains
116 no valid settings and the state will be empty. isNull() will
117 return true after this constructor is called.
118
119 Once any setter methods are called, isNull() will return false.
120*/
121QSslConfiguration::QSslConfiguration()
122 : d(new QSslConfigurationPrivate)
123{
124}
125
126/*!
127 Copies the configuration and state of \a other. If \a other is
128 null, this object will be null too.
129*/
130QSslConfiguration::QSslConfiguration(const QSslConfiguration &other)
131 : d(other.d)
132{
133}
134
135/*!
136 Releases any resources held by QSslConfiguration.
137*/
138QSslConfiguration::~QSslConfiguration()
139{
140 // QSharedDataPointer deletes d for us if necessary
141}
142
143/*!
144 Copies the configuration and state of \a other. If \a other is
145 null, this object will be null too.
146*/
147QSslConfiguration &QSslConfiguration::operator=(const QSslConfiguration &other)
148{
149 d = other.d;
150 return *this;
151}
152
153/*!
154 \fn void QSslConfiguration::swap(QSslConfiguration &other)
155 \since 5.0
156 \memberswap{SSL configuration instance}
157*/
158
159/*!
160 Returns \c true if this QSslConfiguration object is equal to \a
161 other.
162
163 Two QSslConfiguration objects are considered equal if they have
164 the exact same settings and state.
165
166 \sa operator!=()
167*/
168bool QSslConfiguration::operator==(const QSslConfiguration &other) const
169{
170 if (d == other.d)
171 return true;
172 return d->peerCertificate == other.d->peerCertificate &&
173 d->peerCertificateChain == other.d->peerCertificateChain &&
174 d->localCertificateChain == other.d->localCertificateChain &&
175 d->privateKey == other.d->privateKey &&
176 d->sessionCipher == other.d->sessionCipher &&
177 d->sessionProtocol == other.d->sessionProtocol &&
178 d->preSharedKeyIdentityHint == other.d->preSharedKeyIdentityHint &&
179 d->ciphers == other.d->ciphers &&
180 d->ellipticCurves == other.d->ellipticCurves &&
181 d->ephemeralServerKey == other.d->ephemeralServerKey &&
182 d->dhParams == other.d->dhParams &&
183 d->caCertificates == other.d->caCertificates &&
184 d->protocol == other.d->protocol &&
185 d->peerVerifyMode == other.d->peerVerifyMode &&
186 d->peerVerifyDepth == other.d->peerVerifyDepth &&
187 d->allowRootCertOnDemandLoading == other.d->allowRootCertOnDemandLoading &&
188 d->backendConfig == other.d->backendConfig &&
189 d->sslOptions == other.d->sslOptions &&
190 d->sslSession == other.d->sslSession &&
191 d->sslSessionTicketLifeTimeHint == other.d->sslSessionTicketLifeTimeHint &&
192 d->nextAllowedProtocols == other.d->nextAllowedProtocols &&
193 d->nextNegotiatedProtocol == other.d->nextNegotiatedProtocol &&
194 d->nextProtocolNegotiationStatus == other.d->nextProtocolNegotiationStatus &&
195 d->keyingMaterial == other.d->keyingMaterial &&
196 d->dtlsCookieEnabled == other.d->dtlsCookieEnabled &&
197 d->ocspStaplingEnabled == other.d->ocspStaplingEnabled &&
198 d->reportFromCallback == other.d->reportFromCallback &&
199 d->missingCertIsFatal == other.d->missingCertIsFatal;
200}
201
202/*!
203 \fn QSslConfiguration::operator!=(const QSslConfiguration &other) const
204
205 Returns \c true if this QSslConfiguration differs from \a other. Two
206 QSslConfiguration objects are considered different if any state or
207 setting is different.
208
209 \sa operator==()
210*/
211
212/*!
213 Returns \c true if this is a null QSslConfiguration object.
214
215 A QSslConfiguration object is null if it has been
216 default-constructed and no setter methods have been called.
217
218 \sa setProtocol(), setLocalCertificate(), setPrivateKey(),
219 setCiphers(), setCaCertificates()
220*/
221bool QSslConfiguration::isNull() const
222{
223 return (d->protocol == QSsl::SecureProtocols &&
224 d->peerVerifyMode == QSslSocket::AutoVerifyPeer &&
225 d->peerVerifyDepth == 0 &&
226 d->allowRootCertOnDemandLoading == true &&
227 d->caCertificates.size() == 0 &&
228 d->ciphers.size() == 0 &&
229 d->ellipticCurves.isEmpty() &&
230 d->ephemeralServerKey.isNull() &&
231 d->dhParams == QSslDiffieHellmanParameters::defaultParameters() &&
232 d->localCertificateChain.isEmpty() &&
233 d->privateKey.isNull() &&
234 d->peerCertificate.isNull() &&
235 d->peerCertificateChain.size() == 0 &&
236 d->backendConfig.isEmpty() &&
237 d->sslOptions == QSslConfigurationPrivate::defaultSslOptions &&
238 d->sslSession.isNull() &&
239 d->sslSessionTicketLifeTimeHint == -1 &&
240 d->preSharedKeyIdentityHint.isNull() &&
241 d->nextAllowedProtocols.isEmpty() &&
242 d->nextNegotiatedProtocol.isNull() &&
243 d->nextProtocolNegotiationStatus == QSslConfiguration::NextProtocolNegotiationNone &&
244 d->keyingMaterial.isEmpty() &&
245 d->ocspStaplingEnabled == false &&
246 d->reportFromCallback == false &&
247 d->missingCertIsFatal == false);
248}
249
250/*!
251 Returns the protocol setting for this SSL configuration.
252
253 \sa setProtocol()
254*/
255QSsl::SslProtocol QSslConfiguration::protocol() const
256{
257 return d->protocol;
258}
259
260/*!
261 Sets the protocol setting for this configuration to be \a
262 protocol.
263
264 Setting the protocol once the connection has already been
265 established has no effect.
266
267 \sa protocol()
268*/
269void QSslConfiguration::setProtocol(QSsl::SslProtocol protocol)
270{
271 d->protocol = protocol;
272}
273
274/*!
275 Returns the verify mode. This mode decides whether QSslSocket should
276 request a certificate from the peer (i.e., the client requests a
277 certificate from the server, or a server requesting a certificate from the
278 client), and whether it should require that this certificate is valid.
279
280 The default mode is AutoVerifyPeer, which tells QSslSocket to use
281 VerifyPeer for clients, QueryPeer for servers.
282
283 \sa setPeerVerifyMode()
284*/
285QSslSocket::PeerVerifyMode QSslConfiguration::peerVerifyMode() const
286{
287 return d->peerVerifyMode;
288}
289
290/*!
291 Sets the verify mode to \a mode. This mode decides whether QSslSocket
292 should request a certificate from the peer (i.e., the client requests a
293 certificate from the server, or a server requesting a certificate from the
294 client), and whether it should require that this certificate is valid.
295
296 The default mode is AutoVerifyPeer, which tells QSslSocket to use
297 VerifyPeer for clients, QueryPeer for servers.
298
299 \sa peerVerifyMode()
300*/
301void QSslConfiguration::setPeerVerifyMode(QSslSocket::PeerVerifyMode mode)
302{
303 d->peerVerifyMode = mode;
304}
305
306
307/*!
308 Returns the maximum number of certificates in the peer's certificate chain
309 to be checked during the SSL handshake phase, or 0 (the default) if no
310 maximum depth has been set, indicating that the whole certificate chain
311 should be checked.
312
313 The certificates are checked in issuing order, starting with the peer's
314 own certificate, then its issuer's certificate, and so on.
315
316 \sa setPeerVerifyDepth(), peerVerifyMode()
317*/
318int QSslConfiguration::peerVerifyDepth() const
319{
320 return d->peerVerifyDepth;
321}
322
323/*!
324 Sets the maximum number of certificates in the peer's certificate chain to
325 be checked during the SSL handshake phase, to \a depth. Setting a depth of
326 0 means that no maximum depth is set, indicating that the whole
327 certificate chain should be checked.
328
329 The certificates are checked in issuing order, starting with the peer's
330 own certificate, then its issuer's certificate, and so on.
331
332 \sa peerVerifyDepth(), setPeerVerifyMode()
333*/
334void QSslConfiguration::setPeerVerifyDepth(int depth)
335{
336 if (depth < 0) {
337 qCWarning(lcSsl,
338 "QSslConfiguration::setPeerVerifyDepth: cannot set negative depth of %d", depth);
339 return;
340 }
341 d->peerVerifyDepth = depth;
342}
343
344/*!
345 Returns the certificate chain to be presented to the peer during
346 the SSL handshake process.
347
348 \sa localCertificate()
349 \since 5.1
350*/
351QList<QSslCertificate> QSslConfiguration::localCertificateChain() const
352{
353 return d->localCertificateChain;
354}
355
356/*!
357 Sets the certificate chain to be presented to the peer during the
358 SSL handshake to be \a localChain.
359
360 Setting the certificate chain once the connection has been
361 established has no effect.
362
363 A certificate is the means of identification used in the SSL
364 process. The local certificate is used by the remote end to verify
365 the local user's identity against its list of Certification
366 Authorities. In most cases, such as in HTTP web browsing, only
367 servers identify to the clients, so the client does not send a
368 certificate.
369
370 Unlike QSslConfiguration::setLocalCertificate() this method allows
371 you to specify any intermediate certificates required in order to
372 validate your certificate. The first item in the list must be the
373 leaf certificate.
374
375 \sa localCertificateChain()
376 \since 5.1
377 */
378void QSslConfiguration::setLocalCertificateChain(const QList<QSslCertificate> &localChain)
379{
380 d->localCertificateChain = localChain;
381}
382
383/*!
384 Returns the certificate to be presented to the peer during the SSL
385 handshake process.
386
387 \sa setLocalCertificate()
388*/
389QSslCertificate QSslConfiguration::localCertificate() const
390{
391 if (d->localCertificateChain.isEmpty())
392 return QSslCertificate();
393 return d->localCertificateChain[0];
394}
395
396/*!
397 Sets the certificate to be presented to the peer during SSL
398 handshake to be \a certificate.
399
400 Setting the certificate once the connection has been established
401 has no effect.
402
403 A certificate is the means of identification used in the SSL
404 process. The local certificate is used by the remote end to verify
405 the local user's identity against its list of Certification
406 Authorities. In most cases, such as in HTTP web browsing, only
407 servers identify to the clients, so the client does not send a
408 certificate.
409
410 \sa localCertificate()
411*/
412void QSslConfiguration::setLocalCertificate(const QSslCertificate &certificate)
413{
414 d->localCertificateChain = QList<QSslCertificate>();
415 d->localCertificateChain += certificate;
416}
417
418/*!
419 Returns the peer's digital certificate (i.e., the immediate
420 certificate of the host you are connected to), or a null
421 certificate, if the peer has not assigned a certificate.
422
423 The peer certificate is checked automatically during the
424 handshake phase, so this function is normally used to fetch
425 the certificate for display or for connection diagnostic
426 purposes. It contains information about the peer, including
427 its host name, the certificate issuer, and the peer's public
428 key.
429
430 Because the peer certificate is set during the handshake phase, it
431 is safe to access the peer certificate from a slot connected to
432 the QSslSocket::sslErrors() signal, QNetworkReply::sslErrors()
433 signal, or the QSslSocket::encrypted() signal.
434
435 If a null certificate is returned, it can mean the SSL handshake
436 failed, or it can mean the host you are connected to doesn't have
437 a certificate, or it can mean there is no connection.
438
439 If you want to check the peer's complete chain of certificates,
440 use peerCertificateChain() to get them all at once.
441
442 \sa peerCertificateChain(),
443 QSslSocket::sslErrors(), QSslSocket::ignoreSslErrors(),
444 QNetworkReply::sslErrors(), QNetworkReply::ignoreSslErrors()
445*/
446QSslCertificate QSslConfiguration::peerCertificate() const
447{
448 return d->peerCertificate;
449}
450
451/*!
452 Returns the peer's chain of digital certificates, starting with
453 the peer's immediate certificate and ending with the CA's
454 certificate.
455
456 Peer certificates are checked automatically during the handshake
457 phase. This function is normally used to fetch certificates for
458 display, or for performing connection diagnostics. Certificates
459 contain information about the peer and the certificate issuers,
460 including host name, issuer names, and issuer public keys.
461
462 Because the peer certificate is set during the handshake phase, it
463 is safe to access the peer certificate from a slot connected to
464 the QSslSocket::sslErrors() signal, QNetworkReply::sslErrors()
465 signal, or the QSslSocket::encrypted() signal.
466
467 If an empty list is returned, it can mean the SSL handshake
468 failed, or it can mean the host you are connected to doesn't have
469 a certificate, or it can mean there is no connection.
470
471 If you want to get only the peer's immediate certificate, use
472 peerCertificate().
473
474 \sa peerCertificate(),
475 QSslSocket::sslErrors(), QSslSocket::ignoreSslErrors(),
476 QNetworkReply::sslErrors(), QNetworkReply::ignoreSslErrors()
477*/
478QList<QSslCertificate> QSslConfiguration::peerCertificateChain() const
479{
480 return d->peerCertificateChain;
481}
482
483/*!
484 Returns the socket's cryptographic \l {QSslCipher} {cipher}, or a
485 null cipher if the connection isn't encrypted. The socket's cipher
486 for the session is set during the handshake phase. The cipher is
487 used to encrypt and decrypt data transmitted through the socket.
488
489 The SSL infrastructure also provides functions for setting the
490 ordered list of ciphers from which the handshake phase will
491 eventually select the session cipher. This ordered list must be in
492 place before the handshake phase begins.
493
494 \sa ciphers(), setCiphers(), supportedCiphers()
495*/
496QSslCipher QSslConfiguration::sessionCipher() const
497{
498 return d->sessionCipher;
499}
500
501/*!
502 Returns the socket's SSL/TLS protocol or UnknownProtocol if the
503 connection isn't encrypted. The socket's protocol for the session
504 is set during the handshake phase.
505
506 \sa protocol(), setProtocol()
507 \since 5.4
508*/
509QSsl::SslProtocol QSslConfiguration::sessionProtocol() const
510{
511 return d->sessionProtocol;
512}
513
514/*!
515 Returns the \l {QSslKey} {SSL key} assigned to this connection or
516 a null key if none has been assigned yet.
517
518 \sa setPrivateKey(), localCertificate()
519*/
520QSslKey QSslConfiguration::privateKey() const
521{
522 return d->privateKey;
523}
524
525/*!
526 Sets the connection's private \l {QSslKey} {key} to \a key. The
527 private key and the local \l {QSslCertificate} {certificate} are
528 used by clients and servers that must prove their identity to
529 SSL peers.
530
531 Both the key and the local certificate are required if you are
532 creating an SSL server socket. If you are creating an SSL client
533 socket, the key and local certificate are required if your client
534 must identify itself to an SSL server.
535
536 \sa privateKey(), setLocalCertificate()
537*/
538void QSslConfiguration::setPrivateKey(const QSslKey &key)
539{
540 d->privateKey = key;
541}
542
543/*!
544 Returns this connection's current cryptographic cipher suite. This
545 list is used during the handshake phase for choosing a
546 session cipher. The returned list of ciphers is ordered by
547 descending preference. (i.e., the first cipher in the list is the
548 most preferred cipher). The session cipher will be the first one
549 in the list that is also supported by the peer.
550
551 By default, the handshake phase can choose any of the ciphers
552 supported by this system's SSL libraries, which may vary from
553 system to system. The list of ciphers supported by this system's
554 SSL libraries is returned by supportedCiphers(). You can restrict
555 the list of ciphers used for choosing the session cipher for this
556 socket by calling setCiphers() with a subset of the supported
557 ciphers. You can revert to using the entire set by calling
558 setCiphers() with the list returned by supportedCiphers().
559
560 \sa setCiphers(), supportedCiphers()
561*/
562QList<QSslCipher> QSslConfiguration::ciphers() const
563{
564 return d->ciphers;
565}
566
567/*!
568 Sets the cryptographic cipher suite for this socket to \a ciphers,
569 which must contain a subset of the ciphers in the list returned by
570 supportedCiphers().
571
572 Restricting the cipher suite must be done before the handshake
573 phase, where the session cipher is chosen.
574
575 \sa ciphers(), supportedCiphers()
576*/
577void QSslConfiguration::setCiphers(const QList<QSslCipher> &ciphers)
578{
579 d->ciphers = ciphers;
580}
581
582/*!
583 \since 6.0
584
585 Sets the cryptographic cipher suite for this configuration to \a ciphers,
586 which is a colon-separated list of cipher suite names. The ciphers are listed
587 in order of preference, starting with the most preferred cipher.
588 Each cipher name in \a ciphers must be the name of a cipher in the
589 list returned by supportedCiphers(). Restricting the cipher suite
590 must be done before the handshake phase, where the session cipher
591 is chosen.
592
593 \note With the Schannel backend the order of the ciphers is ignored and Schannel
594 picks the most secure one during the handshake.
595
596 \sa ciphers()
597*/
598void QSslConfiguration::setCiphers(const QString &ciphers)
599{
600 auto *p = d.data();
601 p->ciphers.clear();
602 const auto cipherNames = ciphers.split(u':', Qt::SkipEmptyParts);
603 for (const QString &cipherName : cipherNames) {
604 QSslCipher cipher(cipherName);
605 if (!cipher.isNull())
606 p->ciphers << cipher;
607 }
608}
609
610/*!
611 \since 5.5
612
613 Returns the list of cryptographic ciphers supported by this
614 system. This list is set by the system's SSL libraries and may
615 vary from system to system.
616
617 \sa ciphers(), setCiphers()
618*/
619QList<QSslCipher> QSslConfiguration::supportedCiphers()
620{
621 return QSslSocketPrivate::supportedCiphers();
622}
623
624/*!
625 Returns this connection's CA certificate database. The CA certificate
626 database is used by the socket during the handshake phase to
627 validate the peer's certificate. It can be modified prior to the
628 handshake with setCaCertificates(), or with addCaCertificate() and
629 addCaCertificates().
630
631 \sa setCaCertificates(), addCaCertificate(), addCaCertificates()
632*/
633QList<QSslCertificate> QSslConfiguration::caCertificates() const
634{
635 return d->caCertificates;
636}
637
638/*!
639 Sets this socket's CA certificate database to be \a certificates.
640 The certificate database must be set prior to the SSL handshake.
641 The CA certificate database is used by the socket during the
642 handshake phase to validate the peer's certificate.
643
644 \note The default configuration uses the system CA certificate database. If
645 that is not available (as is commonly the case on iOS), the default database
646 is empty.
647
648 \sa caCertificates(), addCaCertificates(), addCaCertificate()
649*/
650void QSslConfiguration::setCaCertificates(const QList<QSslCertificate> &certificates)
651{
652 d->caCertificates = certificates;
653 d->allowRootCertOnDemandLoading = false;
654}
655
656/*!
657 \since 5.15
658
659 Searches all files in the \a path for certificates encoded in the
660 specified \a format and adds them to this socket's CA certificate
661 database. \a path must be a file or a pattern matching one or more
662 files, as specified by \a syntax. Returns \c true if one or more
663 certificates are added to the socket's CA certificate database;
664 otherwise returns \c false.
665
666 The CA certificate database is used by the socket during the
667 handshake phase to validate the peer's certificate.
668
669 For more precise control, use addCaCertificate().
670
671 \sa addCaCertificate(), QSslCertificate::fromPath()
672*/
673bool QSslConfiguration::addCaCertificates(const QString &path, QSsl::EncodingFormat format,
674 QSslCertificate::PatternSyntax syntax)
675{
676 QList<QSslCertificate> certs = QSslCertificate::fromPath(path, format, syntax);
677 if (certs.isEmpty())
678 return false;
679
680 d->caCertificates += certs;
681 return true;
682}
683
684/*!
685 \since 5.15
686
687 Adds \a certificate to this configuration's CA certificate database.
688 The certificate database must be set prior to the SSL handshake.
689 The CA certificate database is used by the socket during the
690 handshake phase to validate the peer's certificate.
691
692 \note The default configuration uses the system CA certificate database. If
693 that is not available (as is commonly the case on iOS), the default database
694 is empty.
695
696 \sa caCertificates(), setCaCertificates(), addCaCertificates()
697*/
698void QSslConfiguration::addCaCertificate(const QSslCertificate &certificate)
699{
700 d->caCertificates += certificate;
701 d->allowRootCertOnDemandLoading = false;
702}
703
704/*!
705 \since 5.15
706
707 Adds \a certificates to this configuration's CA certificate database.
708 The certificate database must be set prior to the SSL handshake.
709 The CA certificate database is used by the socket during the
710 handshake phase to validate the peer's certificate.
711
712 \note The default configuration uses the system CA certificate database. If
713 that is not available (as is commonly the case on iOS), the default database
714 is empty.
715
716 \sa caCertificates(), setCaCertificates(), addCaCertificate()
717*/
718void QSslConfiguration::addCaCertificates(const QList<QSslCertificate> &certificates)
719{
720 d->caCertificates += certificates;
721 d->allowRootCertOnDemandLoading = false;
722}
723
724/*!
725 \since 5.5
726
727 This function provides the CA certificate database
728 provided by the operating system. The CA certificate database
729 returned by this function is used to initialize the database
730 returned by caCertificates() on the default QSslConfiguration.
731
732 \sa caCertificates(), setCaCertificates(), defaultConfiguration(),
733 addCaCertificate(), addCaCertificates()
734*/
735QList<QSslCertificate> QSslConfiguration::systemCaCertificates()
736{
737 // we are calling ensureInitialized() in the method below
738 return QSslSocketPrivate::systemCaCertificates();
739}
740
741/*!
742 Enables or disables an SSL compatibility \a option. If \a on
743 is true, the \a option is enabled. If \a on is false, the
744 \a option is disabled.
745
746 \sa testSslOption()
747*/
748void QSslConfiguration::setSslOption(QSsl::SslOption option, bool on)
749{
750 d->sslOptions.setFlag(option, on);
751}
752
753/*!
754 \since 4.8
755
756 Returns \c true if the specified SSL compatibility \a option is enabled.
757
758 \sa setSslOption()
759*/
760bool QSslConfiguration::testSslOption(QSsl::SslOption option) const
761{
762 return d->sslOptions & option;
763}
764
765/*!
766 \since 5.2
767
768 If QSsl::SslOptionDisableSessionPersistence was turned off, this
769 function returns the session ticket used in the SSL handshake in ASN.1
770 format, suitable to e.g. be persisted to disk. If no session ticket was
771 used or QSsl::SslOptionDisableSessionPersistence was not turned off,
772 this function returns an empty QByteArray.
773
774 \note When persisting the session ticket to disk or similar, be
775 careful not to expose the session to a potential attacker, as
776 knowledge of the session allows for eavesdropping on data
777 encrypted with the session parameters.
778
779 \sa setSessionTicket(), QSsl::SslOptionDisableSessionPersistence, setSslOption(), QSslSocket::newSessionTicketReceived()
780 */
781QByteArray QSslConfiguration::sessionTicket() const
782{
783 return d->sslSession;
784}
785
786/*!
787 \since 5.2
788
789 Sets the session ticket to be used in an SSL handshake.
790 QSsl::SslOptionDisableSessionPersistence must be turned off
791 for this to work, and \a sessionTicket must be in ASN.1 format
792 as returned by sessionTicket().
793
794 \sa sessionTicket(), QSsl::SslOptionDisableSessionPersistence, setSslOption(), QSslSocket::newSessionTicketReceived()
795 */
796void QSslConfiguration::setSessionTicket(const QByteArray &sessionTicket)
797{
798 d->sslSession = sessionTicket;
799}
800
801/*!
802 \since 5.2
803
804 If QSsl::SslOptionDisableSessionPersistence was turned off, this
805 function returns the session ticket life time hint sent by the
806 server (which might be 0).
807 If the server did not send a session ticket (e.g. when
808 resuming a session or when the server does not support it) or
809 QSsl::SslOptionDisableSessionPersistence was not turned off,
810 this function returns -1.
811
812 \sa sessionTicket(), QSsl::SslOptionDisableSessionPersistence, setSslOption(), QSslSocket::newSessionTicketReceived()
813 */
814int QSslConfiguration::sessionTicketLifeTimeHint() const
815{
816 return d->sslSessionTicketLifeTimeHint;
817}
818
819/*!
820 \since 6.13
821
822 Returns \c true if a reused session was negotiated during the handshake
823 of the current connection; otherwise returns \c false.
824
825 \note Only the OpenSSL backend reports session reuse.
826*/
827bool QSslConfiguration::isSessionResumed() const
828{
829 return d->peerSessionShared;
830}
831
832/*!
833 \since 5.7
834
835 Returns the ephemeral server key used for cipher algorithms
836 with forward secrecy, e.g. DHE-RSA-AES128-SHA.
837
838 The ephemeral key is only available when running in client mode, i.e.
839 QSslSocket::SslClientMode. When running in server mode or using a
840 cipher algorithm without forward secrecy a null key is returned.
841 The ephemeral server key will be set before emitting the encrypted()
842 signal.
843 */
844QSslKey QSslConfiguration::ephemeralServerKey() const
845{
846 return d->ephemeralServerKey;
847}
848
849/*!
850 \since 5.5
851
852 Returns this connection's current list of elliptic curves. This
853 list is used during the handshake phase for choosing an
854 elliptic curve (when using an elliptic curve cipher).
855 The returned list of curves is ordered by descending preference
856 (i.e., the first curve in the list is the most preferred one).
857
858 By default, the handshake phase can choose any of the curves
859 supported by this system's SSL libraries, which may vary from
860 system to system. The list of curves supported by this system's
861 SSL libraries is returned by QSslSocket::supportedEllipticCurves().
862
863 You can restrict the list of curves used for choosing the session cipher
864 for this socket by calling setEllipticCurves() with a subset of the
865 supported ciphers. You can revert to using the entire set by calling
866 setEllipticCurves() with the list returned by
867 QSslSocket::supportedEllipticCurves().
868
869 \sa setEllipticCurves
870 */
871QList<QSslEllipticCurve> QSslConfiguration::ellipticCurves() const
872{
873 return d->ellipticCurves;
874}
875
876/*!
877 \since 5.5
878
879 Sets the list of elliptic curves to be used by this socket to \a curves,
880 which must contain a subset of the curves in the list returned by
881 supportedEllipticCurves().
882
883 Restricting the elliptic curves must be done before the handshake
884 phase, where the session cipher is chosen.
885
886 \sa ellipticCurves
887 */
888void QSslConfiguration::setEllipticCurves(const QList<QSslEllipticCurve> &curves)
889{
890 d->ellipticCurves = curves;
891}
892
893/*!
894 \since 5.5
895
896 Returns the list of elliptic curves supported by this
897 system. This list is set by the system's SSL libraries and may
898 vary from system to system.
899
900 \sa ellipticCurves(), setEllipticCurves()
901*/
902QList<QSslEllipticCurve> QSslConfiguration::supportedEllipticCurves()
903{
904 return QSslSocketPrivate::supportedEllipticCurves();
905}
906
907/*!
908 \since 5.8
909
910 Returns the identity hint.
911
912 \sa setPreSharedKeyIdentityHint()
913*/
914QByteArray QSslConfiguration::preSharedKeyIdentityHint() const
915{
916 return d->preSharedKeyIdentityHint;
917}
918
919/*!
920 \since 5.8
921
922 Sets the identity hint for a preshared key authentication to \a hint. This will
923 affect the next initiated handshake; calling this function on an already-encrypted
924 socket will not affect the socket's identity hint.
925
926 The identity hint is used in QSslSocket::SslServerMode only!
927*/
928void QSslConfiguration::setPreSharedKeyIdentityHint(const QByteArray &hint)
929{
930 d->preSharedKeyIdentityHint = hint;
931}
932
933/*!
934 \since 5.8
935
936 Retrieves the current set of Diffie-Hellman parameters.
937
938 If no Diffie-Hellman parameters have been set, the QSslConfiguration object
939 defaults to using the 2048-bit MODP group from RFC 3526.
940
941 \note The default parameters may change in future Qt versions.
942 Please check the documentation of the \e{exact Qt version} that you
943 are using in order to know what defaults that version uses.
944 */
945QSslDiffieHellmanParameters QSslConfiguration::diffieHellmanParameters() const
946{
947 return d->dhParams;
948}
949
950/*!
951 \since 5.8
952
953 Sets a custom set of Diffie-Hellman parameters to be used by this socket when functioning as
954 a server to \a dhparams.
955
956 If no Diffie-Hellman parameters have been set, the QSslConfiguration object
957 defaults to using the 2048-bit MODP group from RFC 3526.
958
959 Since 6.7 you can provide an empty Diffie-Hellman parameter to use auto selection
960 (see SSL_CTX_set_dh_auto of openssl) if the tls backend supports it.
961
962 \note The default parameters may change in future Qt versions.
963 Please check the documentation of the \e{exact Qt version} that you
964 are using in order to know what defaults that version uses.
965 */
966void QSslConfiguration::setDiffieHellmanParameters(const QSslDiffieHellmanParameters &dhparams)
967{
968 d->dhParams = dhparams;
969}
970
971/*!
972 \since 5.11
973
974 Returns the backend-specific configuration.
975
976 Only options set by setBackendConfigurationOption() or setBackendConfiguration() will be
977 returned. The internal standard configuration of the backend is not reported.
978
979 \sa setBackendConfigurationOption(), setBackendConfiguration()
980 */
981QMap<QByteArray, QVariant> QSslConfiguration::backendConfiguration() const
982{
983 return d->backendConfig;
984}
985
986/*!
987 \since 5.11
988
989 Sets the option \a name in the backend-specific configuration to \a value.
990
991 Options supported by the OpenSSL (>= 1.0.2) backend are available in the \l
992 {https://www.openssl.org/docs/manmaster/man3/SSL_CONF_cmd.html#SUPPORTED-CONFIGURATION-FILE-COMMANDS}
993 {supported configuration file commands} documentation. The expected type for
994 the \a value parameter is a QByteArray for all options. The \l
995 {https://www.openssl.org/docs/manmaster/man3/SSL_CONF_cmd.html#EXAMPLES}{examples}
996 show how to use some of the options.
997
998 \note The backend-specific configuration will be applied after the general
999 configuration. Using the backend-specific configuration to set a general
1000 configuration option again will overwrite the general configuration option.
1001
1002 \sa backendConfiguration(), setBackendConfiguration()
1003 */
1004void QSslConfiguration::setBackendConfigurationOption(const QByteArray &name, const QVariant &value)
1005{
1006 d->backendConfig[name] = value;
1007}
1008
1009/*!
1010 \since 5.11
1011
1012 Sets or clears the backend-specific configuration.
1013
1014 Without a \a backendConfiguration parameter this function will clear the
1015 backend-specific configuration. More information about the supported
1016 options is available in the documentation of setBackendConfigurationOption().
1017
1018 \sa backendConfiguration(), setBackendConfigurationOption()
1019 */
1020void QSslConfiguration::setBackendConfiguration(const QMap<QByteArray, QVariant> &backendConfiguration)
1021{
1022 d->backendConfig = backendConfiguration;
1023}
1024
1025/*!
1026 \since 5.3
1027
1028 This function returns the protocol negotiated with the server
1029 if the Next Protocol Negotiation (NPN) or Application-Layer Protocol
1030 Negotiation (ALPN) TLS extension was enabled.
1031 In order for the NPN/ALPN extension to be enabled, setAllowedNextProtocols()
1032 needs to be called explicitly before connecting to the server.
1033
1034 If no protocol could be negotiated or the extension was not enabled,
1035 this function returns a QByteArray which is null.
1036
1037 \sa setAllowedNextProtocols(), nextProtocolNegotiationStatus()
1038 */
1039QByteArray QSslConfiguration::nextNegotiatedProtocol() const
1040{
1041 return d->nextNegotiatedProtocol;
1042}
1043
1044/*!
1045 \since 5.3
1046
1047 This function sets the allowed \a protocols to be negotiated with the
1048 server through the Next Protocol Negotiation (NPN) or Application-Layer
1049 Protocol Negotiation (ALPN) TLS extension; each
1050 element in \a protocols must define one allowed protocol.
1051 The function must be called explicitly before connecting to send the NPN/ALPN
1052 extension in the SSL handshake.
1053 Whether or not the negotiation succeeded can be queried through
1054 nextProtocolNegotiationStatus().
1055
1056 \sa nextNegotiatedProtocol(), nextProtocolNegotiationStatus(), allowedNextProtocols(), QSslConfiguration::NextProtocolHttp1_1
1057 */
1058void QSslConfiguration::setAllowedNextProtocols(const QList<QByteArray> &protocols)
1059{
1060 d->nextAllowedProtocols = protocols;
1061}
1062
1063/*!
1064 \since 5.3
1065
1066 This function returns the allowed protocols to be negotiated with the
1067 server through the Next Protocol Negotiation (NPN) or Application-Layer
1068 Protocol Negotiation (ALPN) TLS extension, as set by setAllowedNextProtocols().
1069
1070 \sa nextNegotiatedProtocol(), nextProtocolNegotiationStatus(), setAllowedNextProtocols(), QSslConfiguration::NextProtocolHttp1_1
1071 */
1072QList<QByteArray> QSslConfiguration::allowedNextProtocols() const
1073{
1074 return d->nextAllowedProtocols;
1075}
1076
1077/*!
1078 \since 5.3
1079
1080 This function returns the status of the Next Protocol Negotiation (NPN)
1081 or Application-Layer Protocol Negotiation (ALPN).
1082 If the feature has not been enabled through setAllowedNextProtocols(),
1083 this function returns NextProtocolNegotiationNone.
1084 The status will be set before emitting the encrypted() signal.
1085
1086 \sa setAllowedNextProtocols(), allowedNextProtocols(), nextNegotiatedProtocol(), QSslConfiguration::NextProtocolNegotiationStatus
1087 */
1088QSslConfiguration::NextProtocolNegotiationStatus QSslConfiguration::nextProtocolNegotiationStatus() const
1089{
1090 return d->nextProtocolNegotiationStatus;
1091}
1092
1093/*!
1094 Returns the default SSL configuration to be used in new SSL
1095 connections.
1096
1097 The default SSL configuration consists of:
1098
1099 \list
1100 \li no local certificate and no private key
1101 \li protocol \l{QSsl::SecureProtocols}{SecureProtocols}
1102 \li the system's default CA certificate list
1103 \li the cipher list equal to the list of the SSL libraries'
1104 supported SSL ciphers that are 128 bits or more
1105 \endlist
1106
1107 \sa supportedCiphers(), setDefaultConfiguration()
1108*/
1109QSslConfiguration QSslConfiguration::defaultConfiguration()
1110{
1111 return QSslConfigurationPrivate::defaultConfiguration();
1112}
1113
1114/*!
1115 Sets the default SSL configuration to be used in new SSL
1116 connections to be \a configuration. Existing connections are not
1117 affected by this call.
1118
1119 \sa supportedCiphers(), defaultConfiguration()
1120*/
1121void QSslConfiguration::setDefaultConfiguration(const QSslConfiguration &configuration)
1122{
1123 QSslConfigurationPrivate::setDefaultConfiguration(configuration);
1124}
1125
1126#if QT_CONFIG(dtls) || defined(Q_QDOC)
1127
1128/*!
1129 This function returns true if DTLS cookie verification was enabled on a
1130 server-side socket.
1131
1132 \sa setDtlsCookieVerificationEnabled()
1133 */
1134bool QSslConfiguration::dtlsCookieVerificationEnabled() const
1135{
1136 return d->dtlsCookieEnabled;
1137}
1138
1139/*!
1140 This function enables DTLS cookie verification when \a enable is true.
1141
1142 \sa dtlsCookieVerificationEnabled()
1143 */
1144void QSslConfiguration::setDtlsCookieVerificationEnabled(bool enable)
1145{
1146 d->dtlsCookieEnabled = enable;
1147}
1148
1149/*!
1150 Returns the default DTLS configuration to be used in new DTLS
1151 connections.
1152
1153 The default DTLS configuration consists of:
1154
1155 \list
1156 \li no local certificate and no private key
1157 \li protocol DtlsV1_2OrLater
1158 \li the system's default CA certificate list
1159 \li the cipher list equal to the list of the SSL libraries'
1160 supported TLS 1.2 ciphers that use 128 or more secret bits
1161 for the cipher.
1162 \endlist
1163
1164 \sa setDefaultDtlsConfiguration()
1165*/
1166QSslConfiguration QSslConfiguration::defaultDtlsConfiguration()
1167{
1168 return QSslConfigurationPrivate::defaultDtlsConfiguration();
1169}
1170
1171/*!
1172 Sets the default DTLS configuration to be used in new DTLS
1173 connections to be \a configuration. Existing connections are not
1174 affected by this call.
1175
1176 \sa defaultDtlsConfiguration()
1177*/
1178void QSslConfiguration::setDefaultDtlsConfiguration(const QSslConfiguration &configuration)
1179{
1180 QSslConfigurationPrivate::setDefaultDtlsConfiguration(configuration);
1181}
1182
1183#endif // dtls
1184
1185/*!
1186 \since 5.13
1187 If \a enabled is true, client QSslSocket will send a certificate status request
1188 to its peer when initiating a handshake. During the handshake QSslSocket will
1189 verify the server's response. This value must be set before the handshake
1190 starts.
1191
1192 \sa ocspStaplingEnabled()
1193*/
1194void QSslConfiguration::setOcspStaplingEnabled(bool enabled)
1195{
1196#if QT_CONFIG(ocsp)
1197 d->ocspStaplingEnabled = enabled;
1198#else
1199 if (enabled)
1200 qCWarning(lcSsl, "Enabling OCSP-stapling requires the feature 'ocsp'");
1201#endif // ocsp
1202}
1203
1204/*!
1205 \since 5.13
1206 Returns true if OCSP stapling was enabled by setOCSPStaplingEnabled(),
1207 otherwise false (which is the default value).
1208
1209 \sa setOcspStaplingEnabled()
1210*/
1211bool QSslConfiguration::ocspStaplingEnabled() const
1212{
1213 return d->ocspStaplingEnabled;
1214}
1215
1216/*!
1217 \since 6.0
1218
1219 Returns true if a verification callback will emit QSslSocket::handshakeInterruptedOnError()
1220 early, before concluding the handshake.
1221
1222 \note This function always returns false for all backends but OpenSSL.
1223
1224 \sa setHandshakeMustInterruptOnError(), QSslSocket::handshakeInterruptedOnError(), QSslSocket::continueInterruptedHandshake()
1225*/
1226bool QSslConfiguration::handshakeMustInterruptOnError() const
1227{
1228 return d->reportFromCallback;
1229}
1230
1231/*!
1232 \since 6.0
1233
1234 If \a interrupt is true and the underlying backend supports this option,
1235 errors found during certificate verification are reported immediately
1236 by emitting QSslSocket::handshakeInterruptedOnError(). This allows
1237 to stop the unfinished handshake and send a proper alert message to
1238 a peer. No special action is required from the application in this case.
1239 QSslSocket will close the connection after sending the alert message.
1240 If the application after inspecting the error wants to continue the
1241 handshake, it must call QSslSocket::continueInterruptedHandshake()
1242 from its slot function. The signal-slot connection must be direct.
1243
1244 \note When interrupting handshake is enabled, errors that would otherwise
1245 be reported by QSslSocket::peerVerifyError() are instead only reported by
1246 QSslSocket::handshakeInterruptedOnError().
1247 \note Even if the handshake was continued, these errors will be
1248 reported when emitting QSslSocket::sslErrors() signal (and thus must
1249 be ignored in the corresponding function slot).
1250
1251 \sa handshakeMustInterruptOnError(), QSslSocket::handshakeInterruptedOnError(), QSslSocket::continueInterruptedHandshake()
1252*/
1253void QSslConfiguration::setHandshakeMustInterruptOnError(bool interrupt)
1254{
1255#if QT_CONFIG(openssl)
1256 d->reportFromCallback = interrupt;
1257#else
1258 Q_UNUSED(interrupt);
1259 qCWarning(lcSsl, "This operation requires OpenSSL as TLS backend");
1260#endif
1261}
1262
1263/*!
1264 \since 6.12
1265
1266 Returns the keying material configuration for this SSL connection.
1267
1268 Keying material allows an application to derive additional
1269 cryptographic material from an established TLS session, using the
1270 TLS exporter mechanism as defined in RFC 5705 and RFC 8446.
1271
1272 Each entry in the returned list describes a request for exported
1273 keying material, including the exporter label, optional context,
1274 and the desired length of the exported data. The actual keying
1275 material becomes available only after a successful handshake.
1276
1277 Exported keying material is bound to the specific TLS session and
1278 cryptographically independent from the session keys used for
1279 encryption. It can be used for application-specific purposes such
1280 as channel binding or key derivation for protocols layered on top
1281 of TLS.
1282
1283 If no keying material configuration was set, this function returns
1284 an empty list.
1285
1286 The values are handed over instead of being shared: the entries left
1287 behind in this configuration are valueless
1288 \l{QSslKeyingMaterial::clone()}{clones}, so they can still be used to
1289 request the same keying material again. Only the returned entries carry
1290 the derived values.
1291
1292 \note The availability of keying material depends on the TLS
1293 backend. Currently, this feature is supported only when using
1294 OpenSSL.
1295
1296 \warning Exported keying material must be handled with care.
1297 Improper use may compromise the security of the TLS
1298 session or higher-level protocols.
1299
1300 \sa setKeyingMaterial()
1301*/
1302QList<QSslKeyingMaterial> QSslConfiguration::takeKeyingMaterial()
1303{
1304 QList<QSslKeyingMaterial> requests;
1305 requests.reserve(d->keyingMaterial.size());
1306 for (const auto &entry : std::as_const(d->keyingMaterial))
1307 requests.append(entry.clone());
1308
1309 return std::exchange(d->keyingMaterial, std::move(requests));
1310}
1311
1312/*!
1313 \since 6.12
1314
1315 Returns the derived keying material for the given \a material request.
1316
1317 Returns the entry from the keying material list that matches
1318 \a material by label, context, and requested size, or
1319 \c{std::nullopt} if no matching entry was found.
1320
1321 If a matching entry is found and the TLS handshake has completed
1322 successfully, the returned object's \l{QSslKeyingMaterial::value()}
1323 contains the derived keying material.
1324
1325 The value can only be taken once: the entry left behind is a valueless
1326 \l{QSslKeyingMaterial::clone()}{clone}, which still matches \a material.
1327
1328 \sa takeKeyingMaterial(), setKeyingMaterial()
1329*/
1330std::optional<QSslKeyingMaterial>
1331QSslConfiguration::takeKeyingMaterial(const QSslKeyingMaterial &material)
1332{
1333 for (auto &entry : d->keyingMaterial) {
1334 if (entry.label() == material.label() &&
1335 // "" and null are equal, so test explicitly:
1336 entry.context().isNull() == material.context().isNull() &&
1337 entry.context() == material.context() &&
1338 entry.requestedSize() == material.requestedSize()) {
1339 // Hand the value over instead of sharing it, leaving the request behind:
1340 return std::exchange(entry, entry.clone());
1341 }
1342 }
1343
1344 return std::nullopt;
1345}
1346
1347/*!
1348 \since 6.12
1349
1350 Sets the keying material configuration for this SSL connection to
1351 \a keyMaterial.
1352
1353 This enables the TLS exporter mechanism, allowing the application
1354 to derive additional cryptographic material from the negotiated TLS
1355 session. The exporter is defined in RFC 5705 and RFC 8446.
1356
1357 The configuration must be set before the TLS handshake starts.
1358 Calling this function on an already encrypted connection has no
1359 effect.
1360
1361 Each QSslKeyingMaterial entry specifies the exporter label, optional
1362 context value, and the length of the keying material to be derived.
1363 After a successful handshake, the requested keying material can be
1364 retrieved from the SSL connection.
1365
1366 Exported keying material is unique to the TLS session and can be
1367 safely used to derive keys for application-level protocols that
1368 require cryptographic binding to the underlying TLS channel.
1369
1370 \note This feature is backend-specific and currently requires
1371 OpenSSL support.
1372
1373 \warning Applications are responsible for defining unique and
1374 collision-resistant exporter labels. Reusing labels or
1375 contexts across different purposes may lead to subtle
1376 security vulnerabilities.
1377
1378 The entries must not carry a value(); that is a programming error and
1379 terminates the program.
1380
1381 \sa takeKeyingMaterial()
1382*/
1383void QSslConfiguration::setKeyingMaterial(const QList<QSslKeyingMaterial> &keyMaterial)
1384{
1385 for (const auto &entry : keyMaterial) {
1386 if (!entry.value().isEmpty()) {
1387 qFatal("QSslConfiguration::setKeyingMaterial: keying material values are "
1388 "derived by the TLS backend and cannot be set by the application");
1389 }
1390 }
1391
1392 d->keyingMaterial = keyMaterial;
1393}
1394
1395/*!
1396 \since 6.0
1397
1398 Returns true if errors with code QSslError::NoPeerCertificate
1399 cannot be ignored.
1400
1401 \note Always returns false for all TLS backends but OpenSSL.
1402
1403 \sa QSslSocket::ignoreSslErrors(), setMissingCertificateIsFatal()
1404*/
1405bool QSslConfiguration::missingCertificateIsFatal() const
1406{
1407 return d->missingCertIsFatal;
1408}
1409
1410/*!
1411 \since 6.0
1412
1413 If \a cannotRecover is true, and verification mode in use is
1414 QSslSocket::VerifyPeer or QSslSocket::AutoVerifyPeer (for a
1415 client-side socket), the missing peer's certificate would be
1416 treated as an unrecoverable error that cannot be ignored. A proper
1417 alert message will be sent to the peer before closing the connection.
1418
1419 \note Only available if Qt was configured and built with OpenSSL backend.
1420
1421 \sa QSslSocket::ignoreSslErrors(), QSslSocket::PeerVerifyMode, missingCertificateIsFatal()
1422*/
1423void QSslConfiguration::setMissingCertificateIsFatal(bool cannotRecover)
1424{
1425#if QT_CONFIG(openssl)
1426 d->missingCertIsFatal = cannotRecover;
1427#else
1428 Q_UNUSED(cannotRecover);
1429 qCWarning(lcSsl, "Handling a missing certificate as a fatal error requires an OpenSSL backend");
1430#endif // openssl
1431}
1432
1433QT_END_NAMESPACE
Combined button and popup list for selecting options.