r_socks 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/r_socks/authenticator.rb +6 -4
- data/lib/r_socks/connection_handler.rb +4 -1
- data/lib/r_socks/http_proxy_parser.rb +5 -3
- data/lib/r_socks/socks5_proxy_parser.rb +5 -0
- data/lib/r_socks/target_connection_handler.rb +6 -1
- data/lib/r_socks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2499018b47dd3233d537be32107df8e398150a21b4b3aef5eca8a960123b52a7
|
4
|
+
data.tar.gz: f0c479c2e0de2be8e1bc1851b9755225a35d4eb36a9344aa7f946ebe8576e5d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 025e9d38508b50bc500fc2484874c4f70610365932d9f974609d5f4d2bc0c626a9588296373cbc2fcb18fffab96536b8b2f20cddf061da890d3f43ad6c2a0bc5
|
7
|
+
data.tar.gz: cd82808668a124bd4d601cd31f2f85a45c08b7212c27fa020627cadbe968710084ac23f823ff2b06cdb81c18d64e50e64ffbe6755578e6c91ac70661905e8f83
|
data/Gemfile.lock
CHANGED
@@ -2,6 +2,8 @@ module RSocks
|
|
2
2
|
|
3
3
|
class Authenticator
|
4
4
|
|
5
|
+
attr_reader :username, :password
|
6
|
+
|
5
7
|
def initialize(adaptor = nil)
|
6
8
|
@default_user = ENV['RSOCKS_USER'] || 'default'
|
7
9
|
@default_password = ENV['RSOCKS_PASSWORD'] || 'default'
|
@@ -16,13 +18,13 @@ module RSocks
|
|
16
18
|
private
|
17
19
|
|
18
20
|
def validate(data)
|
19
|
-
username, remain = get_username(data)
|
20
|
-
password = get_password(remain)
|
21
|
+
@username, remain = get_username(data)
|
22
|
+
@password = get_password(remain)
|
21
23
|
|
22
24
|
if @adaptor.nil?
|
23
|
-
username == @default_user && password == @default_password
|
25
|
+
@username == @default_user && @password == @default_password
|
24
26
|
else
|
25
|
-
@adaptor.call(username, password)
|
27
|
+
@adaptor.call(@username, @password)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -53,8 +53,11 @@ module RSocks
|
|
53
53
|
|
54
54
|
return unless @state_machine.start?
|
55
55
|
|
56
|
+
@username = @parser.username
|
57
|
+
@password = @parser.password
|
56
58
|
if @target.nil?
|
57
59
|
@target = EventMachine.connect(@addr, @port, RSocks::TargetConnectionHandler, self, @config)
|
60
|
+
@target.assign_user_and_password(@username, @password)
|
58
61
|
end
|
59
62
|
rescue => error
|
60
63
|
puts "Error at #{@ip}:#{@port}, message: #{data}, error: #{error.message}"
|
@@ -68,7 +71,7 @@ module RSocks
|
|
68
71
|
@target.close_connection_after_writing if @target
|
69
72
|
|
70
73
|
if @config.unbind_handler
|
71
|
-
@config.unbind_handler.call(get_proxied_bytes)
|
74
|
+
@config.unbind_handler.call(get_proxied_bytes, @username, @password)
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
@@ -3,6 +3,8 @@ require 'base64'
|
|
3
3
|
module RSocks
|
4
4
|
class HttpProxyParser
|
5
5
|
|
6
|
+
attr_reader :username, :password
|
7
|
+
|
6
8
|
def initialize(state_machine, config)
|
7
9
|
@state_machine = state_machine
|
8
10
|
@auth_method = config.auth_method
|
@@ -36,15 +38,15 @@ module RSocks
|
|
36
38
|
token = temp.gsub(pattern, '')
|
37
39
|
begin
|
38
40
|
str = Base64.decode64(token)
|
39
|
-
@
|
41
|
+
@username, @password = str.split(':')
|
40
42
|
rescue
|
41
43
|
raise RSocks::HttpNotSupport, "token parse failed #{token}"
|
42
44
|
end
|
43
45
|
|
44
46
|
if @adaptor
|
45
|
-
return @adaptor.call(@
|
47
|
+
return @adaptor.call(@username, @password)
|
46
48
|
else
|
47
|
-
return @password == @default_password && @
|
49
|
+
return @password == @default_password && @username == @default_user
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
@@ -8,6 +8,9 @@ require 'r_socks/socks5_proxy_parser'
|
|
8
8
|
|
9
9
|
module RSocks
|
10
10
|
class Socks5ProxyParser
|
11
|
+
|
12
|
+
attr_reader :username, :password
|
13
|
+
|
11
14
|
def initialize(state_machine, config, client)
|
12
15
|
@state_machine = state_machine
|
13
16
|
@auth_method = config.auth_method
|
@@ -42,6 +45,8 @@ module RSocks
|
|
42
45
|
|
43
46
|
if @state_machine.connect?
|
44
47
|
connect_request(data)
|
48
|
+
@username = @authenticator.username
|
49
|
+
@password = @authenticator.password
|
45
50
|
return [@addr, @port]
|
46
51
|
end
|
47
52
|
|
@@ -9,6 +9,11 @@ module RSocks
|
|
9
9
|
@config = config
|
10
10
|
end
|
11
11
|
|
12
|
+
def assign_user_and_password(username, password)
|
13
|
+
@username = username
|
14
|
+
@password = password
|
15
|
+
end
|
16
|
+
|
12
17
|
def connection_completed
|
13
18
|
if @config.proxy_type == :http
|
14
19
|
@client.send_data(RSocks::HttpProxyResponseCodes::SUCCESS)
|
@@ -28,7 +33,7 @@ module RSocks
|
|
28
33
|
def unbind
|
29
34
|
@client.close_connection_after_writing
|
30
35
|
if @config.unbind_handler
|
31
|
-
@config.unbind_handler.call(get_proxied_bytes)
|
36
|
+
@config.unbind_handler.call(get_proxied_bytes, @username, @password)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
data/lib/r_socks/version.rb
CHANGED