Skip to content
Merged
2 changes: 1 addition & 1 deletion extension/chrome/settings/modules/add_key.htm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h1>Add Private Key <span id="spinner_container"></span></h1>
</div>
<div class="line">
<br />
<button class="button long green action_add_private_key">Add Private Key</button>
<button class="button long green action_add_private_key" data-test="action-add-private-key-btn">Add Private Key</button>
</div>
</div>
</div>
Expand Down
14 changes: 13 additions & 1 deletion extension/js/common/ui/key-import-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,19 @@ export class KeyImportUi {
const keyinfos = await KeyStore.get(acctEmail);
const privateKeysIds = keyinfos.map(ki => ki.fingerprints[0]);
if (privateKeysIds.includes(k.id)) {
throw new UserAlert('This is one of your current keys, try another one.');
const key = keyinfos.find(ki => ki.id === k.id);
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const existingKey = await KeyUtil.parse(key!.public);
const hasNewerExpiration = !!(k.expiration && existingKey.expiration && k.expiration > existingKey.expiration);
if (hasNewerExpiration) {
const updateKeyMessage =
"The key you're trying to import is a newer version of one you already have, based on its expiry date.\n" +
'Follow the <a href="https://flowcrypt.com/docs/getting-started/common-tasks/update-private-key.html">guide</a> \n' +
'to update it or contact your FlowCrypt admin.';
await Ui.modal.info(updateKeyMessage, true);
} else {
throw new UserAlert('This is one of your current keys, try another one.');
}
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions extension/js/common/ui/passphrase-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const initPassphraseToggle = async (passphraseInputIds: string[], forceIn
for (const id of passphraseInputIds) {
const passphraseInput = $(`#${id}`);
passphraseInput.addClass('toggled_passphrase');
if (!passphraseInput.attr('data-test')) {
passphraseInput.attr('data-test', 'input-passphrase');
}
if (show) {
passphraseInput.after(`<label href="#" id="toggle_${id}" class="toggle_show_hide_pass_phrase" for="${id}">${buttonHide}</label>`); // xss-direct
passphraseInput.attr('type', 'text');
Expand Down
29 changes: 29 additions & 0 deletions test/source/tests/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,35 @@ export const defineSettingsTests = (testVariant: TestVariant, testWithBrowser: T
expect(pubkeyExpiration).to.equal(expectedExpiration);
})
);
test(
'settings - inform user when importing newer key version',
testWithBrowser(async (t, browser) => {
t.context.mockApi!.configProvider = new ConfigurationProvider({
attester: {
pubkeyLookup: {},
},
});
const acct = '[email protected]';
const settingsPage = await BrowserRecipe.openSettingsLoginApprove(t, browser, acct);
const key50yearExpiry = testConstants.keyWith50yearsExpiry;
await SetupPageRecipe.manualEnter(settingsPage, '', {
key: {
title: '?',
armored: key50yearExpiry,
passphrase: 'passphrase',
longid: '6B673BAB02EC3E43',
},
});
await SettingsPageRecipe.toggleScreen(settingsPage, 'additional');
const addKeyPopup = await SettingsPageRecipe.awaitNewPageFrame(settingsPage, '@action-open-add-key-page', ['add_key.htm']);
await addKeyPopup.waitAndClick('@source-paste');
await addKeyPopup.waitAndType('@input-armored-key', testConstants.keyWith80yearsExpiry);
await addKeyPopup.waitAndType('@input-passphrase', 'passphrase');
await addKeyPopup.waitAndClick('@action-add-private-key-btn');
const expectedInfoMsg = "The key you're trying to import is a newer version of one you already have, based on its expiry date";
await addKeyPopup.waitAndRespondToModal('info', 'confirm', expectedInfoMsg);
})
);
test(
'settings - attachment previews are rendered according to their types',
testWithBrowser(async (t, browser) => {
Expand Down
36 changes: 36 additions & 0 deletions test/source/tests/tooling/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,42 @@ UR98qQ186mnyAcpbCVs7suK/0v+OIDHbF4gxMpRZmljstuT7mK4o6obfYwbOAq0Z
LE0zUUI5Yvk=
=XL9F
-----END PGP PUBLIC KEY BLOCK-----`,
keyWith50yearsExpiry: `-----BEGIN PGP PRIVATE KEY BLOCK-----
Comment: passphrase is passphrase

lIYEZ9etehYJKwYBBAHaRw8BAQdAS3w39Z7POxljA2Pw82iHSxdw/LXR+FzOpNMA
v6Pzjuf+BwMCn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S6AopPWvdA
XlKLtolrZzurAuw+QwUCZ9etegIbAwUJlmAYAAULCQgHAgIiAgYVCgkICwIEFgID
AQIeBwIXgAAKCRBrZzurAuw+Q61pAP9UJMO8zjug77uEtepzSTEe42DXD6DPiGzT
2zGfIsuZ3QEA2MfWfxxSylNOcenjDiyJdZXbQ9XBIOd6gnSYpPFi0g+ciwRn1616
EgorBgEEAZdVAQUBAQdA9TVaPoFGzRGv3zmNNEDQDGONRo7Up3baDpux3rgvmnMD
AQgH/gcDAuFWQ5cWpFMO/wxxJn+r1CbUruerHu0m/lNAI9zq5PQ++i5vfrufR34r
ENWg+7hKHItP0eN4dC+63pfKOHw9ugcCQNPOtudaLTC1s9gMu9iIfgQYFgoAJhYh
BLoCik9a90BeUou2iWtnO6sC7D5DBQJn1616AhsMBQmWYBgAAAoJEGtnO6sC7D5D
OkYA/1W6mbl/dAqt1j3kwFptypOiK48yLcXjIYpptpqi6Jy+AQCofaj8LPWXUZmK
dm7daVbBUy6YHWaePL/Si2pfPR1WDg==
=Tujf
-----END PGP PRIVATE KEY BLOCK-----`,
};

export const testKeyConstants = {
Expand Down