Bug 2214984 - error: "sha1 is not supported by this backend for RSA signing."
Summary: error: "sha1 is not supported by this backend for RSA signing."
Keywords:
Status: ASSIGNED
Alias: None
Product: Fedora EPEL
Classification: Fedora
Component: python-paramiko
Version: epel9
Hardware: All
OS: All
unspecified
unspecified
Target Milestone: ---
Assignee: Paul Howarth
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-06-14 11:11 UTC by Phil
Modified: 2024-01-13 14:48 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)
the podman buildfile (912 bytes, text/plain)
2023-06-14 11:11 UTC, Phil
no flags Details
the example python script (2.37 KB, text/x-python3)
2023-06-14 11:12 UTC, Phil
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Github paramiko paramiko issues 2259 0 None open error: "sha1 is not supported by this backend for RSA signing" 2023-06-23 11:04:00 UTC
Github paramiko paramiko pull 2345 0 None open Add option to skip host key verification 2024-01-13 13:35:52 UTC

Description Phil 2023-06-14 11:11:25 UTC
Created attachment 1970842 [details]
the podman buildfile

Description of problem:
When connecting to an ssh server which provides an rsa host key and the host key is known (either by a known_hosts file or by previous connection attempts) paramiko fails with "cryptography.exceptions.UnsupportedAlgorithm: sha1 is not supported by this backend for RSA signing", giving the following traceback:

--%snip%--
  File "/usr/lib/python3.9/site-packages/paramiko/client.py", line 421, in connect
    t.start_client(timeout=timeout)
  File "/usr/lib/python3.9/site-packages/paramiko/transport.py", line 699, in start_client
    raise e
  File "/usr/lib/python3.9/site-packages/paramiko/transport.py", line 2130, in run
    self.kex_engine.parse_next(ptype, m)
  File "/usr/lib/python3.9/site-packages/paramiko/kex_curve25519.py", line 64, in parse_next
    return self._parse_kexecdh_reply(m)
  File "/usr/lib/python3.9/site-packages/paramiko/kex_curve25519.py", line 130, in _parse_kexecdh_reply
    self.transport._verify_key(peer_host_key_bytes, sig)
  File "/usr/lib/python3.9/site-packages/paramiko/transport.py", line 1941, in _verify_key
    if not key.verify_ssh_sig(self.H, Message(sig)):
  File "/usr/lib/python3.9/site-packages/paramiko/rsakey.py", line 152, in verify_ssh_sig
    key.verify(
  File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 571, in verify
    return _rsa_sig_verify(
  File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 270, in _rsa_sig_verify
    pkey_ctx = _rsa_sig_setup(
  File "/usr/lib64/python3.9/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 213, in _rsa_sig_setup
    raise UnsupportedAlgorithm(
cryptography.exceptions.UnsupportedAlgorithm: sha1 is not supported by this backend for RSA signing.
--%snip%--

Version-Release number of selected component (if applicable):
2.12.0-1.el9

How reproducible:
always

Steps to Reproduce:
1. setup an ssh server with an rsa host key
2. clear this host key from any known_hosts files
3. connect twice

Actual results:
the first connect succeeds, the second connect fails with the trace above.

Expected results:
both connects successful

Additional info:
I attached two files to reproduce this behaviour easily. The python script connects to the ssh daemon running in a container via port 22022, logs in using a provided ssh key pair and calls "whoami". Since the script does not load any keys in advance, the rsa host key is unknown at first. Since we're using "AutoAddPolicy" the host key is known when attempting to connect the second time.

podman build -t sshrsa:latest Buildfile-sshrsa
podman run --rm -d -p 22022:22 sshrsa:latest
./paramikotest.py

Comment 1 Phil 2023-06-14 11:12:10 UTC
Created attachment 1970843 [details]
the example python script

Comment 2 Fedora Admin user for bugzilla script actions 2023-06-23 00:18:52 UTC
This package has changed maintainer in Fedora. Reassigning to the new maintainer of this component.

Comment 3 Paul Howarth 2023-06-23 11:04:46 UTC
I raised this issue upstream: https://github.com/paramiko/paramiko/issues/2259

Comment 4 Paul Howarth 2023-07-08 12:43:53 UTC
Upstream's comment:

If I understand correctly what's going on, this error occurs because a server is crafting its host keys with an obsolete, insecure hashing algorithm, in SHA1.

Isn't... the best solution here to upgrade the server so that it can use a modern, secure algorithm? Instead of changing paramiko to blithely ignore a security-relevant error raised out of `cryptography`?

I recognize that a server host key isn't on the same level of importance as an SSL key pair, since server host keys aren't usually backed by third-party CA certs and such, but this seems like an imprudent way to handle the situation.

Rather than accepting this connection by default and warning about an obsolete key being ignored, it seems to me a better solution would be an 'opt in' flag that a user would have to specify... a `skip_host_key_verification` boolean or something.

What do you think?

Comment 5 Phil 2023-07-10 13:56:53 UTC
Of course the best solution is to upgrade the server, but sometimes this isn't a valid option. Either because the server is a proprietary blackbox or it must be kept at a specific stable version, or, simply because noone cared to provide an update to the software to support other algorithms yet. In my case it's about jenkins, it seems only to support rsa sha1 hostkeys for the ssh configuration interface.

Sure, I'm fine with a "skip_host_key_verification" flag if this covers outdated algorithms as well (and not only stuff like mismatching fingerprints).

Thanks!

Comment 6 Paul Howarth 2024-01-10 14:56:17 UTC
I'm working on "skip_host_key_verification" flag implementation for upstream to consider (I have an implementation but want to add some tests for it yet).

However, whilst I was working on that it occurred to me that you could work around the issue you're having by adding:

    ssh._host_keys.clear()

before the ssh.connect(...

That's using a private interface but it's better than nothing at the moment I guess.

Comment 7 Phil 2024-01-13 14:48:45 UTC
Great, thanks a lot!


Note You need to log in before you can comment on or make changes to this bug.