Merge pull request #31 from romanz/master

Update ledger branch with the latest changes from master branch
This commit is contained in:
Roman Zeyde
2016-09-05 22:28:07 +03:00
committed by GitHub
6 changed files with 26 additions and 9 deletions

View File

@@ -15,7 +15,7 @@ Update you TREZOR firmware to the latest version (at least [c720614](https://git
Install latest `trezor-agent` package from [gpg-agent](https://github.com/romanz/trezor-agent/commits/gpg-agent) branch: Install latest `trezor-agent` package from [gpg-agent](https://github.com/romanz/trezor-agent/commits/gpg-agent) branch:
``` ```
$ pip install --user git+https://github.com/romanz/trezor-agent.git@gpg-agent $ pip install --user git+https://github.com/romanz/trezor-agent.git
``` ```
Define your GPG user ID as an environment variable: Define your GPG user ID as an environment variable:

View File

@@ -5,7 +5,6 @@
[![Package Version](https://img.shields.io/pypi/v/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/) [![Package Version](https://img.shields.io/pypi/v/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/)
[![Development Status](https://img.shields.io/pypi/status/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/) [![Development Status](https://img.shields.io/pypi/status/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/)
[![Downloads](https://img.shields.io/pypi/dm/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/) [![Downloads](https://img.shields.io/pypi/dm/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/)
[![Chat](https://badges.gitter.im/romanz/trezor-agent.svg)](https://gitter.im/romanz/trezor-agent)
See SatoshiLabs' blog posts about this feature: See SatoshiLabs' blog posts about this feature:
@@ -15,3 +14,5 @@ See SatoshiLabs' blog posts about this feature:
For usage with SSH, see the [following instructions](README-SSH.md). For usage with SSH, see the [following instructions](README-SSH.md).
For usage with GPG, see the [following instructions](README-GPG.md). For usage with GPG, see the [following instructions](README-GPG.md).
Questions, suggestions and discussions are welcome: [![Chat](https://badges.gitter.im/romanz/trezor-agent.svg)](https://gitter.im/romanz/trezor-agent)

View File

@@ -56,7 +56,7 @@ def _load_trezor():
hid_transport=HidTransport, hid_transport=HidTransport,
passphrase_ack=PassphraseAck, passphrase_ack=PassphraseAck,
identity_type=IdentityType, identity_type=IdentityType,
required_version='>=1.3.4', required_version='>=1.4.0',
call_exception=CallException) call_exception=CallException)
except ImportError: except ImportError:
log.exception('Missing module: install via "pip install trezor"') log.exception('Missing module: install via "pip install trezor"')

View File

@@ -16,6 +16,9 @@ log = logging.getLogger(__name__)
def run_create(args): def run_create(args):
"""Generate a new pubkey for a new/existing GPG identity.""" """Generate a new pubkey for a new/existing GPG identity."""
user_id = os.environ['TREZOR_GPG_USER_ID'] user_id = os.environ['TREZOR_GPG_USER_ID']
log.warning('NOTE: in order to re-generate the exact same GPG key later, '
'run this command with "--time=%d" commandline flag (to set '
'the timestamp of the GPG key manually).', args.time)
conn = encode.HardwareSigner(user_id=user_id, conn = encode.HardwareSigner(user_id=user_id,
curve_name=args.ecdsa_curve) curve_name=args.ecdsa_curve)
verifying_key = conn.pubkey(ecdh=False) verifying_key = conn.pubkey(ecdh=False)
@@ -57,9 +60,9 @@ def run_create(args):
sys.stdout.write(protocol.armor(result, 'PUBLIC KEY BLOCK')) 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.""" """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: with server.unix_domain_socket_server(sock_path) as sock:
for conn in agent.yield_connections(sock): for conn in agent.yield_connections(sock):
with contextlib.closing(conn): with contextlib.closing(conn):
@@ -81,7 +84,6 @@ def main():
create_cmd.set_defaults(run=run_create) create_cmd.set_defaults(run=run_create)
agent_cmd = subparsers.add_parser('agent') 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) agent_cmd.set_defaults(run=run_agent)
args = p.parse_args() args = p.parse_args()

View File

@@ -25,10 +25,17 @@ def parse_subpackets(s):
while True: while True:
try: try:
subpacket_len = s.readfmt('B') first = s.readfmt('B')
except EOFError: except EOFError:
break break
if first < 192:
subpacket_len = first
elif first < 255:
subpacket_len = ((first - 192) << 8) + s.readfmt('B') + 192
else: # first == 255
subpacket_len = s.readfmt('>L')
subpackets.append(s.read(subpacket_len)) subpackets.append(s.read(subpacket_len))
return subpackets return subpackets

View File

@@ -13,9 +13,16 @@ from .. import util
log = logging.getLogger(__name__) 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.""" """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']) sp.check_call(['gpg-connect-agent', '/bye'])
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(sock_path) sock.connect(sock_path)