aboutsummaryrefslogtreecommitdiffstats
path: root/examples/static_server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'examples/static_server.rb')
-rw-r--r--examples/static_server.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/examples/static_server.rb b/examples/static_server.rb
index 452f718..189c9e6 100644
--- a/examples/static_server.rb
+++ b/examples/static_server.rb
@@ -1,5 +1,3 @@
-# frozen-string-literal: true
-
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
require "plum"
require "openssl"
@@ -26,13 +24,17 @@ ctx.alpn_select_cb = -> protocols {
raise "Client does not support HTTP/2: #{protocols}" unless protocols.include?("h2")
"h2"
}
-if ctx.respond_to?(:tmp_ecdh_callback) && !ctx.respond_to?(:set_ecdh_curves)
- ctx.tmp_ecdh_callback = -> (sock, ise, keyl) {
- OpenSSL::PKey::EC.new("prime256v1")
- }
-end
-ctx.cert = OpenSSL::X509::Certificate.new File.read(File.expand_path("../../test/server.crt", __FILE__))
-ctx.key = OpenSSL::PKey::RSA.new File.read(File.expand_path("../../test/server.key", __FILE__))
+ctx.key = OpenSSL::PKey::RSA.new(2048)
+cert = OpenSSL::X509::Certificate.new
+cert.version = 2
+cert.serial = 12345
+cert.subject = OpenSSL::X509::Name.parse_rfc2253("CN=localhost")
+cert.issuer = cert.subject
+cert.public_key = ctx.key
+cert.not_before = Time.now - 3600
+cert.not_after = Time.now + 3600
+cert.sign(ctx.key, "sha256")
+ctx.cert = cert
tcp_server = TCPServer.new("0.0.0.0", 40443)
ssl_server = OpenSSL::SSL::SSLServer.new(tcp_server, ctx)