From b45a73b723039caf61c74143dd16f9ab484ebd14 Mon Sep 17 00:00:00 2001 From: blue Date: Sun, 1 Jan 2023 20:25:51 +0300 Subject: [PATCH] some initial work and thoughts about encryption --- core/handlers/trusthandler.cpp | 24 ++--- main/main.cpp | 1 + shared/CMakeLists.txt | 2 + shared/enums.h | 17 +-- shared/keyinfo.cpp | 46 +++++++++ shared/keyinfo.h | 55 ++++++++++ shared/shared.h | 1 + ui/widgets/vcard/CMakeLists.txt | 4 + ui/widgets/vcard/omemo/CMakeLists.txt | 5 + ui/widgets/vcard/omemo/omemo.cpp | 20 ++++ ui/widgets/vcard/omemo/omemo.h | 43 ++++++++ ui/widgets/vcard/omemo/omemo.ui | 142 ++++++++++++++++++++++++++ 12 files changed, 342 insertions(+), 18 deletions(-) create mode 100644 shared/keyinfo.cpp create mode 100644 shared/keyinfo.h create mode 100644 ui/widgets/vcard/omemo/CMakeLists.txt create mode 100644 ui/widgets/vcard/omemo/omemo.cpp create mode 100644 ui/widgets/vcard/omemo/omemo.h create mode 100644 ui/widgets/vcard/omemo/omemo.ui diff --git a/core/handlers/trusthandler.cpp b/core/handlers/trusthandler.cpp index 2c0be29..caaaf0e 100644 --- a/core/handlers/trusthandler.cpp +++ b/core/handlers/trusthandler.cpp @@ -368,23 +368,23 @@ QFuture TrustHandler::setSecurityPolicy( Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level) { switch (level) { - case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::Undecided; - case QXmpp::TrustLevel::AutomaticallyDistrusted: return Shared::TrustLevel::AutomaticallyDistrusted; - case QXmpp::TrustLevel::ManuallyDistrusted: return Shared::TrustLevel::ManuallyDistrusted; - case QXmpp::TrustLevel::AutomaticallyTrusted: return Shared::TrustLevel::AutomaticallyTrusted; - case QXmpp::TrustLevel::ManuallyTrusted: return Shared::TrustLevel::ManuallyTrusted; - case QXmpp::TrustLevel::Authenticated: return Shared::TrustLevel::Authenticated; + case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::undecided; + case QXmpp::TrustLevel::AutomaticallyDistrusted: return Shared::TrustLevel::automaticallyDistrusted; + case QXmpp::TrustLevel::ManuallyDistrusted: return Shared::TrustLevel::manuallyDistrusted; + case QXmpp::TrustLevel::AutomaticallyTrusted: return Shared::TrustLevel::automaticallyTrusted; + case QXmpp::TrustLevel::ManuallyTrusted: return Shared::TrustLevel::manuallyTrusted; + case QXmpp::TrustLevel::Authenticated: return Shared::TrustLevel::authenticated; } } Core::TrustHandler::TL Core::TrustHandler::convert(Shared::TrustLevel level) { switch (level) { - case Shared::TrustLevel::Undecided: return QXmpp::TrustLevel::Undecided; - case Shared::TrustLevel::AutomaticallyDistrusted: return QXmpp::TrustLevel::AutomaticallyDistrusted; - case Shared::TrustLevel::ManuallyDistrusted: return QXmpp::TrustLevel::ManuallyDistrusted; - case Shared::TrustLevel::AutomaticallyTrusted: return QXmpp::TrustLevel::AutomaticallyTrusted; - case Shared::TrustLevel::ManuallyTrusted: return QXmpp::TrustLevel::ManuallyTrusted; - case Shared::TrustLevel::Authenticated: return QXmpp::TrustLevel::Authenticated; + case Shared::TrustLevel::undecided: return QXmpp::TrustLevel::Undecided; + case Shared::TrustLevel::automaticallyDistrusted: return QXmpp::TrustLevel::AutomaticallyDistrusted; + case Shared::TrustLevel::manuallyDistrusted: return QXmpp::TrustLevel::ManuallyDistrusted; + case Shared::TrustLevel::automaticallyTrusted: return QXmpp::TrustLevel::AutomaticallyTrusted; + case Shared::TrustLevel::manuallyTrusted: return QXmpp::TrustLevel::ManuallyTrusted; + case Shared::TrustLevel::authenticated: return QXmpp::TrustLevel::Authenticated; } } diff --git a/main/main.cpp b/main/main.cpp index 2958b66..3e9add3 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -50,6 +50,7 @@ int main(int argc, char *argv[]) qRegisterMetaType>("QSet"); qRegisterMetaType("Shared::ConnectionState"); qRegisterMetaType("Shared::Availability"); + qRegisterMetaType("Shared::KeyInfo"); #ifdef WITH_OMEMO qRegisterMetaType("QXmppOmemoStorage::OwnDevice"); qRegisterMetaTypeStreamOperators("QXmppOmemoStorage::OwnDevice"); diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt index 51c599f..a227163 100644 --- a/shared/CMakeLists.txt +++ b/shared/CMakeLists.txt @@ -26,4 +26,6 @@ target_sources(squawk PRIVATE form.cpp field.h field.cpp + keyinfo.cpp + keyinfo.h ) diff --git a/shared/enums.h b/shared/enums.h index 7a1f092..7273b2e 100644 --- a/shared/enums.h +++ b/shared/enums.h @@ -127,23 +127,28 @@ Q_ENUM_NS(Support) enum class TrustLevel { /// The key's trust is not decided. - Undecided, + undecided, /// The key is automatically distrusted (e.g., by the security policy TOAKAFA). /// \see SecurityPolicy - AutomaticallyDistrusted, + automaticallyDistrusted, /// The key is manually distrusted (e.g., by clicking a button or \xep{0450, Automatic Trust /// Management (ATM)}). - ManuallyDistrusted, + manuallyDistrusted, /// The key is automatically trusted (e.g., by the client for all keys of a bare JID until one /// of it is authenticated). - AutomaticallyTrusted, + automaticallyTrusted, /// The key is manually trusted (e.g., by clicking a button). - ManuallyTrusted, + manuallyTrusted, /// The key is authenticated (e.g., by QR code scanning or \xep{0450, Automatic Trust /// Management (ATM)}). - Authenticated + authenticated }; Q_ENUM_NS(TrustLevel) +enum class EncryptionProtocol { + omemo +}; +Q_ENUM_NS(EncryptionProtocol) + } #endif // SHARED_ENUMS_H diff --git a/shared/keyinfo.cpp b/shared/keyinfo.cpp new file mode 100644 index 0000000..0c09d1f --- /dev/null +++ b/shared/keyinfo.cpp @@ -0,0 +1,46 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#include "keyinfo.h" + +using namespace Shared; + +Shared::KeyInfo::KeyInfo( + uint32_t p_id, + const QByteArray& p_fingerPrint, + const QString& p_label, + Shared::TrustLevel p_trustLevel, + Shared::EncryptionProtocol p_protocol, + bool p_currentDevice +): + id(p_id), + fingerPrint(p_fingerPrint), + label(p_label), + trustLevel(p_trustLevel), + protocol(p_protocol), + currentDevice(p_currentDevice) +{ +} + +Shared::KeyInfo::KeyInfo(): + id(0), + fingerPrint(), + label(), + trustLevel(TrustLevel::Undecided), + protocol(EncryptionProtocol::omemo), + currentDevice(false) +{ +} diff --git a/shared/keyinfo.h b/shared/keyinfo.h new file mode 100644 index 0000000..b5dc793 --- /dev/null +++ b/shared/keyinfo.h @@ -0,0 +1,55 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#ifndef SHARED_KEYINFO_H +#define SHARED_KEYINFO_H + +#include +#include + +#include + +#include "enums.h" + +namespace Shared { + +class KeyInfo +{ +public: + KeyInfo( + uint32_t id, + const QByteArray& + fingerPrint, + const QString& label, + TrustLevel trustLevel, + EncryptionProtocol protocol = EncryptionProtocol::omemo, + bool currentDevice = false + ); + KeyInfo(); + +private: + uint32_t id; + QByteArray fingerPrint; + QString label; + TrustLevel trustLevel; + EncryptionProtocol protocol; + bool currentDevice; + +}; + +} + +#endif // SHARED_KEYINFO_H diff --git a/shared/shared.h b/shared/shared.h index 1e86c5a..68e5c8d 100644 --- a/shared/shared.h +++ b/shared/shared.h @@ -26,5 +26,6 @@ #include "messageinfo.h" #include "utils.h" #include "vcard.h" +#include "keyinfo.h" #endif // SHARED_H diff --git a/ui/widgets/vcard/CMakeLists.txt b/ui/widgets/vcard/CMakeLists.txt index 51cbaab..c37f4c6 100644 --- a/ui/widgets/vcard/CMakeLists.txt +++ b/ui/widgets/vcard/CMakeLists.txt @@ -7,3 +7,7 @@ target_sources(squawk PRIVATE vcard.h vcard.ui ) + +if (WITH_OMEMO) + add_subdirectory(omemo) +endif() diff --git a/ui/widgets/vcard/omemo/CMakeLists.txt b/ui/widgets/vcard/omemo/CMakeLists.txt new file mode 100644 index 0000000..1468841 --- /dev/null +++ b/ui/widgets/vcard/omemo/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(squawk PRIVATE + omemo.cpp + omemo.h + omemo.ui +) diff --git a/ui/widgets/vcard/omemo/omemo.cpp b/ui/widgets/vcard/omemo/omemo.cpp new file mode 100644 index 0000000..7e39ec0 --- /dev/null +++ b/ui/widgets/vcard/omemo/omemo.cpp @@ -0,0 +1,20 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#include "omemo.h" +#include "ui_omemo.h" + +using namespace Ui; diff --git a/ui/widgets/vcard/omemo/omemo.h b/ui/widgets/vcard/omemo/omemo.h new file mode 100644 index 0000000..3dccbd3 --- /dev/null +++ b/ui/widgets/vcard/omemo/omemo.h @@ -0,0 +1,43 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#ifndef UI_OMEMO_H +#define UI_OMEMO_H + +#include +#include + +namespace Ui { + +namespace Ui +{ +class Omemo; +} + +/** + * @todo write docs + */ +class Omemo : public QWidget +{ + Q_OBJECT + +private: + QScopedPointer m_ui; +}; + +} + +#endif // UI_OMEMO_H diff --git a/ui/widgets/vcard/omemo/omemo.ui b/ui/widgets/vcard/omemo/omemo.ui new file mode 100644 index 0000000..095a3e0 --- /dev/null +++ b/ui/widgets/vcard/omemo/omemo.ui @@ -0,0 +1,142 @@ + + + Ui::Omemo + + + + 0 + 0 + 473 + 657 + + + + + 0 + + + 0 + + + 6 + + + 0 + + + 0 + + + + + + 24 + 75 + true + + + + OMEMO + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + true + + + + + 0 + 0 + 473 + 592 + + + + + + + + + + Qt::Horizontal + + + + + + + + 16 + 75 + true + + + + Active keys + + + + + + + + 16 + 75 + true + + + + Unused keys + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + +