-
Notifications
You must be signed in to change notification settings - Fork 47
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
Switch to OpenPGP v5 #4725
Switch to OpenPGP v5 #4725
Changes from 102 commits
a1bdf38
e657314
7884761
872e73b
b41a0a4
256820b
e1896a1
7901816
997582d
c096acf
dae17fc
0d38c39
ff2a334
164e3c7
0bcec0a
5d6cf8c
a25bcb1
586cac3
501b266
5197b5a
52d98cf
a0de4ad
8f24d4d
cafa1bf
6f49724
4f6006b
988b6c3
a3ad298
a8254e0
3ae3936
bc75942
6bc4555
d9f0da6
4f2f8ab
3d3f85a
e144b57
a649b3a
840fdb8
41d3fc7
7de6019
62ccb17
936f94d
698c802
f5aac3e
6b3ff46
a414e21
6135477
418acc9
ea90384
6ab398e
23a05cb
66b6d06
44fe8cd
ecc2880
11efba5
aedbf10
4022875
b32f27f
97dc5de
dcde656
fe931ce
292c4a0
741238d
7f65321
14bc37e
536f3ce
fd72898
e914f96
063995d
8674f14
1430d69
55fe8b9
f97ab12
14b869a
ce09a64
13b186a
531bc95
2eaf081
5e5f264
13c85ac
4422125
a80797e
2918141
f743e0a
c6f1280
c6f15ad
4e67e17
49e0b05
6814d6a
81df3df
cc1369a
beeb3de
def173f
f6817b3
af1ef05
a568de9
8bc07bc
ca62de3
7e8fcd8
4bf8360
4400f9d
4b397c4
d975626
c6d6ec4
933a1af
File filter
Filter by extension
Conversations
Jump to
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 |
---|---|---|
|
@@ -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
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? 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 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. 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.
Show resolved
Hide resolved
|
||
} 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,16 @@ 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 (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)]; | ||
keys = [new opgp.PrivateKey((await opgp.readMessage({ armoredMessage: armored })).packets)]; // todo: or PublicKey | ||
} | ||
for (const k of keys) { | ||
for (const u of k.users) { | ||
|
@@ -350,7 +358,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 +393,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}`); | ||
} | ||
}; | ||
|
||
|
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.