Skip to content
Snippets Groups Projects
Commit c092b520 authored by Rafael Bidegain's avatar Rafael Bidegain
Browse files

tsa2.php es un script en php fork de tsa2.sh, sella y verifica ejecutandolo desde una consola.

parent 8df94473
No related branches found
No related tags found
No related merge requests found
tsa2.php 0 → 100644
#!/usr/bin/env php
<?php
#
# tsa2.php en un script en php para Sellar y/o Verificar un archivo en la BFA.
# basado en tsa2.sh de Robert Martin-Legene
# Autor: Rafael Bidegain, rbidegain@loteriadelaciudad.gob.ar
#
# Licencia: GPLv2-only, 21 de mayo de 2021
#
function existeArchivo($file) {
return is_file($file);
}
function getSha($file) {
return hash_file('sha256', $file);
}
function firmar($hash) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://tsa2.buenosaires.gob.ar:443/stamp");
#curl_setopt($ch, CURLOPT_URL, "http://tsa.ultimamilla.com.ar/stamp");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"hashes\":[\"$hash\"]}");
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
}
function verificar($hash){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://tsa2.buenosaires.gob.ar:443/verify/$hash");
#curl_setopt($ch, CURLOPT_URL, "http://tsa.ultimamilla.com.ar/verify/$hash");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
else {
print "$result\n";
}
curl_close($ch);
}
function formaDeUso(){
print "forma de uso:\n";
print "./tsa2.php stamp|verify archivo\n";
}
#---------------------------------------------------------------------
# Comienzo
#---------------------------------------------------------------------
if ($argc != 3) {
print "ERROR. Se requieren dos argumentos\n\n";
formaDeUso();
exit(1);
}
$archivo = $argv[2];
if (existeArchivo($archivo) ) {
$sha = getSha($archivo);
#print "$sha\n";
switch ($argv[1]) {
case "stamp":
firmar($sha);
break;
case "verify":
verificar($sha);
break;
default:
print "ERROR. La acción a realizar debe ser stamp o verify\n";
print "\"$argv[1]\" no es una acción contemplada\n\n";
formaDeUso();
exit(1);
}
}
else {
print "No existe el archivo $archivo\n\n";
formaDeUso();
exit(1);
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment