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

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

parent db6aeb46
No related branches found
No related tags found
No related merge requests found
tsa2.rb 0 → 100644
#!/usr/bin/env ruby
#
# tsa2.rb en un script en ruby 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, 15 de mayo de 2021
#
require 'digest'
require 'net/http'
require 'uri'
require 'json'
def existeArchivo(file)
return File.exist?(file)
end
def getSha(file)
return Digest::SHA256.hexdigest( File.read(file) )
end
def sellar(sha)
#
# convertido a ruby usando: https://jhawthorn.github.io/curl-to-ruby/
#
uri = URI.parse("https://tsa2.buenosaires.gob.ar:443/stamp")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request.body = JSON.dump({ "hashes" => ["#{sha}" ] })
req_options = {
use_ssl: uri.scheme == "https",
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
end
def verificar(sha)
uri = URI("https://tsa2.buenosaires.gob.ar:443/verify/#{sha}");
# prueba con la ip de ultima milla
# uri = URI("http://201.190.184.52/verify/#{sha}");
response = Net::HTTP.get_response(URI(uri))
print "#{response}\n"
print "#{response.body}\n"
end
def formaDeUso
print "forma de uso:\n"
print "./tsa2.rb stamp|verify archivo\n"
end
#---------------------------------------------------------------------
# Comienzo
#---------------------------------------------------------------------
if ARGV.length != 2 then
print "ERROR. Se requieren dos argumentos\n\n"
formaDeUso
exit(1)
end
archivo = ARGV[1]
if existeArchivo(archivo)
sha = getSha(archivo)
#print "#{sha}\n"
case ARGV[0]
when "stamp"
sellar(sha)
#print "sellado\n"
when "verify"
verificar(sha)
#print "verificado\n"
else
print "ERROR. La acción a realizar debe ser stamp o verify\n"
print "\"#{ARGV[0]}\" no es una acción contemplada\n\n"
formaDeUso
exit(1)
end
else
print "ERROR. No existe el archivo #{archivo}\n\n"
formaDeUso
exit(1)
end
exit(0)
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