Skip to content

Conversation

twiss
Copy link
Member

@twiss twiss commented May 20, 2025

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 (before, the entire partial packet sequence was checked every time)

twiss added 7 commits May 20, 2025 14:18
Instead of ignoring non-critical unknown packets entirely, write an
UnparseablePacket object to the packet stream.
Instead of signalling that grammar checking should be delayed for
not-yet-authenticated streams on the grammar validator, signal that
the stream is not yet authenticated on the stream object.
@twiss twiss force-pushed the refactor-packet-stream-error-handling branch from a629f83 to 730ef27 Compare May 20, 2025 12:36
@twiss twiss requested a review from larabr May 22, 2025 09:49
*/
export async function readPackets(input, callback) {
const reader = streamGetReader(input);
export async function readPacket(reader, useStreamType, callback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify this further and have it return { tag, packet } instead of taking a callback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because we need to call the callback earlier than returning when streaming. The callback happens when we've parsed the packet header; the function returns when the whole packet has been read.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok; I think it should be possible to return the header and some stream/promises for the rest tho. I'd like to look into this for the next major 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that could work 👍

@twiss twiss force-pushed the refactor-packet-stream-error-handling branch from 63ff85c to 6d375a2 Compare May 23, 2025 11:28
@twiss twiss requested a review from larabr May 23, 2025 11:44
@twiss twiss force-pushed the refactor-packet-stream-error-handling branch 2 times, most recently from 5641132 to 8f30bb1 Compare May 26, 2025 08:41
Instead of checking the list of packets for every new packet, check the
new packet given the state we've recorded from the previous packets.
@twiss twiss force-pushed the refactor-packet-stream-error-handling branch from 8f30bb1 to d94d9d4 Compare May 26, 2025 12:39
twiss and others added 2 commits May 26, 2025 15:24
To make the grammar checker less of a breaking change in v6.
This should be reverted in v7.
Some invalid sequences were not detected after refactor
@twiss twiss force-pushed the refactor-packet-stream-error-handling branch from baf3116 to e584eb7 Compare June 6, 2025 11:13
@twiss twiss force-pushed the refactor-packet-stream-error-handling branch from e584eb7 to 1aedcbe Compare June 6, 2025 11:27
@twiss twiss merged commit fe58fe9 into openpgpjs:main Jun 12, 2025
13 checks passed
@twiss twiss deleted the refactor-packet-stream-error-handling branch June 12, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants