-
Notifications
You must be signed in to change notification settings - Fork 0
/
authheadercomp.py
47 lines (40 loc) · 1.38 KB
/
authheadercomp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import nacl.encoding
import nacl.hash
# Data from the provided JSON
country = "IND"
city = "*"
type_ = "BPP"
subscriber_id = "snoondcogl.snoo.gl"
subscriber_url = "https://snoondcogl.snoo.gl"
domain = "nic2004:52110"
signing_public_key = "ARVbt6qGfrCWdaoqNQfXodgvCOO7XbZf5/Liq0MJwg8="
encr_public_key = "drVJSE7Xh/gBhk4dy/EgNe9M9Qz71BaynaiANIhjkRc="
created = "2023-06-06T21:05:52.470Z2"
valid_from = "2023-06-06T21:05:52.470Z3"
valid_until = "2050-06-01T11:59:59.470Z7"
updated = "2023-06-06T21:05:52.470Z3"
# Step 1: Generate the auth header
auth_header = f'keyId="{subscriber_id}|{domain}|ed25519"'
# Step 2: Generate the payload as a JSON string
payload = {
"country": country,
"city": city,
"type": type_,
"subscriber_id": subscriber_id,
"subscriber_url": subscriber_url,
"domain": domain,
"signing_public_key": signing_public_key,
"encr_public_key": encr_public_key,
"created": created,
"valid_from": valid_from,
"valid_until": valid_until,
"updated": updated
}
# Step 3: Convert the payload to a UTF-8 byte array
payload_bytes = str(payload).encode("utf-8")
# Step 4: Generate the Blake2b hash of the payload
digest = nacl.hash.blake2b(payload_bytes, encoder=nacl.encoding.Base64Encoder)
# Step 5: Add the digest to the authorization header
auth_header += f', digest="{digest.decode()}"'
# Print the auth header
print("Authorization Header:", auth_header)