-
Notifications
You must be signed in to change notification settings - Fork 166
Description
I've run into an issue when trying to connect using a client_key.
asyncssh.connect("hostname", known_hosts=None, tunnel=other_conn, username="username", client_keys=["key_file.pem"])
(the connection is tunneled, but I'm assuming that is not the cause of the issue)
This results in the following error:
asyncssh.misc.PermissionDenied: Permission denied for user username on host hostname
In the sshd log I find the following messages:
Jun 24 19:29:00 XXX sshd[119216]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedKeyTypes [preauth]
Jun 24 19:29:00 XXX sshd[119216]: Connection closed by authenticating user XXX 11.0.0.221 port 57964 [preauth]
The ssh-rsa
key type is indeed configured to be not accepted:
PubkeyAcceptedKeyTypes=ecdsa-sha2-nistp256,[email protected],ecdsa-sha2-nistp384,[email protected],ecdsa-sha2-nistp521,[email protected],rsa-sha2-256,[email protected],rsa-sha2-512,[email protected]
And this is (I think) reflected in the asyncssh logs: (no ssh-rsa
in the Host key algs
line.
DEBUG:asyncssh:[conn=2] Received key exchange request
DEBUG:asyncssh:[conn=2] Key exchange algs: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512
DEBUG:asyncssh:[conn=2] Host key algs: ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256
DEBUG:asyncssh:[conn=2] Client to server:
DEBUG:asyncssh:[conn=2] Encryption algs: [email protected],aes256-ctr,aes256-cbc,[email protected],aes128-ctr,aes128-cbc
DEBUG:asyncssh:[conn=2] MAC algs: [email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha1,hmac-sha2-512
DEBUG:asyncssh:[conn=2] Compression algs: none,[email protected]
DEBUG:asyncssh:[conn=2] Server to client:
DEBUG:asyncssh:[conn=2] Encryption algs: [email protected],aes256-ctr,aes256-cbc,[email protected],aes128-ctr,aes128-cbc
DEBUG:asyncssh:[conn=2] MAC algs: [email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha1,hmac-sha2-512
DEBUG:asyncssh:[conn=2] Compression algs: none,[email protected]
However, it appears that for some reason the ssh-rsa
key type is chosen anyway.
I've fiddled around with the code and when I modify the _choose_signature_alg
function to look like this:
def _choose_signature_alg(self, keypair: _ClientHostKey) -> bool:
"""Choose signature algorithm to use for key-based authentication"""
if self._server_sig_algs:
for alg in keypair.sig_algorithms:
if keypair.use_webauthn and not alg.startswith(b'webauthn-'):
continue
if alg in self._sig_algs and alg in self._server_sig_algs:
keypair.set_sig_algorithm(alg)
return True
# ----- I'VE ADDED THESE LINES -------
remaining_algs = [algo for algo in keypair.sig_algorithms if algo in self._sig_algs]
if remaining_algs:
keypair.set_sig_algorithm(remaining_algs[0])
return True
# ------------------------------------
return keypair.sig_algorithms[-1] in self._sig_algs
Then it's all working correctly.
Did I find a bug in asyncssh (or a missing feature)?
Thinks to note:
- I'm not an expert on ssh. I'm not sure if this is really the good way to fix the problem.
- When using the openssh client or paramiko with the same key_file things are also working correctly, so I assume the ssh server configuration and the key_file are not the issue.
Versions:
asyncss: 2.21
sshd server: OpenSSH_8.0p1, OpenSSL 1.1.1k FIPS 25 Mar 2021