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
a3e8d2d5
Commit
a3e8d2d5
authored
3 years ago
by
Rafael Bidegain
Browse files
Options
Downloads
Patches
Plain Diff
tsa2.pl es un script en perl fork de tsa2.sh, sella y verifica ejecutandolo desde una consola.
parent
c092b520
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tsa2.pl
+103
-0
103 additions, 0 deletions
tsa2.pl
with
103 additions
and
0 deletions
tsa2.pl
0 → 100644
+
103
−
0
View file @
a3e8d2d5
#!/usr/bin/env perl
#
# tsa2.pl en un script en perl 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
#
use
Digest::
file
qw(digest_file_hex)
;
use
LWP::
UserAgent
;
use
HTTP::
Request
();
sub
existeArchivo
()
{
$file
=
@_
[
0
];
return
(
-
e
$file
);
}
sub
getSha
(){
$file
=
@_
[
0
];
return
digest_file_hex
(
$file
,
"
SHA-256
");
}
sub
formaDeUso
()
{
print
"
forma de uso:
\n
";
print
"
./tsa2.pl stamp|verify archivo
\n
";
}
sub
sellar
(){
my
$hash
=
@_
[
0
];
my
$uri
=
"
https://tsa2.buenosaires.gob.ar:443/stamp
";
my
$json
=
'
{"hashes":["
'
.
$hash
.
'
"]}
';
my
$req
=
HTTP::
Request
->
new
(
'
POST
',
$uri
);
$req
->
header
(
'
Content-Type
'
=>
'
application/json
'
);
$req
->
content
(
$json
);
my
$lwp
=
LWP::
UserAgent
->
new
;
$lwp
->
request
(
$req
);
}
sub
verificar
(){
my
$hash
=
@_
[
0
];
my
$URL
=
"
https://tsa2.buenosaires.gob.ar:443/verify/
$hash
";
my
$ua
=
LWP::
UserAgent
->
new
(
ssl_opts
=>
{
verify_hostname
=>
1
});
my
$header
=
HTTP::
Request
->
new
(
GET
=>
$URL
);
my
$request
=
HTTP::
Request
->
new
('
GET
',
$URL
,
$header
);
my
$response
=
$ua
->
request
(
$request
);
if
(
$response
->
is_success
){
#print "URL:$URL\nHeaders:\n";
#print $response->headers_as_string;
print
$response
->
content
,"
\n
";
}
elsif
(
$response
->
is_error
){
print
"
Error:
$URL
\n
";
print
$response
->
error_as_HTML
,
"
\n
";
}
}
#---------------------------------------------------------------------
# Comienzo
#---------------------------------------------------------------------
#print "argumentos: $#ARGV \n";
#print "$ARGV[0] \n";
#print "$ARGV[1] \n";
#print "\n------------------------\n";
if
(
$#ARGV
!=
1
)
{
print
"
ERROR. Se requieren dos argumentos
\n\n
";
&formaDeUso
();
exit
(
1
);
}
my
$archivo
=
$ARGV
[
1
];
if
(
&existeArchivo
(
$archivo
)
){
$sha
=
&getSha
(
$archivo
);
print
"
$sha
\n
";
if
(
$ARGV
[
0
]
eq
"
stamp
")
{
&sellar
(
$sha
);
#print "sellado\n";
}
else
{
if
(
$ARGV
[
0
]
eq
"
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
);
}
}
}
else
{
print
"
ERROR. No existe el archivo
$archivo
\n\n
";
&formaDeUso
();
exit
(
1
);
}
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