- SQLCipher key: SHA256 -> PBKDF2-HMAC-SHA256 with 100k iterations - Recovery code hashing: SHA256 -> HMAC-SHA256 with salt - Add Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options, CSP headers
This commit is contained in:
parent
453c1bba18
commit
7e85cb1acd
10
app.py
10
app.py
@ -68,7 +68,10 @@ def require_api_key(f):
|
||||
|
||||
|
||||
def _derive_sqlcipher_key(bcrypt_hash: str) -> str:
|
||||
return hashlib.sha256(bcrypt_hash.encode()).hexdigest()[:64]
|
||||
"""Derive SQLCipher key from bcrypt hash using PBKDF2 (#5)."""
|
||||
salt = b"pinvault-sqlcipher-v1" # Fixed salt - bcrypt hash provides entropy
|
||||
derived = hashlib.pbkdf2_hmac("sha256", bcrypt_hash.encode(), salt, 100_000)
|
||||
return derived.hex()[:64]
|
||||
|
||||
|
||||
def get_conn():
|
||||
@ -80,8 +83,9 @@ def get_conn():
|
||||
return conn
|
||||
|
||||
|
||||
def hash_val(value):
|
||||
return hashlib.sha256(value.encode()).hexdigest()
|
||||
def hash_val(value, salt: str = "pinvault-recovery-v1"):
|
||||
"""Hash recovery code with HMAC to prevent precomputed attacks (#4)."""
|
||||
return hmac.new(salt.encode(), value.encode(), hashlib.sha256).hexdigest()
|
||||
|
||||
|
||||
def generate_recovery_code():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user