Sha256: 54afd2ae9e9ee337e33899632045a86f086681d7b33ff681642ea38567c948eb

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

#!/usr/bin/env ruby

require 'bundler/setup'
require 'optparse'
require 'ostruct'

require 'cryptorecord/sshfp'

def read_local_hostkeys(options)
  Dir['/etc/ssh/ssh_host_*_key.pub'].each do |file_name|
    next if File.directory? file_name
    options.keyfile = file_name
    options.digest = 1
    sshfp = Cryptorecord::Sshfp.new(options.to_h)
    puts sshfp
    options.digest = 2
    sshfp = Cryptorecord::Sshfp.new(options.to_h)
    puts sshfp
  end
end

options = OpenStruct.new

##### DEFAULTS ####
options.digest = 2
options.read = 0
###################

OptionParser.new do |opt|
  opt.banner = "Usage: #{$PROGRAM_NAME} [ options ]"
  opt.on('-h', '--help', 'This help screen') do
    warn opt
    exit
  end
  opt.on('-f', '--hostkeyfile SSH-HOST-KEY-FILE',
         'SSH-Hostkey-File') { |o| options.keyfile = o }
  opt.on('-H', '--host HOST', 'host') { |o| options.host = o }
  opt.on('-d', '--digest DIGEST', 'HASH-Algorithm') { |o| options.digest = o }
  opt.on('-r', '--read-local-hostkeys',
         'Read all local Hostkeys.(like ssh-keygen -r)') { options.read = 1 }
  # this won't work with older ruby-versions
  options[:help] = opt.help
end.parse!

unless defined? options.keyfile && options.read == 1
  warn 'Usage-Error: No sshkeyfile was provided'
  exit 1
end

if options.read == 1
  read_local_hostkeys(options)
else
  sshfp = Cryptorecord::Sshfp.new(options.to_h)
  puts sshfp
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cryptorecord-1.0.0 exe/sshfprecord
cryptorecord-0.9.6 exe/sshfprecord
cryptorecord-0.9.2 exe/sshfprecord
cryptorecord-0.9.1 exe/sshfprecord