Sha256: d63ba1f7b28caa6f352e4af1b31bec65719ad68319cba60d9ce818e93aa62f30

Contents?: true

Size: 1.7 KB

Versions: 33

Compression:

Stored size: 1.7 KB

Contents

# =XMPP4R - XMPP Library for Ruby
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
# Website::http://home.gna.org/xmpp4r/

require 'socket'

module Jabber
  module Bytestreams

    ##
    # A SOCKS5 client implementation
    #
    # ==Usage:
    # * Initialize with proxy's address and port
    # * Authenticate
    # * Connect to target host
    class SOCKS5Socket < TCPSocket
      ##
      # Connect to SOCKS5 proxy
      def initialize(socks_host, socks_port)
        super(socks_host, socks_port)
      end

      ##
      # Authenticate for SOCKS5 proxy
      #
      # Currently supports only 'no authentication required'
      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

      ##
      # Issue a CONNECT request to a host name
      # which is to be resolved by the proxy.
      # domain:: [String] Host name
      # port:: [Fixnum] Port number
      def connect_domain(domain, port)
        write("\x05\x01\x00\x03#{domain.size.chr}#{domain}#{[port].pack("n")}")
        buf = read(4)
        if buf.nil? or buf[0..1] != "\005\000"
          close
          raise SOCKS5Error.new("Invalid SOCKS5 connect: #{buf.inspect}")
        end

        case buf.respond_to?(:bytes) ? buf.bytes.to_a[3] : buf[3]
          when 1 then read(6)  # IPv4 addr
          when 3 then read(3 + domain.size) # Domain
          when 4 then read(18) # IPv6 addr
          else
            close
            raise SOCKS5Error.new("Invalid SOCKS5 address type #{buf[3].to_s}")
        end

        self
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 13 rubygems

Version Path
brontes3d-xmpp4r-0.4 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
bryanl-xmpp4r-0.3.2 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
edavey-xmpp4r-0.4.1 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
edavey-xmpp4r-0.4.2 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
edavey-xmpp4r-0.4 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
heipei-xmpp4r-0.3.2 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
ln-xmpp4r-0.5 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
mojodna-xmpp4r-0.4.0.2 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
mojodna-xmpp4r-0.4.0.3 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
seanohalpin-xmpp4r-0.4.1 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
xmpp4r-0.5.5 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
gmcmillan-xmpp4r-0.6.2 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
gmcmillan-xmpp4r-0.6.1 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
gmcmillan-xmpp4r-0.6 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
gmcmillan-xmpp4r-0.5 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
mad-p-xmpp4r-0.6.3 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
mad-p-xmpp4r-0.6.2 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
mad-p-xmpp4r-0.6.1 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
mad-p-xmpp4r-0.6.0 lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb
cerberus-0.8.0 lib/vendor/xmpp4r/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb