diff options
Diffstat (limited to 'src/murmur/Cert.cpp')
-rw-r--r-- | src/murmur/Cert.cpp | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/src/murmur/Cert.cpp b/src/murmur/Cert.cpp index 52adf638c..c9f140564 100644 --- a/src/murmur/Cert.cpp +++ b/src/murmur/Cert.cpp @@ -6,31 +6,31 @@ #include <QtCore/QtGlobal> #ifdef Q_OS_WIN -# include "win.h" +# include "win.h" #endif #include "Meta.h" -#include "Server.h" #include "SelfSignedCertificate.h" +#include "Server.h" #include <openssl/err.h> #include <openssl/evp.h> #include <openssl/x509.h> #ifdef Q_OS_WIN -# include <winsock2.h> +# include <winsock2.h> #endif bool Server::isKeyForCert(const QSslKey &key, const QSslCertificate &cert) { if (key.isNull() || cert.isNull() || (key.type() != QSsl::PrivateKey)) return false; - QByteArray qbaKey = key.toDer(); + QByteArray qbaKey = key.toDer(); QByteArray qbaCert = cert.toDer(); - X509 *x509 = nullptr; + X509 *x509 = nullptr; EVP_PKEY *pkey = nullptr; - BIO *mem = nullptr; + BIO *mem = nullptr; mem = BIO_new_mem_buf(qbaKey.data(), qbaKey.size()); Q_UNUSED(BIO_set_close(mem, BIO_NOCLOSE)); @@ -80,30 +80,30 @@ void Server::initializeCert() { qsdhpDHParams = QSslDiffieHellmanParameters(); #endif - crt = getConf("certificate", QString()).toByteArray(); - key = getConf("key", QString()).toByteArray(); - pass = getConf("passphrase", QByteArray()).toByteArray(); + crt = getConf("certificate", QString()).toByteArray(); + key = getConf("key", QString()).toByteArray(); + pass = getConf("passphrase", QByteArray()).toByteArray(); dhparams = getConf("sslDHParams", Meta::mp.qbaDHParams).toByteArray(); - QList<QSslCertificate> ql; + QList< QSslCertificate > ql; // Attempt to load the private key. - if (! key.isEmpty()) { + if (!key.isEmpty()) { qskKey = Server::privateKeyFromPEM(key, pass); } // If we still can't load the key, try loading any keys from the certificate - if (qskKey.isNull() && ! crt.isEmpty()) { + if (qskKey.isNull() && !crt.isEmpty()) { qskKey = Server::privateKeyFromPEM(crt); } // If have a key, walk the list of certs, find the one for our key, // remove any certs for our key from the list, what's left is part of // the CA certificate chain. - if (! qskKey.isNull()) { + if (!qskKey.isNull()) { ql << QSslCertificate::fromData(crt); ql << QSslCertificate::fromData(key); - for (int i=0;i<ql.size();++i) { + for (int i = 0; i < ql.size(); ++i) { const QSslCertificate &c = ql.at(i); if (isKeyForCert(qskKey, c)) { qscCert = c; @@ -114,24 +114,26 @@ void Server::initializeCert() { } #if defined(USE_QSSLDIFFIEHELLMANPARAMETERS) - if (! dhparams.isEmpty()) { + if (!dhparams.isEmpty()) { QSslDiffieHellmanParameters qdhp = QSslDiffieHellmanParameters::fromEncoded(dhparams); if (qdhp.isValid()) { qsdhpDHParams = qdhp; } else { - log(QString::fromLatin1("Unable to use specified Diffie-Hellman parameters (sslDHParams): %1").arg(qdhp.errorString())); + log(QString::fromLatin1("Unable to use specified Diffie-Hellman parameters (sslDHParams): %1") + .arg(qdhp.errorString())); } } #else - if (! dhparams.isEmpty()) { - log("Diffie-Hellman parameters (sslDHParams) were specified, but will not be used. This version of Murmur does not support Diffie-Hellman parameters."); + if (!dhparams.isEmpty()) { + log("Diffie-Hellman parameters (sslDHParams) were specified, but will not be used. This version of Murmur does " + "not support Diffie-Hellman parameters."); } #endif QString issuer; QStringList issuerNames = qscCert.issuerInfo(QSslCertificate::CommonName); - if (! issuerNames.isEmpty()) { + if (!issuerNames.isEmpty()) { issuer = issuerNames.first(); } @@ -140,16 +142,17 @@ void Server::initializeCert() { if (issuer == QString::fromUtf8("Murmur Autogenerated Certificate")) { log("Old autogenerated certificate is unusable for registration, invalidating it"); qscCert = QSslCertificate(); - qskKey = QSslKey(); + qskKey = QSslKey(); } // If we have a cert, and it's a self-signed one, but we're binding to // all the same addresses as the Meta server is, use it's cert instead. // This allows a self-signed certificate generated by Murmur to be // replaced by a CA-signed certificate in the .ini file. - if (!qscCert.isNull() && issuer.startsWith(QString::fromUtf8("Murmur Autogenerated Certificate")) && ! Meta::mp.qscCert.isNull() && ! Meta::mp.qskKey.isNull() && (Meta::mp.qlBind == qlBind)) { - qscCert = Meta::mp.qscCert; - qskKey = Meta::mp.qskKey; + if (!qscCert.isNull() && issuer.startsWith(QString::fromUtf8("Murmur Autogenerated Certificate")) + && !Meta::mp.qscCert.isNull() && !Meta::mp.qskKey.isNull() && (Meta::mp.qlBind == qlBind)) { + qscCert = Meta::mp.qscCert; + qskKey = Meta::mp.qskKey; qlIntermediates = Meta::mp.qlIntermediates; if (!qscCert.isNull() && !qskKey.isNull()) { @@ -159,12 +162,12 @@ void Server::initializeCert() { // If we still don't have a certificate by now, try to load the one from Meta if (qscCert.isNull() || qskKey.isNull()) { - if (! key.isEmpty() || ! crt.isEmpty()) { + if (!key.isEmpty() || !crt.isEmpty()) { log("Certificate specified, but failed to load."); } - qskKey = Meta::mp.qskKey; - qscCert = Meta::mp.qscCert; + qskKey = Meta::mp.qskKey; + qscCert = Meta::mp.qscCert; qlIntermediates = Meta::mp.qlIntermediates; if (!qscCert.isNull() && !qskKey.isNull()) { |