Compare commits

..

No commits in common. "26c39a797782c55d657f649f9d1b2a7753ba5f3e" and "7f8a0b3ffe217d8e5985b0da60f0c12089e04c57" have entirely different histories.

13 changed files with 24 additions and 138 deletions

View File

@ -23,7 +23,7 @@ First is to enable ruby programmers to use HTTP or SOCKS proxies
interchangeably when using TCPSockets. Either manually with
`Proxifier::Proxy#open` or by `require "proxifier/env"`.
The second purpose is to use ruby code that doesn't use proxies for users that
The second purpose is to use ruby code that doesn't user proxies for users that
have to use proxies.<br>The pruby and pirb executables are simple wrappers for
their respective ruby executables that support proxies from environment
variables.

View File

@ -1,10 +1 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
task default: :test
Rake::TestTask.new do |task|
task.libs << 'lib' << 'spec'
task.pattern = 'spec/**/*_spec.rb'
task.verbose = true
end
require "bundler/gem_tasks"

View File

@ -6,7 +6,7 @@ module Proxifier
def open(host, port, local_host = nil, local_port = nil)
return TCPSocket.new(host, port, local_host, local_port, :proxy => nil) unless proxify?(host)
socket = TCPSocket.new(self.host, self.port, local_host, local_port, :proxy => nil)
socket = TCPSocket.new(proxy.host, proxy.port, local_host, local_port, :proxy => nil)
begin
proxify(socket, host, port)

View File

@ -8,8 +8,7 @@ module Proxifier
socket << "CONNECT #{host}:#{port} HTTP/1.1\r\n"
socket << "Host: #{host}:#{port}\r\n"
socket << "Proxy-Authorization: Basic #{Base64.strict_encode64("#{user}:#{password}").chomp}\r\n" if user
socket << "User-Agent: #{user_agent}\r\n" if user_agent
socket << "Proxy-Authorization: Basic #{["#{user}:#{password}"].pack("m").chomp}\r\n" if user
socket << "\r\n"
buffer = Net::BufferedIO.new(socket)

View File

@ -4,7 +4,6 @@ require "proxifier/proxy"
module Proxifier
class SOCKSProxy < Proxy
VERSION = 0x05
SUBNEGOTIATION_VERSION = 0x01
def do_proxify(socket, host, port)
authenticaton_method = greet(socket)
@ -27,12 +26,12 @@ module Proxifier
case method
when 0x00 # NO AUTHENTICATION REQUIRED
when 0x02 # USERNAME/PASSWORD
_user = user ? user[0, 0xFF] : ''
_password = password ? password[0, 0xFF] : ''
user &&= user[0, 0xFF]
password &&= password[0, 0xFF]
socket << [SUBNEGOTIATION_VERSION, _user.size, _user, _password.size, _password].pack("CCA#{_user.size}CA#{_password.size}")
version, status = socket.read(2).unpack('CC')
check_version(version, SUBNEGOTIATION_VERSION)
socket << [user.size, user, password.size, password].pack("CA#{user.size}CA#{password.size}")
version, status = socket.read(2).unpack("CC")
check_version(version)
case status
when 0x00 # SUCCESS

View File

@ -16,14 +16,14 @@ module Proxifier
attr_reader :url, :options
def initialize(url, options = {})
url = URI.parse(url) unless url.is_a?(URI::Generic)
url = URI.parse(uri) unless url.is_a?(URI::Generic)
@url, @options = url, options
end
def open(host, port, local_host = nil, local_port = nil)
return TCPSocket.new(host, port, local_host, local_port) unless proxify?(host)
socket = TCPSocket.new(self.host, self.port, local_host, local_port)
socket = TCPSocket.new(proxy.host, proxy.port, local_host, local_port)
begin
proxify(socket, host, port)
@ -51,7 +51,7 @@ module Proxifier
@query_options ||= query ? Hash[query.split("&").map { |q| q.split("=") }] : {}
end
%w(no_proxy user_agent).each do |option|
%w(no_proxy).each do |option|
class_eval "def #{option}; options[:#{option}] end"
end

View File

@ -1,3 +1,3 @@
module Proxifier
VERSION = '1.0.4'
VERSION = "1.0.1"
end

View File

@ -1,32 +1,18 @@
require 'uri/generic'
require "uri/generic"
module URI
class Socks < Generic
class SOCKS < Generic
DEFAULT_PORT = 1080
COMPONENT = [:scheme, :userinfo, :host, :port, :query].freeze
end
@@schemes["SOCKS"] = SOCKS
@@schemes["SOCKS5"] = SOCKS
def self.build(args)
tmp = Util.make_components_hash(self, args)
super(tmp)
end
class SOCKS4 < SOCKS
end
@@schemes["SOCKS4"] = SOCKS4
class Socks4 < Socks
end
class Socks4A < Socks
end
mapping = {
'SOCKS' => Socks,
'SOCKS5' => Socks,
'SOCKS4' => Socks4,
'SOCKS4A' => Socks4A
}
if URI::VERSION_CODE >= "001100"
mapping.each { |scheme, class_name| register_scheme scheme, class_name }
else
mapping.each { |scheme, class_name| @@schemes[scheme] = class_name }
class SOCKS4A < SOCKS
end
@@schemes["SOCKS4A"] = SOCKS4A
end

View File

@ -8,12 +8,9 @@ Gem::Specification.new do |s|
s.authors = ["Samuel Kadolph"]
s.email = ["samuel@kadolph.com"]
s.homepage = "https://github.com/samuelkadolph/ruby-proxifier"
s.summary = %q{Proxifier is a gem to force ruby to use a proxy.}
s.description = %q{Proxifier adds support for HTTP or SOCKS proxies and lets you force TCPSocket to use proxies.}
s.license = "MIT"
s.summary = %q{}
s.description = %q{}
s.files = Dir["bin/*", "lib/**/*"] + ["LICENSE", "README.md"]
s.executables = ["pirb", "pruby"]
s.add_development_dependency 'minitest', '>= 4.6.0'
end

View File

@ -1,30 +0,0 @@
require 'spec_helper'
require 'uri'
require 'proxifier/proxies/socks'
describe Proxifier::SOCKSProxy do
before do
@socket = MiniTest::Mock.new
end
it 'should comply with SOCKS5 authentication specification' do
proxy = Proxifier::Proxy('socks://joe:sekret@myproxy:60123')
proxy.must_be_instance_of Proxifier::SOCKSProxy
TCPSocket.stub :new, @socket do
@socket.expect :<<, nil, ["\x05\x02\x00\x02"]
@socket.expect :read, "\x05\x02", [2]
@socket.expect :<<, nil, ["\x01\x03joe\x06sekret"]
@socket.expect :read, "\x01\x00", [2]
@socket.expect :<<, nil, ["\x05\x01\x00\x03\tlocalhost\x048"]
@socket.expect :read, "\x05\x00\x00\x01", [4]
@socket.expect :read, "\x7F\x00\x00\x01", [4]
@socket.expect :read, "\x08", [2]
proxy.open('localhost', 1080)
end
end
end

View File

@ -1,28 +0,0 @@
require 'spec_helper'
require 'uri'
require 'proxifier/proxy'
describe Proxifier::Proxy do
it 'should create proxy from URL String' do
proxy = Proxifier::Proxy.new('socks://joe:sekret@myproxy:60123')
proxy.url.scheme.must_equal 'socks'
proxy.user.must_equal 'joe'
proxy.password.must_equal 'sekret'
proxy.host.must_equal 'myproxy'
proxy.port.must_equal 60123
end
it 'should create proxy from generic URI' do
uri = URI::Generic.new('socks', 'joe:sekret', 'myproxy', 60123, nil, nil, nil, nil, nil)
proxy = Proxifier::Proxy.new(uri)
proxy.url.scheme.must_equal 'socks'
proxy.user.must_equal 'joe'
proxy.password.must_equal 'sekret'
proxy.host.must_equal 'myproxy'
proxy.port.must_equal 60123
end
end

View File

@ -1,20 +0,0 @@
require 'spec_helper'
require 'proxifier/proxies/socks'
describe Proxifier do
it 'should have a version number' do
Proxifier::VERSION.wont_be_nil
end
it 'should create Proxy from URL String' do
proxy = Proxifier::Proxy('socks://joe:sekret@myproxy:60123')
proxy.must_be_instance_of Proxifier::SOCKSProxy
proxy.user.must_equal 'joe'
proxy.password.must_equal 'sekret'
proxy.host.must_equal 'myproxy'
proxy.port.must_equal 60123
end
end

View File

@ -1,8 +0,0 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'rubygems'
gem 'minitest' # ensure we are using the gem version
require 'minitest/spec'
require 'minitest/autorun'
require 'proxifier'