From 1601f0ca15aff9db297f1aff2f59dddedbe33f83 Mon Sep 17 00:00:00 2001 From: Salvatore Ingala <6681844+bigspider@users.noreply.github.com> Date: Tue, 22 Oct 2019 12:13:12 +0800 Subject: [PATCH] Renamed constants and default file names for Pisa's private and public keys --- apps/cli/__init__.py | 2 +- apps/cli/pisa-cli.py | 6 ++---- apps/generate_key.py | 6 +++--- pisa/sample_conf.py | 2 +- pisa/watcher.py | 6 +++--- test/unit/test_watcher.py | 4 ++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/apps/cli/__init__.py b/apps/cli/__init__.py index 0be0f2a..c7f8d90 100644 --- a/apps/cli/__init__.py +++ b/apps/cli/__init__.py @@ -11,7 +11,7 @@ CLIENT_LOG_FILE = 'pisa.log' SUPPORTED_HASH_FUNCTIONS = ["SHA256"] SUPPORTED_CIPHERS = ["AES-GCM-128"] -PUBLIC_KEY_FILE = "signing_key_pub.pem" +PISA_PUBLIC_KEY = "pisa_pk.pem" # Configure logging logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=[ diff --git a/apps/cli/pisa-cli.py b/apps/cli/pisa-cli.py index 9989cdf..b6a4519 100644 --- a/apps/cli/pisa-cli.py +++ b/apps/cli/pisa-cli.py @@ -20,13 +20,13 @@ from pisa.appointment import Appointment from apps.cli.blob import Blob from apps.cli.help import help_add_appointment, help_get_appointment -from apps.cli import DEFAULT_PISA_API_SERVER, DEFAULT_PISA_API_PORT, PUBLIC_KEY_FILE +from apps.cli import DEFAULT_PISA_API_SERVER, DEFAULT_PISA_API_PORT, PISA_PUBLIC_KEY HTTP_OK = 200 logger = Logger("Client") -with open(PUBLIC_KEY_FILE, "r") as key_file: +with open(PISA_PUBLIC_KEY, "r") as key_file: pubkey_pem = key_file.read().encode("utf-8") pisa_public_key = load_pem_public_key(pubkey_pem, backend=default_backend()) @@ -88,8 +88,6 @@ def add_appointment(args): try: r = requests.post(url=add_appointment_endpoint, json=appointment.to_json(), timeout=5) - print(r.text) - logger.info("{} (code: {}).".format(r.json(), r.status_code)) response_json = r.json() diff --git a/apps/generate_key.py b/apps/generate_key.py index 7018aeb..e79a0a4 100644 --- a/apps/generate_key.py +++ b/apps/generate_key.py @@ -7,10 +7,10 @@ from cryptography.hazmat.primitives.asymmetric import ec # Simple tool to generate an ECDSA private key using the secp256k1 curve and save private and public keys -# as signing_key_priv.pem and signing_key_pub.pem +# as 'pisa_sk.pem' 'and pisa_pk.pem', respectively. -FILE_NAME_PRIV = 'signing_key_priv.pem' -FILE_NAME_PUB = 'signing_key_pub.pem' +FILE_NAME_PRIV = 'pisa_sk.pem' +FILE_NAME_PUB = 'pisa_pk.pem' def save_sk(sk, filename): diff --git a/pisa/sample_conf.py b/pisa/sample_conf.py index f5a3e5a..7406bfc 100644 --- a/pisa/sample_conf.py +++ b/pisa/sample_conf.py @@ -17,7 +17,7 @@ EXPIRY_DELTA = 6 MIN_DISPUTE_DELTA = 20 SERVER_LOG_FILE = 'pisa.log' DB_PATH = 'appointments/' -SIGNING_KEY_FILE = None +PISA_SECRET_KEY = 'pisa_sk.pem' # PISA-CLI CLIENT_LOG_FILE = 'pisa.log' diff --git a/pisa/watcher.py b/pisa/watcher.py index 91a9cf0..65058d3 100644 --- a/pisa/watcher.py +++ b/pisa/watcher.py @@ -9,7 +9,7 @@ from cryptography.hazmat.primitives.asymmetric import ec from pisa.logger import Logger from pisa.cleaner import Cleaner -from pisa.conf import EXPIRY_DELTA, MAX_APPOINTMENTS, SIGNING_KEY_FILE +from pisa.conf import EXPIRY_DELTA, MAX_APPOINTMENTS, PISA_SECRET_KEY from pisa.responder import Responder from pisa.block_processor import BlockProcessor from pisa.utils.zmq_subscriber import ZMQHandler @@ -27,10 +27,10 @@ class Watcher: self.zmq_subscriber = None self.responder = Responder() - if SIGNING_KEY_FILE is None: + if PISA_SECRET_KEY is None: raise ValueError("No signing key provided. Please fix your pisa.conf") else: - with open(SIGNING_KEY_FILE, "r") as key_file: + with open(PISA_SECRET_KEY, "r") as key_file: privkey_pem = key_file.read().encode("utf-8") self.signing_key = load_pem_private_key(privkey_pem, password=None, backend=default_backend()) diff --git a/test/unit/test_watcher.py b/test/unit/test_watcher.py index 411c634..0637157 100644 --- a/test/unit/test_watcher.py +++ b/test/unit/test_watcher.py @@ -22,7 +22,7 @@ from test.simulator.utils import sha256d from test.simulator.transaction import TX from test.unit.conftest import generate_block from pisa.utils.auth_proxy import AuthServiceProxy -from pisa.conf import EXPIRY_DELTA, BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT, SIGNING_KEY_FILE +from pisa.conf import EXPIRY_DELTA, BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT, PISA_SECRET_KEY logging.getLogger().disabled = True @@ -30,7 +30,7 @@ APPOINTMENTS = 5 START_TIME_OFFSET = 1 END_TIME_OFFSET = 1 -with open(SIGNING_KEY_FILE, "r") as key_file: +with open(PISA_SECRET_KEY, "r") as key_file: pubkey_pem = key_file.read().encode("utf-8") # TODO: should use the public key file instead, but it is not currently exported in the configuration signing_key = load_pem_private_key(pubkey_pem, password=None, backend=default_backend())