Sha256: 724a7deaf7fb1fa8d5626a9dc39900ade0d632618ab2e44c672258708e6694ec

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

module CertificateGenerator

  class CACertificateGenerator < Base

    def generate_ca_cert (subject, output_dir)

      key = OpenSSL::PKey::RSA.new(2048)

      cert = OpenSSL::X509::Certificate.new
      cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)

      cert.not_before = Time.now
      cert.not_after = Time.now + (3600*24*365) # add a year
      cert.public_key = key.public_key
      cert.serial = 0
      cert.version = 2

      ef = OpenSSL::X509::ExtensionFactory.new
      ef.subject_certificate = ef.issuer_certificate = cert

      cert.extensions = [
        ef.create_extension("basicConstraints","CA:TRUE"),
        ef.create_extension("keyUsage","Certificate Sign, CRL Sign"),
      ]

      cert.sign key, OpenSSL::Digest::SHA1.new

      save_cert_and_key cert, key, output_dir, 'ca'

      return cert, key

    end
    
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
certificate_generator-0.0.2 lib/certificate_generator/ca_certificate_generator.rb