From 30d199a76c7d30d9d70eb6cd7594826e7bf6de61 Mon Sep 17 00:00:00 2001 From: "Richard J. Moore" Date: Sat, 18 Jan 2014 17:17:33 +0000 Subject: [PATCH] Fix the QSslSocket::setCiphers(const QString &) overload. The overload used an evil hack to work around a flaw in the QSslCipher API rather than fixing the API. The hack was broken by the addition of support for newer versions of TLS. This change solves the issue properly by fixing the QSslCipher API then using the fixed version. Task-Number: QTBUG-34688 Change-Id: Ibf677c374f837f705395741e730d40d8f912d7c6 Reviewed-by: Peter Hartmann --- src/network/ssl/qsslcipher.cpp | 20 ++++++++++++++++++++ src/network/ssl/qsslcipher.h | 1 + src/network/ssl/qsslsocket.cpp | 9 +++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/network/ssl/qsslcipher.cpp b/src/network/ssl/qsslcipher.cpp index cdb0ed9063..bb5d93e528 100644 --- a/src/network/ssl/qsslcipher.cpp +++ b/src/network/ssl/qsslcipher.cpp @@ -77,6 +77,26 @@ QSslCipher::QSslCipher() { } +/*! + Constructs a QSslCipher object for the cipher determined by \a + name. The constructor accepts only supported ciphers (i.e., the + \a name must identify a cipher in the list of ciphers returned by + QSslSocket::supportedCiphers()). + + You can call isNull() after construction to check if \a name + correctly identified a supported cipher. +*/ +QSslCipher::QSslCipher(const QString &name) + : d(new QSslCipherPrivate) +{ + foreach (const QSslCipher &cipher, QSslSocket::supportedCiphers()) { + if (cipher.name() == name) { + *this = cipher; + return; + } + } +} + /*! Constructs a QSslCipher object for the cipher determined by \a name and \a protocol. The constructor accepts only supported diff --git a/src/network/ssl/qsslcipher.h b/src/network/ssl/qsslcipher.h index e351d7949b..4cebffa7ae 100644 --- a/src/network/ssl/qsslcipher.h +++ b/src/network/ssl/qsslcipher.h @@ -57,6 +57,7 @@ class Q_NETWORK_EXPORT QSslCipher { public: QSslCipher(); + QSslCipher(const QString &name); QSslCipher(const QString &name, QSsl::SslProtocol protocol); QSslCipher(const QSslCipher &other); ~QSslCipher(); diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 0f934fa5d6..e107d94cf2 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -1195,12 +1195,9 @@ void QSslSocket::setCiphers(const QString &ciphers) Q_D(QSslSocket); d->configuration.ciphers.clear(); foreach (const QString &cipherName, ciphers.split(QLatin1String(":"),QString::SkipEmptyParts)) { - for (int i = 0; i < 3; ++i) { - // ### Crude - QSslCipher cipher(cipherName, QSsl::SslProtocol(i)); - if (!cipher.isNull()) - d->configuration.ciphers << cipher; - } + QSslCipher cipher(cipherName); + if (!cipher.isNull()) + d->configuration.ciphers << cipher; } }