Sha256: be510b3dbfe1864b7e2c279016752ef067e0c4bfc6e813ae760f3029abd1bbf9

Contents?: true

Size: 1004 Bytes

Versions: 31

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

require 'base64'
require 'digest/sha1'

module Facter
  module Util
    module Resolvers
      class SshHelper
        class << self
          SSH_NAME = { 'ssh-dss' => 'dsa', 'ecdsa-sha2-nistp256' => 'ecdsa',
                       'ssh-ed25519' => 'ed25519', 'ssh-rsa' => 'rsa' }.freeze
          SSH_FINGERPRINT = { 'rsa' => 1, 'dsa' => 2, 'ecdsa' => 3, 'ed25519' => 4 }.freeze

          def create_ssh(key_type, key)
            key_name = SSH_NAME[key_type]
            return unless key_name

            decoded_key = Base64.decode64(key)
            ssh_fp = SSH_FINGERPRINT[key_name]
            sha1 = "SSHFP #{ssh_fp} 1 #{Digest::SHA1.new.update(decoded_key)}"
            sha256 = "SSHFP #{ssh_fp} 2 #{Digest::SHA2.new.update(decoded_key)}"

            fingerprint = Facter::Util::Resolvers::FingerPrint.new(sha1, sha256)
            Facter::Util::Resolvers::Ssh.new(fingerprint, key_type, key, key_name)
          end
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
facter-4.5.1 lib/facter/util/resolvers/ssh_helper.rb
facter-4.5.0 lib/facter/util/resolvers/ssh_helper.rb
facter-4.4.3 lib/facter/util/resolvers/ssh_helper.rb
facter-4.4.2 lib/facter/util/resolvers/ssh_helper.rb
facter-4.4.1 lib/facter/util/resolvers/ssh_helper.rb
facter-4.4.0 lib/facter/util/resolvers/ssh_helper.rb
facter-4.3.1 lib/facter/util/resolvers/ssh_helper.rb
facter-4.3.0 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.14 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.13 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.12 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.11 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.10 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.9 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.8 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.7 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.6 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.5 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.4 lib/facter/util/resolvers/ssh_helper.rb
facter-4.2.3 lib/facter/util/resolvers/ssh_helper.rb