Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ jobs:
runs-on: ubuntu-latest

services:
services:
socks5:
image: serjs/go-socks5-proxy
env:
PROXY_USER: user
PROXY_PASSWORD: password
ports:
- 1080:1080
socks5:
image: serjs/go-socks5-proxy
env:
PROXY_USER: user
PROXY_PASSWORD: password
ports:
- 1080:1080

strategy:
matrix:
ruby: ['3.1', '3.2', '3.3', head]
ruby: ['3.2', '3.3', '3.4', head]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/pkg/
.ruby-version
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
require:
plugins:
- rubocop-minitest
- rubocop-performance
- rubocop-rake
Expand Down
6 changes: 5 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ SOCKSify Ruby 1.7.3
===================
* add Rakefile
* fix missing :timeout kwarg in TCPSocket class (thanks @lizzypy)
* Authentication support added to Net::HTTP.SOCKSProxy

unreleased
SOCKSify Ruby 1.8.0
===================
* Authentication support added to Net::HTTP.socks_proxy
(thanks to @ojab and @anton-smagin)
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
source 'https://rubygems.org'

group :test do
gem 'minitest', '~> 5.16'
gem 'minitest', '~> 5.25'
end

group :development, :test do
gem 'rake', '~> 13.2'
gem 'rubocop', '~> 1.31'
gem 'rubocop-minitest', '~> 0.20'
gem 'rubocop-performance', '~> 1.21'
gem 'rubocop-rake', '~> 0.6'
gem 'rake', '~> 13.3'
gem 'rubocop', '~> 1.78'
gem 'rubocop-minitest', '~> 0.38'
gem 'rubocop-performance', '~> 1.25'
gem 'rubocop-rake', '~> 0.7'
end
75 changes: 40 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.24.1)
parallel (1.26.1)
parser (3.3.4.2)
ast (2.4.3)
json (2.12.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
minitest (5.25.5)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
prism (1.4.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.3.4)
strscan
rubocop (1.65.1)
rake (13.3.0)
regexp_parser (2.10.0)
rubocop (1.78.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.45.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
rubocop-minitest (0.35.1)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.45.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-minitest (0.38.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-performance (1.25.0)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rake (0.7.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
ruby-progressbar (1.13.0)
strscan (3.1.0)
unicode-display_width (2.5.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
minitest (~> 5.16)
rake (~> 13.2)
rubocop (~> 1.31)
rubocop-minitest (~> 0.20)
rubocop-performance (~> 1.21)
rubocop-rake (~> 0.6)
minitest (~> 5.25)
rake (~> 13.3)
rubocop (~> 1.78)
rubocop-minitest (~> 0.38)
rubocop-performance (~> 1.25)
rubocop-rake (~> 0.7)

BUNDLED WITH
2.5.17
2.6.9
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,32 @@ end
```
Note that `Net::HTTP.socks_proxy` never relies on `TCPSocket.socks_server`/`socks_port`. You should either set `socks_proxy` arguments explicitly or use `Net::HTTP` directly.

### Authentication
```rb
require 'socksify/http'

uri = URI.parse('http://ipecho.net/plain')
Net::HTTP.socks_proxy('127.0.0.1', 1080, username: 'my_username', password: 'my_pwd').start(uri.host, uri.port) do |http|
req = Net::HTTP::Get.new uri
resp = http.request(req)
puts resp.inspect
puts resp.body
end
```

### Resolve addresses via SOCKS
```rb
Socksify.resolve("spaceboyz.net")
# => "87.106.131.203"
```

### Testing and Debugging

A tor proxy and socks5 proxy with auth is required before running the tests.
* Install tor from your usual package manager, check it is running with `pidof tor` then run the tests with:
* Install tor from your usual package manager, check it is running with `pidof tor`
* Start a SOCKS5 proxy using Docker `docker run -d --name socks5 -p 1080:1080 -e PROXY_USER=user -e PROXY_PASSWORD=password serjs/go-socks5-proxy`

Then run the tests with:
`bundle exec rake`

Colorful diagnostic messages are enabled by default via:
Expand Down
6 changes: 3 additions & 3 deletions lib/socksify/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
module Net
# patched class
class HTTP
def self.socks_proxy(p_host, p_port, p_username = nil, p_password = nil)
def self.socks_proxy(p_host, p_port, username: nil, password: nil)
proxyclass.module_eval do
include Ruby3NetHTTPConnectable if RUBY_VERSION.to_f > 3.0 # patch #connect method
include SOCKSProxyDelta::InstanceMethods
extend SOCKSProxyDelta::ClassMethods

@socks_server = p_host
@socks_port = p_port
@socks_username = p_username
@socks_password = p_password
@socks_username = username
@socks_password = password
end

proxyclass
Expand Down
4 changes: 3 additions & 1 deletion lib/socksify/socksproxyable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
module Socksproxyable
# class methods
module ClassMethods
SOCKS4_VERSIONS = %w[4 4a].freeze

attr_accessor :socks_server, :socks_port, :socks_username, :socks_password

def socks_version
Expand All @@ -19,7 +21,7 @@ def socks_ignores=(*hosts)
end

def socks_version_hex
socks_version == '4a' || socks_version == '4' ? "\004" : "\005"
SOCKS4_VERSIONS.include?(socks_version) ? "\004" : "\005"
end
end

Expand Down
6 changes: 6 additions & 0 deletions lib/socksify/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# namespace
module Socksify
VERSION = '1.8.0'
end
4 changes: 2 additions & 2 deletions socksify.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

require 'rubygems'
require_relative 'lib/socksify/version'

Gem::Specification.new do |s|
s.name = 'socksify'
s.version = '1.7.3'
s.version = Socksify::VERSION
s.summary = 'Redirect all TCPSockets through a SOCKS5 proxy'
s.authors = ['Stephan Maka', 'Andrey Kouznetsov', 'Christopher Thorpe', 'Musy Bite', 'Yuichi Tateno', 'David Dollar']
s.licenses = ['Ruby', 'GPL-3.0']
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def http_tor_proxy
end

def http_tor_proxy_with_auth(username, password)
Net::HTTP.socks_proxy('127.0.0.1', 1080, username, password)
Net::HTTP.socks_proxy('127.0.0.1', 1080, username: username, password: password)
end

def get_http(http_klass, url, host_header = nil)
Expand Down