gpg: simplify AgentSigner and move to keyring module

nistp521
Roman Zeyde 8 years ago
parent e7b8379a97
commit 915b326da7

@ -55,24 +55,6 @@ class HardwareSigner(object):
self.client_wrapper.connection.close()
class AgentSigner(object):
"""Sign messages and get public keys using gpg-agent tool."""
def __init__(self, user_id):
"""Connect to the agent and retrieve required public key."""
self.sock = keyring.connect_to_agent()
self.keygrip = keyring.get_keygrip(user_id)
def sign(self, digest):
"""Sign the digest and return an ECDSA/RSA/DSA signature."""
return keyring.sign_digest(sock=self.sock,
keygrip=self.keygrip, digest=digest)
def close(self):
"""Close the connection to gpg-agent."""
self.sock.close()
def _time_format(t):
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
@ -160,7 +142,7 @@ def create_subkey(primary_bytes, pubkey, signer_func):
log.info('confirm signing with primary key')
if not primary['_is_custom']:
signer_func = AgentSigner(primary['user_id']).sign
signer_func = keyring.create_agent_signer(primary['user_id'])
signature = protocol.make_signature(
signer_func=signer_func,

@ -204,3 +204,15 @@ def export_public_key(user_id, sp=subprocess):
log.error('could not find public key %r in local GPG keyring', user_id)
raise KeyError(user_id)
return result
def create_agent_signer(user_id):
"""Sign digest with existing GPG keys using gpg-agent tool."""
sock = connect_to_agent()
keygrip = get_keygrip(user_id)
def sign(digest):
"""Sign the digest and return an ECDSA/RSA/DSA signature."""
return sign_digest(sock=sock, keygrip=keygrip, digest=digest)
return sign

Loading…
Cancel
Save