Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contrib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rafael Bidegain
contrib
Commits
8df94473
Commit
8df94473
authored
4 years ago
by
Rafael Bidegain
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tsa2.rb
+92
-0
92 additions, 0 deletions
tsa2.rb
with
92 additions
and
0 deletions
tsa2.rb
0 → 100644
+
92
−
0
View file @
8df94473
#!/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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment