Files
Investidor-V2/tools/portal-functional-historic-key-check-qa.php
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

16 lines
1.8 KiB
PHP

<?php
// Read-only key provenance probe for an inherited QA envelope. Never print keys.
use Illuminate\Support\Facades\DB;
$root=dirname(__DIR__);$dir=$root.'/storage/app/private/investmoz-v2/portal-audit';
$plan=json_decode(file_get_contents($dir.'/portal-stability-latest.json'),true,512,JSON_THROW_ON_ERROR);
putenv('STABILITY_QA_MODE=consumers');$app=(static fn(string $file)=>require $file)($plan['source'].'/tools/portal-stability-runtime.php');
$row=DB::selectOne('SELECT id,name,email,two_factor_secret FROM users WHERE id=19');
$files=[...glob($root.'/.env*'),...glob($plan['source'].'/.env*'),...glob($root.'/tools/*.php')];
foreach(glob($dir.'/*.json')as$f)if(filesize($f)<2000000)$files[]=$f;
$matches=[];$seen=[];
foreach($files as$file){if(!is_file($file))continue;preg_match_all('/base64:([A-Za-z0-9+\/=]{43,})/',file_get_contents($file),$values);foreach($values[1]as$encoded){$key=base64_decode($encoded,true);if(!is_string($key)||strlen($key)!==32||isset($seen[hash('sha256',$key)]))continue;$seen[hash('sha256',$key)]=true;try{$plain=(new Illuminate\Encryption\Encrypter($key,'AES-256-CBC'))->decrypt($row->two_factor_secret,false);if(is_string($plain)&&$plain!==''){$matches[]=['source'=>$file,'key'=>'base64:'.$encoded];}}catch(Illuminate\Contracts\Encryption\DecryptException){continue;}}}
$proof=['actor_id'=>19,'name'=>$row->name,'email'=>$row->email,'tested_distinct_keys'=>count($seen),'matched_sources'=>array_column($matches,'source'),'active_writes'=>0,'cipher_unchanged'=>true];
if($matches){file_put_contents($dir.'/functional-historical-key-private.json',json_encode(['cipher'=>'AES-256-CBC','keys'=>array_column($matches,'key')],JSON_THROW_ON_ERROR));}
file_put_contents($dir.'/functional-historical-key-provenance-qa-20261011.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
echo json_encode($proof,JSON_THROW_ON_ERROR).PHP_EOL;