Skip to content

Instantly share code, notes, and snippets.

Created April 22, 2013 19:50
Show Gist options
  • Save anonymous/bfb3b887e71fc5ba1851 to your computer and use it in GitHub Desktop.
Save anonymous/bfb3b887e71fc5ba1851 to your computer and use it in GitHub Desktop.
class MyServer < Sinatra::Base
use Rack::Session::Pool
register Sinatra::ActiveRecordExtension
def self.run!
name = "/C=US/ST=SomeState/L=SomeCity/O=Organization/OU=Unit/CN=localhost"
ca = OpenSSL::X509::Name.parse(name)
key = OpenSSL::PKey::RSA.new(1024)
crt = OpenSSL::X509::Certificate.new
crt.version = 2
crt.serial = 1
crt.subject = ca
crt.issuer = ca
crt.public_key = key.public_key
crt.not_before = Time.now-1000
crt.not_after = Time.now + 1 * 365 * 24 * 60 * 60
ssl_options = {
:private_key => key,
:cert_chain => crt,
:verify_peer => false,
}
Rack::Handler::Thin.run(self, :Port=>3001) do |server|
server.ssl = true
server.ssl_options = ssl_options
end
end
get '/' do
end
end
MyServer.run!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment