Skip to content

Commit d0ee03f

Browse files
#6049 Upgrade openpgp to v6.2 (#6050)
* feat: upgraded openpgp to v6.2 * fix: module resolution * fix: module resolution * fix: pr reviews
1 parent 2cb3ad6 commit d0ee03f

File tree

8 files changed

+19
-21
lines changed

8 files changed

+19
-21
lines changed

conf/tsconfig.content_scripts.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"strictFunctionTypes": false,
1414
"sourceMap": false,
1515
"checkJs": false,
16+
"moduleResolution": "node",
1617
"outDir": "../build/_/content_scripts",
1718
"baseUrl": "../extension",
1819
"paths": {

extension/js/common/core/crypto/pgp/msg-util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Key, KeyInfoWithIdentity, KeyInfoWithIdentityAndOptionalPp, KeyUtil } f
55
import { ReplaceableMsgBlockType } from '../../msg-block.js';
66
import { Buf } from '../../buf.js';
77
import { PgpArmor, PreparedForDecrypt } from './pgp-armor.js';
8-
import { opgp } from './openpgpjs-custom.js';
8+
import { OpenPGPDataType, opgp } from './openpgpjs-custom.js';
99
import type * as OpenPGP from 'openpgp';
1010
import { KeyCache } from '../../../platform/key-cache.js';
1111
import { SmimeKey, SmimeMsg } from '../smime/smime-key.js';
@@ -331,7 +331,7 @@ export class MsgUtil {
331331
return true;
332332
}
333333

334-
private static async getSortedKeys(kiWithPp: KeyInfoWithIdentityAndOptionalPp[], msg: OpenPGP.Message<OpenPGP.Data>): Promise<SortedKeysForDecrypt> {
334+
private static async getSortedKeys(kiWithPp: KeyInfoWithIdentityAndOptionalPp[], msg: OpenPGP.Message<OpenPGPDataType>): Promise<SortedKeysForDecrypt> {
335335
const keys: SortedKeysForDecrypt = {
336336
encryptedFor: [],
337337
signedBy: [],

extension/js/common/core/crypto/pgp/openpgp-key.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com */
22
import { Key, PrvPacket, KeyAlgo, KeyUtil, UnexpectedKeyTypeError, PubkeyInfo } from '../key.js';
3-
import { opgp } from './openpgpjs-custom.js';
3+
import { OpenPGPDataType, opgp } from './openpgpjs-custom.js';
44
import { Catch } from '../../../platform/catch.js';
55
import { Str, Value } from '../../common.js';
66
import { Buf } from '../../buf.js';
77
import type * as OpenPGP from 'openpgp';
88
import { PgpMsgMethod, VerifyRes } from './msg-util.js';
99
import * as Stream from '@openpgp/web-stream-tools';
1010

11-
type OpenpgpMsgOrCleartext = OpenPGP.Message<OpenPGP.Data> | OpenPGP.CleartextMessage;
11+
type OpenpgpMsgOrCleartext = OpenPGP.Message<OpenPGPDataType> | OpenPGP.CleartextMessage;
1212
export interface KeyWithPrivateFields extends Key {
1313
internal: OpenPGP.Key | string; // usable key without weak packets
1414
rawArmored: string;
@@ -117,7 +117,7 @@ export class OpenPGPKey {
117117
await OpenPGPKey.convertExternalLibraryObjToKey(encryptedPrv, key);
118118
}
119119

120-
public static async decryptMessage(message: OpenPGP.Message<OpenPGP.Data>, privateKeys: Key[], passwords?: string[]) {
120+
public static async decryptMessage(message: OpenPGP.Message<OpenPGPDataType>, privateKeys: Key[], passwords?: string[]) {
121121
const opgpKeys = await Promise.all(privateKeys.map(key => OpenPGPKey.extractExternalLibraryObjFromKey(key)));
122122
return await message.decrypt(
123123
opgpKeys.filter(key => key.isPrivate()),
@@ -477,12 +477,6 @@ export class OpenPGPKey {
477477
return p instanceof opgp.SecretKeyPacket || p instanceof opgp.SecretSubkeyPacket;
478478
}
479479

480-
public static isBaseKeyPacket(p: OpenPGP.BasePacket): p is OpenPGP.BasePublicKeyPacket {
481-
return (
482-
p instanceof opgp.SecretKeyPacket || p instanceof opgp.SecretSubkeyPacket || p instanceof opgp.PublicKeyPacket || p instanceof opgp.PublicSubkeyPacket
483-
);
484-
}
485-
486480
public static async isPacketDecrypted(pubkey: Key, keyid: OpenPGP.KeyID) {
487481
const [k] = (await OpenPGPKey.extractExternalLibraryObjFromKey(pubkey)).getKeys(keyid); // keyPacket.isDecrypted(keyID);
488482
if (!k) {
@@ -577,7 +571,7 @@ export class OpenPGPKey {
577571
// mimicks OpenPGP.helper.getLatestValidSignature
578572
private static async getLatestValidSignature(
579573
signatures: OpenPGP.SignaturePacket[],
580-
primaryKey: OpenPGP.BasePublicKeyPacket,
574+
primaryKey: OpenPGP.AnyKeyPacket,
581575
signatureType: OpenPGP.enums.signature,
582576
dataToVerify: object | Uint8Array
583577
): Promise<OpenPGP.SignaturePacket | undefined> {
@@ -801,7 +795,7 @@ export class OpenPGPKey {
801795
}
802796
return undefined;
803797
}
804-
private static arePrivateParamsMissing = (packet: OpenPGP.BasePublicKeyPacket): boolean => {
798+
private static arePrivateParamsMissing = (packet: OpenPGP.AnyKeyPacket): boolean => {
805799
// detection of missing private params to solve #2887
806800
if (!OpenPGPKey.paramCountByAlgo) {
807801
OpenPGPKey.paramCountByAlgo = {

extension/js/common/core/crypto/pgp/openpgpjs-custom.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { requireOpenpgp } from '../../../platform/require.js';
77

88
export const opgp = requireOpenpgp();
99

10+
export type OpenPGPDataType = string | Uint8Array;
11+
1012
if (typeof opgp !== 'undefined') {
1113
// in certain environments, eg pgp_block.htm or web content script, openpgp is not included
1214
opgp.config.versionString = `FlowCrypt Email Encryption ${VERSION}`;

extension/js/common/core/crypto/pgp/pgp-armor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Buf } from '../../buf.js';
88
import { ReplaceableMsgBlockType } from '../../msg-block.js';
99
import { Str } from '../../common.js';
1010
import type * as OpenPGP from 'openpgp';
11-
import { opgp } from './openpgpjs-custom.js';
11+
import { OpenPGPDataType, opgp } from './openpgpjs-custom.js';
1212
import * as Stream from '@openpgp/web-stream-tools';
1313
import { SmimeKey, ENVELOPED_DATA_OID } from '../smime/smime-key.js';
1414

@@ -17,9 +17,9 @@ export type PreparedForDecrypt =
1717
isArmored: boolean;
1818
isCleartext: true;
1919
isPkcs7: false;
20-
message: OpenPGP.CleartextMessage | OpenPGP.Message<OpenPGP.Data>;
20+
message: OpenPGP.CleartextMessage | OpenPGP.Message<OpenPGPDataType>;
2121
}
22-
| { isArmored: boolean; isCleartext: false; isPkcs7: false; message: OpenPGP.Message<OpenPGP.Data> }
22+
| { isArmored: boolean; isCleartext: false; isPkcs7: false; message: OpenPGP.Message<OpenPGPDataType> }
2323
| { isArmored: boolean; isCleartext: false; isPkcs7: true; message: forge.pkcs7.PkcsEnvelopedData };
2424

2525
type CryptoArmorHeaderDefinitions = {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"lint-staged": "^16.1.2",
3131
"mailparser": "3.7.4",
3232
"mkdirp": "3.0.1",
33-
"openpgp": "6.1.1",
33+
"openpgp": "6.2.0",
3434
"pdfjs-dist": "5.3.93",
3535
"prettier": "^3.6.2",
3636
"puppeteer": "24.14.0",

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"useUnknownInCatchVariables": false,
1414
"outDir": "build/generic-extension-wip",
1515
"baseUrl": "./extension",
16+
"moduleResolution": "node",
1617
"paths": {
1718
"jquery": ["lib/jquery.min.js", "COMMENT"],
1819
"sweetalert2": ["lib/sweetalert2.js", "COMMENT"],

0 commit comments

Comments
 (0)