1
0
forked from blue/squawk

some initial work and thoughts about encryption

This commit is contained in:
Blue 2023-01-01 20:25:51 +03:00
parent 758a9d95f3
commit b45a73b723
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
12 changed files with 342 additions and 18 deletions

View File

@ -368,23 +368,23 @@ QFuture<void> TrustHandler::setSecurityPolicy(
Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level) Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level)
{ {
switch (level) { switch (level) {
case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::Undecided; case QXmpp::TrustLevel::Undecided: return Shared::TrustLevel::undecided;
case QXmpp::TrustLevel::AutomaticallyDistrusted: return Shared::TrustLevel::AutomaticallyDistrusted; case QXmpp::TrustLevel::AutomaticallyDistrusted: return Shared::TrustLevel::automaticallyDistrusted;
case QXmpp::TrustLevel::ManuallyDistrusted: return Shared::TrustLevel::ManuallyDistrusted; case QXmpp::TrustLevel::ManuallyDistrusted: return Shared::TrustLevel::manuallyDistrusted;
case QXmpp::TrustLevel::AutomaticallyTrusted: return Shared::TrustLevel::AutomaticallyTrusted; case QXmpp::TrustLevel::AutomaticallyTrusted: return Shared::TrustLevel::automaticallyTrusted;
case QXmpp::TrustLevel::ManuallyTrusted: return Shared::TrustLevel::ManuallyTrusted; case QXmpp::TrustLevel::ManuallyTrusted: return Shared::TrustLevel::manuallyTrusted;
case QXmpp::TrustLevel::Authenticated: return Shared::TrustLevel::Authenticated; case QXmpp::TrustLevel::Authenticated: return Shared::TrustLevel::authenticated;
} }
} }
Core::TrustHandler::TL Core::TrustHandler::convert(Shared::TrustLevel level) Core::TrustHandler::TL Core::TrustHandler::convert(Shared::TrustLevel level)
{ {
switch (level) { switch (level) {
case Shared::TrustLevel::Undecided: return QXmpp::TrustLevel::Undecided; case Shared::TrustLevel::undecided: return QXmpp::TrustLevel::Undecided;
case Shared::TrustLevel::AutomaticallyDistrusted: return QXmpp::TrustLevel::AutomaticallyDistrusted; case Shared::TrustLevel::automaticallyDistrusted: return QXmpp::TrustLevel::AutomaticallyDistrusted;
case Shared::TrustLevel::ManuallyDistrusted: return QXmpp::TrustLevel::ManuallyDistrusted; case Shared::TrustLevel::manuallyDistrusted: return QXmpp::TrustLevel::ManuallyDistrusted;
case Shared::TrustLevel::AutomaticallyTrusted: return QXmpp::TrustLevel::AutomaticallyTrusted; case Shared::TrustLevel::automaticallyTrusted: return QXmpp::TrustLevel::AutomaticallyTrusted;
case Shared::TrustLevel::ManuallyTrusted: return QXmpp::TrustLevel::ManuallyTrusted; case Shared::TrustLevel::manuallyTrusted: return QXmpp::TrustLevel::ManuallyTrusted;
case Shared::TrustLevel::Authenticated: return QXmpp::TrustLevel::Authenticated; case Shared::TrustLevel::authenticated: return QXmpp::TrustLevel::Authenticated;
} }
} }

View File

@ -50,6 +50,7 @@ int main(int argc, char *argv[])
qRegisterMetaType<QSet<QString>>("QSet<QString>"); qRegisterMetaType<QSet<QString>>("QSet<QString>");
qRegisterMetaType<Shared::ConnectionState>("Shared::ConnectionState"); qRegisterMetaType<Shared::ConnectionState>("Shared::ConnectionState");
qRegisterMetaType<Shared::Availability>("Shared::Availability"); qRegisterMetaType<Shared::Availability>("Shared::Availability");
qRegisterMetaType<Shared::KeyInfo>("Shared::KeyInfo");
#ifdef WITH_OMEMO #ifdef WITH_OMEMO
qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice"); qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
qRegisterMetaTypeStreamOperators<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice"); qRegisterMetaTypeStreamOperators<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");

View File

@ -26,4 +26,6 @@ target_sources(squawk PRIVATE
form.cpp form.cpp
field.h field.h
field.cpp field.cpp
keyinfo.cpp
keyinfo.h
) )

View File

@ -127,23 +127,28 @@ Q_ENUM_NS(Support)
enum class TrustLevel { enum class TrustLevel {
/// The key's trust is not decided. /// The key's trust is not decided.
Undecided, undecided,
/// The key is automatically distrusted (e.g., by the security policy TOAKAFA). /// The key is automatically distrusted (e.g., by the security policy TOAKAFA).
/// \see SecurityPolicy /// \see SecurityPolicy
AutomaticallyDistrusted, automaticallyDistrusted,
/// The key is manually distrusted (e.g., by clicking a button or \xep{0450, Automatic Trust /// The key is manually distrusted (e.g., by clicking a button or \xep{0450, Automatic Trust
/// Management (ATM)}). /// Management (ATM)}).
ManuallyDistrusted, manuallyDistrusted,
/// The key is automatically trusted (e.g., by the client for all keys of a bare JID until one /// The key is automatically trusted (e.g., by the client for all keys of a bare JID until one
/// of it is authenticated). /// of it is authenticated).
AutomaticallyTrusted, automaticallyTrusted,
/// The key is manually trusted (e.g., by clicking a button). /// 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 /// The key is authenticated (e.g., by QR code scanning or \xep{0450, Automatic Trust
/// Management (ATM)}). /// Management (ATM)}).
Authenticated authenticated
}; };
Q_ENUM_NS(TrustLevel) Q_ENUM_NS(TrustLevel)
enum class EncryptionProtocol {
omemo
};
Q_ENUM_NS(EncryptionProtocol)
} }
#endif // SHARED_ENUMS_H #endif // SHARED_ENUMS_H

46
shared/keyinfo.cpp Normal file
View File

@ -0,0 +1,46 @@
// 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 "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)
{
}

55
shared/keyinfo.h Normal file
View File

@ -0,0 +1,55 @@
// 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/>.
#ifndef SHARED_KEYINFO_H
#define SHARED_KEYINFO_H
#include <QString>
#include <QByteArray>
#include <stdint.h>
#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

View File

@ -26,5 +26,6 @@
#include "messageinfo.h" #include "messageinfo.h"
#include "utils.h" #include "utils.h"
#include "vcard.h" #include "vcard.h"
#include "keyinfo.h"
#endif // SHARED_H #endif // SHARED_H

View File

@ -7,3 +7,7 @@ target_sources(squawk PRIVATE
vcard.h vcard.h
vcard.ui vcard.ui
) )
if (WITH_OMEMO)
add_subdirectory(omemo)
endif()

View File

@ -0,0 +1,5 @@
target_sources(squawk PRIVATE
omemo.cpp
omemo.h
omemo.ui
)

View File

@ -0,0 +1,20 @@
// 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 "omemo.h"
#include "ui_omemo.h"
using namespace Ui;

View File

@ -0,0 +1,43 @@
// 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/>.
#ifndef UI_OMEMO_H
#define UI_OMEMO_H
#include <qwidget.h>
#include <QScopedPointer>
namespace Ui {
namespace Ui
{
class Omemo;
}
/**
* @todo write docs
*/
class Omemo : public QWidget
{
Q_OBJECT
private:
QScopedPointer<Ui::Omemo> m_ui;
};
}
#endif // UI_OMEMO_H

View File

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Ui::Omemo</class>
<widget class="QWidget" name="Ui::Omemo">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>473</width>
<height>657</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="OMEMOHeading">
<property name="font">
<font>
<pointsize>24</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>OMEMO</string>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>473</width>
<height>592</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QListView" name="keysView"/>
</item>
<item row="3" column="1">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="keysHeading">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Active keys</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="unusedKeysHeading">
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Unused keys</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QListView" name="unusedKeysView"/>
</item>
<item row="0" column="0" rowspan="6">
<spacer name="spacerLeft">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2" rowspan="6">
<spacer name="spacerRight">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>