check for qca provider plugin, fixes #1045
authorJohannes Huber <johu@gmx.de>
Thu, 17 Mar 2011 13:19:18 +0000 (14:19 +0100)
committerJohannes Huber <johu@gmx.de>
Thu, 17 Mar 2011 13:19:18 +0000 (14:19 +0100)
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
src/core/cipher.h
src/core/coreircchannel.cpp
src/core/corenetwork.cpp
src/core/coreuserinputhandler.cpp
src/core/ircparser.cpp

index 195936c..92b8fad 100644 (file)
@@ -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;
+}
index b5cf0e0..33a2bf8 100644 (file)
@@ -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
index 85eb333..02b81b7 100644 (file)
@@ -46,6 +46,9 @@ Cipher *CoreIrcChannel::cipher() const {
 }
 
 void CoreIrcChannel::setEncrypted(bool e) {
+  if(!Cipher::neededFeaturesAvailable())
+    return;
+
   if(e) {
     if(topic().isEmpty())
       return;
index 9485499..534199e 100644 (file)
@@ -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;
index 8292325..f1654a4 100644 (file)
@@ -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_;
index 7811e05..b372e35 100644 (file)
@@ -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<CoreNetwork *>(network)->cipher(bufferName);
   if(!cipher)
     return message;