Commit Graph

178 Commits

Author SHA1 Message Date
larabr
7f37a8aaca
Add config parameter to top-level functions (#1241)
Refactor functions to take the configuration as a parameter.

This allows setting a config option for a single function call, whereas
setting `openpgp.config` could lead to concurrency-related issues when
multiple async function calls are made at the same time.

`openpgp.config` is used as default for unset config values in top-level
functions.
`openpgp.config` is used as default config object in low-level functions
(i.e., when calling a low-level function, it may be required to pass
`{ ...openpgp.config, modifiedConfig: modifiedValue }`).

Also,

- remove `config.rsaBlinding`: blinding is now always applied to RSA decryption
- remove `config.debug`: debugging mode can be enabled by setting
  `process.env.NODE_ENV = 'development'`
- remove `config.useNative`: native crypto is always used when available
2021-02-26 20:04:54 +01:00
Daniel Huigens
e1307b88d0
Consolidate read* functions (#1236)
Make all `read*` functions accept an options object, so that we can add config
options to them later (for #1166). This is necessary so that we can remove the
global `openpgp.config`, which doesn't work that well when importing
individual functions.

Furthermore, merge `readMessage` and `readArmoredMessage` into one function,
et cetera.
2021-02-17 20:36:33 +01:00
Ali Cherry
9ae0aae7a2
Add options to select encryption/signing key IDs (#1238) 2021-02-17 20:06:31 +01:00
Daniel Huigens
b6edfe646b Lint all tests (#1235) 2021-02-12 23:00:22 +01:00
larabr
ca092c7cd0 Speed up decryptKey and encryptKey (#1192)
Change `openpgp.decryptKey` and `openpgp.encryptKey` to avoid deep cloning the
original key.
2021-02-09 19:25:20 +01:00
larabr
c23ed58387 Require User IDs to be objects; refactor UserIDPacket (#1187)
- `openpgp.generateKey` now expects `userIds` in object format
  (strings are no longer supported)
- Remove `util.parseUserId` and `util.formatUserId`
- Replace `UserIDPacket#format` with `UserIDPacket.fromObject`
2021-02-09 19:25:20 +01:00
larabr
286d991265 Fix parsing of short P-521 keys and EdDSA, RSA signatures (#1185)
Also, strip leading zeros when serializing MPIs, as per the spec.
2021-02-09 19:25:20 +01:00
Daniel Huigens
2382482090 [v5] Unexport openpgp.util, openpgp.crypto, and low-level types (#1175) 2021-02-09 19:25:20 +01:00
larabr
479d826533 Remove armor comment and version by default (#1170) 2021-02-09 19:25:20 +01:00
Daniel Huigens
b3e08fdc26 Don't export default objects / namespaces
Import individual functions, instead.
2021-02-09 19:25:20 +01:00
Daniel Huigens
f276e1ef51 Export key, message, signature, cleartext functions and classes directly
Instead of as modules.

Replace *.read with read*, *.readArmored with readArmored*, etc.
Replace cleartext.readArmored with readArmoredCleartextMessage.
Replace message.fromText with Message.fromText, etc.
2021-02-09 19:25:20 +01:00
larabr
3a75eadaa0 Store named key params in key objects (#1141)
- Store private and public params separately and by name in objects,
  instead of as an array

- Do not keep params in MPI form, but convert them to Uint8Arrays when
  generating/parsing the key

- Modify low-level crypto functions to always accept and return
  Uint8Arrays instead of BigIntegers

- Move PKCS1 padding to lower level functions
2021-02-09 19:25:20 +01:00
larabr
8854b097b4 Use native BigInt when available instead of bn.js (#1119)
In the lightweight build, lazily load bn.js only when necessary.

Also, use Uint8Arrays instead of strings in PKCS1 padding functions, and
check that the leading zero is present when decoding EME-PKCS1 padding.
2021-02-09 19:25:20 +01:00
larabr
8d67af729a Use higher level functions in key validation tests (#1128)
Use `key.keyPacket.validate` instead of `crypto.publicKey.validateParams`, see
https://github.com/openpgpjs/openpgpjs/pull/1116#discussion_r447781386.

Also, `key.decrypt` now only throws on error, no other value is returned.

Also, fix typo (rebase error) that caused tests to fail in Safari for p521.
2021-02-09 19:25:20 +01:00
larabr
f6ee6e959e Finish merging key validation 2021-02-09 19:25:20 +01:00
Daniel Huigens
6a607c7567 Rename SymEncryptedAEADProtectedDataPacket to AEADEncryptedDataPacket 2021-02-09 19:25:20 +01:00
Daniel Huigens
fb3d23427d Allow dead code elimination 2021-02-09 19:25:20 +01:00
Daniel Huigens
0e33e641af Switch build system to rollup
Also, default to minimized builds.
2021-02-09 19:25:20 +01:00
Ilya Chesnokov
6e648b1cbc Rename enums to use camelCase (#1093) 2021-02-09 19:25:20 +01:00
Ilya Chesnokov
e16807505f Switch util function names to camelCase (#1091) 2021-02-09 19:25:20 +01:00
Ilya Chesnokov
d415bc2546 Rename config option names to camelCase (#1088) 2021-02-09 19:25:20 +01:00
larabr
8823603396 Remove worker (#1072) 2021-02-09 19:25:20 +01:00
larabr
5ad19c8da8 Generate ECC keys by default (#1065)
Also, remove the deprecated numBits options of generateKey in favor of rsaBits.
2021-02-09 19:25:20 +01:00
Daniel Huigens
2bc24f354b Return only one key in key.read[Armored], add readAll[Armored] 2021-02-09 19:25:20 +01:00
Daniel Huigens
3817cca3c6 Throw on unarmored messages with garbage data appended 2021-02-09 19:25:20 +01:00
Daniel Huigens
76a8f11780 Don't mutate key in openpgp.encryptKey/decryptKey 2021-02-09 19:25:20 +01:00
Daniel Huigens
9394fec1f4 Throw in openpgp.initWorker if worker failed to load 2021-02-09 19:25:20 +01:00
Daniel Huigens
ef7c38860b Don't unnecessarily return objects in top-level functions
openpgp.encrypt, sign, encryptSessionKey, encryptKey and decryptKey now
return their result directly without wrapping it in a "result" object.

Also, remove the `detached` and `returnSessionKey` options of
openpgp.encrypt.
2021-02-09 19:25:20 +01:00
Daniel Huigens
3a84442b5f Don't use native streams in old Edge 2021-02-09 19:25:20 +01:00
Daniel Huigens
2fffc76060 Don't overwrite Web Streams Polyfill to globals
Instead, use the ponyfill that's now included in web-stream-tools.
Also, convert back to native ReadableStream when we used the ponyfill.
2021-02-09 19:25:20 +01:00
Daniel Huigens
95eb43a3c2 Return data instead of message in encryptSessionKey
Add `armor=true/false` parameter to decide whether `data` is an armored
String or an unarmored Uint8Array.
2021-02-09 19:25:20 +01:00
Daniel Huigens
08d6b276e3 Return data as string in openpgp.verify by default
Add format='utf8'/'binary' param to openpgp.verify in order to be able
to return binary data instead.
2021-02-09 19:25:20 +01:00
Daniel Huigens
7225251af8 Return Uint8Array(Stream) instead of object when armor = false 2021-02-09 19:25:20 +01:00
larabr
38ec5314d4 Fix ElGamal param range and PKCS1 decoding (#1169)
* Fix ElGamal sampling range

* Stricter PKCS1 decoding
2021-01-20 14:09:52 +01:00
larabr
cc1bdcbae8
Allow decryption with revoked keys (#1135)
However, when decrypting session keys, check that the public key
algorithm matches that of the decryption key.
2020-08-18 15:49:27 +02:00
larabr
14f244a80f Fix decryption tests 2020-07-17 15:14:21 +02:00
larabr
00c5f38689
Cipher-specific key validation (#1116)
Also, check binding signatures for decryption keys.

Also, do not always fallback on Web Crypto ECC errors.
2020-07-13 19:57:33 +02:00
Daniel Huigens
5d71ae8691 Fix normalizing \n after \r\n
Broken in c4a7455.
2020-04-22 19:09:50 +02:00
Daniel Huigens
8c3bcd1f21 Reject signatures using insecure hash algorithms
Also, switch from returning false to throwing errors in most verify*()
functions, as well as in `await signatures[*].verified`, in order to be
able to show more informative error messages.
2020-02-25 15:06:15 +01:00
Daniel Huigens
dc9660f2ae Add tests with old and new Blowfish encrypted messages 2020-02-02 16:51:56 +01:00
Daniel Huigens
6ae6012786 Terminate workers in openpgp.destroyWorker() 2020-01-24 17:57:39 +01:00
Daniel Huigens
2cc3262149 Fix test failing on high-core-count systems due to AEAD concurrency 2019-10-15 18:38:02 +02:00
Daniel Huigens
fbbeaa3cd9
Rename numBits and bits to rsaBits (#970)
Keep supporting the old names as well though in `openpgp.generateKey`
and `getAlgorithmInfo`, but not in `openpgp.key.generate` (as it is
recommended that developers use `openpgp.generateKey` instead, and
it now throws when using `numBits` instead of `rsaBits`, so there's
no risk of silent key security downgrade).

The old names are now deprecated, and might be removed in v5.
2019-09-18 13:40:44 +02:00
Daniel Huigens
9b5124d5cd
Switch from Sauce Labs to Browserstack (#965)
* Switch from Sauce Labs to Browserstack

* Don't run all tests on CI
2019-09-16 14:59:06 +02:00
Daniel Huigens
a184ef6ec4 Remove support for the previous draft00 AEAD 2019-08-12 17:46:37 +02:00
Daniel Huigens
80c535eeb7 Separate config option to use V5 keys from AEAD config option 2019-08-12 17:46:37 +02:00
Daniel Huigens
735d6d088f Implement V5 signatures 2019-08-12 17:46:37 +02:00
Daniel Huigens
9166d6737c Don't babelify ES6 in unit tests when testing in modern browsers 2019-07-19 19:06:19 +02:00
Daniel Huigens
10cbd307c3 Add test for throwing on armor modifications 2019-07-19 19:05:26 +02:00
Daniel Huigens
34e6eacb2f Don't attempt to use workers if they fail to load 2019-05-02 12:08:08 +02:00