2015-07-03 13:09:49 +00:00
|
|
|
import os
|
2015-06-15 13:37:16 +00:00
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
|
2015-06-15 15:13:10 +00:00
|
|
|
from . import trezor
|
|
|
|
from . import server
|
|
|
|
from . import formats
|
2015-06-15 13:37:16 +00:00
|
|
|
|
2015-06-16 07:20:11 +00:00
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2015-06-16 07:03:48 +00:00
|
|
|
|
2015-06-15 13:37:16 +00:00
|
|
|
def main():
|
2015-07-03 13:09:49 +00:00
|
|
|
fmt = '%(asctime)s %(levelname)-12s %(message)-100s [%(filename)s:%(lineno)d]'
|
2015-06-15 13:37:16 +00:00
|
|
|
p = argparse.ArgumentParser()
|
2015-07-04 05:48:36 +00:00
|
|
|
g = p.add_mutually_exclusive_group()
|
|
|
|
g.add_argument('-v', '--verbose', default=0, action='count')
|
|
|
|
g.add_argument('-q', '--quiet', default=False, action='store_true')
|
|
|
|
|
2015-07-03 13:09:49 +00:00
|
|
|
p.add_argument('-c', dest='command', type=str, default=None,
|
|
|
|
help='command to run under the SSH agent')
|
2015-07-04 05:57:38 +00:00
|
|
|
p.add_argument('identity', type=str, nargs='+',
|
2015-07-03 13:09:49 +00:00
|
|
|
help='proto://[user@]host[:port][/path]')
|
2015-06-15 13:37:16 +00:00
|
|
|
args = p.parse_args()
|
|
|
|
|
2015-07-04 05:48:36 +00:00
|
|
|
loglevel = logging.INFO
|
|
|
|
if args.verbose:
|
|
|
|
loglevel = logging.DEBUG
|
|
|
|
if args.quiet:
|
|
|
|
loglevel = logging.WARNING
|
|
|
|
|
|
|
|
logging.basicConfig(level=loglevel, format=fmt)
|
2015-06-15 13:37:16 +00:00
|
|
|
|
2015-06-17 13:52:11 +00:00
|
|
|
with trezor.Client(factory=trezor.TrezorLibrary) as client:
|
2015-07-04 05:51:11 +00:00
|
|
|
public_keys = [client.get_public_key(i) for i in args.identity]
|
2015-06-17 13:52:11 +00:00
|
|
|
|
2015-07-03 13:09:49 +00:00
|
|
|
command = args.command
|
|
|
|
if not command:
|
|
|
|
command = os.environ['SHELL']
|
|
|
|
log.info('using %r shell', command)
|
2015-06-17 13:52:11 +00:00
|
|
|
|
|
|
|
signer = client.sign_ssh_challenge
|
|
|
|
|
|
|
|
try:
|
2015-07-04 05:35:59 +00:00
|
|
|
with server.serve(public_keys=public_keys, signer=signer) as env:
|
2015-07-03 13:09:49 +00:00
|
|
|
return server.run_process(command=command, environ=env)
|
2015-06-17 13:52:11 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
log.info('server stopped')
|
2015-06-15 13:37:16 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-06-17 13:52:11 +00:00
|
|
|
sys.exit(main())
|