diff --git a/apps/cli/pisa_cli.py b/apps/cli/pisa_cli.py index c793b96..0f2eb92 100644 --- a/apps/cli/pisa_cli.py +++ b/apps/cli/pisa_cli.py @@ -21,6 +21,7 @@ from apps.cli import ( ) from common.logger import Logger +from common.appointment import Appointment from common.constants import LOCATOR_LEN_HEX from common.cryptographer import Cryptographer from common.tools import check_sha256_hex_format @@ -128,13 +129,7 @@ def add_appointment(args): return False add_appointment_endpoint = "http://{}:{}".format(pisa_api_server, pisa_api_port) - appointment = build_appointment( - appointment_data.get("tx"), - appointment_data.get("tx_id"), - appointment_data.get("start_time"), - appointment_data.get("end_time"), - appointment_data.get("to_self_delay"), - ) + appointment = Appointment.from_dict(appointment_data) try: sk_der = load_key_file_data(CLI_PRIVATE_KEY) @@ -152,7 +147,7 @@ def add_appointment(args): logger.error("I/O error", errno=e.errno, error=e.strerror) return False - signature = Cryptographer.sign(Cryptographer.signature_format(appointment), cli_sk) + signature = Cryptographer.sign(appointment.serialize(), cli_sk) try: cli_pk_der = load_key_file_data(CLI_PUBLIC_KEY) @@ -217,7 +212,7 @@ def add_appointment(args): logger.error("Failed to deserialize the public key. It might be in an unsupported format") return False - is_sig_valid = Cryptographer.verify(Cryptographer.signature_format(appointment), signature, pisa_pk) + is_sig_valid = Cryptographer.verify(appointment.serialize(), signature, pisa_pk) except FileNotFoundError: logger.error("Pisa's public key file not found. Please check your settings") @@ -278,24 +273,6 @@ def get_appointment(args): return True -def build_appointment(tx, tx_id, start_time, end_time, to_self_delay): - locator = compute_locator(tx_id) - - # FIXME: The blob data should contain more things that just the transaction. Leaving like this for now. - blob = Blob(tx) - encrypted_blob = Cryptographer.encrypt(blob, tx_id) - - appointment = { - "locator": locator, - "start_time": start_time, - "end_time": end_time, - "to_self_delay": to_self_delay, - "encrypted_blob": encrypted_blob, - } - - return appointment - - def show_usage(): return ( "USAGE: " diff --git a/pisa/api.py b/pisa/api.py index 2659e94..f0ec6ae 100644 --- a/pisa/api.py +++ b/pisa/api.py @@ -5,7 +5,7 @@ from flask import Flask, request, abort, jsonify from pisa import HOST, PORT, logging from common.logger import Logger from pisa.inspector import Inspector -from pisa.appointment import Appointment +from common.appointment import Appointment from pisa.block_processor import BlockProcessor from common.constants import HTTP_OK, HTTP_BAD_REQUEST, HTTP_SERVICE_UNAVAILABLE, LOCATOR_LEN_HEX diff --git a/pisa/builder.py b/pisa/builder.py index 063cb98..6f0f2bf 100644 --- a/pisa/builder.py +++ b/pisa/builder.py @@ -1,7 +1,7 @@ from queue import Queue from pisa.responder import TransactionTracker -from pisa.appointment import Appointment +from common.appointment import Appointment class Builder: diff --git a/pisa/inspector.py b/pisa/inspector.py index 54174cb..00a7fc2 100644 --- a/pisa/inspector.py +++ b/pisa/inspector.py @@ -7,7 +7,7 @@ from common.cryptographer import Cryptographer from pisa import errors import pisa.conf as conf from common.logger import Logger -from pisa.appointment import Appointment +from common.appointment import Appointment from pisa.block_processor import BlockProcessor logger = Logger("Inspector") @@ -309,12 +309,12 @@ class Inspector: @staticmethod # Verifies that the appointment signature is a valid signature with public key - def check_appointment_signature(appointment, signature, pk_der): + def check_appointment_signature(appointment_data, signature, pk_der): """ Checks if the provided user signature is correct. Args: - appointment (:obj:`dict`): the appointment that was signed by the user. + appointment_data (:obj:`dict`): the appointment that was signed by the user. signature (:obj:`str`): the user's signature (hex encoded). pk_der (:obj:`str`): the user's public key (hex encoded, DER format). @@ -336,7 +336,7 @@ class Inspector: message = "empty signature received" pk = Cryptographer.load_public_key_der(unhexlify(pk_der)) - valid_sig = Cryptographer.verify(Cryptographer.signature_format(appointment), signature, pk) + valid_sig = Cryptographer.verify(Appointment.from_dict(appointment_data).serialize(), signature, pk) if not valid_sig: rcode = errors.APPOINTMENT_INVALID_SIGNATURE diff --git a/pisa/watcher.py b/pisa/watcher.py index 5079050..9d659db 100644 --- a/pisa/watcher.py +++ b/pisa/watcher.py @@ -141,7 +141,7 @@ class Watcher: logger.info("New appointment accepted", locator=appointment.locator) - signature = Cryptographer.sign(Cryptographer.signature_format(appointment.to_dict()), self.signing_key) + signature = Cryptographer.sign(appointment.serialize(), self.signing_key) else: appointment_added = False