Class: Inspec::Resources::DhParams

Inherits:
Object
  • Object
show all
Includes:
FileReader
Defined in:
lib/inspec/resources/dh_params.rb

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(filename) ⇒ DhParams

Returns a new instance of DhParams.



27
28
29
30
# File 'lib/inspec/resources/dh_params.rb', line 27

def initialize(filename)
  @dh_params_path = filename
  @dh_params = OpenSSL::PKey::DH.new read_file_content(@dh_params_path)
end

Instance Method Details

#dh_params?Boolean

it { should be_dh_params }

Returns:

  • (Boolean)


33
34
35
# File 'lib/inspec/resources/dh_params.rb', line 33

def dh_params?
  !@dh_params.nil?
end

#generatorObject

its(‘generator’) { should eq 2 }



38
39
40
41
42
# File 'lib/inspec/resources/dh_params.rb', line 38

def generator
  return if @dh_params.nil?

  @dh_params.g.to_i
end

#modulusObject

its(‘modulus’) { should eq ‘00:91:a0:15:89:e5:bc:38:93:12:02:fc:…’ }



45
46
47
48
49
# File 'lib/inspec/resources/dh_params.rb', line 45

def modulus
  return if @dh_params.nil?

  "00:" + @dh_params.p.to_s(16).downcase.scan(/.{2}/).join(":")
end

#pemObject

its(‘pem’) { should eq ‘—–BEGIN DH PARAMETERS…’ }



52
53
54
55
56
# File 'lib/inspec/resources/dh_params.rb', line 52

def pem
  return if @dh_params.nil?

  @dh_params.to_pem
end

#prime_lengthObject

its(‘prime_length’) { should be 2048 }



59
60
61
62
63
# File 'lib/inspec/resources/dh_params.rb', line 59

def prime_length
  return if @dh_params.nil?

  @dh_params.p.num_bits
end

#resource_idObject



79
80
81
# File 'lib/inspec/resources/dh_params.rb', line 79

def resource_id
  @dh_params_path || "dh_params"
end

#textObject

its(‘text’) { should eq ‘human-readable-text’ }



66
67
68
69
70
# File 'lib/inspec/resources/dh_params.rb', line 66

def text
  return if @dh_params.nil?

  @dh_params.to_text
end

#to_sObject



83
84
85
# File 'lib/inspec/resources/dh_params.rb', line 83

def to_s
  "dh_params #{@dh_params_path}"
end

#valid?Boolean

it { should be_valid }

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/inspec/resources/dh_params.rb', line 73

def valid?
  return if @dh_params.nil?

  @dh_params.params_ok?
end