-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix SSH certificate fingerprint encoding #207
Conversation
Before this commit, the fingerprint for an SSH certificate would include the bytes that encode the certificate. An SSH fingerprint should only be based on its public key. This commit checks if the SSH key is actually an SSH certificate and will fingerprint just the SSH certificate public key instead of the entire certificate contents.
Example cert: $ step ssh inspect example-cert.pub
example-cert.pub:
Type: [email protected] user certificate
Public key: ECDSA-CERT SHA256:RvkDPGwl/G9d7LUFm1kmWhvOD9I/moPq4yxcb0STwr0
Signing CA: ECDSA SHA256:AXEctpST7/1MfakrLrE+xrtF8Eixh6YsmqNaxiN6AFI (using ecdsa-sha2-nistp256)
Key ID: "herman"
Serial: 14376510.... Fingerprint before patching: $ step ssh fingerprint example-cert.pub
256 SHA256:YuV7pyvW7Jp4iEwddOsMw+EdugrhKGqOKh6o+PP0xeg herman (ECDSA-CERT) After patching: $ step ssh fingerprint example-cert.pub
256 SHA256:RvkDPGwl/G9d7LUFm1kmWhvOD9I/moPq4yxcb0STwr0 herman (ECDSA-CERT) Output for SSH agent: $ ssh-add -l
256 SHA256:RvkDPGwl/G9d7LUFm1kmWhvOD9I/moPq4yxcb0STwr0 herman (ECDSA)
256 SHA256:RvkDPGwl/G9d7LUFm1kmWhvOD9I/moPq4yxcb0STwr0 herman (ECDSA-CERT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this.
For X.509 certificates we differentiate the fingerprint of a certificate than the fingerprint of the key. And getting the fingerprint of the key is as easy as inspecting the certificate.
SSH does shows the fingerprint of the key on both ssh-add -l
or ssh-keygen -l -f foo-cert.pub
.
My patched logic returns the same result as I could change it to only do this logic for The output of I'm aware there's different logic for fingerprinting public keys vs. certificates for X.509, but I don't think that outweighs the fact that other tools seem to generate the fingerprint always for the public key from an SSH certificate, instead of over the entire certificate contents. If there's a use for a fingerprint over the entire certificate, I think that can be done with an additional flag. In my opinion it shouldn't be the default for the reasons mentioned above. |
@hslatman, Are you going to create a new method to get the fingerprint for the certificate instead of the key as part of this PR? And yes, there are uses for looking for a certificate fingerprint. It is the only way to differentiate two certificates that share the same key. So that it can be used for indexing. |
Yes, will add it to this PR. Will be a new function, so that we don't need to change the signature of the current one, as you suggested. What do you think would be a good name for the flag (which will go in a PR for the CLI)? Something like |
Probably |
The `FormatCertificateFingerprint` allows fingerprints for SSH certificates to be calculated. As opposed to the `FormatFingerprint` function, the new function will always include all certificate bytes as opposed to just the marshaled public key when calculating the fingerprint. The default behavior for `FormatFingerprint` now behaves like other systems, such as `ssh-add -l`.
With the changes from smallstep/crypto#207, the default behavior of `step ssh fingerprint` changes to be like the behavior of `ssh-add` (and similar tools). When a fingerprint is determined for an SSH certificate, the fingerprint will only include the bytes of the public key. With the `--certificate` flag, a user can create a fingerprint for the entire SSH certificate contents.
Before the change the fingerprint for an SSH certificate would
include the bytes that encode the certificate. An SSH fingerprint
should only be based on its public key.
This commit checks if the SSH key is actually an SSH certificate
and will fingerprint just the SSH certificate public key instead
of the entire certificate contents.