Add lock, unlock, keyfile error detail
This commit is contained in:
parent
031bc5a618
commit
f353930f44
@ -21,4 +21,9 @@ class SignerError(Exception):
|
||||
return self.jsonrpc_error
|
||||
|
||||
|
||||
class DecryptError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class KeyfileError(Exception):
|
||||
pass
|
||||
|
@ -12,6 +12,10 @@ from Crypto.Util import Counter
|
||||
import sha3
|
||||
|
||||
# local imports
|
||||
from funga.error import (
|
||||
DecryptError,
|
||||
KeyfileError,
|
||||
)
|
||||
from funga.eth.encoding import private_key_to_address
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
@ -127,17 +131,28 @@ def from_dict(o, passphrase=''):
|
||||
|
||||
# check mac
|
||||
calculated_mac = to_mac(decryption_key[16:], ciphertext_bytes)
|
||||
assert control_mac == calculated_mac
|
||||
if control_mac != calculated_mac:
|
||||
raise DecryptError('mac mismatch when decrypting passphrase')
|
||||
|
||||
m = getattr(Ciphers, 'decrypt_{}'.format(cipher.replace('-', '_')))
|
||||
|
||||
try:
|
||||
pk = m(ciphertext_bytes, decryption_key[:16], iv)
|
||||
except AssertionError as e:
|
||||
raise DecryptError('could not decrypt keyfile: {}'.format(e))
|
||||
logg.debug('bar')
|
||||
|
||||
return pk
|
||||
|
||||
|
||||
def from_file(filepath, passphrase=''):
|
||||
|
||||
f = open(filepath, 'r')
|
||||
try:
|
||||
o = json.load(f)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
f.close()
|
||||
raise KeyfileError(e)
|
||||
f.close()
|
||||
|
||||
return from_dict(o, passphrase)
|
||||
|
@ -11,11 +11,12 @@ import coincurve
|
||||
from hexathon import strip_0x
|
||||
|
||||
# local imports
|
||||
from crypto_dev_signer.keystore.keyfile import (
|
||||
from funga.error import DecryptError
|
||||
from funga.eth.keystore.keyfile import (
|
||||
from_file,
|
||||
to_dict,
|
||||
)
|
||||
from crypto_dev_signer.encoding import (
|
||||
from funga.eth.encoding import (
|
||||
private_key_to_address,
|
||||
private_key_from_bytes,
|
||||
)
|
||||
@ -60,7 +61,7 @@ def main():
|
||||
passphrase = getpass.getpass('decryption phrase: ')
|
||||
try:
|
||||
r = from_file(args.d, passphrase).hex()
|
||||
except AssertionError:
|
||||
except DecryptError:
|
||||
sys.stderr.write('Invalid passphrase\n')
|
||||
sys.exit(1)
|
||||
if not secret:
|
||||
|
@ -23,6 +23,14 @@ class Keystore:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def lock(self, address=None):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def unlock(self, address=None):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def new(self, password=None):
|
||||
self.private_key_generator(password=password)
|
||||
|
||||
|
8
setup.py
8
setup.py
@ -38,12 +38,12 @@ setup(
|
||||
author="Louis Holbrook",
|
||||
author_email="dev@holbrook.no",
|
||||
packages=[
|
||||
'funga',
|
||||
'funga.eth.signer',
|
||||
'funga.eth',
|
||||
'funga.cli',
|
||||
'funga.keystore',
|
||||
'funga.runnable',
|
||||
'funga',
|
||||
'funga.eth.cli',
|
||||
'funga.eth.keystore',
|
||||
'funga.eth.runnable',
|
||||
],
|
||||
install_requires=requirements,
|
||||
extras_require={
|
||||
|
Loading…
Reference in New Issue
Block a user