11"""
2+ logic/smp.py
3+ ----------
24 The socialist millionaire problem
35 A variant of Yao's millionaire problem
46
3436from logic .storage import save_account_data
3537from logic .contacts import save_contact
3638from logic .pfs import send_new_ephemeral_keys
37- from core .crypto import random_number_range , generate_sign_keys
39+ from core .crypto import generate_sign_keys
3840from core .trad_crypto import derive_key_argon2id , sha3_512
3941from base64 import b64encode , b64decode
4042import hashlib
4143import secrets
4244import hmac
43- import time
44- import copy
4545import logging
46- import json
4746
4847
4948logger = logging .getLogger (__name__ )
@@ -71,7 +70,7 @@ def initiate_smp(user_data: dict, user_data_lock, contact_id: str, question: str
7170 "recipient" : contact_id
7271
7372 }, auth_token = auth_token )
74- except :
73+ except Exception :
7574 raise ValueError ("Could not connect to server" )
7675
7776 if (not ("status" in response )) or response ["status" ] != "success" :
@@ -135,7 +134,7 @@ def smp_step_2_answer_provided(user_data, user_data_lock, contact_id, answer, ui
135134 "recipient" : contact_id
136135
137136 }, auth_token = auth_token )
138- except :
137+ except Exception :
139138 logger .error ("Failed to send proof request to server, either you are offline or the server is down" )
140139 smp_failure_notify_contact (user_data , user_data_lock , contact_id , ui_queue )
141140 return
@@ -217,11 +216,11 @@ def smp_step_3(user_data, user_data_lock, contact_id, message, ui_queue) -> None
217216 logger .debug ("Message to contact: %s" , our_message )
218217
219218 try :
220- response = http_request (f"{ server_url } /smp/step_3" , "POST" , payload = {
219+ http_request (f"{ server_url } /smp/step_3" , "POST" , payload = {
221220 "proof" : our_message ,
222221 "recipient" : contact_id
223222 }, auth_token = auth_token )
224- except :
223+ except Exception :
225224 logger .error ("Failed to send proof request to server, either you are offline or the server is down" )
226225 smp_failure_notify_contact (user_data , user_data_lock , contact_id , ui_queue )
227226 return
@@ -232,16 +231,11 @@ def smp_step_3(user_data, user_data_lock, contact_id, message, ui_queue) -> None
232231
233232def smp_step_4 (user_data , user_data_lock , contact_id , message , ui_queue ) -> None :
234233 with user_data_lock :
235- server_url = user_data ["server_url" ]
236- auth_token = user_data ["token" ]
237-
238234 answer = normalize_answer (user_data ["contacts" ][contact_id ]["lt_sign_key_smp" ]["answer" ])
239235
240236 our_public_key = user_data ["contacts" ][contact_id ]["lt_sign_keys" ]["our_keys" ]["public_key" ]
241237 our_nonce = b64decode (user_data ["contacts" ][contact_id ]["lt_sign_key_smp" ]["our_nonce" ], validate = True )
242238 contact_nonce = b64decode (user_data ["contacts" ][contact_id ]["lt_sign_key_smp" ]["contact_nonce" ], validate = True )
243-
244- contact_public_key = user_data ["contacts" ][contact_id ]["lt_sign_keys" ]["contact_public_key" ]
245239
246240 our_key_fingerprint = sha3_512 (our_public_key )
247241
@@ -323,8 +317,8 @@ def smp_failure_notify_contact(user_data, user_data_lock, contact_id, ui_queue)
323317 smp_failure (user_data , user_data_lock , contact_id , ui_queue )
324318
325319 try :
326- response = http_request (f"{ server_url } /smp/failure" , "POST" , payload = {"recipient" : contact_id }, auth_token = auth_token )
327- except :
320+ http_request (f"{ server_url } /smp/failure" , "POST" , payload = {"recipient" : contact_id }, auth_token = auth_token )
321+ except Exception :
328322 logger .error ("Failed to send SMP failure to server, either you are offline or the server is down" )
329323 pass
330324
0 commit comments