-
Notifications
You must be signed in to change notification settings - Fork 69
/
tcpProxy.rb
executable file
·67 lines (55 loc) · 1.53 KB
/
tcpProxy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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("/Users/romain/server.key").read)
sslContext.cert = OpenSSL::X509::Certificate.new(File.open("/Users/romain/server.crt").read)
sslServer = OpenSSL::SSL::SSLServer.new(server, sslContext)
puts "Listening on port #{listeningPort}"
bufferSize = 16
loop do
connection = sslServer.accept
Thread.new do
socket = TCPSocket.new('guzzoni.apple.com', 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