diff options
author | Richard Moore <rich@kde.org> | 2011-07-11 10:47:16 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-11 12:43:52 +0200 |
commit | c82af87b5375eacaabc81b8fe7e75f83d27bc6e5 (patch) | |
tree | 1917d5558536cfecb853fc51d1aa17bc2cb23864 | |
parent | d9bec0a1d2d7ac18a9a8ae5eff8dd8204eb6bf70 (diff) |
QSslSocket: Add accessors for SSL version
This commit adds accessors for both the openssl version number and the
version string. The intention here is to aid debugging by making it
possible for applications to know which version of the openssl library
has been found by the runtime linking code.
Since the version of openssl in use will depend on the installation of
the developer, the test cases merely display the version string and
number rather than verifying that any particular version is in use.
Change-Id: Ieec44f0941f99887c85c2858bab0481722d739e5
Merge-request: 12
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/1406
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
-rw-r--r-- | src/network/ssl/qsslsocket.cpp | 21 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket.h | 3 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_openssl.cpp | 17 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_openssl_symbols.cpp | 2 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_openssl_symbols_p.h | 1 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qsslsocket/tst_qsslsocket.cpp | 10 |
7 files changed, 56 insertions, 0 deletions
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index f191ed9324..20e520a3d5 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -1599,6 +1599,27 @@ bool QSslSocket::supportsSsl() } /*! + Returns the version number of the SSL library in use. Note that + this is the version of the library in use at run-time not compile + time. If no SSL support is available then this will return an + undefined value. +*/ +long QSslSocket::sslLibraryVersionNumber() +{ + return QSslSocketPrivate::opensslVersionNumber(); +} + +/*! + Returns the version string of the SSL library in use. Note that + this is the version of the library in use at run-time not compile + time. If no SSL support is available then this will return an empty value. +*/ +QString QSslSocket::sslLibraryVersionString() +{ + return QSslSocketPrivate::opensslVersionString(); +} + +/*! Starts a delayed SSL handshake for a client connection. This function can be called when the socket is in the \l ConnectedState but still in the \l UnencryptedMode. If it is not yet connected, diff --git a/src/network/ssl/qsslsocket.h b/src/network/ssl/qsslsocket.h index f175ffd946..803e79e0c4 100644 --- a/src/network/ssl/qsslsocket.h +++ b/src/network/ssl/qsslsocket.h @@ -176,6 +176,9 @@ public: QList<QSslError> sslErrors() const; static bool supportsSsl(); + static long sslLibraryVersionNumber(); + static QString sslLibraryVersionString(); + void ignoreSslErrors(const QList<QSslError> &errors); public Q_SLOTS: diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index 479a6bd60e..b87570b7bf 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -602,6 +602,23 @@ void QSslSocketPrivate::ensureInitialized() ensureCiphersAndCertsLoaded(); } +long QSslSocketPrivate::opensslVersionNumber() +{ + return q_SSLeay(); +} + +QString QSslSocketPrivate::opensslVersionString() +{ + if (!supportsSsl()) + return QString(); + + const char *versionString = q_SSLeay_version(SSLEAY_VERSION); + if (!versionString) + return QString(); + + return QString::fromLatin1(versionString); +} + /*! \internal diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp index b652833b45..18a845b312 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols.cpp +++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp @@ -276,6 +276,7 @@ DEFINEFUNC(void, OPENSSL_add_all_algorithms_noconf, void, DUMMYARG, return, DUMM DEFINEFUNC(void, OPENSSL_add_all_algorithms_conf, void, DUMMYARG, return, DUMMYARG) DEFINEFUNC3(int, SSL_CTX_load_verify_locations, SSL_CTX *ctx, ctx, const char *CAfile, CAfile, const char *CApath, CApath, return 0, return) DEFINEFUNC(long, SSLeay, void, DUMMYARG, return 0, return) +DEFINEFUNC(const char *, SSLeay_version, int a, a, return 0, return) #ifdef Q_OS_SYMBIAN #define RESOLVEFUNC(func, ordinal, lib) \ @@ -788,6 +789,7 @@ bool q_resolveOpenSslSymbols() RESOLVEFUNC(OPENSSL_add_all_algorithms_conf) RESOLVEFUNC(SSL_CTX_load_verify_locations) RESOLVEFUNC(SSLeay) + RESOLVEFUNC(SSLeay_version) #endif // Q_OS_SYMBIAN symbolsResolved = true; delete libs.first; diff --git a/src/network/ssl/qsslsocket_openssl_symbols_p.h b/src/network/ssl/qsslsocket_openssl_symbols_p.h index 658aa144a7..12b3890512 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols_p.h +++ b/src/network/ssl/qsslsocket_openssl_symbols_p.h @@ -426,6 +426,7 @@ void q_OPENSSL_add_all_algorithms_noconf(); void q_OPENSSL_add_all_algorithms_conf(); int q_SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, const char *CApath); long q_SSLeay(); +const char *q_SSLeay_version(int type); // Helper function class QDateTime; diff --git a/src/network/ssl/qsslsocket_p.h b/src/network/ssl/qsslsocket_p.h index 86ecba07ce..c8ab820639 100644 --- a/src/network/ssl/qsslsocket_p.h +++ b/src/network/ssl/qsslsocket_p.h @@ -116,6 +116,8 @@ public: bool allowRootCertOnDemandLoading; static bool supportsSsl(); + static long opensslVersionNumber(); + static QString opensslVersionString(); static void ensureInitialized(); static void deinitialize(); static QList<QSslCipher> defaultCiphers(); diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp index 5070d4b043..8b3ec3d31e 100644 --- a/tests/auto/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp @@ -191,6 +191,7 @@ private slots: void writeBigChunk(); void blacklistedCertificates(); void setEmptyDefaultConfiguration(); + void versionAccessors(); static void exitLoop() { @@ -2049,6 +2050,15 @@ void tst_QSslSocket::setEmptyDefaultConfiguration() QVERIFY2(!socket->waitForEncrypted(4000), qPrintable(socket->errorString())); } +void tst_QSslSocket::versionAccessors() +{ + if (!QSslSocket::supportsSsl()) + return; + + qDebug() << QSslSocket::sslLibraryVersionString(); + qDebug() << QString::number(QSslSocket::sslLibraryVersionNumber(), 16); +} + #endif // QT_NO_OPENSSL QTEST_MAIN(tst_QSslSocket) |