1
0
Fork 0
forked from blue/squawk

qt6 build

This commit is contained in:
Blue 2024-12-14 01:53:04 +02:00
parent a04693e39d
commit d4cec645b5
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
35 changed files with 279 additions and 632 deletions

View file

@ -23,10 +23,7 @@ set(HEADER_FILES
squawk.h
)
target_sources(squawk PRIVATE
${SOURCE_FILES}
${HEADER_FILES}
)
target_sources(squawk PRIVATE ${SOURCE_FILES})
target_include_directories(squawk PRIVATE ${LMDB_INCLUDE_DIRS})
@ -34,3 +31,4 @@ add_subdirectory(handlers)
add_subdirectory(passwordStorageEngines)
add_subdirectory(components)
add_subdirectory(delayManager)
add_subdirectory(utils)

View file

@ -81,6 +81,7 @@ Core::Account::Account(
config.setDomain(p_server);
config.setPassword(p_password);
config.setAutoAcceptSubscriptions(true);
config.setIgnoreSslErrors(true);
//config.setAutoReconnectionEnabled(false);
delay = new DelayManager::Manager(getBareJid());
QObject::connect(delay, &DelayManager::Manager::gotInfo, this, &Account::infoReady);

View file

@ -12,7 +12,4 @@ set(HEADER_FILES
archive.h
)
target_sources(squawk PRIVATE
${SOURCE_FILES}
${HEADER_FILES}
)
target_sources(squawk PRIVATE ${SOURCE_FILES})

View file

@ -550,10 +550,8 @@ void Core::NetworkAccess::moveFilesDirectory(const QString& newPath) {
QDir dir(currentPath);
bool success = true;
qDebug() << "moving" << currentPath << "to" << newPath;
for (QFileInfo fileInfo : dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System)) {
QString fileName = fileInfo.fileName();
for (QString fileName : dir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System))
success = dir.rename(fileName, newPath + QDir::separator() + fileName) && success;
}
if (!success)
qDebug() << "couldn't move downloads directory, most probably downloads will be broken";

View file

@ -492,7 +492,7 @@ void Core::MessageHandler::prepareUpload(const Shared::Message& data, bool newMe
QFileInfo file(path);
if (file.exists() && file.isReadable()) {
pendingStateMessages.insert(std::make_pair(id, jid));
uploadingSlotsQueue.emplace_back(path, id);
uploadingSlotsQueue.emplace_back(file, id);
if (uploadingSlotsQueue.size() == 1)
acc->um->requestUploadSlot(file);
} else {
@ -505,10 +505,10 @@ void Core::MessageHandler::onUploadSlotReceived(const QXmppHttpUploadSlotIq& slo
if (uploadingSlotsQueue.size() == 0) {
qDebug() << "HTTP Upload manager of account" << acc->name << "reports about success requesting upload slot, but none was requested";
} else {
const std::pair<QString, QString>& pair = uploadingSlotsQueue.front();
const std::pair<QFileInfo, QString>& pair = uploadingSlotsQueue.front();
const QString& mId = pair.second;
QString palJid = pendingStateMessages.at(mId);
acc->network->uploadFile({acc->name, palJid, mId}, pair.first, slot.putUrl(), slot.getUrl(), slot.putHeaders());
acc->network->uploadFile({acc->name, palJid, mId}, pair.first.path(), slot.putUrl(), slot.getUrl(), slot.putHeaders());
uploadingSlotsQueue.pop_front();
if (uploadingSlotsQueue.size() > 0)
@ -522,7 +522,7 @@ void Core::MessageHandler::onUploadSlotRequestFailed(const QXmppHttpUploadReques
qDebug() << "HTTP Upload manager of account" << acc->name << "reports about an error requesting upload slot, but none was requested";
qDebug() << err;
} else {
const std::pair<QString, QString>& pair = uploadingSlotsQueue.front();
const std::pair<QFileInfo, QString>& pair = uploadingSlotsQueue.front();
qDebug() << "Error requesting upload slot for file" << pair.first << "in account" << acc->name << ":" << err;
handleUploadError(pendingStateMessages.at(pair.second), pair.second, err);

View file

@ -19,6 +19,7 @@
#pragma once
#include <QObject>
#include <QFileInfo>
#include <deque>
#include <map>
@ -81,7 +82,7 @@ private:
Account* acc;
std::map<QString, QString> pendingStateMessages; //key is message id, value is JID
std::map<QString, QString> pendingCorrectionMessages; //key is new mesage, value is originalOne
std::deque<std::pair<QString, QString>> uploadingSlotsQueue;
std::deque<std::pair<QFileInfo, QString>> uploadingSlotsQueue;
};
}

View file

@ -1,9 +1,6 @@
if (WITH_KWALLET)
target_sources(squawk PRIVATE
kwallet.cpp
kwallet.h
)
target_sources(squawk PRIVATE kwallet.cpp)
add_subdirectory(wrappers)
target_include_directories(squawk PRIVATE $<TARGET_PROPERTY:KF5::Wallet,INTERFACE_INCLUDE_DIRECTORIES>)
target_include_directories(squawk PRIVATE $<TARGET_PROPERTY:KF${QT_VERSION_MAJOR}::Wallet,INTERFACE_INCLUDE_DIRECTORIES>)
endif ()

View file

@ -27,7 +27,7 @@
#include <map>
#include <set>
#include <KF5/KWallet/KWallet>
#include <KWallet>
namespace Core {
namespace PSE {

View file

@ -1,4 +1,5 @@
add_library(kwalletWrapper SHARED kwallet.cpp)
target_link_libraries(kwalletWrapper PRIVATE KF5::Wallet)
target_link_libraries(kwalletWrapper PRIVATE KF${QT_VERSION_MAJOR}::Wallet)
install(TARGETS kwalletWrapper LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/squawk)

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <KF5/KWallet/KWallet>
#include <KWallet>
extern "C" KWallet::Wallet* openWallet(const QString &name, WId w, KWallet::Wallet::OpenType ot = KWallet::Wallet::Synchronous) {
return KWallet::Wallet::openWallet(name, w, ot);

View file

@ -22,9 +22,7 @@
#include <QDir>
#include <QStandardPaths>
#ifdef WITH_SIMPLE_CRYPT
#include "external/simpleCrypt/simplecrypt.h"
#endif
#include "utils/jammer.h"
Core::Squawk::Squawk(QObject* parent):
QObject(parent),
@ -87,18 +85,14 @@ void Core::Squawk::stop() {
password = acc->getPassword();
break;
case Shared::AccountPassword::jammed:
#ifdef WITH_SIMPLE_CRYPT2
password = SimpleCrypt(passwordHash).encryptToString(acc->getPassword());
#else
qDebug() << "The password for account" << acc->getName() << "is set to be jammed, but Squawk was compiled without SimpleCrypt support";
qDebug("Can not encode password, setting this account to always ask password mode");
ap = Shared::AccountPassword::alwaysAsk;
#endif
password = Jammer::encrypt(acc->getPassword(), passwordHash);
break;
default:
break;
}
qDebug() << "Saving password for" << acc->getName() << password;
settings.setValue("name", acc->getName());
settings.setValue("server", acc->getServer());
settings.setValue("login", acc->getLogin());
@ -708,16 +702,8 @@ void Core::Squawk::readSettings() {
QString name = settings.value("name").toString();
QString password = settings.value("password", "").toString();
if (passwordType == Shared::AccountPassword::jammed) {
#ifdef WITH_SIMPLE_CRYPT
SimpleCrypt crypto(passwordHash);
password = crypto.decryptToString(password);
#else
qDebug() << "The password for account" << name << "is jammed, but Squawk was compiled without SimpleCrypt support";
qDebug("Can not decode password, setting this account to always ask password mode");
passwordType = Shared::AccountPassword::alwaysAsk;
#endif
}
if (passwordType == Shared::AccountPassword::jammed)
password = Jammer::decrypt(password, passwordHash);
addAccount(
settings.value("login").toString(),

View file

@ -0,0 +1,9 @@
set(SOURCE_FILES
jammer.cpp
)
set(HEADER_FILES
jammer.h
)
target_sources(squawk PRIVATE ${SOURCE_FILES})

94
core/utils/jammer.cpp Normal file
View file

@ -0,0 +1,94 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "jammer.h"
#include <memory>
#include <openssl/evp.h>
#include <openssl/err.h>
struct CipherCtxDeleter {
void operator()(EVP_CIPHER_CTX* ctx) const {
EVP_CIPHER_CTX_free(ctx);
}
};
typedef std::unique_ptr<EVP_CIPHER_CTX, CipherCtxDeleter> CipherCtx;
QString Core::Jammer::encrypt(const QString& plaintext, qint64 key) {
QByteArray encryptedData = process(plaintext.toUtf8(), intToKey(key), true);
return QString::fromUtf8(encryptedData.toHex());
}
QString Core::Jammer::decrypt(const QString& ciphertext, qint64 key) {
QByteArray encryptedData = QByteArray::fromHex(ciphertext.toUtf8());
QByteArray decryptedData = process(encryptedData, intToKey(key), false);
return QString::fromUtf8(decryptedData);
}
std::string Core::Jammer::getOpenSSLErrorString() {
unsigned long errCode = ERR_get_error();
if (errCode == 0) {
return "No OpenSSL error";
}
const char *errMsg = ERR_reason_error_string(errCode);
return errMsg ? std::string(errMsg) : "Unknown OpenSSL error";
}
QByteArray Core::Jammer::process(const QByteArray& input, const QByteArray& key, bool encrypt) {
CipherCtx ctx(EVP_CIPHER_CTX_new());
if (!ctx)
throw std::runtime_error("Failed to create password jammer context");
QByteArray output(input.size() + 16, 0);
int outputLength = 0;
int finalLength = 0;
if (!ctx)
throw std::runtime_error("Failed to create EVP_CIPHER_CTX: " + getOpenSSLErrorString());
if (EVP_CipherInit_ex(ctx.get(), EVP_chacha20(), nullptr, toUChar(key), nullptr, encrypt) != 1)
throw std::runtime_error("EVP_CipherInit_ex failed. " + getOpenSSLErrorString());
if (EVP_CipherUpdate(ctx.get(), toUChar(output), &outputLength, toUChar(input), input.size()) != 1)
throw std::runtime_error("EVP_CipherUpdate failed. " + getOpenSSLErrorString());
if (EVP_CipherFinal_ex(ctx.get(), toUChar(output) + outputLength, &finalLength) != 1)
throw std::runtime_error("EVP_CipherFinal_ex failed. " + getOpenSSLErrorString());
output.resize(outputLength + finalLength);
return output;
}
QByteArray Core::Jammer::intToKey(qint64 key, int keySize) {
QByteArray keyBytes(reinterpret_cast<const char *>(&key), sizeof(key));
while (keyBytes.size() < keySize)
keyBytes.append(keyBytes);
keyBytes.truncate(keySize);
return keyBytes;
}
unsigned char* Core::Jammer::toUChar(QByteArray& data) {
return reinterpret_cast<unsigned char *>(data.data());}
const unsigned char* Core::Jammer::toUChar(const QByteArray& data) {
return reinterpret_cast<const unsigned char *>(data.constData());}

44
core/utils/jammer.h Normal file
View file

@ -0,0 +1,44 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdexcept>
#include <QByteArray>
#include <QString>
namespace Core {
class Jammer {
public:
static QString encrypt(const QString& plaintext, qint64 key);
static QString decrypt(const QString& ciphertext, qint64 key);
private:
Jammer() = delete;
static QByteArray process(const QByteArray& input, const QByteArray& key, bool encrypt);
static QByteArray intToKey(qint64 key, int keySize = 32);
static unsigned char* toUChar(QByteArray& data);
static const unsigned char* toUChar(const QByteArray& data);
static std::string getOpenSSLErrorString();
};
}