Module: Hop::DevTls
- Defined in:
- lib/hop/dev_tls.rb
Overview
DEV/TEST ONLY: an in-process self-signed cert for the discovery example + test (no openssl CLI,
no gems; OpenSSL ships with Ruby). Never use a self-signed cert in production; there a real WebPKI
cert proves the domain.
Class Method Summary collapse
-
.server_context(cn = "localhost") ⇒ Object
An SSLContext backed by a fresh in-process self-signed cert (RSA-2048, CN=
, 1h).
Class Method Details
.server_context(cn = "localhost") ⇒ Object
An SSLContext backed by a fresh in-process self-signed cert (RSA-2048, CN=
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hop/dev_tls.rb', line 11 def self.server_context(cn = "localhost") key = OpenSSL::PKey::RSA.new(2048) cert = OpenSSL::X509::Certificate.new cert.version = 2 cert.serial = 1 cert.subject = OpenSSL::X509::Name.parse("/CN=#{cn}") cert.issuer = cert.subject cert.public_key = key.public_key cert.not_before = Time.now - 60 cert.not_after = Time.now + 3600 cert.sign(key, OpenSSL::Digest.new("SHA256")) ctx = OpenSSL::SSL::SSLContext.new ctx.cert = cert ctx.key = key ctx end |