From add9e1afd5a4ec7eb104a7cd111429037740a0a0 Mon Sep 17 00:00:00 2001 From: Michael Marley Date: Sun, 25 Mar 2018 22:11:39 -0400 Subject: [PATCH] SslServer: Add support for Elliptic Curve keys If the key won't load as an RSA key, attempt to load it again as an EC key. DSA support was not added because DSA is obsolete and no- one should be using it. Note that this only works with Qt5.5 and up as EC support was added in that version (https://github.com/qt/qtbase/commit/962ea569). An if macro has been used to allow for continued compilation under Qt4 and Qt5<5.5. Closes GH-344. (cherry picked from commit d31101ed316b6449de0d8dad7a1e1e8d097807a5) --- src/core/sslserver.cpp | 22 +++++++++++++++++++--- src/core/sslserver.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/core/sslserver.cpp b/src/core/sslserver.cpp index 1daa7706..5a5be5ce 100644 --- a/src/core/sslserver.cpp +++ b/src/core/sslserver.cpp @@ -25,7 +25,6 @@ #endif #include -#include #include "logger.h" #include "quassel.h" @@ -182,10 +181,10 @@ bool SslServer::setCertificate(const QString &path, const QString &keyPath) return false; } - untestedKey = QSslKey(&keyFile, QSsl::Rsa); + untestedKey = loadKey(&keyFile); keyFile.close(); } else { - untestedKey = QSslKey(&certFile, QSsl::Rsa); + untestedKey = loadKey(&certFile); } certFile.close(); @@ -227,4 +226,21 @@ bool SslServer::setCertificate(const QString &path, const QString &keyPath) } +QSslKey SslServer::loadKey(QFile *keyFile) +{ + QSslKey key; + key = QSslKey(keyFile, QSsl::Rsa); +#if QT_VERSION >= 0x050500 + if (key.isNull()) { + if (!keyFile->reset()) { + quWarning() << "SslServer: IO error reading key file"; + return key; + } + key = QSslKey(keyFile, QSsl::Ec); + } +#endif + return key; +} + + #endif // HAVE_SSL diff --git a/src/core/sslserver.h b/src/core/sslserver.h index b0f92b58..cf04c53d 100644 --- a/src/core/sslserver.h +++ b/src/core/sslserver.h @@ -27,6 +27,7 @@ #include #include #include +#include class SslServer : public QTcpServer { @@ -71,6 +72,7 @@ private: * @return True if certificates loaded successfully, otherwise false. */ bool loadCerts(); + QSslKey loadKey(QFile *keyFile); QLinkedList _pendingConnections; QSslCertificate _cert; -- 2.20.1