Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion controls/sshd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@
impact 1.0
title 'Server: Specify SSH HostKeys'
desc 'Specify HostKey for protection against Man-In-The-Middle Attacks'

sshd_valid_hostkeys = ssh_crypto.valid_algorithms.map { |alg| "#{sshd_custom_path}/ssh_host_#{alg}_key" }
sshd_valid_hostkeys = sshd_valid_hostkeys[0] if sshd_valid_hostkeys.length == 1

describe sshd_config(sshd_custom_path + '/sshd_config') do
its('HostKey') { should cmp ssh_crypto.valid_hostkeys }
its('HostKey') { should cmp sshd_valid_hostkeys }
end
end

Expand Down
11 changes: 0 additions & 11 deletions libraries/ssh_crypto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,4 @@ def valid_algorithms # rubocop:disable Metrics/CyclomaticComplexity

alg
end

# returns the hostkeys value based on valid_algorithms
def valid_hostkeys
hostkeys = valid_algorithms.map { |alg| "#{sshd_custom_path}/ssh_host_#{alg}_key" }
# its('HostKey') provides a string for a single-element value.
# we have to return a string if we have a single-element
# https://github.com/chef/inspec/issues/1434
return hostkeys[0] if hostkeys.length == 1

hostkeys
end
end