From ca46931c912ac9cceea07afe93a615b06f42dd3e Mon Sep 17 00:00:00 2001 From: Andrew Somerville Date: Sun, 26 Apr 2020 20:32:06 -0400 Subject: [PATCH] feat: option to use ssh agent --- README.md | 2 +- remarkable_mouse/remarkable_mouse.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5525f18..46bcdd8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ pip install remarkable-mouse remouse ``` -By default, `10.11.99.1` is used as the address. Seems to work pretty well wirelessly, too. +By default, `10.11.99.1` is used as the address. Seems to work pretty well wirelessly, too. By default ssh-agent is used to authenticate if it is available, otherwise you are asked for your password. # Examples diff --git a/remarkable_mouse/remarkable_mouse.py b/remarkable_mouse/remarkable_mouse.py index 41b4f15..b17fe2a 100755 --- a/remarkable_mouse/remarkable_mouse.py +++ b/remarkable_mouse/remarkable_mouse.py @@ -10,6 +10,7 @@ import struct from getpass import getpass import paramiko +import paramiko.agent logging.basicConfig(format='%(message)s') log = logging.getLogger(__name__) @@ -27,6 +28,14 @@ def open_remote_device(args, file='/dev/input/event0'): """ log.info("Connecting to input '{}' on '{}'".format(file, args.address)) + client = paramiko.SSHClient() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + pkey = None + password = None + + agent = paramiko.agent.Agent() + if args.key is not None: password = None try: @@ -42,14 +51,12 @@ def open_remote_device(args, file='/dev/input/event0'): elif args.password: password = args.password pkey = None - else: + elif not agent.get_keys(): password = getpass( "Password for '{}': ".format(args.address) ) pkey = None - client = paramiko.SSHClient() - client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect( args.address, username='root', @@ -58,6 +65,10 @@ def open_remote_device(args, file='/dev/input/event0'): look_for_keys=False ) + session = client.get_transport().open_session() + + paramiko.agent.AgentRequestHandler(session) + # Start reading events _, stdout, _ = client.exec_command('cat ' + file)