Skip to content

Commit f65e34a

Browse files
committed
refactor: Add new availability features
1 parent d965d44 commit f65e34a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

logic/background_worker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from core.requests import http_request
2-
from logic.smp import smp_data_handler
2+
from logic.smp import (
3+
smp_data_handler,
4+
smp_unanswered_questions
5+
)
36
from logic.pfs import pfs_data_handler
47
from logic.message import messages_data_handler
58
from logic.user import validate_identifier
@@ -67,6 +70,9 @@ def parse_blobs(blobs: list[bytes]) -> dict:
6770
return parsed_messages
6871

6972
def background_worker(user_data, user_data_lock, ui_queue, stop_flag):
73+
# Incase we received a SMP question request last time and user did not answer it.
74+
smp_unanswered_questions(user_data, user_data_lock, ui_queue)
75+
7076

7177
# Acknowledgements
7278
acks = {}

logic/smp.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ def smp_step_2(user_data: dict, user_data_lock, contact_id: str, blob: bytes, ui
166166
user_data["contacts"][contact_id]["our_next_strand_key"] = our_next_strand_key
167167
user_data["contacts"][contact_id]["contact_next_strand_key"] = contact_next_strand_key
168168

169-
user_data["contacts"][contact_id]["our_next_strand_key"] = our_next_strand_key
170-
user_data["contacts"][contact_id]["contact_next_strand_key"] = contact_next_strand_key
171-
172169

173170
user_data["contacts"][contact_id]["our_next_strand_nonce"] = our_next_strand_nonce
174171
user_data["contacts"][contact_id]["contact_next_strand_nonce"] = contact_next_strand_nonce
@@ -504,6 +501,7 @@ def smp_failure(user_data, user_data_lock, contact_id, ui_queue) -> None:
504501

505502
ui_queue.put({"type": "showerror", "title": "Error", "message": "Verification has failed! Please re-try."})
506503

504+
save_account_data(user_data, user_data_lock)
507505

508506
def smp_failure_notify_contact(user_data, user_data_lock, contact_id, ui_queue) -> None:
509507
with user_data_lock:
@@ -512,12 +510,20 @@ def smp_failure_notify_contact(user_data, user_data_lock, contact_id, ui_queue)
512510
session_headers = user_data["tmp"]["session_headers"]
513511

514512
our_next_strand_key = user_data["contacts"][contact_id]["our_next_strand_key"]
515-
our_next_strand_nonce = user_data["contacts"][contact_id]["contact_next_strand_nonce"]
513+
our_next_strand_nonce = user_data["contacts"][contact_id]["our_next_strand_nonce"]
516514

515+
517516

518517
# we don t need to save them.
519518
new_strand_key = sha3_512(secrets.token_bytes(32))[:32]
520519
new_strand_nonce = sha3_512(secrets.token_bytes(XCHACHA20POLY1305_NONCE_LEN))[:XCHACHA20POLY1305_NONCE_LEN]
520+
521+
522+
# This is so the request happens. Receiver triggers SMP failure anyway if contact is pending verification and we couldn't decrypt data.
523+
if not our_next_strand_key or not our_next_strand_nonce:
524+
our_next_strand_key = new_strand_key
525+
our_next_strand_nonce = new_strand_nonce
526+
521527
_, ciphertext_blob = encrypt_xchacha20poly1305(
522528
our_next_strand_key,
523529
new_strand_key + new_strand_nonce + SMP_TYPES["SMP_INIT"] + b"failure",

0 commit comments

Comments
 (0)