|
1 | 1 | from pathlib import Path |
2 | 2 | from base64 import b64encode, b64decode |
3 | 3 | from core.constants import ( |
| 4 | + XCHACHA20POLY1305_NONCE_LEN, |
4 | 5 | ML_KEM_1024_NAME, |
5 | 6 | CLASSIC_MCELIECE_8_F_NAME, |
6 | 7 | ACCOUNT_FILE_PATH, |
@@ -29,13 +30,13 @@ def load_account_data(password = None) -> dict: |
29 | 30 | with open(ACCOUNT_FILE_PATH, "rb") as f: |
30 | 31 | blob = f.read() |
31 | 32 |
|
32 | | - # first 12 bytes is nonce, and last 32 bytes is the password salt, |
| 33 | + # first XCHACHA20POLY13055_NONCE_LEN bytes is nonce, and last 32 bytes is the password salt, |
33 | 34 | # and the ciphertext is inbetween. |
34 | 35 | password_kdf, _ = crypto.derive_key_argon2id(password.encode(), salt=blob[-ARGON2_SALT_LEN:]) |
35 | 36 |
|
36 | 37 | blob = blob[:-ARGON2_SALT_LEN] |
37 | 38 |
|
38 | | - user_data = json.loads(crypto.decrypt_xchacha20poly1305(password_kdf, blob[:12], blob[12:])) |
| 39 | + user_data = json.loads(crypto.decrypt_xchacha20poly1305(password_kdf[:32], blob[:XCHACHA20POLY1305_NONCE_LEN], blob[XCHACHA20POLY1305_NONCE_LEN:])) |
39 | 40 |
|
40 | 41 |
|
41 | 42 | with open(Path("assets") / "browsers_headers.json", "r") as f: |
@@ -258,7 +259,7 @@ def save_account_data(user_data: dict, user_data_lock, password = None) -> None: |
258 | 259 | password_kdf, password_salt = crypto.derive_key_argon2id(password.encode()) |
259 | 260 |
|
260 | 261 |
|
261 | | - nonce, ciphertext = crypto.encrypt_xchacha20poly1305(password_kdf, json.dumps(user_data).encode("utf-8")) |
| 262 | + nonce, ciphertext = crypto.encrypt_xchacha20poly1305(password_kdf[:32], json.dumps(user_data).encode("utf-8")) |
262 | 263 | with open(ACCOUNT_FILE_PATH, "wb") as f: |
263 | 264 | f.write(nonce + ciphertext + password_salt) |
264 | 265 |
|
|
0 commit comments