class Ritm::Certificate
Wraps a SSL Certificate
via on-the-fly creation or loading from files
Attributes
cert[RW]
Public Class Methods
create(common_name, serial_number: nil) { |cert| ... }
click to toggle source
# File lib/ritm/certs/certificate.rb, line 16 def self.create(common_name, serial_number: nil) cert = CertificateAuthority::Certificate.new cert.subject.common_name = common_name cert.subject.organization = cert.subject.organizational_unit = 'dongjia' cert.subject.country = 'CN' cert.not_before = Time.now - 7 * 24 * 60 * 60 # 7 days before cert.not_after = cert.not_before + 397 * 24 * 60 * 60 # 397 days cert.serial_number.number = serial_number || common_name.hash.abs cert.key_material.generate_key(2048) yield cert if block_given? new cert end
load(crt, private_key) { |cert| ... }
click to toggle source
# File lib/ritm/certs/certificate.rb, line 8 def self.load(crt, private_key) x509 = OpenSSL::X509::Certificate.new(crt) cert = CertificateAuthority::Certificate.from_openssl(x509) cert.key_material.private_key = OpenSSL::PKey::RSA.new(private_key) yield cert if block_given? new cert end
new(cert)
click to toggle source
# File lib/ritm/certs/certificate.rb, line 29 def initialize(cert) @cert = cert end
Public Instance Methods
pem()
click to toggle source
# File lib/ritm/certs/certificate.rb, line 41 def pem @cert.to_pem end
private_key()
click to toggle source
# File lib/ritm/certs/certificate.rb, line 33 def private_key @cert.key_material.private_key end
public_key()
click to toggle source
# File lib/ritm/certs/certificate.rb, line 37 def public_key @cert.key_material.public_key end
x509()
click to toggle source
# File lib/ritm/certs/certificate.rb, line 45 def x509 @cert.openssl_body end