diff --git a/src/murmur/Cert.cpp b/src/murmur/Cert.cpp index b16351b57..5c5a37c8c 100644 --- a/src/murmur/Cert.cpp +++ b/src/murmur/Cert.cpp @@ -70,6 +70,18 @@ bool Server::isKeyForCert(const QSslKey &key, const QSslCertificate &cert) { return false; } +QSslKey Server::privateKeyFromPEM(const QByteArray &buf, const QByteArray &pass) { + QSslKey key; + key = QSslKey(buf, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, pass); + if (key.isNull()) + key = QSslKey(buf, QSsl::Dsa, QSsl::Pem, QSsl::PrivateKey, pass); +#if QT_VERSION >= 0x050000 + if (key.isNull()) + key = QSslKey(buf, QSsl::Ec, QSsl::Pem, QSsl::PrivateKey, pass); +#endif + return key; +} + void Server::initializeCert() { QByteArray crt, key, pass, dhparams; diff --git a/src/murmur/Server.h b/src/murmur/Server.h index b8cddf433..0d4d9ef73 100644 --- a/src/murmur/Server.h +++ b/src/murmur/Server.h @@ -169,6 +169,11 @@ class Server : public QThread { // Certificate stuff, implemented partially in Cert.cpp public: static bool isKeyForCert(const QSslKey &key, const QSslCertificate &cert); + /// Attempt to load a private key in PEM format from |buf|. + /// If |passphrase| is non-empty, it will be used for decrypting the private key in |buf|. + /// If a valid RSA, DSA or EC key is found, it is returned. + /// If no valid private key is found, a null QSslKey is returned. + static QSslKey privateKeyFromPEM(const QByteArray &buf, const QByteArray &pass = QByteArray()); void initializeCert(); const QString getDigest() const;