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