Skip to content

Commit 9cce48c

Browse files
authored
Allow ssh-rsa keys to be used for rsa-sha2-* auth (#290)
This worked before [this change](194430b#diff-81b0128d04a2d9a37bdc6931dec1cb426a8ff7c6ad4ef10e1555ca3e29f08380L159), and is permitted by the specification, as can be seen in [the example in section 3.2 of RFC8332](https://www.rfc-editor.org/rfc/rfc8332#section-3.2).
1 parent 7e407d2 commit 9cce48c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

russh-keys/src/key.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,16 @@ impl PublicKey {
136136
pub fn parse(algo: &[u8], pubkey: &[u8]) -> Result<Self, Error> {
137137
use ssh_encoding::Decode;
138138
let key_data = &ssh_key::public::KeyData::decode(&mut pubkey.reader(0))?;
139-
if key_data.algorithm().as_str().as_bytes() != algo {
139+
let key_algo = key_data.algorithm();
140+
let key_algo = key_algo.as_str().as_bytes();
141+
if key_algo == b"ssh-rsa" {
142+
if algo != SSH_RSA.as_ref().as_bytes()
143+
&& algo != RSA_SHA2_256.as_ref().as_bytes()
144+
&& algo != RSA_SHA2_512.as_ref().as_bytes()
145+
{
146+
return Err(Error::KeyIsCorrupt);
147+
}
148+
} else if key_algo != algo {
140149
return Err(Error::KeyIsCorrupt);
141150
}
142151
Self::try_from(key_data)

0 commit comments

Comments
 (0)