Class: DhParams

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

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ DhParams

Returns a new instance of DhParams.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/resources/dh_params.rb', line 25

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

Instance Method Details

#dh_params?Boolean

it { should be_dh_params }

Returns:

  • (Boolean)


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

def dh_params?
  !@dh_params.nil?
end

#generatorObject

its(‘generator’) { should eq 2 }



44
45
46
47
# File 'lib/resources/dh_params.rb', line 44

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:…’ }



50
51
52
53
# File 'lib/resources/dh_params.rb', line 50

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…’ }



56
57
58
59
# File 'lib/resources/dh_params.rb', line 56

def pem
  return if @dh_params.nil?
  @dh_params.to_pem
end

#prime_lengthObject

its(‘prime_length’) { should be 2048 }



62
63
64
65
# File 'lib/resources/dh_params.rb', line 62

def prime_length
  return if @dh_params.nil?
  @dh_params.p.num_bits
end

#textObject

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



68
69
70
71
# File 'lib/resources/dh_params.rb', line 68

def text
  return if @dh_params.nil?
  @dh_params.to_text
end

#to_sObject



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

def to_s
  "dh_params #{@dh_params_path}"
end

#valid?Boolean

it { should be_valid }

Returns:

  • (Boolean)


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

def valid?
  return if @dh_params.nil?
  @dh_params.params_ok?
end