Skip to content

[BUG] - RSA host-key parsing rejects rsa-sha2-512-labelled public key blob (interoperability) #2735

Backlog

Description

@saiaprameya

Are you using paramiko as a client or server?

Client

What feature(s) aren't working right?

Keys/auth

What version(s) of paramiko are you using?

3.5.1 (transport-only fix from PR #2722 backported; rsakey.py unchanged when this failure was reproduced)

What version(s) of Python are you using?

3.12

What operating system and version are you using?

Linux under WSL; distribution version not recorded

If you're connecting as a client, which SSH server are you connecting to?

Embedded SSH server advertising OpenSSH. Identifying banner and device details intentionally omitted.

If you're using paramiko as part of another tool, which tool/version?

Reproduced directly using paramiko.Transport, independently of the application framework.

Expected/desired behavior

Investigate an SSH host-key interoperability failure: an embedded server sends an RSA public-key blob whose leading type string is rsa-sha2-512, and Paramiko rejects it before user authentication. The system OpenSSH client can connect to the same server using RSA-SHA512.

Please advise whether narrowly accepting this RSA key-label variant is appropriate, or whether this should be addressed exclusively in the server implementation. I am not assuming that the server encoding is standards-compliant.

Actual behavior

After resolving the separate AES-GCM/empty-MAC negotiation issue using the transport changes from #2722, direct Paramiko negotiation reaches host-key parsing and fails.

Sanitized observed negotiation values:

Cipher: [email protected]
Separate MAC: None (AEAD)
Host-key algorithm: rsa-sha2-512

Exception:

paramiko.ssh_exception.SSHException: Invalid key (class: RSAKey, data type: rsa-sha2-512

The failure originates in RSAKey.__init__ -> PKey._check_type_and_load_cert, which accepts ssh-rsa as the regular RSA public-key blob type. No addresses, usernames, credentials, host keys, fingerprints, or internal file paths are included here.

How to reproduce

The following local-only example constructs the observed blob-label variant. Run with unmodified rsakey.py from Paramiko 3.5.1; no SSH server or credentials are required. The generated key is temporary and is not printed.

from paramiko import Message, RSAKey

key = RSAKey.generate(2048)
numbers = key.public_numbers

blob = Message()
blob.add_string("rsa-sha2-512")
blob.add_mpint(numbers.e)
blob.add_mpint(numbers.n)

RSAKey(data=blob.asbytes())
# SSHException: Invalid key (class: RSAKey, data type: rsa-sha2-512

Using ssh-rsa as the leading string works. This reproducer deliberately models the observed server encoding; it is not a claim that this encoding is RFC-compliant.

Anything else?

This is separate from #2491 / #2722: those address MAC negotiation, while this report concerns RSA public-key blob parsing after that issue is bypassed.

A local compatibility experiment changed the RSAKey.__init__ call from:

key_type=self.name,

to:

key_type=(self.name, "rsa-sha2-256", "rsa-sha2-512"),

This allowed the key to load and the RSA-SHA512 connection to proceed without disabling signature verification. A local generated-key check accepted a valid signature and rejected a signature checked against tampered data.

I understand that RFC 8332 retains the ssh-rsa public-key format for RSA-SHA2 signatures. The observed label may therefore be a server-side defect, and the change above is an interoperability experiment rather than a claim about the correct upstream solution. I have not validated this RSA-label behavior on the latest Paramiko release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions