mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 06:34:19 +01:00
Updates cli to use the new key formats
This commit is contained in:
@@ -5,9 +5,10 @@ import requests
|
||||
import time
|
||||
import binascii
|
||||
from sys import argv
|
||||
from uuid import uuid4
|
||||
from coincurve import PublicKey
|
||||
from getopt import getopt, GetoptError
|
||||
from requests import ConnectTimeout, ConnectionError
|
||||
from uuid import uuid4
|
||||
|
||||
from apps.cli import config, LOG_PREFIX
|
||||
from apps.cli.help import help_add_appointment, help_get_appointment
|
||||
@@ -63,7 +64,7 @@ common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=LOG_
|
||||
|
||||
def load_keys():
|
||||
PISA_PUBLIC_KEY = "3056301006072a8648ce3d020106052b8104000a0342000430053e39c53b8bcb43354a4ed886b8082af1d1e8fc14956e60ad0592bfdfab511b7e309f6ac83b7495462196692e145bf7b1a321e96ec8fc4d678719c77342da"
|
||||
pisa_pk = Cryptographer.load_public_key_der(binascii.unhexlify(PISA_PUBLIC_KEY))
|
||||
pisa_pk = PublicKey(binascii.unhexlify(PISA_PUBLIC_KEY))
|
||||
|
||||
return pisa_pk
|
||||
|
||||
@@ -161,7 +162,8 @@ def add_appointment(args):
|
||||
logger.error("The response does not contain the signature of the appointment")
|
||||
return False
|
||||
|
||||
if not Cryptographer.verify(appointment.serialize(), signature, pisa_pk):
|
||||
rpk = Cryptographer.recover_pk(appointment.serialize(), signature)
|
||||
if not Cryptographer.verify_rpk(pisa_pk, rpk):
|
||||
logger.error("The returned appointment's signature is invalid")
|
||||
return False
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import responses
|
||||
import json
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
from binascii import hexlify
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import ec
|
||||
import responses
|
||||
from coincurve import PrivateKey
|
||||
|
||||
import common.cryptographer
|
||||
from common.logger import Logger
|
||||
@@ -21,18 +17,9 @@ from test.apps.cli.unit.conftest import get_random_value_hex
|
||||
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix=wt_cli.LOG_PREFIX)
|
||||
|
||||
# dummy keys for the tests
|
||||
dummy_sk = ec.generate_private_key(ec.SECP256K1, default_backend())
|
||||
dummy_pk = dummy_sk.public_key()
|
||||
another_sk = ec.generate_private_key(ec.SECP256K1, default_backend())
|
||||
|
||||
dummy_sk_der = dummy_sk.private_bytes(
|
||||
encoding=serialization.Encoding.DER,
|
||||
format=serialization.PrivateFormat.TraditionalOpenSSL,
|
||||
encryption_algorithm=serialization.NoEncryption(),
|
||||
)
|
||||
dummy_pk_der = dummy_pk.public_bytes(
|
||||
encoding=serialization.Encoding.DER, format=serialization.PublicFormat.SubjectPublicKeyInfo
|
||||
)
|
||||
dummy_sk = PrivateKey()
|
||||
dummy_pk = dummy_sk.public_key
|
||||
another_sk = PrivateKey()
|
||||
|
||||
|
||||
# Replace the key in the module with a key we control for the tests
|
||||
@@ -69,14 +56,6 @@ def load_dummy_keys(*args):
|
||||
return dummy_pk
|
||||
|
||||
|
||||
def get_dummy_pisa_pk_der(*args):
|
||||
return dummy_pk_der
|
||||
|
||||
|
||||
def get_dummy_hex_pk_der(*args):
|
||||
return hexlify(get_dummy_pisa_pk_der())
|
||||
|
||||
|
||||
def get_dummy_signature(*args):
|
||||
return Cryptographer.sign(dummy_appointment.serialize(), dummy_sk)
|
||||
|
||||
@@ -90,7 +69,7 @@ def get_bad_signature(*args):
|
||||
# private_key_file_path = "sk_test_file"
|
||||
# public_key_file_path = "pk_test_file"
|
||||
# with open(private_key_file_path, "wb") as f:
|
||||
# f.write(dummy_sk_der)
|
||||
# f.write(dummy_sk.to_der())
|
||||
# with open(public_key_file_path, "wb") as f:
|
||||
# f.write(dummy_pk_der)
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user