Sha256: 9b11e04d1f09fa4dd66992bcb49a2d115e7f41f6416e3dca73ae242af3014b36

Contents?: true

Size: 1.78 KB

Versions: 22

Compression:

Stored size: 1.78 KB

Contents

#!/usr/bin/env ruby

require 'openssl'
require 'awesome_print'

root_key = OpenSSL::PKey::RSA.new 2048 # the CA's public/private key
root_ca = OpenSSL::X509::Certificate.new
root_ca.version = 2 # cf. RFC 5280 - to make it a "v3" certificate
root_ca.serial = 1
root_ca.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby CA"
root_ca.issuer = root_ca.subject # root CA's are "self-signed"
root_ca.public_key = root_key.public_key
root_ca.not_before = Time.now
root_ca.not_after = root_ca.not_before + 2 * 365 * 24 * 60 * 60 # 2 years validity
ef = OpenSSL::X509::ExtensionFactory.new
ef.subject_certificate = root_ca
ef.issuer_certificate = root_ca
root_ca.add_extension(ef.create_extension("basicConstraints","CA:TRUE",true))
root_ca.add_extension(ef.create_extension("keyUsage","keyCertSign, cRLSign", true))
root_ca.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
root_ca.add_extension(ef.create_extension("authorityKeyIdentifier","keyid:always",false))
root_ca.sign(root_key, OpenSSL::Digest::SHA256.new)

key = OpenSSL::PKey::RSA.new 2048
cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 2
cert.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby certificate rbcert"
cert.issuer = root_ca.subject # root CA is the issuer
cert.public_key = key.public_key
cert.not_before = Time.now
cert.not_after = cert.not_before + 1 * 365 * 24 * 60 * 60 # 1 years validity
ef = OpenSSL::X509::ExtensionFactory.new
ef.subject_certificate = cert
ef.issuer_certificate = root_ca
cert.add_extension(ef.create_extension("keyUsage","digitalSignature", true))
cert.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
cert.sign(root_key, OpenSSL::Digest::SHA256.new)

File.write('ruby_user.crt', cert)
File.write('ruby_user.pub', cert.public_key)

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
cert_munger-1.0.0 spec/certs/create_spec_cert.rb
cert_munger-0.2.2 spec/certs/create_spec_cert.rb
cert_munger-0.2.1 spec/certs/create_spec_cert.rb
omniauth-dice-0.2.4 spec/certs/create_spec_cert.rb
cert_munger-0.2.0 spec/certs/create_spec_cert.rb
omniauth-dice-0.2.3 spec/certs/create_spec_cert.rb
omniauth-dice-0.2.2 spec/certs/create_spec_cert.rb
omniauth-dice-0.2.1 spec/certs/create_spec_cert.rb
omniauth-dice-0.2.0 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.9 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.8 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.7 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.6 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.5 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.4 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.3 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.2 spec/certs/create_spec_cert.rb
omniauth-dice-0.1.1 spec/certs/create_spec_cert.rb
cert_munger-0.1.1 spec/certs/create_spec_cert.rb
cert_munger-0.1.0 spec/certs/create_spec_cert.rb