commit 5810ce25a3b92a499e5a709fb16b4b44aad82d76
parent ba5bc5f985885458e4ebfc8ad180f5906e3f4645
Author: nolash <dev@holbrook.no>
Date: Fri, 25 Dec 2020 09:21:09 +0100
Fix crash on unknown account sign
Diffstat:
6 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+* 0.4.8
+ - Fix server crash on sign request for unknown key
* 0.4.7
- Upgrade dependencies
* 0.4.6
diff --git a/crypto_dev_signer/error.py b/crypto_dev_signer/error.py
@@ -0,0 +1,2 @@
+class UnknownAccountError(Exception):
+ pass
diff --git a/crypto_dev_signer/keystore/postgres.py b/crypto_dev_signer/keystore/postgres.py
@@ -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)
diff --git a/crypto_dev_signer/runnable/signer.py b/crypto_dev_signer/runnable/signer.py
@@ -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()
diff --git a/setup.py b/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",
diff --git a/test/test_keystore.py b/test/test_keystore.py
@@ -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()