broadfield-dev commited on
Commit
5b92625
·
verified ·
1 Parent(s): 6feefab

Update server/server.py

Browse files
Files changed (1) hide show
  1. server/server.py +6 -0
server/server.py CHANGED
@@ -117,11 +117,17 @@ def decode_data(image_base64_string: str) -> dict:
117
  ciphertext_with_tag = crypto_payload[offset:]
118
  recovered_aes_key = PRIVATE_KEY_OBJECT.decrypt(encrypted_aes_key, padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None))
119
  decrypted_bytes = AESGCM(recovered_aes_key).decrypt(nonce, ciphertext_with_tag, None)
 
 
120
  decrypted_payload = json.loads(decrypted_bytes.decode('utf-8'))
121
  logger.info(f"Successfully decoded payload: {decrypted_payload}")
 
 
122
  api_key = decrypted_payload.get('API_KEY')
123
  user_id = decrypted_payload.get('USER')
 
124
  is_authenticated = example_authenticate(api_key=api_key, user_id=user_id)
 
125
  if is_authenticated:
126
  return {
127
  "authentication_status": "Success",
 
117
  ciphertext_with_tag = crypto_payload[offset:]
118
  recovered_aes_key = PRIVATE_KEY_OBJECT.decrypt(encrypted_aes_key, padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None))
119
  decrypted_bytes = AESGCM(recovered_aes_key).decrypt(nonce, ciphertext_with_tag, None)
120
+
121
+ # Symmetrical decoding: json.loads correctly parses the JSON string into a Python dict.
122
  decrypted_payload = json.loads(decrypted_bytes.decode('utf-8'))
123
  logger.info(f"Successfully decoded payload: {decrypted_payload}")
124
+
125
+ # The values retrieved are now clean Python strings, ready for direct use.
126
  api_key = decrypted_payload.get('API_KEY')
127
  user_id = decrypted_payload.get('USER')
128
+
129
  is_authenticated = example_authenticate(api_key=api_key, user_id=user_id)
130
+
131
  if is_authenticated:
132
  return {
133
  "authentication_status": "Success",