Class: Wsv::TlsContext::SelfSignedCert
- Inherits:
-
Object
- Object
- Wsv::TlsContext::SelfSignedCert
- Defined in:
- lib/wsv/tls_context/self_signed_cert.rb
Constant Summary collapse
- SUBJECT =
"/CN=localhost"- SAN =
"DNS:localhost,IP:127.0.0.1,IP:::1"- VALIDITY_SECONDS =
365 * 24 * 60 * 60
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(key) ⇒ SelfSignedCert
constructor
A new instance of SelfSignedCert.
Constructor Details
#initialize(key) ⇒ SelfSignedCert
Returns a new instance of SelfSignedCert.
17 18 19 |
# File 'lib/wsv/tls_context/self_signed_cert.rb', line 17 def initialize(key) @key = key end |
Class Method Details
.build(key) ⇒ Object
13 14 15 |
# File 'lib/wsv/tls_context/self_signed_cert.rb', line 13 def self.build(key) new(key).build end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wsv/tls_context/self_signed_cert.rb', line 21 def build cert = OpenSSL::X509::Certificate.new cert.version = 2 cert.serial = SecureRandom.random_number((2**63) - 1) + 1 cert.subject = OpenSSL::X509::Name.parse(SUBJECT) cert.issuer = cert.subject cert.public_key = @key.public_key cert.not_before = Time.now - 60 cert.not_after = Time.now + VALIDITY_SECONDS ef = OpenSSL::X509::ExtensionFactory.new(cert, cert) cert.add_extension(ef.create_extension("subjectAltName", SAN)) cert.add_extension(ef.create_extension("basicConstraints", "CA:FALSE", true)) cert.sign(@key, OpenSSL::Digest.new("SHA256")) cert end |