From 28c1973405a9ff35fe176c735c95250cf7cd8630 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Sat, 12 Mar 2022 13:53:46 +0100 Subject: [PATCH] Show warning on corrupted keys --- src/MainWindow.cpp | 9 +++++++++ src/MainWindow.h | 2 ++ src/SendWidget.cpp | 9 ++++++++- src/SendWidget.h | 7 +++++-- src/appcontext.cpp | 10 ++++++++-- src/appcontext.h | 1 + src/libwalletqt/Subaddress.cpp | 5 +++-- src/libwalletqt/Subaddress.h | 2 +- 8 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 11ca5e1..82c9ea4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -377,6 +377,7 @@ void MainWindow::initWalletContext() { connect(m_ctx.get(), &AppContext::initiateTransaction, this, &MainWindow::onInitiateTransaction); connect(m_ctx.get(), &AppContext::endTransaction, this, &MainWindow::onEndTransaction); connect(m_ctx.get(), &AppContext::customRestoreHeightSet, this, &MainWindow::onCustomRestoreHeightSet); + connect(m_ctx.get(), &AppContext::keysCorrupted, this, &MainWindow::onKeysCorrupted); // Nodes connect(m_ctx->nodes, &Nodes::updateStatus, this, &MainWindow::onSetStatusText); @@ -1439,6 +1440,14 @@ void MainWindow::onCustomRestoreHeightSet(int height) { this->menuQuitClicked(); } +void MainWindow::onKeysCorrupted() { + if (!m_criticalWarningShown) { + m_criticalWarningShown = true; + QMessageBox::warning(this, "Critical error", "WARNING!\n\nThe wallet keys are corrupted.\n\nTo prevent LOSS OF FUNDS do NOT continue to use this wallet file.\n\nRestore your wallet from seed.\n\nPlease report this incident to the Feather developers.\n\nWARNING!"); + m_sendWidget->disableSendButton(); + } +} + void MainWindow::onExportHistoryCSV(bool checked) { if (m_ctx->wallet == nullptr) return; diff --git a/src/MainWindow.h b/src/MainWindow.h index 03271aa..97612b8 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -139,6 +139,7 @@ private slots: void onInitiateTransaction(); void onEndTransaction(); void onCustomRestoreHeightSet(int height); + void onKeysCorrupted(); // libwalletqt void onBalanceUpdated(quint64 balance, quint64 spendable); @@ -274,6 +275,7 @@ private: QTimer m_txTimer; bool cleanedUp = false; + bool m_criticalWarningShown = false; EventFilter *m_eventFilter = nullptr; qint64 m_userLastActive = QDateTime::currentSecsSinceEpoch(); diff --git a/src/SendWidget.cpp b/src/SendWidget.cpp index 920ec8a..20f09db 100644 --- a/src/SendWidget.cpp +++ b/src/SendWidget.cpp @@ -305,7 +305,14 @@ void SendWidget::onInitiateTransaction() { } void SendWidget::onEndTransaction() { - ui->btnSend->setEnabled(true); + if (!m_sendDisabled) { + ui->btnSend->setEnabled(true); + } +} + +void SendWidget::disableSendButton() { + m_sendDisabled = true; + ui->btnSend->setEnabled(false); } void SendWidget::onDataPasted(const QString &data) { diff --git a/src/SendWidget.h b/src/SendWidget.h index f961f53..bc9bc73 100644 --- a/src/SendWidget.h +++ b/src/SendWidget.h @@ -40,6 +40,7 @@ public slots: void onOpenAliasResolveError(const QString &err); void onOpenAliasResolved(const QString &openAlias, const QString &address, bool dnssecValid); void onPreferredFiatCurrencyChanged(); + void disableSendButton(); void onInitiateTransaction(); void onEndTransaction(); @@ -51,10 +52,12 @@ private: void setupComboBox(); double amountDouble(); - QScopedPointer ui; - QSharedPointer m_ctx; quint64 amount(); double conversionAmount(); + + QScopedPointer ui; + QSharedPointer m_ctx; + bool m_sendDisabled = false; }; #endif // FEATHER_SENDWIDGET_H diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 06db594..15420b0 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -345,7 +345,13 @@ void AppContext::syncStatusUpdated(quint64 height, quint64 target) { void AppContext::refreshModels() { this->wallet->history()->refresh(this->wallet->currentSubaddressAccount()); - this->wallet->subaddress()->refresh(this->wallet->currentSubaddressAccount()); this->wallet->coins()->refresh(this->wallet->currentSubaddressAccount()); - // Todo: set timer for refreshes + bool r = this->wallet->subaddress()->refresh(this->wallet->currentSubaddressAccount()); + + if (!r) { + // This should only happen if wallet keys got corrupted or were tampered with + // The list of subaddresses is wiped to prevent loss of funds + // Notify MainWindow to display an error message + emit keysCorrupted(); + } } diff --git a/src/appcontext.h b/src/appcontext.h index 9fb7a10..dd6fcde 100644 --- a/src/appcontext.h +++ b/src/appcontext.h @@ -92,6 +92,7 @@ signals: void deviceButtonRequest(quint64 code); void deviceButtonPressed(); void deviceError(const QString &message); + void keysCorrupted(); private: DaemonRpc *m_rpc; diff --git a/src/libwalletqt/Subaddress.cpp b/src/libwalletqt/Subaddress.cpp index c39aa27..4b635b0 100644 --- a/src/libwalletqt/Subaddress.cpp +++ b/src/libwalletqt/Subaddress.cpp @@ -73,10 +73,11 @@ bool Subaddress::setLabel(quint32 accountIndex, quint32 addressIndex, const QStr return r; } -void Subaddress::refresh(quint32 accountIndex) const +bool Subaddress::refresh(quint32 accountIndex) const { - m_subaddressImpl->refresh(accountIndex); + bool r = m_subaddressImpl->refresh(accountIndex); getAll(); + return r; } quint64 Subaddress::unusedLookahead() const diff --git a/src/libwalletqt/Subaddress.h b/src/libwalletqt/Subaddress.h index 543fb79..a27e435 100644 --- a/src/libwalletqt/Subaddress.h +++ b/src/libwalletqt/Subaddress.h @@ -20,7 +20,7 @@ public: bool getRow(int index, std::function callback) const; bool addRow(quint32 accountIndex, const QString &label) const; bool setLabel(quint32 accountIndex, quint32 addressIndex, const QString &label) const; - void refresh(quint32 accountIndex) const; + bool refresh(quint32 accountIndex) const; quint64 unusedLookahead() const; quint64 count() const; QString errorString() const;