Sha256: 7123caaf9379b6ce220393900683923931e80b3a2a3424a9ad0e1fb9e30c62ed

Contents?: true

Size: 877 Bytes

Versions: 29

Compression:

Stored size: 877 Bytes

Contents

# frozen_string_literal: true

require 'base64'
require 'digest/sha1'

module Resolvers
  module Utils
    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]
          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::FingerPrint.new(sha1, sha256)
          Facter::Ssh.new(fingerprint, key_type, key, key_name)
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
facter-4.0.46 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.44 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.43 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.42 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.41 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.40 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.39 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.38 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.37 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.36 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.35 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.34 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.33 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.32 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.31 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.30 lib/facter/resolvers/utils/ssh_helper.rb
facter-4.0.29 lib/resolvers/utils/ssh_helper.rb
facter-4.0.28 lib/resolvers/utils/ssh_helper.rb
facter-4.0.26 lib/resolvers/utils/ssh_helper.rb
facter-4.0.25 lib/resolvers/utils/ssh_helper.rb