Class: CertificateAuthority::SigningRequestKeyMaterial
- Inherits:
-
Object
- Object
- CertificateAuthority::SigningRequestKeyMaterial
- Includes:
- ActiveModel::Validations, KeyMaterial
- Defined in:
- lib/certificate_authority/key_material.rb
Instance Attribute Summary collapse
- #certificate ⇒ CertificateAuthority::Certificate readonly
- #csr ⇒ OpenSSL::X509::Request, OpenSSL::Netscape::SPKI readonly
- #public_key ⇒ OpenSSL::Pkey::RSA
Instance Method Summary collapse
-
#initialize(request = nil) ⇒ SigningRequestKeyMaterial
constructor
A new instance of SigningRequestKeyMaterial.
- #is_in_hardware? ⇒ Boolean
- #is_in_memory? ⇒ Boolean
- #private_key ⇒ NilClass
-
#sign_and_certify(root_cert, key, serial_number, options = {}) ⇒ CertificateAuthority::Certificate
Given a root certificate and a key, will generate a signed certificate.
Constructor Details
#initialize(request = nil) ⇒ SigningRequestKeyMaterial
Returns a new instance of SigningRequestKeyMaterial.
81 82 83 84 85 86 87 |
# File 'lib/certificate_authority/key_material.rb', line 81 def initialize(request=nil) if request.is_a?(OpenSSL::X509::Request) || request.is_a?(OpenSSL::Netscape::SPKI) @csr = request raise "Invalid certificate signing request" unless @csr.verify(@csr.public_key) self.public_key = @csr.public_key end end |
Instance Attribute Details
#certificate ⇒ CertificateAuthority::Certificate (readonly)
78 79 80 |
# File 'lib/certificate_authority/key_material.rb', line 78 def certificate @certificate end |
#csr ⇒ OpenSSL::X509::Request, OpenSSL::Netscape::SPKI (readonly)
77 78 79 |
# File 'lib/certificate_authority/key_material.rb', line 77 def csr @csr end |
#public_key ⇒ OpenSSL::Pkey::RSA
131 132 133 |
# File 'lib/certificate_authority/key_material.rb', line 131 def public_key @public_key end |
Instance Method Details
#is_in_hardware? ⇒ Boolean
116 117 118 |
# File 'lib/certificate_authority/key_material.rb', line 116 def is_in_hardware? false end |
#is_in_memory? ⇒ Boolean
121 122 123 |
# File 'lib/certificate_authority/key_material.rb', line 121 def is_in_memory? true end |
#private_key ⇒ NilClass
126 127 128 |
# File 'lib/certificate_authority/key_material.rb', line 126 def private_key nil end |
#sign_and_certify(root_cert, key, serial_number, options = {}) ⇒ CertificateAuthority::Certificate
Given a root certificate and a key, will generate a signed certificate
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/certificate_authority/key_material.rb', line 95 def sign_and_certify(root_cert, key, serial_number, = {}) if csr.is_a? OpenSSL::Netscape::SPKI raise "Must pass :dn in options to generate certificates for OpenSSL::Netscape::SPKI requests" unless [:dn] end algorithm = [:algorithm] || OpenSSL::Digest::SHA1.new cert = OpenSSL::X509::Certificate.new if [:dn] cert.subject = [:dn].to_x509_name else cert.subject = csr.subject end cert.public_key = public_key cert.not_before = Time.now cert.not_after = [:not_after] || (Time.now + 100000000) cert.issuer = root_cert.subject.to_x509_name cert.serial = serial_number cert.sign key, algorithm @certificate = CertificateAuthority::Certificate.from_openssl cert end |