22from core .requests import http_request
33from core .crypto import create_signature
44from core .constants import (
5- ML_DSA_87_NAME
5+ ML_DSA_87_NAME ,
6+ CHALLENGE_LEN
67)
78
89def 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