Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit ad6c18d

Browse files
committed
refactor: Remove unused variables and imports
1 parent a4edbdc commit ad6c18d

File tree

13 files changed

+24
-57
lines changed

13 files changed

+24
-57
lines changed

core/crypto.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import secrets
2121
from core.constants import (
2222
OTP_PAD_SIZE,
23-
OTP_PADDING_LIMIT,
2423
OTP_PADDING_LENGTH,
2524
ML_KEM_1024_NAME,
2625
ML_KEM_1024_SK_LEN,

core/requests.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from urllib import request
2-
import urllib
32
import json
4-
import time
53

64
def http_request(url: str, method: str, auth_token: str = None, payload: dict = None, longpoll: int = -1) -> dict:
75
if payload:
@@ -16,15 +14,11 @@ def http_request(url: str, method: str, auth_token: str = None, payload: dict =
1614
if auth_token:
1715
req.add_header("Authorization", "Bearer " + auth_token)
1816

19-
# urllib raises a HTTPError for status code >= 400
20-
# try:
17+
# NOTE: urllib raises a HTTPError for status code >= 400
2118
if longpoll == -1:
2219
with request.urlopen(req) as response:
2320
return json.loads(response.read().decode())
2421
else:
2522
with request.urlopen(req, timeout=longpoll) as response:
2623
return json.loads(response.read().decode())
2724

28-
29-
# except urllib.error.HTTPError as e:
30-
# return json.loads(e.read().decode())

logic/authentication.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ def authenticate_account(user_data: dict) -> dict:
1515
response = http_request(url + "/authenticate/init", "POST", payload = {"public_key": public_key_encoded, "user_id": user_id })
1616
if not 'challenge' in response:
1717
raise ValueError("Server did not give authenticatation challenge! Are you sure this is a Coldwire server ?")
18-
except:
18+
except Exception:
1919
if 'proxy_info' in user_data:
2020
raise ValueError("Could not connect to server! Are you sure your proxy settings are valid ?")
2121
else:
2222
raise ValueError("Could not connect to server! Are you sure the URL is valid ?")
2323

2424
try:
2525
challenge = b64decode(response["challenge"], validate=True)
26-
except:
26+
except Exception:
2727
raise ValueError("Server gave a malformed challenge! Are you sure this is Coldwire server ?")
2828

2929

3030
signature = create_signature("Dilithium5", challenge, private_key)
3131

3232
try:
3333
response = http_request(url + "/authenticate/verify", "POST", payload = {"signature": b64encode(signature).decode(), "challenge": response["challenge"]})
34-
except:
34+
except Exception:
3535
raise ValueError("Server gave a malformed response, your account is probably missing from the server")
3636

3737
required_keys = ["status", "user_id", "token"]

logic/background_worker.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from core.requests import http_request
2-
from logic.storage import save_account_data
3-
from logic.contacts import save_contact
42
from logic.smp import smp_unanswered_questions, smp_data_handler
53
from logic.pfs import pfs_data_handler
64
from logic.message import messages_data_handler
@@ -9,12 +7,6 @@
97
LONGPOLL_MAX
108
)
119
from core.crypto import random_number_range
12-
from core.trad_crypto import derive_key_argon2id, sha3_512
13-
from base64 import b64encode, b64decode
14-
import hashlib
15-
import secrets
16-
import hmac
17-
import time
1810
import copy
1911
import logging
2012
import json

logic/contacts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import string
33
import json
44
import math
5-
import copy
65

76

87
def generate_nickname_id(length: int = 4) -> str:

logic/message.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
ML_DSA_87_NAME,
2929
)
3030
from base64 import b64decode, b64encode
31-
import copy
3231
import json
3332
import logging
3433

@@ -61,8 +60,8 @@ def generate_and_send_pads(user_data, user_data_lock, contact_id: str, ui_queue)
6160
"recipient": contact_id
6261
}
6362
try:
64-
response = http_request(f"{server_url}/messages/send_pads", "POST", payload=payload, auth_token=auth_token)
65-
except:
63+
http_request(f"{server_url}/messages/send_pads", "POST", payload=payload, auth_token=auth_token)
64+
except Exception:
6665
ui_queue.put({"type": "showerror", "title": "Error", "message": "Failed to send our one-time-pads key batch to the server"})
6766
return False
6867

@@ -87,7 +86,6 @@ def send_message_processor(user_data, user_data_lock, contact_id: str, message:
8786
Returns:
8887
bool: True if successful, False otherwise.
8988
"""
90-
# We don't deepcopy here as real-time states are required here for maximum future-proofing.
9189

9290
with user_data_lock:
9391
if contact_id in user_data["tmp"]["ephemeral_key_send_lock"]:
@@ -103,16 +101,14 @@ def send_message_processor(user_data, user_data_lock, contact_id: str, message:
103101

104102

105103
contact_kyber_public_key = user_data["contacts"][contact_id]["ephemeral_keys"]["contact_public_key"]
106-
our_lt_private_key = user_data["contacts"][contact_id]["lt_sign_keys"]["our_keys"]["private_key"]
107-
108104

109105

110106
if (not contact_kyber_public_key):
111107
logger.debug("This shouldn't usually happen, contact kyber keys are not initialized even once yet???")
112108
ui_queue.put({
113109
"type": "showwarning",
114110
"title": f"Warning for {contact_id[:32]}",
115-
"message": f"Ephemeral keys have not yet initialized, maybe contact is offline. We will notify you when keys are initialized"
111+
"message": "Ephemeral keys have not yet initialized, maybe contact is offline. We will notify you when keys are initialized"
116112
})
117113

118114
send_new_ephemeral_keys(user_data, user_data_lock, contact_id, ui_queue)
@@ -211,7 +207,7 @@ def send_message_processor(user_data, user_data_lock, contact_id: str, message:
211207
save_account_data(user_data, user_data_lock)
212208

213209
try:
214-
response = http_request(f"{server_url}/messages/send_message", "POST", payload = {
210+
http_request(f"{server_url}/messages/send_message", "POST", payload = {
215211
"message_encrypted": message_encrypted,
216212
"recipient": contact_id
217213
},

logic/pfs.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
generate_sign_keys,
88
random_number_range
99
)
10-
from core.trad_crypto import derive_key_argon2id, sha3_512
10+
from core.trad_crypto import sha3_512
1111
from base64 import b64encode, b64decode
1212
import secrets
13-
import hmac
14-
import time
1513
import copy
1614
import json
1715
import logging
18-
import oqs
19-
2016

2117
logger = logging.getLogger(__name__)
2218

@@ -57,8 +53,8 @@ def send_new_ephemeral_keys(user_data, user_data_lock, contact_id, ui_queue) ->
5753

5854

5955
try:
60-
response = http_request(f"{server_url}/pfs/send_keys", "POST", payload=payload, auth_token=auth_token)
61-
except:
56+
http_request(f"{server_url}/pfs/send_keys", "POST", payload=payload, auth_token=auth_token)
57+
except Exception:
6258
ui_queue.put({"type": "showerror", "title": "Error", "message": "Failed to send our ephemeral keys to the server"})
6359
return
6460

logic/smp.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
logic/smp.py
3+
----------
24
The socialist millionaire problem
35
A variant of Yao's millionaire problem
46
@@ -34,16 +36,13 @@
3436
from logic.storage import save_account_data
3537
from logic.contacts import save_contact
3638
from 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
3840
from core.trad_crypto import derive_key_argon2id, sha3_512
3941
from base64 import b64encode, b64decode
4042
import hashlib
4143
import secrets
4244
import hmac
43-
import time
44-
import copy
4545
import logging
46-
import json
4746

4847

4948
logger = 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

233232
def 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

ui/chat_window.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import tkinter as tk
2-
from tkinter import messagebox
32
from logic.message import send_message_processor
43

54
class ChatWindow(tk.Toplevel):

ui/connect_window.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from logic.storage import save_account_data
44
from logic.authentication import authenticate_account
55
from core.crypto import generate_sign_keys
6-
from base64 import b64encode
76
from urllib.parse import urlparse
87
import tkinter as tk
98
import logging
@@ -200,7 +199,7 @@ def on_connect(self, event=None):
200199

201200
try:
202201
self.server_url_fixed = self.clean_server_url(self.server_url_fixed)
203-
except:
202+
except Exception:
204203
self.status_label.config(text="Server address is invalid!")
205204
return
206205

0 commit comments

Comments
 (0)