Skip to content

Instantly share code, notes, and snippets.

@brandonweeks brandonweeks/ruby_ecdh_test.rb Secret
Created Nov 25, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.