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

Prevent signature malleability #1839

Merged
merged 5 commits into from
Nov 21, 2023
Merged

Prevent signature malleability #1839

merged 5 commits into from
Nov 21, 2023

Conversation

dholms
Copy link
Collaborator

@dholms dholms commented Nov 9, 2023

We want a canonical representation for every signature. Otherwise a commit or a plc operation can be deterministically transformed such that it has a different CID (without possession of the private key).

The crypto library that we use allows signatures to be encoded as compact bytes or DER-encoded.

This leads to similar consequences as allowing high-s signatures (which we disallow for repo commits & plc operations).

As a fix, we alter the signature verification logic to first parse the signature from compact bytes before passing to the verify function.

In some cases where distributed consensus is not necessary, such as JWT signatures, we allow DER signatures as well as high-s signatures.


Reference:
did-method-plc/did-method-plc#53
paulmillr/noble-curves#99

@DavidBuchanan314
Copy link
Contributor

DavidBuchanan314 commented Nov 9, 2023

btw I think you also still have malleability due to =-padding. Example: https://plc.directory/did:plc:m4aa5oy4t7rk5m6uthcg2dwy/log/audit

@dholms
Copy link
Collaborator Author

dholms commented Nov 9, 2023

Yup this library works with just bytes, so I'll need to fix that over in PLC.

Thanks for the reports on both of these!

Copy link
Collaborator

@bnewbold bnewbold left a comment

Choose a reason for hiding this comment

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

oof, another curve-ball.

I think there needs to be tests in here with otherwise-valid, DER-encoded signatures for both of the curve types, to confirm that this actually disallows that format as expected. The existing tests presumably cover the happy path. I feel like we've been bitten too many times with "fixed for one curve type, but not the other".

It would be most helpful to add them to the "invalid" DER-encoded examples to interop-test-files/crypto/signature-fixtures.json.

Copy link
Collaborator

@bnewbold bnewbold left a comment

Choose a reason for hiding this comment

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

yay, thanks for adding test fixtures!

I tried these new fixtures against golang and they were already rejected (that is, golang impl already correctly rejected DER-encoded signatures). I won't commit those golang changes until this PR gets merged.

@dholms dholms merged commit e1b5f25 into main Nov 21, 2023
10 checks passed
@dholms dholms deleted the prevent-signature-malleability branch November 21, 2023 21:30
@github-actions github-actions bot mentioned this pull request Nov 21, 2023
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.

3 participants