Add SAS Method choice and Add send_to_device API call
This commit is contained in:
parent
b628f485ff
commit
cd5dd0e39b
@ -107,18 +107,28 @@ ApplicationWindow{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button{
|
Button{
|
||||||
|
id: verifyButton
|
||||||
text:"Verify"
|
text:"Verify"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var dialog = deviceVerificationDialog.createObject(userProfileDialog,
|
var dialog = deviceVerificationDialog.createObject(userProfileDialog,
|
||||||
{flow: deviceVerificationFlow,sender: true});
|
{flow: deviceVerificationFlow,sender: false});
|
||||||
|
deviceVerificationFlow.userId = user_data.userId
|
||||||
|
deviceVerificationFlow.deviceId = model.deviceID
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
contentItem: Text {
|
||||||
|
text: verifyButton.text
|
||||||
|
color: colors.background
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button{
|
Button{
|
||||||
|
id: okbutton
|
||||||
text:"OK"
|
text:"OK"
|
||||||
onClicked: userProfileDialog.close()
|
onClicked: userProfileDialog.close()
|
||||||
anchors.margins: {
|
anchors.margins: {
|
||||||
@ -126,6 +136,13 @@ ApplicationWindow{
|
|||||||
bottom:10
|
bottom:10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentItem: Text {
|
||||||
|
text: okbutton.text
|
||||||
|
color: colors.background
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
}
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
|
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,22 @@ ApplicationWindow {
|
|||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
RadioButton {
|
||||||
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
text: "Decimal"
|
||||||
|
onClicked: { flow.method = DeviceVerificationFlow.Decimal }
|
||||||
|
}
|
||||||
|
Item {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
RadioButton {
|
||||||
|
Layout.alignment: Qt.AlignRight
|
||||||
|
text: "Emoji"
|
||||||
|
onClicked: { flow.method = DeviceVerificationFlow.Emoji }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Button {
|
Button {
|
||||||
Layout.alignment: Qt.AlignLeft
|
Layout.alignment: Qt.AlignLeft
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#include "DeviceVerificationFlow.h"
|
#include "DeviceVerificationFlow.h"
|
||||||
|
|
||||||
#include <MatrixClient.h>
|
#include "Logging.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug> // only for debugging
|
#include <QDebug> // only for debugging
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <iostream> // only for debugging
|
||||||
|
|
||||||
static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
||||||
|
|
||||||
@ -18,11 +19,42 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *)
|
|||||||
timeout->start(TIMEOUT);
|
timeout->start(TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
QString
|
||||||
DeviceVerificationFlow::generate_txn_id()
|
DeviceVerificationFlow::getUserId()
|
||||||
{
|
{
|
||||||
this->transaction_id = mtx::client::utils::random_token(32, false);
|
toClient = mtx::identifiers::parse<mtx::identifiers::User>((this->userId).toStdString());
|
||||||
return this->transaction_id;
|
std::cout << http::client()->device_id() << std::endl;
|
||||||
|
return this->userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
DeviceVerificationFlow::getDeviceId()
|
||||||
|
{
|
||||||
|
return this->deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceVerificationFlow::Method
|
||||||
|
DeviceVerificationFlow::getMethod()
|
||||||
|
{
|
||||||
|
return this->method;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DeviceVerificationFlow::setUserId(QString userID)
|
||||||
|
{
|
||||||
|
this->userId = userID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DeviceVerificationFlow::setDeviceId(QString deviceID)
|
||||||
|
{
|
||||||
|
this->deviceId = deviceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DeviceVerificationFlow::setMethod(DeviceVerificationFlow::Method method_)
|
||||||
|
{
|
||||||
|
this->method = method_;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! accepts a verification
|
//! accepts a verification
|
||||||
@ -34,32 +66,53 @@ DeviceVerificationFlow::acceptVerificationRequest()
|
|||||||
|
|
||||||
req.transaction_id = this->transaction_id;
|
req.transaction_id = this->transaction_id;
|
||||||
req.method = mtx::events::msg::VerificationMethods::SASv1;
|
req.method = mtx::events::msg::VerificationMethods::SASv1;
|
||||||
req.key_agreement_protocol = "";
|
req.key_agreement_protocol = "curve25519";
|
||||||
req.hash = "";
|
req.hash = "sha256";
|
||||||
req.message_authentication_code = "";
|
req.message_authentication_code = "";
|
||||||
// req.short_authentication_string = "";
|
// req.short_authentication_string = "";
|
||||||
req.commitment = "";
|
req.commitment = "";
|
||||||
|
|
||||||
emit verificationRequestAccepted(rand() % 2 ? Emoji : Decimal);
|
emit this->verificationRequestAccepted(this->method);
|
||||||
|
|
||||||
// Yet to add send to_device message
|
body[this->toClient][this->deviceId.toStdString()] = req;
|
||||||
|
|
||||||
|
http::client()
|
||||||
|
->send_to_device<mtx::events::msg::KeyVerificationAccept,
|
||||||
|
mtx::events::EventType::KeyVerificationAccept>(
|
||||||
|
"m.key.verification.accept", body, [](mtx::http::RequestErr err) {
|
||||||
|
if (err)
|
||||||
|
nhlog::net()->warn("failed to accept verification request: {} {}",
|
||||||
|
err->matrix_error.error,
|
||||||
|
static_cast<int>(err->status_code));
|
||||||
|
// emit this->verificationRequestAccepted(rand() % 2 ? Emoji : Decimal);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
//! starts the verification flow
|
//! starts the verification flow
|
||||||
void
|
void
|
||||||
DeviceVerificationFlow::startVerificationRequest()
|
DeviceVerificationFlow::startVerificationRequest()
|
||||||
{
|
{
|
||||||
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationAccept> body;
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationStart> body;
|
||||||
mtx::events::msg::KeyVerificationAccept req;
|
mtx::events::msg::KeyVerificationStart req;
|
||||||
|
|
||||||
// req.from_device = "";
|
req.from_device = http::client()->device_id();
|
||||||
req.transaction_id = this->transaction_id;
|
req.transaction_id = this->transaction_id;
|
||||||
req.method = mtx::events::msg::VerificationMethods::SASv1;
|
req.method = mtx::events::msg::VerificationMethods::SASv1;
|
||||||
req.key_agreement_protocol = {};
|
req.key_agreement_protocols = {};
|
||||||
// req.hashes = {};
|
req.hashes = {};
|
||||||
req.message_authentication_code = {};
|
req.message_authentication_codes = {};
|
||||||
// req.short_authentication_string = "";
|
// req.short_authentication_string = "";
|
||||||
|
|
||||||
// Yet to add send to_device message
|
body[this->toClient][this->deviceId.toStdString()] = req;
|
||||||
|
|
||||||
|
http::client()
|
||||||
|
->send_to_device<mtx::events::msg::KeyVerificationStart,
|
||||||
|
mtx::events::EventType::KeyVerificationStart>(
|
||||||
|
"m.key.verification.start", body, [](mtx::http::RequestErr err) {
|
||||||
|
if (err)
|
||||||
|
nhlog::net()->warn("failed to start verification request: {} {}",
|
||||||
|
err->matrix_error.error,
|
||||||
|
static_cast<int>(err->status_code));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
//! sends a verification request
|
//! sends a verification request
|
||||||
void
|
void
|
||||||
@ -70,13 +123,25 @@ DeviceVerificationFlow::sendVerificationRequest()
|
|||||||
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationRequest> body;
|
mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationRequest> body;
|
||||||
mtx::events::msg::KeyVerificationRequest req;
|
mtx::events::msg::KeyVerificationRequest req;
|
||||||
|
|
||||||
req.from_device = "";
|
this->transaction_id = http::client()->generate_txn_id();
|
||||||
req.transaction_id = generate_txn_id();
|
|
||||||
|
req.from_device = http::client()->device_id();
|
||||||
|
req.transaction_id = this->transaction_id;
|
||||||
req.methods.resize(1);
|
req.methods.resize(1);
|
||||||
req.methods[0] = mtx::events::msg::VerificationMethods::SASv1;
|
req.methods[0] = mtx::events::msg::VerificationMethods::SASv1;
|
||||||
req.timestamp = (uint64_t)CurrentTime.toTime_t();
|
req.timestamp = (uint64_t)CurrentTime.toTime_t();
|
||||||
|
|
||||||
// Yet to add send to_device message
|
body[this->toClient][this->deviceId.toStdString()] = req;
|
||||||
|
|
||||||
|
http::client()
|
||||||
|
->send_to_device<mtx::events::msg::KeyVerificationRequest,
|
||||||
|
mtx::events::EventType::KeyVerificationRequest>(
|
||||||
|
"m.key.verification.request", body, [](mtx::http::RequestErr err) {
|
||||||
|
if (err)
|
||||||
|
nhlog::net()->warn("failed to send verification request: {} {}",
|
||||||
|
err->matrix_error.error,
|
||||||
|
static_cast<int>(err->status_code));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
//! cancels a verification flow
|
//! cancels a verification flow
|
||||||
void
|
void
|
||||||
@ -86,12 +151,22 @@ DeviceVerificationFlow::cancelVerification()
|
|||||||
mtx::events::msg::KeyVerificationCancel req;
|
mtx::events::msg::KeyVerificationCancel req;
|
||||||
|
|
||||||
req.transaction_id = this->transaction_id;
|
req.transaction_id = this->transaction_id;
|
||||||
req.reason = "";
|
// TODO: Add Proper Error Messages and Code
|
||||||
req.code = "";
|
req.reason = "Device Verification Cancelled";
|
||||||
|
req.code = "400";
|
||||||
|
|
||||||
|
body[this->toClient][deviceId.toStdString()] = req;
|
||||||
|
|
||||||
|
http::client()
|
||||||
|
->send_to_device<mtx::events::msg::KeyVerificationCancel,
|
||||||
|
mtx::events::EventType::KeyVerificationCancel>(
|
||||||
|
"m.key.verification.cancel", body, [this](mtx::http::RequestErr err) {
|
||||||
|
if (err)
|
||||||
|
nhlog::net()->warn("failed to cancel verification request: {} {}",
|
||||||
|
err->matrix_error.error,
|
||||||
|
static_cast<int>(err->status_code));
|
||||||
this->deleteLater();
|
this->deleteLater();
|
||||||
|
});
|
||||||
// Yet to add send to_device message
|
|
||||||
}
|
}
|
||||||
//! Completes the verification flow
|
//! Completes the verification flow
|
||||||
void
|
void
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <MatrixClient.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
@ -8,6 +9,9 @@ class DeviceVerificationFlow : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
|
// Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
|
||||||
|
Q_PROPERTY(QString userId READ getUserId WRITE setUserId)
|
||||||
|
Q_PROPERTY(QString deviceId READ getDeviceId WRITE setDeviceId)
|
||||||
|
Q_PROPERTY(Method method READ getMethod WRITE setMethod)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Method
|
enum Method
|
||||||
@ -18,6 +22,12 @@ public:
|
|||||||
Q_ENUM(Method)
|
Q_ENUM(Method)
|
||||||
|
|
||||||
DeviceVerificationFlow(QObject *parent = nullptr);
|
DeviceVerificationFlow(QObject *parent = nullptr);
|
||||||
|
QString getUserId();
|
||||||
|
QString getDeviceId();
|
||||||
|
Method getMethod();
|
||||||
|
void setUserId(QString userID);
|
||||||
|
void setDeviceId(QString deviceID);
|
||||||
|
void setMethod(Method method_);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! sends a verification request
|
//! sends a verification request
|
||||||
@ -38,9 +48,11 @@ signals:
|
|||||||
void verificationCanceled();
|
void verificationCanceled();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! generates a unique transaction id
|
QString userId;
|
||||||
std::string generate_txn_id();
|
QString deviceId;
|
||||||
|
Method method;
|
||||||
|
|
||||||
QTimer *timeout = nullptr;
|
QTimer *timeout = nullptr;
|
||||||
std::string transaction_id;
|
std::string transaction_id;
|
||||||
|
mtx::identifiers::User toClient;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user