17#include <QtCore/private/qfactoryloader_p.h>
19#include "QtCore/qapplicationstatic.h"
20#include <QtCore/qbytearray.h>
21#include <QtCore/qmutex.h>
35class BackendCollection
41 Q_ASSERT(std::find(backends.begin(), backends.end(), backend) == backends.end());
43 backends.push_back(backend);
50 const auto it = std::find(backends.begin(), backends.end(), backend);
55 bool tryPopulateCollection()
66 qtlsbLoader->update();
69 while (qtlsbLoader->instance(
index))
78 if (!tryPopulateCollection())
85 names.reserve(backends.size());
86 for (
const auto *backend : backends) {
96 if (!tryPopulateCollection())
100 const auto it = std::find_if(backends.begin(), backends.end(),
101 [&
name](
const auto *fct) {return fct->backendName() == name;});
107 std::vector<QTlsBackend *> backends;
170 backends->addBackend(
this);
188 backends->removeBackend(
this);
271#define REPORT_MISSING_SUPPORT(message) \
272 qCWarning(lcSsl) << "The backend" << backendName() << message
571 return backends->backendNames();
594 return name != builtinBackendNames[nameIndexCertOnly];
657 if (
const auto *fct = backends->backend(
backendName))
658 return fct->supportedProtocols();
677 if (
const auto *fct = backends->backend(
backendName))
678 return fct->supportedFeatures();
696 if (
const auto *fct = backends->backend(
backendName))
697 return fct->implementedClasses();
709 key.d->backend.reset(keyBackend);
722 int hintLength,
unsigned maxIdentityLen,
unsigned maxPskLen)
746 const QByteArray &identityHint,
unsigned int maxPskLen)
771QSslCipher QTlsBackend::createCiphersuite(
const QString &descriptionOneLine,
int bits,
int supportedBits)
776 if (descriptionList.size() > 5) {
777 ciph.d->isNull =
false;
778 ciph.d->name = descriptionList.at(0).toString();
781 ciph.d->protocolString = protoString.
toString();
791 else if (tail == u
"2")
793 else if (tail == u
"1")
794 ciph.d->protocol = QSsl::TlsV1_1;
796 ciph.d->protocol = QSsl::TlsV1_0;
801 if (descriptionList.at(2).startsWith(
"Kx="_L1))
802 ciph.d->keyExchangeMethod = descriptionList.at(2).mid(3).toString();
803 if (descriptionList.at(3).startsWith(
"Au="_L1))
804 ciph.d->authenticationMethod = descriptionList.at(3).mid(3).toString();
805 if (descriptionList.at(4).startsWith(
"Enc="_L1))
806 ciph.d->encryptionMethod = descriptionList.at(4).mid(4).toString();
807 ciph.d->exportable = (descriptionList.size() > 6 && descriptionList.at(6) ==
"export"_L1);
810 ciph.d->supportedBits = supportedBits;
829 if (!suiteName.
size())
832 ciph.d->isNull =
false;
833 ciph.d->name = suiteName;
834 ciph.d->protocol = protocol;
835 ciph.d->protocolString = protocolString;
838 if (
bits.size() >= 2) {
839 if (
bits.size() == 2 ||
bits.size() == 3)
840 ciph.d->keyExchangeMethod =
"RSA"_L1;
841 else if (
bits.front() ==
"DH"_L1 ||
bits.front() ==
"DHE"_L1)
842 ciph.d->keyExchangeMethod =
"DH"_L1;
843 else if (
bits.front() ==
"ECDH"_L1 ||
bits.front() ==
"ECDHE"_L1)
844 ciph.d->keyExchangeMethod =
"ECDH"_L1;
846 qCWarning(lcSsl) <<
"Unknown Kx" << ciph.d->name;
848 if (
bits.size() == 2 ||
bits.size() == 3)
849 ciph.d->authenticationMethod =
"RSA"_L1;
850 else if (ciph.d->name.contains(
"-ECDSA-"_L1))
851 ciph.d->authenticationMethod =
"ECDSA"_L1;
852 else if (ciph.d->name.contains(
"-RSA-"_L1))
853 ciph.d->authenticationMethod =
"RSA"_L1;
855 qCWarning(lcSsl) <<
"Unknown Au" << ciph.d->name;
857 if (ciph.d->name.contains(
"RC4-"_L1)) {
858 ciph.d->encryptionMethod =
"RC4(128)"_L1;
860 ciph.d->supportedBits = 128;
861 }
else if (ciph.d->name.contains(
"DES-CBC3-"_L1)) {
862 ciph.d->encryptionMethod =
"3DES(168)"_L1;
864 ciph.d->supportedBits = 168;
865 }
else if (ciph.d->name.contains(
"AES128-"_L1)) {
866 ciph.d->encryptionMethod =
"AES(128)"_L1;
868 ciph.d->supportedBits = 128;
869 }
else if (ciph.d->name.contains(
"AES256-GCM"_L1)) {
870 ciph.d->encryptionMethod =
"AESGCM(256)"_L1;
872 ciph.d->supportedBits = 256;
873 }
else if (ciph.d->name.contains(
"AES256-"_L1)) {
874 ciph.d->encryptionMethod =
"AES(256)"_L1;
876 ciph.d->supportedBits = 256;
877 }
else if (ciph.d->name.contains(
"CHACHA20-"_L1)) {
878 ciph.d->encryptionMethod =
"CHACHA20"_L1;
880 ciph.d->supportedBits = 256;
881 }
else if (ciph.d->name.contains(
"NULL-"_L1)) {
882 ciph.d->encryptionMethod =
"NULL"_L1;
884 qCWarning(lcSsl) <<
"Unknown Enc" << ciph.d->name;
901 const QString &encryptionMethod,
902 const QString &authenticationMethod,
907 cipher.d->isNull =
false;
908 cipher.d->name =
name;
909 cipher.d->bits =
bits;
910 cipher.d->supportedBits =
bits;
911 cipher.d->keyExchangeMethod = keyExchangeMethod;
912 cipher.d->encryptionMethod = encryptionMethod;
913 cipher.d->authenticationMethod = authenticationMethod;
914 cipher.d->protocol = protocol;
915 cipher.d->protocolString = protocolString;
977void QTlsBackend::resetDefaultEllipticCurves()
997bool QTlsBackend::rootLoadingOnDemandAllowed(
const QSslConfiguration &configuration)
1039 d->configuration.peerCertificate.clear();
1040 d->configuration.peerCertificateChain.clear();
1050 d->configuration.peerSessionShared = shared;
1060 d->configuration.sslSession = asn1;
1070 d->configuration.sslSessionTicketLifeTimeHint =
hint;
1080 d->configuration.nextProtocolNegotiationStatus = st;
1090 d->configuration.nextNegotiatedProtocol = protocol;
1100 d->configuration.peerCertificate = peerCert;
1115 d->configuration.peerCertificateChain = peerChain;
1128 if (!
d->configuration.caCertificates.contains(rootCert))
1129 d->configuration.caCertificates += rootCert;
1142 d->configuration.ephemeralServerKey =
key;
1151void QTlsBackend::forceAutotestSecurityLevel()
1393 Q_UNREACHABLE_RETURN({});
1414 Q_UNREACHABLE_RETURN({});
1838TlsCryptograph::~TlsCryptograph() =
default;
1850void TlsCryptograph::checkSettingSslContext(std::shared_ptr<QSslContext> tlsContext)
1863std::shared_ptr<QSslContext> TlsCryptograph::sslContext()
const
1878void TlsCryptograph::enableHandshakeContinuation()
1889void TlsCryptograph::cancelCAFetch()
1902bool TlsCryptograph::hasUndecryptedData()
const
1936 const QString &errorDescription)
const
1939 d->setErrorAndEmit(errorCode, errorDescription);
2046DtlsBase::~DtlsBase() =
default;
2347Q_NETWORK_EXPORT
void qt_ForceTlsSecurityLevel()
2350 backend->forceAutotestSecurityLevel();
2357#include "moc_qtlsbackend_p.cpp"
SocketError
This enum describes the socket errors that can occur.
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
This class provides encryption for UDP sockets.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
The QSslCertificate class provides a convenient API for an X509 certificate.
void clear()
Clears the contents of this certificate, making it a null certificate.
The QSslCipher class represents an SSL cryptographic cipher.
bool allowRootCertOnDemandLoading
QList< QSslCertificate > peerCertificateChain
QSslCertificate peerCertificate
The QSslConfiguration class holds the configuration and state of an SSL connection.
The QSslKey class provides an interface for private and public keys.
int maximumIdentityLength
int maximumPreSharedKeyLength
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
static void setDefaultCaCertificates(const QList< QSslCertificate > &certs)
static void setDefaultDtlsCiphers(const QList< QSslCipher > &ciphers)
static QTlsBackend * tlsBackendInUse()
static void setDefaultCiphers(const QList< QSslCipher > &ciphers)
static QList< QSslCipher > defaultDtlsCiphers()
static void resetDefaultEllipticCurves()
static bool isMatchingHostname(const QSslCertificate &cert, const QString &peerName)
static QList< QSslCipher > defaultCiphers()
static void setDefaultSupportedCiphers(const QList< QSslCipher > &ciphers)
bool startsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
QString toString() const
Returns a deep copy of this string view's data as a QString.
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
constexpr QStringView sliced(qsizetype pos) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
qsizetype size() const
Returns the number of characters in this string.
QTlsBackend is a factory class, providing implementations for the QSsl classes.
virtual QList< QSslCertificate > systemCaCertificates() const
virtual QTlsPrivate::X509PemReaderPtr X509PemReader() const
virtual long tlsLibraryVersionNumber() const
virtual QList< QSsl::SupportedFeature > supportedFeatures() const =0
virtual int curveIdFromLongName(const QString &name) const
static void resetBackend(QSslKey &key, QTlsPrivate::TlsKey *keyBackend)
virtual QTlsPrivate::DtlsCryptograph * createDtlsCryptograph(class QDtls *qObject, int mode) const
static constexpr const int nameIndexSchannel
virtual QTlsPrivate::DtlsCookieVerifier * createDtlsCookieVerifier() const
static constexpr const int nameIndexSecureTransport
virtual QString shortNameForId(int cid) const
virtual QString backendName() const =0
static void setupClientPskAuth(QSslPreSharedKeyAuthenticator *auth, const char *hint, int hintLength, unsigned maxIdentityLen, unsigned maxPskLen)
virtual int dhParametersFromPem(const QByteArray &pemData, QByteArray *data) const
virtual QList< QSsl::SslProtocol > supportedProtocols() const =0
static QList< QString > availableBackendNames()
virtual QTlsPrivate::TlsCryptograph * createTlsCryptograph() const
virtual QTlsPrivate::TlsKey * createKey() const
virtual QList< QSsl::ImplementedClass > implementedClasses() const =0
virtual long tlsLibraryBuildVersionNumber() const
virtual QString longNameForId(int cid) const
virtual void ensureInitialized() const
virtual bool isTlsNamedCurve(int cid) const
static constexpr const int nameIndexOpenSSL
virtual QList< int > ellipticCurvesIds() const
virtual QTlsPrivate::X509Pkcs12ReaderPtr X509Pkcs12Reader() const
virtual QString tlsLibraryBuildVersionString() const
virtual bool isValid() const
static QString defaultBackendName()
virtual QString tlsLibraryVersionString() const
virtual int curveIdFromShortName(const QString &name) const
virtual QTlsPrivate::X509Certificate * createCertificate() const
static const QString builtinBackendNames[]
virtual QTlsPrivate::X509DerReaderPtr X509DerReader() const
static QTlsBackend * activeOrAnyBackend()
static QTlsBackend * findBackend(const QString &backendName)
virtual QTlsPrivate::X509ChainVerifyPtr X509Verifier() const
virtual int dhParametersFromDer(const QByteArray &derData, QByteArray *data) const
static void setupServerPskAuth(QSslPreSharedKeyAuthenticator *auth, const char *identity, const QByteArray &identityHint, unsigned maxPskLen)
TlsKey is an abstract class, that allows a TLS plugin to provide an underlying implementation for the...
virtual KeyType type() const =0
QByteArray pemHeader() const
QByteArray pemFooter() const
virtual KeyAlgorithm algorithm() const =0
X509Certificate is an abstract class that allows a TLS backend to provide an implementation of the QS...
virtual ~X509Certificate()
virtual TlsKey * publicKey() const
QSet< QString >::iterator it
SslProtocol
Describes the protocol of the cipher.
Combined button and popup list for selecting options.
Namespace containing onternal types that TLS backends implement.
bool(*)(QIODevice *device, QSslKey *key, QSslCertificate *cert, QList< QSslCertificate > *caCertificates, const QByteArray &passPhrase) X509Pkcs12ReaderPtr
#define Q_APPLICATION_STATIC(TYPE, NAME,...)
#define QByteArrayLiteral(str)
#define QT_WARNING_DISABLE_DEPRECATED
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define qCWarning(category,...)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define REPORT_MISSING_SUPPORT(message)