Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to configure a pinentry #202

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Refactor config parsing
  • Loading branch information
rendaw committed Feb 22, 2018
commit c7cb578fb349f8c993d81b0ab1a200266d45a075
6 changes: 1 addition & 5 deletions libagent/gpg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ def run_agent(device_type):
args, _ = parser.parse_known_args()

assert args.homedir
config_file = os.path.join(args.homedir, 'gpg-agent.conf')

lines = (line.strip() for line in open(config_file))
lines = (line for line in lines if line and not line.startswith('#'))
config = dict(line.split(' ', 1) for line in lines)
config = util.parse_config(args.homedir)

util.setup_logging(verbosity=int(config['verbosity']),
filename=config['log-file'])
Expand Down
1 change: 1 addition & 0 deletions libagent/gpg/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AgentStop(Exception):

class Handler(object):
"""GPG agent requests' handler."""
# pylint: disable=too-many-instance-attributes

def __init__(self, device, pubkey_bytes):
"""C-tor."""
Expand Down
3 changes: 2 additions & 1 deletion libagent/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def _dummy_context():
def main(device_type):
"""Run ssh-agent using given hardware client factory."""
args = create_agent_parser(device_type=device_type).parse_args()
config = util.parse_config()
util.setup_logging(verbosity=args.verbose, filename=args.log_file)

public_keys = None
Expand Down Expand Up @@ -255,7 +256,7 @@ def main(device_type):
sys.stdin.close()

conn = JustInTimeConnection(
conn_factory=lambda: client.Client(device_type()),
conn_factory=lambda: client.Client(device_type(config=config)),
identities=identities, public_keys=public_keys)

if command or args.daemonize:
Expand Down
11 changes: 11 additions & 0 deletions libagent/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import logging
import struct
import os

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -229,3 +230,13 @@ def which(cmd):
raise OSError('Cannot find {!r} in $PATH'.format(cmd))
log.debug('which %r => %r', cmd, full_path)
return full_path


def parse_config(homedir=None):
if not homedir:
homedir = os.environ.get('GNUPGHOME')
config_file = os.path.join(homedir, 'gpg-agent.conf')
with open(config_file, 'r') as source:
lines = (line.strip() for line in source)
lines = (line for line in lines if line and not line.startswith('#'))
return dict(line.split(' ', 1) for line in lines)