mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-08-22 07:13:39 +00:00
feat(signup-credit): digest an identity into a keyed fingerprint
The ledger has to outlive the account that wrote it, so it cannot store a subject id or an email. HMAC under SECRET_KEY rather than a bare hash: the space of Google subject ids and email addresses is small enough to exhaust offline against a plain SHA-256.
This commit is contained in:
parent
f0da52c766
commit
8639ade964
2 changed files with 21 additions and 0 deletions
1
surfsense_backend/app/signup_credit/__init__.py
Normal file
1
surfsense_backend/app/signup_credit/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
"""The signup credit: granted once per person, not once per account."""
|
||||
20
surfsense_backend/app/signup_credit/identity/fingerprint.py
Normal file
20
surfsense_backend/app/signup_credit/identity/fingerprint.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
"""One-way, keyed digest of an identity value."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import hmac
|
||||
|
||||
from app.config import config
|
||||
|
||||
|
||||
def fingerprint(value: str) -> str:
|
||||
"""Digest an identity so it stays comparable but never readable."""
|
||||
# Keyed rather than a bare hash: the space of subject ids and email
|
||||
# addresses is small enough to exhaust offline.
|
||||
if not config.SECRET_KEY:
|
||||
raise RuntimeError("SECRET_KEY must be set before identities can be claimed.")
|
||||
|
||||
return hmac.new(
|
||||
config.SECRET_KEY.encode(), value.encode(), hashlib.sha256
|
||||
).hexdigest()
|
||||
Loading…
Add table
Add a link
Reference in a new issue