diff --git a/examples/UbirchWrapper.py b/examples/UbirchWrapper.py index b6199b3..043f3a1 100644 --- a/examples/UbirchWrapper.py +++ b/examples/UbirchWrapper.py @@ -6,9 +6,6 @@ import ubirch from ubirch.ubirch_protocol import UNPACKED_UPP_FIELD_PREV_SIG, UBIRCH_PROTOCOL_TYPE_REG, UBIRCH_PROTOCOL_TYPE_BIN -# from ubirch_keys_and_uuids import UBIRCH_UUIDS, UBIRCH_PUBKEYS_EC, UBIRCH_PUBKEYS_ED -# from ubirch.ubirch_backend_keys import * - ECDSA_TYPE = "ecdsa" EDDSA_TYPE = "ed25519" @@ -53,22 +50,16 @@ def __init__(self, key_store: ubirch.KeyStore, uuid: UUID, env: str, key_type: s raise ValueError(f"existing key for {uuid} is not from expected type {key_type}") # check env - if env not in ubirch.getBackendEnvironemts(): - raise ValueError("Invalid ubirch env! Must be one of {}".format(list(ubirch.getBackendEnvironemts()))) + if env not in ubirch.get_backend_environments(): + raise ValueError("Invalid ubirch env! Must be one of {}".format(ubirch.get_backend_environments())) - # check if the keystore has the same key_type for the device UUID and the backend response + # insert key for backend response signature verification into keystore if key_type == ECDSA_TYPE: - if self.__ks._ks.entries.get(ubirch.getBackendUuid(env).hex, None) != None: - # suffix-less pubkey found, delete it - self.__ks._ks.entries.pop(ubirch.getBackendUuid(env).hex) - - self.__ks.insert_ecdsa_verifying_key(ubirch.getBackendUuid(env), ubirch.getBackendKeys(env,ECDSA_TYPE)) + self.__ks.insert_ecdsa_verifying_key(ubirch.get_backend_uuid(env), + ubirch.get_backend_verifying_key(env, ECDSA_TYPE)) elif key_type == EDDSA_TYPE: - if self.__ks._ks.entries.get(ubirch.getBackendUuid(env).hex + '_ecd', None) != None: - # suffix-less pubkey found, delete it - self.__ks._ks.entries.pop(ubirch.getBackendUuid(env).hex + '_ecd') - - self.__ks.insert_ed25519_verifying_key(ubirch.getBackendUuid(env), ubirch.getBackendKeys(env,EDDSA_TYPE)) + self.__ks.insert_ed25519_verifying_key(ubirch.get_backend_uuid(env), + ubirch.get_backend_verifying_key(env, EDDSA_TYPE)) # load last signature for device self.load(uuid) @@ -80,7 +71,6 @@ def persist(self, uuid: UUID): with open(uuid.hex + ".sig", "wb") as f: pickle.dump(signatures, f) - #===== The functions below are called from inside ubirch.Protocol ====# def load(self, uuid: UUID): try: with open(uuid.hex + ".sig", "rb") as f: @@ -91,6 +81,7 @@ def load(self, uuid: UUID): logger.warning("no existing saved signatures") pass + #===== The functions below are called from inside ubirch.Protocol ====# def _sign(self, uuid: UUID, message: bytes) -> bytes: signing_key = self.__ks.find_signing_key(uuid) @@ -225,7 +216,7 @@ def handleMessageResponse(self, response: Response): def verifyResponseSender(self, response: Response): """! Verify that the response came from the backend """ - if self.protocol.verify_signature(ubirch.getBackendUuid(self.env), response.content) == True: + if self.protocol.verify_signature(ubirch.get_backend_uuid(self.env), response.content): logger.info("Backend response signature successfully verified!") else: logger.error("Backend response signature verification FAILED!") diff --git a/ubirch/__init__.py b/ubirch/__init__.py index f9ecabe..1928072 100644 --- a/ubirch/__init__.py +++ b/ubirch/__init__.py @@ -17,4 +17,4 @@ from .ubirch_ks import KeyStore from .ubirch_protocol import Protocol from .ubirch_api import API -from .ubirch_backend_keys import getBackendKeys, getBackendUuid, getBackendEnvironemts +from .ubirch_backend_keys import get_backend_verifying_key, get_backend_uuid, get_backend_environments diff --git a/ubirch/ubirch_backend_keys.py b/ubirch/ubirch_backend_keys.py index ccf0c8c..9d2e048 100644 --- a/ubirch/ubirch_backend_keys.py +++ b/ubirch/ubirch_backend_keys.py @@ -1,6 +1,6 @@ ## -# @file ubirch_backen_keys.py +# @file ubirch_backend_keys.py # ubirch backend keys getter functions # # @author Waldemar Gruenwald @@ -29,7 +29,7 @@ "dev":{ "uuid":"9d3c78ff-22f3-4441-a5d1-85c636d486ff", "vk":{ - "ed25519":"39ff77632b034d0eba6d219c2ff192e9f24916c9a02672acb49fd05118aad251", + "ed25519":"a2403b92bc9add365b3cd12ff120d020647f84ea6983f98bc4c87e0f4be8cd66", "ecdsa":"2e753c064bc671940fcb98165542fe3c70340cff5d53ad47f0304ef2166f4f223b9572251b5fe8aee54c4fb812da79590caf501beba0911b7fcd3add2eb0180c" } }, @@ -49,14 +49,14 @@ } } -def getBackendEnvironemts() -> list: +def get_backend_environments() -> list: """! Getter to list the available backend environments. @return available Environments """ - return KEYS.keys() + return list(KEYS.keys()) -def getBackendUuid(env: str = "demo") -> UUID: +def get_backend_uuid(env: str = "demo") -> UUID: """! Getter function for environment (`env`) specific backend UUID @param env Environment of the backend, can be `"dev"`, `"demo"`, or `"prod"`. Default is `"demo"` @@ -64,7 +64,7 @@ def getBackendUuid(env: str = "demo") -> UUID: """ return UUID(hex=KEYS[env]["uuid"]) -def getBackendKeys(env: str = "demo", key_type: str = EDDSA_TYPE) -> ed25519.VerifyingKey or ecdsa.VerifyingKey: +def get_backend_verifying_key(env: str = "demo", key_type: str = EDDSA_TYPE) -> ed25519.VerifyingKey or ecdsa.VerifyingKey: """! Getter function for environment (`env`) specific backend verification key @param env Environment of the backend, can be `"dev"`, `"demo"`, or `"prod"`. Default is `"demo"`