From fdcdc4772b81754c36104b81b14e4ff1be00a8f7 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 30 Mar 2022 15:49:43 +0000 Subject: [PATCH] mmgen-autosign: move autosign key to mountpoint --- mmgen/main_autosign.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/mmgen/main_autosign.py b/mmgen/main_autosign.py index f4e5c194..73a537b5 100755 --- a/mmgen/main_autosign.py +++ b/mmgen/main_autosign.py @@ -31,7 +31,6 @@ mountpoint = '/mnt/tx' tx_dir = '/mnt/tx/tx' part_label = 'MMGEN_TX' wallet_dir = '/dev/shm/autosign' -key_fn = 'autosign.key' mn_fmts = { 'mmgen': 'words', 'bip39': 'bip39', @@ -67,7 +66,7 @@ opts_data = { COMMANDS -gen_key - generate the wallet encryption key and copy it to '{tx_dir}' +gen_key - generate the wallet encryption key and copy it to {mountpoint!r} setup - generate the wallet encryption key and wallet wait - start in loop mode: wait-mount-sign-unmount-wait @@ -105,7 +104,7 @@ Alternatively, the password and wallet can be created separately by first invoking the command with 'gen_key' and then creating and encrypting the wallet using the -P (--passwd-file) option: - $ mmgen-walletconv -r0 -q -iwords -d{wallet_dir} -p1 -P{tx_dir}/{key_fn} -Llabel + $ mmgen-walletconv -r0 -q -iwords -d{wallet_dir} -p1 -P/mnt/tx/autosign.key -Llabel Note that the hash preset must be '1'. Multiple wallets are permissible. @@ -145,8 +144,9 @@ from .rpc import rpc_init if opt.mountpoint: mountpoint = opt.mountpoint +keyfile = os.path.join(mountpoint,'autosign.key') opt.outdir = tx_dir = os.path.join(mountpoint,'tx') -opt.passwd_file = os.path.join(tx_dir,key_fn) +opt.passwd_file = keyfile async def check_daemons_running(): if opt.coin: @@ -311,23 +311,21 @@ async def do_sign(): return False def wipe_existing_key(): - fn = os.path.join(tx_dir,key_fn) - try: os.stat(fn) + try: os.stat(keyfile) except: pass else: from .fileutil import shred_file - msg(f'\nShredding existing key {fn!r}') - shred_file( fn, verbose=opt.verbose ) + msg(f'\nShredding existing key {keyfile!r}') + shred_file( keyfile, verbose=opt.verbose ) def create_key(): kdata = os.urandom(32).hex() - fn = os.path.join(tx_dir,key_fn) - desc = f'key file {fn!r}' + desc = f'key file {keyfile!r}' msg('Creating ' + desc) try: - with open(fn,'w') as fp: + with open(keyfile,'w') as fp: fp.write(kdata+'\n') - os.chmod(fn,0o400) + os.chmod(keyfile,0o400) msg('Wrote ' + desc) except: die(2,'Unable to write ' + desc)