Class: Certify::Certificate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Certify::Certificate
- Defined in:
- app/models/certify/certificate.rb
Instance Method Summary collapse
-
#csr=(csrpem) ⇒ Object
set the csr where you want to generate a certificate from.
Instance Method Details
#csr=(csrpem) ⇒ Object
set the csr where you want to generate a certificate from
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/certify/certificate.rb', line 17 def csr=(csrpem) # read the csr csr = OpenSSL::X509::Request.new(csrpem) # get the ca_cert ca = self. ca_cert = ca.root_certificate ca_key = ca.private_key # generate a new cert csr_cert = OpenSSL::X509::Certificate.new csr_cert.serial = 0 csr_cert.version = 2 csr_cert.not_before = Time.now csr_cert.not_after = Time.now + 600 csr_cert.subject = csr.subject csr_cert.public_key = csr.public_key csr_cert.issuer = ca_cert.subject extension_factory = OpenSSL::X509::ExtensionFactory.new extension_factory.subject_certificate = csr_cert extension_factory.issuer_certificate = ca_cert extension_factory.create_extension 'basicConstraints', 'CA:FALSE' extension_factory.create_extension 'keyUsage', 'keyEncipherment,dataEncipherment,digitalSignature' extension_factory.create_extension 'subjectKeyIdentifier', 'hash' csr_cert.sign ca_key, OpenSSL::Digest::SHA1.new self.ssldata = csr_cert.to_pem end |