Bug 3375 - SHA1 is used as a proof of possession for the RSA key
Summary: SHA1 is used as a proof of possession for the RSA key
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 8.7p1
Hardware: Other Linux
: P3 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_8_9
  Show dependency treegraph
 
Reported: 2021-12-16 20:56 AEDT by Dmitry Belyavskiy
Modified: 2022-02-25 13:56 AEDT (History)
2 users (show)

See Also:


Attachments
Here is the proposed solution (3.47 KB, patch)
2021-12-21 22:17 AEDT, Dmitry Belyavskiy
no flags Details | Diff
tweaked diff (3.80 KB, patch)
2022-01-05 18:41 AEDT, Damien Miller
no flags Details | Diff
client side (3.87 KB, patch)
2022-01-05 18:44 AEDT, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Belyavskiy 2021-12-16 20:56:04 AEDT
If we need to get a proof of ownership for a RSA key on establishing a connection, the SHA1 algorithm is used by default (see the ssh_rsa_sign function). Not sure that it is the best possible option now. 

As it is possible to explicitly request the hash, it's worth analyze the client's capabilities and use SHA2 for this purpose.
Comment 1 Damien Miller 2021-12-20 15:05:56 AEDT
I'm not sure what you're talking about - there are already extensive negotiation mechanisms that default to SHA2 for user and host authentication.
Comment 2 Dmitry Belyavskiy 2021-12-20 19:32:44 AEDT
When we have, say, an ECDSA key confirmed by fingerprint and RSA key to be confirmed, we have EC-based KEX, so the KEX-based prevention of using SHA1 (https://github.com/openssh/openssh-portable/blob/7a7c69d8b4022b1e5c0afb169c416af8ce70f3e8/serverloop.c#L725-L730) will not work and SHA1 will be used for the proof of posession of the RSA key.
Comment 3 Jakub Jelen 2021-12-20 21:48:14 AEDT
The condition `kexsigtype == KEY_RSA` in the above link will work only if the rsa-sha2-* hostkey type was negotiated during key exchange and we are sending a proof of possession of another RSA key.

In any other case, for example ECDSA or Ed25519 hostkey is negotiated, the above condition will evaluate always to `false` and RSA with SHA1 will be used regardless the client capabilities.

I think the above condition should be rewritten to check not against the negotiated hostkey type, but if the client supports the RSA with SHA2 (regardless of the negotiated key type). But I did not have time to look better into the implementation yet.
Comment 4 Dmitry Belyavskiy 2021-12-21 22:17:48 AEDT
Created attachment 3559 [details]
Here is the proposed solution
Comment 5 Dmitry Belyavskiy 2022-01-03 21:52:21 AEDT
I suggest to increase the priority. The problem occurs when we use OpenSSL in FIPS mode, so signing a SHA1 hash becomes not an option.
Comment 6 Damien Miller 2022-01-05 18:41:17 AEDT
Created attachment 3561 [details]
tweaked diff

IMO it's important to retain the current algorithm selection logic for RSA keys, because otherwise the client will reject them for having the wrong signature algorithm.

This patch does this and tweaks a few other things.
Comment 7 Damien Miller 2022-01-05 18:44:15 AEDT
Created attachment 3562 [details]
client side

Similarly, if you want to avoid use of RSA-SHA1 completely then you also need to ensure the client only accepts RSA-SHA2 signatures.

This patch to the client does this. It will disregard hostkey proofs if they use ssh-rsa except when it has been explicitly negotiated as the hostkey algorithm.

AFAIK this should be fine for backwards compatibility, except for the case when a <openssh-8.9 server is configured with multiple RSA keys. I expect this to be a rare situation.
Comment 8 Dmitry Belyavskiy 2022-01-05 19:14:44 AEDT
Thanks!

I need to test it, but your code looks great.

The problem is, when we are in FIPS mode, we shouldn't use sha1 for signature (but still are allowed to use for the verification).
Comment 9 Damien Miller 2022-01-07 12:37:21 AEDT
These have been committed now. Thanks for spotting the bug and for providing a fix. If there are any further problems then please reopen this bug
Comment 10 Damien Miller 2022-02-25 13:56:41 AEDT
closing bugs resolved before openssh-8.9