Commit graph

2624 commits

Author SHA1 Message Date
larabr
b7fc9a76cb
TS: emit type declarations for .ts files with external exports, and publish them under dist/types
This change makes it possible to easily expose types from internal .ts files.
This is achieved by adding a TS compilation step which generates .d.ts files from
.ts ones.
Additionally, a copying step is needed for existing .d.ts files, which are not
automatically moved to the outDir by tsc.
The dist types will still only include those exported by the index files.

Other tried approaches (to e.g. avoid the manual copying step) that were not viable:
- generating a single .d.ts bundle is not supported by tsc, and other tools/plugins
  are either deprecated or (in the case of `rollup-plugin-dts`) failed to process our
  source code due to unsupported JS syntax
- relying on the `rollup-typescript` plugin to emit declarations felt overly messy
  to configure and potentially unreliable as it generated declarations for .js files as well
- renaming existing .d.ts to .ts (alongside .js ones) is not an option since it results
in an empty output for the corresponding modules on Rollup compilation, as the .js
source files are ignored.
2025-09-02 15:32:31 +02:00
larabr
e4c754f144
TS: declare Uint8Array<ArrayBuffer> over generic Uint8Array (#20)
And add lint TS rule to enforce declaring `Uint8Array<ArrayBuffer>`.

This change is to limit the need to downcast Uint8Array in output
when using them with e.g. WebCrypto and Blobs,
following an incompatible interface change between ArrayBuffer
and ArrayBufferLike (enforced in TS v5.9).
2025-09-02 15:32:31 +02:00
larabr
2fe1dedefd
Temporary workaround for Babel issue affecting web-app tests
The Babel plugin `@babel/plugin-transform-regenerator` used in the web-app Jest tests
(as part of @babel/preset-env) introduces a bug when transforming this specific minified
lightweight built.
The issue is that the mangled `ArrayStream` class name (`n` in the specific case) gets wrongly
reused and shadowed by a local variable in the `readPacket` function.
As a workaround for the problem, and to not have to amend the babel config for each monorepo workspace,
we disable mangling the specific class name.
2025-09-02 15:32:31 +02:00
larabr
2e0f652e85
PQC: implement ML-KEM and ML-DSA from RFC draft-10 (past last call)
See MRs #10, #13, #19 for the incremental changes .

Reference: https://datatracker.ietf.org/doc/draft-ietf-openpgp-pqc/10/ .

Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
2025-09-02 15:32:30 +02:00
larabr
09263d1a4a
Temporarily add config.ignoreSEIPDv2FeatureFlag for compatibility (#15)
SEIPDv2 is a more secure and faster choice, but it is
not necessarily compatible with other libs and our mobile apps.

Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
2025-09-02 15:32:30 +02:00
larabr
412f81a18b
Only add SHA3 preferences to v6 keys
To ensure compatibility with older mobile clients, which may not
support verifying SHA3 message signatures
2025-09-02 15:32:30 +02:00
larabr
55b8b4793c
Add Argon2S2K.reloadWasmModule() for manually triggering memory deallocation (#14)
Also, make `ARGON2_WASM_MEMORY_THRESHOLD_RELOAD`
a static class property, to be able to change its value.
2025-09-02 15:32:30 +02:00
larabr
ea4ba58208
Export Argon2S2K to reuse the WASM module outside of the OpenPGP.js context (#12) 2025-09-02 15:32:30 +02:00
larabr
7d7d75ce06
Support generating subkeys with 'forwarded communication' flag to decrypt autoforwarded messages (#8)
These subkeys must not have the standard encryption flags (EtEr) set,
as they are not supposed to be used for direct messages.

Also:
- preserve 'forwarded communication' key flag when reformatting
- fix bug allowing to decrypt forwarded messages by setting
`config.allowInsecureDecryptionWithSigningKeys` instead of
`config.allowForwardedMessages`
- add TS definition for `config.allowForwardedMessages`
2025-09-02 15:32:30 +02:00
larabr
10de67ce07
Update support for decrypting autoforwarded messages (#6)
Update implementation to reflect spec changes to KDF params (v2 -> v255) and
new forwarding-related key flag (0x40).
2025-09-02 15:32:30 +02:00
Dan Ristea
26adbb8ec2
Add symmetric encryption and MAC support
To enable stored messages to be protected using symmetric key encryption and validated
using message authentication codes, this set of changes adds support for storing
symmetric key material as Secret Key Packets, symmetric key encrypted session keys as
Public Key Encrypted Session Key Packets, and MAC tags as Signature Packets.

Co-authored-by: Konstantinos Andrikopoulos <kandrikopoulos@proton.ch>
Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
2025-09-02 15:32:29 +02:00
larabr
2dfe0db0f7
Add support for decrypting autoforwarded messages (#1) 2025-09-02 15:32:29 +02:00
Daniel Huigens
e9928be294
Update package.json name and url 2025-09-02 15:32:26 +02:00
larabr
6f9584d13f
6.2.2 2025-09-02 14:45:07 +02:00
larabr
93d9df7724
Fix zlib compression for data larger than 65KB (#1894)
Regression introduced in https://github.com/openpgpjs/openpgpjs/pull/1826
(v6.2.0) .
Due to internal fflate lib changes, part of the compressed data ended up being discarded,
leading to a corrupted compressed payload for the encrypted/signed message,
which cannot be decompressed.

Compression is disabled by default in openpgpjs.
Hence, the issue affects only users who enabled zlib compression via e.g.
`config.preferredCompressionAlgorithm = openpgp.enums.compression.zlib`
and encrypted or signed data larger than 65KB.
2025-09-02 14:40:35 +02:00
larabr
30ce607245
6.2.1 2025-08-26 14:44:09 +02:00
larabr
2138b80cba
Merge pull request #1886
Bump dev dependencies to latest versions, and fix TS test setup
2025-08-25 17:09:13 +02:00
larabr
c5f9ecf3e4
Tests: TS: add back missing type checking
tsx does not run any type checking, hence a separate
tsc step is needed .

Also, fix resulting type issue caused by external lib types.
2025-08-25 15:59:50 +02:00
larabr
5027bcd0eb
Tests: TS: temporarily lock @types/node version to v22
v24 brings breaking changes that will be fixed in the next
minor openpgpjs release
2025-08-25 15:49:24 +02:00
larabr
bcdb59729c
Run npm update
Including npm audit
2025-08-25 15:47:46 +02:00
dependabot[bot]
0a92baf8ba
Tests: bump playwright from 1.54.1 to 1.55.0 (#1883)
Bumps [playwright](https://github.com/microsoft/playwright) from 1.54.1 to 1.55.0.
- [Release notes](https://github.com/microsoft/playwright/releases)
- [Commits](https://github.com/microsoft/playwright/compare/v1.54.1...v1.55.0)

---
updated-dependencies:
- dependency-name: playwright
  dependency-version: 1.55.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-21 11:38:50 +02:00
dependabot[bot]
449ba5bc7a
Build(deps-dev): bump @noble/curves from 1.9.5 to 1.9.6 (#1880)
Bumps the noble group with 1 update: [@noble/curves](https://github.com/paulmillr/noble-curves).


Updates `@noble/curves` from 1.9.5 to 1.9.6
- [Release notes](https://github.com/paulmillr/noble-curves/releases)
- [Commits](https://github.com/paulmillr/noble-curves/compare/1.9.5...1.9.6)

---
updated-dependencies:
- dependency-name: "@noble/curves"
  dependency-version: 1.9.6
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: noble
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-06 14:39:30 +02:00
larabr
ddbd0d72f9
Merge pull request #1873 2025-07-31 19:19:10 +02:00
larabr
c1ea7ca464
Tests: update ECDH negative test expectations to match WebKit Windows behavior
AES-KW unwrapping failure does not throw an OperationError there,
instead it returns an empty buffer, which then fails to be PKCS5 decoded.
2025-07-31 19:09:59 +02:00
larabr
faeceec49e
CI: set fail-on-cache-miss for cached build folders 2025-07-31 19:09:59 +02:00
larabr
0f586241e8
CI: run browser tests also on Windows 2025-07-31 19:09:59 +02:00
larabr
6b1da73b97
Merge pull request #1875 2025-07-31 19:08:40 +02:00
larabr
e05ca9e2d2
Internal: switch away from deprecated noble-curve util.randomPrivateKey 2025-07-31 19:07:57 +02:00
dependabot[bot]
29cdf978c4
Build(deps-dev): bump @noble/curves from 1.9.2 to 1.9.5
Bumps the noble group with 1 update: [@noble/curves](https://github.com/paulmillr/noble-curves).

Updates `@noble/curves` from 1.9.2 to 1.9.5
- [Release notes](https://github.com/paulmillr/noble-curves/releases)
- [Commits](https://github.com/paulmillr/noble-curves/compare/1.9.2...1.9.5)

---
updated-dependencies:
- dependency-name: "@noble/curves"
  dependency-version: 1.9.5
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: noble
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-31 19:07:57 +02:00
larabr
659e3dbbd0
Merge pull request #1877 2025-07-31 18:05:14 +02:00
larabr
ed5554e114
Lightweight build: lazy load tweetnacl dependency module (curve25519 JS fallback)
Since all major browsers have shipped support for the curve
in WebCrypto, we only load the JS fallback if needed.

Also, add native/non-native ECDH test for Curve25519Legacy.
(The more modern X25519/X448 algo implementations cannot be
tested that way since they include an HKDF step for which
we assume native support and do not implement a fallback.)
2025-07-31 17:42:37 +02:00
larabr
721b918296
Key validation: use WebCrypto API when available for curve25519
For Ed25519/Ed25519Legacy native validation code does a sign-verify check over random data.
This is faster than re-deriving the public point using tweetnacl.
If the native implementation is not available, we fall back to re-deriving
the public point only.

For X25519/Curve25519Legacy, both the native and fallback flows do an ecdh exchange;
in the fallback case, this results in slower performance compared to the existing check,
but encryption subkeys are hardly ever validated directly (only in case of gnu-dummy keys),
and this solution keeps the code simpler.

Separately, all validation tests have been updated to use valid params from a different
key, rather than corrupted parameters.
2025-07-28 15:13:54 +02:00
larabr
4054ff0543
README: add section about how to update to the latest version and deprecation policy (#1876) [skip ci]
Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
2025-07-25 14:47:36 +02:00
larabr
c30404c143
6.2.0 2025-07-17 18:14:15 +02:00
dependabot[bot]
732f3c88b2
Tests: bump playwright from 1.53.0 to 1.54.1 (#1872)
Bumps [playwright](https://github.com/microsoft/playwright) from 1.53.0 to 1.54.1.
- [Release notes](https://github.com/microsoft/playwright/releases)
- [Commits](https://github.com/microsoft/playwright/compare/v1.53.0...v1.54.1)

---
updated-dependencies:
- dependency-name: playwright
  dependency-version: 1.54.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-14 10:47:42 +02:00
larabr
24f776a9af
Merge pull request #1870
Add workarounds for WebCrypto X25519 bugs on WebKit Linux

At least some of the errors were found to also affect Epiphany ,
not just the playwright built , unlike previously reported (4762d2c) .
2025-07-14 10:45:25 +02:00
larabr
9703ab891e
Add workaround for WebCrypto X25519 key generation bug on WebKit Linux
Similar/same issue was already patched for Ed25519 .

https://bugs.webkit.org/show_bug.cgi?id=279113
2025-07-10 21:22:20 +02:00
larabr
b9275642e1
Add workaround for WebCrypto X25519 key export bug on WebKit Linux
https://bugs.webkit.org/show_bug.cgi?id=289693
2025-07-10 21:21:15 +02:00
larabr
d155da23dd
Revert "CI: do not test Webkit on Linux"
This reverts commit 4762d2c762.
2025-07-09 16:00:08 +02:00
dependabot[bot]
448418a6f5
Bump @noble/curves from 1.9.0 to 1.9.2 in the noble group (#1855)
Bumps the noble group with 1 update: [@noble/curves](https://github.com/paulmillr/noble-curves).


Updates `@noble/curves` from 1.9.0 to 1.9.2
- [Release notes](https://github.com/paulmillr/noble-curves/releases)
- [Commits](https://github.com/paulmillr/noble-curves/compare/1.9.0...1.9.2)

---
updated-dependencies:
- dependency-name: "@noble/curves"
  dependency-version: 1.9.2
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: noble
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-17 16:58:58 +02:00
larabr
208402ebcb
Merge pull request #1850
Bump dev dependencies to latest versions
2025-06-17 15:54:00 +02:00
larabr
232da14940 Tests: revert update to chai v5
Chai v5 broke support for Safari below v16.4;
we delay the update for now, waiting for their fix.
2025-06-13 16:46:40 +02:00
larabr
cabc91c42c Bump dev dependencies to latest versions
Only one breaking change with `@rollup/plugin-typescript`,
that enforced a check on the `outDir` location.
2025-06-13 16:38:12 +02:00
larabr
a51249a964 Run npm update
as well as npm audit.
2025-06-13 16:37:41 +02:00
Daniel Huigens
fe58fe9ac0
Improve packet stream & error handling (#1856)
Refactor & simplify the handling of the packet stream and errors in
packet parsing & grammar validation.

This PR also makes the following observable changes:

- Packet parsing errors in not-yet-authenticated streams (i.e. SEIPDv1
  with `allowUnauthenticatedStream: true`) get delayed until the
  decrypted data stream is authenticated (i.e. the MDC has been
  validated)
- Non-critical unknown packets get turned into `UnparseablePacket`
  objects on the packet stream instead of being ignored
- The grammar validation internals are changed to a state machine where
  each input packet is only checked once, for efficiency (before, the
  entire partial packet sequence was checked for every packet)

Co-authored-by: larabr <larabr+github@protonmail.com>
2025-06-12 15:49:31 +02:00
martgil
66baa5f57b
Simplify User ID parsing (#1862) 2025-06-12 12:27:42 +02:00
dependabot[bot]
b31bc89854
Tests: bump playwright from 1.52.0 to 1.53.0 (#1861)
Bumps [playwright](https://github.com/microsoft/playwright) from 1.52.0 to 1.53.0.
- [Release notes](https://github.com/microsoft/playwright/releases)
- [Commits](https://github.com/microsoft/playwright/compare/v1.52.0...v1.53.0)

---
updated-dependencies:
- dependency-name: playwright
  dependency-version: 1.53.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-11 16:32:54 +02:00
Kevin Kredit
38c56f84c2
Improve type definition for the User class (#1857) 2025-05-28 20:55:16 +02:00
larabr
88cd1810a3 Implement OpenPGP message grammar validation (add config.enforceGrammar)
It enforces a message structure as defined in
https://www.rfc-editor.org/rfc/rfc9580.html#section-10.3
(but slightly more permissive with Padding packets allowed in all cases).
Since we are unclear on whether this change might
impact handling of some messages in the wild, generated by
odd use-cases or non-conformant implementations, we
also add the option to disable the grammar check via
`config.enforceGrammar`.

GrammarErrors are only sensitive in the context of
unauthenticated decrypted streams.
2025-05-20 14:17:13 +02:00
larabr
4c4ebe4a76 Internal: move config TS declaration to standalone file
To access the types in internally
2025-05-20 14:17:13 +02:00