diff --git a/setup.py b/setup.py index be07821..9cb19d6 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open('README.rst') as f: setup( name="shadowsocks", - version="2.1.0", + version="2.2.0", license='MIT', description="A fast tunnel proxy that help you get through firewalls", author='clowwindy', diff --git a/shadowsocks/encrypt.py b/shadowsocks/encrypt.py index 952fd72..1156d89 100644 --- a/shadowsocks/encrypt.py +++ b/shadowsocks/encrypt.py @@ -27,6 +27,7 @@ import string import struct import logging import encrypt_salsa20 +import encrypt_rc4_sha256 def random_string(length): @@ -115,6 +116,7 @@ method_supported = { 'idea-cfb': (16, 8), 'rc2-cfb': (16, 8), 'rc4': (16, 0), + 'rc4-sha256': (32, 16), 'seed-cfb': (16, 16), 'salsa20-ctr': (32, 8), } @@ -156,13 +158,15 @@ class Encryptor(object): if op == 1: # this iv is for cipher not decipher self.cipher_iv = iv[:m[1]] - if method != 'salsa20-ctr': + if method == 'salsa20-ctr': + return encrypt_salsa20.Salsa20Cipher(method, key, iv, op) + elif method == 'rc4-sha256': + return encrypt_rc4_sha256.create_cipher(method, key, iv, op) + else: import M2Crypto.EVP return M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv, op, key_as_bytes=0, d='md5', salt=None, i=1, padding=1) - else: - return encrypt_salsa20.Salsa20Cipher(method, key, iv, op) logging.error('method %s not supported' % method) sys.exit(1) @@ -217,11 +221,13 @@ def encrypt_all(password, method, op, data): else: iv = data[:iv_len] data = data[iv_len:] - if method != 'salsa20-ctr': + if method == 'salsa20-ctr': + cipher = encrypt_salsa20.Salsa20Cipher(method, key, iv, op) + elif method == 'rc4-sha256': + return encrypt_rc4_sha256.create_cipher(method, key, iv, op) + else: cipher = M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv, op, key_as_bytes=0, d='md5', salt=None, i=1, padding=1) - else: - cipher = encrypt_salsa20.Salsa20Cipher(method, key, iv, op) result.append(cipher.update(data)) return ''.join(result) diff --git a/shadowsocks/encrypt_rc4_sha256.py b/shadowsocks/encrypt_rc4_sha256.py new file mode 100644 index 0000000..968f3e2 --- /dev/null +++ b/shadowsocks/encrypt_rc4_sha256.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# Copyright (c) 2014 clowwindy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import hashlib + + +def create_cipher(alg, key, iv, op, key_as_bytes=0, d=None, salt=None, + i=1, padding=1): + sha256 = hashlib.sha256() + sha256.update(key) + sha256.update(iv) + rc4_key = sha256.digest() + + import M2Crypto.EVP + return M2Crypto.EVP.Cipher('rc4', rc4_key, '', op, key_as_bytes=0, + d='md5', salt=None, i=1, padding=1) diff --git a/shadowsocks/encrypt_salsa20.py b/shadowsocks/encrypt_salsa20.py index 823ae65..be8cb8b 100644 --- a/shadowsocks/encrypt_salsa20.py +++ b/shadowsocks/encrypt_salsa20.py @@ -1,4 +1,24 @@ -#!/usr/bin/python +#!/usr/bin/env python + +# Copyright (c) 2014 clowwindy +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. import time import struct diff --git a/tests/rc4-sha256.json b/tests/rc4-sha256.json new file mode 100644 index 0000000..7119c09 --- /dev/null +++ b/tests/rc4-sha256.json @@ -0,0 +1,10 @@ +{ + "server":"127.0.0.1", + "server_port":8388, + "local_port":1081, + "password":"aes_password", + "timeout":60, + "method":"rc4-sha256", + "local_address":"127.0.0.1", + "fast_open":false +}