Skip to content

Instantly share code, notes, and snippets.

@mostlyfine
Created May 25, 2016 03:52
Show Gist options
  • Save mostlyfine/e50107d86e83a2a9049c21eec988d563 to your computer and use it in GitHub Desktop.
Save mostlyfine/e50107d86e83a2a9049c21eec988d563 to your computer and use it in GitHub Desktop.
Creating an SSL certificate for Sinatra
require "webrick"
require "webrick/https"
require "openssl"
require 'sinatra'
configure do
cn = [[ "CN", WEBrick::Utils::getservername]]
cert, rsa = WEBrick::Utils::create_self_signed_cert(2048, cn, "Generated by Ruby/OpenSSL")
set :server_settings, {
SSLEnable: true,
SSLVerifyClient: OpenSSL::SSL::VERIFY_NONE,
SSLCertificate: OpenSSL::X509::Certificate.new(cert.to_s),
SSLPrivateKey: OpenSSL::PKey::RSA.new(rsa.to_s),
SSLCertName: cn,
}
end
get "/" do
"hello SSL world!"
end
@mostlyfine
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment