| 84 | } |
| 85 | |
| 86 | void AskPassphraseDialog::accept() |
| 87 | { |
| 88 | SecureString oldpass, newpass1, newpass2; |
| 89 | if (!model && mode != Encrypt) |
| 90 | return; |
| 91 | oldpass.reserve(MAX_PASSPHRASE_SIZE); |
| 92 | newpass1.reserve(MAX_PASSPHRASE_SIZE); |
| 93 | newpass2.reserve(MAX_PASSPHRASE_SIZE); |
| 94 | // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string) |
| 95 | // Alternately, find a way to make this input mlock()'d to begin with. |
| 96 | oldpass.assign(ui->passEdit1->text().toStdString().c_str()); |
| 97 | newpass1.assign(ui->passEdit2->text().toStdString().c_str()); |
| 98 | newpass2.assign(ui->passEdit3->text().toStdString().c_str()); |
| 99 | |
| 100 | secureClearPassFields(); |
| 101 | |
| 102 | switch(mode) |
| 103 | { |
| 104 | case Encrypt: { |
| 105 | if(newpass1.empty() || newpass2.empty()) |
| 106 | { |
| 107 | // Cannot encrypt with empty passphrase |
| 108 | break; |
| 109 | } |
| 110 | QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm wallet encryption"), |
| 111 | tr("Warning: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!") + "<br><br>" + tr("Are you sure you wish to encrypt your wallet?"), |
| 112 | QMessageBox::Yes|QMessageBox::Cancel, |
| 113 | QMessageBox::Cancel); |
| 114 | if(retval == QMessageBox::Yes) |
| 115 | { |
| 116 | if(newpass1 == newpass2) |
| 117 | { |
| 118 | QString encryption_reminder = tr("Remember that encrypting your wallet cannot fully protect " |
| 119 | "your bitcoins from being stolen by malware infecting your computer."); |
| 120 | if (m_passphrase_out) { |
| 121 | m_passphrase_out->assign(newpass1); |
| 122 | QMessageBox::warning(this, tr("Wallet to be encrypted"), |
| 123 | "<qt>" + |
| 124 | tr("Your wallet is about to be encrypted. ") + encryption_reminder + |
| 125 | "</b></qt>"); |
| 126 | } else { |
| 127 | assert(model != nullptr); |
| 128 | if (model->setWalletEncrypted(newpass1)) { |
| 129 | QMessageBox::warning(this, tr("Wallet encrypted"), |
| 130 | "<qt>" + |
| 131 | tr("Your wallet is now encrypted. ") + encryption_reminder + |
| 132 | "<br><br><b>" + |
| 133 | tr("IMPORTANT: Any previous backups you have made of your wallet file " |
| 134 | "should be replaced with the newly generated, encrypted wallet file. " |
| 135 | "For security reasons, previous backups of the unencrypted wallet file " |
| 136 | "will become useless as soon as you start using the new, encrypted wallet.") + |
| 137 | "</b></qt>"); |
| 138 | } else { |
| 139 | QMessageBox::critical(this, tr("Wallet encryption failed"), |
| 140 | tr("Wallet encryption failed due to an internal error. Your wallet was not encrypted.")); |
| 141 | } |
| 142 | } |
| 143 | QDialog::accept(); // Success |
nothing calls this directly
no test coverage detected