Class: EaSSL::CertificateAuthority

Inherits:
Object
  • Object
show all
Defined in:
lib/eassl/certificate_authority.rb

Overview

Author

Paul Nicholson ([email protected])

Co-Author

Adam Williams ([email protected])

Copyright

Copyright © 2006 WebPower Design

License

Distributes under the same terms as Ruby

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CertificateAuthority

Returns a new instance of CertificateAuthority.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eassl/certificate_authority.rb', line 10

def initialize(options = {})
  if options[:key] && options[:certificate] && options[:serial]
    @key = options[:key]
    @certificate = options[:certificate]
    @serial = options[:serial]
  else
    options[:name] ||= {}
    @key = Key.new({:password => 'ca_ssl_password'}.update(options))
    @certificate = AuthorityCertificate.new(:key => @key, :name => options[:name])
    @serial = Serial.new(:next => 1)
  end
end

Instance Attribute Details

#certificateObject (readonly)

Returns the value of attribute certificate.



9
10
11
# File 'lib/eassl/certificate_authority.rb', line 9

def certificate
  @certificate
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/eassl/certificate_authority.rb', line 9

def key
  @key
end

#serialObject (readonly)

Returns the value of attribute serial.



9
10
11
# File 'lib/eassl/certificate_authority.rb', line 9

def serial
  @serial
end

Class Method Details

.load(options) ⇒ Object



23
24
25
26
27
28
# File 'lib/eassl/certificate_authority.rb', line 23

def self.load(options)
  key = Key.load(File.join(options[:ca_path], 'cakey.pem'), options[:ca_password])
  certificate = AuthorityCertificate.load(File.join(options[:ca_path], 'cacert.pem'))
  serial = Serial.load(File.join(options[:ca_path], 'serial.txt'))
  self.new(:key => key, :certificate => certificate, :serial => serial)
end

Instance Method Details

#create_certificate(signing_request, type = 'server', days_valid = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/eassl/certificate_authority.rb', line 30

def create_certificate(signing_request, type='server', days_valid=nil)
  options = {
    :signing_request => signing_request,
    :ca_certificate => @certificate,
    :serial => @serial.issue_serial,
    :type => type
  }
  if days_valid
    options[:days_valid] = days_valid
  end
  cert = Certificate.new(options)
  @serial.save!
  cert.sign(@key)
  cert
end