Skip to content

Instantly share code, notes, and snippets.

@sandro
Created April 9, 2012 15:41
Show Gist options
  • Save sandro/2344327 to your computer and use it in GitHub Desktop.
Save sandro/2344327 to your computer and use it in GitHub Desktop.
ssl socket tunneling proxy; performs an ssl handshake on behalf of another socket.
require 'net/http'
s = TCPSocket.open('localhost', 44567)
ss = OpenSSL::SSL::SSLSocket.new s
ss.sync_close = true
puts 'connecting...'
p ss.connect
puts 'done'
require 'socket'
BLOCK = 1024 * 16 * 16
def read(socket)
puts "reading #{socket.inspect}"
data = socket.sysread(BLOCK)
p data
puts
data
rescue => e
p e.inspect
sleep 1
retry
end
puts 'starting server'
server = TCPServer.new 44567
google = TCPSocket.new('google.com', 443)
puts 'got google'
client = server.accept
puts 'got client'
data = read(client)
google.syswrite(data)
data = read(google)
client.syswrite(data)
data = read(google)
client.syswrite(data)
data = read(client)
google.syswrite(data)
data = read(google)
client.syswrite(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment