Fixes for Proxy creation from URL String and SOCKS5 authentication. Bump version number to 1.0.4.
This commit is contained in:
parent
41ead73b21
commit
bf1f0bee18
11
Rakefile
11
Rakefile
|
@ -1 +1,10 @@
|
||||||
require "bundler/gem_tasks"
|
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
|
||||||
|
|
|
@ -4,6 +4,7 @@ require "proxifier/proxy"
|
||||||
module Proxifier
|
module Proxifier
|
||||||
class SOCKSProxy < Proxy
|
class SOCKSProxy < Proxy
|
||||||
VERSION = 0x05
|
VERSION = 0x05
|
||||||
|
SUBNEGOTIATION_VERSION = 0x01
|
||||||
|
|
||||||
def do_proxify(socket, host, port)
|
def do_proxify(socket, host, port)
|
||||||
authenticaton_method = greet(socket)
|
authenticaton_method = greet(socket)
|
||||||
|
@ -26,12 +27,12 @@ module Proxifier
|
||||||
case method
|
case method
|
||||||
when 0x00 # NO AUTHENTICATION REQUIRED
|
when 0x00 # NO AUTHENTICATION REQUIRED
|
||||||
when 0x02 # USERNAME/PASSWORD
|
when 0x02 # USERNAME/PASSWORD
|
||||||
user &&= user[0, 0xFF]
|
_user = user ? user[0, 0xFF] : ''
|
||||||
password &&= password[0, 0xFF]
|
_password = password ? password[0, 0xFF] : ''
|
||||||
|
|
||||||
socket << [user.size, user, password.size, password].pack("CA#{user.size}CA#{password.size}")
|
socket << [SUBNEGOTIATION_VERSION, _user.size, _user, _password.size, _password].pack("CCA#{_user.size}CA#{_password.size}")
|
||||||
version, status = socket.read(2).unpack("CC")
|
version, status = socket.read(2).unpack('CC')
|
||||||
check_version(version)
|
check_version(version, SUBNEGOTIATION_VERSION)
|
||||||
|
|
||||||
case status
|
case status
|
||||||
when 0x00 # SUCCESS
|
when 0x00 # SUCCESS
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Proxifier
|
||||||
attr_reader :url, :options
|
attr_reader :url, :options
|
||||||
|
|
||||||
def initialize(url, options = {})
|
def initialize(url, options = {})
|
||||||
url = URI.parse(uri) unless url.is_a?(URI::Generic)
|
url = URI.parse(url) unless url.is_a?(URI::Generic)
|
||||||
@url, @options = url, options
|
@url, @options = url, options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module Proxifier
|
module Proxifier
|
||||||
VERSION = "1.0.3"
|
VERSION = '1.0.4'
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,4 +13,6 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
s.files = Dir["bin/*", "lib/**/*"] + ["LICENSE", "README.md"]
|
s.files = Dir["bin/*", "lib/**/*"] + ["LICENSE", "README.md"]
|
||||||
s.executables = ["pirb", "pruby"]
|
s.executables = ["pirb", "pruby"]
|
||||||
|
|
||||||
|
s.add_development_dependency 'minitest', '>= 4.6.0'
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
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
|
|
@ -0,0 +1,28 @@
|
||||||
|
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
|
|
@ -0,0 +1,20 @@
|
||||||
|
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
|
|
@ -0,0 +1,8 @@
|
||||||
|
$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'
|
Loading…
Reference in New Issue