Skip to content

Commit d1affa2

Browse files
ubuntu versions (#151)
* ubuntu versions Add recent ubuntu versions to get the correct algorithms list. Signed-off-by: Michée Lengronne <[email protected]> * ubuntu versions comparison Signed-off-by: Michée Lengronne <[email protected]> * rubocop style Signed-off-by: Michée Lengronne <[email protected]> * useless rubocop rule Signed-off-by: Michée Lengronne <[email protected]>
1 parent 7f15d47 commit d1affa2

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

libraries/ssh_crypto.rb

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def ssh_version
2323
inspec.command('ssh -V 2>&1 | cut -f1 -d" " | cut -f2 -d"_"').stdout.to_f
2424
end
2525

26-
def valid_ciphers # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
26+
def valid_ciphers # rubocop:disable Metrics/CyclomaticComplexity
2727
# define a set of default ciphers
2828
ciphers53 = 'aes256-ctr,aes192-ctr,aes128-ctr'
2929
ciphers66 = '[email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr'
@@ -32,12 +32,7 @@ def valid_ciphers # rubocop:disable Metrics/CyclomaticComplexity, Metrics/Method
3232
# adjust ciphers based on OS + release
3333
case inspec.os[:name]
3434
when 'ubuntu'
35-
case inspec.os[:release]
36-
when '12.04'
37-
ciphers = ciphers53
38-
when '14.04', '15.10', '16.04', '18.04'
39-
ciphers = ciphers66
40-
end
35+
ciphers = ciphers66 if inspec.os[:release][0, 2] > '12'
4136
when 'debian'
4237
case inspec.os[:release]
4338
when /^6\./, /^7\./
@@ -73,7 +68,7 @@ def valid_ciphers # rubocop:disable Metrics/CyclomaticComplexity, Metrics/Method
7368
ciphers
7469
end
7570

76-
def valid_kexs # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
71+
def valid_kexs # rubocop:disable Metrics/CyclomaticComplexity
7772
# define a set of default KEXs
7873
kex66 = '[email protected],diffie-hellman-group-exchange-sha256'
7974
kex59 = 'diffie-hellman-group-exchange-sha256'
@@ -82,12 +77,7 @@ def valid_kexs # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLen
8277
# adjust KEXs based on OS + release
8378
case inspec.os[:name]
8479
when 'ubuntu'
85-
case inspec.os[:release]
86-
when '12.04'
87-
kex = kex59
88-
when '14.04', '15.10', '16.04', '18.04'
89-
kex = kex66
90-
end
80+
kex = kex66 if inspec.os[:release][0, 2] > '12'
9181
when 'debian'
9282
case inspec.os[:release]
9383
when /^6\./
@@ -136,12 +126,7 @@ def valid_macs # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLen
136126
# adjust MACs based on OS + release
137127
case inspec.os[:name]
138128
when 'ubuntu'
139-
case inspec.os[:release]
140-
when '12.04'
141-
macs = macs59
142-
when '14.04', '15.10', '16.04', '18.04'
143-
macs = macs66
144-
end
129+
macs = macs66 if inspec.os[:release][0, 2] > '12'
145130
when 'debian'
146131
case inspec.os[:release]
147132
when /^6\./
@@ -225,20 +210,15 @@ def valid_privseparation # rubocop:disable Metrics/CyclomaticComplexity
225210
end
226211

227212
# return a list of valid algoriths for a current platform
228-
def valid_algorithms # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
213+
def valid_algorithms # rubocop:disable Metrics/CyclomaticComplexity
229214
alg53 = %w[rsa]
230215
alg60 = %w[rsa ecdsa]
231216
alg66 = %w[rsa ecdsa ed25519]
232217
alg = alg66 # probably its a best suitable set for everything unknown
233218

234219
case inspec.os[:name]
235220
when 'ubuntu'
236-
case inspec.os[:release]
237-
when '12.04'
238-
alg = alg53
239-
when '14.04', '15.10', '16.04', '18.04'
240-
alg = alg66
241-
end
221+
alg = alg53 if inspec.os[:release][0, 2] < '14'
242222
when 'debian'
243223
case inspec.os[:release]
244224
when /^7\./

0 commit comments

Comments
 (0)