This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FACT-2330) Add ssh fact for Windows OpenSSH feature
- Loading branch information
Oana Tanasoiu
committed
Apr 15, 2020
1 parent
bc2aca6
commit 126eca8
Showing
9 changed files
with
541 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Windows | ||
class Ssh | ||
FACT_NAME = 'ssh' | ||
|
||
def call_the_resolver | ||
privileged = Facter::Resolvers::Identity.resolve(:privileged) | ||
ssh_info = Facter::Resolvers::Windows::Ssh.resolve(:ssh) if privileged | ||
ssh_facts = {} | ||
ssh_info&.each { |ssh| ssh_facts.merge!(create_ssh_fact(ssh)) } | ||
Facter::ResolvedFact.new(FACT_NAME, ssh_facts.empty? ? nil : ssh_facts) | ||
end | ||
|
||
private | ||
|
||
def create_ssh_fact(ssh) | ||
{ ssh.name.to_sym => | ||
{ fingerprints: { sha1: ssh.fingerprint.sha1, | ||
sha256: ssh.fingerprint.sha256 }, | ||
key: ssh.key, | ||
type: ssh.type } } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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] | ||
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 |
Oops, something went wrong.