Archived
1
0

fix check_ssh_key

This commit is contained in:
Mercier Pierre-Olivier 2013-09-06 05:24:42 +02:00
parent cc1b765e58
commit 41ac95c878

View File

@ -16,9 +16,11 @@ use ACU::Log;
sub check_key($) sub check_key($)
{ {
my $filename = shift;
# Call ssh-keygen # Call ssh-keygen
if (`ssh-keygen -l -f ".shift." 2> /dev/null` =~ /^([0-9]+) [0-9a-f:]+ [a-zA-Z0-9\/_-]+ \(([A-Z]+)\)$/) if (`ssh-keygen -l -f $filename 2> /dev/null` =~ /^([0-9]+) [0-9a-f:]+ [a-zA-Z0-9\/_-]+ \(([A-Z]+)\)$/)
{ {
log INFO, "Receive valid key: type $2, size $1";
if ($2 eq "RSA") { if ($2 eq "RSA") {
if ($1 >= 4096) { if ($1 >= 4096) {
return API::Base::make_response("0", "Clef RSA valide."); return API::Base::make_response("0", "Clef RSA valide.");
@ -34,7 +36,7 @@ sub check_key($)
return API::Base::make_response("3", "Veuillez utiliser ssh-keygen -t rsa ou ssh-keygen -t ecdsa"); return API::Base::make_response("3", "Veuillez utiliser ssh-keygen -t rsa ou ssh-keygen -t ecdsa");
} }
else { else {
do_warn(""); do_warn("Unknown type: $2");
return API::Base::make_response("3", "Veuillez utiliser ssh-keygen -t rsa ou ssh-keygen -t ecdsa"); return API::Base::make_response("3", "Veuillez utiliser ssh-keygen -t rsa ou ssh-keygen -t ecdsa");
} }
} }
@ -52,13 +54,15 @@ sub process
print $fh $args->{param}{key}; print $fh $args->{param}{key};
close $fh; close $fh;
check_key $filename; my $msg = check_key $filename;
unlink $filename; unlink $filename;
return $msg;
} }
if (@ARGV) { if (@ARGV) {
check_key check_key shift;
} }
else { else {
Process::register("check_ssh_key", \&process); Process::register("check_ssh_key", \&process);