Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 53
Switch to OpenPGP v5#4725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Switch to OpenPGP v5 #4725
Changes from all commits
a1bdf38e6573147884761872e73bb41a0a4256820be1896a17901816997582dc096acfdae17fc0d38c39ff2a334164e3c70bcec0a5d6cf8ca25bcb1586cac3501b2665197b5a52d98cfa0de4ad8f24d4dcafa1bf6f497244f6006b988b6c3a3ad298a8254e03ae3936bc759426bc4555d9f0da64f2f8ab3d3f85ae144b57a649b3a840fdb841d3fc77de601962ccb17936f94d698c802f5aac3e6b3ff46a414e216135477418acc9ea903846ab398e23a05cb66b6d0644fe8cdecc288011efba5aedbf104022875b32f27f97dc5dedcde656fe931ce292c4a0741238d7f6532114bc37e536f3cefd72898e914f96063995d8674f141430d6955fe8b9f97ab1214b869ace09a6413b186a531bc952eaf0815e5f26413c85ac4422125a80797e2918141f743e0ac6f1280c6f15ad4e67e1749e0b056814d6a81df3dfcc1369abeeb3dedef173ff6817b3af1ef05a568de98bc07bcca62de37e8fcd84bf83604400f9d4b397c4d975626c6d6ec4933a1afFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2020", | ||
| "lib": [ | ||
| "es6", | ||
| "dom" | ||
| ], | ||
| "allowJs": true, | ||
| "alwaysStrict": true, | ||
| "noImplicitAny": true, | ||
| "strictNullChecks": true, | ||
| "allowSyntheticDefaultImports": true, | ||
| "esModuleInterop": true, | ||
| "module": "commonjs", | ||
| "sourceMap": true, | ||
| "outDir": "../build/streams", | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": [ | ||
| "../node_modules/@openpgp/web-stream-tools/lib/*.js" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,7 +6,6 @@ import { GoogleAuth } from '../common/api/email-provider/gmail/google-auth.js'; | ||
| import { Bm, BrowserMsg } from '../common/browser/browser-msg.js'; | ||
| import { emailKeyIndex } from '../common/core/common.js'; | ||
| import { VERSION } from '../common/core/const.js'; | ||
| import { opgp } from '../common/core/crypto/pgp/openpgpjs-custom.js'; | ||
| import { ExpirationCache } from '../common/core/expiration-cache.js'; | ||
| import { processAndStoreKeysFromEkmLocally, getLocalKeyExpiration } from '../common/helpers.js'; | ||
| import { Catch } from '../common/platform/catch.js'; | ||
| @@ -20,8 +19,6 @@ import { migrateGlobal, moveContactsToEmailsAndPubkeys, updateOpgpRevocations, u | ||
| console.info('background_process.js starting'); | ||
| opgp.initWorker({ path: '/lib/openpgp.worker.js' }); | ||
tomholub marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| (async () => { | ||
| let db: IDBDatabase; | ||
| let storage: GlobalStoreDict; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,6 +8,7 @@ import { MsgBlockParser } from '../msg-block-parser.js'; | ||
| import { PgpArmor } from './pgp/pgp-armor.js'; | ||
| import { opgp } from './pgp/openpgpjs-custom.js'; | ||
| import { OpenPGPKey } from './pgp/openpgp-key.js'; | ||
| import type * as OpenPGP from 'openpgp'; | ||
| import { SmimeKey } from './smime/smime-key.js'; | ||
| import { MsgBlock } from '../msg-block.js'; | ||
| import { EmailParts } from '../common.js'; | ||
| @@ -95,7 +96,7 @@ export interface KeyInfoWithIdentityAndOptionalPp extends KeyInfoWithIdentity { | ||
| export type KeyAlgo = 'curve25519' | 'rsa2048' | 'rsa3072' | 'rsa4096'; | ||
| export type PrvPacket = OpenPGP.packet.SecretKey | OpenPGP.packet.SecretSubkey; | ||
| export type PrvPacket = OpenPGP.SecretKeyPacket | OpenPGP.SecretSubkeyPacket; | ||
| export class UnexpectedKeyTypeError extends Error {} | ||
| @@ -203,7 +204,7 @@ export class KeyUtil { | ||
| allErr: Error[] = []; | ||
| let uncheckedOpgpKeyCount = 0; | ||
| try { | ||
| const { keys, err } = await opgp.key.read(key); | ||
| const keys= await opgp.readKeys({ binaryKeys: key }); // todo: opgp.readKey ? | ||
Comment on lines
-206
to
+207
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks ok to me as implemented, is the todo still current? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. Not ideal but ok to proceed as is and file an issue. Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also #4725 (comment) | ||
| uncheckedOpgpKeyCount = keys.length; | ||
| for (const key of keys) { | ||
| try { | ||
| @@ -221,9 +222,9 @@ export class KeyUtil { | ||
| allErr.push(e as Error); | ||
| } | ||
| } | ||
| if (err) { | ||
| /* todo: re-throw? if (err) { | ||
| allErr.push(...err); | ||
| } | ||
| } */ | ||
tomholub marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } catch (e) { | ||
| allErr.push(e as Error); | ||
| } | ||
| @@ -246,14 +247,21 @@ export class KeyUtil { | ||
| throw new Error(err.length ? err.map((e, i) => i + 1 + '. ' + e.message).join('\n') : 'Should not happen: no keys and no errors.'); | ||
| }; | ||
| public static armor = (pubkey: Key): string => { | ||
| const armored = (pubkey as unknown as { rawArmored: string }).rawArmored; | ||
| public static armor = (key: Key): string => { | ||
| const armored = (key as unknown as { rawArmored: string }).rawArmored; | ||
| if (!armored) { | ||
| throw new Error('The Key object has no rawArmored field.'); | ||
| } | ||
| return armored; | ||
| }; | ||
| // remove crypto-library objects (useful when sending the object to/from background) | ||
| public static pack = (key: Key): void => { | ||
| if (key.family === 'openpgp') { | ||
| OpenPGPKey.pack(key); | ||
| } | ||
| }; | ||
| public static diagnose = async (key: Key, passphrase: string): Promise<Map<string, string>> => { | ||
| let result = new Map<string, string>(); | ||
| result.set(`Key type`, key.family); | ||
| @@ -303,16 +311,17 @@ export class KeyUtil { | ||
| }; | ||
| // todo - this should be made to tolerate smime keys | ||
| public static normalize = async (armored: string): Promise<{ normalized: string; keys: OpenPGP.key.Key[] }> => { | ||
| public static normalize = async (type: 'publicKey' | 'privateKey', armored: string): Promise<{ normalized: string; keys: OpenPGP.Key[] }> => { | ||
| try { | ||
| let keys: OpenPGP.key.Key[] = []; | ||
| let keys: OpenPGP.Key[] = []; | ||
| armored = PgpArmor.normalize(armored, 'key'); | ||
| if (RegExp(PgpArmor.headers('publicKey', 're').begin).test(armored)) { | ||
| keys = (await opgp.key.readArmored(armored)).keys; | ||
| keys = await opgp.readKeys({ armoredKeys: armored }); | ||
| } else if (RegExp(PgpArmor.headers('privateKey', 're').begin).test(armored)) { | ||
| keys = (await opgp.key.readArmored(armored)).keys; | ||
| keys = await opgp.readKeys({ armoredKeys: armored }); | ||
| } else if (RegExp(PgpArmor.headers('encryptedMsg', 're').begin).test(armored)) { | ||
| keys = [new opgp.key.Key((await opgp.message.readArmored(armored)).packets)]; | ||
| const packets = (await opgp.readMessage({ armoredMessage: armored })).packets; | ||
| keys = [type === 'publicKey' ? new opgp.PublicKey(packets) : new opgp.PrivateKey(packets)]; | ||
| } | ||
| for (const k of keys) { | ||
| for (const u of k.users) { | ||
| @@ -350,7 +359,7 @@ export class KeyUtil { | ||
| public static decrypt = async ( | ||
| key: Key, | ||
| passphrase: string, | ||
| optionalKeyid?: OpenPGP.Keyid, | ||
| optionalKeyid?: OpenPGP.KeyID, | ||
| optionalBehaviorFlag?: 'OK-IF-ALREADY-DECRYPTED' | ||
| ): Promise<boolean> => { | ||
| if (key.family === 'openpgp') { | ||
| @@ -385,11 +394,11 @@ export class KeyUtil { | ||
| } | ||
| }; | ||
| public static revoke = async (key: Key): Promise<string | undefined> => { | ||
| public static getOrCreateRevocationCertificate = async (key: Key): Promise<string | undefined> => { | ||
| if (key.family === 'openpgp') { | ||
| return await OpenPGPKey.revoke(key); | ||
| return await OpenPGPKey.getOrCreateRevocationCertificate(key); | ||
| } else { | ||
| throw new Error(`KeyUtil.revoke does not support key family ${key.family}`); | ||
| throw new Error(`KeyUtil.getOrCreateRevocationCertificate does not support key family ${key.family}`); | ||
| } | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole page (and related html page if any) can be removed. This downloads the whole inbox at once, in a format we don't use anymore.
These days when we need a message we download it one by one, based on steps/instructions elsewhere in the code.