Bind essentials recovery to explicit manifest and verified offsite provenance
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a06ecb-456a-71c2-b41e-0755d336e883
This commit is contained in:
parent
4707bf08d7
commit
11322a5256
7 changed files with 151 additions and 14 deletions
38
scripts/decrypt_primary_forgejo_archive.py
Normal file
38
scripts/decrypt_primary_forgejo_archive.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Silent attended decryption of the hash-verified primary archive download."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
from state_hub_preflight_lane import bao, data
|
||||
|
||||
|
||||
def digest(path):
|
||||
with path.open('rb') as source: return hashlib.file_digest(source,'sha256').hexdigest()
|
||||
|
||||
|
||||
def main():
|
||||
p=argparse.ArgumentParser(description=__doc__)
|
||||
for name in ['source','output','transfer-receipt','receipt']: p.add_argument('--'+name,required=True,type=Path)
|
||||
a=p.parse_args();receipt={'schema':'platform.forgejo-primary-decryption.v1','status':'failed'}
|
||||
fd=os.open(a.receipt,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
|
||||
try:
|
||||
transfer=json.loads(a.transfer_receipt.read_text())
|
||||
if (transfer.get('status')!='primary_fetched_pending_application_restore'
|
||||
or not transfer.get('download_hash_matches')
|
||||
or digest(a.source)!=transfer.get('ciphertext_sha256')):
|
||||
raise ValueError('verified_primary_download_required')
|
||||
value=data(bao(['read','-format=json','platform/data/workloads/railiance/backup/offsite-lane']))['data']['data']['AGE_PRIVATE_KEY']
|
||||
with a.output.open('xb') as target:
|
||||
a.output.chmod(0o600)
|
||||
result=subprocess.run(['age','-d','-i','/dev/stdin',str(a.source)],input=(value.strip()+'\n').encode(),stdout=target,stderr=subprocess.PIPE,timeout=1200)
|
||||
if result.returncode: raise ValueError('primary_decryption_failed')
|
||||
receipt.update(transfer,decrypted=True,plaintext_sha256=digest(a.output))
|
||||
except Exception:
|
||||
receipt['error']='bounded_primary_decryption_failed'
|
||||
finally:
|
||||
with os.fdopen(fd,'w') as output: json.dump(receipt,output,indent=2)
|
||||
return int(receipt['status']=='failed')
|
||||
if __name__=='__main__': raise SystemExit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue