diff options
author | Martin Smith <martin.smith@nokia.com> | 2010-07-09 11:58:22 (GMT) |
---|---|---|
committer | Martin Smith <martin.smith@nokia.com> | 2010-07-09 11:58:22 (GMT) |
commit | f0900258cac9bb58ba1bfa4178e9e774408dc546 (patch) | |
tree | bf1257b5237b61a84fe5ae1b30ee4414cca6342c | |
parent | 8e1edcd846a46cf55f2f198d3b959498b58fe352 (diff) | |
parent | b1a52a071e3741d46df5c45423c6654d517ac4c2 (diff) | |
download | Qt-f0900258cac9bb58ba1bfa4178e9e774408dc546.zip Qt-f0900258cac9bb58ba1bfa4178e9e774408dc546.tar.gz Qt-f0900258cac9bb58ba1bfa4178e9e774408dc546.tar.bz2 |
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
-rw-r--r-- | src/network/ssl/qsslsocket.cpp | 6 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_openssl.cpp | 55 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_p.h | 11 |
3 files changed, 36 insertions, 36 deletions
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index 809e8aa..f85fa84 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -1849,7 +1849,7 @@ QList<QSslCipher> QSslSocketPrivate::defaultCiphers() */ QList<QSslCipher> QSslSocketPrivate::supportedCiphers() { - QSslSocketPrivate::ensureCertsAndCiphersLoaded(); + QSslSocketPrivate::ensureInitialized(); QMutexLocker locker(&globalData()->mutex); return globalData()->supportedCiphers; } @@ -1879,7 +1879,7 @@ void QSslSocketPrivate::setDefaultSupportedCiphers(const QList<QSslCipher> &ciph */ QList<QSslCertificate> QSslSocketPrivate::defaultCaCertificates() { - QSslSocketPrivate::ensureCertsAndCiphersLoaded(); + QSslSocketPrivate::ensureInitialized(); QMutexLocker locker(&globalData()->mutex); return globalData()->config->caCertificates; } @@ -1962,7 +1962,7 @@ void QSslConfigurationPrivate::setDefaultConfiguration(const QSslConfiguration & */ void QSslConfigurationPrivate::deepCopyDefaultConfiguration(QSslConfigurationPrivate *ptr) { - QSslSocketPrivate::ensureCertsAndCiphersLoaded(); + QSslSocketPrivate::ensureInitialized(); QMutexLocker locker(&globalData()->mutex); const QSslConfigurationPrivate *global = globalData()->config.constData(); diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index b602b29..b537582 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -74,9 +74,8 @@ QT_BEGIN_NAMESPACE -bool QSslSocketPrivate::s_initialized = false; -QBasicAtomicInt QSslSocketPrivate::s_CertsAndCiphersLoaded; -Q_GLOBAL_STATIC(QMutex, s_CertsAndCiphersLoadedMutex); +bool QSslSocketPrivate::s_libraryLoaded = false; +bool QSslSocketPrivate::s_loadedCiphersAndCerts = false; // Useful defines #define SSL_ERRORSTR() QString::fromLocal8Bit(q_ERR_error_string(q_ERR_get_error(), NULL)) @@ -171,7 +170,7 @@ QSslSocketBackendPrivate::QSslSocketBackendPrivate() session(0) { // Calls SSL_library_init(). - ensureCertsAndCiphersLoaded(); + ensureInitialized(); } QSslSocketBackendPrivate::~QSslSocketBackendPrivate() @@ -422,18 +421,18 @@ void QSslSocketPrivate::deinitialize() bool QSslSocketPrivate::supportsSsl() { - return ensureInitialized(); + return ensureLibraryLoaded(); } -bool QSslSocketPrivate::ensureInitialized() +bool QSslSocketPrivate::ensureLibraryLoaded() { if (!q_resolveOpenSslSymbols()) return false; // Check if the library itself needs to be initialized. QMutexLocker locker(openssl_locks()->initLock()); - if (!s_initialized) { - s_initialized = true; + if (!s_libraryLoaded) { + s_libraryLoaded = true; // Initialize OpenSSL. q_CRYPTO_set_id_callback(id_function); @@ -474,25 +473,15 @@ bool QSslSocketPrivate::ensureInitialized() return true; } -/*! - \internal - - Declared static in QSslSocketPrivate, makes sure the SSL libraries have - been initialized. -*/ - -void QSslSocketPrivate::ensureCertsAndCiphersLoaded() +void QSslSocketPrivate::ensureCiphersAndCertsLoaded() { - // use double-checked locking to speed up this function - if (s_CertsAndCiphersLoaded) + QMutexLocker locker(openssl_locks()->initLock()); + if (s_loadedCiphersAndCerts) return; + s_loadedCiphersAndCerts = true; - QMutexLocker locker(s_CertsAndCiphersLoadedMutex()); - if (s_CertsAndCiphersLoaded) - return; + resetDefaultCiphers(); - if (!supportsSsl()) - return; //load symbols needed to receive certificates from system store #if defined(Q_OS_MAC) QLibrary securityLib("/System/Library/Frameworks/Security.framework/Versions/Current/Security"); @@ -528,12 +517,22 @@ void QSslSocketPrivate::ensureCertsAndCiphersLoaded() qWarning("could not load crypt32 library"); // should never happen } #endif - resetDefaultCiphers(); setDefaultCaCertificates(systemCaCertificates()); - // we need to make sure that s_CertsAndCiphersLoaded is executed after the library loading above - // (the compiler/processor might reorder instructions otherwise) - if (!s_CertsAndCiphersLoaded.testAndSetRelease(0, 1)) - Q_ASSERT_X(false, "certificate store", "certificate store has already been initialized!"); +} + +/*! + \internal + + Declared static in QSslSocketPrivate, makes sure the SSL libraries have + been initialized. +*/ + +void QSslSocketPrivate::ensureInitialized() +{ + if (!supportsSsl()) + return; + + ensureCiphersAndCertsLoaded(); } /*! diff --git a/src/network/ssl/qsslsocket_p.h b/src/network/ssl/qsslsocket_p.h index b474175..72b3ef7 100644 --- a/src/network/ssl/qsslsocket_p.h +++ b/src/network/ssl/qsslsocket_p.h @@ -63,7 +63,6 @@ #include <QtCore/qstringlist.h> #include <private/qringbuffer_p.h> -#include <QtCore/QMutex> QT_BEGIN_NAMESPACE @@ -114,8 +113,7 @@ public: QString verificationPeerName; static bool supportsSsl(); - static bool ensureInitialized(); - static void ensureCertsAndCiphersLoaded(); + static void ensureInitialized(); static void deinitialize(); static QList<QSslCipher> defaultCiphers(); static QList<QSslCipher> supportedCiphers(); @@ -163,8 +161,11 @@ public: virtual QSslCipher sessionCipher() const = 0; private: - static bool s_initialized; - static QBasicAtomicInt s_CertsAndCiphersLoaded; + static bool ensureLibraryLoaded(); + static void ensureCiphersAndCertsLoaded(); + + static bool s_libraryLoaded; + static bool s_loadedCiphersAndCerts; }; QT_END_NAMESPACE |