Created
December 1, 2011 16:10
-
-
Save guanix/1417859 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "socket" | |
require "openssl" | |
require "thread" | |
listeningPort = 443 | |
server = TCPServer.new(listeningPort) | |
sslContext = OpenSSL::SSL::SSLContext.new | |
sslContext.key = OpenSSL::PKey::RSA.new(File.open("nemid.key").read) | |
sslContext.cert = OpenSSL::X509::Certificate.new(File.open("nemid.crt").read) | |
sslServer = OpenSSL::SSL::SSLServer.new(server, sslContext) | |
puts "Listening on port #{listeningPort}" | |
bufferSize = 16 | |
loop do | |
connection = sslServer.accept | |
Thread.new do | |
puts "new thread" | |
socket = TCPSocket.new('87.48.159.22', 443) | |
ssl = OpenSSL::SSL::SSLSocket.new(socket) | |
ssl.sync_close = true | |
ssl.connect | |
# Thread.new do | |
# begin | |
# while lineIn = ssl.gets | |
# lineIn = lineIn.chomp | |
# $stdout.puts lineIn | |
# end | |
# rescue | |
# $stderr.puts "Error in input loop: " + $! | |
# end | |
# end | |
# while (lineOut = $stdin.gets) | |
# lineOut = lineOut.chomp | |
# ssl.puts lineOut | |
# end | |
begin | |
while (buffer = connection.read(bufferSize)) | |
ssl.write buffer | |
inBuffer = ssl.read | |
lineIn = lineIn.chomp | |
$stdout.puts "=> " + lineIn | |
lineOut = "You said: " + lineIn | |
$stdout.puts "<= " + lineOut | |
connection.puts lineOut | |
end | |
rescue | |
$stderr.puts $! | |
end | |
end | |
end | |
# ssl : proxy <-> Guzzoni | |
# connection : iPhone <-> proxy | |
# | |
# ssl.read -> récupère de guzzoni | |
# ssl.write -> envoie à guzzoni | |
# connection.read -> récupère de l'iPhone | |
# connection.write -> envoi à l'iPhone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment