How to check if your ssh keys are in the ssh-rsa2 format?

All we need is an easy explanation of the problem, so here it is.

So recently there were news of OpenSSH dropping support for SHA-1 logins and I am trying to understand which format they are referring to. Since years i’ve been generating keys via ssh-keygen -t rsa -b 2048. Is this the type not recommended anymore and I should switch for example, to ECDSA?

In this man page, https://www.man7.org/linux/man-pages/man1/ssh-keygen.1.html , the default option rsa for the -t argument explains that the chosen option is using the SHA1 signature, so one should choose rsa-sha2-256 for example.

I tried checking the type of the key with ssh-keygen -l -f key and it shows me that it is indeed SHA256 type. If so, then it solves my question but some clarity would be welcome. thank you!

Source of news: https://www.zdnet.com/article/openssh-to-deprecate-sha-1-logins-due-to-security-risk/

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

The key format has not changed. The only thing that changes is the signature format that’s sent during each authentication handshake.

What makes everything confusing is that originally in SSHv2, the key type and the signature type used to be defined in combination. (For example, the same "ssh-rsa" identifier was defined to mean RSA keys and RSA/SHA-1 signatures.) So changing the signature process would have meant assigning a new key type identifier, and that would have meant generating a new key…

However, protocol extensions have been developed to avoid this, and modern SSH clients will automatically negotiate the signature types whenever RSA keys are involved. If you connect with ssh -v you will notice a few additional packets being exchanged:

debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,
                            rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,
                            ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>

So you can continue using "ssh-rsa" keys – you only need to upgrade the software on both ends to something reasonably recent, and it will automatically start producing "rsa-sha2-256" signatures from that key. (For example, you might need to install a new version of PuTTY and Pageant, and you might have troubles with older versions of gpg-agent.)

Signatures in ssh-keygen

the default option rsa for the -t argument explains that the chosen option is using the SHA1 signature, so one should choose rsa-sha2-256 for example.

This applies when issuing certificates, but is irrelevant when generating plain keys.

Each certificate is signed by the parent CA at the time it is issued. This long-term signature is stored in the certificate itself (and it’s very important to realize that this is a different thing from the short-term signatures that are made during each connection and then thrown away). That’s why many HTTPS (X.509) certificates had to be replaced – the issuing CA had stamped them with RSA/SHA-1 signatures.

OpenSSH has also created its own certificate format, which is what the manual page is referring to. These so-called "SSH certificates" are not just regular SSH keys – they’re additionaly signed by e.g. your workplace CA. So if you have files whose names end with *-cert.pub, you might need to have those re-issued. (Use ssh-keygen -Lf <file> to check how they were signed).

But plain SSH keys do not hold any long-term signature inside – they’re only used to make temporary signatures during each connection. So there is nothing that needs replacement in the key itself.

The -l option

I tried checking the type of the key with ssh-keygen -l -f key and it shows me that it is indeed SHA256 type

No, that is not what ssh-keygen shows at all. The -l option is showing you the key’s "fingerprint" and it’s telling you that it used SHA256 to compute this fingerprint – but it has nothing to do with the key’s type, nor with how the key will actually be used. The fingerprint is just a hash that was computed right now in order to be shown to you.

(Remember that previously SSH software used to show MD5-based key fingerprints – even though there was no MD5 usage in the actual SSHv2 protocol.)

Other key types

Is this the type not recommended anymore and I should switch for example, to ECDSA?

From what I know (i.e. from what I gathered on Security.SE), RSA as a signature algorithm is still strong – problems mostly just occur when trying to use RSA as an encryption algorithm, and that’s not an issue with SSHv2. (Well, the ever-increasing key size is not great either.)

ECDSA has its own problems – it is difficult to get its implementation right and certain kinds of programmer mistakes can be disastrous. If you had to switch, EdDSA (that is ssh-ed25519 or ssh-ed448) would be a better option.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply