Sha256: e942cb2902a4fe60bbef5b469bf452a4ee533fb3a3f4a9118a498a61f5c319ce

Contents?: true

Size: 1.45 KB

Versions: 15

Compression:

Stored size: 1.45 KB

Contents

# Fact: ssh
#
# Purpose:
#
# Resolution:
#
# Caveats:
#

## ssh.rb
## Facts related to SSH
##

{"SSHDSAKey" => { :file => "ssh_host_dsa_key.pub", :sshfprrtype => 2 } , "SSHRSAKey" => { :file => "ssh_host_rsa_key.pub", :sshfprrtype => 1 }, "SSHECDSAKey" => { :file => "ssh_host_ecdsa_key.pub", :sshfprrtype => 3 } }.each do |name,key|
  
  Facter.add(name) do
    setcode do
      value = nil
      
      [ "/etc/ssh",
        "/usr/local/etc/ssh",
        "/etc",
        "/usr/local/etc",
        "/etc/opt/ssh",
      ].each do |dir|
      
        filepath = File.join(dir,key[:file])
      
        if FileTest.file?(filepath)
          begin
            value = File.read(filepath).chomp.split(/\s+/)[1]
            break
          rescue
            value = nil
          end
        end
      end
      
      value
    end
  end
  
  Facter.add('SSHFP_' + name[3..-4]) do
    setcode do
      ssh = Facter.fact(name).value
      value = nil
      
      if ssh && key[:sshfprrtype]
        begin
          require 'digest/sha1'
          require 'base64'
          digest = Base64.decode64(ssh)
          value = 'SSHFP ' + key[:sshfprrtype].to_s + ' 1 ' + Digest::SHA1.hexdigest(digest)
          begin
            require 'digest/sha2'
            value += "\nSSHFP " + key[:sshfprrtype].to_s + ' 2 ' + Digest::SHA256.hexdigest(digest)
          rescue
          end
        rescue
          value = nil
        end
      end
      
      value
    end
    
  end
  
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
facter-1.7.6 lib/facter/ssh.rb
facter-1.7.5 lib/facter/ssh.rb
facter-1.7.5.rc2 lib/facter/ssh.rb
facter-1.7.5.rc1 lib/facter/ssh.rb
facter-1.7.4 lib/facter/ssh.rb
facter-1.7.4.rc1 lib/facter/ssh.rb
facter-1.7.3 lib/facter/ssh.rb
facter-1.7.3.rc1 lib/facter/ssh.rb
facter-1.7.2 lib/facter/ssh.rb
facter-1.7.2.rc1 lib/facter/ssh.rb
facter-1.7.1 lib/facter/ssh.rb
facter-1.7.1.rc1 lib/facter/ssh.rb
facter-1.7.0 lib/facter/ssh.rb
facter-1.7.0.rc2 lib/facter/ssh.rb
facter-1.7.0.rc1 lib/facter/ssh.rb