Skip to content

Commit

Permalink
issue #1362 Upgrade to openpgp.js v5 (#1374)
Browse files Browse the repository at this point in the history
* wip issue 1362

* update local copy

* add old version for reference

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* fix build script

* wip

* wip

* wip

* wip

* cleanup and formatting

* comment about key.getExpirationTime()

* refactor (algoInfo as any)

* remove unnecessary code

* fix encrypt

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* fix

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* clarify error messages in the lastSig()

* deduplicate preparation of encryptionKeys

* add block

* update build script

* remove test.sh

* fix gitignore

* remove random()

* indicate origin of the str_to_hex()

* wip

* latestValidKeyBindingSig

* str_to_hex LGPL

* wip

* Add web-stream-tools

* wip

* import readToEnd() from web-stream-tools

* added ambiets.d.ts

* wip

* added web-stream-tools.d.ts

* patch web-stream-tools

* wip

* Change type of PrvKeyInfo.decrypted to PrivateKey

* revert to openpgp.js patch

* import web-stream-tools

* clean up

* cleanup

* remove openpgp.d.ts

* fix path

* remove reference to .d.ts

* added todos

* use Math.max() in the lastSig()

Co-authored-by: Ivan Pizhenko <Ivan.Pizhenko@users.noreply.github.com>
Co-authored-by: tomholub <info@nvimp.com>
Co-authored-by: Roma Sosnovsky <roma.sosnovsky@gmail.com>
  • Loading branch information
4 people committed Feb 18, 2022
1 parent ec58e12 commit 42ddb39
Show file tree
Hide file tree
Showing 25 changed files with 765 additions and 44,418 deletions.
1 change: 1 addition & 0 deletions Core/.gitignore
Expand Up @@ -2,3 +2,4 @@
build/*
tmp/*
node_modules
/test.sh
91 changes: 73 additions & 18 deletions Core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Core/package.json
Expand Up @@ -4,7 +4,9 @@
"description": "TypeScript core for FlowCrypt iOS internal use",
"dependencies": {
"encoding-japanese": "^1.0.30",
"openpgp": "^5.1.0",
"sanitize-html": "2.6.1",
"@openpgp/web-stream-tools": "^0.0.9",
"zxcvbn": "4.4.2"
},
"devDependencies": {
Expand Down Expand Up @@ -41,4 +43,4 @@
"license": "SEE LICENSE IN <LICENSE>",
"private": true,
"homepage": "https://flowcrypt.com"
}
}
24 changes: 18 additions & 6 deletions Core/source/core/pgp-armor.ts
Expand Up @@ -5,10 +5,10 @@
import { Buf } from './buf';
import { ReplaceableMsgBlockType } from './msg-block';
import { Str } from './common';
import { openpgp } from './pgp';
import { CleartextMessage, Data, Message, readCleartextMessage, readMessage } from 'openpgp';

export type PreparedForDecrypt = { isArmored: boolean, isCleartext: true, message: OpenPGP.cleartext.CleartextMessage }
| { isArmored: boolean, isCleartext: false, message: OpenPGP.message.Message };
export type PreparedForDecrypt = { isArmored: boolean, isCleartext: true, message: CleartextMessage }
| { isArmored: boolean, isCleartext: false, message: Message<Data> };

type CryptoArmorHeaderDefinitions = { readonly [type in ReplaceableMsgBlockType | 'null' | 'signature']: CryptoArmorHeaderDefinition; };
type CryptoArmorHeaderDefinition = { begin: string, middle?: string, end: string | RegExp, replace: boolean };
Expand Down Expand Up @@ -83,11 +83,23 @@ export class PgpArmor {
const isArmoredSignedOnly = utfChunk.includes(PgpArmor.headers('signedMsg').begin);
const isArmored = isArmoredEncrypted || isArmoredSignedOnly;
if (isArmoredSignedOnly) {
return { isArmored, isCleartext: true, message: await openpgp.cleartext.readArmored(new Buf(encrypted).toUtfStr()) };
return {
isArmored,
isCleartext: true,
message: await readCleartextMessage({cleartextMessage: (new Buf(encrypted)).toUtfStr()})
};
} else if (isArmoredEncrypted) {
return { isArmored, isCleartext: false, message: await openpgp.message.readArmored(new Buf(encrypted).toUtfStr()) };
return {
isArmored,
isCleartext: false,
message: await readMessage({armoredMessage: (new Buf(encrypted)).toUtfStr()})
};
} else if (encrypted instanceof Uint8Array) {
return { isArmored, isCleartext: false, message: await openpgp.message.read(encrypted) };
return {
isArmored,
isCleartext: false,
message: await readMessage({binaryMessage: encrypted})
};
}
throw new Error('Message does not have armor headers');
}
Expand Down
33 changes: 0 additions & 33 deletions Core/source/core/pgp-hash.ts

This file was deleted.

0 comments on commit 42ddb39

Please sign in to comment.