Skip to content

Instantly share code, notes, and snippets.

@brandonweeks
Created November 25, 2015 06:10
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 brandonweeks/e26414cc1e9eea9453a8 to your computer and use it in GitHub Desktop.
Save brandonweeks/e26414cc1e9eea9453a8 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'socket'
require 'webrick'
require 'webrick/ssl'
OpenSSL.debug = true
cert, key = WEBrick::Utils::create_self_signed_cert(2048, [['CN', 'nobody'], ['DC', 'example']], "Generated by Ruby/OpenSSL")
ctx = OpenSSL::SSL::SSLContext.new
ctx.cert = cert
ctx.key = key
ctx.ciphers = 'ECDH+aRSA'
puts "#{ctx.ciphers.count} ciphers"
tcps = TCPServer.new('127.0.0.1', 8443)
ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
ssls.start_immediately = true
begin
loop do
begin
ssl = ssls.accept
rescue OpenSSL::SSL::SSLError => e
puts e
next
end
puts "Connected"
begin
ssl.write('ACK')
ensure
ssl.close if ssl
end
end
ensure
tcps.close if tcps
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment