summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DeviceVerificationFlow.cpp70
-rw-r--r--src/DeviceVerificationFlow.h10
2 files changed, 78 insertions, 2 deletions
diff --git a/src/DeviceVerificationFlow.cpp b/src/DeviceVerificationFlow.cpp

index 69d6ab9c..12e31c04 100644 --- a/src/DeviceVerificationFlow.cpp +++ b/src/DeviceVerificationFlow.cpp
@@ -1,5 +1,8 @@ #include "DeviceVerificationFlow.h" +#include <MatrixClient.h> +#include <QDateTime> +#include <QDebug> // only for debugging #include <QTimer> static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes @@ -15,17 +18,80 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *) timeout->start(TIMEOUT); } -//! accepts a verification and starts the verification flow +std::string +DeviceVerificationFlow::generate_txn_id() +{ + this->transaction_id = mtx::client::utils::random_token(32, false); + return this->transaction_id; +} + +//! accepts a verification void DeviceVerificationFlow::acceptVerificationRequest() { + mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationAccept> body; + mtx::events::msg::KeyVerificationAccept req; + + req.transaction_id = this->transaction_id; + req.method = mtx::events::msg::VerificationMethods::SASv1; + req.key_agreement_protocol = ""; + req.hash = ""; + req.message_authentication_code = ""; + // req.short_authentication_string = ""; + req.commitment = ""; + emit verificationRequestAccepted(rand() % 2 ? Emoji : Decimal); + + // Yet to add send to_device message +} +//! starts the verification flow +void +DeviceVerificationFlow::startVerificationRequest() +{ + mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationAccept> body; + mtx::events::msg::KeyVerificationAccept req; + + // req.from_device = ""; + req.transaction_id = this->transaction_id; + req.method = mtx::events::msg::VerificationMethods::SASv1; + req.key_agreement_protocol = {}; + // req.hashes = {}; + req.message_authentication_code = {}; + // req.short_authentication_string = ""; + + // Yet to add send to_device message +} +//! sends a verification request +void +DeviceVerificationFlow::sendVerificationRequest() +{ + QDateTime CurrentTime = QDateTime::currentDateTimeUtc(); + + mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationRequest> body; + mtx::events::msg::KeyVerificationRequest req; + + req.from_device = ""; + req.transaction_id = generate_txn_id(); + req.methods.resize(1); + req.methods[0] = mtx::events::msg::VerificationMethods::SASv1; + req.timestamp = (uint64_t)CurrentTime.toTime_t(); + + // Yet to add send to_device message } //! cancels a verification flow void DeviceVerificationFlow::cancelVerification() { + mtx::requests::ToDeviceMessages<mtx::events::msg::KeyVerificationCancel> body; + mtx::events::msg::KeyVerificationCancel req; + + req.transaction_id = this->transaction_id; + req.reason = ""; + req.code = ""; + this->deleteLater(); + + // Yet to add send to_device message } //! Completes the verification flow void @@ -33,4 +99,6 @@ DeviceVerificationFlow::acceptDevice() { emit deviceVerified(); this->deleteLater(); + + // Yet to add send to_device message } diff --git a/src/DeviceVerificationFlow.h b/src/DeviceVerificationFlow.h
index 038f1e13..71c40cd5 100644 --- a/src/DeviceVerificationFlow.h +++ b/src/DeviceVerificationFlow.h
@@ -20,8 +20,12 @@ public: DeviceVerificationFlow(QObject *parent = nullptr); public slots: - //! accepts a verification and starts the verification flow + //! sends a verification request + void sendVerificationRequest(); + //! accepts a verification void acceptVerificationRequest(); + //! starts the verification flow + void startVerificationRequest(); //! cancels a verification flow void cancelVerification(); //! Completes the verification flow @@ -34,5 +38,9 @@ signals: void verificationCanceled(); private: + //! generates a unique transaction id + std::string generate_txn_id(); + QTimer *timeout = nullptr; + std::string transaction_id; };