Class: EventMachine::CertificateCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/em/pure_ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCertificateCreator



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/em/pure_ruby.rb', line 71

def initialize
  @key = OpenSSL::PKey::RSA.new(1024)
  public_key = @key.public_key
  subject = "/C=EventMachine/O=EventMachine/OU=EventMachine/CN=EventMachine"
  @cert = OpenSSL::X509::Certificate.new
  @cert.subject = @cert.issuer = OpenSSL::X509::Name.parse(subject)
  @cert.not_before = Time.now
  @cert.not_after = Time.now + 365 * 24 * 60 * 60
  @cert.public_key = public_key
  @cert.serial = 0x0
  @cert.version = 2
  factory = OpenSSL::X509::ExtensionFactory.new
  factory.subject_certificate = @cert
  factory.issuer_certificate = @cert
  @cert.extensions = [
    factory.create_extension("basicConstraints","CA:TRUE", true),
    factory.create_extension("subjectKeyIdentifier", "hash")
  ]
  @cert.add_extension factory.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
  @cert.sign(@key, OpenSSL::Digest::SHA1.new)
end

Instance Attribute Details

#certObject (readonly)

Returns the value of attribute cert



69
70
71
# File 'lib/em/pure_ruby.rb', line 69

def cert
  @cert
end

#keyObject (readonly)

Returns the value of attribute key



69
70
71
# File 'lib/em/pure_ruby.rb', line 69

def key
  @key
end