Browse Source

feat: option to use ssh agent

master
Andrew Somerville 5 years ago
parent
commit
ca46931c91
  1. 2
      README.md
  2. 17
      remarkable_mouse/remarkable_mouse.py

2
README.md

@ -15,7 +15,7 @@ pip install remarkable-mouse
remouse 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 # Examples

17
remarkable_mouse/remarkable_mouse.py

@ -10,6 +10,7 @@ import struct
from getpass import getpass from getpass import getpass
import paramiko import paramiko
import paramiko.agent
logging.basicConfig(format='%(message)s') logging.basicConfig(format='%(message)s')
log = logging.getLogger(__name__) 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)) 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: if args.key is not None:
password = None password = None
try: try:
@ -42,14 +51,12 @@ def open_remote_device(args, file='/dev/input/event0'):
elif args.password: elif args.password:
password = args.password password = args.password
pkey = None pkey = None
else: elif not agent.get_keys():
password = getpass( password = getpass(
"Password for '{}': ".format(args.address) "Password for '{}': ".format(args.address)
) )
pkey = None pkey = None
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect( client.connect(
args.address, args.address,
username='root', username='root',
@ -58,6 +65,10 @@ def open_remote_device(args, file='/dev/input/event0'):
look_for_keys=False look_for_keys=False
) )
session = client.get_transport().open_session()
paramiko.agent.AgentRequestHandler(session)
# Start reading events # Start reading events
_, stdout, _ = client.exec_command('cat ' + file) _, stdout, _ = client.exec_command('cat ' + file)

Loading…
Cancel
Save