diff --git a/crypto_dev_signer/runnable/keyfile.py b/crypto_dev_signer/runnable/keyfile.py index ad9937b..aed9740 100644 --- a/crypto_dev_signer/runnable/keyfile.py +++ b/crypto_dev_signer/runnable/keyfile.py @@ -4,6 +4,7 @@ import logging import sys import json import argparse +import getpass # external impors import coincurve @@ -21,23 +22,36 @@ logg = logging.getLogger() argparser = argparse.ArgumentParser() argparser.add_argument('-d', type=str, help='decrypt file') argparser.add_argument('-v', action='store_true', help='be verbose') -argparser.add_argument('arg', type=str, help='decrypt file') args = argparser.parse_args() if args.v: logg.setLevel(logging.DEBUG) -r = None +mode = 'create' if args.d: - try: - r = from_file(args.d, args.arg).hex() - except AssertionError: - sys.stderr.write('Invalid passphrase\n') - sys.exit(1) -else: - pk_bytes = os.urandom(32) - pk = coincurve.PrivateKey(secret=pk_bytes) - o = to_dict(pk, args.arg) - r = json.dumps(o) + mode = 'decrypt' -print(r) +def main(): + passphrase = os.environ.get('PASSPHRASE') + r = None + if mode == 'decrypt': + if passphrase == None: + passphrase = getpass.getpass('decryption phrase: ') + try: + r = from_file(args.d, passphrase).hex() + except AssertionError: + sys.stderr.write('Invalid passphrase\n') + sys.exit(1) + elif mode == 'create': + if passphrase == None: + passphrase = getpass.getpass('encryption phrase: ') + pk_bytes = os.urandom(32) + pk = coincurve.PrivateKey(secret=pk_bytes) + o = to_dict(pk, passphrase) + r = json.dumps(o) + + print(r) + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 54ab373..6a74495 100644 --- a/setup.py +++ b/setup.py @@ -48,6 +48,7 @@ setup( entry_points = { 'console_scripts': [ 'crypto-dev-daemon=crypto_dev_signer.runnable.signer:main', + 'eth-keyfile=crypto_dev_signer.runnable.keyfile:main', ], }, url='https://gitlab.com/nolash/crypto-dev-signer',