Module: EventMachine::Socksify::SOCKS5

Defined in:
lib/em-socksify/socks5.rb

Instance Method Summary collapse

Instance Method Details

#socks_send_authenticationObject



33
34
35
36
37
38
39
40
# File 'lib/em-socksify/socks5.rb', line 33

def socks_send_authentication
  @socks_state = :authenticating

  send_data [5,
             @socks_username.length, @socks_username,
             @socks_password.length, @socks_password
             ].pack('CCA*CA*')
end

#socks_send_connect_requestObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/em-socksify/socks5.rb', line 15

def socks_send_connect_request
  @socks_state = :connecting

  send_data [5, 1, 0].pack('CCC')

  if matches = @socks_target_host.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
    send_data "\xF1\x00\x01" + matches.to_a[1 .. -1].map { |s| s.to_i }.pack('CCCC')

  elsif @socks_target_host =~ /^[:0-9a-f]+$/
    raise SOCKSError, 'TCP/IPv6 over SOCKS is not yet supported (inet_pton missing in Ruby & not supported by Tor)'

  else
    send_data [3, @socks_target_host.size, @socks_target_host].pack('CCA*')
  end

  send_data [@socks_target_port].pack('n')
end

#socks_send_handshakeObject



5
6
7
8
9
10
11
12
13
# File 'lib/em-socksify/socks5.rb', line 5

def socks_send_handshake
  # Method Negotiation as described on
  # http://www.faqs.org/rfcs/rfc1928.html Section 3
  @socks_state = :method_negotiation

  socks_methods.tap do |methods|
    send_data [5, methods.size].pack('CC') + methods.pack('C*')
  end
end