From 4afb214f54121c80544258b42edf2e2d64d63780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6rg=C3=A6sis?= <91963632+morgaesis@users.noreply.github.com> Date: Mon, 21 Feb 2022 22:13:38 +0000 Subject: [PATCH] Add Ed25519 and ECDSA key support (#69) --- remarkable_mouse/remarkable_mouse.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/remarkable_mouse/remarkable_mouse.py b/remarkable_mouse/remarkable_mouse.py index 9834979..785623e 100755 --- a/remarkable_mouse/remarkable_mouse.py +++ b/remarkable_mouse/remarkable_mouse.py @@ -41,16 +41,19 @@ def open_rm_inputs(*, address, key, password): agent = paramiko.agent.Agent() def use_key(key): - try: - pkey = paramiko.RSAKey.from_private_key_file(os.path.expanduser(key)) - except paramiko.ssh_exception.PasswordRequiredException: - passphrase = getpass( - "Enter passphrase for key '{}': ".format(os.path.expanduser(key)) - ) - pkey = paramiko.RSAKey.from_private_key_file( - os.path.expanduser(key), - password=passphrase - ) + for key_type in [paramiko.RSAKey, paramiko.Ed25519Key, paramiko.ECDSAKey]: + try: + pkey = key_type.from_private_key_file(os.path.expanduser(key)) + except paramiko.ssh_exception.SSHException: + continue + except paramiko.ssh_exception.PasswordRequiredException: + passphrase = getpass( + "Enter passphrase for key '{}': ".format(os.path.expanduser(key)) + ) + pkey = paramiko.RSAKey.from_private_key_file( + os.path.expanduser(key), password=passphrase + ) + break return pkey if key is not None: