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

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

Class Method Summary collapse

Class Method Details

.authenticate(parameters) ⇒ Object



129
130
131
132
133
# File 'lib/httpx/plugins/proxy/socks5.rb', line 129

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

.connect(uri) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/httpx/plugins/proxy/socks5.rb', line 135

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



121
122
123
124
125
126
127
# File 'lib/httpx/plugins/proxy/socks5.rb', line 121

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