|
1 | 1 | import tkinter as tk |
2 | 2 | from tkinter import messagebox |
3 | | -from ui.utils import * |
| 3 | +from ui.utils import ( |
| 4 | + enhanced_entry |
| 5 | + ) |
| 6 | +from logic.utils import ( |
| 7 | + check_str_high_entropy |
| 8 | +) |
4 | 9 | from logic.smp import initiate_smp |
5 | 10 | from core.constants import ( |
6 | 11 | SMP_QUESTION_MAX_LEN |
@@ -29,17 +34,15 @@ def __init__(self, master, contact_id): |
29 | 34 | tk.Label(self, text="Question:", fg="white", bg="black", anchor="w").pack(fill="x", padx=20) |
30 | 35 | self.question_entry = tk.Entry(self, width=50) |
31 | 36 | self.question_entry.pack(padx=20, pady=(0, 10)) |
32 | | - self.question_entry.focus() |
| 37 | + # self.question_entry.focus() |
33 | 38 |
|
34 | 39 | tk.Label(self, text="Answer:", fg="white", bg="black", anchor="w").pack(fill="x", padx=20) |
35 | 40 | self.answer_entry = tk.Entry(self, width=50) |
36 | 41 | self.answer_entry.pack(padx=20, pady=(0, 20)) |
37 | 42 |
|
38 | | - # TODO: Figure out why enhanced_entry bricks the question and answer entry |
39 | | - # enhanced_entry(self.question_entry, placeholder="I.e. Where did we meet last Thursday ?") |
40 | | - # enhanced_entry(self.answer_entry, placeholder="I.e. Central Park") |
| 43 | + enhanced_entry(self.question_entry, placeholder="I.e. What's our secret passphrase ?") |
| 44 | + enhanced_entry(self.answer_entry, placeholder="I.e. Horse Whale Australia Dog Times Lake") |
41 | 45 |
|
42 | | - # Send button |
43 | 46 | tk.Button( |
44 | 47 | self, |
45 | 48 | text="Send Verification Request", |
@@ -70,39 +73,30 @@ def submit(self): |
70 | 73 | messagebox.showerror("Error", "Question must not contain the answer!") |
71 | 74 | return |
72 | 75 |
|
| 76 | + if question.lower() in answer.lower(): |
| 77 | + messagebox.showerror("Error", "Answer must not contain any part of the question!") |
| 78 | + return |
73 | 79 |
|
74 | 80 | if len(question) > SMP_QUESTION_MAX_LEN: |
75 | 81 | messagebox.showerror("Error", f"Question must be under {SMP_QUESTION_MAX_LEN} characters long.") |
76 | 82 |
|
77 | | - |
78 | | - # This is just unacceptable, 4 characaters is the bare minimum. |
79 | | - # Given our argon2id parameters, we have calculated the worst case scenario of an adversary with |
80 | | - # many 128-core CPU clusters, and 1000s of machines available, with custom-optimizied cracking-rigs |
81 | | - # and we concluded that as of 2025, would still require a couple minutes - couple seconds short of |
82 | | - # a minute to crack the answer which might *just* be enough time if both users are online and the |
83 | | - # server is not malicious. If the server is malicious, it could delay the process, which means that |
84 | | - # powerful adversary would have cracked the answer to your question and possibly fed you spoofed keys |
85 | | - # |
86 | | - # We don't actually enforce high-entropy answers because we know users will try to bypass the limit |
87 | | - # by picking long-length but low-entropy answers, or worse, put / hint the answer in the question |
88 | | - # Instead, we opted for an approach of allowing the user to choose low-entropy answers but give |
89 | | - # them 2 warnings to ensure they understand the risks. |
90 | | - # |
91 | | - |
92 | 83 | if len(answer) <= 3: |
93 | 84 | messagebox.showerror("Error", "Answer must be at least 4 characters long!") |
94 | 85 | return |
95 | 86 |
|
96 | | - if len(answer) <= 5: |
| 87 | + if len(answer) <= 5 or not check_str_high_entropy(answer): |
97 | 88 | # Even though we enforce SMP, sometime a user might want to add someone whom our user don't have a out-of-band channel to communicate with |
98 | 89 | # allowing the user to set a low-entropy answer gives user the opportunity to do so |
99 | 90 | # But we still warn the user twice about the importance of the answer's entropy in context of SMP verification |
100 | | - if messagebox.askyesno("Warning", "Answer is less than 6 characters long, this is unsafe and not recommended, do you want to proceed anyway ?"): |
| 91 | + if messagebox.askyesno("Warning", "Answer does not contain good entropy, this is unsafe and not recommended, do you want to proceed anyway ?"): |
101 | 92 | if not messagebox.askyesno("Warning", "If the server is malicious, low-entropy answer potentially undermines encryption. To reduce risks only proceed if you are certain that the contact is online right now, are you absolutely sure?"): |
102 | 93 | return |
103 | 94 | else: |
104 | 95 | return |
105 | 96 |
|
106 | | - initiate_smp(self.master.user_data, self.master.user_data_lock, self.contact_id, question, answer) |
107 | | - |
| 97 | + try: |
| 98 | + initiate_smp(self.master.user_data, self.master.user_data_lock, self.contact_id, question, answer) |
| 99 | + except Exception as e: |
| 100 | + messagebox.showerror("Error", e) |
| 101 | + |
108 | 102 | self.destroy() |
0 commit comments