mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Error Handling and some fixes
This commit is contained in:
parent
00e36b6068
commit
ffa61095b8
5 changed files with 144 additions and 102 deletions
|
@ -108,7 +108,18 @@ ApplicationWindow{
|
||||||
// userProfileList.ignoreUser()
|
// userProfileList.ignoreUser()
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
ImageButton{
|
||||||
|
image:":/icons/icons/ui/black-bubble-speech.png"
|
||||||
|
Layout.margins: {
|
||||||
|
left: 5
|
||||||
|
right: 5
|
||||||
|
}
|
||||||
|
ToolTip.visible: hovered
|
||||||
|
ToolTip.text: qsTr("Start a private chat")
|
||||||
|
onClicked : {
|
||||||
|
userProfileList.startChat()
|
||||||
|
}
|
||||||
|
}
|
||||||
ImageButton{
|
ImageButton{
|
||||||
image:":/icons/icons/ui/round-remove-button.png"
|
image:":/icons/icons/ui/round-remove-button.png"
|
||||||
Layout.margins: {
|
Layout.margins: {
|
||||||
|
@ -121,19 +132,6 @@ ApplicationWindow{
|
||||||
userProfileList.kickUser()
|
userProfileList.kickUser()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageButton{
|
|
||||||
image:":/icons/icons/ui/black-bubble-speech.png"
|
|
||||||
Layout.margins: {
|
|
||||||
left: 5
|
|
||||||
right: 5
|
|
||||||
}
|
|
||||||
ToolTip.visible: hovered
|
|
||||||
ToolTip.text: qsTr("Start a conversation")
|
|
||||||
onClicked : {
|
|
||||||
userProfileList.startChat()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
|
@ -205,7 +203,7 @@ ApplicationWindow{
|
||||||
text:"OK"
|
text:"OK"
|
||||||
onClicked: userProfileDialog.close()
|
onClicked: userProfileDialog.close()
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
|
||||||
|
|
||||||
Layout.margins : {
|
Layout.margins : {
|
||||||
right : 10
|
right : 10
|
||||||
|
|
|
@ -22,12 +22,6 @@ ApplicationWindow {
|
||||||
implicitHeight: currentItem.implicitHeight
|
implicitHeight: currentItem.implicitHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
onClosing: {
|
|
||||||
flow.cancelVerification();
|
|
||||||
deviceVerificationList.remove(flow.tranId);
|
|
||||||
delete flow;
|
|
||||||
}
|
|
||||||
|
|
||||||
property var flow
|
property var flow
|
||||||
Connections {
|
Connections {
|
||||||
target: flow
|
target: flow
|
||||||
|
@ -123,33 +117,6 @@ ApplicationWindow {
|
||||||
color:colors.text
|
color:colors.text
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
|
||||||
RadioButton {
|
|
||||||
id: decimalRadio
|
|
||||||
Layout.alignment: Qt.AlignLeft
|
|
||||||
text: qsTr("Decimal")
|
|
||||||
contentItem: Text {
|
|
||||||
text: decimalRadio.text
|
|
||||||
color: colors.text
|
|
||||||
}
|
|
||||||
onClicked: { flow.method = DeviceVerificationFlow.Decimal }
|
|
||||||
}
|
|
||||||
Item {
|
|
||||||
Layout.fillWidth: true
|
|
||||||
}
|
|
||||||
RadioButton {
|
|
||||||
id: emojiRadio
|
|
||||||
Layout.alignment: Qt.AlignRight
|
|
||||||
text: qsTr("Emoji")
|
|
||||||
contentItem: Text {
|
|
||||||
text: emojiRadio.text
|
|
||||||
color: colors.text
|
|
||||||
}
|
|
||||||
onClicked: { flow.method = DeviceVerificationFlow.Emoji }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Button {
|
Button {
|
||||||
Layout.alignment: Qt.AlignLeft
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
@ -165,9 +132,8 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
flow.cancelVerification();
|
flow.cancelVerification(DeviceVerificationFlow.User);
|
||||||
deviceVerificationList.remove(flow.tranId);
|
deviceVerificationList.remove(flow.tranId);
|
||||||
delete flow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
|
@ -227,9 +193,8 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
flow.cancelVerification();
|
flow.cancelVerification(DeviceVerificationFlow.User);
|
||||||
deviceVerificationList.remove(flow.tranId);
|
deviceVerificationList.remove(flow.tranId);
|
||||||
delete flow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
|
@ -261,14 +226,17 @@ ApplicationWindow {
|
||||||
Label {
|
Label {
|
||||||
font.pixelSize: Qt.application.font.pixelSize * 2
|
font.pixelSize: Qt.application.font.pixelSize * 2
|
||||||
text: flow.sasList[0]
|
text: flow.sasList[0]
|
||||||
|
color:colors.text
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
font.pixelSize: Qt.application.font.pixelSize * 2
|
font.pixelSize: Qt.application.font.pixelSize * 2
|
||||||
text: flow.sasList[1]
|
text: flow.sasList[1]
|
||||||
|
color:colors.text
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
font.pixelSize: Qt.application.font.pixelSize * 2
|
font.pixelSize: Qt.application.font.pixelSize * 2
|
||||||
text: flow.sasList[2]
|
text: flow.sasList[2]
|
||||||
|
color:colors.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,9 +255,8 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
flow.cancelVerification();
|
flow.cancelVerification(DeviceVerificationFlow.MismatchedSAS);
|
||||||
deviceVerificationList.remove(flow.tranId);
|
deviceVerificationList.remove(flow.tranId);
|
||||||
delete flow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
|
@ -411,6 +378,7 @@ ApplicationWindow {
|
||||||
implicitWidth: col.width
|
implicitWidth: col.width
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: col
|
id: col
|
||||||
|
Layout.fillWidth: true
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
property var emoji: emojis.mapping[flow.sasList[index]]
|
property var emoji: emojis.mapping[flow.sasList[index]]
|
||||||
Label {
|
Label {
|
||||||
|
@ -424,6 +392,7 @@ ApplicationWindow {
|
||||||
Label {
|
Label {
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
||||||
text: col.emoji.description
|
text: col.emoji.description
|
||||||
|
color:colors.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -445,9 +414,8 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
flow.cancelVerification();
|
flow.cancelVerification(DeviceVerificationFlow.MismatchedSAS);
|
||||||
deviceVerificationList.remove(flow.tranId);
|
deviceVerificationList.remove(flow.tranId);
|
||||||
delete flow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
|
@ -507,7 +475,7 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
flow.cancelVerification();
|
flow.cancelVerification(DeviceVerificationFlow.User);
|
||||||
deviceVerificationList.remove(flow.tranId);
|
deviceVerificationList.remove(flow.tranId);
|
||||||
delete flow;
|
delete flow;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,12 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
|
||||||
this->isMacVerified = false;
|
this->isMacVerified = false;
|
||||||
connect(timeout, &QTimer::timeout, this, [this]() {
|
connect(timeout, &QTimer::timeout, this, [this]() {
|
||||||
emit timedout();
|
emit timedout();
|
||||||
|
this->cancelVerification(DeviceVerificationFlow::Error::Timeout);
|
||||||
this->deleteLater();
|
this->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(ChatPage::instance(),
|
connect(
|
||||||
|
ChatPage::instance(),
|
||||||
&ChatPage::recievedDeviceVerificationStart,
|
&ChatPage::recievedDeviceVerificationStart,
|
||||||
this,
|
this,
|
||||||
[this](const mtx::events::collections::DeviceEvents &message) {
|
[this](const mtx::events::collections::DeviceEvents &message) {
|
||||||
|
@ -37,19 +39,28 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
|
||||||
(std::find(msg.content.message_authentication_codes.begin(),
|
(std::find(msg.content.message_authentication_codes.begin(),
|
||||||
msg.content.message_authentication_codes.end(),
|
msg.content.message_authentication_codes.end(),
|
||||||
"hmac-sha256") !=
|
"hmac-sha256") !=
|
||||||
msg.content.message_authentication_codes.end()) &&
|
msg.content.message_authentication_codes.end())) {
|
||||||
((std::find(msg.content.short_authentication_string.begin(),
|
if (std::find(msg.content.short_authentication_string.begin(),
|
||||||
msg.content.short_authentication_string.end(),
|
msg.content.short_authentication_string.end(),
|
||||||
mtx::events::msg::SASMethods::Decimal) !=
|
mtx::events::msg::SASMethods::Decimal) !=
|
||||||
msg.content.short_authentication_string.end()) ||
|
msg.content.short_authentication_string.end()) {
|
||||||
(std::find(msg.content.short_authentication_string.begin(),
|
this->method = DeviceVerificationFlow::Method::Emoji;
|
||||||
|
} else if (std::find(
|
||||||
|
msg.content.short_authentication_string.begin(),
|
||||||
msg.content.short_authentication_string.end(),
|
msg.content.short_authentication_string.end(),
|
||||||
mtx::events::msg::SASMethods::Emoji) !=
|
mtx::events::msg::SASMethods::Emoji) !=
|
||||||
msg.content.short_authentication_string.end()))) {
|
msg.content.short_authentication_string.end()) {
|
||||||
|
this->method = DeviceVerificationFlow::Method::Decimal;
|
||||||
|
} else {
|
||||||
|
this->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::UnknownMethod);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this->acceptVerificationRequest();
|
this->acceptVerificationRequest();
|
||||||
this->canonical_json = nlohmann::json(msg.content);
|
this->canonical_json = nlohmann::json(msg.content);
|
||||||
} else {
|
} else {
|
||||||
this->cancelVerification();
|
this->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::UnknownMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -76,7 +87,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
|
||||||
this->mac_method = msg.content.message_authentication_code;
|
this->mac_method = msg.content.message_authentication_code;
|
||||||
this->sendVerificationKey();
|
this->sendVerificationKey();
|
||||||
} else {
|
} else {
|
||||||
this->cancelVerification();
|
this->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::UnknownMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -130,7 +142,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
|
||||||
msg.content.key + this->canonical_json.dump()))) {
|
msg.content.key + this->canonical_json.dump()))) {
|
||||||
emit this->verificationRequestAccepted(this->method);
|
emit this->verificationRequestAccepted(this->method);
|
||||||
} else {
|
} else {
|
||||||
this->cancelVerification();
|
this->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::MismatchedCommitment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +169,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
|
||||||
this->sas->calculate_mac(this->device_keys[mac.first],
|
this->sas->calculate_mac(this->device_keys[mac.first],
|
||||||
info + mac.first)) {
|
info + mac.first)) {
|
||||||
} else {
|
} else {
|
||||||
this->cancelVerification();
|
this->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::KeyMismatch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +186,8 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
|
||||||
else
|
else
|
||||||
this->isMacVerified = true;
|
this->isMacVerified = true;
|
||||||
} else {
|
} else {
|
||||||
this->cancelVerification();
|
this->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::KeyMismatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -429,15 +444,31 @@ DeviceVerificationFlow::sendVerificationRequest()
|
||||||
}
|
}
|
||||||
//! cancels a verification flow
|
//! cancels a verification flow
|
||||||
void
|
void
|
||||||
DeviceVerificationFlow::cancelVerification()
|
DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_code)
|
||||||
{
|
{
|
||||||
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationCancel> body;
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationCancel> body;
|
||||||
mtx::events::msg::KeyVerificationCancel req;
|
mtx::events::msg::KeyVerificationCancel req;
|
||||||
|
|
||||||
req.transaction_id = this->transaction_id;
|
req.transaction_id = this->transaction_id;
|
||||||
// TODO: Add Proper Error Messages and Code
|
if (error_code == DeviceVerificationFlow::Error::UnknownMethod) {
|
||||||
req.reason = "Device Verification Cancelled";
|
req.code = "m.unknown_method";
|
||||||
req.code = "400";
|
req.reason = "unknown method recieved";
|
||||||
|
} else if (error_code == DeviceVerificationFlow::Error::MismatchedCommitment) {
|
||||||
|
req.code = "m.mismatched_commitment";
|
||||||
|
req.reason = "commitment didn't match";
|
||||||
|
} else if (error_code == DeviceVerificationFlow::Error::MismatchedSAS) {
|
||||||
|
req.code = "m.mismatched_sas";
|
||||||
|
req.reason = "sas didn't match";
|
||||||
|
} else if (error_code == DeviceVerificationFlow::Error::KeyMismatch) {
|
||||||
|
req.code = "m.key_match";
|
||||||
|
req.reason = "keys did not match";
|
||||||
|
} else if (error_code == DeviceVerificationFlow::Error::Timeout) {
|
||||||
|
req.code = "m.timeout";
|
||||||
|
req.reason = "timed out";
|
||||||
|
} else if (error_code == DeviceVerificationFlow::Error::User) {
|
||||||
|
req.code = "m.user";
|
||||||
|
req.reason = "user cancelled the verification";
|
||||||
|
}
|
||||||
|
|
||||||
body[this->toClient][deviceId.toStdString()] = req;
|
body[this->toClient][deviceId.toStdString()] = req;
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,16 @@ public:
|
||||||
Emoji
|
Emoji
|
||||||
};
|
};
|
||||||
Q_ENUM(Method)
|
Q_ENUM(Method)
|
||||||
|
enum Error
|
||||||
|
{
|
||||||
|
UnknownMethod,
|
||||||
|
MismatchedCommitment,
|
||||||
|
MismatchedSAS,
|
||||||
|
KeyMismatch,
|
||||||
|
Timeout,
|
||||||
|
User
|
||||||
|
};
|
||||||
|
Q_ENUM(Error)
|
||||||
|
|
||||||
DeviceVerificationFlow(QObject *parent = nullptr);
|
DeviceVerificationFlow(QObject *parent = nullptr);
|
||||||
QString getTransactionId();
|
QString getTransactionId();
|
||||||
|
@ -56,7 +66,7 @@ public slots:
|
||||||
//! starts the verification flow
|
//! starts the verification flow
|
||||||
void startVerificationRequest();
|
void startVerificationRequest();
|
||||||
//! cancels a verification flow
|
//! cancels a verification flow
|
||||||
void cancelVerification();
|
void cancelVerification(DeviceVerificationFlow::Error error_code);
|
||||||
//! sends the verification key
|
//! sends the verification key
|
||||||
void sendVerificationKey();
|
void sendVerificationKey();
|
||||||
//! sends the mac of the keys
|
//! sends the mac of the keys
|
||||||
|
|
|
@ -184,6 +184,9 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
|
||||||
QString::fromStdString(msg.content.transaction_id),
|
QString::fromStdString(msg.content.transaction_id),
|
||||||
QString::fromStdString(msg.sender),
|
QString::fromStdString(msg.sender),
|
||||||
QString::fromStdString(msg.content.from_device));
|
QString::fromStdString(msg.content.from_device));
|
||||||
|
} else {
|
||||||
|
flow->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::UnknownMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -197,11 +200,43 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin
|
||||||
auto flow = new DeviceVerificationFlow(this);
|
auto flow = new DeviceVerificationFlow(this);
|
||||||
flow->canonical_json = nlohmann::json(msg.content);
|
flow->canonical_json = nlohmann::json(msg.content);
|
||||||
if (!(this->dvList->exist(QString::fromStdString(msg.content.transaction_id)))) {
|
if (!(this->dvList->exist(QString::fromStdString(msg.content.transaction_id)))) {
|
||||||
|
if ((std::find(msg.content.key_agreement_protocols.begin(),
|
||||||
|
msg.content.key_agreement_protocols.end(),
|
||||||
|
"curve25519-hkdf-sha256") !=
|
||||||
|
msg.content.key_agreement_protocols.end()) &&
|
||||||
|
(std::find(msg.content.hashes.begin(),
|
||||||
|
msg.content.hashes.end(),
|
||||||
|
"sha256") != msg.content.hashes.end()) &&
|
||||||
|
(std::find(msg.content.message_authentication_codes.begin(),
|
||||||
|
msg.content.message_authentication_codes.end(),
|
||||||
|
"hmac-sha256") !=
|
||||||
|
msg.content.message_authentication_codes.end())) {
|
||||||
|
if (std::find(msg.content.short_authentication_string.begin(),
|
||||||
|
msg.content.short_authentication_string.end(),
|
||||||
|
mtx::events::msg::SASMethods::Emoji) !=
|
||||||
|
msg.content.short_authentication_string.end()) {
|
||||||
|
flow->setMethod(DeviceVerificationFlow::Method::Emoji);
|
||||||
|
} else if (std::find(
|
||||||
|
msg.content.short_authentication_string.begin(),
|
||||||
|
msg.content.short_authentication_string.end(),
|
||||||
|
mtx::events::msg::SASMethods::Decimal) !=
|
||||||
|
msg.content.short_authentication_string.end()) {
|
||||||
|
flow->setMethod(DeviceVerificationFlow::Method::Decimal);
|
||||||
|
} else {
|
||||||
|
flow->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::UnknownMethod);
|
||||||
|
return;
|
||||||
|
}
|
||||||
emit newDeviceVerificationRequest(
|
emit newDeviceVerificationRequest(
|
||||||
std::move(flow),
|
std::move(flow),
|
||||||
QString::fromStdString(msg.content.transaction_id),
|
QString::fromStdString(msg.content.transaction_id),
|
||||||
QString::fromStdString(msg.sender),
|
QString::fromStdString(msg.sender),
|
||||||
QString::fromStdString(msg.content.from_device));
|
QString::fromStdString(msg.content.from_device));
|
||||||
|
flow->canonical_json = nlohmann::json(msg.content);
|
||||||
|
} else {
|
||||||
|
flow->cancelVerification(
|
||||||
|
DeviceVerificationFlow::Error::UnknownMethod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue