Class: Ant::SSL::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ant/ssl/configuration.rb

Constant Summary collapse

ONE_YEAR =
60 * 60 * 24 * 365

Instance Method Summary collapse

Constructor Details

#initialize(root, group, cert) ⇒ Configuration

Returns a new instance of Configuration.



6
7
8
# File 'lib/ant/ssl/configuration.rb', line 6

def initialize(root, group, cert)
  @config = root.merge(group).merge(cert)
end

Instance Method Details

#[](key) ⇒ Object



49
50
51
# File 'lib/ant/ssl/configuration.rb', line 49

def [](key)
  @config[key]
end

#configure_cert_details!(cert) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/ant/ssl/configuration.rb', line 30

def configure_cert_details!(cert)
  cert.version = 2
  cert.serial = @config['serial']
  cert.subject = OpenSSL::X509::Name.parse(subject_string)
  cert.not_before = Time.now
  cert.not_after = cert.not_before + ONE_YEAR * @config['expiration']
end

#configure_extensions!(cert, extension_factory) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/ant/ssl/configuration.rb', line 38

def configure_extensions!(cert, extension_factory)
  @config['extensions'].each do |name, details|
    extension = extension_factory.create_extension(
      name,
      details['details'],
      details['critical']
    )
    cert.add_extension(extension)
  end
end

#crt_pathObject



16
17
18
# File 'lib/ant/ssl/configuration.rb', line 16

def crt_path
  saving_directory('crt')
end

#key_pathObject



20
21
22
# File 'lib/ant/ssl/configuration.rb', line 20

def key_path
  saving_directory('key')
end

#saving_directory(type) ⇒ Object



10
11
12
13
14
# File 'lib/ant/ssl/configuration.rb', line 10

def saving_directory(type)
  path = @config['saving_directory']
  serial = @config['serial']
  "#{path}/#{serial}.#{type}.pem"
end

#subject_stringObject



24
25
26
27
28
# File 'lib/ant/ssl/configuration.rb', line 24

def subject_string
  "/C=#{@config['country']}/ST=#{@config['state']}" \
  "/L=#{@config['city']}/O=#{@config['organization']}" \
  "/OU=#{@config['team']}/CN=#{@config['name']}"
end