Fix crash on unknown account sign
This commit is contained in:
parent
ba5bc5f985
commit
5810ce25a3
@ -1,3 +1,5 @@
|
||||
* 0.4.8
|
||||
- Fix server crash on sign request for unknown key
|
||||
* 0.4.7
|
||||
- Upgrade dependencies
|
||||
* 0.4.6
|
||||
|
2
crypto_dev_signer/error.py
Normal file
2
crypto_dev_signer/error.py
Normal file
@ -0,0 +1,2 @@
|
||||
class UnknownAccountError(Exception):
|
||||
pass
|
@ -15,6 +15,7 @@ import sha3
|
||||
from .interface import Keystore
|
||||
from crypto_dev_signer.common import strip_hex_prefix
|
||||
from . import keyapi
|
||||
from crypto_dev_signer.error import UnknownAccountError
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger(__file__)
|
||||
@ -59,7 +60,10 @@ class ReferenceKeystore(Keystore):
|
||||
'a': safe_address,
|
||||
},
|
||||
)
|
||||
try:
|
||||
k = r.first()[0]
|
||||
except TypeError:
|
||||
raise UnknownAccountError(address)
|
||||
return self._decrypt(k, password)
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@ from jsonrpc.exceptions import *
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner
|
||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
||||
from crypto_dev_signer.keystore import ReferenceKeystore
|
||||
from crypto_dev_signer.error import UnknownAccountError
|
||||
|
||||
#logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@ -198,6 +199,9 @@ def start_server():
|
||||
# TODO: handle cases to give better error context to caller
|
||||
logg.error('process error {}'.format(e))
|
||||
csock.send(json.dumps(jsonrpc_error(j['id'], JSONRPCServerError)).encode('utf-8'))
|
||||
except UnknownAccountError as e:
|
||||
logg.error('process unknown account error {}'.format(e))
|
||||
csock.send(json.dumps(jsonrpc_error(j['id'], JSONRPCServerError)).encode('utf-8'))
|
||||
|
||||
csock.close()
|
||||
s.close()
|
||||
|
2
setup.py
2
setup.py
@ -24,7 +24,7 @@ f.close()
|
||||
|
||||
setup(
|
||||
name="crypto-dev-signer",
|
||||
version="0.4.7",
|
||||
version="0.4.8",
|
||||
description="A signer and keystore daemon and library for cryptocurrency software development",
|
||||
author="Louis Holbrook",
|
||||
author_email="dev@holbrook.no",
|
||||
|
@ -4,6 +4,7 @@
|
||||
import unittest
|
||||
import logging
|
||||
import base64
|
||||
import os
|
||||
|
||||
# third-party imports
|
||||
import psycopg2
|
||||
@ -12,6 +13,7 @@ from cryptography.fernet import Fernet, InvalidToken
|
||||
|
||||
# local imports
|
||||
from crypto_dev_signer.keystore import ReferenceKeystore
|
||||
from crypto_dev_signer.error import UnknownAccountError
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@ -52,6 +54,10 @@ class TestDatabase(unittest.TestCase):
|
||||
with self.assertRaises(InvalidToken):
|
||||
self.db.get(self.address_hex, 'bar')
|
||||
|
||||
bogus_account = '0x' + os.urandom(20).hex()
|
||||
with self.assertRaises(UnknownAccountError):
|
||||
self.db.get(bogus_account, 'bar')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user