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

ssh-key: add partial support for U2F signatures verification #44

Merged
merged 1 commit into from
Dec 1, 2022

Conversation

a-dma
Copy link
Contributor

@a-dma a-dma commented Oct 31, 2022

Hi,

I saw the recent release of v0.5 that added support for SSH signatures, and noticed that U2F/sk signatures were still missing.

I did some preliminary work to implement verification of ed25519-sk signatures. This is almost in a mergeable state, there's a few outstanding items and before doing too much I thought I'd check in with you.

Here's a short recap:

  • only verification is supported as signature generation would require interaction with hardware devices which is a lot more work;
  • only sk-ed25519 is currently implemented, p256 is TBD;
  • I made a few design choices about where to store the various components of the signature, I'm not super familiar with the project so if you have objections on how some of the things are implemented, I'm happy to change stuff around. Generally, feel free to change things yourself if you want. Mostly I tried to keep everything inside the Sshsig layer, but it could make sense to have a dedicated one for this format as those signature are a sort of wrapper around regular SSH signatures;
  • one of the tests (encoding the signature from raw bytes) currently fails. I am not entirely sure what is the best abstraction to hook into. The Signature decoding mechanism expects length-prefixed data, but sk signatures have 5 trailing bytes that are just added at the end. They are part of the signed data. Is there a good way to read those? Alternatively they could be removed from the test data given that they're not included in the length.

As mentioned before, I can (time permitting) incorporate comments that you may have, or I'm perfectly fine if you'd like to take it from here and hit this into shape.

Bye
A.

@tarcieri
Copy link
Member

This is definitely something we'd like to add. See also #4, where I had discussed with @obelisk about merging some similar code from the sshcerts crate (including signing support).

Just a general thought having looked through the code: this implementation is putting a lot of code in SshSig which should probably go in the lower-level Signature type, especially the modifications to the SignedData struct.

Putting the implementation in Signature rather than SshSig permits more use cases, like signing low-level SSH protocol messages (e.g. for SSH authentication).

Also it'd be good to avoid breaking changes to public APIs for now, like the one made to SshSig::signed_data.

@a-dma a-dma force-pushed the u2f_signatures branch 2 times, most recently from 7828287 to 1cb17e4 Compare November 1, 2022 16:27
@a-dma
Copy link
Contributor Author

a-dma commented Nov 1, 2022

Hi,

thanks for the reply. I have made a few changes and moved most of the additions into the Signature layer. In my opinion it is slightly harder to figure out what's going on, but perhaps that's not something that the user should be concerned with. The public interface should be unchanged at this point.

I've also added tests for SshSig and all tests pass now.

@tarcieri
Copy link
Member

tarcieri commented Nov 4, 2022

It looks like there are redundant imports when the crate is built with --all-features

use crate::{private::Ed25519Keypair, public::Ed25519PublicKey};
use {
crate::{private::Ed25519Keypair, public::Ed25519PublicKey},
sha2::{Digest, Sha256},
Copy link
Member

Choose a reason for hiding this comment

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

You need to consolidate these imports with the ones for the rsa crate.

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 noticed the lints but haven't had the time to fix them. I have pushed a new commit now.

All checks seem to pass now.

@tarcieri
Copy link
Member

@a-dma can you rebase? I think #48 should "fix" the build failure (which seems to be a rustc OOM)

@a-dma
Copy link
Contributor Author

a-dma commented Nov 13, 2022

@tarcieri done.

@tarcieri tarcieri changed the title WIP: ssh-key: add partial support for U2F signatures verification ssh-key: add partial support for U2F signatures verification Nov 16, 2022
@tarcieri
Copy link
Member

@a-dma looks like the build is failing. In one case, it's with the alloc feature enabled but nothing else

Initial work to add support for verifying `sk-ssh-ed25519` signatures.
@a-dma
Copy link
Contributor Author

a-dma commented Nov 16, 2022

Interesting, I couldn't see those failures before, did you allow more checks?

It looks like the issue is KeyData::is_sk_ecdsa_p256() being defined only when the ecdsa feature is enabled. I've split the check that uses it to also depend on that feature. I hope that's an acceptable solution.

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks!

@tarcieri tarcieri merged commit bc0c3d0 into RustCrypto:master Dec 1, 2022
@tarcieri tarcieri mentioned this pull request Aug 13, 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.

2 participants