From 393ac8b4bca9db98f297cb4756ef2e79364bf6f0 Mon Sep 17 00:00:00 2001 From: Johannes Huber Date: Thu, 17 Mar 2011 14:19:18 +0100 Subject: [PATCH] check for qca provider plugin, fixes #1045 Prevents core from crashing when qca provider plugin is missing. The plugin is needed at runtime. Can occurres when packagers did not install it. --- src/core/cipher.cpp | 12 ++++++++++++ src/core/cipher.h | 1 + src/core/coreircchannel.cpp | 3 +++ src/core/corenetwork.cpp | 3 +++ src/core/coreuserinputhandler.cpp | 9 +++++++++ src/core/ircparser.cpp | 3 +++ 6 files changed, 31 insertions(+) diff --git a/src/core/cipher.cpp b/src/core/cipher.cpp index 195936cb..92b8fad1 100644 --- a/src/core/cipher.cpp +++ b/src/core/cipher.cpp @@ -13,6 +13,7 @@ */ #include "cipher.h" +#include "logger.h" Cipher::Cipher() @@ -449,3 +450,14 @@ QByteArray Cipher::b64ToByte(QByteArray text) } return decoded; } + +bool Cipher::neededFeaturesAvailable() +{ + QCA::Initializer init; + + if (QCA::isSupported("blowfish-ecb") && QCA::isSupported("blowfish-cbc") && QCA::isSupported("dh")) + return true; + + qWarning() << "QCA provider plugin not found. It is usually provided by the qca-ossl plugin."; + return false; +} diff --git a/src/core/cipher.h b/src/core/cipher.h index b5cf0e0f..33a2bf8c 100644 --- a/src/core/cipher.h +++ b/src/core/cipher.h @@ -33,6 +33,7 @@ class Cipher QByteArray key() { return m_key; } bool setType(const QString &type); QString type() { return m_type; } + static bool neededFeaturesAvailable(); private: //direction is true for encrypt, false for decrypt diff --git a/src/core/coreircchannel.cpp b/src/core/coreircchannel.cpp index 85eb333f..02b81b76 100644 --- a/src/core/coreircchannel.cpp +++ b/src/core/coreircchannel.cpp @@ -46,6 +46,9 @@ Cipher *CoreIrcChannel::cipher() const { } void CoreIrcChannel::setEncrypted(bool e) { + if(!Cipher::neededFeaturesAvailable()) + return; + if(e) { if(topic().isEmpty()) return; diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index 94854990..534199e3 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -275,6 +275,9 @@ Cipher *CoreNetwork::cipher(const QString &target) const { if(target.isEmpty()) return 0; + if(!Cipher::neededFeaturesAvailable()) + return 0; + QByteArray key = cipherKey(target); if(key.isEmpty()) return 0; diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index 8292325f..f1654a4d 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -164,6 +164,9 @@ void CoreUserInputHandler::handleDelkey(const BufferInfo &bufferInfo, const QStr if(!bufferInfo.isValid()) return; + if(!Cipher::neededFeaturesAvailable()) + return; + QStringList parms = msg.split(' ', QString::SkipEmptyParts); if(parms.isEmpty() && !bufferInfo.bufferName().isEmpty()) @@ -454,6 +457,9 @@ void CoreUserInputHandler::handleSetkey(const BufferInfo &bufferInfo, const QStr if(!bufferInfo.isValid()) return; + if(!Cipher::neededFeaturesAvailable()) + return; + QStringList parms = msg.split(' ', QString::SkipEmptyParts); if(parms.count() == 1 && !bufferInfo.bufferName().isEmpty()) @@ -638,6 +644,9 @@ QByteArray CoreUserInputHandler::encrypt(const QString &target, const QByteArray if(message_.isEmpty()) return message_; + if(!Cipher::neededFeaturesAvailable()) + return message_; + Cipher *cipher = network()->cipher(target); if(!cipher) return message_; diff --git a/src/core/ircparser.cpp b/src/core/ircparser.cpp index 7811e05d..b372e351 100644 --- a/src/core/ircparser.cpp +++ b/src/core/ircparser.cpp @@ -50,6 +50,9 @@ QByteArray IrcParser::decrypt(Network *network, const QString &bufferName, const if(message.isEmpty()) return message; + if(!Cipher::neededFeaturesAvailable()) + return message; + Cipher *cipher = qobject_cast(network)->cipher(bufferName); if(!cipher) return message; -- 2.20.1