From 5db644222b75817e03f40010c474c429826eb40c Mon Sep 17 00:00:00 2001
From: Aditya Patil <ad1tya.patil.3297@gmail.com>
Date: Sat, 11 Nov 2023 11:21:35 +0530
Subject: [PATCH] Fix auth header string and optimise code

---
 utilities/signing_and_verification/cryptic_utils.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/utilities/signing_and_verification/cryptic_utils.py b/utilities/signing_and_verification/cryptic_utils.py
index 651824e..b1ad6fc 100644
--- a/utilities/signing_and_verification/cryptic_utils.py
+++ b/utilities/signing_and_verification/cryptic_utils.py
@@ -69,12 +69,11 @@ def create_authorisation_header(request_body=request_body_raw_text, created=None
     signing_key = create_signing_string(hash_message(request_body),
                                         created=created, expires=expires)
     signature = sign_response(signing_key, private_key=os.getenv("PRIVATE_KEY"))
-    #signature = sign_response(signing_key, private_key="unkLJfHZRmKf88Ac5zv6Wb5caVbYN9Uav0XJ5OOyitdbVo4xZhS8g23JLKY9Ve66uAAL/zrl0PGjpwkvp0d3eA==")
 
     subscriber_id = os.getenv("SUBSCRIBER_ID", "buyer-app.ondc.org")
     unique_key_id = os.getenv("UNIQUE_KEY_ID", "207")
-    header = f'"Signature keyId=\\"{subscriber_id}|{unique_key_id}|ed25519\\",algorithm=\\"ed25519\\",created=' \
-             f'\\"{created}\\",expires=\\"{expires}\\",headers=\\"(created) (expires) digest\\",signature=\\"{signature}\\""'
+    header = f'"Signature keyId="{subscriber_id}|{unique_key_id}|ed25519",algorithm="ed25519",created=' \
+             f'"{created}",expires="{expires}",headers="(created) (expires) digest",signature="{signature}""'
     return header
 
 
@@ -120,6 +119,7 @@ def generate_key_pairs():
             "Crypto_Privatekey": crypto_private_key,
             "Crypto_Publickey": crypto_public_key}
 
+
 def encrypt(crypto_private_key, crypto_public_key, null):
     private_key = serialization.load_der_private_key(
         base64.b64decode(crypto_private_key),
@@ -133,6 +133,7 @@ def encrypt(crypto_private_key, crypto_public_key, null):
     text = b'ONDC is a Great Initiative!!'
     return base64.b64encode(cipher.encrypt(pad(text,AES.block_size))).decode('utf-8')
 
+
 def decrypt(crypto_private_key, crypto_public_key, cipherstring):
     private_key = serialization.load_der_private_key(
         base64.b64decode(crypto_private_key),
@@ -147,5 +148,6 @@ def decrypt(crypto_private_key, crypto_public_key, cipherstring):
     # print(AES.block_size, len(ciphertxt))
     return unpad(cipher.decrypt(ciphertxt), AES.block_size).decode('utf-8')
 
+
 if __name__ == '__main__':
     fire.Fire()