Skip to content

Commit 5309452

Browse files
committed
fix: local identifier verification
1 parent b8e7742 commit 5309452

File tree

3 files changed

+29
-40
lines changed

3 files changed

+29
-40
lines changed

logic/get_user.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

logic/user.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,24 @@ def build_initial_user_data() -> dict:
88
"ignore_new_contacts_smp": False,
99
}
1010
}
11+
12+
13+
def validate_identifier(identifier) -> bool:
14+
if identifier.isdigit() and len(identifier) == 16:
15+
return True
16+
17+
18+
split = identifier.split("@")
19+
if len(split) != 2:
20+
return False
21+
22+
if not split[0].isdigit():
23+
return False
24+
25+
# Max domain length is 253 bytes
26+
if len(split[1] > 253):
27+
return False
28+
29+
30+
return True
31+

ui/add_contact_prompt.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from tkinter import messagebox
22
from ui.utils import *
3-
from logic.get_user import check_if_contact_exists
3+
from logic.user import validate_identifier
44
from logic.contacts import save_contact
55
from logic.storage import save_account_data
66
import tkinter as tk
@@ -51,18 +51,14 @@ def add_contact(self):
5151
self.status.config(text="You cannot add yourself", fg="red")
5252
return
5353

54-
try:
55-
# if not check_if_contact_exists(self.master.user_data, self.master.user_data_lock, contact_id):
56-
# logger.error("[BUG] This should never execute, because the server should return a 40X error code and that should cause an exception..")
57-
# return
58-
59-
save_contact(self.master.user_data, self.master.user_data_lock, contact_id)
60-
save_account_data(self.master.user_data, self.master.user_data_lock)
61-
except ValueError as e:
62-
self.status.config(text=e, fg="red")
63-
logger.error("Error occured while adding new contact (%s): %s ", contact_id, e)
54+
if not validate_identifier(contact_id):
55+
logger.debug("Identifier is invalid.")
56+
self.status.config(text = "Invalid identifier", fg="red")
6457
return
65-
58+
59+
save_contact(self.master.user_data, self.master.user_data_lock, contact_id)
60+
save_account_data(self.master.user_data, self.master.user_data_lock)
61+
6662

6763
self.master.new_contact(contact_id)
6864
self.destroy()

0 commit comments

Comments
 (0)