Bug 2066882

Summary: OpenSSH can still use 1k RSA keys despite DEFAULT crypto-policy settings claims 2k is minimum
Product: Red Hat Enterprise Linux 9 Reporter: Jakub Jelen <jjelen>
Component: opensshAssignee: Dmitry Belyavskiy <dbelyavs>
Status: CLOSED ERRATA QA Contact: Ondrej Moriš <omoris>
Severity: medium Docs Contact: Jan Fiala <jafiala>
Priority: medium    
Version: 9.0CC: asosedki, dbelyavs, hkario, jafiala, jjelen, mhavrila, omoris, szidek, tscherf
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
.New option in OpenSSH supports setting the minimum RSA key length Accidentally using short RSA keys makes the system more vulnerable to attacks. With this update, you can set minimum RSA key lengths for OpenSSH servers and clients. To define the minimum RSA key length, use the new `RequiredRSASize` option in the `/etc/ssh/sshd_config` file for OpenSSH servers, and in the `/etc/ssh/ssh_config` file for OpenSSH clients.
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-15 11:21:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2102774    

Description Jakub Jelen 2022-03-22 16:49:10 UTC
Description of problem:
The crypto-policy claims the RSA keys smaller than 2k are not allowed:

https://gitlab.com/redhat-crypto/fedora-crypto-policies/-/blob/rhel9/policies/DEFAULT.pol#L11

But they clearly work in OpenSSH. They can be generated, used to authenticate to remote server and the server accepts them.

The upstream OpenSSH has hardcoded minimum 1024 since 2017 [1] and this is not configurable at runtime:

https://github.com/openssh/openssh-portable/commit/bd636f40911094a39c2920bf87d2ec340533c152

The OpenSSL claims that this affects only TLS usage so I see the only way out to invent a new configuration option that would make this value dynamic and that could be passed from the crypto-policies.

Version-Release number of selected component (if applicable):
openssl-3.0.1-17.el9.x86_64
openssh-8.7p1-8.el9.x86_64

How reproducible:
always

Steps to Reproduce:
1. Generate 1k RSA key
2. Copy the public key to authorized_keys
3. Try to connect using this key to RHEL9 server

Actual results:
succeeds

Expected results:
failure with scary security warning

Additional info:

The same issue will be with hostkeys.

Transcript of the reproducer above:

# ssh-keygen -t rsa -b 1024
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk root.local
The key's randomart image is:
+---[RSA 1024]----+
|     ..===o..    |
|      o+o.+o..   |
|      o .. ..    |
|       o  .    o.|
|        S. o .o=o|
|          + =.*=.|
|         . E.o+*+|
|          .o=++ *|
|          o+++.oo|
+----[SHA256]-----+
# ssh-keygen -lf .ssh/id_rsa
1024 SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk root.local (RSA)
# cat .ssh/id_rsa.pub  >> ~/.ssh/authorized_keys 
# grep DEBUG3 /etc/ssh/sshd_config
LogLevel DEBUG3
# systemctl restart sshd
# ssh -i .ssh/id_rsa localhost
The authenticity of host 'localhost (::1)' can't be established.
ED25519 key fingerprint is SHA256:yEvZW3MpW2BeXmbMPMNTUyM8tuJc950AAPhnXaEjTNE.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'localhost' (ED25519) to the list of known hosts.
Last login: Fri Mar 18 13:35:24 2022 from 10.0.2.2
[root@rhel-9-1-0-20220313-2 ~]# 
logout
Connection to localhost closed.
# grep RSA /var/log/secure 
Mar 18 13:36:39 rhel-9-1-0-20220313-2 sshd[897]: Accepted publickey for root from ::1 port 42286 ssh2: RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: debug1: userauth_pubkey: test pkalg rsa-sha2-256 pkblob RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk [preauth]
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: debug1: /root/.ssh/authorized_keys:2: matching key found: RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: Accepted key RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk found at /root/.ssh/authorized_keys:2
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: debug3: mm_answer_keyallowed: publickey authentication test: RSA key is allowed
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: debug3: userauth_pubkey: have rsa-sha2-256 signature for RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk [preauth]
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: debug1: /root/.ssh/authorized_keys:2: matching key found: RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: Accepted key RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk found at /root/.ssh/authorized_keys:2
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: debug3: mm_answer_keyallowed: publickey authentication: RSA key is allowed
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: debug3: mm_answer_keyverify: publickey RSA signature verified
Mar 18 13:49:04 rhel-9-1-0-20220313-2 sshd[938]: Accepted publickey for root from ::1 port 42288 ssh2: RSA SHA256:UHcLLdAM5BKczf+J/LodXoVe+H8l+ZCljyh0trcX6gk

Comment 2 Dmitry Belyavskiy 2022-06-06 10:25:44 UTC
Ideal solution would be to have a configuration option, but upstream will probably not like it. Maybe use as downstream patch?
The problem is not the ssh-keygen generating the keys, but the ssh/sshd using and accepting these keys.

Comment 22 errata-xmlrpc 2022-11-15 11:21:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (openssh bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:8375