Skip to content

Instantly share code, notes, and snippets.

@advorak
Created August 11, 2014 19:42
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 advorak/5762e79a3d82a1d3c95d to your computer and use it in GitHub Desktop.
Save advorak/5762e79a3d82a1d3c95d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# I am trying to replicate the successful connection granted by issuing the following command:
# openssl s_client -dtls1 -cipher DHE-DSS-AES256-SHA -connect 209.87.112.215:34135
# http://stackoverflow.com/questions/12836847/how-to-establish-a-ssl-enabled-tcp-ip-connection-in-ruby
require 'socket'
require 'openssl'
socket = TCPSocket.open('209.87.112.215', 34135)
ssl_context = OpenSSL::SSL::SSLContext.new
#ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
ssl_context.ssl_version = :TLSv1
ssl_context.ciphers = "DHE-DSS-AES256-SHA"
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
ssl_socket.sync_close = true
ssl_socket.connect
## Error occurs here, and I have a feeling it has to do with my failure to replicate
## the -dtls1 option in my ruby code:
#
# OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server hello A: sslv3 alert handshake failure
# from (irb):11:in `connect'
# from (irb):11
# from /home/advorak/.rbenv/versions/2.1.1/bin/irb:11:in `<main>'
while line = ssl_socket.gets
p line
end
ssl_socket.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment