- This OpenPGP key is not usable.
+ This OpenPGP key is not usable.
diff --git a/extension/chrome/elements/pgp_pubkey.ts b/extension/chrome/elements/pgp_pubkey.ts
index fd1f85a5596..53b5d829e57 100644
--- a/extension/chrome/elements/pgp_pubkey.ts
+++ b/extension/chrome/elements/pgp_pubkey.ts
@@ -13,6 +13,8 @@ import { Url } from '../../js/common/core/common.js';
import { View } from '../../js/common/view.js';
import { Xss } from '../../js/common/platform/xss.js';
import { ContactStore } from '../../js/common/platform/store/contact-store.js';
+import { Buf } from '../../js/common/core/buf.js';
+import { OpenPGPKey } from '../../js/common/core/crypto/pgp/openpgp-key.js';
// todo - this should use KeyImportUI for consistency.
View.run(
@@ -71,7 +73,7 @@ View.run(
!this.firstParsedPublicKey.usableForEncryption &&
!this.firstParsedPublicKey.usableForSigning
) {
- this.showKeyNotUsableError();
+ await this.showKeyNotUsableError();
} else {
let emailText = '';
if (this.parsedPublicKeys.length === 1) {
@@ -116,7 +118,7 @@ View.run(
frameId: this.frameId,
});
} else {
- this.showKeyNotUsableError();
+ await this.showKeyNotUsableError();
}
}
this.sendResizeMsg();
@@ -137,6 +139,25 @@ View.run(
);
};
+ private getErrorText = async () => {
+ let errorStr = '';
+ const { keys, errs } = await KeyUtil.readMany(Buf.fromUtfStr(this.armoredPubkey));
+ errorStr = errs.join('\n');
+ for (const key of keys) {
+ const errorMessage = await OpenPGPKey.checkPublicKeyError(key);
+ if (errorMessage) {
+ const match = new RegExp(/Error encrypting message: (.+)$/).exec(errorMessage);
+ // remove `error: error encrypting message: part`, so error message will begin directly from error reason
+ if (match) {
+ errorStr += match[1];
+ } else {
+ errorStr += errorMessage;
+ }
+ }
+ }
+ return errorStr;
+ };
+
private sendResizeMsg = () => {
const origHeight = $('#pgp_block').height();
if (!origHeight) {
@@ -167,8 +188,9 @@ View.run(
}
};
- private showKeyNotUsableError = () => {
+ private showKeyNotUsableError = async () => {
$('.error_container').removeClass('hidden');
+ $('.error_introduce_label').html(`This OpenPGP key is not usable.
(${await this.getErrorText()})`); // xss-escaped
$('.hide_if_error').hide();
$('.fingerprints, .add_contact, #manual_import_warning').remove();
const email = this.firstParsedPublicKey?.emails[0];
diff --git a/extension/css/cryptup.css b/extension/css/cryptup.css
index cea22762c56..18427ca6013 100644
--- a/extension/css/cryptup.css
+++ b/extension/css/cryptup.css
@@ -1446,6 +1446,10 @@ td {
align-items: flex-start;
}
+.pgp_neutral .error_container .error_info .error_introduce_label {
+ white-space: pre-line;
+}
+
.pgp_neutral .error_container .error_info span {
color: #a44;
font-size: 14px;
@@ -1625,6 +1629,10 @@ td {
display: none;
}
+#pgp_block.pgp_pubkey .action_show_full {
+ width: 118px;
+}
+
#pgp_block .three_dots {
text-align: center;
width: 25px;
diff --git a/extension/js/common/core/crypto/pgp/openpgp-key.ts b/extension/js/common/core/crypto/pgp/openpgp-key.ts
index 121369f7a57..fc762dd38de 100644
--- a/extension/js/common/core/crypto/pgp/openpgp-key.ts
+++ b/extension/js/common/core/crypto/pgp/openpgp-key.ts
@@ -428,6 +428,19 @@ export class OpenPGPKey {
return nonDummyPrvPackets.every(p => p.isDecrypted());
}
+ public static async checkPublicKeyError(pubkey: Key): Promise
{
+ try {
+ const key = await OpenPGPKey.extractExternalLibraryObjFromKey(pubkey);
+ await opgp.encrypt({
+ message: await opgp.createMessage({ text: OpenPGPKey.encryptionText }),
+ encryptionKeys: key.toPublic(),
+ format: 'armored',
+ });
+ return undefined;
+ } catch (err) {
+ return String(err);
+ }
+ }
public static isFullyEncrypted(key: OpenPGP.PrivateKey): boolean {
const nonDummyPrvPackets = OpenPGPKey.getPrvPackets(key);
return nonDummyPrvPackets.every(p => !p.isDecrypted());
diff --git a/test/source/tests/settings.ts b/test/source/tests/settings.ts
index 446d7f9e15e..0addfe2bb5a 100644
--- a/test/source/tests/settings.ts
+++ b/test/source/tests/settings.ts
@@ -382,6 +382,7 @@ export const defineSettingsTests = (testVariant: TestVariant, testWithBrowser: T
const firstFrameId = /frameId=.*?&/s.exec(framesUrls[0])![0];
const errorFrame = await contactsFrame.getFrame(['pgp_pubkey.htm', firstFrameId]);
await errorFrame.waitForContent('@error-introduce-label', 'This OpenPGP key is not usable.');
+ await errorFrame.waitForContent('@error-introduce-label', 'Could not verify primary key: dsa keys are considered too weak');
await errorFrame.waitForInputValue('@error-email-input', 'dsa@flowcrypt.test');
})
);