Skip to content

Instantly share code, notes, and snippets.

@AlexKalinin
Forked from hvasconcelos/gen_keys.sh
Created October 27, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexKalinin/66682105917fc246f4703df095c656e5 to your computer and use it in GitHub Desktop.
Save AlexKalinin/66682105917fc246f4703df095c656e5 to your computer and use it in GitHub Desktop.
Create an Sinatra SSL Server
# Generate a self-signed Certificate and a Private Key
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout pkey.pem -out cert.crt
require 'sinatra'
require './sinatra_ssl'
set :ssl_certificate, "cert.crt"
set :ssl_key, "pkey.pem"
set :port, 9494
get '/try' do
"helloworld"
end
require 'webrick/ssl'
module Sinatra
class Application
def self.run!
certificate_content = File.open(ssl_certificate).read
key_content = File.open(ssl_key).read
server_options = {
:Host => bind,
:Port => port,
:SSLEnable => true,
:SSLCertificate => OpenSSL::X509::Certificate.new(certificate_content),
# 123456 is the Private Key Password
:SSLPrivateKey => OpenSSL::PKey::RSA.new(key_content,"123456")
}
Rack::Handler::WEBrick.run self, server_options do |server|
[:INT, :TERM].each { |sig| trap(sig) { server.stop } }
server.threaded = settings.threaded if server.respond_to? :threaded=
set :running, true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment