Fix crash on unknown account sign

This commit is contained in:
nolash 2020-12-25 09:21:09 +01:00
parent ba5bc5f985
commit 5810ce25a3
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,5 @@
* 0.4.8
- Fix server crash on sign request for unknown key
* 0.4.7
- Upgrade dependencies
* 0.4.6

View File

@ -0,0 +1,2 @@
class UnknownAccountError(Exception):
pass

View File

@ -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,
},
)
k = r.first()[0]
try:
k = r.first()[0]
except TypeError:
raise UnknownAccountError(address)
return self._decrypt(k, password)

View File

@ -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()

View File

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

View File

@ -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()