Skip to content

Commit

Permalink
Merge pull request #46 from ONDC-Official/fix/signing-and-verification
Browse files Browse the repository at this point in the history
Fix auth header string and optimise code
  • Loading branch information
navdeep710 authored Nov 11, 2023
2 parents 4f9690c + 5db6442 commit a9e5502
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions utilities/signing_and_verification/cryptic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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()

0 comments on commit a9e5502

Please sign in to comment.