Skip to content

Commit e832d98

Browse files
committed
fix: update shared constants to reflect new NIST sizes
1 parent f5a4b07 commit e832d98

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

core/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
LONGPOLL_MAX = 30
1111

1212
# crypto parameters (bytes)
13+
CHALLENGE_LEN = 11264
14+
1315
AES_GCM_NONCE_LEN = 12
1416

1517
OTP_PAD_SIZE = 11264

logic/authentication.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from core.requests import http_request
33
from core.crypto import create_signature
44
from core.constants import (
5-
ML_DSA_87_NAME
5+
ML_DSA_87_NAME,
6+
CHALLENGE_LEN
67
)
78

89
def authenticate_account(user_data: dict) -> dict:
@@ -11,26 +12,26 @@ def authenticate_account(user_data: dict) -> dict:
1112
private_key = user_data["lt_auth_sign_keys"]["private_key"]
1213
public_key_encoded = user_data["lt_auth_sign_keys"]["public_key"]
1314
public_key_encoded = b64encode(public_key_encoded).decode()
15+
user_id = user_data.get("user_id") or ""
1416

1517
try:
16-
user_id = user_data.get("user_id") or ""
17-
1818
response = http_request(url + "/authenticate/init", "POST", payload = {"public_key": public_key_encoded, "user_id": user_id })
19-
if not 'challenge' in response:
20-
raise ValueError("Server did not give authenticatation challenge! Are you sure this is a Coldwire server ?")
2119
except Exception:
2220
if user_data["settings"]["proxy_info"] is not None:
2321
raise ValueError("Could not connect to server! Are you sure your proxy settings are valid ?")
2422
else:
2523
raise ValueError("Could not connect to server! Are you sure the URL is valid ?")
2624

25+
if not 'challenge' in response:
26+
raise ValueError("Server did not give authenticatation challenge! Are you sure this is a Coldwire server ?")
27+
2728
try:
2829
challenge = b64decode(response["challenge"], validate=True)
2930
except Exception:
3031
raise ValueError("Server gave a malformed challenge! Are you sure this is Coldwire server ?")
3132

3233

33-
signature = create_signature(ML_DSA_87_NAME, challenge, private_key)
34+
signature = create_signature(ML_DSA_87_NAME, challenge[:CHALLENGE_LEN], private_key)
3435

3536
try:
3637
response = http_request(url + "/authenticate/verify", "POST", payload = {"signature": b64encode(signature).decode(), "challenge": response["challenge"]})

0 commit comments

Comments
 (0)