Sha256: 5f044f7bfefef38bbe0261fd823795138bcd21c96a9c9d73e6ed64b65c86c5f1

Contents?: true

Size: 1.1 KB

Versions: 52

Compression:

Stored size: 1.1 KB

Contents

require 'openssl'

module Kontena
  module Machine
    module CertHelper

      def generate_self_signed_cert
        key = OpenSSL::PKey::RSA.new(2048)
        public_key = key.public_key

        subject = "/C=FI/O=Test/OU=Test/CN=Test"

        cert = OpenSSL::X509::Certificate.new
        cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)
        cert.not_before = Time.now
        cert.not_after = Time.now + (10 * 365 * 24 * 60 * 60)
        cert.public_key = public_key
        cert.serial = 0x0
        cert.version = 2

        ef = OpenSSL::X509::ExtensionFactory.new
        ef.subject_certificate = cert
        ef.issuer_certificate = cert
        cert.extensions = [
          ef.create_extension("basicConstraints","CA:TRUE", true),
          ef.create_extension("subjectKeyIdentifier", "hash")
        ]
        cert.add_extension ef.create_extension("authorityKeyIdentifier",
                                               "keyid:always,issuer:always")

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

        pem = cert.to_pem
        pem << key.to_s
        pem
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
kontena-cli-0.16.3 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.3.rc1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.2 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.2.rc1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.1.rc3 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.1.rc2 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.1.rc1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.rc3 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.rc2 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.rc1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.pre9 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.pre8 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.pre7 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.pre6 lib/kontena/machine/cert_helper.rb
kontena-cli-0.15.5 lib/kontena/machine/cert_helper.rb
kontena-cli-0.15.5.rc2 lib/kontena/machine/cert_helper.rb
kontena-cli-0.15.5.rc1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.16.0.pre5 lib/kontena/machine/cert_helper.rb