X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcipher.cpp;h=fb6a69720668f7acd905e88e3989092046a91d8a;hp=9ea9c1302dd935dc61c95e80c902f4871c327c35;hb=fd2b2fa2f94e9c1fa353b9ba1cd72792df07abb0;hpb=c4917f44ac75393d56bc859f6da7d474cd5ec02b diff --git a/src/core/cipher.cpp b/src/core/cipher.cpp index 9ea9c130..fb6a6972 100644 --- a/src/core/cipher.cpp +++ b/src/core/cipher.cpp @@ -13,7 +13,7 @@ */ #include "cipher.h" -#include "logger.h" +#include "logmessage.h" Cipher::Cipher() { @@ -117,7 +117,6 @@ QByteArray Cipher::decrypt(QByteArray cipherText) // (if cbc and no error we parse cbc) || (if ecb and error we parse cbc) if ((m_cbc && !error) || (!m_cbc && error)) { - cipherText = cipherText; temp = blowfishCBC(cipherText, false); if (temp == cipherText) @@ -170,6 +169,13 @@ QByteArray Cipher::initKeyExchange() QByteArray Cipher::parseInitKeyX(QByteArray key) { QCA::Initializer init; + bool isCBC = false; + + if (key.endsWith(" CBC")) + { + isCBC = true; + key.chop(4); + } if (key.length() != 181) return QByteArray(); @@ -198,6 +204,9 @@ QByteArray Cipher::parseInitKeyX(QByteArray key) //remove trailing = because mircryption and fish think it's a swell idea. while (sharedKey.endsWith('=')) sharedKey.chop(1); + if (isCBC) + sharedKey.prepend("cbc:"); + bool success = setKey(sharedKey); if (!success) @@ -354,6 +363,10 @@ QByteArray Cipher::blowfishECB(QByteArray cipherText, bool direction) } else { + // ECB Blowfish encodes in blocks of 12 chars, so anything else is malformed input + if ((temp.length() % 12) != 0) + return cipherText; + temp = b64ToByte(temp); while ((temp.length() % 8) != 0) temp.append('\0'); } @@ -366,8 +379,13 @@ QByteArray Cipher::blowfishECB(QByteArray cipherText, bool direction) if (!cipher.ok()) return cipherText; - if (direction) + if (direction) { + // Sanity check + if ((temp2.length() % 8) != 0) + return cipherText; + temp2 = byteToB64(temp2); + } return temp2; } @@ -410,13 +428,13 @@ QByteArray Cipher::byteToB64(QByteArray text) right += v; for (int i = 0; i < 6; i++) { - encoded.append(base64.at(right & 0x3F).toAscii()); + encoded.append(base64.at(right & 0x3F).toLatin1()); right = right >> 6; } - //TODO make sure the .toascii doesn't break anything + //TODO make sure the .toLatin1 doesn't break anything for (int i = 0; i < 6; i++) { - encoded.append(base64.at(left & 0x3F).toAscii()); + encoded.append(base64.at(left & 0x3F).toLatin1()); left = left >> 6; } }