6 use Digest::SHA qw(sha256_hex);
 
  11 if (-f "/etc/ssh/ssh_known_hosts")
 
  13     open(HOSTS, "<", "/etc/ssh/ssh_known_hosts") || die $!;
 
  15     while (my $line = <HOSTS>)
 
  17         last if $line =~ /^# Manually maintained records$/;
 
  19         if ($line =~ /^([^, ]+)\S* (\S+) (\S+)$/)
 
  23             my $value = uc(sha256_hex(decode_base64($3)));
 
  25             $host =~ s/\.openstreetmap\.org$//;
 
  27             if ($algorithm ne "2")
 
  31                 $hosts{$host}->{$algorithm} = $value;
 
  39 open(SSHFP_JS, ">", "include/sshfp.js") || die $!;
 
  41 print SSHFP_JS qq|var SSHFP_RECORDS = [\n|;
 
  43 foreach my $host (sort keys %hosts)
 
  45     if ($hosts{$host}->{"ecdsa-sha2-nistp256"} || $hosts{$host}->{"ssh-ed25519"})
 
  47         if ($hosts{$host}->{"ecdsa-sha2-nistp256"})
 
  49             print SSHFP_JS sshfp_record($host, "3", $hosts{$host}->{"ecdsa-sha2-nistp256"});
 
  52         if ($hosts{$host}->{"ssh-ed25519"})
 
  54             print SSHFP_JS sshfp_record($host, "4", $hosts{$host}->{"ssh-ed25519"});
 
  57     elsif ($hosts{$host}->{"ssh-rsa"})
 
  59         print SSHFP_JS sshfp_record($host, "1", $hosts{$host}->{"ssh-rsa"});
 
  63 print SSHFP_JS qq|];\n|;
 
  72     my $algorithm = shift;
 
  75     return qq|  SSHFP("${host}", ${algorithm}, 2, "${value}"),\n|;