Module: HTTPX::Plugins::Proxy::Socks5::Packet

Defined in:
lib/httpx/plugins/proxy/socks5.rb

Class Method Summary collapse

Class Method Details

.authenticate(parameters) ⇒ Object



139
140
141
142
143
# File 'lib/httpx/plugins/proxy/socks5.rb', line 139

def authenticate(parameters)
  user = parameters.username
  pass = parameters.password
  [0x01, user.bytesize, user, pass.bytesize, password].pack("CCA*CA*")
end

.connect(uri) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/httpx/plugins/proxy/socks5.rb', line 145

def connect(uri)
  packet = [VERSION, CONNECT, 0].pack("C*")
  begin
    ip = IPAddr.new(uri.host)
    raise Error, "Socks4 connection to #{ip} not supported" unless ip.ipv4?
    packet << [IPV4, ip.to_i].pack("CN")
  rescue IPAddr::InvalidAddressError
    packet << [DOMAIN, uri.host.bytesize, uri.host].pack("CCA*")
  end
  packet << [uri.port].pack("n")
  packet
end

.negotiate(parameters) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/httpx/plugins/proxy/socks5.rb', line 131

def negotiate(parameters)
  methods = [NOAUTH]
  methods << PASSWD if parameters.authenticated?
  methods.unshift(methods.size)
  methods.unshift(VERSION)
  methods.pack("C*")
end