Skip to content

Commit 305b1b7

Browse files
authored
fix cat-id generation for the signed docs (#2371)
1 parent 9314d8e commit 305b1b7

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import sys
2-
from loguru import logger
32
import os
43

54
try:
6-
os.environ["EVENT_DB_TEST_URL"]
5+
os.environ["EVENT_DB_TEST_URL"]
76
except KeyError:
8-
print("Please set the environment variable EVENT_DB_TEST_URL")
9-
sys.exit(1)
7+
print("Please set the environment variable EVENT_DB_TEST_URL")
8+
sys.exit(1)
109

1110
EVENT_DB_TEST_URL = os.environ["EVENT_DB_TEST_URL"]
12-

catalyst-gateway/tests/api_tests/utils/rbac_chain.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def cat_id_for_role(self, role_id: RoleID) -> (str, str):
4242
role_id,
4343
role_0_pk,
4444
role_data["rotation"],
45+
True,
4546
),
4647
role_data["sk"],
4748
)
@@ -63,18 +64,22 @@ def __rbac_chain_factory(role_id: RoleID) -> RBACChain:
6364

6465

6566
def generate_cat_id(
66-
network: str, subnet: str, role_id: RoleID, pk_hex: str, rotation: int
67+
network: str, subnet: str, role_id: RoleID, pk_hex: str, rotation: int, is_uri: bool
6768
):
6869
pk = bytes.fromhex(pk_hex)[:32]
69-
prefix = "catid.:"
7070
nonce = int(datetime.now(timezone.utc).timestamp())
7171
subnet = f"{subnet}." if subnet else ""
7272
role0_pk_b64 = base64_url(pk)
7373

7474
if role_id == RoleID.ROLE_0 and rotation == 0:
75-
return f"{prefix}{nonce}@{subnet}{network}/{role0_pk_b64}"
75+
res = f"{nonce}@{subnet}{network}/{role0_pk_b64}"
76+
else:
77+
res = f"{nonce}@{subnet}{network}/{role0_pk_b64}/{role_id}/{rotation}"
7678

77-
return f"{prefix}{nonce}@{subnet}{network}/{role0_pk_b64}/{role_id}/{rotation}"
79+
if is_uri:
80+
res = f"id.catalyst://{res}"
81+
82+
return res
7883

7984

8085
def generate_rbac_auth_token(
@@ -90,13 +95,14 @@ def generate_rbac_auth_token(
9095
bip32_ed25519_sk = BIP32ED25519PrivateKey(sk, chain_code)
9196
bip32_ed25519_pk = BIP32ED25519PublicKey(pk, chain_code)
9297

93-
cat_id = generate_cat_id(network, subnet, RoleID.ROLE_0, pk_hex, 0)
98+
token_prefix = "catid.:"
99+
cat_id = generate_cat_id(network, subnet, RoleID.ROLE_0, pk_hex, 0, False)
94100

95101
signature = bip32_ed25519_sk.sign(cat_id.encode())
96102
bip32_ed25519_pk.verify(signature, cat_id.encode())
97103
signature_b64 = base64_url(signature)
98104

99-
return f"{cat_id}.{signature_b64}"
105+
return f"{token_prefix}{cat_id}.{signature_b64}"
100106

101107

102108
def base64_url(data: bytes) -> str:

0 commit comments

Comments
 (0)