This document describes the secure fingerprinting approach used for logging sensitive identifiers (device IDs, device names, session keys) in the application.
CodeQL Alert: Use of a broken or weak cryptographic hashing algorithm on sensitive data
The codebase was using SHA256 directly to create "fingerprints" of sensitive identifiers for logging purposes:
# INSECURE - vulnerable to brute-force attacks
device_fp = hashlib.sha256(device_id.encode('utf-8')).hexdigest()[:8]While SHA256 is secure for file integrity checking, it's inappropriate for sensitive data because:
- Too fast - Attackers can brute-force original values from intercepted logs
- No key - Anyone with the hash can attempt to reverse it
- Deterministic - Same input always produces same output, enabling correlation attacks
We now use HMAC-SHA256 with a random per-session key:
# SECURE - uses HMAC with random key
import hmac
import hashlib
import secrets
fp_key = secrets.token_bytes(32) # Random 256-bit key per session
device_fp = hmac.new(fp_key, device_id.encode('utf-8'), hashlib.sha256).hexdigest()[:8]- Keyed hash - Requires secret key, making brute-force attacks infeasible
- Random key per session - Fingerprints change between runs, preventing correlation
- Industry standard - HMAC-SHA256 is approved for cryptographic use (FIPS 197)
- Same debugging utility - Still provides unique identifiers for troubleshooting
-
- Device ID and name fingerprints (initialization)
- Session key fingerprint (handshake)
-
- Device ID fingerprints (initialization and loading)
-
- Command-line device fingerprint display
-
- Device generation fingerprint display
-
- Device protection setup fingerprint
Note: SHA256 is still used appropriately for:
- File integrity checking in crypto_handshake.py
- This is a valid use case - SHA256 is perfect for verifying file modifications
- No key storage needed - Random keys are ephemeral (per-session only)
- Forward secrecy - Old logs can't be correlated with new ones
- Performance - HMAC-SHA256 is just as fast as plain SHA256
- Compliance - Meets security best practices for sensitive data handling
- HMAC (RFC 2104): https://tools.ietf.org/html/rfc2104
- NIST FIPS 198-1: https://csrc.nist.gov/publications/detail/fips/198/1/final
- OWASP: Don't use fast hashes for sensitive data