Class: Jabber::Bytestreams::SOCKS5Socket

Inherits:
TCPSocket
  • Object
show all
Defined in:
lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb

Overview

A SOCKS5 client implementation

Usage:

  • Initialize with proxy’s address and port

  • Authenticate

  • Connect to target host

Instance Method Summary collapse

Constructor Details

#initialize(socks_host, socks_port) ⇒ SOCKS5Socket

Connect to SOCKS5 proxy



20
21
22
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb', line 20

def initialize(socks_host, socks_port)
  super(socks_host, socks_port)
end

Instance Method Details

#authObject

Authenticate for SOCKS5 proxy

Currently supports only ‘no authentication required’



28
29
30
31
32
33
34
35
36
37
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb', line 28

def auth
  write("\x05\x01\x00")
  buf = read(2)
  if buf.nil? or buf != "\x05\x00"
    close
    raise SOCKS5Error.new("Invalid SOCKS5 authentication: #{buf.inspect}")
  end

  self
end

#connect_domain(domain, port) ⇒ Object

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

domain
String

Host name

port
Fixnum

Port number



44
45
46
47
48
49
50
51
52
53
# File 'lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb', line 44

def connect_domain(domain, port)
  write("\x05\x01\x00\x03#{domain.size.chr}#{domain}#{[port].pack("n")}")
  buf = read(7 + domain.size)
  if buf.nil? or buf[0..1] != "\005\000"
    close
    raise SOCKS5Error.new("Invalid SOCKS5 connect: #{buf.inspect}")
  end

  self
end