check_ssh_key: now check file content before type validity
This commit is contained in:
parent
6dca90348a
commit
cb9bf00da4
@ -17,8 +17,16 @@ use ACU::Log;
|
|||||||
sub check_key($)
|
sub check_key($)
|
||||||
{
|
{
|
||||||
my $filename = shift;
|
my $filename = shift;
|
||||||
|
|
||||||
|
# Check file content format
|
||||||
|
open my $fh, "<", $filename;
|
||||||
|
my $fcnt = <$fh>;
|
||||||
|
close $fh;
|
||||||
|
chomp($fcnt);
|
||||||
|
|
||||||
# Call ssh-keygen
|
# Call ssh-keygen
|
||||||
if (`ssh-keygen -l -f $filename 2> /dev/null` =~ /^([0-9]+) +[0-9a-f:]+ +.+ +\(([A-Z]+)\)$/)
|
if ($fcnt =~ /^(ssh|ecdsa)-[a-z0-9-]+ [a-zA-Z0-9+=\/]+( .*)?$/ &&
|
||||||
|
`ssh-keygen -l -f $filename 2> /dev/null` =~ /^([0-9]+) +[0-9a-f:]+ +.+ +\(([A-Z]+)\)$/)
|
||||||
{
|
{
|
||||||
log INFO, "Receive valid key: type $2, size $1";
|
log INFO, "Receive valid key: type $2, size $1";
|
||||||
if ($2 eq "RSA") {
|
if ($2 eq "RSA") {
|
||||||
|
Reference in New Issue
Block a user