commit bee2a278b5f06609408d9dfcb736f8b116e2dc74
parent b4fa0f3f17f499cc66de0f175aa07cdd944c5f91
Author: lash <dev@holbrook.no>
Date: Mon, 19 Sep 2022 21:00:05 +0000
WIP feedback on wrong passphrase
Diffstat:
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/index.html b/index.html
@@ -56,15 +56,17 @@ let g_counter = undefined;
}
async function unlockLocalKey(pwd) {
- try {
- stateChange('check existing key');
- g_local_key = await getKey(pwd);
- } catch(e) {
- return false;
- }
- const decrypted = g_local_key.isDecrypted()
- stateChange('found key ' + g_local_key.getKeyID().toHex() + ' (decrypted: ' + decrypted + ')');
- return decrypted;
+ return new Promise(async (whohoo, doh) => {
+ try {
+ stateChange('check existing key');
+ g_local_key = await getKey(pwd);
+ } catch(e) {
+ doh(e);
+ }
+ const decrypted = g_local_key.isDecrypted()
+ stateChange('found key ' + g_local_key.getKeyID().toHex() + ' (decrypted: ' + decrypted + ')');
+ whohoo(decrypted);
+ });
}
async function applyLocalKey() {
@@ -274,7 +276,9 @@ let g_counter = undefined;
} else if (g_local_key === undefined) {
await createLocalKey(pwd);
}
- const r = await unlockLocalKey(pwd);
+ let r = false;
+ console.log('rrr', r);
+ r = await unlockLocalKey(pwd);
if (r) {
applyLocalKey();
}
@@ -324,7 +328,7 @@ let g_counter = undefined;
x-show='!have_passphrase'>
<input name="pwd" type="password" x-model='passphrase_cache' x-bind:placeholder='passphrase_status' />
- <button @click='have_passphrase = true; await setPwd(passphrase_cache);' >go</button>
+ <button @click='have_passphrase = await setPwd(passphrase_cache); if (!have_passphrase) { passphrase_status = "wrong passphrase"; passphrase_cache = ""; };' >go</button>
<button x-show='!key' @click='have_passphrase = true; await setPwd();' >without passphrase</button>
</div>
<div x-show='have_passphrase' x-init="await setUp();" x-data="{
diff --git a/key.js b/key.js
@@ -44,13 +44,17 @@ async function getKey(pwd) {
console.debug('our public key', pk.toPublic().armor());
if (pwd !== undefined) {
- pk = await openpgp.decryptKey({
+ openpgp.decryptKey({
privateKey: pk,
passphrase: pwd,
+ }).then((pk) => {
+ whohoo(pk);
+ }).catch((e) => {
+ doh(e);
});
+ } else {
+ whohoo(pk);
}
-
- whohoo(pk);
});
}