2397 Commits

Author SHA1 Message Date
larabr
ff4181ad5a Add back zlib and zip to preferred compression algos on key generation
To signal support, despite "no compression" being preferred by default,
for security reasons.
2023-12-08 14:00:22 +01:00
larabr
e93702bb8d Fix types path for lightweight build [skip ci] 2023-11-21 17:34:59 +01:00
Ryan
54fc2c8fbd
Add SHA3-256 and SHA3-512 to preferred hash algos on key generation (#1696)
This is to signal support to senders who wish to use these algos.
Note  that SHA256 remains as first default preference, followed by SHA512,
as in the context of OpenPGP signatures they provide
better performance/security ratio than their SHA3 counterparts.
2023-11-02 14:16:40 +01:00
larabr
7881b850ec 6.0.0-alpha.0 v6.0.0-alpha.0 2023-10-25 12:55:43 +02:00
larabr
0da131cd9a Update README 2023-10-25 12:53:15 +02:00
larabr
30635c72e8 Lint: error on unnecessary switch-case braces
Also fix some indent issues with armoring code detected after required ESLint update.

s
2023-10-25 12:53:15 +02:00
larabr
917faa56f5 Rename internal functions, filter key algos on decryption 2023-10-25 12:53:14 +02:00
larabr
690346a854 Refuse to use keys without key flags, add config.allowMissingKeyFlags
Key flags are needed to restrict key usage to specific purposes:
https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-10.html#section-5.2.3.29 .
Some older keys (e.g. from OpenPGP.js v1) do not declare any key flags.
In previous OpenPGP.js versions, we've allowed such keys to be used for any operation for which they were compatible.
This behaviour has now changed, and these keys are not allowed to be used for any operation.

The setting  `config.allowMissingKeyFlags` has been added to selectively revert to the past behaviour.
2023-10-25 12:53:14 +02:00
larabr
9a547b4553 Update rollup to v3 2023-10-25 12:53:14 +02:00
larabr
86f5a8b71b Rollup: use preserveEntrySignatures = 'exports-only' setting in lightweight build
This is the default setting and it ensures that the main chunk does not include
additional exports, which is is important when importing the module as `import *`
as shown in the readme.
In practice, this change does not affect the chunking with the current code.
2023-10-25 12:53:14 +02:00
larabr
4ee9deae62 Switch back to using standard BigInteger class instead of wrapper
Using a wrapper requires adding some handling code to fix race conditions,
but it does not provide advantages until we switch to TS.
2023-10-25 12:53:14 +02:00
larabr
9e1962f006 Import noble-hashes, noble-curves and BN.js only on demand
This primarily affects the lightweight build, which will not include these
(fairly large) libs in the main bundle file. This allows fetching their code only if required:
- Noble-curves is only needed for curves other than curve25519.
- Noble-hashes is needed for streamed hashing and e.g. SHA3 on web.
- BN.js is used by the above libs, and it's also separately needed for platforms
without native BigInt support.
2023-10-25 12:53:14 +02:00
larabr
5456211266 Simplify userID parsing based on conventions, drop third-party parsing lib
Follow conventions as per https://datatracker.ietf.org/doc/draft-dkg-openpgp-userid-conventions
2023-10-25 12:53:14 +02:00
larabr
a56a4a16e8 Use internal tweetnacl SHA-512 implementation
Instead of relying on externally provided one (no async loading supported)
2023-10-25 12:53:14 +02:00
larabr
7295a2e7b3 Rename config.useIndutnyElliptic to .useEllipticFallback
To reflect change of underlying library
2023-10-25 12:53:14 +02:00
larabr
909d44f436 Add back support for verification of some invalid ECDSA sigs affected by old lib bug
At some point we used to generate invalid ECDSA sigs with the js (non-native) elliptic lib,
if the signature digest had leading zeros: https://github.com/openpgpjs/openpgpjs/pull/948 .

Brainpool curves are the most likely to have been affected by the bug, since they do not
have WebCrypto support (unlike NIST curves).
This commit reintroduces support on web to verify such invalid signatures
(support for this was previously built-in in the indutny-elliptic library).
It also expands the fix to work in Node.
2023-10-25 12:53:14 +02:00
larabr
a9fae5ff12 Replace indutny-elliptic lib with noble-curves
Unlike elliptic, noble-curves targets algorithmic constant time, and
it relies on the native BigInts when available, resulting in a smaller bundle
and improved performance.

Also, expand testing of fallback elliptic implementation.
2023-10-25 12:53:14 +02:00
larabr
01df8ca889 Rename values of enums.curve.{curve, ed}25519Legacy from '{curve. ed}25519' to '{curve. ed}25519Legacy'
To reflect the crypto-refresh naming, after the standardisation of the new EdDSA
key types.
2023-10-25 12:53:14 +02:00
larabr
d6d8576700 Prevent generating v6 keys using legacy curve25519 2023-10-25 12:53:14 +02:00
larabr
c7efef60ac Throw when parsing v6 keys using legacy curve25519 2023-10-25 12:53:14 +02:00
larabr
7c2248151d Default to generating new curve25519 format for v6 keys
As per the spec, v6 keys must not use the legacy curve25519 format.
The new format is not used by default with v4 keys as it's not compatible with OpenPGP.js older than v5.10.0 .
However, v6 keys already break compatibility, so if the user requests them via config flag, we can safely use the new curve format as well.
2023-10-25 12:53:14 +02:00
larabr
360a44f57b addSubkey: match primary key version
As required by the spec.
2023-10-25 12:53:14 +02:00
larabr
0b7a5f69fa Drop enums.publicKey.eddsa in favour of enums.publicKey.eddsaLegacy
The crypto-refresh has standardised a new key format for EdDSA, whose algorithm
identifier are `enums.publicKey.ed25519` and `.ed448`
2023-10-25 12:53:14 +02:00
larabr
24c644207d Support generating Curve448 and Curve25519 keys (new format)
Neither type is set as default for now, since they are not widely supported.
2023-10-25 12:53:14 +02:00
larabr
1509364a49 Throw on unexpected param sizes in secret keys, session keys and signatures
Detect extra bytes in secret key material, as well as missing bytes in other parameters.
2023-10-25 12:53:14 +02:00
larabr
2afa19db01 Run npm audit 2023-10-25 12:53:13 +02:00
larabr
d291ce6d0f Update Curve448 tests using inputs from gopenpgp 2023-10-25 12:53:13 +02:00
larabr
089a14f9e0 Internal: refactor uint8ArrayToHex for performance and to avoid branching 2023-10-25 12:53:13 +02:00
larabr
56cd448a32 crypto-refresh: add support for X448 2023-10-25 12:53:13 +02:00
larabr
1ebf7034f5 crypto-refresh: add support for Ed448 2023-10-25 12:53:13 +02:00
larabr
105b3cdde4 Disregard config.aeadProtect when encrypting to public keys (#1678)
Determine whether AEAD should be used for encryption solely based the encryption key preferences.
Previously, the config flag was also used to control the behaviour, since AEAD messages were not standardised nor widely supported.

To generate keys that declare AEAD in their preferences, use `generateKey` with `config.aeadProtect = true`.
2023-10-25 12:53:13 +02:00
larabr
97ebd14829 Fix parsing of v6 signatures with unknown hash algorithm (#1683)
Fail on verification rather than parsing, also for unexpected salt size.
2023-10-25 12:53:13 +02:00
Ryan
53e1ec023f Add SHA-3 signature support (#1680)
To support parsing, signing and verifying SHA3 signatures over messages and
keys.
2023-10-25 12:53:12 +02:00
larabr
8fe04c99c6 Remove unused enums.symmetric.plaintext
This special cipher value can be relevant for unencrypted private keys:
https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-10.html#section-12.2.1 .
However, it is no longer used internally, and on the contrary it could cause
confusion on SKESK decryption, where "random" cipher algos are returned in case
of wrong password.

This change also fixes a flaky test on password-based decryption, caused by the
PKESK v6 changes which add support for `null` cipher algos. The code did not
distinguish between a `null` and a `0` (plaintext) algo identifier, and would
break when the latter was returned on SKESK decryption.
2023-10-25 12:53:12 +02:00
larabr
278a61adab Add SEIP.fromObject
To avoid defaulting to v1
2023-10-25 12:53:12 +02:00
larabr
1423bdd564 Add PKESK.fromObject 2023-10-25 12:53:12 +02:00
Lukas Burkhalter
79b3687424 Only emit Hash header below V6 for cleartext messages
The latest version of the crypto refresh (i.e., !313, !314) specifies that
the "Hash" header is depricated. This commit changes that the Hash header
is only generated if a cleartext message contains a non-V6 signature.
2023-10-25 12:53:12 +02:00
Lukas Burkhalter
1ddf4e151c Accept cleartext messages without hash header
The latest version of the crypto refresh (i.e., !313, !314) specifies that
the  "Hash" header is deprecated, and that an implementation that is verifying
a cleartext signed message MUST ignore this header.
However, we go against this directive, and keep the checks in place to avoid
arbitrary injection of text as part of the "Hash" header payload.
We also mandate that if the hash header is present, the declared
algorithm matches the signature algorithm. This is again to avoid
a spoofing attack where e.g. a SHA1 signature is presented as
using SHA512.
Related CVEs: CVE-2019-11841, CVE-2023-41037.

This commit does not change the writing part of cleartext messages.

# Conflicts:
#	src/cleartext.js
2023-10-25 12:53:12 +02:00
Lukas Burkhalter
af96628855 Add support for v6 one-pass signature packets
Introduces v6 one-pass signature packets required for v6 signatures.
Includes the changes from !305 of the crypto refresh:
https://gitlab.com/openpgp-wg/rfc4880bis/-/merge_requests/305

Also, introduce `OnePassSignaturePacket.fromSignaturePacket` to simplify
OPS generation.
2023-10-25 12:53:12 +02:00
larabr
0b8501427b Implement packet criticality check
The Packet Tag space is now partitioned into critical packets and non-critical packets.
If an implementation encounters a critical packet where the packet type is unknown in a packet sequence,
it MUST reject the whole packet sequence. On the other hand, an unknown non-critical packet MUST be ignored.

See https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-10.html#section-4.3.1 .
2023-10-25 12:53:12 +02:00
larabr
95fd04db8e Support AEAD encryption for v4 and v6 private keys 2023-10-25 12:53:12 +02:00
Daniel Huigens
21343f2bb8 Appease linter 2023-10-25 12:53:12 +02:00
larabr
33af3debc4 Throw intelligible error on GCM authentication failure, fix/refactor test for modification detection on decryption
Also, address race condition in error handling as part of AEAD message decryption,
which would cause non-uniform errors during testing.
2023-10-25 12:53:12 +02:00
Daniel Huigens
0e08abb3e2 When decrypting a v6 PKESK in constant-time, use the v2 SEIPD algorithm
Rather than using the config to determine which algorithms to try
to decrypt session keys for, try the algorithm we know the message
was encrypted with.
2023-10-25 12:53:12 +02:00
Daniel Huigens
7e382e6e43 Add support for PKESK v6
Also, set version in PKESK constructor to null,
requiring to explicitly set all fields.

Co-authored-by: Lukas Burkhalter <lukas.burkhalter@proton.ch>
2023-10-25 12:53:12 +02:00
Daniel Huigens
f77ed0c0ed Look up preferred ciphersuite in one go
Instead of calling getPreferredAlgo('symmetric') and
getPreferredAlgo('aead'), we define and call getPreferredCipherSuite()
to determine the preferred symmetric and AEAD algorithm.

Additionally, we remove isAEADSupported(), instead we return
aeadAlgorithm: undefined from getPreferredCipherSuite() if AEAD is not
supported (CFB is used instead).

And finally, we define getPreferredCompressionAlgo() to replace
getPreferredAlgo('compression').
2023-10-25 12:53:12 +02:00
Daniel Huigens
e5fe84dc2e Support SKESK v6 as per the latest crypto refresh
The latest crypto refresh specifies an HKDF step to be used for
deriving the key to encrypt the session key with.

It also specifies two additional length fields.
2023-10-25 12:53:12 +02:00
Daniel Huigens
6ae87b9208 Implement Padding Packet 2023-10-25 12:53:12 +02:00
Daniel Huigens
9d85938ed7 Implement SEIPD v2 2023-10-25 12:53:12 +02:00
Daniel Huigens
939622e827 Remove armor checksum check
The crypto refresh says that we MUST NOT reject messages where the
CRC24 checksum is incorrect. So, we remove the check for it.

Also, remove the checksumRequired config.
2023-10-25 12:53:12 +02:00