Class: Ant::SSL::Certificate

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

Overview

Stores a X509 certificate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, inventory) ⇒ Certificate

Returns a new instance of Certificate.



11
12
13
14
15
16
17
18
19
# File 'lib/ant/ssl/certificate.rb', line 11

def initialize(config, inventory)
  @config = config
  @inventory = inventory
  @key = OpenSSL::PKey::RSA.new(@config['key_size'])
  @cert = OpenSSL::X509::Certificate.new
  @cert.public_key = @key.public_key
  @extensions = OpenSSL::X509::ExtensionFactory.new
  @extensions.subject_certificate = @cert
end

Instance Attribute Details

#certObject (readonly)

Returns the value of attribute cert.



9
10
11
# File 'lib/ant/ssl/certificate.rb', line 9

def cert
  @cert
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/ant/ssl/certificate.rb', line 9

def key
  @key
end

Instance Method Details

#ca_nameObject



50
51
52
# File 'lib/ant/ssl/certificate.rb', line 50

def ca_name
  @config['ca']
end

#configure_details!Object



31
32
33
# File 'lib/ant/ssl/certificate.rb', line 31

def configure_details!
  @config.configure_cert_details!(@cert)
end

#configure_extensions!Object



35
36
37
38
# File 'lib/ant/ssl/certificate.rb', line 35

def configure_extensions!
  @extensions.issuer_certificate = @ca.cert
  @config.configure_extensions!(@cert, @extensions)
end

#create!Object



21
22
23
24
25
26
27
28
29
# File 'lib/ant/ssl/certificate.rb', line 21

def create!
  return if File.file?(@config.key_path)

  @ca = @inventory.ca(@config['parent'])
  configure_details!
  configure_extensions!
  sign!
  save!
end

#save!Object



45
46
47
48
# File 'lib/ant/ssl/certificate.rb', line 45

def save!
  File.write(@config.key_path, @key.to_s)
  File.write(@config.crt_path, @cert.to_s)
end

#sign!Object



40
41
42
43
# File 'lib/ant/ssl/certificate.rb', line 40

def sign!
  @cert.issuer = @ca.cert.subject
  @cert.sign(@ca.key, OpenSSL::Digest::SHA256.new)
end