Created
March 10, 2022 20:54
-
-
Save rennex/760023af341ee598d90d18255a866f05 to your computer and use it in GitHub Desktop.
TLS connection in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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