shadowsocks 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffa53ad10b7ef10c31fbec7b957634073144266f
4
- data.tar.gz: ba754df84d406718006c4259e75b2513da528054
3
+ metadata.gz: 89505690269fc4fea4a159ad713ea3a69045a269
4
+ data.tar.gz: 076b3e073b3cd64d4c56b4dd22647eddaa866e22
5
5
  SHA512:
6
- metadata.gz: b09c4253cbfc84d1a6974aa2e92075c58df655b08b881e448be0a362601e0b24f909ba2ab0c04e5402d944c8fc25ff1144b1a59069e1612942b99ce4801ad856
7
- data.tar.gz: d72621ffe2282033410bb989a85b3ede86d8d8aed22a8f4eaab2c8c9ec326f5d39a1f91e8f03a42074d4d92e25f36ed8bde76d28e7cd8395a52508f9020e5322
6
+ metadata.gz: 6016baaee667416efb16d7884e41cba5957a8f2f3ccd12036ddf2c36238341965a8ca3971fcda5ea28d2254e4c15f3d5dc384d5621732a23145197473368e1e9
7
+ data.tar.gz: e839023341a1870a1c624d7263909c6e65657954dd90336eb4e5c841d23a474c391251f974c1564a274904d707d7877f80172da504345cebde85afee23b56acb
data/README.md CHANGED
@@ -3,7 +3,7 @@ shadowsocks-ruby
3
3
 
4
4
  [![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed)
5
5
 
6
- Current version: 0.5
6
+ Current version: 0.6
7
7
 
8
8
  shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks).
9
9
 
@@ -27,7 +27,7 @@ Create a file named `config.json`, with the following content.
27
27
  "local_port":1080,
28
28
  "password":"barfoo!",
29
29
  "timeout":60,
30
- "method":"aes-256-cfb"
30
+ "method":"aes-128-cfb"
31
31
  }
32
32
 
33
33
  Explanation of the fields:
@@ -37,7 +37,7 @@ Explanation of the fields:
37
37
  local_port local port
38
38
  password a password used to encrypt transfer
39
39
  timeout in seconds
40
- method encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is aes-256-cfb
40
+ method encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is "aes-128-cfb"
41
41
 
42
42
  `cd` into the directory of `config.json`. Run `ss-server` on your server. To run it in the background, run
43
43
  `nohup ss-server -c ./config.json > log &`.
data/config.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "local_port":1080,
5
5
  "password":"barfoo!",
6
6
  "timeout":60,
7
- "method":"aes-256-cfb"
7
+ "method":"aes-128-cfb"
8
8
  }
@@ -57,6 +57,7 @@ module Shadowsocks
57
57
  connection.config = @config
58
58
  connection.crypto = Shadowsocks::Crypto.new @method_options
59
59
  connection.pending_connect_timeout = @config.timeout
60
+ connection.comm_inactivity_timeout = @config.timeout
60
61
  end
61
62
 
62
63
  end
@@ -1,6 +1,6 @@
1
1
  module Shadowsocks
2
2
  class Connection < EventMachine::Connection
3
- BackpressureLevel = 2097152 # 2m
3
+ BackpressureLevel = 524288 # 512k
4
4
 
5
5
  attr_accessor :crypto
6
6
 
@@ -18,10 +18,10 @@ module Shadowsocks
18
18
  remote.get_outbound_data_size > BackpressureLevel
19
19
  end
20
20
 
21
- def outbound_checker
21
+ def outbound_scheduler
22
22
  if over_pressure?
23
23
  pause unless paused?
24
- EM.add_timer(1) { outbound_checker }
24
+ EM.add_timer(0.2) { outbound_scheduler }
25
25
  else
26
26
  resume if paused?
27
27
  end
@@ -9,6 +9,23 @@ module Shadowsocks
9
9
  attr_accessor :encrypt_table, :decrypt_table, :password, :method,
10
10
  :cipher, :bytes_to_key_results, :iv_sent
11
11
 
12
+ def initialize(options = {})
13
+ @password = options[:password]
14
+ @method = options[:method].downcase
15
+ if method == 'table'
16
+ @encrypt_table = options[:encrypt_table]
17
+ @decrypt_table = options[:decrypt_table]
18
+ else
19
+ if method_supported.nil?
20
+ raise "Encrypt method not support"
21
+ end
22
+ end
23
+
24
+ if method != 'table'
25
+ @cipher = get_cipher(1, SecureRandom.hex(32))
26
+ end
27
+ end
28
+
12
29
  def method_supported
13
30
  case method
14
31
  when 'aes-128-cfb' then [16, 16]
@@ -28,24 +45,6 @@ module Shadowsocks
28
45
  end
29
46
  alias_method :get_cipher_len, :method_supported
30
47
 
31
- def initialize(options = {})
32
- @password = options[:password]
33
- @method = options[:method].downcase
34
- @iv_sent = false
35
- if method == 'table'
36
- @encrypt_table = options[:encrypt_table]
37
- @decrypt_table = options[:decrypt_table]
38
- else
39
- if method_supported.nil?
40
- raise "Encrypt method not support"
41
- end
42
- end
43
-
44
- if method != 'table'
45
- @cipher = get_cipher(1, SecureRandom.hex(32))
46
- end
47
- end
48
-
49
48
  def encrypt buf
50
49
  return buf if buf.length == 0
51
50
  if method == 'table'
@@ -71,6 +70,7 @@ module Shadowsocks
71
70
  @iv = decipher_iv
72
71
  @decipher = get_cipher(0, @iv)
73
72
  buf = buf[decipher_iv_len..-1]
73
+
74
74
  return buf if buf.length == 0
75
75
  end
76
76
  @decipher.update(buf)
@@ -85,21 +85,20 @@ module Shadowsocks
85
85
 
86
86
  def get_cipher(op, iv)
87
87
  m = get_cipher_len
88
- unless m.nil?
89
- key, _iv = EVP_BytesToKey(m[0], m[1])
90
88
 
91
- iv = _iv[0..m[1] - 1]
92
- @iv = iv unless @iv
93
- @cipher_iv = iv if op == 1
89
+ key, _iv = EVP_BytesToKey(m[0], m[1])
94
90
 
95
- cipher = OpenSSL::Cipher.new method
91
+ iv = _iv[0..m[1] - 1]
92
+ @iv = iv unless @iv
93
+ @cipher_iv = iv if op == 1
96
94
 
97
- op == 1 ? cipher.encrypt : cipher.decrypt
95
+ cipher = OpenSSL::Cipher.new method
98
96
 
99
- cipher.key = key
100
- cipher.iv = @iv
101
- cipher
102
- end
97
+ op == 1 ? cipher.encrypt : cipher.decrypt
98
+
99
+ cipher.key = key
100
+ cipher.iv = @iv
101
+ cipher
103
102
  end
104
103
 
105
104
  def EVP_BytesToKey key_len, iv_len
@@ -112,21 +111,19 @@ module Shadowsocks
112
111
 
113
112
  len = key_len + iv_len
114
113
 
115
- code = password.unpack('H*').first
116
-
117
114
  while m.join.length < len do
118
115
  data = if i > 0
119
116
  m[i - 1] + password
120
117
  else
121
118
  password
122
119
  end
123
- m.push Digest::MD5.digest data
120
+ m.push Digest::MD5.digest(data)
124
121
  i += 1
125
122
  end
126
123
  ms = m.join
127
124
  key = ms[0, key_len]
128
125
  iv = ms[key_len, key_len + iv_len]
129
- bytes_to_key_results = [key, iv]
126
+ @bytes_to_key_results = [key, iv]
130
127
  bytes_to_key_results
131
128
  end
132
129
  end
@@ -5,7 +5,7 @@ module Shadowsocks
5
5
 
6
6
  def receive_data data
7
7
  data_handler data
8
- outbound_checker if connector
8
+ outbound_scheduler if connector
9
9
  end
10
10
 
11
11
  def post_init
@@ -14,7 +14,7 @@ module Shadowsocks
14
14
 
15
15
  def receive_data data
16
16
  server.send_data decrypt(data)
17
- outbound_checker
17
+ outbound_scheduler
18
18
  end
19
19
  end
20
20
 
@@ -12,7 +12,7 @@ module Shadowsocks
12
12
 
13
13
  def receive_data data
14
14
  server.send_data encrypt(data)
15
- outbound_checker
15
+ outbound_scheduler
16
16
  end
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module Shadowsocks
2
- VERSION = '0.5'
2
+ VERSION = '0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shadowsocks
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sen