File tree Expand file tree Collapse file tree 5 files changed +46
-22
lines changed Expand file tree Collapse file tree 5 files changed +46
-22
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,13 @@ def get_server_kexs(enable_weak = false)
119119 get_crypto_data ( :kexs , :server , enable_weak )
120120 end
121121
122+ { client : 'sshclient' ,
123+ server : 'sshserver' } . each do |k , v |
124+ define_method ( "get_ssh_#{ k } _version" ) do
125+ get_ssh_version ( node [ 'ssh-hardening' ] [ v ] [ 'package' ] )
126+ end
127+ end
128+
122129 private
123130
124131 # :nocov:
@@ -170,13 +177,6 @@ def find_ssh_version(version, versions)
170177 found_ssh_version
171178 end
172179
173- { client : 'sshclient' ,
174- server : 'sshserver' } . each do |k , v |
175- define_method ( "get_ssh_#{ k } _version" ) do
176- get_ssh_version ( node [ 'ssh-hardening' ] [ v ] [ 'package' ] )
177- end
178- end
179-
180180 def get_ssh_version ( package )
181181 version = node [ 'packages' ] [ package ] [ 'version' ]
182182 # on debian we get the epoch in front of version number: 1:7.2p2-4ubuntu2.1
Original file line number Diff line number Diff line change 4848 {
4949 mac : node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'mac' ] || DevSec ::Ssh . get_client_macs ( node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'weak_hmac' ] ) ,
5050 kex : node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'kex' ] || DevSec ::Ssh . get_client_kexs ( node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'weak_kex' ] ) ,
51- cipher : node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'cipher' ] || DevSec ::Ssh . get_client_ciphers ( node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'cbc_required' ] )
51+ cipher : node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'cipher' ] || DevSec ::Ssh . get_client_ciphers ( node [ 'ssh-hardening' ] [ 'ssh' ] [ 'client' ] [ 'cbc_required' ] ) ,
52+ version : DevSec ::Ssh . get_ssh_client_version
5253 }
5354 end
5455 )
Original file line number Diff line number Diff line change @@ -195,20 +195,6 @@ def self.debug(*); end
195195 end
196196 end
197197
198- describe 'get_ssh_server_version' do
199- it 'should call get_ssh_version with server package attribute' do
200- expect ( subject ) . to receive ( :get_ssh_version ) . with ( package_name )
201- subject . send ( :get_ssh_server_version )
202- end
203- end
204-
205- describe 'get_ssh_client_version' do
206- it 'should call get_ssh_version with client package attribute' do
207- expect ( subject ) . to receive ( :get_ssh_version ) . with ( package_name )
208- subject . send ( :get_ssh_client_version )
209- end
210- end
211-
212198 describe 'find_ssh_version' do
213199 context 'when it gets the valid ssh version' do
214200 it 'should return the next small version' do
@@ -314,4 +300,18 @@ def self.debug(*); end
314300 end
315301 end
316302 end
303+
304+ describe 'get_ssh_server_version' do
305+ it 'should call get_ssh_version with server package attribute' do
306+ expect ( subject ) . to receive ( :get_ssh_version ) . with ( package_name )
307+ subject . send ( :get_ssh_server_version )
308+ end
309+ end
310+
311+ describe 'get_ssh_client_version' do
312+ it 'should call get_ssh_version with client package attribute' do
313+ expect ( subject ) . to receive ( :get_ssh_version ) . with ( package_name )
314+ subject . send ( :get_ssh_client_version )
315+ end
316+ end
317317end
Original file line number Diff line number Diff line change 219219 end
220220 end
221221
222+ describe 'version specifc options' do
223+ context 'running with OpenSSH < 7.6' do
224+ it 'should have RhostsRSAAuthentication and RSAAuthentication' do
225+ expect ( chef_run ) . to render_file ( '/etc/ssh/ssh_config' ) . with_content ( /RhostsRSAAuthentication/ )
226+ expect ( chef_run ) . to render_file ( '/etc/ssh/ssh_config' ) . with_content ( /RSAAuthentication/ )
227+ end
228+ end
229+
230+ context 'running with OpenSSH >= 7.6 on Ubuntu 18.04' do
231+ cached ( :chef_run ) do
232+ ChefSpec ::ServerRunner . new ( version : '18.04' ) . converge ( described_recipe )
233+ end
234+
235+ it 'should not have RhostsRSAAuthentication and RSAAuthentication' do
236+ expect ( chef_run ) . to_not render_file ( '/etc/ssh/ssh_config' ) . with_content ( /RhostsRSAAuthentication/ )
237+ expect ( chef_run ) . to_not render_file ( '/etc/ssh/ssh_config' ) . with_content ( /RSAAuthentication/ )
238+ end
239+ end
240+ end
241+
222242 context 'chef-solo' do
223243 cached ( :chef_run ) do
224244 ChefSpec ::SoloRunner . new . converge ( described_recipe )
Original file line number Diff line number Diff line change @@ -82,10 +82,13 @@ ForwardX11 no
8282
8383# Never use host-based authentication. It can be exploited.
8484HostbasedAuthentication no
85+
86+ <% if @version.to_f < 7.6 %>
8587RhostsRSAAuthentication no
8688
8789# Enable RSA authentication via identity files.
8890RSAAuthentication yes
91+ <% end %>
8992
9093# Disable password-based authentication, it can allow for potentially easier brute-force attacks.
9194PasswordAuthentication <%= ((@node['ssh-hardening']['ssh']['client']['password_authentication']) ? "yes" : "no" ) %>
You can’t perform that action at this time.
0 commit comments