wallet_api: do not cache wallet password

This commit is contained in:
tobtoht 2023-01-31 17:00:50 +01:00
parent 96928f1a74
commit 1571d59409
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
5 changed files with 20 additions and 19 deletions

2
monero

@ -1 +1 @@
Subproject commit 18bdad879d9f25f35f065354aedf1236e6b0a60b Subproject commit 57e241748fb8caec0033f84cb14ef7861132c4e6

View file

@ -798,7 +798,8 @@ void MainWindow::showPasswordDialog() {
} }
void MainWindow::updatePasswordIcon() { void MainWindow::updatePasswordIcon() {
QIcon icon = m_ctx->wallet->getPassword().isEmpty() ? icons()->icon("unlock.svg") : icons()->icon("lock.svg"); bool emptyPassword = m_ctx->wallet->verifyPassword("");
QIcon icon = emptyPassword ? icons()->icon("unlock.svg") : icons()->icon("lock.svg");
m_statusBtnPassword->setIcon(icon); m_statusBtnPassword->setIcon(icon);
} }
@ -1650,7 +1651,8 @@ bool MainWindow::verifyPassword(bool sensitive) {
if (ret == QDialog::Rejected) { if (ret == QDialog::Rejected) {
return false; return false;
} }
if (passwordDialog.password != m_ctx->wallet->getPassword()) {
if (!m_ctx->wallet->verifyPassword(passwordDialog.password)) {
incorrectPassword = true; incorrectPassword = true;
continue; continue;
} }
@ -1725,7 +1727,7 @@ void MainWindow::unlockWallet(const QString &password) {
return; return;
} }
if (password != m_ctx->wallet->getPassword()) { if (!m_ctx->wallet->verifyPassword(password)) {
m_walletUnlockWidget->incorrectPassword(); m_walletUnlockWidget->incorrectPassword();
return; return;
} }

View file

@ -13,8 +13,7 @@ PasswordChangeDialog::PasswordChangeDialog(QWidget *parent, Wallet *wallet)
{ {
ui->setupUi(this); ui->setupUi(this);
bool noPassword = wallet->getPassword().isEmpty(); bool noPassword = wallet->verifyPassword("");
QString warning_str = noPassword ? "Your wallet is not password protected. Use this dialog to add a password to your wallet." : QString warning_str = noPassword ? "Your wallet is not password protected. Use this dialog to add a password to your wallet." :
"Your wallet is password protected and encrypted. Use this dialog to change your password."; "Your wallet is password protected and encrypted. Use this dialog to change your password.";
ui->label_warning->setText(warning_str); ui->label_warning->setText(warning_str);
@ -50,14 +49,14 @@ void PasswordChangeDialog::setPassword() {
QString currentPassword = ui->lineEdit_currentPassword->text(); QString currentPassword = ui->lineEdit_currentPassword->text();
QString newPassword = ui->lineEdit_newPassword->text(); QString newPassword = ui->lineEdit_newPassword->text();
if (currentPassword != m_wallet->getPassword()) { if (!m_wallet->verifyPassword(currentPassword)) {
QMessageBox::warning(this, "Error", "Incorrect password"); QMessageBox::warning(this, "Error", "Incorrect password");
ui->lineEdit_currentPassword->setText(""); ui->lineEdit_currentPassword->setText("");
ui->lineEdit_currentPassword->setFocus(); ui->lineEdit_currentPassword->setFocus();
return; return;
} }
if (m_wallet->setPassword(newPassword)) { if (m_wallet->setPassword(currentPassword, newPassword)) {
QMessageBox::information(this, "Information", "Password changed successfully"); QMessageBox::information(this, "Information", "Password changed successfully");
this->accept(); this->accept();
} }

View file

@ -164,14 +164,14 @@ QString Wallet::errorString() const
return QString::fromStdString(m_walletImpl->errorString()); return QString::fromStdString(m_walletImpl->errorString());
} }
bool Wallet::setPassword(const QString &password) bool Wallet::setPassword(const QString &oldPassword, const QString &newPassword)
{ {
return m_walletImpl->setPassword(password.toStdString()); return m_walletImpl->setPassword(oldPassword.toStdString(), newPassword.toStdString());
} }
QString Wallet::getPassword() bool Wallet::verifyPassword(const QString &password)
{ {
return QString::fromStdString(m_walletImpl->getPassword()); return m_walletImpl->verifyPassword(password.toStdString());
} }
QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const
@ -198,9 +198,9 @@ QString Wallet::keysPath() const
return QDir::toNativeSeparators(QString::fromStdString(m_walletImpl->keysFilename()));; return QDir::toNativeSeparators(QString::fromStdString(m_walletImpl->keysFilename()));;
} }
void Wallet::store(const QString &path) void Wallet::store()
{ {
m_walletImpl->store(path.toStdString()); m_walletImpl->store();
} }
bool Wallet::init(const QString &daemonAddress, bool trustedDaemon, quint64 upperTransactionLimit, bool isRecovering, bool isRecoveringFromDevice, quint64 restoreHeight, const QString& proxyAddress) bool Wallet::init(const QString &daemonAddress, bool trustedDaemon, quint64 upperTransactionLimit, bool isRecovering, bool isRecoveringFromDevice, quint64 restoreHeight, const QString& proxyAddress)
@ -1416,7 +1416,7 @@ Wallet::~Wallet()
//Monero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl); //Monero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl);
if(status() == Status_Critical || status() == Status_BadPassword) if(status() == Status_Critical || status() == Status_BadPassword)
qDebug("Not storing wallet cache"); qDebug("Not storing wallet cache");
else if( m_walletImpl->store("")) else if( m_walletImpl->store())
qDebug("Wallet cache stored successfully"); qDebug("Wallet cache stored successfully");
else else
qDebug("Error storing wallet cache"); qDebug("Error storing wallet cache");

View file

@ -144,10 +144,10 @@ public:
QString errorString() const; QString errorString() const;
//! changes the password using existing parameters (path, seed, seed lang) //! changes the password using existing parameters (path, seed, seed lang)
bool setPassword(const QString &password); bool setPassword(const QString &oldPassword, const QString &newPassword);
//! get current wallet password //! verify wallet password
QString getPassword(); bool verifyPassword(const QString &password);
//! returns wallet's public address //! returns wallet's public address
QString address(quint32 accountIndex, quint32 addressIndex) const; QString address(quint32 accountIndex, quint32 addressIndex) const;
@ -163,7 +163,7 @@ public:
//! saves wallet to the file by given path //! saves wallet to the file by given path
//! empty path stores in current location //! empty path stores in current location
void store(const QString &path = ""); void store();
// void storeAsync(const QJSValue &callback, const QString &path = ""); // void storeAsync(const QJSValue &callback, const QString &path = "");
//! initializes wallet asynchronously //! initializes wallet asynchronously