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

Handle verification of keys using elliptic curve #132

Merged
merged 2 commits into from
Mar 4, 2022

Conversation

flavio
Copy link
Contributor

@flavio flavio commented Mar 1, 2022

This PR introduces support for handling certificates using elliptic curve public keys.

Only signature verification is currently implemented.
Update: Both signature creation and verification are supported.

The implementation relies on the ring crate, which currently is the only one capable of supporting both ECDSA p256 and ECDSA p384.

I haven't yet extended the unit tests. I'm looking forward to hear your feedback about this contribution. I think this is something you're interested about (see #100). I wonder if this is going in the direction you like.
Update: The unit tests have been extended too

@CBenoit
Copy link
Member

CBenoit commented Mar 1, 2022

Thank you very much 🎉

I haven't yet extended the unit tests. I'm looking forward to hear your feedback about this contribution. I think this is something you're interested about (see #100). I wonder if this is going in the direction you like.

This is going in the right direction! However, I wanted to use RustCrypto's crates to stay purely Rust only.
I think both ECDSA p256 and ECDSA p384 are supported:

Would that be acceptable on you side? (p384 crate might not be mature enough?)

I read the issue on sigstore-rs. Glad to see picky have been considered as a possible candidate for what you’re trying to do despite the limited popularity. I understand if you wish to switch to webpki in the future. In the meantime, I'll be happy to help and merge PR for functionalities you might need. 🙂

@flavio
Copy link
Contributor Author

flavio commented Mar 1, 2022

This is going in the right direction! However, I wanted to use RustCrypto's crates to stay purely Rust only. I think both ECDSA p256 and ECDSA p384 are supported:

I kinda imagined that :) I started to use ecdsa + p256 + p384 crates but then I realized the p384 crate isn't mature enough. It cannot be used yet, because some traits required by the ecdsa structs are not implemented yet. This is tracked inside of this issue: RustCrypto/elliptic-curves#240

If you want, I have another branch that builds on top of ring-compat. This however would bring ring as a dependency. Plus, the code using ring-compat looks a bit uglier compared to the one inside of this PR. That's because it's harder to abstract it.

I know ring is not written in pure Rust, but at least is not relying on openssl or some other library :)

Right now I need p384 support, because this what Fulcio (a project part of sigstore) uses.

If you are really against using ring, I could build EC P256 support on top of ecdsa + p256. While EC P384 could be hidden behind a feature flag, and be implemented via either ring or ring-compat. To be honest, this would be a bit painful and the final code would probably look uglier, but this could be a temporary solution until p384 matures.

What do you think?

@thenextman
Copy link
Member

Hello @flavio; I resolved an issue in the CI that prevented checks from running on your branch. If you rebase on master the build should now run (tests are failing but I see from your OP that you haven't touched that side yet). Thank you for your contribution.

@CBenoit
Copy link
Member

CBenoit commented Mar 1, 2022

If you want, I have another branch that builds on top of ring-compat. This however would bring ring as a dependency. Plus, the code using ring-compat looks a bit uglier compared to the one inside of this PR. That's because it's harder to abstract it.

I know ring is not written in pure Rust, but at least is not relying on openssl or some other library :)

If you are really against using ring, I could build EC P256 support on top of ecdsa + p256. While EC P384 could be hidden behind a feature flag, and be implemented via either ring or ring-compat. To be honest, this would be a bit painful and the final code would probably look uglier, but this could be a temporary solution until p384 matures.

Thank you for the insight! I think it's good to use ring at least until p384 crate has arithmetic implemented. I agree, it's not worth to use ring-compat in our case either, we don't even rely that much on their traits in the first place.

@flavio
Copy link
Contributor Author

flavio commented Mar 2, 2022

Thank you for the insight! I think it's good to use ring at least until p384 crate has arithmetic implemented. I agree, it's not worth to use ring-compat in our case either, we don't even rely that much on their traits in the first place

Thanks, I'll go ahead with this PR and look into the unit tests

This commit introduces support for handling certificates using elliptic
curve public keys.

The implementation relies on the `ring` crate, which currently is the
only one capable of supporting both ECDSA p256 and ECDSA p384.

Signed-off-by: Flavio Castelli <[email protected]>
@flavio
Copy link
Contributor Author

flavio commented Mar 3, 2022

@thenextman, @CBenoit: I've forcefully pushed. The code now handles both signature creation and verification using ECDSA keys. The unit tests have been extended too, I hope you won't mind the new rstest dependency, I like how it can be used to reduce the boilerplate.

All the unit tests are green on my machine, clippy is happy too.

Some details:

  • The whole implementation relies on ring, as discussed above
  • Signature creation:
    • ECDSA P-256 keys can be used only with sha2 256 hashing algorithm.
    • ECDSA P-384 keys can be used only with sha2 384 hashing algorithm.
    • ECDSA P-512 keys cannot be used to produce signatures. This is a limitation of ring and all the other rust crates.
  • Signature verification:
    • A certificate with a ECDSA P-256 public key assumes the sha2 256 algorithm has been used to produce the signature. This is what the official RFCs recommend (I don't remember the number of the RFC unfortunately, I got lost into the rabbit hole).
    • A certificate with a ECDSA P-384 public key assumes the sha2 384 algorithm has been used to produce the signature. This is what the official RFCs recommend (I don't remember the number of the RFC unfortunately, I got lost into the rabbit hole).
    • Signatures produced with a ECDSA P-512 keys cannot be verified. This is a limitation of ring and all the other rust crates.

Thanks again for your prompt and welcoming responses!

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

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

Very high quality pull request, thank you!
Introduction of rstest is much welcomed. I just didn't know about it yet. :)

CI shows that some code is still failing to compile behind a feature gate. It's not a big deal so I sent a patch directly since you allowed maintainer modifications.

I'll merge and release next version tomorrow 🎉

By the way, next version will be a candidate release, just to see if there is additional breaking changes before committing to picky 7.x. Would it cause any issue on your side?

@CBenoit CBenoit merged commit bbc4fb5 into Devolutions:master Mar 4, 2022
@flavio
Copy link
Contributor Author

flavio commented Mar 4, 2022

CI shows that some code is still failing to compile behind a feature gate. It's not a big deal so I sent a patch directly since you allowed maintainer modifications.

Sorry, I didn't notice that while testing locally. Thanks for having fixed it!

I'll merge and release next version tomorrow 🎉

By the way, next version will be a candidate release, just to see if there is additional breaking changes before committing to picky 7.x. Would it cause any issue on your side?

That's fantastic news 👏
I have no worries about possible API breaking changes, go ahead with them if you need to.

@flavio flavio deleted the ec-sign-verify branch March 4, 2022 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants