Verify the master key against the database at startup (B-89, SEC-49, SEC-50, SEC-09)
The lifespan decrypts the key and compares a fixed sample (reserve/round pool addresses, the 10 lowest and highest user addresses, unrevealed round secrets) with the database, and refuses to serve on any mismatch without printing key material. The key scripts refuse a new or imported key that would not reproduce the stored addresses, and write 0600. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
32df50cb75
commit
55d852fe08
14 files changed
+281
-46
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
from app.config import settings
|
||||
@@ -20,3 +22,12 @@ def encrypt_round_seed(server_seed_hex: str) -> str:
|
||||
|
||||
def decrypt_round_seed(token: str) -> str:
|
||||
return Fernet(settings.xprv_encryption_key).decrypt(token.encode()).decode()
|
||||
|
||||
|
||||
def write_secret_file(path: str, data: bytes) -> None:
|
||||
"""B-89 (SEC-50): created `0600` from the start (never through a wider mode) and
|
||||
rewritten with the same mode, so a key file is not readable by other users."""
|
||||
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
||||
with os.fdopen(fd, "wb") as f:
|
||||
os.fchmod(f.fileno(), 0o600)
|
||||
f.write(data)
|
||||
Reference in new issue
Block a user