Sha256: 39328043c53e2e2cfc43ee76f454bf6ced212da237fc091db5edd8a13dedcb19

Contents?: true

Size: 1.56 KB

Versions: 99

Compression:

Stored size: 1.56 KB

Contents

# Fact: ssh
#
# Purpose:
#   Gather facts related to SSH.
#
# 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 },
 "SSHED25519Key" => { :file => "ssh_host_ed25519_key.pub", :sshfprrtype => 4 } }.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

99 entries across 99 versions & 2 rubygems

Version Path
facter-2.5.7 lib/facter/ssh.rb
facter-2.5.7-x86-mingw32 lib/facter/ssh.rb
facter-2.5.7-x64-mingw32 lib/facter/ssh.rb
facter-2.5.7-universal-darwin lib/facter/ssh.rb
facter-2.5.6-x86-mingw32 lib/facter/ssh.rb
facter-2.5.6-x64-mingw32 lib/facter/ssh.rb
facter-2.5.6-universal-darwin lib/facter/ssh.rb
facter-2.5.6 lib/facter/ssh.rb
facter-2.5.5-x86-mingw32 lib/facter/ssh.rb
facter-2.5.5-x64-mingw32 lib/facter/ssh.rb
facter-2.5.5-universal-darwin lib/facter/ssh.rb
facter-2.5.5 lib/facter/ssh.rb
facter-2.5.4-x86-mingw32 lib/facter/ssh.rb
facter-2.5.4-x64-mingw32 lib/facter/ssh.rb
facter-2.5.4-universal-darwin lib/facter/ssh.rb
facter-2.5.4 lib/facter/ssh.rb
bolt-0.24.0 vendored/facter/lib/facter/ssh.rb
bolt-0.23.0 vendored/facter/lib/facter/ssh.rb
bolt-0.22.0 vendored/facter/lib/facter/ssh.rb
bolt-0.21.8 vendored/facter/lib/facter/ssh.rb