Class: Ritm::Certificate
- Inherits:
-
Object
- Object
- Ritm::Certificate
- Defined in:
- lib/ritm/certs/certificate.rb
Overview
Wraps a SSL Certificate via on-the-fly creation or loading from files
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cert ⇒ Object
Returns the value of attribute cert.
Class Method Summary collapse
- .create(common_name, serial_number: nil) {|cert| ... } ⇒ Object
- .load(crt, private_key) {|cert| ... } ⇒ Object
Instance Method Summary collapse
-
#initialize(cert) ⇒ Certificate
constructor
A new instance of Certificate.
- #pem ⇒ Object
- #private_key ⇒ Object
- #public_key ⇒ Object
- #x509 ⇒ Object
Constructor Details
#initialize(cert) ⇒ Certificate
Returns a new instance of Certificate.
28 29 30 |
# File 'lib/ritm/certs/certificate.rb', line 28 def initialize(cert) @cert = cert end |
Instance Attribute Details
#cert ⇒ Object
Returns the value of attribute cert.
6 7 8 |
# File 'lib/ritm/certs/certificate.rb', line 6 def cert @cert end |
Class Method Details
.create(common_name, serial_number: nil) {|cert| ... } ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# 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 = 'RubyInTheMiddle' cert.subject.country = 'AR' cert.not_before = cert.not_before - 3600 * 24 * 30 # Substract 30 days cert.serial_number.number = serial_number || common_name.hash.abs cert.key_material.generate_key(1024) yield cert if block_given? new cert end |
.load(crt, private_key) {|cert| ... } ⇒ Object
8 9 10 11 12 13 14 |
# 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 |
Instance Method Details
#pem ⇒ Object
40 41 42 |
# File 'lib/ritm/certs/certificate.rb', line 40 def pem @cert.to_pem end |
#private_key ⇒ Object
32 33 34 |
# File 'lib/ritm/certs/certificate.rb', line 32 def private_key @cert.key_material.private_key end |
#public_key ⇒ Object
36 37 38 |
# File 'lib/ritm/certs/certificate.rb', line 36 def public_key @cert.key_material.public_key end |
#x509 ⇒ Object
44 45 46 |
# File 'lib/ritm/certs/certificate.rb', line 44 def x509 @cert.openssl_body end |