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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

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

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins:

AllCops:
NewCops: enable
TargetRubyVersion: 2.0
TargetRubyVersion: 2.7

Gemspec/RequireMFA:
Enabled: false
7 changes: 6 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ SOCKSify Ruby 1.7.3
* add Rakefile
* fix missing :timeout kwarg in TCPSocket class (thanks @lizzypy)

unreleased
2025-07-17
SOCKSify Ruby 1.8.0
===================
* Authentication support added to Net::HTTP.socks_proxy
(thanks to @ojab and @anton-smagin)

unreleased
SOCKSify Ruby 1.8.1
===================
* clarify required ruby version >= 2.7
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

group :test do
Expand Down
7 changes: 3 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
json (2.12.2)
json (2.13.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
minitest (5.25.5)
Expand All @@ -26,7 +26,7 @@ GEM
rubocop-ast (>= 1.45.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.45.1)
rubocop-ast (1.46.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-minitest (0.38.1)
Expand All @@ -46,7 +46,6 @@ GEM
unicode-emoji (4.0.4)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
Expand All @@ -58,4 +57,4 @@ DEPENDENCIES
rubocop-rake (~> 0.7)

BUNDLED WITH
2.6.9
2.4.22
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'

Expand Down
1 change: 1 addition & 0 deletions bin/socksify_ruby
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

if ARGV.size < 2
puts "Usage: #{$PROGRAM_NAME} <SOCKS host> <SOCKS port> [script args ...]"
Expand Down
3 changes: 2 additions & 1 deletion lib/socksify.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: us-ascii
# frozen_string_literal: true

# Copyright (C) 2007 Stephan Maka <stephan@spaceboyz.net>
#
Expand Down Expand Up @@ -119,7 +120,7 @@ def self.proxy(server, port)
end

def self.request(host)
req = String.new << "\005"
req = (+'') << "\005"
case host
when /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ # to IPv4 address
req << "\xF1\000\001#{(1..4).map { |i| Regexp.last_match(i).to_i }.pack('CCCC')}"
Expand Down
2 changes: 2 additions & 0 deletions lib/socksify/debug.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# namespace
module Socksify
# rubocop:disable Style/Documentation
Expand Down
2 changes: 2 additions & 0 deletions lib/socksify/http.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright (C) 2007 Stephan Maka <stephan@spaceboyz.net>
# Copyright (C) 2011 Musy Bite <musybite@gmail.com>
#
Expand Down
8 changes: 4 additions & 4 deletions lib/socksify/socksproxyable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ module InstanceMethodsConnect
# rubocop:disable Metrics
def socks_connect(host, port)
port = Socket.getservbyname(port) if port.is_a?(String)
req = String.new
req = +''
Socksify.debug_debug 'Sending destination address'
req << TCPSocket.socks_version_hex
Socksify.debug_debug TCPSocket.socks_version_hex.unpack 'H*'
req << "\001"
req << "\000" if self.class.socks_version == '5'
req << [port].pack('n') if self.class.socks_version =~ /^4/
req << [port].pack('n') if /^4/.match?(self.class.socks_version)
host = Resolv::DNS.new.getaddress(host).to_s if self.class.socks_version == '4'
Socksify.debug_debug host
if host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ # to IPv4 address
req << "\001" if self.class.socks_version == '5'
ip = (1..4).map { |i| Regexp.last_match(i).to_i }.pack('CCCC')
req << ip
elsif host =~ /^[:0-9a-f]+$/ # to IPv6 address
elsif /^[:0-9a-f]+$/.match?(host) # to IPv6 address
raise 'TCP/IPv6 over SOCKS is not yet supported (inet_pton missing in Ruby & not supported by Tor'
# req << "\004" # UNREACHABLE
elsif self.class.socks_version == '5' # to hostname
Expand Down Expand Up @@ -133,7 +133,7 @@ def socks_receive_reply
i = 0
ip6 = ''
bind_addr_s.each_byte do |b|
ip6 += ':' if i > 0 && i.even?
ip6 += ':' if i.positive? && i.even?
i += 1
ip6 += b.to_s(16).rjust(2, '0')
end
Expand Down
4 changes: 3 additions & 1 deletion lib/socksify/tcpsocket.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'socksproxyable'

# monkey patch
Expand Down Expand Up @@ -70,7 +72,7 @@ def socks_ignores
def make_socks_connection(host, port, **kwargs)
Socksify.debug_notice "Connecting to SOCKS server #{socks_server}:#{socks_port}"
initialize_tcp socks_server, socks_port, **kwargs
socks_authenticate(socks_username, socks_password) unless @socks_version =~ /^4/
socks_authenticate(socks_username, socks_password) unless /^4/.match?(@socks_version)
socks_connect(host, port) if host
end

Expand Down
2 changes: 1 addition & 1 deletion lib/socksify/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# namespace
module Socksify
VERSION = '1.8.0'
VERSION = '1.8.1'
end
2 changes: 1 addition & 1 deletion socksify.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |s|
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']
s.required_ruby_version = '>= 2.0'
s.required_ruby_version = '>= 2.7'
s.email = 'stephan@spaceboyz.net'
s.homepage = 'https://github.com/astro/socksify-ruby'
s.files = %w[COPYING]
Expand Down
2 changes: 2 additions & 0 deletions test/test_socksify_legacy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module TestSocksifyLegacy
if RUBY_VERSION.to_f < 3.1 # test legacy methods TCPSocket.socks_server= and TCPSocket.socks_port=
def test_check_tor
Expand Down