mirror of
https://git.proxmox.com/git/pve-common
synced 2025-06-02 17:13:01 +00:00
Add validate_ssh_public_keys
validate format of SSH public keys using ssh-keygen -l and temp files.
This commit is contained in:
parent
344c19ff41
commit
48df47a466
@ -1307,4 +1307,19 @@ sub tempfile_contents {
|
||||
return ("/proc/$$/fd/".$fh->fileno, $fh);
|
||||
}
|
||||
|
||||
sub validate_ssh_public_keys {
|
||||
my ($raw) = @_;
|
||||
my @lines = split(/\n/, $raw);
|
||||
|
||||
foreach my $line (@lines) {
|
||||
next if $line =~ m/^\s*$/;
|
||||
eval {
|
||||
my ($filename, $handle) = tempfile_contents($line);
|
||||
run_command(["ssh-keygen", "-l", "-f", $filename],
|
||||
outfunc => sub {}, errfunc => sub {});
|
||||
};
|
||||
die "SSH public key validation error\n" if $@;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user