ref(omemo): reformat qomemo/

This commit is contained in:
vae 2021-05-13 17:54:37 +03:00
parent 574210f5d9
commit bbeeee4c8a
Signed by: vae
GPG Key ID: A9A33351400E00E5
23 changed files with 447 additions and 455 deletions

View File

@ -1,12 +0,0 @@
* Generate device w/ keys
* PubSub set urn:xmpp:omemo:1:devices to announce new device
* PubSub set urn:xmpp:omemo:1:bundles to announce new key bundles
* PubSub get urn:xmpp:omemo:1:bundles to get user bundles
Sending a message:
* Create urn:xmpp:sce:0 with padding and content
* Add <encrypted xmlns='urn:xmpp:omemo:1'> with header (key list) and payload (b64)
Receiving a message:
* Check <keys> => <key>
* Decrypt (TODO)

View File

@ -8,23 +8,25 @@
#include <QString>
class QXmppPubSubIq;
class QXmppElement;
class QXmppIq;
namespace QXmpp::Omemo {
class PreKey {
public:
class PreKey {
public:
[[nodiscard]] QXmppElement toXml() const;
/// Expects a <pk>
void fromXml(const QXmppElement &element);
int id;
QString data;
};
};
class Bundle {
public:
class Bundle {
public:
[[nodiscard]] static QXmppPubSubIq fetchDeviceBundleIq(int deviceId);
[[nodiscard]] QXmppElement toXml() const;
@ -36,6 +38,6 @@ public:
QString spks;
QString ik;
QList<PreKey> prekeys;
};
};
} // namespace QXmpp::Omemo

View File

@ -74,7 +74,7 @@ bool Database::saveIdentityKeySecret(int deviceId,
int Database::loadActiveDeviceId() {
MDB_val key, value;
key.mv_data = (void *)"active";
key.mv_data = (void *) "active";
key.mv_size = sizeof("active");
MDB_txn *txn;
@ -101,7 +101,7 @@ int Database::loadActiveDeviceId() {
bool Database::saveActiveDeviceId(int deviceId) {
MDB_val key, value;
key.mv_data = (void *)"active";
key.mv_data = (void *) "active";
key.mv_size = sizeof("active");
value.mv_data = &deviceId;

View File

@ -10,8 +10,8 @@
namespace QXmpp::Omemo {
class Database {
public:
class Database {
public:
explicit Database(QString jid);
~Database();
Database(const Database &) = delete;
@ -29,12 +29,12 @@ public:
const QString jid;
private:
private:
MDB_env *env{};
MDB_dbi dbiDevices{};
MDB_dbi dbiKeys{};
MDB_dbi dbiPreKeys{};
MDB_dbi dbiIdentityKeys{};
};
};
} // namespace QXmpp::Omemo

View File

@ -7,18 +7,19 @@
#include <QList>
class QXmppElement;
class QXmppIq;
namespace QXmpp::Omemo {
class Device {
public:
class Device {
public:
int id;
};
};
class DeviceList {
public:
class DeviceList {
public:
QList<Device> devices;
};
};
} // namespace QXmpp::Omemo

View File

@ -11,5 +11,4 @@ int QXmpp::Omemo::DeviceKeyStorage::generateDeviceId() {
return 1 + random.bounded(INT32_MAX - 1);
}
QXmpp::Omemo::DeviceKeyStorage::DeviceKeyStorage(int deviceId)
: deviceId(deviceId) {}
QXmpp::Omemo::DeviceKeyStorage::DeviceKeyStorage(int deviceId) : deviceId(deviceId) {}

View File

@ -6,13 +6,13 @@
namespace QXmpp::Omemo {
class DeviceKeyStorage {
public:
class DeviceKeyStorage {
public:
static int generateDeviceId();
explicit DeviceKeyStorage(int deviceId);
const int deviceId;
};
};
} // namespace QXmpp::Omemo

View File

@ -7,8 +7,7 @@
QXmpp::Omemo::DeviceService::DeviceService(QObject *parent) : QObject(parent) {}
void QXmpp::Omemo::DeviceService::onDeviceListReceived(
const QString &jid, const QXmpp::Omemo::DeviceList &list) {
void QXmpp::Omemo::DeviceService::onDeviceListReceived(const QString &jid, const QXmpp::Omemo::DeviceList &list) {
for (const auto &device : list.devices) {
qInfo() << "Got device for" << jid << ":" << device.id;

View File

@ -11,19 +11,19 @@
namespace QXmpp::Omemo {
class DeviceList;
class DeviceList;
class DeviceService : public QObject {
class DeviceService : public QObject {
Q_OBJECT
public:
public:
explicit DeviceService(QObject *parent);
public slots:
void onDeviceListReceived(const QString &jid, const DeviceList &list);
public slots:
void onDeviceListReceived(const QString &jid, const QXmpp::Omemo::DeviceList &list);
private:
private:
QMap<QString, UserDeviceList> device_lists{};
};
};
} // namespace QXmpp::Omemo

View File

@ -11,17 +11,17 @@
namespace QXmpp::Omemo {
class MessageKey {
public:
class MessageKey {
public:
[[nodiscard]] QXmppElement toXml() const;
int receivingDeviceId{};
bool prekey{};
QString key{};
};
};
class EncryptedMessage {
public:
class EncryptedMessage {
public:
[[nodiscard]] QXmppElement header() const;
[[nodiscard]] QXmppElement content() const;
[[nodiscard]] QXmppElement toXml() const;
@ -37,6 +37,6 @@ public:
QString iv{};
QXmppMessage message{};
};
};
} // namespace QXmpp::Omemo

View File

@ -18,8 +18,7 @@ using namespace QXmpp::Omemo;
Manager::Manager()
: deviceService(new DeviceService(this)),
omemoVariant(new Variant::Conversations) {
connect(this, &Manager::deviceListReceived, deviceService.get(),
&DeviceService::onDeviceListReceived);
connect(this, &Manager::deviceListReceived, deviceService.get(), &DeviceService::onDeviceListReceived);
}
bool QXmpp::Omemo::Manager::handleStanza(const QDomElement &stanza) {

View File

@ -12,27 +12,27 @@
namespace QXmpp::Omemo {
class Manager : public QXmppClientExtension {
class Manager : public QXmppClientExtension {
Q_OBJECT;
public:
public:
Manager();
~Manager() override = default;
bool handleStanza(const QDomElement &stanza) override;
public slots:
public slots:
void fetchOwnDevices();
signals:
void deviceListReceived(const QString &jid, const DeviceList &list);
signals:
void deviceListReceived(const QString &jid, const QXmpp::Omemo::DeviceList &list);
protected:
protected:
void setClient(QXmppClient *client) override;
private:
private:
QScopedPointer<DeviceService> deviceService;
QScopedPointer<Variant::Base> omemoVariant;
};
};
} // namespace QXmpp::Omemo

View File

@ -6,12 +6,14 @@
#include <QRandomGenerator>
#define RPAD_ALPHABET "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
constexpr int RPAD_MAX_LENGTH = 200;
QString QXmpp::Sce::generatePadding() {
QRandomGenerator random{};
QString result{};
QString alphabet{ QStringLiteral("!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~") };
QString alphabet{QStringLiteral(RPAD_ALPHABET)};
auto length = random.bounded(RPAD_MAX_LENGTH);
result.resize(length);

View File

@ -9,6 +9,6 @@
namespace QXmpp::Sce {
QString generatePadding();
QString generatePadding();
}

View File

@ -35,7 +35,8 @@ int Signal::Store::SignedPreKeyStore::loadSignedPreKey(signal_buffer **record, u
return 0;
}
int Signal::Store::SignedPreKeyStore::storeSignedPreKey(uint32_t signed_pre_key_id, uint8_t *record, size_t record_len) {
int
Signal::Store::SignedPreKeyStore::storeSignedPreKey(uint32_t signed_pre_key_id, uint8_t *record, size_t record_len) {
return 0;
}

View File

@ -6,5 +6,4 @@
#include <utility>
QXmpp::Omemo::UserDeviceList::UserDeviceList(QString jid)
: jid(std::move(jid)) {}
QXmpp::Omemo::UserDeviceList::UserDeviceList(QString jid) : jid(std::move(jid)) {}

View File

@ -8,11 +8,11 @@
namespace QXmpp::Omemo {
class UserDeviceList {
public:
class UserDeviceList {
public:
explicit UserDeviceList(QString jid);
const QString jid;
};
};
} // namespace QXmpp::Omemo

View File

@ -8,8 +8,8 @@
namespace QXmpp::Omemo::Variant {
class Conversations : public Base {
public:
class Conversations : public Base {
public:
~Conversations() override = default;
QXmppElement deviceToXml(const Device &device) override;
@ -18,6 +18,6 @@ public:
QXmppElement deviceListToXml(const DeviceList &deviceList) override;
DeviceList deviceListFromXml(const QXmppElement &xml) override;
QXmppIq deviceListSetIq(const DeviceList &deviceList) override;
};
};
} // namespace QXmpp::Omemo::Variant

View File

@ -5,17 +5,19 @@
#pragma once
class QXmppElement;
class QXmppIq;
namespace QXmpp::Omemo {
class Device;
class DeviceList;
class Device;
namespace Variant {
class DeviceList;
class Base {
public:
namespace Variant {
class Base {
public:
virtual ~Base() = default;
virtual QXmppElement deviceToXml(const Device &device) = 0;
@ -24,8 +26,8 @@ public:
virtual QXmppElement deviceListToXml(const DeviceList &deviceList) = 0;
virtual DeviceList deviceListFromXml(const QXmppElement &xml) = 0;
virtual QXmppIq deviceListSetIq(const DeviceList &deviceList) = 0;
};
};
} // namespace Variant
} // namespace Variant
} // namespace QXmpp::Omemo