mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 15:28:44 +00:00
Validate AES-GCM payload length
This commit is contained in:
@@ -89,6 +89,9 @@ class EncryptionManager:
|
||||
try:
|
||||
nonce = encrypted_data[3:15]
|
||||
ciphertext = encrypted_data[15:]
|
||||
if len(ciphertext) < 16:
|
||||
logger.error("AES-GCM payload too short")
|
||||
raise InvalidToken("AES-GCM payload too short")
|
||||
return self.cipher.decrypt(nonce, ciphertext, None)
|
||||
except InvalidTag as e:
|
||||
logger.error("AES-GCM decryption failed: Invalid authentication tag.")
|
||||
|
@@ -1,6 +1,10 @@
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from cryptography.fernet import InvalidToken
|
||||
|
||||
from helpers import TEST_SEED
|
||||
from utils.key_derivation import derive_index_key
|
||||
from password_manager.encryption import EncryptionManager
|
||||
@@ -19,3 +23,16 @@ def test_v2_prefix_fernet_fallback(tmp_path: Path, caplog) -> None:
|
||||
|
||||
assert decrypted == original
|
||||
assert "incorrect 'V2:' header" in caplog.text
|
||||
|
||||
|
||||
def test_aesgcm_payload_too_short(tmp_path: Path, caplog) -> None:
|
||||
key = derive_index_key(TEST_SEED)
|
||||
manager = EncryptionManager(key, tmp_path)
|
||||
|
||||
payload = b"V2:" + os.urandom(12) + b"short"
|
||||
|
||||
caplog.set_level(logging.ERROR, logger="password_manager.encryption")
|
||||
with pytest.raises(InvalidToken, match="AES-GCM payload too short"):
|
||||
manager.decrypt_data(payload)
|
||||
|
||||
assert "AES-GCM payload too short" in caplog.text
|
||||
|
Reference in New Issue
Block a user