Class: Ant::SSL::Certificate

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, inventory) ⇒ Certificate

Returns a new instance of Certificate.



8
9
10
11
12
13
14
15
16
# File 'lib/ant/ssl/certificate.rb', line 8

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.



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

def cert
  @cert
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#ca_nameObject



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

def ca_name
  @config['ca']
end

#configure_details!Object



27
28
29
# File 'lib/ant/ssl/certificate.rb', line 27

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

#configure_extensions!Object



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

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

#create!Object



18
19
20
21
22
23
24
25
# File 'lib/ant/ssl/certificate.rb', line 18

def create!
  # return if File.file?(@config.key_path)
  @ca = @inventory.ca(@config['parent'])
  configure_details!
  configure_extensions!
  sign!
  save!
end

#save!Object



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

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

#sign!Object



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

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