Skip to content

Commit

Permalink
Remove remembered passphrase after 15 minutes of inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Mar 18, 2024
1 parent 9bc56a5 commit 190db75
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion dev/Storage/Passphrases.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,16 @@ export const Passphrases = new WeakMap();

Passphrases.ask = async (key, sAskDesc, btnText) =>
Passphrases.has(key)
? {password:Passphrases.get(key)/*, remember:false*/}
? {password:Passphrases.handle(key)/*, remember:false*/}
: await AskPopupView.password(sAskDesc, btnText);

const timeouts = {};
// get/set accessor to control deletion after 15 minutes of inactivity
Passphrases.handle = (key, pass) => {
if (!timeouts[key]) {
timeouts[key] = (()=>Passphrases.delete(key)).debounce(900000);
}
pass && Passphrases.set(key, pass);
timeouts[key]();
return Passphrases.get(key);
};
2 changes: 1 addition & 1 deletion dev/Stores/User/GnuPG.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const GnuPGUserStore = new class {
'GnuPG key<br>' + key.id + ' ' + key.emails[0],
btnTxt
);
pass && pass.remember && Passphrases.set(key, pass.password);
pass && pass.remember && Passphrases.handle(key, pass.password);
return pass?.password;
};
}
Expand Down
2 changes: 1 addition & 1 deletion dev/Stores/User/OpenPGP.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const
privateKey: privateKey.key,
passphrase
});
result && pass.remember && Passphrases.set(privateKey, passphrase);
result && pass.remember && Passphrases.handle(privateKey, passphrase);
return result;
}
},
Expand Down
2 changes: 1 addition & 1 deletion dev/View/Popup/Compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ export class ComposePopupView extends AbstractViewPopup {
);
if (null != pass) {
params.signPassphrase = pass.password;
// pass.remember && Passphrases.set(identity, pass.password);
// pass.remember && Passphrases.handle(identity, pass.password);
} else {
sign = false;
}
Expand Down
2 changes: 1 addition & 1 deletion dev/View/User/MailBox/MessageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ export class MailMessageView extends AbstractViewRight {
message.smimeDecrypted(true);
MimeToMessage(response.Result.data, message);
message.html() ? message.viewHtml() : message.viewPlain();
pass && pass.remember && Passphrases.set(identity, pass.password);
pass && pass.remember && Passphrases.handle(identity, pass.password);
if ('signed' in response.Result) {
message.smimeSigned(response.Result.signed);
}
Expand Down

0 comments on commit 190db75

Please sign in to comment.