From 76f86f782a90b0bda14f25a9dfb2ed06d45077bd Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 8 Jun 2022 12:37:24 +0200 Subject: [PATCH] Moved Destination Fernet to internal implementation --- RNS/Destination.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/RNS/Destination.py b/RNS/Destination.py index 90839b2..ae2143b 100755 --- a/RNS/Destination.py +++ b/RNS/Destination.py @@ -20,13 +20,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -import base64 import math import time import RNS -from cryptography.fernet import Fernet -from cryptography.hazmat.backends import default_backend +from RNS.Cryptography import Fernet class Callbacks: def __init__(self): @@ -311,8 +309,8 @@ class Destination: raise TypeError("A single destination holds keys through an Identity instance") if self.type == Destination.GROUP: - self.prv_bytes = base64.urlsafe_b64decode(Fernet.generate_key()) - self.prv = Fernet(base64.urlsafe_b64encode(self.prv_bytes)) + self.prv_bytes = Fernet.generate_key() + self.prv = Fernet(self.prv_bytes) def get_private_key(self): @@ -344,7 +342,7 @@ class Destination: if self.type == Destination.GROUP: self.prv_bytes = key - self.prv = Fernet(base64.urlsafe_b64encode(self.prv_bytes)) + self.prv = Fernet(self.prv_bytes) def load_public_key(self, key): if self.type != Destination.SINGLE: @@ -369,7 +367,7 @@ class Destination: if self.type == Destination.GROUP: if hasattr(self, "prv") and self.prv != None: try: - return base64.urlsafe_b64decode(self.prv.encrypt(plaintext)) + return self.prv.encrypt(plaintext) except Exception as e: RNS.log("The GROUP destination could not encrypt data", RNS.LOG_ERROR) RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR) @@ -394,7 +392,7 @@ class Destination: if self.type == Destination.GROUP: if hasattr(self, "prv") and self.prv != None: try: - return self.prv.decrypt(base64.urlsafe_b64encode(ciphertext)) + return self.prv.decrypt(ciphertext) except Exception as e: RNS.log("The GROUP destination could not decrypt data", RNS.LOG_ERROR) RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)