Added signatures to appointment

This commit is contained in:
Salvatore Ingala
2019-10-10 16:38:34 +07:00
parent b74df42a2b
commit 99db9a29ad
5 changed files with 21 additions and 5 deletions

6
apps/generate_key.py Normal file
View File

@@ -0,0 +1,6 @@
import ecdsa
if __name__ == '__main__':
sk = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1)
print(sk.to_der())

View File

@@ -30,12 +30,12 @@ def add_appointment():
appointment = inspector.inspect(request_data)
if type(appointment) == Appointment:
appointment_added = watcher.add_appointment(appointment)
appointment_added, signature = watcher.add_appointment(appointment)
# ToDo: #13-create-server-side-signature-receipt
if appointment_added:
rcode = HTTP_OK
response = "appointment accepted. locator: {}".format(appointment.locator)
response = "appointment accepted. locator: {}. signature: {}".format(appointment.locator, signature)
else:
rcode = HTTP_SERVICE_UNAVAILABLE
response = "appointment rejected"

View File

@@ -1,3 +1,5 @@
import json
from pisa.encrypted_blob import EncryptedBlob
@@ -22,3 +24,5 @@ class Appointment:
# ToDO: #3-improve-appointment-structure
def serialize(self):
return json.dumps(self.to_json())

View File

@@ -1,4 +1,5 @@
zmq
flask
cryptography
ecdsa
requests

View File

@@ -1,12 +1,12 @@
from uuid import uuid4
from queue import Queue
from threading import Thread
import ecdsa
from pisa.logger import Logger
from pisa.cleaner import Cleaner
from pisa.conf import EXPIRY_DELTA
from pisa.conf import EXPIRY_DELTA, MAX_APPOINTMENTS, SIGNING_KEY_DER
from pisa.responder import Responder
from pisa.conf import MAX_APPOINTMENTS
from pisa.block_processor import BlockProcessor
from pisa.utils.zmq_subscriber import ZMQHandler
@@ -22,6 +22,7 @@ class Watcher:
self.max_appointments = max_appointments
self.zmq_subscriber = None
self.responder = Responder()
self.sk = ecdsa.SigningKey.from_der(SIGNING_KEY_DER)
def add_appointment(self, appointment):
# Rationale:
@@ -31,6 +32,8 @@ class Watcher:
# If the watcher is awake, every new appointment will just be added to the appointment list until
# max_appointments is reached.
signature = None
if len(self.appointments) < self.max_appointments:
# Appointments are identified by the locator: the sha256 of commitment txid (H(tx_id)).
# Two different nodes may ask for appointments using the same commitment txid, what will result in a
@@ -60,12 +63,14 @@ class Watcher:
logger.info("New appointment accepted.", locator=appointment.locator)
signature = self.sk.sign(appointment.serialize().encode('utf8'))
else:
appointment_added = False
logger.info("Maximum appointments reached, appointment rejected.", locator=appointment.locator)
return appointment_added
return (appointment_added, signature)
def do_subscribe(self):
self.zmq_subscriber = ZMQHandler(parent="Watcher")