From fe054fd03c4c4f8a4325c617e74cea754e7cfbd3 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 7 Sep 2024 22:32:03 +0200 Subject: [PATCH] Added destination ratchet ID getter to API --- RNS/Identity.py | 20 +++++++++++++++++--- RNS/Transport.py | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/RNS/Identity.py b/RNS/Identity.py index 4a6802d..82108ec 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -213,7 +213,7 @@ class Identity: Get a SHA-256 hash of passed data. :param data: Data to be hashed as *bytes*. - :returns: SHA-256 hash as *bytes* + :returns: SHA-256 hash as *bytes*. """ return RNS.Cryptography.sha256(data) @@ -223,7 +223,7 @@ class Identity: Get a truncated SHA-256 hash of passed data. :param data: Data to be hashed as *bytes*. - :returns: Truncated SHA-256 hash as *bytes* + :returns: Truncated SHA-256 hash as *bytes*. """ return Identity.full_hash(data)[:(Identity.TRUNCATED_HASHLENGTH//8)] @@ -233,10 +233,24 @@ class Identity: Get a random SHA-256 hash. :param data: Data to be hashed as *bytes*. - :returns: Truncated SHA-256 hash of random data as *bytes* + :returns: Truncated SHA-256 hash of random data as *bytes*. """ return Identity.truncated_hash(os.urandom(Identity.TRUNCATED_HASHLENGTH//8)) + @staticmethod + def current_ratchet_id(destination_hash): + """ + Get the ID of the currently used ratchet key for a given destination hash + + :param destination_hash: A destination hash as *bytes*. + :returns: A ratchet ID as *bytes* or *None*. + """ + ratchet = Identity.get_ratchet(destination_hash) + if ratchet == None: + return None + else: + return Identity.truncated_hash(ratchet) + @staticmethod def _ratchet_public_bytes(ratchet): return X25519PrivateKey.from_private_bytes(ratchet).public_key().public_bytes() diff --git a/RNS/Transport.py b/RNS/Transport.py index f6c5c23..f0a0248 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -1709,6 +1709,7 @@ class Transport: except Exception as e: RNS.log("Error while processing external announce callback.", RNS.LOG_ERROR) RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR) + RNS.trace_exception(e) # Handling for link requests to local destinations elif packet.packet_type == RNS.Packet.LINKREQUEST: