Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leave unhashed subpackets as-is when re-serializing signatures #1561

Merged
merged 3 commits into from
Aug 30, 2022

Conversation

wussler
Copy link
Contributor

@wussler wussler commented Aug 26, 2022

When an embedded signature is already present in the hashed part it will be serialized twice when exporting an already signed public key.

@wussler wussler force-pushed the fix-serialization-embedded-sig branch from 17dd14b to 4fadec5 Compare August 26, 2022 11:39
@twiss
Copy link
Member

twiss commented Aug 26, 2022

Hey 👋 Thanks for the PR, but this fix is a bit too specific / hacky, in my opinion. Instead, we should create the unhashed subpackets during signing, and just serialize them as they were during serialization. To achieve that, you could split the writeUnhashedSubPackets function into createUnhashedSubPackets and writeUnhashedSubPackets, and in the latter just write them out, and then in sign set this.unhashedSubpackets = this.createUnhashedSubPackets(). You'd also have to change the calls to writeSubPacket and only write the type and body instead.

@wussler
Copy link
Contributor Author

wussler commented Aug 26, 2022

Sure, I'll split the packet serialization. The original intention was to keep the PR minimal, but I understand that it looks too specific indeed.

@wussler wussler force-pushed the fix-serialization-embedded-sig branch 3 times, most recently from 320a496 to 13873c4 Compare August 26, 2022 13:43
@wussler wussler force-pushed the fix-serialization-embedded-sig branch from 13873c4 to ab07ffd Compare August 26, 2022 13:59
Comment on lines 377 to 381
if (!allowedUnhashedSubpackets.has(type)) {
this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
return;
}
this.allowedUnhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
Copy link
Member

Choose a reason for hiding this comment

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

Tbh, I would just change the condition and store all of them in unhashedSubpackets. There's nothing saying that those are only the disallowed ones, it's just that for the others there was no reason (until now) to store them there. It's technically a small breaking change, but imo we change it in a minor release.

Suggested change
if (!allowedUnhashedSubpackets.has(type)) {
this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
return;
}
this.allowedUnhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
if (!allowedUnhashedSubpackets.has(type)) {
return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this approach, but it doesn't work, because when we overwrite the allowedUnhashedSubpackets we do not intend to rewrite all the unhashedSubpackets, but just the one the implementation understands (i.e. the allowed ones).

In other words, there might be some packet in the unhashed section that we do not want to overwrite when re-signing, therefore we need to store them separately or flag them as "to be overwritten" or "not to be overwritten" on re-sign.

Copy link
Member

Choose a reason for hiding this comment

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

OK, but.. do we rely on preserving unhashed subpackets when re-signing somewhere?
Re-signing in general isn't really something that's often done in OpenPGP.js; we leave the signatures alone by default (unlike go-crypto).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we had dozens of tests failing by not preserving the unhashed subpackets. I didn't inspect most of them, since I'm not very familiar with the codebase, but it seemed to be a pretty rooted assumption.

@twiss twiss changed the title Serialize correctly embedded signatures Leave unhashed subpackets as-is when re-serializing signatures Aug 30, 2022
@twiss twiss merged commit 000e133 into openpgpjs:main Aug 30, 2022
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.

None yet

2 participants