mirror of
https://github.com/inspec/inspec
synced 2024-11-14 00:47:10 +00:00
4b9acb4800
* Bump Rubocop to 0.49.1 This change bumps Rubocop to 0.49.1. There have been a lot of changes since 0.39.0 and this PR is hopefully a nice compromise of turning off certain cops and updating our codebase to take advantage of new Ruby 2.3 methods and operators. Signed-off-by: Adam Leff <adam@leff.co> * Set end-of-line format to line-feed only, avoid Windows-related CRLF issues Signed-off-by: Adam Leff <adam@leff.co>
83 lines
1.9 KiB
Ruby
83 lines
1.9 KiB
Ruby
# encoding: utf-8
|
|
# author: Doc Walker
|
|
|
|
require 'openssl'
|
|
|
|
class DhParams < Inspec.resource(1)
|
|
name 'dh_params'
|
|
|
|
desc '
|
|
Use the `dh_params` InSpec audit resource to test Diffie-Hellman (DH)
|
|
parameters.
|
|
'
|
|
|
|
example "
|
|
describe dh_params('/path/to/file.dh_pem') do
|
|
it { should be_dh_params }
|
|
it { should be_valid }
|
|
its('generator') { should eq 2 }
|
|
its('modulus') { should eq '00:91:a0:15:89:e5:bc:38:93:12:02:fc:...' }
|
|
its('prime_length') { should eq 2048 }
|
|
its('pem') { should eq '-----BEGIN DH PARAMETERS...' }
|
|
its('text') { should eq 'PKCS#3 DH Parameters: (2048 bit)...' }
|
|
end
|
|
"
|
|
|
|
def initialize(filename)
|
|
@dh_params_path = filename
|
|
file = inspec.file(@dh_params_path)
|
|
return skip_resource "Unable to find DH parameters file #{@dh_params_path}" unless file.exist?
|
|
|
|
begin
|
|
@dh_params = OpenSSL::PKey::DH.new file.content
|
|
rescue
|
|
@dh_params = nil
|
|
return skip_resource "Unable to load DH parameters #{@dh_params_path}"
|
|
end
|
|
end
|
|
|
|
# it { should be_dh_params }
|
|
def dh_params?
|
|
!@dh_params.nil?
|
|
end
|
|
|
|
# its('generator') { should eq 2 }
|
|
def generator
|
|
return if @dh_params.nil?
|
|
@dh_params.g.to_i
|
|
end
|
|
|
|
# its('modulus') { should eq '00:91:a0:15:89:e5:bc:38:93:12:02:fc:...' }
|
|
def modulus
|
|
return if @dh_params.nil?
|
|
'00:' + @dh_params.p.to_s(16).downcase.scan(/.{2}/).join(':')
|
|
end
|
|
|
|
# its('pem') { should eq '-----BEGIN DH PARAMETERS...' }
|
|
def pem
|
|
return if @dh_params.nil?
|
|
@dh_params.to_pem
|
|
end
|
|
|
|
# its('prime_length') { should be 2048 }
|
|
def prime_length
|
|
return if @dh_params.nil?
|
|
@dh_params.p.num_bits
|
|
end
|
|
|
|
# its('text') { should eq 'human-readable-text' }
|
|
def text
|
|
return if @dh_params.nil?
|
|
@dh_params.to_text
|
|
end
|
|
|
|
# it { should be_valid }
|
|
def valid?
|
|
return if @dh_params.nil?
|
|
@dh_params.params_ok?
|
|
end
|
|
|
|
def to_s
|
|
"dh_params #{@dh_params_path}"
|
|
end
|
|
end
|