Class: EaSSL::AuthorityCertificate

Inherits:
Object
  • Object
show all
Defined in:
lib/eassl/authority_certificate.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 Method Summary collapse

Constructor Details

#initialize(options) ⇒ AuthorityCertificate

Returns a new instance of AuthorityCertificate.



9
10
11
12
13
14
# File 'lib/eassl/authority_certificate.rb', line 9

def initialize(options)
  @options = {
    :key => nil,        #required
    :name       => {},                #required, CertificateName
  }.update(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



39
40
41
# File 'lib/eassl/authority_certificate.rb', line 39

def method_missing(method)
  ssl.send(method)
end

Instance Method Details

#sslObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/eassl/authority_certificate.rb', line 16

def ssl
  cert = OpenSSL::X509::Certificate.new
  cert.not_before = Time.now
  cert.subject = cert.issuer = CertificateName.new({ :common_name => "CA" }.update(@options[:name])).ssl
  cert.not_after = cert.not_before + (365 * 5) * 24 * 60 * 60
  cert.public_key = @options[:key].public_key
  cert.serial = 1
  cert.version = 2 # X509v3
  
  ef = OpenSSL::X509::ExtensionFactory.new
  ef.subject_certificate = cert
  ef.issuer_certificate = cert
  cert.extensions = [
    ef.create_extension("basicConstraints","CA:TRUE"),
    ef.create_extension("keyUsage", "cRLSign, keyCertSign"),
    ef.create_extension("subjectKeyIdentifier", "hash"),
    ef.create_extension("nsComment", "Ruby/OpenSSL/EaSSL Generated Certificate"),
  ]
  cert.add_extension(ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always"))
  cert.sign(@options[:key].private_key, OpenSSL::Digest::SHA1.new)
  cert
end