gpg: use gpgconf to get correct GPG agent UNIX socket path
This commit is contained in:
@@ -60,9 +60,9 @@ def run_create(args):
|
||||
sys.stdout.write(protocol.armor(result, 'PUBLIC KEY BLOCK'))
|
||||
|
||||
|
||||
def run_agent(args):
|
||||
def run_agent(args): # pylint: disable=unused-argument
|
||||
"""Run a simple GPG-agent server."""
|
||||
sock_path = os.path.expanduser(args.sock_path)
|
||||
sock_path = keyring.get_agent_sock_path()
|
||||
with server.unix_domain_socket_server(sock_path) as sock:
|
||||
for conn in agent.yield_connections(sock):
|
||||
with contextlib.closing(conn):
|
||||
@@ -84,7 +84,6 @@ def main():
|
||||
create_cmd.set_defaults(run=run_create)
|
||||
|
||||
agent_cmd = subparsers.add_parser('agent')
|
||||
agent_cmd.add_argument('-s', '--sock-path', default='~/.gnupg/S.gpg-agent')
|
||||
agent_cmd.set_defaults(run=run_agent)
|
||||
|
||||
args = p.parse_args()
|
||||
|
||||
@@ -13,9 +13,16 @@ from .. import util
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def connect_to_agent(sock_path='~/.gnupg/S.gpg-agent', sp=subprocess):
|
||||
def get_agent_sock_path(sp=subprocess):
|
||||
"""Parse gpgconf output to find out GPG agent UNIX socket path."""
|
||||
lines = sp.check_output(['gpgconf', '--list-dirs']).strip().split('\n')
|
||||
dirs = dict(line.split(':', 1) for line in lines)
|
||||
return dirs['agent-socket']
|
||||
|
||||
|
||||
def connect_to_agent(sp=subprocess):
|
||||
"""Connect to GPG agent's UNIX socket."""
|
||||
sock_path = os.path.expanduser(sock_path)
|
||||
sock_path = get_agent_sock_path(sp=sp)
|
||||
sp.check_call(['gpg-connect-agent', '/bye'])
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(sock_path)
|
||||
|
||||
Reference in New Issue
Block a user