| 1 | package Net::SSH::Perl::Util::Hosts; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Net::SSH::Perl::Constants qw( :hosts ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Crypt::Misc qw( encode_b64 decode_b64 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Crypt::Mac::HMAC qw( hmac ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Socket; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use constant SALT_LEN => 20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | sub _check_host_in_hostfile { | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my($host, $port, $hostfile, $key) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_host_in_hostfile: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $key_class = ref($key); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if (defined $port && $port != 22) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $port and $port != 22
MC/DC0%0/2
defined $port and $port != 22
defined $port
$port != 22
Truth table0%0/3
A and B
A= defined $portB= $port != 22
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $host = "[$host]:$port"; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # ssh returns HOST_NEW if the host file can't be opened | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | open my $fh, '<', $hostfile or return HOST_NEW; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | local($_, $/); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $status = HOST_NEW; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | HOST: while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my ($hosts, $keyblob) = split /\s+/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | next unless $keyblob; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my $fkey; | |||||||||||||||||||||||||||||||||||||||||
| 32 | ## Trap errors for any potentially unsupported key types | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $fkey = $key_class->extract_public($keyblob); | |||||||||||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | next if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $checkhost = $host; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | ## Check for hashed entries | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if (index($hosts, '|') == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($hosts !~ /^\|1\|(.+?)\|/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | warn qq{Cannot parse line $. of $hostfile\n}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $salt = $1; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $rawsalt = decode_b64($salt); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $hash = encode_b64(hmac('SHA1',$rawsalt,$host)); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $checkhost = "|1|$salt|$hash"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | for my $h (split /,/, $hosts) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($h eq $checkhost && $key->ssh_name eq $fkey->ssh_name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$h eq $checkhost and $key->ssh_name eq $fkey->ssh_name
MC/DC0%0/2
$h eq $checkhost and $key->ssh_name eq $fkey->ssh_name
$h eq $checkhost
$key->ssh_name eq $fkey->ssh_name
Truth table0%0/3
A and B
A= $h eq $checkhostB= $key->ssh_name eq $fkey->ssh_name
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $status = $key->equal($fkey) ? HOST_OK : HOST_CHANGED; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | last HOST | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $status; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | sub _all_keys_for_host { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my($host, $port, $hostfile) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_keys_for_host: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $ip; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($host =~ /[a-zA-Z]+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $ip = inet_ntoa(inet_aton($host)); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (defined $port && $port != 22) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $port and $port != 22
MC/DC0%0/2
defined $port and $port != 22
defined $port
$port != 22
Truth table0%0/3
A and B
A= defined $portB= $port != 22
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $host = "[$host]:$port"; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $ip = "[$ip]:$port"; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | open my $fh, '<', $hostfile or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | local($_, $/); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my @keys; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my ($hosts, $keyblob) = split /\s+/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my @hosts_to_check = ($host); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | push @hosts_to_check, $ip if $ip; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | foreach my $checkhost (@hosts_to_check) { | |||||||||||||||||||||||||||||||||||||||||
| 86 | ## Check for hashed entries | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (index($hosts, '|') == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($hosts !~ /^\|1\|(.+?)\|/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | warn qq{Cannot parse line $. of $hostfile\n}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | next | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $salt = $1; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $rawsalt = decode_b64($salt); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $hash = encode_b64(hmac('SHA1',$rawsalt,$host)); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $checkhost = "|1|$salt|$hash"; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | for my $h (split /,/, $hosts) { | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($h eq $checkhost) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $fkey; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | eval { $fkey = Net::SSH::Perl::Key->extract_public($keyblob) }; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | push @keys, $fkey if $fkey; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | return wantarray ? @keys : \@keys | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | sub _add_host_to_hostfile { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my($host, $port, $hostfile, $key, $hash_flag) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_host_to_hostfile: not called CC=16 SCAR=54.6
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | unless (-e $hostfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | require File::Basename; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $dir = File::Basename::dirname($hostfile); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless (-d $dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | require File::Path; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | File::Path::mkpath([ $dir ]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | or die "Can't create directory $dir: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $ip; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($host =~ /[a-zA-Z]+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $ip = inet_ntoa(inet_aton($host)); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $ip = "[$ip]:$port" if $ip && defined $port && $port != 22; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ip and defined $port and $port != 22
$ip and defined $port
MC/DC0%0/3
$ip and defined $port and $port != 22
$ip
defined $port
$port != 22
Truth table0%0/4
A and B and C
A= $ipB= defined $portC= $port != 22
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $host = "[$host]:$port" if defined $port && $port != 22; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $port and $port != 22
MC/DC0%0/2
defined $port and $port != 22
defined $port
$port != 22
Truth table0%0/3
A and B
A= defined $portB= $port != 22
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | open my $fh, '>>', $hostfile or croak "Can't write to $hostfile: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($hash_flag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | ▶ | use Crypt::PRNG qw( random_bytes ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my @entries = ($host); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | push @entries, $ip if $ip; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | foreach my $entry (@entries) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $rawsalt = random_bytes(SALT_LEN); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $salt = encode_b64($rawsalt); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $hash = encode_b64(hmac('SHA1', $rawsalt, $entry)); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $data .= join(' ', "|1|$salt|$hash", $key->dump_public, "\n"); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $host = "$host,$ip" if $ip; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $data = join(' ', $host, $key->dump_public, "\n"); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | print $fh $data; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | close $fh or croak "Can't close $hostfile: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | sub _remove_host_from_hostfile { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my($host, $port, $hostfile, $key) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_host_from_hostfile: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | return unless -e $hostfile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $ip; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ($host =~ /[a-zA-Z]+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $ip = inet_ntoa(inet_aton($host)); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $ip = "[$ip]:$port" if $ip && defined $port && $port != 22; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ip and defined $port and $port != 22
$ip and defined $port
MC/DC0%0/3
$ip and defined $port and $port != 22
$ip
defined $port
$port != 22
Truth table0%0/4
A and B and C
A= $ipB= defined $portC= $port != 22
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $host = "[$host]:$port" if defined $port && $port != 22; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $port and $port != 22
MC/DC0%0/2
defined $port and $port != 22
defined $port
$port != 22
Truth table0%0/3
A and B
A= defined $portB= $port != 22
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | open my $fh, '<', $hostfile or croak "Can't open $hostfile: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | open my $fhw, '>', "$hostfile.new" or croak "Can't open $hostfile.new for writing: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | LINE: while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my ($hosts, $keyblob) = split /\s+/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $fkey; | |||||||||||||||||||||||||||||||||||||||||
| 169 | ## Trap errors for any potentially unsupported key types | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $fkey = Net::SSH::Perl::Key->extract_public($keyblob); | |||||||||||||||||||||||||||||||||||||||||
| 172 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | # keep it if we don't know what it is | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | print $fhw $_,"\n"; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | next LINE; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my @hosts_to_check = ($host); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | push @hosts_to_check, $ip if $ip; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | foreach my $checkhost (@hosts_to_check) { | |||||||||||||||||||||||||||||||||||||||||
| 183 | ## Check for hashed entries | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if (index($hosts, '|') == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if ($hosts !~ /^\|1\|(.+?)\|/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | warn qq{Cannot parse line $. of $hostfile\n}; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my $salt = $1; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $rawsalt = decode_b64($salt); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $hash = encode_b64(hmac('SHA1',$rawsalt,$checkhost)); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $checkhost = "|1|$salt|$hash"; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | for my $h (split /,/, $hosts) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ($h eq $checkhost && $key->equal($fkey)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$h eq $checkhost and $key->equal($fkey)
MC/DC0%0/2
$h eq $checkhost and $key->equal($fkey)
$h eq $checkhost
$key->equal($fkey)
Truth table0%0/3
A and B
A= $h eq $checkhostB= $key->equal($fkey)
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | next LINE; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | print $fhw $_,"\n"; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | close $fhw or croak "Can't close $hostfile.new: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | close $fh or croak "Can't close $hostfile: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | rename "$hostfile.new", $hostfile; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||