Commit Graph

121 Commits

Author SHA1 Message Date
larabr
ab22fe86da
Lint: enforce single quotes and do not error on class methods without this (#1341) 2021-06-24 22:58:15 +02:00
larabr
b76236755a
Ignore Trust and Marker packets on parsing and always throw on unexpected packets (#1340)
- When parsing, throw on unexpected packets even if `config.tolerant = true`
(e.g. if a Public Key packet is found when reading a signature).
- Always ignore Trust and Marker packets on parsing.
- Fix #1145: correctly verify signatures that include Marker packets when
`config.tolerant = false`.
2021-06-23 12:17:29 +02:00
larabr
0e088aec28
Fix various signature verification issues (#1302)
- Throw on signature parsing (e.g. in `openpgp.readSignature`) if the
  creation time subpacket is missing
- `SignaturePacket.verify` now directly checks for signature creation
  and expiration times. This makes it easier to thoroughly check the
  validity of signatures. Also:
  - `openpgp.revokeKey` now takes a `date` to check the provided
    revocation certificate
  - `openpgp.decryptSessionKeys` now takes a `date` to check the
    validity of the provided private keys
  - whenever a `date` is used internally, the function accepts a
    `date` param to allow passing the correct date
- Add tests for all of the above
- Like `openpgp.generateKey`, `openpgp.reformatKey` now also requires
  `options.userIDs`
- Simplify calling `SubKey.isRevoked/update/getExpirationTime` by
  adding the `SubKey.mainKey` field to hold the reference of the
  corresponding `Key`

Breaking changes in low-level functions:
- Added/removed `date` params:
  - `Key.update(key, config)` -> `update(key, date, config)`
  - `Key.applyRevocationCertificate(revocationCertificate, config)` ->
    `applyRevocationCertificate(revocationCertificate, date, config)`
  - `Key.signAllUsers(privateKeys, config)` ->
    `signAllUsers(privateKeys, date, config)`
  - `Key.verifyAllUsers(keys, config)` ->
    `verifyAllUsers(keys, date, config)`
  - `new SignaturePacket(date)` -> `new SignaturePacket()`
  - `SignaturePacket.sign(key, data, detached)` ->
    `sign(key, data, date, detached)`
  - `Message.sign(primaryKey, privateKeys, config)` ->
    `sign(primaryKey, privateKeys, date, config)`
  - `Message.decrypt(privateKeys, passwords, sessionKeys, config)` ->
    `decrypt(privateKeys, passwords, sessionKeys, date, config)`
  - `Message.decryptSessionKeys(privateKeys, passwords, config)` ->
    `decryptSessionKeys(privateKeys, passwords, date, config)`
- Removed `primaryKey` params:
  - `SubKey.isRevoked(primaryKey, signature, key, date, config)` ->
    `isRevoked(signature, key, date, config)`
  - `SubKey.update(subKey, primaryKey, date, config)` ->
    `update(subKey, date, config)`
  - `SubKey.getExpirationTime(primaryKey, date, config)` ->
    `getExpirationTime(date, config)`
2021-06-08 18:12:48 +02:00
Daniel Huigens
0ca83cf121 Switch from Uint8Array.from to new Uint8Array 2021-05-28 17:08:13 +02:00
Daniel Huigens
93b77669bc
Unexport openpgp.stream (#1291)
This change allows us to only load the `ReadableStream` polyfill when
needed without behaving inconsistently in the external API.

Users of the library should use the global `ReadableStream` or Node.js
`stream.Readable` instead, or import a polyfill if needed. This patch
loosens the detection criteria such that polyfilled streams are better
detected.
2021-05-05 20:20:20 +02:00
larabr
31fe960261
Only ignore unsupported packets when config.tolerant is set (#1298)
Don't ignore parse errors if `config.tolerant` is enabled. This leads to
more useful error messages in most cases, as ignoring these errors will
most likely still lead to an error down the line (e.g. if a key binding
signature is missing). Unsupported and unknown packets and packets with
an unsupported or unknown version are still ignored, for forward
compatibility.

Also, make `PKESK.encrypt`/`decrypt` void.
2021-05-05 19:51:33 +02:00
larabr
02a1ed2d78
Make key fingerprint computation async (#1297)
- Make fingerprint and key ID computation async, and rely on Web Crypto
  for hashing if available
- Always set fingerprint and keyID on key parsing / generation
- Introduce `*KeyPacket.computeFingerprint()` and
  `*KeyPacket.computeFingerprintAndKeyID()` 
- Change `getKeyID` and `getFingerprint*` functions to return the
  pre-computed key ID and fingerprint, respectively
- Make `PublicKeyPacket.read` async
2021-05-05 17:39:19 +02:00
larabr
247ad58344
Add PacketList.fromBinary and add missing config param in some functions (#1294)
- Add `PacketList.fromBinary` which parses binary data and returns a
  `PacketList`. Using it instead of `PacketList.read` avoids being left
  with partially read data in case of errors.
- Rename `toPacketlist` to `toPacketList` in `Key`, `Subkey` and `User`
  classes
- In `readMessage`, pass down `config` to `PacketList.read`
- Add `config` param to `CompressedDataPacket.decompress`,
  `AEADEncryptedDataPacket.decrypt` and `Message.appendSignature`
2021-05-05 16:56:11 +02:00
larabr
aeddac438e
Make PacketList a valid subtype of Array and update Packet.tag types (#1289)
Changes:
- Implementation:
  - Remove `PacketList.prototype.concat` and `push`
    (we solely rely on `Array.push` instead)
  - Fix https://github.com/openpgpjs/openpgpjs/issues/907 by
    correctly handling result of `filterByTag`
  - Implement `write()` method for `Trust` and `Marker` packets,
    to make them compatible with the `BasePacket` interface
- Types:
  - Simplify and updated `PacketList` type definitions
  - Fix types for `Packet.tag`, which is `static` since
    https://github.com/openpgpjs/openpgpjs/pull/1268
  - Prevent passing SubkeyPackets where KeyPackets are expected,
    and vice versa
2021-04-29 17:18:39 +02:00
larabr
0654bbe505
Remove Key.prototype.encrypt() and Key.prototype.decrypt() (#1285)
To encrypt/decrypt a key, the top-level functions `openpgp.encryptKey` and
`openpgp.decryptKey` should be used instead: these don't mutate the key;
instead, they either return a new encrypted/decrypted key object or throw an
error.

With `Key.prototype.encrypt` and `decrypt`, which mutated the key, it was
possible to end up in an inconsistent state if some (sub)keys could be
decrypted but others couldn't, they would both mutate the key and throw an
error, which is unexpected.

Note that the `keyID` parameter is not supported by `encryptKey`/`decryptKey`,
since partial key decryption is not recommended. If you still need to decrypt
a single subkey or primary key `k`, you can call `k.keyPacket.decrypt(...)`,
followed by `k.keyPacket.validate(...)`. Similarly, for encryption, call
`k.keyPacket.encrypt(...)`.

Additionally, `openpgp.generateKey` now requires `options.userIDs` again,
since otherwise the key is basically unusable. This was a regression from v4,
since we now allow parsing keys without user IDs (but still not using them).
2021-04-23 15:43:38 +02:00
Kostis Andrikopoulos
39aa742c7a
Fix encoded length in unencrypted v5 secret key packets (#1278)
When unencrypted secret key packets are serialized, a 2-byte checksum is
appended after the key material. According to rfc4880bis, these 2 bytes are
not included in the length of the key material (this encoded length is a new
addition of rfc4880bis, specific to v5 keys). We erroneously included them,
causing other implementations to fail to parse unencrypted v5 private keys
generated by OpenPGP.js.
2021-04-06 15:00:45 +02:00
Daniel Huigens
18ec54bf4b Fetch Streams ponyfill on demand in lightweight build 2021-03-26 10:56:02 +01:00
Daniel Huigens
06aef92752 Remove internal streaming parameters 2021-03-25 19:23:58 +01:00
larabr
6cff19c44a
Use consistent name casing (#1268)
- Use PascalCase for classes, with uppercase acronyms.
- Use camelCase for function and variables. First word/acronym is always
  lowercase, otherwise acronyms are uppercase.

Also, make the packet classes' `tag` properties `static`.
2021-03-25 19:56:59 +01:00
larabr
6e2a787ff8
Rename config.ignoreMdcError, drop config.integrityProtect and allow V4 keys to be AEAD-encrypted (#1261)
* Rename `config.ignoreMdcError` to `config.allowUnauthenticatedMessages`

* Do not support creating sym. enc. messages without integrity protection

* Use `config.aeadProtect` to determine SKESK encryption mode
2021-03-03 18:05:40 +01:00
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
Daniel Huigens
b6edfe646b Lint all tests (#1235) 2021-02-12 23:00:22 +01:00
larabr
2ee36c2984 Drop inconsistent boolean returns and fix type definitions (#1191)
- Remove the boolean return value of various internal functions that throw on
  error (the returned value was unused in most cases)
- Update and fix type definitions
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
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
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
4c93abb9f9 Use V5 keys by default (#1063) 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
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
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
Wiktor Kwapisiewicz
0712e8af2d
Support non-human-readable notation values (#983)
This change adds support for binary (non-human-readable) values in
signature notations through `rawNotations` property on signature objects.
Human-readable notations will additionally appear in `notations` object
where the value of the notation will be deserialized into a string.

Additionally the check for human-readable flag was modified to check the
existence of the flag instead of comparison with the whole value.
2020-08-18 11:07:58 +02:00
Daniel Huigens
a7cc71e35e
Throw when trying to encrypt a key that's already encrypted (#950) 2019-08-19 13:27:52 +02:00
Daniel Huigens
a184ef6ec4 Remove support for the previous draft00 AEAD 2019-08-12 17:46:37 +02:00
Wiktor Kwapisiewicz
16b12d7f55
Expose all signature notations
Previous implementation used an object to hold notations so if multiple
notations had the same key name only the last one was visible.

After this change notations are exposed as an array of key-value pairs
that can be converted to a map through `new Map(notations)`.

See #897.
2019-05-09 12:12:22 +02:00
Daniel Huigens
997f3e8e38 Compute signed data based on expected signature type 2018-11-05 17:13:40 +01:00
Daniel Huigens
11fd2313a7 Fix unhandled promise rejection when decrypting non-MDC message 2018-11-01 11:46:43 +01:00
Daniel Huigens
4bdc5e92ab Add --compat option
Without it, the generated build is for recent versions of
Chrome, Firefox, Safari and Edge.

With it, the generated build is for IE11+.
2018-08-14 17:24:41 +02:00
Daniel Huigens
d844b8b06c Add minimum AEAD buffer size
This enables parallelism for streaming AEAD chunked encryption.

The reason we can't do so at the very end of the pipe chain
(e.g., in `readToEnd`) is because requests for increased
buffering (i.e. `desiredSize > 1`) do not propagate backwards,
only requests for backpressure (i.e. `desiredSize <= 0`) do.
2018-08-14 16:35:39 +02:00
Daniel Huigens
d2ba6b3c6c Wait for data to be read before resolving signatures 2018-08-10 14:46:28 +02:00
Daniel Huigens
4d82d25559 Pass more tests
We now use streams internally in more places.
2018-08-10 14:46:26 +02:00
Daniel Huigens
ade2627bca Streaming verify one-pass signatures 2018-08-10 14:44:01 +02:00
Daniel Huigens
37014ecf30 Pass more tests
- Allow leading spaces in headers (since we were already accepting
leading spaces everywhere else in the armored text).
- Read ReadableStreams before passing them to a Worker
2018-08-10 14:44:01 +02:00
Daniel Huigens
db39e616ca Replace stream.tee() with stream.clone()
Also some other fixes to pass more tests.
2018-08-10 14:44:01 +02:00
Daniel Huigens
16ba26c298 Streaming AEAD 2018-08-10 14:44:01 +02:00
Daniel Huigens
4ada3fa590 Don't mutate prototypes of Uint8Array, ReadableStream and ReadableStreamDefaultWriter 2018-08-10 14:44:01 +02:00
Daniel Huigens
0372bf78f1 Make (de)armoring and packet reading asynchronous 2018-08-10 14:44:01 +02:00