airgap: allow transmitting view-only details over UR

This commit is contained in:
tobtoht 2023-12-05 22:06:48 +01:00
parent 3dd6dbc9ba
commit 87aae77fda
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
13 changed files with 167 additions and 42 deletions

View file

@ -405,6 +405,9 @@ void MainWindow::initOffline() {
connect(ui->btn_help, &QPushButton::clicked, [this] { connect(ui->btn_help, &QPushButton::clicked, [this] {
windowManager()->showDocs(this, "offline_tx_signing"); windowManager()->showDocs(this, "offline_tx_signing");
}); });
connect(ui->btn_viewOnlyDetails, &QPushButton::clicked, [this] {
this->showViewOnlyDialog();
});
connect(ui->btn_checkAddress, &QPushButton::clicked, [this]{ connect(ui->btn_checkAddress, &QPushButton::clicked, [this]{
AddressCheckerIndexDialog dialog{m_wallet, this}; AddressCheckerIndexDialog dialog{m_wallet, this};
dialog.exec(); dialog.exec();

View file

@ -403,6 +403,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="btn_viewOnlyDetails">
<property name="text">
<string>View-only details</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="btn_checkAddress"> <widget class="QPushButton" name="btn_checkAddress">
<property name="text"> <property name="text">

View file

@ -8,12 +8,29 @@
#include "utils/Utils.h" #include "utils/Utils.h"
URDialog::URDialog(QWidget *parent) URDialog::URDialog(QWidget *parent, const QString &data, bool scanOnly)
: WindowModalDialog(parent) : WindowModalDialog(parent)
, ui(new Ui::URDialog) , ui(new Ui::URDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
if (!data.isEmpty()) {
ui->btn_loadFile->setVisible(false);
ui->btn_loadClipboard->setVisible(false);
ui->tabWidget->setTabVisible(1, false);
QScreen *currentScreen = QApplication::screenAt(this->geometry().center());
if (!currentScreen) {
currentScreen = QApplication::primaryScreen();
}
int availableHeight = currentScreen->availableGeometry().height() - 200;
this->resize(availableHeight, availableHeight);
std::string d = data.toStdString();
ui->widgetUR->setData("xmr-viewonly", d);
return;
}
connect(ui->btn_loadFile, &QPushButton::clicked, [this]{ connect(ui->btn_loadFile, &QPushButton::clicked, [this]{
QString fn = QFileDialog::getOpenFileName(this, "Load file", QDir::homePath(), "All Files (*)"); QString fn = QFileDialog::getOpenFileName(this, "Load file", QDir::homePath(), "All Files (*)");
if (fn.isEmpty()) { if (fn.isEmpty()) {
@ -41,7 +58,7 @@ URDialog::URDialog(QWidget *parent)
std::string data = qdata.toStdString(); std::string data = qdata.toStdString();
ui->widgetUR->setData("ana", data); ui->widgetUR->setData("any", data);
}); });
connect(ui->tabWidget, &QTabWidget::currentChanged, [this](int index){ connect(ui->tabWidget, &QTabWidget::currentChanged, [this](int index){
@ -51,44 +68,76 @@ URDialog::URDialog(QWidget *parent)
}); });
connect(ui->widgetScanner, &QrCodeScanWidget::finished, [this](bool success){ connect(ui->widgetScanner, &QrCodeScanWidget::finished, [this](bool success){
if (!success) { if (!success) {
Utils::showError(this, "Unable to scan UR"); Utils::showError(this, "Unable to scan UR");
ui->widgetScanner->reset(); ui->widgetScanner->reset();
return; return;
} }
if (ui->radio_clipboard->isChecked()) { if (ui->widgetScanner->getURType() == "xmr-viewonly") {
Utils::copyToClipboard(QString::fromStdString(ui->widgetScanner->getURData())); QRegularExpression viewOnlyDetails(
Utils::showInfo(this, "Data copied to clipboard"); "Secret view key: (?<key>[0-9a-f]{64})\nAddress: (?<address>\\w+)\nRestore height: (?<restoreheight>\\d+)\nWallet name: (?<walletname>\\w+)\n",
} QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption);
else if (ui->radio_file->isChecked()) { QString data = QString::fromStdString(ui->widgetScanner->getURData());
QString fn = QFileDialog::getSaveFileName(this, "Save to file", QDir::homePath(), "ur_data"); QRegularExpressionMatch match = viewOnlyDetails.match(data);
if (fn.isEmpty()) {
ui->widgetScanner->reset();
return;
}
QFile file{fn}; if (!match.hasMatch()) {
if (!file.open(QIODevice::WriteOnly)) { Utils::showError(this, "Unable to load view-only details", "Unexpected data");
Utils::showError(this, "Failed to save file", QString("Could not open file %1 for writing").arg(fn)); return;
ui->widgetScanner->reset(); }
return;
}
std::string data = ui->widgetScanner->getURData(); m_viewOnlyDetails.address = match.captured("address");
file.write(data.data(), data.size()); m_viewOnlyDetails.key = match.captured("key").toLower();
file.close(); m_viewOnlyDetails.restoreHeight = match.captured("restoreheight").toInt();
m_viewOnlyDetails.walletName = QString("%1_view_only").arg(match.captured("walletname"));
Utils::showInfo(this, "Successfully saved data to file");
} this->accept();
}
ui->widgetScanner->reset();
if (ui->radio_clipboard->isChecked()) {
Utils::copyToClipboard(QString::fromStdString(ui->widgetScanner->getURData()));
Utils::showInfo(this, "Data copied to clipboard");
}
else if (ui->radio_file->isChecked()) {
QString fn = QFileDialog::getSaveFileName(this, "Save to file", QDir::homePath(), "ur_data");
if (fn.isEmpty()) {
ui->widgetScanner->reset();
return;
}
QFile file{fn};
if (!file.open(QIODevice::WriteOnly)) {
Utils::showError(this, "Failed to save file", QString("Could not open file %1 for writing").arg(fn));
ui->widgetScanner->reset();
return;
}
std::string data = ui->widgetScanner->getURData();
file.write(data.data(), data.size());
file.close();
Utils::showInfo(this, "Successfully saved data to file");
}
ui->widgetScanner->reset();
}); });
if (scanOnly) {
ui->tabWidget->setCurrentIndex(1);
ui->tabWidget->setTabVisible(0, false);
ui->radio_clipboard->setVisible(false);
ui->radio_file->setVisible(false);
return;
}
ui->radio_file->setChecked(true); ui->radio_file->setChecked(true);
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
this->resize(600, 700); this->resize(600, 700);
} }
ViewOnlyDetails URDialog::getViewOnlyDetails() {
return m_viewOnlyDetails;
}
URDialog::~URDialog() = default; URDialog::~URDialog() = default;

View file

@ -12,16 +12,26 @@ namespace Ui {
class URDialog; class URDialog;
} }
struct ViewOnlyDetails {
QString address;
QString key;
int restoreHeight = 0;
QString walletName;
};
class URDialog : public WindowModalDialog class URDialog : public WindowModalDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit URDialog(QWidget *parent = nullptr); explicit URDialog(QWidget *parent, const QString &data = "", bool scanOnly = false);
~URDialog() override; ~URDialog() override;
ViewOnlyDetails getViewOnlyDetails();
private: private:
QScopedPointer<Ui::URDialog> ui; QScopedPointer<Ui::URDialog> ui;
ViewOnlyDetails m_viewOnlyDetails;
}; };

View file

@ -8,6 +8,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include "URDialog.h"
#include "utils/Utils.h" #include "utils/Utils.h"
ViewOnlyDialog::ViewOnlyDialog(Wallet *wallet, QWidget *parent) ViewOnlyDialog::ViewOnlyDialog(Wallet *wallet, QWidget *parent)
@ -23,6 +24,10 @@ ViewOnlyDialog::ViewOnlyDialog(Wallet *wallet, QWidget *parent)
connect(ui->btn_Copy, &QPushButton::clicked, this, &ViewOnlyDialog::copyToClipboard); connect(ui->btn_Copy, &QPushButton::clicked, this, &ViewOnlyDialog::copyToClipboard);
connect(ui->btn_Save, &QPushButton::clicked, this, &ViewOnlyDialog::onWriteViewOnlyWallet); connect(ui->btn_Save, &QPushButton::clicked, this, &ViewOnlyDialog::onWriteViewOnlyWallet);
connect(ui->btn_transmitOverUR, &QPushButton::clicked, [this] {
URDialog dialog{this, this->toString()};
dialog.exec();
});
if (m_wallet->viewOnly()) { if (m_wallet->viewOnly()) {
ui->btn_Save->setEnabled(false); ui->btn_Save->setEnabled(false);
@ -52,12 +57,17 @@ void ViewOnlyDialog::onWriteViewOnlyWallet(){
QMessageBox::information(this, "Information", "View-only wallet successfully written to disk."); QMessageBox::information(this, "Information", "View-only wallet successfully written to disk.");
} }
void ViewOnlyDialog::copyToClipboard() { QString ViewOnlyDialog::toString() {
QString text = ""; QString text;
text += QString("Address: %1\n").arg(ui->label_primaryAddress->text());
text += QString("Secret view key: %1\n").arg(ui->label_secretViewKey->text()); text += QString("Secret view key: %1\n").arg(ui->label_secretViewKey->text());
text += QString("Address: %1\n").arg(ui->label_primaryAddress->text());
text += QString("Restore height: %1\n").arg(ui->label_restoreHeight->text()); text += QString("Restore height: %1\n").arg(ui->label_restoreHeight->text());
Utils::copyToClipboard(text); text += QString("Wallet name: %1\n").arg(m_wallet->walletName());
return text;
}
void ViewOnlyDialog::copyToClipboard() {
Utils::copyToClipboard(this->toString());
} }
ViewOnlyDialog::~ViewOnlyDialog() = default; ViewOnlyDialog::~ViewOnlyDialog() = default;

View file

@ -25,6 +25,7 @@ private slots:
void onWriteViewOnlyWallet(); void onWriteViewOnlyWallet();
private: private:
QString toString();
void copyToClipboard(); void copyToClipboard();
QScopedPointer<Ui::ViewOnlyDialog> ui; QScopedPointer<Ui::ViewOnlyDialog> ui;

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>659</width> <width>659</width>
<height>254</height> <height>260</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,13 +15,13 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox_6"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>Restore height</string> <string>Secret view key</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QLabel" name="label_restoreHeight"> <widget class="QLabel" name="label_secretViewKey">
<property name="text"> <property name="text">
<string>TextLabel</string> <string>TextLabel</string>
</property> </property>
@ -53,13 +53,13 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_6">
<property name="title"> <property name="title">
<string>Secret view key</string> <string>Restore height</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
<widget class="QLabel" name="label_secretViewKey"> <widget class="QLabel" name="label_restoreHeight">
<property name="text"> <property name="text">
<string>TextLabel</string> <string>TextLabel</string>
</property> </property>
@ -87,6 +87,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="btn_transmitOverUR">
<property name="text">
<string>Transmit over UR</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">

View file

@ -233,6 +233,14 @@ std::string QrCodeScanWidget::getURData() {
return data; return data;
} }
std::string QrCodeScanWidget::getURType() {
if (!m_decoder.is_success()) {
return "";
}
return m_decoder.expected_type().value_or("");
}
QString QrCodeScanWidget::getURError() { QString QrCodeScanWidget::getURError() {
if (!m_decoder.is_failure()) { if (!m_decoder.is_failure()) {
return {}; return {};

View file

@ -29,6 +29,7 @@ public:
QString decodedString = ""; QString decodedString = "";
std::string getURData(); std::string getURData();
std::string getURType();
QString getURError(); QString getURError();
void startCapture(bool scan_ur = false); void startCapture(bool scan_ur = false);

View file

@ -50,6 +50,12 @@ void PageSetRestoreHeight::initializePage() {
ui->line_creationDate->setText(creationDate.toString("yyyy-MM-dd")); ui->line_creationDate->setText(creationDate.toString("yyyy-MM-dd"));
this->onCreationDateEdited(); this->onCreationDateEdited();
} }
if (m_fields->restoreHeight > 0) {
ui->line_restoreHeight->setText(QString::number(m_fields->restoreHeight));
this->onRestoreHeightEdited();
this->completeChanged();
}
} }
void PageSetRestoreHeight::onCreationDateEdited() { void PageSetRestoreHeight::onCreationDateEdited() {

View file

@ -42,6 +42,10 @@ void PageWalletFile::initializePage() {
ui->line_walletName->setText(this->defaultWalletName()); ui->line_walletName->setText(this->defaultWalletName());
ui->check_defaultWalletDirectory->setVisible(false); ui->check_defaultWalletDirectory->setVisible(false);
ui->check_defaultWalletDirectory->setChecked(false); ui->check_defaultWalletDirectory->setChecked(false);
if (!m_fields->walletName.isEmpty()) {
ui->line_walletName->setText(m_fields->walletName);
}
} }
bool PageWalletFile::validateWidgets(){ bool PageWalletFile::validateWidgets(){

View file

@ -11,6 +11,7 @@
#include "WalletWizard.h" #include "WalletWizard.h"
#include "constants.h" #include "constants.h"
#include "dialog/URDialog.h"
#include "libwalletqt/WalletManager.h" #include "libwalletqt/WalletManager.h"
PageWalletRestoreKeys::PageWalletRestoreKeys(WizardFields *fields, QWidget *parent) PageWalletRestoreKeys::PageWalletRestoreKeys(WizardFields *fields, QWidget *parent)
@ -41,6 +42,17 @@ PageWalletRestoreKeys::PageWalletRestoreKeys(WizardFields *fields, QWidget *pare
connect(ui->btnOptions, &QPushButton::clicked, this, &PageWalletRestoreKeys::onOptionsClicked); connect(ui->btnOptions, &QPushButton::clicked, this, &PageWalletRestoreKeys::onOptionsClicked);
connect(ui->combo_walletType, &QComboBox::currentTextChanged, this, &PageWalletRestoreKeys::showInputLines); connect(ui->combo_walletType, &QComboBox::currentTextChanged, this, &PageWalletRestoreKeys::showInputLines);
connect(ui->btn_scanUR, &QPushButton::clicked, [this] {
URDialog dialog{this, "", true};
dialog.exec();
ViewOnlyDetails details = dialog.getViewOnlyDetails();
ui->line_address->setText(details.address);
ui->line_address->setCursorPosition(0);
ui->line_viewkey->setText(details.key);
ui->line_viewkey->setCursorPosition(0);
m_fields->restoreHeight = details.restoreHeight;
m_fields->walletName = details.walletName;
});
} }
void PageWalletRestoreKeys::initializePage() { void PageWalletRestoreKeys::initializePage() {

View file

@ -215,6 +215,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="btn_scanUR">
<property name="text">
<string>Scan UR</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">