Class Jabber::Bytestreams::SOCKS5Socket
In: lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
Parent: TCPSocket

A SOCKS5 client implementation

Usage:

  • Initialize with proxy‘s address and port
  • Authenticate
  • Connect to target host

Methods

auth   connect_domain   new  

Public Class methods

Connect to SOCKS5 proxy

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb, line 20
20:       def initialize(socks_host, socks_port)
21:         super(socks_host, socks_port)
22:       end

Public Instance methods

Authenticate for SOCKS5 proxy

Currently supports only ‘no authentication required‘

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb, line 28
28:       def auth
29:         write("\x05\x01\x00")
30:         buf = read(2)
31:         if buf.nil? or buf != "\x05\x00"
32:           close
33:           raise SOCKS5Error.new("Invalid SOCKS5 authentication: #{buf.inspect}")
34:         end
35: 
36:         self
37:       end

Issue a CONNECT request to a host name which is to be resolved by the proxy.

domain:[String] Host name
port:[Fixnum] Port number

[Source]

    # File lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb, line 44
44:       def connect_domain(domain, port)
45:         write("\x05\x01\x00\x03#{domain.size.chr}#{domain}#{[port].pack("n")}")
46:         buf = read(4)
47:         if buf.nil? or buf[0..1] != "\005\000"
48:           close
49:           raise SOCKS5Error.new("Invalid SOCKS5 connect: #{buf.inspect}")
50:         end
51: 
52:         case buf.respond_to?(:bytes) ? buf.bytes.to_a[3] : buf[3]
53:           when 1 then read(6)  # IPv4 addr
54:           when 3 then read(3 + domain.size) # Domain
55:           when 4 then read(18) # IPv6 addr
56:           else
57:             close
58:             raise SOCKS5Error.new("Invalid SOCKS5 address type #{buf[3].to_s}")
59:         end
60: 
61:         self
62:       end

[Validate]