2016-04-16 18:21:12 +00:00
|
|
|
#!/usr/bin/env python
|
2016-04-24 10:04:53 +00:00
|
|
|
"""Create signatures and export public keys for GPG using TREZOR."""
|
2016-04-16 18:21:12 +00:00
|
|
|
import argparse
|
2016-05-21 14:21:16 +00:00
|
|
|
import contextlib
|
2016-04-16 18:21:12 +00:00
|
|
|
import logging
|
2016-05-28 20:02:45 +00:00
|
|
|
import os
|
2016-04-24 11:23:16 +00:00
|
|
|
import sys
|
2016-04-16 18:21:12 +00:00
|
|
|
import time
|
|
|
|
|
2016-05-30 14:49:21 +00:00
|
|
|
from . import encode, keyring, proto
|
2016-04-16 18:21:12 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2016-05-06 19:16:03 +00:00
|
|
|
def run_create(args):
|
|
|
|
"""Generate a new pubkey for a new/existing GPG identity."""
|
2016-05-07 06:41:58 +00:00
|
|
|
user_id = os.environ['TREZOR_GPG_USER_ID']
|
2016-05-21 14:25:01 +00:00
|
|
|
f = encode.Factory(user_id=user_id, created=args.time,
|
2016-05-21 17:00:38 +00:00
|
|
|
curve_name=args.ecdsa_curve)
|
2016-05-21 14:21:16 +00:00
|
|
|
|
2016-05-21 14:25:01 +00:00
|
|
|
with contextlib.closing(f):
|
2016-05-21 14:21:16 +00:00
|
|
|
if args.subkey:
|
2016-05-27 08:19:10 +00:00
|
|
|
primary_key = keyring.export_public_key(user_id=user_id)
|
|
|
|
result = f.create_subkey(primary_bytes=primary_key)
|
2016-05-21 14:21:16 +00:00
|
|
|
else:
|
2016-05-21 14:25:01 +00:00
|
|
|
result = f.create_primary()
|
2016-05-06 19:16:03 +00:00
|
|
|
|
2016-05-21 14:15:42 +00:00
|
|
|
sys.stdout.write(proto.armor(result, 'PUBLIC KEY BLOCK'))
|
2016-05-06 19:16:03 +00:00
|
|
|
|
2016-04-24 11:23:16 +00:00
|
|
|
|
2016-04-16 18:21:12 +00:00
|
|
|
def main():
|
2016-04-24 09:22:02 +00:00
|
|
|
"""Main function."""
|
2016-04-16 18:21:12 +00:00
|
|
|
p = argparse.ArgumentParser()
|
|
|
|
p.add_argument('-v', '--verbose', action='store_true', default=False)
|
2016-05-06 19:16:03 +00:00
|
|
|
subparsers = p.add_subparsers()
|
2016-05-22 19:28:07 +00:00
|
|
|
subparsers.required = True
|
|
|
|
subparsers.dest = 'command'
|
2016-05-06 19:16:03 +00:00
|
|
|
|
|
|
|
create = subparsers.add_parser('create')
|
|
|
|
create.add_argument('-s', '--subkey', action='store_true', default=False)
|
|
|
|
create.add_argument('-e', '--ecdsa-curve', default='nist256p1')
|
|
|
|
create.add_argument('-t', '--time', type=int, default=int(time.time()))
|
|
|
|
create.set_defaults(run=run_create)
|
|
|
|
|
2016-04-16 18:21:12 +00:00
|
|
|
args = p.parse_args()
|
|
|
|
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO,
|
|
|
|
format='%(asctime)s %(levelname)-10s %(message)s')
|
2016-05-07 06:41:58 +00:00
|
|
|
args.run(args)
|
2016-04-16 18:21:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|