Trezor: add passphrase support

This commit is contained in:
tobtoht 2021-07-08 02:34:27 +02:00
parent a01a66a85e
commit 2bba5c4787
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
5 changed files with 61 additions and 18 deletions

View file

@ -377,6 +377,7 @@ void MainWindow::initWalletContext() {
// Wallet
connect(m_ctx->wallet, &Wallet::connectionStatusChanged, this, &MainWindow::onConnectionStatusChanged);
connect(m_ctx->wallet, &Wallet::currentSubaddressAccountChanged, this, &MainWindow::updateTitle);
connect(m_ctx->wallet, &Wallet::walletPassphraseNeeded, this, &MainWindow::onWalletPassphraseNeeded);
}
void MainWindow::menuToggleTabVisible(const QString &key){
@ -1190,6 +1191,25 @@ void MainWindow::onDeviceButtonPressed() {
m_splashDialog->hide();
}
void MainWindow::onWalletPassphraseNeeded(bool on_device) {
auto button = QMessageBox::question(nullptr, "Wallet Passphrase Needed", "Enter passphrase on hardware wallet?\n\n"
"It is recommended to enter passphrase on "
"the hardware wallet for better security.",
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (button == QMessageBox::Yes) {
m_ctx->wallet->onPassphraseEntered("", true, false);
return;
}
bool ok;
QString passphrase = QInputDialog::getText(nullptr, "Wallet Passphrase Needed", "Enter passphrase:", QLineEdit::EchoMode::Password, "", &ok);
if (ok) {
m_ctx->wallet->onPassphraseEntered(passphrase, false, false);
} else {
m_ctx->wallet->onPassphraseEntered(passphrase, false, true);
}
}
void MainWindow::updateNetStats() {
if (!m_ctx->wallet || m_ctx->wallet->connectionStatus() == Wallet::ConnectionStatus_Disconnected
|| m_ctx->wallet->connectionStatus() == Wallet::ConnectionStatus_Synchronized)

View file

@ -174,6 +174,7 @@ private slots:
void onDeviceError(const QString &error);
void onDeviceButtonRequest(quint64 code);
void onDeviceButtonPressed();
void onWalletPassphraseNeeded(bool on_device);
void menuHwDeviceClicked();
void onUpdatesAvailable(const QJsonObject &updates);
void toggleSearchbar(bool enabled);

View file

@ -3,6 +3,7 @@
#include "WindowManager.h"
#include <QInputDialog>
#include <QMessageBox>
#include "constants.h"
@ -24,6 +25,7 @@ WindowManager::WindowManager() {
connect(m_walletManager, &WalletManager::deviceButtonRequest, this, &WindowManager::onDeviceButtonRequest);
connect(m_walletManager, &WalletManager::deviceButtonPressed, this, &WindowManager::onDeviceButtonPressed);
connect(m_walletManager, &WalletManager::deviceError, this, &WindowManager::onDeviceError);
connect(m_walletManager, &WalletManager::walletPassphraseNeeded, this, &WindowManager::onWalletPassphraseNeeded);
connect(qApp, &QGuiApplication::lastWindowClosed, this, &WindowManager::quitAfterLastWindow);
@ -393,6 +395,25 @@ void WindowManager::onDeviceError(const QString &errorMessage) {
qCritical() << Q_FUNC_INFO << errorMessage;
}
void WindowManager::onWalletPassphraseNeeded(bool on_device) {
auto button = QMessageBox::question(nullptr, "Wallet Passphrase Needed", "Enter passphrase on hardware wallet?\n\n"
"It is recommended to enter passphrase on "
"the hardware wallet for better security.",
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (button == QMessageBox::Yes) {
m_walletManager->onPassphraseEntered("", true, false);
return;
}
bool ok;
QString passphrase = QInputDialog::getText(nullptr, "Wallet Passphrase Needed", "Enter passphrase:", QLineEdit::EchoMode::Password, "", &ok);
if (ok) {
m_walletManager->onPassphraseEntered(passphrase, false, false);
} else {
m_walletManager->onPassphraseEntered(passphrase, false, true);
}
}
// ######################## TRAY ########################
void WindowManager::buildTrayMenu() {

View file

@ -41,6 +41,7 @@ private slots:
void onDeviceButtonRequest(quint64 code);
void onDeviceButtonPressed();
void onDeviceError(const QString &errorMessage);
void onWalletPassphraseNeeded(bool on_device);
private:
void tryCreateWallet(FeatherSeed seed, const QString &path, const QString &password, const QString &seedOffset);

View file

@ -9,40 +9,40 @@
class WalletPassphraseListenerImpl : public Monero::WalletListener, public PassphraseReceiver
{
public:
WalletPassphraseListenerImpl(WalletManager * mgr): m_mgr(mgr), m_phelper(mgr) {}
explicit WalletPassphraseListenerImpl(WalletManager * mgr): m_mgr(mgr), m_phelper(mgr) {}
virtual void moneySpent(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
virtual void moneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
virtual void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
virtual void newBlock(uint64_t height) override { (void) height; };
virtual void updated() override {};
virtual void refreshed(bool success) override {};
void moneySpent(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
void moneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
void newBlock(uint64_t height) override { (void) height; };
void updated() override {};
void refreshed(bool success) override {};
virtual void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort) override
void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort) override
{
qDebug() << __FUNCTION__;
m_phelper.onPassphraseEntered(passphrase, enter_on_device, entry_abort);
}
// virtual Monero::optional<std::string> onDevicePassphraseRequest(bool & on_device) override
// {
// qDebug() << __FUNCTION__;
// return m_phelper.onDevicePassphraseRequest(on_device);
// }
//
virtual void onDeviceButtonRequest(uint64_t code) override
Monero::optional<std::string> onDevicePassphraseRequest(bool & on_device) override
{
qDebug() << __FUNCTION__;
return m_phelper.onDevicePassphraseRequest(on_device);
}
void onDeviceButtonRequest(uint64_t code) override
{
qDebug() << __FUNCTION__;
emit m_mgr->deviceButtonRequest(code);
}
//
virtual void onDeviceButtonPressed() override
void onDeviceButtonPressed() override
{
qDebug() << __FUNCTION__;
emit m_mgr->deviceButtonPressed();
}
virtual void onDeviceError(const std::string &message) override
void onDeviceError(const std::string &message) override
{
qDebug() << __FUNCTION__;
emit m_mgr->deviceError(QString::fromStdString(message));