From 2b78e96d2341dc0bf53ab9ccb22cfa55bf1037e0 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 20 Jan 2020 09:41:51 +0100 Subject: QNAM: Avoid compile error if QT_NO_SSL Change-Id: Iff8a0893cc7aca172c5b3f207a359762b270ed76 Reviewed-by: Jesus Fernandez --- src/network/access/qnetworkaccessmanager.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/network') diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 1f05fd931f..4c2ee138ed 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1776,6 +1776,8 @@ void QNetworkAccessManagerPrivate::_q_replyEncrypted(QNetworkReply *reply) #ifndef QT_NO_SSL Q_Q(QNetworkAccessManager); emit q->encrypted(reply); +#else + Q_UNUSED(reply); #endif } -- cgit v1.2.3 From 49f143e19ca11ef48260a3aaaa4ddbe490cf81ab Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 26 Nov 2019 23:55:01 +0100 Subject: QSslCertificate: migrate to QRegularExpression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is part of the migration of qtbase from QRexExp to QRegularExpression. If support for regular expression is disabled, fixed string can still be used. [ChangeLog][QtCore][QSslCertificate] Add overload of fromPath that does not make use of QRegExp and deprecate the QRegExp variant. Task-number: QTBUG-72587 Change-Id: I507d8941cc7d70166da0948375dc421fe5e7d967 Reviewed-by: Mårten Nordheim --- .../code/src_network_ssl_qsslcertificate.cpp | 8 ++ src/network/ssl/qsslcertificate.cpp | 107 ++++++++++++++++++++- src/network/ssl/qsslcertificate.h | 20 +++- 3 files changed, 133 insertions(+), 2 deletions(-) (limited to 'src/network') diff --git a/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp b/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp index 12691da7a2..b381ae7b6e 100644 --- a/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp +++ b/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp @@ -55,3 +55,11 @@ for (const QSslCertificate &cert : certs) { qDebug() << cert.issuerInfo(QSslCertificate::Organization); } //! [0] + +//! [1] +const auto certs = QSslCertificate::fromPath("C:/ssl/certificate.*.pem", + QSsl::Pem, QSslCertificate::Wildcard); +for (const QSslCertificate &cert : certs) { + qDebug() << cert.issuerInfo(QSslCertificate::Organization); +} +//! [1] diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index 4820953468..c179cf9c4a 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -124,7 +124,9 @@ #if QT_CONFIG(schannel) #include "qsslsocket_schannel_p.h" #endif - +#if QT_CONFIG(regularexpression) +#include "qregularexpression.h" +#endif #include "qssl_p.h" #include "qsslcertificate.h" #include "qsslcertificate_p.h" @@ -462,7 +464,10 @@ QByteArray QSslCertificate::digest(QCryptographicHash::Algorithm algorithm) cons \since 5.0 */ +#if QT_DEPRECATED_SINCE(5,15) /*! + \obsolete + Searches all files in the \a path for certificates encoded in the specified \a format and returns them in a list. \a path must be a file or a pattern matching one or more files, as specified by \a syntax. @@ -537,6 +542,106 @@ QList QSslCertificate::fromPath(const QString &path, } return certs; } +#endif // QT_DEPRECATED_SINCE(5,15) + +/*! + \since 5.15 + + Searches all files in the \a path for certificates encoded in the + specified \a format and returns them in a list. \a path must be a file + or a pattern matching one or more files, as specified by \a syntax. + + Example: + + \snippet code/src_network_ssl_qsslcertificate.cpp 1 + + \sa fromData() +*/ +QList QSslCertificate::fromPath(const QString &path, + QSsl::EncodingFormat format, + PatternSyntax syntax) +{ + // $, (,), *, +, ., ?, [, ,], ^, {, | and }. + + // make sure to use the same path separators on Windows and Unix like systems. + QString sourcePath = QDir::fromNativeSeparators(path); + + // Find the path without the filename + QString pathPrefix = sourcePath.left(sourcePath.lastIndexOf(QLatin1Char('/'))); + + // Check if the path contains any special chars + int pos = -1; + +#if QT_CONFIG(regularexpression) + if (syntax == Wildcard) + pos = pathPrefix.indexOf(QRegularExpression(QLatin1String("[*?[]"))); + else if (syntax == RegExp) + pos = sourcePath.indexOf(QRegularExpression(QLatin1String("[\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\}\\|]"))); +#else + if (syntax == Wildcard || syntax == RegExp) + qWarning("Regular expression support is disabled in this build. Only fixed string can be searched"); + return QList(); +#endif + + if (pos != -1) { + // there was a special char in the path so cut of the part containing that char. + pathPrefix = pathPrefix.left(pos); + const int lastIndexOfSlash = pathPrefix.lastIndexOf(QLatin1Char('/')); + if (lastIndexOfSlash != -1) + pathPrefix = pathPrefix.left(lastIndexOfSlash); + else + pathPrefix.clear(); + } else { + // Check if the path is a file. + if (QFileInfo(sourcePath).isFile()) { + QFile file(sourcePath); + QIODevice::OpenMode openMode = QIODevice::ReadOnly; + if (format == QSsl::Pem) + openMode |= QIODevice::Text; + if (file.open(openMode)) + return QSslCertificate::fromData(file.readAll(), format); + return QList(); + } + } + + // Special case - if the prefix ends up being nothing, use "." instead. + int startIndex = 0; + if (pathPrefix.isEmpty()) { + pathPrefix = QLatin1String("."); + startIndex = 2; + } + + // The path can be a file or directory. + QList certs; + +#if QT_CONFIG(regularexpression) + if (syntax == Wildcard) + sourcePath = QRegularExpression::wildcardToRegularExpression(sourcePath); + + QRegularExpression pattern(QRegularExpression::anchoredPattern(sourcePath)); +#endif + + QDirIterator it(pathPrefix, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); + while (it.hasNext()) { + QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex); + +#if QT_CONFIG(regularexpression) + if (!pattern.match(filePath).hasMatch()) + continue; +#else + if (sourcePath != filePath) + continue; +#endif + + QFile file(filePath); + QIODevice::OpenMode openMode = QIODevice::ReadOnly; + if (format == QSsl::Pem) + openMode |= QIODevice::Text; + if (file.open(openMode)) + certs += QSslCertificate::fromData(file.readAll(), format); + } + return certs; +} /*! Searches for and parses all certificates in \a device that are diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h index 69901b526c..9993769888 100644 --- a/src/network/ssl/qsslcertificate.h +++ b/src/network/ssl/qsslcertificate.h @@ -84,6 +84,13 @@ public: EmailAddress }; + enum PatternSyntax { + RegExp, + Wildcard, + FixedString + }; + + explicit QSslCertificate(QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem); explicit QSslCertificate(const QByteArray &data = QByteArray(), QSsl::EncodingFormat format = QSsl::Pem); QSslCertificate(const QSslCertificate &other); @@ -139,9 +146,20 @@ public: QByteArray toDer() const; QString toText() const; - static QList fromPath( +#if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_X("Use the overload not using QRegExp") static QList fromPath( const QString &path, QSsl::EncodingFormat format = QSsl::Pem, QRegExp::PatternSyntax syntax = QRegExp::FixedString); + + static QList fromPath( + const QString &path, QSsl::EncodingFormat format, + PatternSyntax syntax); +#else + static QList fromPath( + const QString &path, QSsl::EncodingFormat format = QSsl::Pem, + PatternSyntax syntax = FixedString); +#endif + static QList fromDevice( QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem); static QList fromData( -- cgit v1.2.3 From 2e377f29481475e938ab5a1e5857a1d3a88fa397 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 25 Jan 2020 20:16:02 +0100 Subject: Doc/QtBase: replace some 0 with \nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace some 'is 0' or 'are 0' where 0 referes to a nullptr with 'is \nullptr' and 'are \nullptr' Change-Id: Ida9af2971924377efe2f49f435d79e109de2bdf4 Reviewed-by: André Hartmann Reviewed-by: Sze Howe Koh --- src/network/access/qftp.cpp | 2 +- src/network/socket/qudpsocket.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/network') diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index 62ae1adbd9..66dd3f9371 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -1820,7 +1820,7 @@ int QFtp::cd(const QString &dir) \internal Downloads the file \a file from the server. - If \a dev is 0, then the readyRead() signal is emitted when there + If \a dev is \nullptr, then the readyRead() signal is emitted when there is data available to read. You can then read the data with the read() or readAll() functions. diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp index 0e3d516535..9694dfa507 100644 --- a/src/network/socket/qudpsocket.cpp +++ b/src/network/socket/qudpsocket.cpp @@ -479,7 +479,7 @@ QNetworkDatagram QUdpSocket::receiveDatagram(qint64 maxSize) /*! Receives a datagram no larger than \a maxSize bytes and stores it in \a data. The sender's host address and port is stored in - *\a address and *\a port (unless the pointers are 0). + *\a address and *\a port (unless the pointers are \nullptr). Returns the size of the datagram on success; otherwise returns -1. -- cgit v1.2.3