Add passphrase prompt

This commit is contained in:
nolash 2021-03-17 22:08:20 +01:00
parent 75eaf90205
commit fc30b9272f
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 28 additions and 13 deletions

View File

@ -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:
mode = 'decrypt'
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, args.arg).hex()
r = from_file(args.d, passphrase).hex()
except AssertionError:
sys.stderr.write('Invalid passphrase\n')
sys.exit(1)
else:
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, args.arg)
o = to_dict(pk, passphrase)
r = json.dumps(o)
print(r)
if __name__ == '__main__':
main()

View File

@ -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',