Skip to content

Commit

Permalink
Improve Mnemonic + Password handling security (#150)
Browse files Browse the repository at this point in the history
* Improve Mnemonic + Password handling security

* Improve GUI import too
  • Loading branch information
JSKitty committed Jul 10, 2023
1 parent 4c89ecd commit 4b5d2d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 14 additions & 7 deletions scripts/global.js
Expand Up @@ -1423,8 +1423,10 @@ export async function onPrivateKeyChanged() {
* Imports a wallet using the GUI input, handling decryption via UI
*/
export async function guiImportWallet() {
const fEncrypted =
doms.domPrivKey.value.length >= 128 && isBase64(doms.domPrivKey.value);
// Important: These fields will be wiped by importWallet();
const strPrivKey = doms.domPrivKey.value;
const strPassword = doms.domPrivKeyPassword.value;
const fEncrypted = strPrivKey.length >= 128 && isBase64(strPrivKey);

// If we are in testnet: prompt an import
if (cChainParams.current.isTestnet) return importWallet();
Expand All @@ -1433,8 +1435,6 @@ export async function guiImportWallet() {
if (!(await hasEncryptedWallet()) && !fEncrypted) return importWallet();

// If we don't have a DB wallet and the input is ciphered:
const strPrivKey = doms.domPrivKey.value;
const strPassword = doms.domPrivKeyPassword.value;
if (!(await hasEncryptedWallet()) && fEncrypted) {
const strDecWIF = await decrypt(strPrivKey, strPassword);
if (!strDecWIF || strDecWIF === 'decryption failed!') {
Expand All @@ -1452,6 +1452,9 @@ export async function guiImportWallet() {
encWif: strPrivKey,
});
}
// Destroy residue import data
doms.domPrivKey.value = '';
doms.domPrivKeyPassword.value = '';
return;
}
}
Expand Down Expand Up @@ -1488,6 +1491,8 @@ export function guiEncryptWallet() {
createAlert('success', ALERTS.NEW_PASSWORD_SUCCESS, [], 5500);

$('#encryptWalletModal').modal('hide');
doms.domEncryptPasswordFirst.value = '';
doms.domEncryptPasswordSecond.value = '';

doms.domWipeWallet.hidden = false;
}
Expand Down Expand Up @@ -1772,10 +1777,12 @@ export async function restoreWallet(strReason = '') {
html: `${strHTML}<input type="password" id="restoreWalletPassword" placeholder="Wallet password" style="text-align: center;">`,
})
) {
// Fetch the password from the prompt, and immediately destroy the prompt input
const domPassword = document.getElementById('restoreWalletPassword');
const strPassword = domPassword.value;
domPassword.value = '';

// Attempt to unlock the wallet with the provided password
const strPassword = document.getElementById(
'restoreWalletPassword'
).value;
if (await decryptWallet(strPassword)) {
doms.domRestoreWallet.hidden = true;
doms.domWipeWallet.hidden = false;
Expand Down
4 changes: 4 additions & 0 deletions scripts/wallet.js
Expand Up @@ -841,6 +841,10 @@ function informUserOfMnemonic(mnemonic) {
doms.domMnemonicModalButton.onclick = () => {
res(doms.domMnemonicModalPassphrase.value);
$('#mnemonicModal').modal('hide');

// Wipe the mnemonic displays of sensitive data
doms.domMnemonicModalContent.innerText = '';
doms.domMnemonicModalPassphrase.value = '';
};
$('#mnemonicModal').modal('show');
});
Expand Down

0 comments on commit 4b5d2d2

Please sign in to comment.