Checker::Checker() { Settings se; this->previousMessage = ""; this->isWorking = false; this->accessUrl = QUrl(se.getString("accessUrl")); accessManager = new QNetworkAccessManager(this); // Signal for finishing network access connect(accessManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); // SSL/TLS configuration this->sslConfiguration = new QSslConfiguration; sslConfiguration->setProtocol(QSsl::SecureProtocols); // QT 5.0.1: TlsV1SslV3 // CA Certs QList<QSslCertificate> certs = QSslCertificate::fromPath(QString(se.getString("certificateFile")), QSsl::Pem); sslConfiguration->setPeerVerifyMode(QSslSocket::VerifyPeer); // Default behaviour for clients sslConfiguration->setCaCertificates(certs); // Ciphers QList<QSslCipher> ciphers; QStringList cipherList = se.getStringList("cipherList"); foreach (QString cipherName, cipherList) { QSslCipher cipher = QSslCipher(cipherName,QSsl::SecureProtocols); qDebug() << "Instantiated" << cipherName << ":" << cipher.isNull(); if (!cipher.isNull()) { ciphers.append(cipher); } }
QList<QSslCipher> MumbleSSL::ciphersFromOpenSSLCipherString(QString cipherString) { QList<QSslCipher> chosenCiphers; SSL_CTX *ctx = NULL; SSL *ssl = NULL; const SSL_METHOD *meth = NULL; int i = 0; QByteArray csbuf = cipherString.toLatin1(); const char *ciphers = csbuf.constData(); meth = SSLv23_server_method(); if (meth == NULL) { qWarning("MumbleSSL: unable to get SSL method"); goto out; } // We use const_cast to be compatible with OpenSSL 0.9.8. ctx = SSL_CTX_new(const_cast<SSL_METHOD *>(meth)); if (ctx == NULL) { qWarning("MumbleSSL: unable to allocate SSL_CTX"); goto out; } if (!SSL_CTX_set_cipher_list(ctx, ciphers)) { qWarning("MumbleSSL: error parsing OpenSSL cipher string in ciphersFromOpenSSLCipherString"); goto out; } ssl = SSL_new(ctx); if (ssl == NULL) { qWarning("MumbleSSL: unable to create SSL object in ciphersFromOpenSSLCipherString"); goto out; } while (1) { const char *name = SSL_get_cipher_list(ssl, i); if (name == NULL) { break; } #if QT_VERSION >= 0x050300 QSslCipher c = QSslCipher(QString::fromLatin1(name)); if (!c.isNull()) { chosenCiphers << c; } #else foreach (const QSslCipher &c, QSslSocket::supportedCiphers()) { if (c.name() == QString::fromLatin1(name)) { chosenCiphers << c; } } #endif ++i; } out: SSL_CTX_free(ctx); SSL_free(ssl); return chosenCiphers; }
void WebsocketServer::initialisieren(const QString &name, const QString &ipAdresse, const int &anschluss, const QStringList &sslAlgorithmen, const QStringList &ssl_EK, const QString &ssl_DH, const QString &zertifikatSchluessel, const QString &zertifikat, const QString &zertifkatKette, const bool &ssl_aktiv) { QWebSocketServer::SslMode SSL_Modus; if (ssl_aktiv) { SSL_Modus=QWebSocketServer::SecureMode; K_IPAdresse=QHostAddress(ipAdresse); } else { SSL_Modus=QWebSocketServer::NonSecureMode; K_IPAdresse=QHostAddress(QHostAddress::LocalHost); } K_Server=new QWebSocketServer(name,SSL_Modus,this); connect(K_Server,&QWebSocketServer::sslErrors,this, &WebsocketServer::SSL_Fehler); connect(K_Server,&QWebSocketServer::serverError,this,&WebsocketServer::SSL_Serverfehler); connect(K_Server,&QWebSocketServer::newConnection,this,&WebsocketServer::NeuerKlient); connect(K_Server,&QWebSocketServer::acceptError,this,&WebsocketServer::Verbindungsfehler); K_Anschluss=anschluss; QSslConfiguration SSL; QList<QSslCipher> Algorithmen; QVector<QSslEllipticCurve> EK; SSL.setProtocol(QSsl::TlsV1_2OrLater); SSL.setPeerVerifyMode(QSslSocket::VerifyNone); QSslCipher Algorithmus; QSslEllipticCurve Kurve; if (ssl_aktiv) { //BUG Das mit der Reihenfolge geht nicht for (auto Eintrag : sslAlgorithmen) { Algorithmus=QSslCipher(Eintrag); if (Algorithmus.isNull()) qCWarning(qalarm_serverWebsocketServer)<< tr("Algorithmus %1 wird nicht unterstützt.").arg(Eintrag); else Algorithmen.append(Algorithmus); } SSL.setCiphers(Algorithmen); //BUG Es werden nie Kurven angeboten for (auto Eintrag : ssl_EK) { Kurve=QSslEllipticCurve::fromShortName(Eintrag); if (!Kurve.isValid()) qCWarning(qalarm_serverWebsocketServer)<< tr("Kurve %1 wird nicht unterstützt.").arg(Eintrag); else EK.append(Kurve); } SSL.setEllipticCurves(EK); if(!ssl_DH.isEmpty()) { #if (QT_VERSION >= QT_VERSION_CHECK(5,8,0)) SSL.setDiffieHellmanParameters(QSslDiffieHellmanParameters::fromEncoded(DateiLaden(ssl_DH,tr("Die DH Parameter %1 konnten nicht geladen werden.")))); #else qCWarning(qalarm_serverWebsocketServer)<<tr("Qt kann die DH Parameter erst ab Version 5.8.0 setzen"); #endif } QList<QSslCertificate> Zertifikate; Zertifikate=QSslCertificate::fromDevice(DateiLaden(zertifikat,tr("Zertifikat %1 konnte nicht geladen werden.").arg(zertifikat))); Zertifikate.append(QSslCertificate::fromDevice(DateiLaden(zertifkatKette,tr("Die Zertifikatskette %1 konnte nicht geladen werden.").arg(zertifkatKette)))); SSL.setLocalCertificateChain(Zertifikate); SSL.setPrivateKey(QSslKey(DateiLaden(zertifikatSchluessel,tr("Der Schlüssel %1 für das Zertifikat konnte nicht geladen werden.").arg(zertifikatSchluessel)),QSsl::Rsa)); if(SSL.privateKey().isNull() || SSL.localCertificate().isNull() || SSL.localCertificateChain().isEmpty()) return; qCDebug(qalarm_serverWebsocketServer)<<tr("Setze SSL Konfiguration"); qCDebug(qalarm_serverWebsocketServer)<<tr("Privater Schlüssel: ")<<SSL.privateKey(); qCDebug(qalarm_serverWebsocketServer)<<tr("Zertifikate: ")<<SSL.localCertificateChain(); #if (QT_VERSION >= QT_VERSION_CHECK(5,8,0)) qCDebug(qalarm_serverWebsocketServer)<<tr("DH Parameter: ")<<SSL.diffieHellmanParameters(); #endif qCDebug(qalarm_serverWebsocketServer)<<tr("Zerttest: ")<<SSL.peerVerifyMode(); qCDebug(qalarm_serverWebsocketServer)<<tr("Elliptische Kurven: ")<<SSL.ellipticCurves(); qCDebug(qalarm_serverWebsocketServer)<<tr("Algorithmen: ")<<SSL.ciphers(); K_Server->setSslConfiguration(SSL); } if(!K_Initfehler) Q_EMIT Initialisiert(); }