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

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

Class Method Summary collapse

Class Method Details

.authenticate(parameters) ⇒ Object



152
153
154
155
156
# File 'lib/httpx/plugins/proxy/socks5.rb', line 152

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

.connect(uri) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/httpx/plugins/proxy/socks5.rb', line 158

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



144
145
146
147
148
149
150
# File 'lib/httpx/plugins/proxy/socks5.rb', line 144

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