Overview
The WhatsApp Forensic Tool implements a sophisticated key management system to securely store and retrieve decryption keys. This system protects sensitive encryption keys using machine-specific encryption, preventing unauthorized access even if the key storage file is copied to another machine.Key Storage Architecture
Storage Location
Keys are stored in a centralized, OS-specific application data directory:- Windows:
%LOCALAPPDATA%\WhatsAppForensicTool\keys.json - macOS:
~/Library/Application Support/WhatsAppForensicTool/keys.json - Linux:
~/.config/WhatsAppForensicTool/keys.json
get_app_data_path() utility function in core/utils.py:74-91.
The key file is stored outside the tool’s installation directory to persist across updates and prevent accidental deletion.
File Structure
Thekeys.json file uses a hierarchical structure:
- Device ID: ADB serial number or device identifier
- Package Name: Either
com.whatsapporcom.whatsapp.w4b
Machine-Specific Encryption
Storage Key Derivation
The tool derives a machine-specific encryption key to protect the stored keys. This is implemented inCryptoManager._get_storage_key() at core/crypto_manager.py:33-43:
- Machine ID: Uses
uuid.getnode()to obtain MAC address-based unique identifier - Salt: Hardcoded application salt ensures consistent derivation
- PBKDF2: Key derivation with 100,000 iterations for computational hardness
- Output: 256-bit (32-byte) AES key
AES-GCM Encryption
The key file is encrypted using AES-256-GCM (Galois/Counter Mode), providing both confidentiality and authenticity.Encryption Process (_encrypt_data at line 45-49)
- Bytes 0-11: Nonce (12 bytes)
- Bytes 12-27: Authentication tag (16 bytes)
- Bytes 28+: Encrypted JSON data
Decryption Process (_decrypt_data at line 51-59)
decrypt_and_verify method ensures data integrity—tampering with the file will cause decryption to fail.
Key Migration System
Legacy to Encrypted Migration
The tool automatically migrates plaintext keys to encrypted storage on first run. This process is handled by_migrate_keys() at core/crypto_manager.py:61-91.
Migration Steps
Step 1: Local Plaintext File Migration Ifkeys.json exists in the current directory (legacy location):
Migration is automatic and idempotent. Running the tool multiple times will not cause issues.
Core Methods
save_key()
Location:core/crypto_manager.py:114-118
- Called automatically after successful decryption (
main.py:434) - Keys are saved immediately (no manual “save” action required)
- Overwrites existing keys for the same device/package combination
get_key()
Location:core/crypto_manager.py:121-123
- Called before prompting user for a key (
main.py:408) - Returns
Noneif key not found - Automatically tries saved key first during decryption
Security Considerations
Strengths
- Machine Binding: Keys cannot be used on different machines
- AES-GCM: Provides both encryption and authentication
- PBKDF2: Computational hardness against brute force
- Automatic Migration: Users don’t need to manually secure old keys
Limitations
Enterprise Considerations
For production forensic environments, consider:- Hardware Security Modules (HSM): Store keys in dedicated hardware
- OS Keyring Integration: Use Windows Credential Manager, macOS Keychain, or Linux Secret Service
- Multi-factor Authentication: Require additional authentication before key access
- Audit Logging: Log all key access events
Manual Key Management
Viewing Stored Keys
To inspect stored keys (for debugging or auditing):Manual Key Deletion
Exporting Keys (Backup)
Importing Keys
Troubleshooting
”Failed to decrypt” on Key Load
Cause:keys.json was copied from another machine or corrupted.
Solution: Delete the file and re-enter keys:
Keys Not Persisting
Cause: Permission issues writing to AppData directory. Solution: Run tool with appropriate permissions or check directory ownership:“Saved key failed” During Decryption
Cause: Saved key is for wrong backup version or corrupt. Solution: Delete the specific key and re-enter manually. The tool will prompt for a new key.Implementation Reference
File:core/crypto_manager.py
Key Functions:
__init__(): Initializes manager, loads keys (line 26)_get_storage_key(): Derives machine-specific key (line 33)_encrypt_data(): AES-GCM encryption (line 45)_decrypt_data(): AES-GCM decryption (line 51)_migrate_keys(): Legacy key migration (line 61)_save_keys_internal(): Save encrypted key file (line 93)_load_keys(): Load and decrypt key file (line 101)save_key(): Store new key (line 114)get_key(): Retrieve stored key (line 121)
Crypto.Cipher.AES: AES encryptionCrypto.Protocol.KDF.PBKDF2: Key derivationCrypto.Random.get_random_bytes: Nonce generationuuid.getnode(): Machine ID extraction
