mirror of
https://github.com/ovh/the-bastion.git
synced 2025-02-27 09:04:13 +08:00
enh: egress ssh key: compute an ID so that keys can be pointed to and deleted
This commit is contained in:
parent
c88be2def1
commit
fe58cf1d14
1 changed files with 15 additions and 0 deletions
|
@ -270,6 +270,7 @@ sub get_ssh_pub_key_info {
|
|||
|
||||
$pubKey =~ s/[\r\n]//g;
|
||||
|
||||
my $mtime;
|
||||
if ($file) {
|
||||
if (open(my $fh, '<', $file)) {
|
||||
$pubKey = <$fh>;
|
||||
|
@ -278,6 +279,7 @@ sub get_ssh_pub_key_info {
|
|||
else {
|
||||
return R('ERR_CANNOT_OPEN_FILE', msg => "Couldn't open specified file ($!)");
|
||||
}
|
||||
$mtime = (stat($file))[9];
|
||||
}
|
||||
|
||||
# some little sanity check
|
||||
|
@ -302,12 +304,19 @@ sub get_ssh_pub_key_info {
|
|||
if ($prefix =~ /^from=["']([^ "']+)/) {
|
||||
@fromList = split /,/, $1;
|
||||
}
|
||||
|
||||
# generate a uniq id f($line)
|
||||
require Digest::MD5;
|
||||
my $id = 'id' . substr(Digest::MD5::md5_hex($line), 0, 8);
|
||||
|
||||
my %return = (
|
||||
prefix => $prefix,
|
||||
typecode => $typecode,
|
||||
base64 => $base64,
|
||||
comment => $comment,
|
||||
line => $line,
|
||||
id => $id,
|
||||
mtime => $mtime,
|
||||
fromList => \@fromList,
|
||||
);
|
||||
|
||||
|
@ -699,6 +708,12 @@ sub print_public_key {
|
|||
|
||||
require Term::ANSIColor;
|
||||
|
||||
# if id is passed directly, this is a key from an authkeys file, the id is the line number
|
||||
# otherwise, we should have an id within the key, it depends on $key->line, usually this is a key from a .pub file (no line number)
|
||||
if (!$id && $key->{'id'}) {
|
||||
$id = $key->{'id'};
|
||||
}
|
||||
|
||||
my $line = $key->{'line'};
|
||||
if ($key->{'base64'}) {
|
||||
$line = sprintf("%s%s %s %s", $key->{'prefix'} ? $key->{'prefix'} . ' ' : '', $key->{'typecode'}, $key->{'base64'}, $key->{'comment'});
|
||||
|
|
Loading…
Reference in a new issue