Skip to content

Instantly share code, notes, and snippets.

@rennex
Created March 10, 2022 20:54
Show Gist options
  • Save rennex/760023af341ee598d90d18255a866f05 to your computer and use it in GitHub Desktop.
Save rennex/760023af341ee598d90d18255a866f05 to your computer and use it in GitHub Desktop.
TLS connection in Ruby
require "socket"
require "openssl"
sock = TCPSocket.new(ARGV[0], ARGV[1].to_i)
ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER)
io = OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |socket|
socket.sync_close = true
socket.connect
end
loop do
p io.gets
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment