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
qqmlsslconfiguration.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 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#include <QtCore/qfile.h>
5#include <QtNetwork/qsslcipher.h>
7#include <array>
8
20
25
26QList<QSsl::SslOption> QQmlSslConfiguration::sslOptions() const
27{
28 return m_sslOptions;
29}
30
35
40
45
50
55
57{
58 if (m_certificateFiles == certificateFiles)
59 return;
60
61 m_certificateFiles = certificateFiles;
62 QList<QSslCertificate> certificates;
63 for (const QString &fileName: m_certificateFiles) {
64 QFile certificateFile(fileName);
65 if (certificateFile.open(QIODevice::ReadOnly)) {
66 QByteArray cert = certificateFile.readAll();
67 certificates.append(QSslCertificate(cert));
68 } else {
69 qWarning() << "File: " << fileName << "is not found. It will be skipped.";
70 }
71 }
72
73 if (!certificates.isEmpty())
75 else
76 qWarning() << "No certificates loaded.";
77}
78
86
94
102
104{
105 if (ciphers == m_ciphers)
106 return;
107
109 m_configuration.setCiphers(ciphers); // split(":") is used inside
110}
111
112void QQmlSslConfiguration::setSslOptions(const QList<QSsl::SslOption> &options)
113{
114 if (m_sslOptions == options)
115 return;
116
117 m_sslOptions = options;
120}
121
129
131{
133}
134
142
144{
145 QList<QSslCipher> ciphers = configuration.ciphers();
146 for (int i = 0; i < ciphers.size(); ++i) {
147 if (i != 0) {
149 }
150 m_ciphers += ciphers[i].name();
151 }
152}
153
161
164{
165#if QT_CONFIG(dtls)
166 m_configuration = QSslConfiguration::defaultDtlsConfiguration();
167#else
168 qWarning() << "No dtls support enabled";
170#endif // QT_CONFIG(dtls)
173}
174
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qfile.h:93
void append(parameter_type t)
Definition qlist.h:458
Q_INVOKABLE void setPrivateKey(const QQmlSslKey &privateKey)
void setSessionTicket(const QByteArray &sessionTicket)
QList< QSsl::SslOption > m_sslOptions
void setCiphersList(const QSslConfiguration &configuration)
void setPeerVerifyDepth(int depth)
QList< QSsl::SslOption > sslOptions
void setCiphers(const QString &ciphers)
QSslSocket::PeerVerifyMode peerVerifyMode
void setSslOptionsList(const QSslConfiguration &configuration)
Q_INVOKABLE void setCertificateFiles(const QStringList &certificateFiles)
void setProtocol(QSsl::SslProtocol protocol)
void setPeerVerifyMode(QSslSocket::PeerVerifyMode mode)
QSslConfiguration m_configuration
QSslConfiguration const configuration()
void setSslOptions(const QList< QSsl::SslOption > &options)
QSslKey getSslKey() const
Definition qqmlsslkey.cpp:9
The QSslCertificate class provides a convenient API for an X509 certificate.
The QSslConfiguration class holds the configuration and state of an SSL connection.
bool testSslOption(QSsl::SslOption option) const
void setSessionTicket(const QByteArray &sessionTicket)
void setPeerVerifyMode(QSslSocket::PeerVerifyMode mode)
Sets the verify mode to mode.
QSslSocket::PeerVerifyMode peerVerifyMode() const
Returns the verify mode.
QSsl::SslProtocol protocol() const
Returns the protocol setting for this SSL configuration.
int peerVerifyDepth() const
Returns the maximum number of certificates in the peer's certificate chain to be checked during the S...
void setSslOption(QSsl::SslOption option, bool on)
Enables or disables an SSL compatibility option.
QList< QSslCipher > ciphers() const
Returns this connection's current cryptographic cipher suite.
QByteArray sessionTicket() const
void setPrivateKey(const QSslKey &key)
Sets the connection's private \l {QSslKey} {key} to key.
void setCiphers(const QList< QSslCipher > &ciphers)
Sets the cryptographic cipher suite for this socket to ciphers, which must contain a subset of the ci...
void setPeerVerifyDepth(int depth)
Sets the maximum number of certificates in the peer's certificate chain to be checked during the SSL ...
static QSslConfiguration defaultConfiguration()
Returns the default SSL configuration to be used in new SSL connections.
void setCaCertificates(const QList< QSslCertificate > &certificates)
Sets this socket's CA certificate database to be certificates.
void setProtocol(QSsl::SslProtocol protocol)
Sets the protocol setting for this configuration to be protocol.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
SslOption
Describes the options that can be used to control the details of SSL behaviour.
Definition qssl.h:73
@ SslOptionDisableSessionPersistence
Definition qssl.h:80
@ SslOptionDisableCompression
Definition qssl.h:76
@ SslOptionDisableSessionTickets
Definition qssl.h:75
@ SslOptionDisableServerNameIndication
Definition qssl.h:77
@ SslOptionDisableLegacyRenegotiation
Definition qssl.h:78
@ SslOptionDisableSessionSharing
Definition qssl.h:79
@ SslOptionDisableServerCipherPreference
Definition qssl.h:81
@ SslOptionDisableEmptyFragments
Definition qssl.h:74
SslProtocol
Describes the protocol of the cipher.
Definition qssl.h:50
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum mode
GLuint GLenum option
static QT_BEGIN_NAMESPACE constexpr std::array< QSsl::SslOption, 8 > SslOptions
QList< QSslCertificate > cert
[0]