summaryrefslogtreecommitdiffstats
path: root/src/network/ssl
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-08-22 11:30:00 +0200
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-08-22 11:30:01 +0200
commitd314819fc02139e05e16c56657898c704f7fb48f (patch)
treea61ba968233634948401c8339f9613844de1c2b5 /src/network/ssl
parent9f888d2fde9c5413e5519e0914e9b13638760985 (diff)
parente0e9e196a72ffe5457034894eaaadc90ed0d34ef (diff)
Merge dev into 5.8
Diffstat (limited to 'src/network/ssl')
-rw-r--r--src/network/ssl/qsslcontext_openssl.cpp2
-rw-r--r--src/network/ssl/qssldiffiehellmanparameters.cpp66
-rw-r--r--src/network/ssl/qssldiffiehellmanparameters.h13
-rw-r--r--src/network/ssl/qsslsocket.cpp2
-rw-r--r--src/network/ssl/qsslsocket_mac.cpp4
-rw-r--r--src/network/ssl/qsslsocket_mac_p.h4
-rw-r--r--src/network/ssl/ssl.pri6
7 files changed, 57 insertions, 40 deletions
diff --git a/src/network/ssl/qsslcontext_openssl.cpp b/src/network/ssl/qsslcontext_openssl.cpp
index dec8e12abb..c92d8fc3f8 100644
--- a/src/network/ssl/qsslcontext_openssl.cpp
+++ b/src/network/ssl/qsslcontext_openssl.cpp
@@ -320,7 +320,7 @@ init_context:
}
if (!dhparams.isEmpty()) {
- const QByteArray &params = dhparams.d.data()->derData;
+ const QByteArray &params = dhparams.d->derData;
const char *ptr = params.constData();
DH *dh = q_d2i_DHparams(NULL, reinterpret_cast<const unsigned char **>(&ptr), params.length());
if (dh == NULL)
diff --git a/src/network/ssl/qssldiffiehellmanparameters.cpp b/src/network/ssl/qssldiffiehellmanparameters.cpp
index e75ffe4da5..d0fcb3189a 100644
--- a/src/network/ssl/qssldiffiehellmanparameters.cpp
+++ b/src/network/ssl/qssldiffiehellmanparameters.cpp
@@ -77,7 +77,7 @@ QT_BEGIN_NAMESPACE
QSslDiffieHellmanParameters QSslDiffieHellmanParameters::defaultParameters()
{
// The 1024-bit MODP group from RFC 2459 (Second Oakley Group)
- return QSslDiffieHellmanParameters(
+ return fromEncoded(
QByteArray::fromBase64(QByteArrayLiteral(
"MIGHAoGBAP//////////yQ/aoiFowjTExmKLgNwc0SkCTgiKZ8x0Agu+pjsTmyJR"
"Sgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHCReSFtXZiXn7G9ExC6aY37WsL"
@@ -100,73 +100,82 @@ QSslDiffieHellmanParameters QSslDiffieHellmanParameters::defaultParameters()
QSslDiffieHellmanParameters::QSslDiffieHellmanParameters()
: d(new QSslDiffieHellmanParametersPrivate)
{
+ d->ref.ref();
}
/*!
Constructs a QSslDiffieHellmanParameters object using
the byte array \a encoded in either PEM or DER form as specified by \a encoding.
- After construction, the isValid() method should be used to
+ Use the isValid() method on the returned object to
check whether the Diffie-Hellman parameters were valid and
loaded correctly.
\sa isValid()
\sa QSslConfiguration
*/
-QSslDiffieHellmanParameters::QSslDiffieHellmanParameters(const QByteArray &encoded, QSsl::EncodingFormat encoding)
- : d(new QSslDiffieHellmanParametersPrivate)
+QSslDiffieHellmanParameters QSslDiffieHellmanParameters::fromEncoded(const QByteArray &encoded, QSsl::EncodingFormat encoding)
{
+ QSslDiffieHellmanParameters result;
switch (encoding) {
case QSsl::Der:
- d->decodeDer(encoded);
+ result.d->decodeDer(encoded);
break;
case QSsl::Pem:
- d->decodePem(encoded);
+ result.d->decodePem(encoded);
break;
}
+ return result;
}
/*!
Constructs a QSslDiffieHellmanParameters object by
reading from \a device in either PEM or DER form as specified by \a encoding.
- After construction, the isValid() method should be used
+ Use the isValid() method on the returned object
to check whether the Diffie-Hellman parameters were valid
and loaded correctly.
+ In particular, if \a device is \c nullptr or not open for reading, an invalid
+ object will be returned.
+
\sa isValid()
\sa QSslConfiguration
*/
-QSslDiffieHellmanParameters::QSslDiffieHellmanParameters(QIODevice *device, QSsl::EncodingFormat encoding)
- : d(new QSslDiffieHellmanParametersPrivate)
+QSslDiffieHellmanParameters QSslDiffieHellmanParameters::fromEncoded(QIODevice *device, QSsl::EncodingFormat encoding)
{
- if (!device)
- return;
-
- const QByteArray encoded = device->readAll();
-
- switch (encoding) {
- case QSsl::Der:
- d->decodeDer(encoded);
- break;
- case QSsl::Pem:
- d->decodePem(encoded);
- break;
- }
+ if (device)
+ return fromEncoded(device->readAll(), encoding);
+ else
+ return QSslDiffieHellmanParameters();
}
/*!
Constructs an identical copy of \a other.
*/
-QSslDiffieHellmanParameters::QSslDiffieHellmanParameters(const QSslDiffieHellmanParameters &other) : d(other.d)
+QSslDiffieHellmanParameters::QSslDiffieHellmanParameters(const QSslDiffieHellmanParameters &other)
+ : d(other.d)
{
+ if (d)
+ d->ref.ref();
}
/*!
+ \fn QSslDiffieHellmanParameters(QSslDiffieHellmanParameters &&other)
+
+ Move-constructs from \a other.
+
+ \note The moved-from object \a other is placed in a partially-formed state, in which
+ the only valid operations are destruction and assignment of a new value.
+*/
+
+/*!
Destroys the QSslDiffieHellmanParameters object.
*/
QSslDiffieHellmanParameters::~QSslDiffieHellmanParameters()
{
+ if (d && !d->ref.deref())
+ delete d;
}
/*!
@@ -177,7 +186,8 @@ QSslDiffieHellmanParameters::~QSslDiffieHellmanParameters()
*/
QSslDiffieHellmanParameters &QSslDiffieHellmanParameters::operator=(const QSslDiffieHellmanParameters &other)
{
- d = other.d;
+ QSslDiffieHellmanParameters copy(other);
+ swap(copy);
return *this;
}
@@ -185,6 +195,9 @@ QSslDiffieHellmanParameters &QSslDiffieHellmanParameters::operator=(const QSslDi
\fn QSslDiffieHellmanParameters &QSslDiffieHellmanParameters::operator=(QSslDiffieHellmanParameters &&other)
Move-assigns \a other to this QSslDiffieHellmanParameters instance.
+
+ \note The moved-from object \a other is placed in a partially-formed state, in which
+ the only valid operations are destruction and assignment of a new value.
*/
/*!
@@ -265,6 +278,7 @@ QString QSslDiffieHellmanParameters::errorString() const Q_DECL_NOTHROW
}
/*!
+ \since 5.8
\relates QSslDiffieHellmanParameters
Returns \c true if \a lhs is equal to \a rhs; otherwise returns \c false.
@@ -276,6 +290,7 @@ bool operator==(const QSslDiffieHellmanParameters &lhs, const QSslDiffieHellmanP
#ifndef QT_NO_DEBUG_STREAM
/*!
+ \since 5.8
\relates QSslDiffieHellmanParameters
Writes the set of Diffie-Hellman parameters in \a dhparam into the debug object \a debug for
@@ -295,7 +310,8 @@ QDebug operator<<(QDebug debug, const QSslDiffieHellmanParameters &dhparam)
#endif
/*!
- \relates QHash
+ \since 5.8
+ \relates QSslDiffieHellmanParameters
Returns an hash value for \a dhparam, using \a seed to seed
the calculation.
diff --git a/src/network/ssl/qssldiffiehellmanparameters.h b/src/network/ssl/qssldiffiehellmanparameters.h
index aa40be83a6..4533ea4ed2 100644
--- a/src/network/ssl/qssldiffiehellmanparameters.h
+++ b/src/network/ssl/qssldiffiehellmanparameters.h
@@ -82,24 +82,25 @@ public:
Q_NETWORK_EXPORT static QSslDiffieHellmanParameters defaultParameters();
Q_NETWORK_EXPORT QSslDiffieHellmanParameters();
- Q_NETWORK_EXPORT explicit QSslDiffieHellmanParameters(const QByteArray &encoded, QSsl::EncodingFormat format = QSsl::Pem);
- Q_NETWORK_EXPORT explicit QSslDiffieHellmanParameters(QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem);
Q_NETWORK_EXPORT QSslDiffieHellmanParameters(const QSslDiffieHellmanParameters &other);
+ QSslDiffieHellmanParameters(QSslDiffieHellmanParameters &&other) Q_DECL_NOTHROW : d(other.d) { other.d = nullptr; }
Q_NETWORK_EXPORT ~QSslDiffieHellmanParameters();
+
Q_NETWORK_EXPORT QSslDiffieHellmanParameters &operator=(const QSslDiffieHellmanParameters &other);
-#ifdef Q_COMPILER_RVALUE_REFS
QSslDiffieHellmanParameters &operator=(QSslDiffieHellmanParameters &&other) Q_DECL_NOTHROW { swap(other); return *this; }
-#endif
void swap(QSslDiffieHellmanParameters &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ Q_NETWORK_EXPORT static QSslDiffieHellmanParameters fromEncoded(const QByteArray &encoded, QSsl::EncodingFormat format = QSsl::Pem);
+ Q_NETWORK_EXPORT static QSslDiffieHellmanParameters fromEncoded(QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem);
+
Q_NETWORK_EXPORT bool isEmpty() const Q_DECL_NOTHROW;
Q_NETWORK_EXPORT bool isValid() const Q_DECL_NOTHROW;
- Q_NETWORK_EXPORT QSslDiffieHellmanParameters::Error error() const Q_DECL_NOTHROW;
+ Q_NETWORK_EXPORT Error error() const Q_DECL_NOTHROW;
Q_NETWORK_EXPORT QString errorString() const Q_DECL_NOTHROW;
private:
- QExplicitlySharedDataPointer<QSslDiffieHellmanParametersPrivate> d;
+ QSslDiffieHellmanParametersPrivate *d;
friend class QSslContext;
friend Q_NETWORK_EXPORT bool operator==(const QSslDiffieHellmanParameters &lhs, const QSslDiffieHellmanParameters &rhs) Q_DECL_NOTHROW;
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index 2371dd7212..29e1f32815 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -142,7 +142,7 @@
addDefaultCaCertificates(), and QSslConfiguration::defaultConfiguration().setCaCertificates().
\endlist
- \note If available, root certificates on Unix (excluding OS X) will be
+ \note If available, root certificates on Unix (excluding \macos) will be
loaded on demand from the standard certificate directories. If you do not
want to load root certificates on demand, you need to call either
QSslConfiguration::defaultConfiguration().setCaCertificates() before the first
diff --git a/src/network/ssl/qsslsocket_mac.cpp b/src/network/ssl/qsslsocket_mac.cpp
index 438ea9a38e..4c06404415 100644
--- a/src/network/ssl/qsslsocket_mac.cpp
+++ b/src/network/ssl/qsslsocket_mac.cpp
@@ -204,7 +204,7 @@ bool QSslSocketPrivate::s_loadedCiphersAndCerts = false;
bool QSslSocketPrivate::s_loadRootCertsOnDemand = false;
-#if !defined(QT_PLATFORM_UIKIT) // dhparam is not used on iOS or tvOS. (see the SSLSetDiffieHellmanParams call below)
+#if !defined(QT_PLATFORM_UIKIT) // dhparam is only used on macOS. (see the SSLSetDiffieHellmanParams call below)
static const uint8_t dhparam[] =
"\x30\x82\x01\x08\x02\x82\x01\x01\x00\x97\xea\xd0\x46\xf7\xae\xa7\x76\x80"
"\x9c\x74\x56\x98\xd8\x56\x97\x2b\x20\x6c\x77\xe2\x82\xbb\xc8\x84\xbe\xe7"
@@ -223,7 +223,7 @@ static const uint8_t dhparam[] =
"\x90\x0b\x35\x64\xff\xd9\xe3\xac\xf2\xf2\xeb\x3a\x63\x02\x01\x02";
#endif
-// No ioErr on iOS/tvOS. (defined in MacErrors.h on OS X)
+// No ioErr on iOS/tvOS/watchOS. (defined in MacErrors.h on macOS)
#if defined(QT_PLATFORM_UIKIT)
# define ioErr -36
#endif
diff --git a/src/network/ssl/qsslsocket_mac_p.h b/src/network/ssl/qsslsocket_mac_p.h
index 5210fb7f30..9e1d18981e 100644
--- a/src/network/ssl/qsslsocket_mac_p.h
+++ b/src/network/ssl/qsslsocket_mac_p.h
@@ -75,7 +75,7 @@ public:
private:
SSLContextRef context;
- Q_DISABLE_COPY(QSecureTransportContext);
+ Q_DISABLE_COPY(QSecureTransportContext)
};
class QSslSocketBackendPrivate : public QSslSocketPrivate
@@ -122,7 +122,7 @@ private:
QSecureTransportContext context;
- Q_DISABLE_COPY(QSslSocketBackendPrivate);
+ Q_DISABLE_COPY(QSslSocketBackendPrivate)
};
QT_END_NAMESPACE
diff --git a/src/network/ssl/ssl.pri b/src/network/ssl/ssl.pri
index edbbeadf51..8139af50af 100644
--- a/src/network/ssl/ssl.pri
+++ b/src/network/ssl/ssl.pri
@@ -1,5 +1,5 @@
# OpenSSL support; compile in QSslSocket.
-contains(QT_CONFIG, ssl) {
+qtConfig(ssl) {
HEADERS += ssl/qasn1element_p.h \
ssl/qssl.h \
ssl/qssl_p.h \
@@ -45,7 +45,7 @@ contains(QT_CONFIG, ssl) {
ssl/qsslellipticcurve_dummy.cpp
}
- contains(QT_CONFIG, securetransport) {
+ qtConfig(securetransport) {
HEADERS += ssl/qsslsocket_mac_p.h
SOURCES += ssl/qsslcertificate_qt.cpp \
ssl/qssldiffiehellmanparameters_dummy.cpp \
@@ -56,7 +56,7 @@ contains(QT_CONFIG, ssl) {
ssl/qsslellipticcurve_dummy.cpp
}
- contains(QT_CONFIG, openssl) | contains(QT_CONFIG, openssl-linked) {
+ qtConfig(openssl)|qtConfig(openssl-linked) {
HEADERS += ssl/qsslcontext_openssl_p.h \
ssl/qsslsocket_openssl_p.h \
ssl/qsslsocket_openssl_symbols_p.h