Skip to content

EC signature padding#91

Merged
adferrand merged 1 commit intocertbot:masterfrom
commonism:unhexlify
Mar 14, 2021
Merged

EC signature padding#91
adferrand merged 1 commit intocertbot:masterfrom
commonism:unhexlify

Conversation

@commonism
Copy link
Contributor

@commonism commonism commented Feb 27, 2021

The r||s encoding is wrong for ec keys and signatures with leading zeros.
This results in bad signatures, I've come across:

"Parse error reading JWS: EC public key has incorrect padding"
"failed to unmarshal JWK: square/go-jose: invalid EC public key, wrong length"

Leading zero happens very frequently for ES512, rare with ES256.

This was already wrong in my proposal for r||s and just got ported to using cryptography api.

int.to_bytes requires python >= 3.2
bytes.fromhex python >= 3.0
so they are safe to use here.

@commonism commonism force-pushed the unhexlify branch 3 times, most recently from 2ad3e3f to 5b147c8 Compare February 28, 2021 11:07
@commonism
Copy link
Contributor Author

Had some issues with the CI, force pushed to keep things tidy.

 - it works often for P256 & P384, fails often for P521
@bmw
Copy link
Member

bmw commented Mar 10, 2021

@atombrella or @adferrand, do either of you have the time and interest to take a look at this since you reviewed #51?

@bmw bmw self-assigned this Mar 10, 2021
@adferrand
Copy link
Collaborator

For sure I will review it in the next days. I already looked at it quickly this week and it seemed good.

@bmw
Copy link
Member

bmw commented Mar 10, 2021

Thanks Adrien!

I'm assigning you for now but if you end up not being able to get to it for whatever reason, just let me know.

@bmw bmw assigned adferrand and unassigned bmw Mar 10, 2021
Copy link
Collaborator

@adferrand adferrand left a comment

Choose a reason for hiding this comment

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

Thanks a lot @commonism, this LGTM. I appreciate in particular the updated test cases that will catch this error if future developments would break again when leading zeros are involved, since this is something quite hard to catch without unit tests.

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