44 lines
5.1 KiB
Python
44 lines
5.1 KiB
Python
from pathlib import Path
|
|
from datetime import datetime,timezone
|
|
import json,csv,hashlib,zipfile,re,shutil,collections
|
|
csv.field_size_limit(10000000)
|
|
OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1];DOC=ROOT/'docs/investmoz/v2/auditoria-portal'
|
|
load=lambda p:json.loads(p.read_text(encoding='utf-8-sig'));sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
|
before=load(OUT/'C132-preflight.json');after=load(OUT/'C132-runtime-after.json');assert before['key_fingerprint']==after['key_fingerprint'] and before['flags']==after['flags'] and before['C131_active_hash']==after['C131_active_hash'] and before['build_hash']==after['build_hash']
|
|
assert sha(ROOT/'config/inertia.php')=='80c68e12bf6cb64e39931e2467b43909893cea3eb6d04c3c1e68bdcb1236dfb7';assert sha(ROOT/'app/Services/OpportunityContacts.php')==before['C131_active_hash'];assert not (ROOT/'config/inertia.C132.pending.php').exists()
|
|
assert load(OUT/'C132-rotation-active.json')['affected_ids']==[14,15,16,17];assert load(OUT/'C132-usability-after-rotation.json')['current_credential_matches']==[]
|
|
assert load(OUT/'C132-manual-auth-confirmation.json')['dashboard_confirmed'];assert all(c['status']==404 for c in load(OUT/'C132-http-contained.json')['checks'][:3])
|
|
location=Path(load(OUT/'C132-private-location.json')['private_directory']);manifest=load(location/'evidence-manifest-private.json')
|
|
assert all(sha(location/'diagnostics'/r['name'])==r['sha256'] for r in manifest['files'])
|
|
source=ROOT/'storage/inertia-devtools';assert set(p.name for p in source.iterdir() if p.is_file())=={r['name'] for r in manifest['files']};assert all(sha(source/r['name'])==r['sha256'] for r in manifest['files'])
|
|
original=list(csv.DictReader((OUT/'matriz-requisitos.csv.before').open(encoding='utf-8-sig',newline='')));matrix=list(csv.DictReader((DOC/'matriz-requisitos.csv').open(encoding='utf-8-sig',newline='')))
|
|
assert len(matrix)==len(original)==3401 and len({r['ID'] for r in matrix})==3401 and sum(int(r['Quantidade de linhas de origem']) for r in matrix)==7739
|
|
immutable=['ID','Pedido/trecho','Fonte/ocorrências','Módulo','Rotas','Critério de aceitação','Versões divergentes','IDs das linhas de origem','Quantidade de linhas de origem','Critérios e versões por origem (JSON)']
|
|
assert all(all(a[k]==b[k] for k in immutable) for a,b in zip(original,matrix))
|
|
proof={'at':datetime.now(timezone.utc).isoformat(),'result':'passed','C132_only':True,'C131_not_applied':True,'app_key_flags_cookie_bundle_preserved':True,'original_diagnostics_and_restricted_snapshot_hashes_preserved':True,'no_new_diagnostics_after_HTTP_and_owner_authentication':True,
|
|
'requirements':3401,'source_occurrences':7739,'new_ids':0,'AB_C37_preserved':True,'states':dict(collections.Counter(r['Estado'] for r in matrix)),
|
|
'matrix_sha256':sha(DOC/'matriz-requisitos.csv'),'backlog_sha256':sha(DOC/'backlog-priorizado.csv'),'incident_closed':False,'MFA_affected_owners_confirmation_pending':True}
|
|
(OUT/'C132-final-integrity.json').write_text(json.dumps(proof,ensure_ascii=False,indent=2),encoding='utf-8')
|
|
review=OUT/'C132-para-revisao';review.mkdir(exist_ok=True)
|
|
shutil.copyfile(DOC/'C132-incidente-contido.md',review/'relatorio-C132.md');shutil.copyfile(OUT/'C132-manifesto-contencao.json',review/'manifesto-contencao.json')
|
|
names=['C132-containment.json','C132-http-contained.json','C132-local-analysis.json','C132-usability-before-snapshot.json','C132-usability-after-rotation.json','C132-rotation-QA.json','C132-rotation-active.json','C132-backup-restoration.json','C132-manual-auth-confirmation.json','C132-audit-record.json','C132-ACL-verification.json','C132-exposure-period.json','C132-final-integrity.json']
|
|
(review/'evidencias').mkdir(exist_ok=True)
|
|
for n in names:shutil.copyfile(OUT/n,review/'evidencias'/n)
|
|
# Only the contained config and sanitized incident report/proofs, never C131 or diagnostic/credential files.
|
|
(review/'config').mkdir(exist_ok=True);shutil.copyfile(ROOT/'config/inertia.php',review/'config/inertia.php')
|
|
fileManifest=[]
|
|
for p in sorted(review.rglob('*')):
|
|
if not p.is_file():continue
|
|
s=p.read_text(encoding='utf-8-sig');assert 'otpauth://' not in s and not re.search(r'QA-[a-f0-9]{32,}',s)
|
|
assert p.name not in ['.env','secret-candidates-private.json','handoff-manifest-private.json','users-before-response-private.json']
|
|
fileManifest.append({'file':p.relative_to(review).as_posix(),'sha256':sha(p),'bytes':p.stat().st_size})
|
|
zipPath=OUT/'investmoz-C132-contencao-revisao-20261012.zip'
|
|
with zipfile.ZipFile(zipPath,'w',zipfile.ZIP_DEFLATED,compresslevel=8) as z:
|
|
for r in fileManifest:z.write(review/r['file'],r['file'])
|
|
z.writestr('inventario-pacote.json',json.dumps(fileManifest,ensure_ascii=False,indent=2))
|
|
with zipfile.ZipFile(zipPath) as z:
|
|
assert z.testzip() is None
|
|
assert all(hashlib.sha256(z.read(r['file'])).hexdigest()==r['sha256'] for r in fileManifest)
|
|
delivery={'case':'C132','result':'passed','file':str(zipPath),'sha256':sha(zipPath),'bytes':zipPath.stat().st_size,'entries':len(fileManifest)+1,'sensitive_values_included':False,'C131_included':False,'incident_closed':False}
|
|
(OUT/'C132-delivery-proof.json').write_text(json.dumps(delivery,indent=2),encoding='utf-8');print(json.dumps(delivery))
|