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.14.2 lib/kontena/machine/cert_helper.rb
kontena-cli-0.14.1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.14.0 lib/kontena/machine/cert_helper.rb
kontena-cli-0.13.4 lib/kontena/machine/cert_helper.rb
kontena-cli-0.13.3 lib/kontena/machine/cert_helper.rb
kontena-cli-0.13.2 lib/kontena/machine/cert_helper.rb
kontena-cli-0.13.1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.13.0.1 lib/kontena/machine/cert_helper.rb
kontena-cli-0.13.0 lib/kontena/machine/cert_helper.rb
kontena-cli-0.12.3 lib/kontena/machine/cert_helper.rb
kontena-cli-0.12.2 lib/kontena/machine/cert_helper.rb
kontena-cli-0.12.1 lib/kontena/machine/cert_helper.rb