Compare commits

...

518 Commits
1.4 ... rm

Author SHA1 Message Date
Your Name de7c05b449 :) 9 years ago
BreakWa11 1ee344220a merge manyuser 2.6.13 11 years ago
BreakWa11 a681a72b16 a stupid bug 11 years ago
breakwa11 2d695441d2 bump 2.6.12 11 years ago
breakwa11 7df3152608 merge manyuser 11 years ago
BreakWa11 eebd5c548e Merge pull request #26 from mengskysama/patch-6
发现好多坑
11 years ago
mengskysama 3db5a4918f 发现好多坑
233
11 years ago
BreakWa11 1e41de7d0b Merge pull request #24 from mengskysama/patch-2
Update lru_cache.py
11 years ago
BreakWa11 9bb52acaf5 Merge pull request #25 from mengskysama/patch-4
memory leak
11 years ago
mengskysama b059b9ad85 memory leak 11 years ago
mengskysama 418cadb945 Update lru_cache.py 11 years ago
breakwa11 c18b002754 bump 2.6.11 11 years ago
breakwa11 1bc0e60cfd merge manyuser branch 11 years ago
breakwa11 3200b7d4fe merge manyuser branch 11 years ago
breakwa11 8f402277e6 merge manyuser branch 11 years ago
breakwa11 a37623b0b7 log TCP header if parse error 11 years ago
breakwa11 5b6dec5940 merge manyuser branch 11 years ago
breakwa11 a38db829f2 new UDP over TCP protocol, merge master 11 years ago
breakwa11 d475076cdc listen ipv6 12 years ago
breakwa11 e751534234 Merge branch 'master' of shadowsocks/shadowsocks 12 years ago
clowwindy 1bb0e51e8e refine tests 12 years ago
clowwindy f7d69db6d1 bump 12 years ago
clowwindy f55bd0302f update CHANGES 12 years ago
clowwindy 13a6bb007c cache DNS results in UDPRelay 12 years ago
clowwindy 99b4121fd9 fix problem when UDP client requesting both IPv4 and IPv6 12 years ago
clowwindy c34c99450f fix UDP source port issue 12 years ago
clowwindy 1a62694a3b add udp source port test 12 years ago
breakwa11 7c3e047449 merge manyuser branch 12 years ago
breakwa11 1b0504ade2 merge manyuser branch 12 years ago
clowwindy a2edd6a46d Merge pull request #361 from jackyyf/master
Add fail2ban filter.
12 years ago
Yifu Yu 0edae7069f Add fail2ban filter.
Please put the shadowsocks.conf into your filter.d directory, and
using `filter = shadowsocks` to use the filter.
12 years ago
breakwa11 e5b4a804e9 double UDP sockets for IPv4 and IPv6 12 years ago
breakwa11 3d1563ecac fix udp ipv6 12 years ago
breakwa11 c549929dfb fix udp ipv6 12 years ago
breakwa11 d065dba34f merge manyuser
udp ipv6 bug fix
12 years ago
breakwa11 f16749962a drop UDP message if frag != 0 12 years ago
breakwa11 62dca9d3cd udp over tcp 12 years ago
clowwindy e001f1818c bump 12 years ago
clowwindy 56c289ba21 update CHANGES 12 years ago
clowwindy e74ae193d0 elaborate reasons of header parsing failure 12 years ago
clowwindy 16db66675b optimize LRUCache 12 years ago
clowwindy c46234af41 update CHANGES 12 years ago
clowwindy 405120c59f bump 12 years ago
clowwindy 082c8a80f4 fix duplicated close in LRUCache
close #324
12 years ago
clowwindy 893d21da76 Merge pull request #332 from sky-chen/master
flush autoban output
12 years ago
sky ea7a3e1b58 flush autoban output 12 years ago
clowwindy e898f92191 Merge pull request #295 from jlund/no-rc4
Use AES in the Usage example instead of RC4.
12 years ago
clowwindy 5c0391d146 Merge pull request #312 from kimw/patch-1
remove duplicated line (refer line 221)
12 years ago
Kim Wong e17279e5bf remove duplicated line (refer line 221) 12 years ago
clowwindy f17da943b3 Merge pull request #305 from lazybios/patch
remove duplicate code from shell.py
12 years ago
lazybios d3831bef8c remove duplicate code from shell.py 12 years ago
Joshua Lund b6e6e14b8a Use AES in the Usage example instead of RC4. 12 years ago
clowwindy 4172639d48 Update README.md 12 years ago
clowwindy e8488895f0 Merge pull request #291 from felixonmars/py3-remote-address
convert remote_address to str so it will be printed more correctly on python 3
12 years ago
Felix Yan edb7822a7b convert remote_address to str so it will be printed more correctly on python 3 12 years ago
clowwindy 294556f8bc bump 2.6.9 12 years ago
clowwindy 1b7ab23f78 release 2.6.8 12 years ago
clowwindy 0e14f3bbef fix travis 12 years ago
clowwindy 42ce2569c4 also test with real website
Now that localhost is used in tests, DNS code is uncovered.
Use clients1.google.com/generate_204 to test if a real website works.
12 years ago
clowwindy 581d6e687f use localhost in test.py
Since now the unit tests is huge, using third party website
is not polite. So use localhost instead.
12 years ago
clowwindy d774286dc0 rename utils module into shell
Since utils is ambiguous, we want to give the module a more
clear role.
12 years ago
clowwindy cb7062e1c1 implement utils.print_exception()
Previously we used logging.error(e) and traceback.print_exc()
to output error stack trace. The problem is, we want to
output the stack trace only when verbose > 0. The if statement
scattered around the code. So we replaced them with the new
utils.print_exception() call.
12 years ago
clowwindy 48ddc1714b move jenkins.sh 12 years ago
clowwindy dfd81af844 support --version 12 years ago
clowwindy 783a6ef7f2 support multiple server ip on client side 12 years ago
clowwindy e71ce6c758 fix server check 12 years ago
clowwindy e564f17505 fix bytes in utils 12 years ago
clowwindy 6d09cd21ca fix openssl 12 years ago
clowwindy 318d88ec89 use string more 12 years ago
clowwindy ce805f0aea license under Apache License v2.0 12 years ago
clowwindy 96a86c028d update CHANGES 12 years ago
clowwindy 2c59ffb952 update rst 12 years ago
clowwindy 27a0c7754d bump 12 years ago
clowwindy 0cd261dd10 catch KeyError 12 years ago
clowwindy fbf15cb942 update command tests 12 years ago
clowwindy 1c81465436 fix command line 12 years ago
clowwindy 73f21ffbf6 do not check config for daemon stop 12 years ago
clowwindy 7aa37cad8e check cipher before daemon start
fix #280
12 years ago
clowwindy ae99698b4e implement --user
fix @278
12 years ago
clowwindy da65d0a2ee update coverage_server 12 years ago
clowwindy 3b7755bd5e fix a travis issue 12 years ago
clowwindy 5a7225c54b fix a problem in test arguments 12 years ago
clowwindy 4aba904d6e fix typo 12 years ago
clowwindy b77f419336 test if localhost is in the default forbidden list 12 years ago
clowwindy c39bbbe237 test invalid CIDR 12 years ago
clowwindy 453a9c61a6 show CIDR error more friendly 12 years ago
clowwindy 54181ef821 Merge pull request #279 from planetmeow/develop/CIDRForbidden
Implement CIDR forbidden blacklist
12 years ago
Sunny 17624d0b99 Fix large file test since forbidden ip list is default to localhost
Use an empty forbidden ip list to override default list should work.
12 years ago
Sunny a0aa9173a8 Fix for Python3 map changed behavior
In Python3, map returns an iterator instead of list in Python2,
which cause map "lazier" than before, wrap with list() force it running.
12 years ago
Sunny 79b9b53dbe Never process empty string and prevent infinite loop
If user provide an empty string as network range, inet_pton will
treate it as an IPv6 unspecified address, it seems a bug but I
can't confirm. Then empty string will be converted to 0, 0 & 1
always be zero, so it caused dead loop.
12 years ago
Sunny 070108f78b Disable forbidden ip feature for local shadowsocks
Since forbidden ip is server-side only, disable it for local-side.
This commit also supress warning about IPv6 loopback because I can
confirm ::1/128 is the only loopback address, not like IPv4.
12 years ago
Sunny b11d848986 Fix for Python3 lambda behavior change
In Python3, lambda no longer support use tuple as syntax.
So, ugly changes is inevitable.
12 years ago
Sunny aa28796524 Make common fit PEP8 12 years ago
Sunny 8af359ae05 Use IPNetwork supporting forbidden ip feature in config utils
This commit also make "forbidden_ip" field available in config file.
If no forbidden ip specified in command line and config file,
default to "127.0.0.0/8,::1".
12 years ago
Sunny 100ebcf064 Add IPNetwork class to support CIDR calculation
Usage:
Use IPNetwork(str|list<str>) to create an IPNetwork object.
Use operator 'in' to determine whether the specified
IP address is in the IP network or not, like:
>>> '192.168.1.1' in IPNetwork('192.168.1.0/24')
True

Both IPv4 and IPv6 address are supported.
Note: When using string to initialize the IPNetwork,
a comma seperated IP network list should be provided.

Currently, IPNetwork just support standard CIDR like:
x.x.x.x/y eg. 192.168.1.0/24
::x/y     eg. ::1/10
If pure IP address was provided,
it will be treated as implicit IP network,
like 192.168.0.0 will be treated as 192.168.0.0/16
and  192.168.1.1 will be treated as 192.168.1.1/32
This implicit translate may cause some unexpected behavior,
like user provide 192.168.2.0 and expect it will be treated as
192.168.2.0/24 but actually it will be translated to
192.168.2.0/23 because there are 9 continuous 0 from right.
In order to avoid confusion, a warning message
will be displayed when pure IP address was provided.

Other variants of CIDR are not supported yet.
12 years ago
Sunny 8783e0e9ae Move is_ip from asyncdns to common
Since implement CIDR forbidden need this function,
move it to common file seems to be a better choice.
12 years ago
clowwindy ada97ab6d9 improve comments 12 years ago
clowwindy 5316b3bf11 update .gitignore 12 years ago
clowwindy 4a2d98b280 update coverage url 12 years ago
clowwindy 51f47ccb91 update coverage url 12 years ago
clowwindy 70ebd2ef28 bump 12 years ago
clowwindy 1f8819f790 fix #270 12 years ago
clowwindy 0e6a4cd8ff output python version in unit tests 12 years ago
clowwindy f4052fbc84 fix MANIFEST.in 12 years ago
clowwindy 5e5d25efd9 Update CONTRIBUTING.md 12 years ago
clowwindy 2e9ce11ea1 bump 12 years ago
clowwindy 6efb3d00e4 fix #264 12 years ago
clowwindy 13413267dc Update README.md 12 years ago
clowwindy bd22e3ef75 try every dll that matches by name in PATH 12 years ago
clowwindy 5179e018e2 bump 12 years ago
clowwindy af6c6f3f23 also search lib* for library names 12 years ago
clowwindy 5c05a74727 fix a potential name conflict 12 years ago
clowwindy 53a7e4d0e4 remove print 12 years ago
clowwindy 5e476843ec fix python3 12 years ago
clowwindy 32a6b8fd7a update CHANGES 12 years ago
clowwindy 9fe2f4ef16 bump 12 years ago
clowwindy f7316c0047 change logging level for UDP warning 12 years ago
clowwindy cc36de5a2f fix pep8 12 years ago
clowwindy 4312eb9e58 add forbidden support for UDP and add tests 12 years ago
clowwindy eb94bd1cc3 support forbidden iplist 12 years ago
clowwindy f29bfb0cc7 remove salsa20-ctr test 12 years ago
clowwindy 80b8bd7014 remove M2Crypto completely 12 years ago
clowwindy a4b0ea5b8f fix find_library 12 years ago
clowwindy e582b2b929 rename ctypes_* and remove salsa20-ctr 12 years ago
clowwindy 3d03dbf716 extract find_library 12 years ago
clowwindy 1becc9362d Merge pull request #257 from fa08c/master
Searching libcrypto.so in more locations
12 years ago
fa08c ebfd1486d8 Removing the overhead of creating a new list per event 12 years ago
fa08c 6eadfca78e Removing trailing whites 12 years ago
fa08c 3294a92a61 Search libcrypto.so in more locations
Some linux distro may store .so in some alternative locations. Now we
try harder to find them.
12 years ago
fa08c 2711002142 Merge remote-tracking branch 'upstream/master' 12 years ago
fa08c 18da3554ff Minor fix: never use except: unless you reraise 12 years ago
clowwindy a5fc1c7e5f Merge pull request #248 from peterfyj/master
Set default method as bytes.
12 years ago
peter 8b2deb01d8 Set default method as bytes.
Default method as string may cause false error report.
12 years ago
fa08c 176e97bb45 Fixing some minor issues 12 years ago
clowwindy b6efc0efd9 Update README.md 12 years ago
clowwindy 4598e09b78 now works on OpenWRT 12 years ago
clowwindy 363965c364 Update CONTRIBUTING.md 12 years ago
clowwindy a90c354f42 update README 12 years ago
clowwindy 69d1d876bc Update README.rst 12 years ago
clowwindy ae57ebde68 Update README.md 12 years ago
clowwindy 09f8f1ccc8 Update CONTRIBUTING.md 12 years ago
clowwindy b12ba5383c Update CONTRIBUTING.md 12 years ago
clowwindy 0bc0117cd7 update help url 12 years ago
clowwindy 85cbac127d Update README.md 12 years ago
clowwindy f7a63a0ad7 Update README.md 12 years ago
clowwindy a3faf2c5fb Update README.md 12 years ago
clowwindy d01ef02b5a Update README.md 12 years ago
clowwindy 1db1e4f4e9 Update README.md 12 years ago
clowwindy 510dc64bf2 Update README.md 12 years ago
clowwindy 8be120518b Update README.md 12 years ago
clowwindy e7984930d1 use HTTPS 12 years ago
clowwindy b8f1825776 update CHANGES 12 years ago
clowwindy dde25f89e1 Update README.md 12 years ago
clowwindy 98f73e44d0 bump 12 years ago
clowwindy e0189ab1de update readme 12 years ago
clowwindy e68b3e430b add autoban 12 years ago
clowwindy bac675d7f6 2015 12 years ago
clowwindy 291adf8b85 log client address 12 years ago
clowwindy 1423fe1921 support color 12 years ago
clowwindy 5a5c8b9c7e fix coverage server 12 years ago
clowwindy 70559a1030 fix pep8 12 years ago
clowwindy 45ee594d58 coverage server now supports more projects 12 years ago
clowwindy 707b5c1def Merge pull request #237 from v3aqb/patch-1
Update ctypes_libsodium.py
12 years ago
v3aqb d91f7d85d4 Update ctypes_libsodium.py 12 years ago
clowwindy 5a5158b33f update url 12 years ago
clowwindy 7f19c31640 update project url 12 years ago
clowwindy 937693519a update url in readme 12 years ago
clowwindy 9e6e884b12 bump 12 years ago
clowwindy e8501da271 fix vim 12 years ago
clowwindy 99c8bbafe7 fix fastopen and add a new test 12 years ago
clowwindy 30f4f78557 fix travis 12 years ago
clowwindy dd140814a8 suppress some warnings 12 years ago
clowwindy d228ffbe84 add command line test 12 years ago
clowwindy ab975d1753 fix tests 12 years ago
clowwindy c6bc912c11 add command line tests 12 years ago
clowwindy b785d95f66 fix tests 12 years ago
clowwindy 1d0c8b1800 add coverage 12 years ago
clowwindy 9cfffa360e sudo tc setup 12 years ago
clowwindy cd07001471 use SIGINT instead in large file test 12 years ago
clowwindy 2cc7ee5053 alter tc rule 12 years ago
clowwindy 9b3944c954 fix large file test 12 years ago
clowwindy f1b084be06 add large file test 12 years ago
clowwindy 5ea8403e56 fix daemon and add fastopen tests 12 years ago
clowwindy 072afd68f2 use local tmp dir 12 years ago
clowwindy be1d1d5032 add SIGINT in workers 12 years ago
clowwindy 536b7d1ee6 use SIGINT instead in tests
Conflicts:
	tests/test.py
12 years ago
clowwindy c7b5a5a011 fix ci 12 years ago
clowwindy be2ab378ff add jenkins 12 years ago
clowwindy 2b4c3619d6 reorder setsid and kill 12 years ago
clowwindy dae2624b30 add setsid 12 years ago
clowwindy fb789d8e9f update readme 12 years ago
clowwindy 2733e6a4ba update readme 12 years ago
clowwindy 35c3b0b41c refine documentation 12 years ago
clowwindy 6dbabdea9d bump 12 years ago
clowwindy 28347b685e add unit test for daemon 12 years ago
clowwindy 134497c24f implement daemon 12 years ago
clowwindy 78f93a091c Update README.md 12 years ago
clowwindy 7274c7ad96 fix comments 12 years ago
clowwindy 706a137b3f fix typo 12 years ago
clowwindy 4b0b252953 improve comments 12 years ago
clowwindy 5257653440 Update CONTRIBUTING.md 12 years ago
clowwindy 163992b98b small fix 12 years ago
clowwindy 676bf9617b fix key cache when just method changes 12 years ago
clowwindy cbbc880f44 try to find the problem 12 years ago
clowwindy 810db996cd disable M2Crypto on Python 3 12 years ago
clowwindy 3e503bf677 log method in encrypt unit test 12 years ago
clowwindy 1459282ae6 only test some ciphers 12 years ago
clowwindy 4d5d6c7c85 add unit tests in encrypt 12 years ago
clowwindy a377cc3fb2 remove coveralls 12 years ago
clowwindy 92e49099b6 remove pypy as it is too slow 12 years ago
clowwindy 95ed8a7576 add coveralls 12 years ago
clowwindy 60c16fae69 fix coverage 12 years ago
clowwindy 134bf332a4 remove domain not existed test(causing time out) 12 years ago
clowwindy e1f2046229 lint code 12 years ago
clowwindy 030cdbcec0 add asyncdns test 12 years ago
clowwindy d42a32fbc0 master should wait for child to quit 12 years ago
clowwindy 2a149a5b3f fix tests 12 years ago
clowwindy c214dbf7b5 parallel libsodium and socksify builds 12 years ago
clowwindy 55630f5a7e add coverage 12 years ago
clowwindy b4ce4b7f48 update CHANGES 12 years ago
clowwindy 5fe886efad bump 12 years ago
clowwindy d7d9e5c103 add ldconfig 12 years ago
clowwindy e6416562fc add salsa20 and chacha20 12 years ago
clowwindy 9d33a59b60 add libsodium tests 12 years ago
clowwindy 84dcff83c1 add libsodium support 12 years ago
clowwindy ffcbf05975 bump 12 years ago
clowwindy 0a3730942f update CHANGES 12 years ago
clowwindy fa31a233b6 add ipv6 tests 12 years ago
clowwindy e476a54658 Merge pull request #214 from wb14123/py3-str
fix str/byte issue in python 3
12 years ago
Bin Wang f43906006a fix str/byte issue in python 3 12 years ago
clowwindy ea535c74b2 bump 12 years ago
clowwindy 143750f699 update README.rst 12 years ago
clowwindy a8996b812b update CHANGES 12 years ago
clowwindy 70dae91e7c add tests for common.py 12 years ago
clowwindy b5010df575 fix args on Python 3 12 years ago
clowwindy 4e3c055406 lint code 12 years ago
clowwindy a88d47883b add tests for command line args 12 years ago
clowwindy 6bbf347d0e Merge branch 'master' of https://github.com/jinliu/shadowsocks into jinliu-master 12 years ago
clowwindy 5209860db1 fix cipher name in test 12 years ago
clowwindy f9ba6f7390 fix table test 12 years ago
clowwindy 710fe14190 rename test_cipher as it will break unit tests 12 years ago
clowwindy 039451bcfb fix encrypt_all 12 years ago
clowwindy cbf8c6705b refactor table into a single cipher plugin 12 years ago
clowwindy 2519fb9abe Merge pull request #208 from felixonmars/table-py3
encrypt.py: port table to support python 3 (recreated)
12 years ago
Felix Yan aca86f8685 encrypt.py: port table to support python 3 12 years ago
刘缙 fb27cf52a9 Fix str/byte related TypeError in Python 3.4
Traceback (most recent call last):
File "/usr/bin/sslocal", line 9, in <module>
load_entry_point('shadowsocks==2.4', 'console_scripts', 'sslocal')()
File "/usr/lib/python3.4/site-packages/shadowsocks/local.py", line 68, in main
loop.run()
File "/usr/lib/python3.4/site-packages/shadowsocks/eventloop.py", line 230, in run
handler(events)
File "/usr/lib/python3.4/site-packages/shadowsocks/tcprelay.py", line 630, in _handle_events
handler.handle_event(sock, event)
File "/usr/lib/python3.4/site-packages/shadowsocks/tcprelay.py", line 458, in handle_event
self._on_local_read()
File "/usr/lib/python3.4/site-packages/shadowsocks/tcprelay.py", line 377, in _on_local_read
self._handle_stage_reply(data)
File "/usr/lib/python3.4/site-packages/shadowsocks/tcprelay.py", line 212, in _handle_stage_reply
s = remote_sock.sendto(data, MSG_FASTOPEN, self._chosen_server)
TypeError: 'str' does not support the buffer interface
12 years ago
clowwindy 7ac8434983 Update README.md 12 years ago
clowwindy f02e9a3132 fix EVP_CIPHER_CTX_new's arg types 12 years ago
clowwindy 9fe3cf17d5 just start curl, don't wait 12 years ago
clowwindy 22b87f6f16 Merge pull request #205 from felixonmars/py3-logging
tcprelay.py: decode remote_addr to fix extra b'' in logging on python 3
12 years ago
Felix Yan d971cb44a8 tcprelay.py: wrap long line for PEP8 12 years ago
Felix Yan 833c98e114 tcprelay.py: decode remote_addr to fix extra b'' in logging on python 3 12 years ago
clowwindy 4e08344035 bump 12 years ago
clowwindy 5892789005 refine tests: add time limit for curl; output shadowsocks logs 12 years ago
clowwindy d64450915b Merge pull request #203 from felixonmars/setup-py3-fix
setup.py: use codecs.open() so it works for non-utf8 locales
12 years ago
Felix Yan e6306f7b32 setup.py: use codecs.open() so it works for non-utf8 locales 12 years ago
clowwindy 90dc03c762 prefer ctypes over m2crypto in rc4-md5 12 years ago
clowwindy 4affb56d36 fix test 12 years ago
clowwindy 13c6c393db fix pyflakes 12 years ago
clowwindy 82ddafafa5 skip m2crypto tests on pypy 12 years ago
clowwindy 1205b8c50e skip m2crypto tests on Python 3 12 years ago
clowwindy 812a286f12 lint code 12 years ago
clowwindy 7bff002202 more cipher tests 12 years ago
clowwindy c69a127772 add some tests 12 years ago
clowwindy 099323e28e update CHANGES 12 years ago
clowwindy 50e5e620a3 fix version detection 12 years ago
clowwindy aff411a456 seems that dependency requires 3.3+ 12 years ago
clowwindy 0719e80fbd fix python 3.* 12 years ago
clowwindy efd45ddfc6 fix UDP server 12 years ago
clowwindy 4699de1dd9 fix python 3.2 12 years ago
clowwindy a502dd32fc fix UDP 12 years ago
clowwindy 5024b300f1 fix rc4-md5 12 years ago
clowwindy be045f1687 fix import 12 years ago
clowwindy 497524b313 drop table on Python 3 12 years ago
clowwindy 05ba3cc5aa lint code 12 years ago
clowwindy ede2b1b120 fix salsa20 on python 3 12 years ago
clowwindy 753e46654d bump 12 years ago
clowwindy f0b0c1edfa update python requirement 12 years ago
clowwindy 0fd2f30911 lint code 12 years ago
clowwindy b409c18877 fix python 3 tests 12 years ago
clowwindy 53d1bfaecf update setup.py 12 years ago
clowwindy f98728a761 drop table support in python 3 12 years ago
clowwindy 2a53b67c65 python 3 support; not stable yet 12 years ago
clowwindy 0814888ba5 use absolute import 12 years ago
clowwindy 89dc6031e8 lint code 12 years ago
clowwindy c553e7a725 lint code 12 years ago
clowwindy ac94104ac0 use deque instead of heapq 12 years ago
clowwindy da11d02706 fix memory leak 12 years ago
clowwindy 03eecf1206 fix pep8 12 years ago
clowwindy 8454220adc update unit test 12 years ago
clowwindy 3fc543cb7f add unit test for lru cache 12 years ago
clowwindy 2461f623dd change lru behaviour; #202 12 years ago
clowwindy 89a9872308 remove m2crypto from readme 12 years ago
clowwindy cd09638023 bump 12 years ago
clowwindy 9e8aa1c56a fix libcrypto on Windows 12 years ago
clowwindy b47de1dcf6 update CHANGES 12 years ago
clowwindy 0b64f7670f add help for Windows 12 years ago
clowwindy eb9b6f0a9b does not require M2Crypto anymore 12 years ago
clowwindy 6609de4577 Merge branch 'sybblow-patch-1' into dev 12 years ago
sybblow dfd4cdd758 avoid memory leak
Although fd is always the smallest number which haven't been allocated, which means memory leak is quite small. but the worst situation may consume lots of memory.
12 years ago
clowwindy 1af7f84f41 update changes 12 years ago
clowwindy dda8f31bd3 fix PEP8 12 years ago
clowwindy c668ddbc1b fix multiple ports 12 years ago
clowwindy f677c8152d close #185 12 years ago
clowwindy ab74c010fd close #183 12 years ago
clowwindy f0b0f6edff do not mix config of client and server for server-multi-passwd 12 years ago
clowwindy 81223902d0 fix a potential BOF 12 years ago
clowwindy b3420f24c7 update readme 12 years ago
clowwindy 4be2731293 fix PEP8 12 years ago
clowwindy f6951c9633 fix m2 12 years ago
clowwindy d6a5c567ae lint 12 years ago
clowwindy 402bc5743b add comment about buf 12 years ago
clowwindy 4ddc20945e add travis test 12 years ago
clowwindy 8114f7043a add CTR test 12 years ago
clowwindy 0e649453ed support CTR mode 12 years ago
clowwindy 2122f96aeb lint code 12 years ago
clowwindy 76fed23b34 refactor encrypt; add cfb1 and cfb8 modes 12 years ago
clowwindy a2ed12611c bump 12 years ago
clowwindy 64503498d0 update changes 12 years ago
clowwindy 5aece6f464 remove test in asyncdns 12 years ago
clowwindy e72594ffbe only end querying when response is of query type AAAA 12 years ago
clowwindy 3ce7c18dfb close #180 12 years ago
clowwindy ebf5baa311 udpate changes 12 years ago
clowwindy 21f61c7d91 avoid removing items of the handler list while iterating over it; #179 12 years ago
clowwindy 2a61e80071 only output exception in verbose mode 12 years ago
clowwindy ea70a5bd79 exit 1 on error; #179 12 years ago
clowwindy 380a646f09 handle signal soon; #179 12 years ago
clowwindy e43520da58 log when closing port 12 years ago
clowwindy fdb3a36170 implement graceful shutdown in sslocal; close #179 12 years ago
clowwindy a6b8a5eef9 add some debug logs 12 years ago
clowwindy 327c70e353 Graceful shutdown; close #179 12 years ago
clowwindy 964d7613cb update changes 12 years ago
clowwindy 3e3c885a42 remove print 12 years ago
clowwindy 1044358a6b use md5 instead of sha256; #178 12 years ago
clowwindy 1fea9dca8d update README: add link to encryption methods 12 years ago
clowwindy c9b489b5e3 fix UDP 12 years ago
clowwindy 1e1b1adba9 add RC4-SHA256 unit test 12 years ago
clowwindy 1b4e885818 add rc4-sha256; close #178 12 years ago
clowwindy 63fae5119d add debian sid instructions 12 years ago
clowwindy f7a2878c6f fix CHANGES 12 years ago
clowwindy 972bf22e6d fix PEP8 12 years ago
clowwindy b468476c9c add PEP8 check in travis CI 12 years ago
clowwindy eb7ef6e6e3 remove py2exe files 12 years ago
clowwindy a2cdc291fc Merge pull request #175 from shell909090/master
dd already uploaded
12 years ago
Shell.Xu 7ac2967d29 * still package issue 12 years ago
Shell.Xu 6d16175636 * issue with package 12 years ago
Shell.Xu fcdb1a3402 * not sure why, but gbp.conf made python source code disappear 12 years ago
Shell.Xu 78f7ee2ca1 * fix build issue 12 years ago
Shell.Xu 47d0183b80 * 3.9.5 is not passed in stable system 12 years ago
Shell.Xu a053b1e110 * add vcs info in control file 12 years ago
Shell.Xu b0be74ad48 * fix base version and quite mode 12 years ago
clowwindy f7288e3490 Merge pull request #173 from shell909090/master
debian package system
12 years ago
Shell.Xu 858dd5a62e * fix init.d issue, pass test on server 12 years ago
Shell.Xu eafc3ab547 * clean all lintian errors and warnings 12 years ago
Shell.Xu 8d74b6276e + add manpage 12 years ago
Shell.Xu 48780fed24 * adjust some config, look almostly done. 12 years ago
Shell.Xu 3b242bee5e * debian inital package files. 12 years ago
clowwindy c7d2d76767 fix typo 12 years ago
clowwindy e51aa4f137 use only ipv4 dns server 12 years ago
clowwindy 8165904eaf bump 3.0 12 years ago
clowwindy 4c29b54b7d bump 12 years ago
clowwindy ca6f72e22b better error msg 12 years ago
clowwindy fb7e83a753 less jump steps 12 years ago
clowwindy 72fe18212e add quiet mode; close #164 12 years ago
clowwindy da842918bd close #158 13 years ago
clowwindy da13e768b0 bump 13 years ago
clowwindy c1cf02cbea fix tests 13 years ago
clowwindy 68b9a063c5 move tests and remove config.json 13 years ago
clowwindy 0df13b5715 bump year 13 years ago
clowwindy c66d9b2c20 more details 13 years ago
clowwindy e7e226768a add instructions for installing m2crypto 13 years ago
clowwindy fed480bb17 include LICENSE in package tar 13 years ago
clowwindy a323f878e1 prefer addrtype 1 and 4 over 3 in UDP relay 13 years ago
clowwindy edeb66395a bump 13 years ago
clowwindy a1bc23c161 fix salsa20 13 years ago
clowwindy 2950f99da6 fix salsa20 for UDP 13 years ago
clowwindy 040c956472 fix server-multi-ports 13 years ago
clowwindy c788aa59b6 fix UDP tests 13 years ago
clowwindy 122f233143 fix udprelay for local 13 years ago
clowwindy 68cf94b10e add dnsutils for tests 13 years ago
clowwindy 130cf8fe35 add UDP tests 13 years ago
clowwindy d97e351b88 Merge branch 'dev' 13 years ago
clowwindy a614dd6e5b bump 13 years ago
clowwindy b0c8e50492 fix #145 13 years ago
clowwindy 13436b224e add EWOULDBLOCK to fix Windows; close #138 13 years ago
clowwindy 1d7d015cd3 Merge branch 'master' of github.com:clowwindy/shadowsocks 13 years ago
clowwindy b7bfdb9918 add timeout support in DNS; close #138 13 years ago
clowwindy d82441e0b4 Update CONTRIBUTING.md 13 years ago
clowwindy 63ed7a1bc6 Update CONTRIBUTING.md 13 years ago
clowwindy f4e68dc64e bump 13 years ago
clowwindy 012ab70500 use multiple DNS instead of trying each one 13 years ago
clowwindy d4458bceb7 add timeout support in DNS 13 years ago
clowwindy 5b193d6f92 Merge branch 'master' of github.com:clowwindy/shadowsocks into dev 13 years ago
clowwindy 868c7c5b38 Update README.md 13 years ago
clowwindy bbd649b1c1 Update CONTRIBUTING.md 13 years ago
clowwindy 61d9e17cae remove print 13 years ago
clowwindy f9fef0e229 add TypeError 13 years ago
clowwindy 1dd722acc7 bump 13 years ago
clowwindy 9dd3922189 update readme 13 years ago
clowwindy c3ae04d07d update readme 13 years ago
clowwindy 4b3c018aa9 verify hostname 13 years ago
clowwindy 0592fcefbd refine test 13 years ago
clowwindy 4fd19a7714 refine test 13 years ago
clowwindy cb5481499e fix tcp fastopen 13 years ago
clowwindy 41010d810e support -vv verbose logging 13 years ago
clowwindy 6c6afde2a5 auto fallback when fast open not available 13 years ago
clowwindy d639a375bc remove fd logging 13 years ago
clowwindy d949d11b28 larger buffer 13 years ago
clowwindy 35bfa56eaf fix POLL_HUP 13 years ago
clowwindy 46d23bf0d4 more log 13 years ago
clowwindy e811bdb891 bump 13 years ago
clowwindy e594478852 close #132 13 years ago
clowwindy 743d3cddb5 close #132 13 years ago
clowwindy a0e1a9f1b0 close #122 13 years ago
clowwindy 08e351a55d add more logs 13 years ago
clowwindy f19fb4ed8e Merge branch 'master' into dev 13 years ago
clowwindy 1c847a9a58 Update README.md 13 years ago
clowwindy eeda2c258d Update README.md 13 years ago
clowwindy 3c0024cef0 Update README.md 13 years ago
clowwindy c1a6dc4c9e Update README.md 13 years ago
clowwindy 71b4d34ce4 Update README.md 13 years ago
clowwindy a68b9a0520 Update README.md 13 years ago
clowwindy ed5888387b Update README.md 13 years ago
clowwindy f5caa5b3d2 update README.rst 13 years ago
clowwindy 06a87c385b bump 13 years ago
clowwindy a109f571e3 fix worker master 13 years ago
clowwindy df836bed77 fix DNS record parsing 13 years ago
clowwindy 4fb6b9df98 add CONTRIBUTING.md 13 years ago
clowwindy a7592b8625 bump 13 years ago
clowwindy 9422ef2fd3 Fix table encryption with UDP 13 years ago
clowwindy cb2e2ce0df bump 13 years ago
clowwindy 917acdf499 Merge branch 'master' into dev 13 years ago
clowwindy 2306add1df split parse_header() 13 years ago
clowwindy 4faf5cf8ae Update README.md 13 years ago
clowwindy 4cc979b998 Merge branch 'master' into dev 13 years ago
clowwindy 6e93bdd5a5 Update README.md 13 years ago
clowwindy 26fa1ab555 refine comments 13 years ago
clowwindy 24eadfbb5f send again even if in queue 13 years ago
clowwindy bcdc1e9671 add async dns to tcp relay 13 years ago
clowwindy 5c274a1bc7 update dns 13 years ago
clowwindy cdd333ea97 update dns 13 years ago
clowwindy de5461a17e refine test 13 years ago
clowwindy 71c3759c12 add async dns 13 years ago
clowwindy fbc4906445 add cache 13 years ago
clowwindy 9c0bab297e more work 13 years ago
clowwindy 5fd2f3d6ee Merge branch 'dev' into asyncdns 13 years ago
clowwindy 45f9998fa9 more work 13 years ago
clowwindy 6b76319495 more work 13 years ago
clowwindy 7a77205530 update ns 13 years ago
clowwindy 795e0f4b8e update ns 13 years ago
clowwindy 4b630d0814 update CHANGES 13 years ago
clowwindy d7d125082f handle POLL_ERR first 13 years ago
clowwindy 816592b674 add more log 13 years ago
clowwindy a185e1671b add some status protection 13 years ago
clowwindy c354d8a8af add asyncdns 13 years ago
clowwindy d88d2802b0 change status image to https 13 years ago
clowwindy aab163f067 update README.rst 13 years ago
clowwindy a7bdac3578 update setup.py 13 years ago
clowwindy f3defc8b92 update CHANGES 13 years ago
clowwindy dbaf83eb7b fix a typo 13 years ago
clowwindy e98e9232e8 update readme 13 years ago
clowwindy d3f294217c close #121 13 years ago
clowwindy a3748a292d Merge branch 'master' into dev 13 years ago
clowwindy b50a89b1f5 add server-multi-passwd-table test 13 years ago
clowwindy 5f29cd6fb5 Update README.md 13 years ago
clowwindy f832628968 Update README.md 13 years ago
clowwindy 345696cf29 Update README.md 13 years ago
clowwindy 816eee8dc1 Update README.md 13 years ago
clowwindy 8aae1f07ca warn table encryption 13 years ago
clowwindy 944c422768 fix fast open 13 years ago
clowwindy a08edd2007 fix fastopen local 13 years ago
clowwindy 8d25047d56 fix fastopen local 13 years ago
clowwindy adda6d6e29 lint code 13 years ago
clowwindy 0c12ee04cb implement fast open in local 13 years ago
clowwindy f6a9cad684 add fast open support in server 13 years ago
clowwindy fd6a0a8af0 update travis 13 years ago
clowwindy 30e8d5d1a1 add pypy 13 years ago
clowwindy 6c35dfd832 fix typo 13 years ago
clowwindy 904498fdc7 update readme 13 years ago
clowwindy 476738d273 fix errno 13 years ago
clowwindy 5d022e2828 fix None 13 years ago
clowwindy 1966b643fc update log 13 years ago
clowwindy 74566308d1 update readme 13 years ago
clowwindy baebe31df0 Merge remote-tracking branch 'origin/master' 13 years ago
clowwindy 66bbe50719 update readme 13 years ago
clowwindy c5bcb9a050 add timeout support 13 years ago
clowwindy 0e662e04b6 lint 13 years ago
clowwindy cadf0e11bb fix header parsing 13 years ago
clowwindy c225b808d6 UDP assoc 13 years ago
clowwindy e66636867a align 13 years ago
clowwindy bbad408ace rename things 13 years ago
clowwindy d69272767f update readme python version now checked by utils 13 years ago
clowwindy fe01025ba7 rename tests 13 years ago
clowwindy 0c8a8ef23f refine loop 13 years ago
clowwindy 5e19fdc66b refine exiting 13 years ago
clowwindy 7a1647278f fix multiple servers 13 years ago
clowwindy 7a98331655 add salsa20 test 13 years ago
clowwindy 77f74a0668 fix python version check 13 years ago
clowwindy 21ab52c62b fix tests 13 years ago
clowwindy 20ba04c4ce fix tests 13 years ago
clowwindy 2672a6378e fix ctrl C 13 years ago
clowwindy fd35f1d067 fix server 13 years ago
clowwindy f49d086d6a add event names 13 years ago
clowwindy c721a1c02f local works 13 years ago
clowwindy 3cefe374c2 socket.SO_REUSEADDR 13 years ago
clowwindy 5e9a9c9beb almost done 13 years ago
clowwindy cd22d474fe almost done 13 years ago
clowwindy 47fd479d6e almost done 13 years ago
clowwindy bacf9cb443 more work 13 years ago
clowwindy 4ccf4081b3 more work 13 years ago
clowwindy 9b2a45583e more work 13 years ago
clowwindy c2f6bc369c more work 13 years ago
clowwindy d1aec8bc28 Update README.md 13 years ago
clowwindy 0d6c39900b more work 13 years ago
clowwindy 2cdddd4515 update config 13 years ago
clowwindy 4f46400145 add ssloop branch 13 years ago
clowwindy 5ad8cd6f3d Update README.md 13 years ago
clowwindy 1868487c11 Update README.md 13 years ago

3
.gitignore vendored

@ -17,7 +17,8 @@ develop-eggs
pip-log.txt
# Unit test / coverage reports
.coverage
htmlcov
.coverage*
.tox
#Translations

@ -2,12 +2,20 @@ language: python
python:
- 2.6
- 2.7
- 3.3
- 3.4
cache:
directories:
- dante-1.4.0
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq build-essential libssl-dev swig libevent-dev python-gevent python-m2crypto python-numpy
- pip install m2crypto gevent salsa20
- sudo apt-get install -qq build-essential dnsutils iproute nginx bc
- sudo dd if=/dev/urandom of=/usr/share/nginx/www/file bs=1M count=10
- sudo sh -c "echo '127.0.0.1 localhost' > /etc/hosts"
- sudo service nginx restart
- pip install pep8 pyflakes nose coverage PySocks
- sudo tests/socksify/install.sh
- sudo tests/libsodium/install.sh
- sudo tests/setup_tc.sh
script:
- python test.py -c test/table.json
- python test.py -c test/aes.json
- python test.py -c test/salsa20.json
- python test.py -c test/server-multi-passwd.json
- tests/jenkins.sh

@ -1,105 +0,0 @@
1.4.5 2014-05-24
- Add timeout in TCP server
- Close sockets in master process
1.4.4 2014-05-17
- Support multiple workers
1.4.3 2014-05-13
- Fix Windows
1.4.2 2014-05-10
- Add salsa20-ctr cipher
1.4.1 2014-05-03
- Fix error log
- Fix EINPROGESS with some version of gevent
1.4.0 2014-05-02
- Adds UDP relay
- TCP fast open support on Linux 3.7+
1.3.7 2014-04-10
- Fix a typo in help
1.3.6 2014-04-10
- Fix a typo in help
1.3.5 2014-04-07
- Add help
- Change default local binding address into 127.0.0.1
1.3.4 2014-02-17
- Fix a bug when no config file exists
- Client now support multiple server ports and multiple server/port pairs
- Better error message with bad config.json format and wrong password
1.3.3 2013-07-09
- Fix default key length of rc2
1.3.2 2013-07-04
- Server will listen at server IP specified in config
- Check config file and show some warning messages
1.3.1 2013-06-29
- Fix -c arg
1.3.0 2013-06-22
- Move to pypi
1.2.3 2013-06-14
- add bind address
1.2.2 2013-05-31
- local can listen at ::0 with -6 arg; bump 1.2.2
1.2.1 2013-05-23
- Fix an OpenSSL crash
1.2 2013-05-22
- Use random iv, we finally have strong encryption
1.1.1 2013-05-21
- Add encryption, AES, blowfish, etc.
1.1 2013-05-16
- Support IPv6 addresses (type 4)
- Drop Python 2.5 support
1.0 2013-04-03
- Fix -6 IPv6
0.9.4 2013-03-04
- Support Python 2.5
0.9.3 2013-01-14
- Fix conn termination null data
0.9.2 2013-01-05
- Change default timeout
0.9.1 2013-01-05
- Add Travis-CI test
0.9 2012-12-30
- Replace send with sendall, fix FreeBSD
0.6 2012-12-06
- Support args
0.5 2012-11-08
- Fix encryption with negative md5sum
0.4 2012-11-02
- Move config into a JSON file
- Auto-detect config path
0.3 2012-06-06
- Move socks5 negotiation to local
0.2 2012-05-11
- Add -6 arg for IPv6
- Fix socket.error
0.1 2012-04-20
- Initial version

@ -1,21 +0,0 @@
Shadowsocks
Copyright (c) 2013 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.

@ -1,138 +1 @@
shadowsocks
===========
Current version: 1.4.5 [![Build Status][1]][0]
shadowsocks is a lightweight tunnel proxy which can help you get through firewalls.
Both TCP CONNECT and UDP ASSOCIATE are implemented.
[中文说明][3]
Install
-------
First, make sure you have Python 2.6 or 2.7.
$ python --version
Python 2.6.8
Install Shadowsocks.
#### Debian / Ubuntu:
apt-get install python-pip python-gevent python-m2crypto
pip install shadowsocks
#### CentOS:
yum install m2crypto python-setuptools
easy_install pip
pip install shadowsocks
#### OS X:
git clone https://github.com/clowwindy/M2Crypto.git
cd M2Crypto
pip install .
pip install shadowsocks
#### Windows:
Choose a [GUI client][7]
Usage
-----
Create a config file `/etc/shadowsocks.json` (or put it in other path).
Example:
{
"server":"my_server_ip",
"server_port":8388,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"mypassword",
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false,
"workers": 1
}
Explanation of the fields:
| Name | Explanation |
| ------------- | ----------------------------------------------- |
| server | the address your server listens |
| server_port | server port |
| local_address | the address your local listens |
| local_port | local port |
| password | password used for encryption |
| timeout | in seconds |
| method | encryption method, "aes-256-cfb" is recommended |
| fast_open | use [TCP_FASTOPEN][2], true / false |
| workers | number of workers, available on Unix/Linux |
Run `ssserver -c /etc/shadowsocks.json` on your server. To run it in the background, [use supervisor][8].
On your client machine, run `sslocal -c /etc/shadowsocks.json`.
Change the proxy settings in your browser to
protocol: socks5
hostname: 127.0.0.1
port: your local_port
**Notice: If you want to use encryption methods other than "table", please install M2Crypto (See Encryption Section).**
It's recommended to use shadowsocks with AutoProxy or Proxy SwitchySharp.
Command line args
------------------
You can use args to override settings from `config.json`.
sslocal -s server_name -p server_port -l local_port -k password -m bf-cfb
ssserver -p server_port -k password -m bf-cfb --workers 2
ssserver -c /etc/shadowsocks/config.json
Salsa20
-------
Salsa20 is a fast stream cipher.
Use "salsa20-ctr" in shadowsocks.json.
And install these packages:
#### Debian / Ubuntu:
apt-get install python-numpy
pip install salsa20
Wiki
----
https://github.com/clowwindy/shadowsocks/wiki
License
-------
MIT
Bugs and Issues
----------------
Please visit [issue tracker][5]
Mailing list: http://groups.google.com/group/shadowsocks
Also see [troubleshooting][6]
[0]: https://travis-ci.org/clowwindy/shadowsocks
[1]: https://travis-ci.org/clowwindy/shadowsocks.png?branch=master
[2]: https://github.com/clowwindy/shadowsocks/wiki/TCP-Fast-Open
[3]: https://github.com/clowwindy/shadowsocks/wiki/Shadowsocks-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E
[4]: http://chandlerproject.org/Projects/MeTooCrypto
[5]: https://github.com/clowwindy/shadowsocks/issues?state=open
[6]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting
[7]: https://github.com/clowwindy/shadowsocks/wiki/Ports-and-Clients
[8]: https://github.com/clowwindy/shadowsocks/wiki/Configure-Shadowsocks-with-Supervisor
:)

@ -1,170 +0,0 @@
shadowsocks
===========
shadowsocks is a lightweight tunnel proxy which can help you get through
firewalls.
Both TCP CONNECT and UDP ASSOCIATE are implemented.
`中文说明 <https://github.com/clowwindy/shadowsocks/wiki/Shadowsocks-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E>`__
Install
-------
First, make sure you have Python 2.6 or 2.7.
::
$ python --version
Python 2.6.8
Install Shadowsocks.
Debian / Ubuntu:
^^^^^^^^^^^^^^^^
::
apt-get install python-pip python-gevent python-m2crypto
pip install shadowsocks
CentOS:
^^^^^^^
::
yum install m2crypto python-setuptools
easy_install pip
pip install shadowsocks
OS X:
^^^^^
::
git clone https://github.com/clowwindy/M2Crypto.git
cd M2Crypto
pip install .
pip install shadowsocks
Windows:
^^^^^^^^
Choose a `GUI
client <https://github.com/clowwindy/shadowsocks/wiki/Ports-and-Clients>`__
Usage
-----
Create a config file ``/etc/shadowsocks.json`` (or put it in other
path). Example:
::
{
"server":"my_server_ip",
"server_port":8388,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"mypassword",
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false,
"workers": 1
}
Explanation of the fields:
+------------------+-----------------------------------------------------------------------------------------------------+
| Name | Explanation |
+==================+=====================================================================================================+
| server | the address your server listens |
+------------------+-----------------------------------------------------------------------------------------------------+
| server\_port | server port |
+------------------+-----------------------------------------------------------------------------------------------------+
| local\_address | the address your local listens |
+------------------+-----------------------------------------------------------------------------------------------------+
| local\_port | local port |
+------------------+-----------------------------------------------------------------------------------------------------+
| password | password used for encryption |
+------------------+-----------------------------------------------------------------------------------------------------+
| timeout | in seconds |
+------------------+-----------------------------------------------------------------------------------------------------+
| method | encryption method, "aes-256-cfb" is recommended |
+------------------+-----------------------------------------------------------------------------------------------------+
| fast\_open | use `TCP\_FASTOPEN <https://github.com/clowwindy/shadowsocks/wiki/TCP-Fast-Open>`__, true / false |
+------------------+-----------------------------------------------------------------------------------------------------+
| workers | number of workers, available on Unix/Linux |
+------------------+-----------------------------------------------------------------------------------------------------+
Run ``ssserver -c /etc/shadowsocks.json`` on your server. To run it in
the background, `use
supervisor <https://github.com/clowwindy/shadowsocks/wiki/Configure-Shadowsocks-with-Supervisor>`__.
On your client machine, run ``sslocal -c /etc/shadowsocks.json``.
Change the proxy settings in your browser to
::
protocol: socks5
hostname: 127.0.0.1
port: your local_port
**Notice: If you want to use encryption methods other than "table",
please install M2Crypto (See Encryption Section).**
It's recommended to use shadowsocks with AutoProxy or Proxy
SwitchySharp.
Command line args
-----------------
You can use args to override settings from ``config.json``.
::
sslocal -s server_name -p server_port -l local_port -k password -m bf-cfb
ssserver -p server_port -k password -m bf-cfb --workers 2
ssserver -c /etc/shadowsocks/config.json
Salsa20
-------
Salsa20 is a fast stream cipher.
Use "salsa20-ctr" in shadowsocks.json.
And install these packages:
Debian / Ubuntu:
^^^^^^^^^^^^^^^^
::
apt-get install python-numpy
pip install salsa20
Wiki
----
https://github.com/clowwindy/shadowsocks/wiki
License
-------
MIT
Bugs and Issues
---------------
Please visit `issue
tracker <https://github.com/clowwindy/shadowsocks/issues?state=open>`__
Mailing list: http://groups.google.com/group/shadowsocks
Also see
`troubleshooting <https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting>`__
.. |Build Status| image:: https://travis-ci.org/clowwindy/shadowsocks.png?branch=master
:target: https://travis-ci.org/clowwindy/shadowsocks

@ -1,10 +0,0 @@
{
"server":"0.0.0.0",
"server_port":8388,
"local_port":1080,
"password":"barfoo!",
"timeout":300,
"method":"aes-256-cfb",
"local_address":"127.0.0.1",
"fast_open":false
}

@ -1,19 +0,0 @@
from distutils.core import setup
# NOTICE!!
# This setup.py is written for py2exe
# Don't make a python package using this file!
try:
import py2exe
except ImportError:
pass
setup(name='shadowsocks',
version='1.2.3',
description='a lightweight tunnel proxy which can help you get through firewalls',
author='clowwindy',
author_email='clowwindy42@gmail.com',
url='https://github.com/clowwindy/shadowsocks',
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{"script":"local.py", "dest_base": "shadowsocks_local",}],
zipfile = None)

@ -1,33 +0,0 @@
from setuptools import setup
with open('README.rst') as f:
long_description = f.read()
setup(
name="shadowsocks",
version="1.4.5",
license='MIT',
description="a lightweight tunnel proxy",
author='clowwindy',
author_email='clowwindy42@gmail.com',
url='https://github.com/clowwindy/shadowsocks',
packages=['shadowsocks'],
package_data={
'shadowsocks': ['README.rst', 'LICENSE', 'config.json']
},
install_requires=['setuptools'],
entry_points="""
[console_scripts]
sslocal = shadowsocks.local:main
ssserver = shadowsocks.server:main
""",
classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Internet :: Proxy Servers',
],
long_description=long_description,
)

@ -1 +0,0 @@
#!/usr/bin/python

@ -1,226 +0,0 @@
#!/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 os
import sys
import hashlib
import string
import struct
import logging
import encrypt_salsa20
def random_string(length):
try:
import M2Crypto.Rand
return M2Crypto.Rand.rand_bytes(length)
except ImportError:
# TODO really strong enough on Linux?
return os.urandom(length)
cached_tables = {}
cached_keys = {}
def get_table(key):
m = hashlib.md5()
m.update(key)
s = m.digest()
(a, b) = struct.unpack('<QQ', s)
table = [c for c in string.maketrans('', '')]
for i in xrange(1, 1024):
table.sort(lambda x, y: int(a % (ord(x) + i) - a % (ord(y) + i)))
return table
def init_table(key, method=None):
if method is not None and method == 'table':
method = None
if method:
try:
__import__('M2Crypto')
except ImportError:
logging.error('M2Crypto is required to use encryption other than '
'default method')
sys.exit(1)
if not method:
if key in cached_tables:
return cached_tables[key]
encrypt_table = ''.join(get_table(key))
decrypt_table = string.maketrans(encrypt_table,
string.maketrans('', ''))
cached_tables[key] = [encrypt_table, decrypt_table]
else:
try:
Encryptor(key, method) # test if the settings if OK
except Exception as e:
logging.error(e)
sys.exit(1)
def EVP_BytesToKey(password, key_len, iv_len):
# equivalent to OpenSSL's EVP_BytesToKey() with count 1
# so that we make the same key and iv as nodejs version
password = str(password)
r = cached_keys.get(password, None)
if r:
return r
m = []
i = 0
while len(''.join(m)) < (key_len + iv_len):
md5 = hashlib.md5()
data = password
if i > 0:
data = m[i - 1] + password
md5.update(data)
m.append(md5.digest())
i += 1
ms = ''.join(m)
key = ms[:key_len]
iv = ms[key_len:key_len + iv_len]
cached_keys[password] = (key, iv)
return (key, iv)
method_supported = {
'aes-128-cfb': (16, 16),
'aes-192-cfb': (24, 16),
'aes-256-cfb': (32, 16),
'bf-cfb': (16, 8),
'camellia-128-cfb': (16, 16),
'camellia-192-cfb': (24, 16),
'camellia-256-cfb': (32, 16),
'cast5-cfb': (16, 8),
'des-cfb': (8, 8),
'idea-cfb': (16, 8),
'rc2-cfb': (16, 8),
'rc4': (16, 0),
'seed-cfb': (16, 16),
'salsa20-ctr': (32, 8),
}
class Encryptor(object):
def __init__(self, key, method=None):
if method == 'table':
method = None
self.key = key
self.method = method
self.iv = None
self.iv_sent = False
self.cipher_iv = ''
self.decipher = None
if method:
self.cipher = self.get_cipher(key, method, 1, iv=random_string(32))
else:
self.encrypt_table, self.decrypt_table = init_table(key)
self.cipher = None
def get_cipher_len(self, method):
method = method.lower()
m = method_supported.get(method, None)
return m
def iv_len(self):
return len(self.cipher_iv)
def get_cipher(self, password, method, op, iv=None):
password = password.encode('utf-8')
method = method.lower()
m = self.get_cipher_len(method)
if m:
key, iv_ = EVP_BytesToKey(password, m[0], m[1])
if iv is None:
iv = iv_
iv = iv[:m[1]]
if op == 1:
self.cipher_iv = iv[:m[1]] # this iv is for cipher not decipher
if method != 'salsa20-ctr':
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)
def encrypt(self, buf):
if len(buf) == 0:
return buf
if not self.method:
return string.translate(buf, self.encrypt_table)
else:
if self.iv_sent:
return self.cipher.update(buf)
else:
self.iv_sent = True
return self.cipher_iv + self.cipher.update(buf)
def decrypt(self, buf):
if len(buf) == 0:
return buf
if not self.method:
return string.translate(buf, self.decrypt_table)
else:
if self.decipher is None:
decipher_iv_len = self.get_cipher_len(self.method)[1]
decipher_iv = buf[:decipher_iv_len]
self.decipher = self.get_cipher(self.key, self.method, 0,
iv=decipher_iv)
buf = buf[decipher_iv_len:]
if len(buf) == 0:
return buf
return self.decipher.update(buf)
def encrypt_all(password, method, op, data):
if method is not None and method.lower() == 'table':
method = None
if not method:
[encrypt_table, decrypt_table] = init_table(password)
if op:
return string.translate(encrypt_table, data)
else:
return string.translate(decrypt_table, data)
else:
import M2Crypto.EVP
result = []
method = method.lower()
(key_len, iv_len) = method_supported[method]
(key, _) = EVP_BytesToKey(password, key_len, iv_len)
if op:
iv = random_string(iv_len)
result.append(iv)
else:
iv = data[:iv_len]
data = data[iv_len:]
cipher = M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv, op,
key_as_bytes=0, d='md5', salt=None, i=1,
padding=1)
result.append(cipher.update(data))
f = cipher.final()
if f:
result.append(f)
return ''.join(result)

@ -1,132 +0,0 @@
#!/usr/bin/python
import time
import struct
import logging
import sys
slow_xor = False
imported = False
BLOCK_SIZE = 16384
def run_imports():
global imported, slow_xor, salsa20, numpy
if not imported:
imported = True
try:
import numpy
except ImportError:
logging.error('can not import numpy, using SLOW XOR')
logging.error('please install numpy if you use salsa20')
slow_xor = True
try:
import salsa20
except ImportError:
logging.error('you have to install salsa20 before you use salsa20')
sys.exit(1)
def numpy_xor(a, b):
if slow_xor:
return py_xor_str(a, b)
dtype = numpy.byte
if len(a) % 4 == 0:
dtype = numpy.uint32
elif len(a) % 2 == 0:
dtype = numpy.uint16
ab = numpy.frombuffer(a, dtype=dtype)
bb = numpy.frombuffer(b, dtype=dtype)
c = numpy.bitwise_xor(ab, bb)
r = c.tostring()
return r
def py_xor_str(a, b):
c = []
for i in xrange(0, len(a)):
c.append(chr(ord(a[i]) ^ ord(b[i])))
return ''.join(c)
class Salsa20Cipher(object):
"""a salsa20 CTR implemetation, provides m2crypto like cipher API"""
def __init__(self, alg, key, iv, op, key_as_bytes=0, d=None, salt=None,
i=1, padding=1):
run_imports()
if alg != 'salsa20-ctr':
raise Exception('unknown algorithm')
self._key = key
self._nonce = struct.unpack('<Q', iv)[0]
self._pos = 0
self._next_stream()
def _next_stream(self):
self._nonce &= 0xFFFFFFFFFFFFFFFF
self._stream = salsa20.Salsa20_keystream(BLOCK_SIZE,
struct.pack('<Q', self._nonce),
self._key)
self._nonce += 1
def update(self, data):
results = []
while True:
remain = BLOCK_SIZE - self._pos
cur_data = data[:remain]
cur_data_len = len(cur_data)
cur_stream = self._stream[self._pos:self._pos + cur_data_len]
self._pos = self._pos + cur_data_len
data = data[remain:]
results.append(numpy_xor(cur_data, cur_stream))
if self._pos >= BLOCK_SIZE:
self._next_stream()
self._pos = 0
if not data:
break
return ''.join(results)
def test():
from os import urandom
import random
rounds = 1 * 1024
plain = urandom(BLOCK_SIZE * rounds)
import M2Crypto.EVP
# cipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 1,
# key_as_bytes=0, d='md5', salt=None, i=1,
# padding=1)
# decipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 0,
# key_as_bytes=0, d='md5', salt=None, i=1,
# padding=1)
cipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
results = []
pos = 0
print 'start'
start = time.time()
while pos < len(plain):
l = random.randint(100, 32768)
c = cipher.update(plain[pos:pos + l])
results.append(c)
pos += l
pos = 0
c = ''.join(results)
results = []
while pos < len(plain):
l = random.randint(100, 32768)
results.append(decipher.update(c[pos:pos + l]))
pos += l
end = time.time()
print BLOCK_SIZE * rounds / (end - start)
assert ''.join(results) == plain
if __name__ == '__main__':
test()

@ -1,189 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# 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.
# from ssloop
# https://github.com/clowwindy/ssloop
import select
from collections import defaultdict
__all__ = ['EventLoop', 'POLL_NULL', 'POLL_IN', 'POLL_OUT', 'POLL_ERR',
'POLL_HUP', 'POLL_NVAL']
POLL_NULL = 0x00
POLL_IN = 0x01
POLL_OUT = 0x04
POLL_ERR = 0x08
POLL_HUP = 0x10
POLL_NVAL = 0x20
class EpollLoop(object):
def __init__(self):
self._epoll = select.epoll()
def poll(self, timeout):
return self._epoll.poll(timeout)
def add_fd(self, fd, mode):
self._epoll.register(fd, mode)
def remove_fd(self, fd):
self._epoll.unregister(fd)
def modify_fd(self, fd, mode):
self._epoll.modify(fd, mode)
class KqueueLoop(object):
MAX_EVENTS = 1024
def __init__(self):
self._kqueue = select.kqueue()
self._fds = {}
def _control(self, fd, mode, flags):
events = []
if mode & POLL_IN:
events.append(select.kevent(fd, select.KQ_FILTER_READ, flags))
if mode & POLL_OUT:
events.append(select.kevent(fd, select.KQ_FILTER_WRITE, flags))
for e in events:
self._kqueue.control([e], 0)
def poll(self, timeout):
if timeout < 0:
timeout = None # kqueue behaviour
events = self._kqueue.control(None, KqueueLoop.MAX_EVENTS, timeout)
results = defaultdict(lambda: POLL_NULL)
for e in events:
fd = e.ident
if e.filter == select.KQ_FILTER_READ:
results[fd] |= POLL_IN
elif e.filter == select.KQ_FILTER_WRITE:
results[fd] |= POLL_OUT
return results.iteritems()
def add_fd(self, fd, mode):
self._fds[fd] = mode
self._control(fd, mode, select.KQ_EV_ADD)
def remove_fd(self, fd):
self._control(fd, self._fds[fd], select.KQ_EV_DELETE)
del self._fds[fd]
def modify_fd(self, fd, mode):
self.remove_fd(fd)
self.add_fd(fd, mode)
class SelectLoop(object):
def __init__(self):
self._r_list = set()
self._w_list = set()
self._x_list = set()
def poll(self, timeout):
r, w, x = select.select(self._r_list, self._w_list, self._x_list,
timeout)
results = defaultdict(lambda: POLL_NULL)
for p in [(r, POLL_IN), (w, POLL_OUT), (x, POLL_ERR)]:
for fd in p[0]:
results[fd] |= p[1]
return results.items()
def add_fd(self, fd, mode):
if mode & POLL_IN:
self._r_list.add(fd)
if mode & POLL_OUT:
self._w_list.add(fd)
if mode & POLL_ERR:
self._x_list.add(fd)
def remove_fd(self, fd):
if fd in self._r_list:
self._r_list.remove(fd)
if fd in self._w_list:
self._w_list.remove(fd)
if fd in self._x_list:
self._x_list.remove(fd)
def modify_fd(self, fd, mode):
self.remove_fd(fd)
self.add_fd(fd, mode)
class EventLoop(object):
def __init__(self):
if hasattr(select, 'epoll'):
self._impl = EpollLoop()
elif hasattr(select, 'kqueue'):
self._impl = KqueueLoop()
elif hasattr(select, 'select'):
self._impl = SelectLoop()
else:
raise Exception('can not find any available functions in select '
'package')
self._fd_to_f = {}
def poll(self, timeout=None):
events = self._impl.poll(timeout)
return ((self._fd_to_f[fd], event) for fd, event in events)
def add(self, f, mode):
fd = f.fileno()
self._fd_to_f[fd] = f
self._impl.add_fd(fd, mode)
def remove(self, f):
fd = f.fileno()
self._fd_to_f[fd] = None
self._impl.remove_fd(fd)
def modify(self, f, mode):
fd = f.fileno()
self._impl.modify_fd(fd, mode)
# from tornado
def errno_from_exception(e):
"""Provides the errno from an Exception object.
There are cases that the errno attribute was not set so we pull
the errno out of the args but if someone instatiates an Exception
without any args you will get a tuple error. So this function
abstracts all that behavior to give you a safe way to get the
errno.
"""
if hasattr(e, 'errno'):
return e.errno
elif e.args:
return e.args[0]
else:
return None

@ -1,374 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 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.
from __future__ import with_statement
import sys
if sys.version_info < (2, 6):
import simplejson as json
else:
import json
try:
import gevent
import gevent.monkey
gevent.monkey.patch_all(dns=gevent.version_info[0] >= 1)
except ImportError:
gevent = None
print >>sys.stderr, 'warning: gevent not found, using threading instead'
import socket
import eventloop
import errno
import select
import SocketServer
import struct
import os
import random
import re
import logging
import getopt
import encrypt
import utils
import udprelay
MSG_FASTOPEN = 0x20000000
def send_all(sock, data):
bytes_sent = 0
while True:
r = sock.send(data[bytes_sent:])
if r < 0:
return r
bytes_sent += r
if bytes_sent == len(data):
return bytes_sent
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
allow_reuse_address = True
def get_request(self):
connection = self.socket.accept()
connection[0].settimeout(config_timeout)
return connection
class Socks5Server(SocketServer.StreamRequestHandler):
@staticmethod
def get_server():
a_port = config_server_port
a_server = config_server
if isinstance(config_server_port, list):
# support config like "server_port": [8081, 8082]
a_port = random.choice(config_server_port)
if isinstance(config_server, list):
# support config like "server": ["123.123.123.1", "123.123.123.2"]
a_server = random.choice(config_server)
r = re.match(r'^(.*):(\d+)$', a_server)
if r:
# support config like "server": "123.123.123.1:8381"
# or "server": ["123.123.123.1:8381", "123.123.123.2:8381"]
a_server = r.group(1)
a_port = int(r.group(2))
return a_server, a_port
@staticmethod
def handle_tcp(sock, remote, encryptor, pending_data=None,
server=None, port=None):
connected = False
try:
if config_fast_open:
fdset = [sock]
else:
fdset = [sock, remote]
while True:
should_break = False
r, w, e = select.select(fdset, [], [], config_timeout)
if not r:
logging.warn('read time out')
break
if sock in r:
if not connected and config_fast_open:
data = sock.recv(4096)
data = encryptor.encrypt(pending_data + data)
pending_data = None
logging.info('fast open %s:%d' % (server, port))
try:
remote.sendto(data, MSG_FASTOPEN, (server, port))
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) == errno.EINPROGRESS:
pass
else:
raise e
connected = True
fdset = [sock, remote]
else:
data = sock.recv(4096)
if pending_data:
data = pending_data + data
pending_data = None
data = encryptor.encrypt(data)
if len(data) <= 0:
should_break = True
else:
result = send_all(remote, data)
if result < len(data):
raise Exception('failed to send all data')
if remote in r:
data = encryptor.decrypt(remote.recv(4096))
if len(data) <= 0:
should_break = True
else:
result = send_all(sock, data)
if result < len(data):
raise Exception('failed to send all data')
if should_break:
# make sure all data are read before we close the sockets
# TODO: we haven't read ALL the data, actually
# http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/TCPRST.pdf
break
finally:
sock.close()
remote.close()
def handle(self):
try:
encryptor = encrypt.Encryptor(config_password, config_method)
sock = self.connection
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
data = sock.recv(262)
if not data:
sock.close()
return
if len(data) < 3:
return
method = ord(data[2])
if method == 2:
logging.warn('client tries to use username/password auth, prete'
'nding the password is OK')
sock.send('\x05\x02')
try:
ver_ulen = sock.recv(2)
ulen = ord(ver_ulen[1])
if ulen:
username = sock.recv(ulen)
assert(ulen == len(username))
plen = ord(sock.recv(1))
if plen:
_password = sock.recv(plen)
assert(plen == len(_password))
sock.send('\x01\x00')
except Exception as e:
logging.error(e)
return
elif method == 0:
sock.send("\x05\x00")
else:
logging.error('unsupported method %d' % method)
return
data = self.rfile.read(4) or '\x00' * 4
mode = ord(data[1])
if mode == 1:
pass
elif mode == 3:
# UDP
logging.debug('UDP assc request')
if sock.family == socket.AF_INET6:
header = '\x05\x00\x00\x04'
else:
header = '\x05\x00\x00\x01'
addr, port = sock.getsockname()
addr_to_send = socket.inet_pton(sock.family, addr)
port_to_send = struct.pack('>H', port)
sock.send(header + addr_to_send + port_to_send)
while True:
data = sock.recv(4096)
if not data:
break
return
else:
logging.warn('unknown mode %d' % mode)
return
addrtype = ord(data[3])
addr_to_send = data[3]
if addrtype == 1:
addr_ip = self.rfile.read(4)
addr = socket.inet_ntoa(addr_ip)
addr_to_send += addr_ip
elif addrtype == 3:
addr_len = self.rfile.read(1)
addr = self.rfile.read(ord(addr_len))
addr_to_send += addr_len + addr
elif addrtype == 4:
addr_ip = self.rfile.read(16)
addr = socket.inet_ntop(socket.AF_INET6, addr_ip)
addr_to_send += addr_ip
else:
logging.warn('addr_type not supported')
# not supported
return
addr_port = self.rfile.read(2)
addr_to_send += addr_port
port = struct.unpack('>H', addr_port)
try:
reply = "\x05\x00\x00\x01"
reply += socket.inet_aton('0.0.0.0') + struct.pack(">H", 2222)
self.wfile.write(reply)
# reply immediately
a_server, a_port = Socks5Server.get_server()
addrs = socket.getaddrinfo(a_server, a_port)
if addrs:
af, socktype, proto, canonname, sa = addrs[0]
if config_fast_open:
remote = socket.socket(af, socktype, proto)
remote.setsockopt(socket.IPPROTO_TCP,
socket.TCP_NODELAY, 1)
Socks5Server.handle_tcp(sock, remote, encryptor,
addr_to_send, a_server, a_port)
else:
logging.info('connecting %s:%d' % (addr, port[0]))
remote = socket.create_connection((a_server, a_port),
timeout=config_timeout)
remote.settimeout(config_timeout)
remote.setsockopt(socket.IPPROTO_TCP,
socket.TCP_NODELAY, 1)
Socks5Server.handle_tcp(sock, remote, encryptor,
addr_to_send)
except (OSError, IOError) as e:
logging.warn(e)
return
except (OSError, IOError) as e:
raise e
logging.warn(e)
def main():
global config_server, config_server_port, config_password, config_method,\
config_fast_open, config_timeout
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
version = ''
try:
import pkg_resources
version = pkg_resources.get_distribution('shadowsocks').version
except:
pass
print 'shadowsocks %s' % version
config_password = None
config_method = None
config_path = utils.find_config()
try:
optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:t:',
['fast-open'])
for key, value in optlist:
if key == '-c':
config_path = value
if config_path:
logging.info('loading config from %s' % config_path)
with open(config_path, 'rb') as f:
try:
config = json.load(f)
except ValueError as e:
logging.error('found an error in config.json: %s',
e.message)
sys.exit(1)
else:
config = {}
optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:t:',
['fast-open'])
for key, value in optlist:
if key == '-p':
config['server_port'] = int(value)
elif key == '-k':
config['password'] = value
elif key == '-l':
config['local_port'] = int(value)
elif key == '-s':
config['server'] = value
elif key == '-m':
config['method'] = value
elif key == '-b':
config['local_address'] = value
elif key == '--fast-open':
config['fast_open'] = True
except getopt.GetoptError as e:
logging.error(e)
utils.print_local_help()
sys.exit(2)
config_server = config['server']
config_server_port = config['server_port']
config_local_port = config['local_port']
config_password = config['password']
config_method = config.get('method', None)
config_local_address = config.get('local_address', '127.0.0.1')
config_timeout = int(config.get('timeout', 300))
config_fast_open = config.get('fast_open', False)
if not config_password and not config_path:
sys.exit('config not specified, please read '
'https://github.com/clowwindy/shadowsocks')
utils.check_config(config)
encrypt.init_table(config_password, config_method)
addrs = socket.getaddrinfo(config_local_address, config_local_port)
if not addrs:
logging.error('cant resolve listen address')
sys.exit(1)
ThreadingTCPServer.address_family = addrs[0][0]
try:
udprelay.UDPRelay(config_local_address, int(config_local_port),
config_server, config_server_port, config_password,
config_method, int(config_timeout), True).start()
server = ThreadingTCPServer((config_local_address, config_local_port),
Socks5Server)
server.timeout = int(config_timeout)
logging.info("starting local at %s:%d" %
tuple(server.server_address[:2]))
server.serve_forever()
except socket.error, e:
logging.error(e)
except KeyboardInterrupt:
server.shutdown()
sys.exit(0)
if __name__ == '__main__':
main()

@ -1,64 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import collections
import logging
import heapq
import time
class LRUCache(collections.MutableMapping):
"""This class is not thread safe"""
def __init__(self, timeout=60, close_callback=None, *args, **kwargs):
self.timeout = timeout
self.close_callback = close_callback
self.store = {}
self.time_to_keys = collections.defaultdict(list)
self.last_visits = []
self.update(dict(*args, **kwargs)) # use the free update to set keys
def __getitem__(self, key):
"O(logm)"
t = time.time()
self.time_to_keys[t].append(key)
heapq.heappush(self.last_visits, t)
return self.store[key]
def __setitem__(self, key, value):
"O(logm)"
t = time.time()
self.store[key] = value
self.time_to_keys[t].append(key)
heapq.heappush(self.last_visits, t)
def __delitem__(self, key):
"O(1)"
del self.store[key]
def __iter__(self):
return iter(self.store)
def __len__(self):
return len(self.store)
def sweep(self):
"O(m)"
now = time.time()
c = 0
while len(self.last_visits) > 0:
least = self.last_visits[0]
if now - least <= self.timeout:
break
for key in self.time_to_keys[least]:
heapq.heappop(self.last_visits)
if self.store.__contains__(key):
value = self.store[key]
if self.close_callback is not None:
self.close_callback(value)
del self.store[key]
c += 1
del self.time_to_keys[least]
if c:
logging.debug('%d keys swept' % c)

@ -1,322 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 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.
from __future__ import with_statement
import sys
if sys.version_info < (2, 6):
import simplejson as json
else:
import json
# TODO remove gevent
try:
import gevent
import gevent.monkey
gevent.monkey.patch_all(dns=gevent.version_info[0] >= 1)
except ImportError:
gevent = None
print >>sys.stderr, 'warning: gevent not found, using threading instead'
import socket
import select
import threading
import SocketServer
import struct
import logging
import getopt
import encrypt
import os
import utils
import udprelay
def send_all(sock, data):
bytes_sent = 0
while True:
r = sock.send(data[bytes_sent:])
if r < 0:
return r
bytes_sent += r
if bytes_sent == len(data):
return bytes_sent
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
allow_reuse_address = True
def server_activate(self):
if config_fast_open:
try:
self.socket.setsockopt(socket.SOL_TCP, 23, 5)
except socket.error:
logging.error('warning: fast open is not available')
self.socket.listen(self.request_queue_size)
def get_request(self):
connection = self.socket.accept()
connection[0].settimeout(config_timeout)
return connection
class Socks5Server(SocketServer.StreamRequestHandler):
def handle_tcp(self, sock, remote):
try:
fdset = [sock, remote]
while True:
should_break = False
r, w, e = select.select(fdset, [], [], config_timeout)
if not r:
logging.warn('read time out')
break
if sock in r:
data = self.decrypt(sock.recv(4096))
if len(data) <= 0:
should_break = True
else:
result = send_all(remote, data)
if result < len(data):
raise Exception('failed to send all data')
if remote in r:
data = self.encrypt(remote.recv(4096))
if len(data) <= 0:
should_break = True
else:
result = send_all(sock, data)
if result < len(data):
raise Exception('failed to send all data')
if should_break:
# make sure all data are read before we close the sockets
# TODO: we haven't read ALL the data, actually
# http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/TCPRST.pdf
break
finally:
sock.close()
remote.close()
def encrypt(self, data):
return self.encryptor.encrypt(data)
def decrypt(self, data):
return self.encryptor.decrypt(data)
def handle(self):
try:
self.encryptor = encrypt.Encryptor(self.server.key,
self.server.method)
sock = self.connection
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
iv_len = self.encryptor.iv_len()
data = sock.recv(iv_len)
if iv_len > 0 and not data:
sock.close()
return
if iv_len:
self.decrypt(data)
data = sock.recv(1)
if not data:
sock.close()
return
addrtype = ord(self.decrypt(data))
if addrtype == 1:
addr = socket.inet_ntoa(self.decrypt(self.rfile.read(4)))
elif addrtype == 3:
addr = self.decrypt(
self.rfile.read(ord(self.decrypt(sock.recv(1)))))
elif addrtype == 4:
addr = socket.inet_ntop(socket.AF_INET6,
self.decrypt(self.rfile.read(16)))
else:
# not supported
logging.warn('addr_type not supported, maybe wrong password')
return
port = struct.unpack('>H', self.decrypt(self.rfile.read(2)))
try:
logging.info('connecting %s:%d' % (addr, port[0]))
remote = socket.create_connection((addr, port[0]),
timeout=config_timeout)
remote.settimeout(config_timeout)
remote.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
except socket.error, e:
# Connection refused
logging.warn(e)
return
self.handle_tcp(sock, remote)
except socket.error, e:
logging.warn(e)
def main():
global config_server, config_server_port, config_method, config_fast_open, \
config_timeout
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
version = ''
try:
import pkg_resources
version = pkg_resources.get_distribution('shadowsocks').version
except:
pass
print 'shadowsocks %s' % version
config_path = utils.find_config()
try:
optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:t:',
['fast-open', 'workers:'])
for key, value in optlist:
if key == '-c':
config_path = value
if config_path:
logging.info('loading config from %s' % config_path)
with open(config_path, 'rb') as f:
try:
config = json.load(f)
except ValueError as e:
logging.error('found an error in config.json: %s',
e.message)
sys.exit(1)
else:
config = {}
optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:t:',
['fast-open', 'workers='])
for key, value in optlist:
if key == '-p':
config['server_port'] = int(value)
elif key == '-k':
config['password'] = value
elif key == '-s':
config['server'] = value
elif key == '-m':
config['method'] = value
elif key == '-t':
config['timeout'] = value
elif key == '--fast-open':
config['fast_open'] = True
elif key == '--workers':
config['workers'] = value
except getopt.GetoptError:
utils.print_server_help()
sys.exit(2)
config_server = config['server']
config_server_port = config['server_port']
config_key = config['password']
config_method = config.get('method', None)
config_port_password = config.get('port_password', None)
config_timeout = int(config.get('timeout', 300))
config_fast_open = config.get('fast_open', False)
config_workers = config.get('workers', 1)
if not config_key and not config_path:
sys.exit('config not specified, please read '
'https://github.com/clowwindy/shadowsocks')
utils.check_config(config)
if config_port_password:
if config_server_port or config_key:
logging.warn('warning: port_password should not be used with '
'server_port and password. server_port and password '
'will be ignored')
else:
config_port_password = {}
config_port_password[str(config_server_port)] = config_key
encrypt.init_table(config_key, config_method)
addrs = socket.getaddrinfo(config_server, int(8387))
if not addrs:
logging.error('cant resolve listen address')
sys.exit(1)
ThreadingTCPServer.address_family = addrs[0][0]
tcp_servers = []
udp_servers = []
for port, key in config_port_password.items():
tcp_server = ThreadingTCPServer((config_server, int(port)),
Socks5Server)
tcp_server.key = key
tcp_server.method = config_method
tcp_server.timeout = int(config_timeout)
logging.info("starting server at %s:%d" %
tuple(tcp_server.server_address[:2]))
tcp_servers.append(tcp_server)
udp_server = udprelay.UDPRelay(config_server, int(port), None, None,
key, config_method, int(config_timeout),
False)
udp_servers.append(udp_server)
def run_server():
for tcp_server in tcp_servers:
threading.Thread(target=tcp_server.serve_forever).start()
for udp_server in udp_servers:
udp_server.start()
if int(config_workers) > 1:
if os.name == 'posix':
children = []
is_child = False
for i in xrange(0, int(config_workers)):
r = os.fork()
if r == 0:
logging.info('worker started')
is_child = True
run_server()
break
else:
children.append(r)
if not is_child:
def handler(signum, frame):
for pid in children:
os.kill(pid, signum)
os.waitpid(pid, 0)
sys.exit()
import signal
signal.signal(signal.SIGTERM, handler)
# master
for tcp_server in tcp_servers:
tcp_server.server_close()
for udp_server in udp_servers:
udp_server.close()
for child in children:
os.waitpid(child, 0)
else:
logging.warn('worker is only available on Unix/Linux')
run_server()
else:
run_server()
if __name__ == '__main__':
try:
main()
except socket.error, e:
logging.error(e)

@ -1,291 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# 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.
# SOCKS5 UDP Request
# +----+------+------+----------+----------+----------+
# |RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
# +----+------+------+----------+----------+----------+
# | 2 | 1 | 1 | Variable | 2 | Variable |
# +----+------+------+----------+----------+----------+
# SOCKS5 UDP Response
# +----+------+------+----------+----------+----------+
# |RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
# +----+------+------+----------+----------+----------+
# | 2 | 1 | 1 | Variable | 2 | Variable |
# +----+------+------+----------+----------+----------+
# shadowsocks UDP Request (before encrypted)
# +------+----------+----------+----------+
# | ATYP | DST.ADDR | DST.PORT | DATA |
# +------+----------+----------+----------+
# | 1 | Variable | 2 | Variable |
# +------+----------+----------+----------+
# shadowsocks UDP Response (before encrypted)
# +------+----------+----------+----------+
# | ATYP | DST.ADDR | DST.PORT | DATA |
# +------+----------+----------+----------+
# | 1 | Variable | 2 | Variable |
# +------+----------+----------+----------+
# shadowsocks UDP Request and Response (after encrypted)
# +-------+--------------+
# | IV | PAYLOAD |
# +-------+--------------+
# | Fixed | Variable |
# +-------+--------------+
# HOW TO NAME THINGS
# ------------------
# `dest` means destination server, which is from DST fields in the SOCKS5
# request
# `local` means local server of shadowsocks
# `remote` means remote server of shadowsocks
# `client` means UDP clients that connects to other servers
# `server` means the UDP server that handles user requests
import time
import threading
import socket
import logging
import struct
import encrypt
import eventloop
import lru_cache
import errno
BUF_SIZE = 65536
def parse_header(data):
addrtype = ord(data[0])
dest_addr = None
dest_port = None
header_length = 0
if addrtype == 1:
if len(data) >= 7:
dest_addr = socket.inet_ntoa(data[1:5])
dest_port = struct.unpack('>H', data[5:7])[0]
header_length = 7
else:
logging.warn('[udp] header is too short')
elif addrtype == 3:
if len(data) > 2:
addrlen = ord(data[1])
if len(data) >= 2 + addrlen:
dest_addr = data[2:2 + addrlen]
dest_port = struct.unpack('>H', data[2 + addrlen:4 +
addrlen])[0]
header_length = 4 + addrlen
else:
logging.warn('[udp] header is too short')
else:
logging.warn('[udp] header is too short')
elif addrtype == 4:
if len(data) >= 19:
dest_addr = socket.inet_ntop(socket.AF_INET6, data[1:17])
dest_port = struct.unpack('>H', data[17:19])[0]
header_length = 19
else:
logging.warn('[udp] header is too short')
else:
logging.warn('unsupported addrtype %d' % addrtype)
if dest_addr is None:
return None
return (addrtype, dest_addr, dest_port, header_length)
def client_key(a, b, c, d):
return '%s:%s:%s:%s' % (a, b, c, d)
class UDPRelay(object):
def __init__(self, listen_addr='127.0.0.1', listen_port=1080,
remote_addr='127.0.0.1', remote_port=8387, password=None,
method='table', timeout=300, is_local=True):
self._listen_addr = listen_addr
self._listen_port = listen_port
self._remote_addr = remote_addr
self._remote_port = remote_port
self._password = password
self._method = method
self._timeout = timeout
self._is_local = is_local
self._cache = lru_cache.LRUCache(timeout=timeout,
close_callback=self._close_client)
self._client_fd_to_server_addr = lru_cache.LRUCache(timeout=timeout)
self._closed = False
addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0,
socket.SOCK_DGRAM, socket.SOL_UDP)
if len(addrs) == 0:
raise Exception("can't get addrinfo for %s:%d" %
(self._listen_addr, self._listen_port))
af, socktype, proto, canonname, sa = addrs[0]
server_socket = socket.socket(af, socktype, proto)
server_socket.bind((self._listen_addr, self._listen_port))
server_socket.setblocking(False)
self._server_socket = server_socket
def _close_client(self, client):
if hasattr(client, 'close'):
self._eventloop.remove(client)
client.close()
else:
# just an address
pass
def _handle_server(self):
server = self._server_socket
data, r_addr = server.recvfrom(BUF_SIZE)
if self._is_local:
frag = ord(data[2])
if frag != 0:
logging.warn('drop a message since frag is not 0')
return
else:
data = data[3:]
else:
# decrypt data
data = encrypt.encrypt_all(self._password, self._method, 0, data)
if not data:
return
header_result = parse_header(data)
if header_result is None:
return
addrtype, dest_addr, dest_port, header_length = header_result
if self._is_local:
server_addr, server_port = self._remote_addr, self._remote_port
else:
server_addr, server_port = dest_addr, dest_port
key = client_key(r_addr[0], r_addr[1], dest_addr, dest_port)
client = self._cache.get(key, None)
if not client:
# TODO async getaddrinfo
addrs = socket.getaddrinfo(server_addr, server_port, 0,
socket.SOCK_DGRAM, socket.SOL_UDP)
if addrs:
af, socktype, proto, canonname, sa = addrs[0]
client = socket.socket(af, socktype, proto)
client.setblocking(False)
self._cache[key] = client
self._client_fd_to_server_addr[client.fileno()] = r_addr
else:
# drop
return
self._eventloop.add(client, eventloop.POLL_IN)
data = data[header_length:]
if not data:
return
if self._is_local:
data = encrypt.encrypt_all(self._password, self._method, 1, data)
if not data:
return
try:
client.sendto(data, (server_addr, server_port))
except IOError as e:
err = eventloop.errno_from_exception(e)
if err in (errno.EINPROGRESS, errno.EAGAIN):
pass
else:
logging.error(e)
def _handle_client(self, sock):
data, r_addr = sock.recvfrom(BUF_SIZE)
if not self._is_local:
addrlen = len(r_addr[0])
if addrlen > 255:
# drop
return
data = '\x03' + chr(addrlen) + r_addr[0] + \
struct.pack('>H', r_addr[1]) + data
response = encrypt.encrypt_all(self._password, self._method, 1,
data)
if not response:
return
else:
data = encrypt.encrypt_all(self._password, self._method, 0,
data)
if not data:
return
header_result = parse_header(data)
if header_result is None:
return
# addrtype, dest_addr, dest_port, header_length = header_result
response = '\x00\x00\x00' + data
client_addr = self._client_fd_to_server_addr.get(sock.fileno(), None)
if client_addr:
self._server_socket.sendto(response, client_addr)
else:
# this packet is from somewhere else we know
# simply drop that packet
pass
def _run(self):
server_socket = self._server_socket
self._eventloop = eventloop.EventLoop()
self._eventloop.add(server_socket, eventloop.POLL_IN)
last_time = time.time()
while not self._closed:
try:
events = self._eventloop.poll(10)
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) == errno.EPIPE:
# Happens when the client closes the connection
continue
else:
logging.error(e)
continue
for sock, event in events:
if sock == self._server_socket:
self._handle_server()
else:
self._handle_client(sock)
now = time.time()
if now - last_time > 3.5:
self._cache.sweep()
if now - last_time > 7:
self._client_fd_to_server_addr.sweep()
last_time = now
def start(self):
if self._closed:
raise Exception('closed')
t = threading.Thread(target=self._run)
t.setName('UDPThread')
t.setDaemon(False)
t.start()
self._thread = t
def close(self):
self._closed = True
self._server_socket.close()
def thread(self):
return self._thread

@ -1,132 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# 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 os
import socket
import logging
def inet_ntop(family, ipstr):
if family == socket.AF_INET:
return socket.inet_ntoa(ipstr)
elif family == socket.AF_INET6:
v6addr = ':'.join(('%02X%02X' % (ord(i), ord(j)))
for i, j in zip(ipstr[::2], ipstr[1::2]))
return v6addr
def inet_pton(family, addr):
if family == socket.AF_INET:
return socket.inet_aton(addr)
elif family == socket.AF_INET6:
if '.' in addr: # a v4 addr
v4addr = addr[addr.rindex(':') + 1:]
v4addr = socket.inet_aton(v4addr)
v4addr = map(lambda x: ('%02X' % ord(x)), v4addr)
v4addr.insert(2, ':')
newaddr = addr[:addr.rindex(':') + 1] + ''.join(v4addr)
return inet_pton(family, newaddr)
dbyts = [0] * 8 # 8 groups
grps = addr.split(':')
for i, v in enumerate(grps):
if v:
dbyts[i] = int(v, 16)
else:
for j, w in enumerate(grps[::-1]):
if w:
dbyts[7 - j] = int(w, 16)
else:
break
break
return ''.join((chr(i // 256) + chr(i % 256)) for i in dbyts)
else:
raise RuntimeError("What family?")
if not hasattr(socket, 'inet_pton'):
socket.inet_pton = inet_pton
if not hasattr(socket, 'inet_ntop'):
socket.inet_ntop = inet_ntop
def find_config():
config_path = 'config.json'
if os.path.exists(config_path):
return config_path
config_path = os.path.join(os.path.dirname(__file__), '../', 'config.json')
if os.path.exists(config_path):
return config_path
return None
def check_config(config):
if config.get('local_address', '') in ['0.0.0.0']:
logging.warn('warning: local set to listen 0.0.0.0, which is not safe')
if config.get('server', '') in ['127.0.0.1', 'localhost']:
logging.warn('warning: server set to listen %s:%s, are you sure?' %
(config['server'], config['server_port']))
if (config.get('method', '') or '').lower() == 'rc4':
logging.warn('warning: RC4 is not safe; please use a safer cipher, '
'like AES-256-CFB')
if (int(config.get('timeout', 300)) or 300) < 100:
logging.warn('warning: your timeout %d seems too short' %
int(config.get('timeout')))
if (int(config.get('timeout', 300)) or 300) > 600:
logging.warn('warning: your timeout %d seems too long' %
int(config.get('timeout')))
def print_local_help():
print '''usage: sslocal [-h] -s SERVER_ADDR -p SERVER_PORT [-b LOCAL_ADDR]
-l LOCAL_PORT -k PASSWORD -m METHOD [-t TIMEOUT] [-c CONFIG]
[--fast-open]
optional arguments:
-h, --help show this help message and exit
-s SERVER_ADDR server address
-p SERVER_PORT server port
-b LOCAL_ADDR local binding address, default is 127.0.0.1
-l LOCAL_PORT local port
-k PASSWORD password
-m METHOD encryption method, for example, aes-256-cfb
-t TIMEOUT timeout in seconds
-c CONFIG path to config file
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
'''
def print_server_help():
print '''usage: ssserver [-h] -s SERVER_ADDR -p SERVER_PORT -k PASSWORD
-m METHOD [-t TIMEOUT] [-c CONFIG] [--fast-open]
optional arguments:
-h, --help show this help message and exit
-s SERVER_ADDR server address
-p SERVER_PORT server port
-k PASSWORD password
-m METHOD encryption method, for example, aes-256-cfb
-t TIMEOUT timeout in seconds
-c CONFIG path to config file
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
--workers WORKERS number of workers, available on Unix/Linux
'''

@ -1,131 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import signal
import sys
import select
import struct
import hashlib
import string
import time
from subprocess import Popen, PIPE
target1 = [
[60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181, 255, 143, 83, 247, 162, 16, 31, 209, 190,
171, 115, 65, 38, 41, 21, 245, 236, 46, 121, 62, 166, 233, 44, 154, 153, 145, 230, 49, 128, 216, 173, 29, 241, 119,
64, 229, 194, 103, 131, 110, 26, 197, 218, 59, 204, 56, 27, 34, 141, 221, 149, 239, 192, 195, 24, 155, 170, 183, 11
, 254, 213, 37, 137, 226, 75, 203, 55, 19, 72, 248, 22, 129, 33, 175, 178, 10, 198, 71, 77, 36, 113, 167, 48, 2,
117, 140, 142, 66, 199, 232, 243, 32, 123, 54, 51, 82, 57, 177, 87, 251, 150, 196, 133, 5, 253, 130, 8, 184, 14,
152, 231, 3, 186, 159, 76, 89, 228, 205, 156, 96, 163, 146, 18, 91, 132, 85, 80, 109, 172, 176, 105, 13, 50, 235,
127, 0, 189, 95, 98, 136, 250, 200, 108, 179, 211, 214, 106, 168, 78, 79, 74, 210, 30, 73, 201, 151, 208, 114, 101,
174, 92, 52, 120, 240, 15, 169, 220, 182, 81, 224, 43, 185, 40, 99, 180, 17, 212, 158, 42, 90, 9, 191, 45, 6, 25, 4
, 222, 67, 126, 1, 116, 124, 206, 69, 61, 7, 68, 97, 202, 63, 244, 20, 28, 58, 93, 134, 104, 144, 227, 147, 102,
118, 135, 148, 47, 238, 86, 112, 122, 70, 107, 215, 100, 139, 223, 225, 164, 237, 111, 125, 207, 160, 187, 246, 234
, 161, 188, 193, 249, 252],
[151, 205, 99, 127, 201, 119, 199, 211, 122, 196, 91, 74, 12, 147, 124, 180, 21, 191, 138, 83, 217, 30, 86, 7, 70,
200, 56, 62, 218, 47, 168, 22, 107, 88, 63, 11, 95, 77, 28, 8, 188, 29, 194, 186, 38, 198, 33, 230, 98, 43, 148,
110, 177, 1, 109, 82, 61, 112, 219, 59, 0, 210, 35, 215, 50, 27, 103, 203, 212, 209, 235, 93, 84, 169, 166, 80, 130
, 94, 164, 165, 142, 184, 111, 18, 2, 141, 232, 114, 6, 131, 195, 139, 176, 220, 5, 153, 135, 213, 154, 189, 238
, 174, 226, 53, 222, 146, 162, 236, 158, 143, 55, 244, 233, 96, 173, 26, 206, 100, 227, 49, 178, 34, 234, 108,
207, 245, 204, 150, 44, 87, 121, 54, 140, 118, 221, 228, 155, 78, 3, 239, 101, 64, 102, 17, 223, 41, 137, 225, 229,
66, 116, 171, 125, 40, 39, 71, 134, 13, 193, 129, 247, 251, 20, 136, 242, 14, 36, 97, 163, 181, 72, 25, 144, 46,
175, 89, 145, 113, 90, 159, 190, 15, 183, 73, 123, 187, 128, 248, 252, 152, 24, 197, 68, 253, 52, 69, 117, 57, 92,
104, 157, 170, 214, 81, 60, 133, 208, 246, 172, 23, 167, 160, 192, 76, 161, 237, 45, 4, 58, 10, 182, 65, 202, 240,
185, 241, 79, 224, 132, 51, 42, 126, 105, 37, 250, 149, 32, 243, 231, 67, 179, 48, 9, 106, 216, 31, 249, 19, 85,
254, 156, 115, 255, 120, 75, 16]]
target2 = [
[124, 30, 170, 247, 27, 127, 224, 59, 13, 22, 196, 76, 72, 154, 32, 209, 4, 2, 131, 62, 101, 51, 230, 9, 166, 11, 99
, 80, 208, 112, 36, 248, 81, 102, 130, 88, 218, 38, 168, 15, 241, 228, 167, 117, 158, 41, 10, 180, 194, 50, 204,
243, 246, 251, 29, 198, 219, 210, 195, 21, 54, 91, 203, 221, 70, 57, 183, 17, 147, 49, 133, 65, 77, 55, 202, 122,
162, 169, 188, 200, 190, 125, 63, 244, 96, 31, 107, 106, 74, 143, 116, 148, 78, 46, 1, 137, 150, 110, 181, 56, 95,
139, 58, 3, 231, 66, 165, 142, 242, 43, 192, 157, 89, 175, 109, 220, 128, 0, 178, 42, 255, 20, 214, 185, 83, 160,
253, 7, 23, 92, 111, 153, 26, 226, 33, 176, 144, 18, 216, 212, 28, 151, 71, 206, 222, 182, 8, 174, 205, 201, 152,
240, 155, 108, 223, 104, 239, 98, 164, 211, 184, 34, 193, 14, 114, 187, 40, 254, 12, 67, 93, 217, 6, 94, 16, 19, 82
, 86, 245, 24, 197, 134, 132, 138, 229, 121, 5, 235, 238, 85, 47, 103, 113, 179, 69, 250, 45, 135, 156, 25, 61,
75, 44, 146, 189, 84, 207, 172, 119, 53, 123, 186, 120, 171, 68, 227, 145, 136, 100, 90, 48, 79, 159, 149, 39, 213,
236, 126, 52, 60, 225, 199, 105, 73, 233, 252, 118, 215, 35, 115, 64, 37, 97, 129, 161, 177, 87, 237, 141, 173, 191
, 163, 140, 234, 232, 249],
[117, 94, 17, 103, 16, 186, 172, 127, 146, 23, 46, 25, 168, 8, 163, 39, 174, 67, 137, 175, 121, 59, 9, 128, 179, 199
, 132, 4, 140, 54, 1, 85, 14, 134, 161, 238, 30, 241, 37, 224, 166, 45, 119, 109, 202, 196, 93, 190, 220, 69, 49
, 21, 228, 209, 60, 73, 99, 65, 102, 7, 229, 200, 19, 82, 240, 71, 105, 169, 214, 194, 64, 142, 12, 233, 88, 201
, 11, 72, 92, 221, 27, 32, 176, 124, 205, 189, 177, 246, 35, 112, 219, 61, 129, 170, 173, 100, 84, 242, 157, 26,
218, 20, 33, 191, 155, 232, 87, 86, 153, 114, 97, 130, 29, 192, 164, 239, 90, 43, 236, 208, 212, 185, 75, 210, 0,
81, 227, 5, 116, 243, 34, 18, 182, 70, 181, 197, 217, 95, 183, 101, 252, 248, 107, 89, 136, 216, 203, 68, 91, 223,
96, 141, 150, 131, 13, 152, 198, 111, 44, 222, 125, 244, 76, 251, 158, 106, 24, 42, 38, 77, 2, 213, 207, 249, 147,
113, 135, 245, 118, 193, 47, 98, 145, 66, 160, 123, 211, 165, 78, 204, 80, 250, 110, 162, 48, 58, 10, 180, 55, 231,
79, 149, 74, 62, 50, 148, 143, 206, 28, 15, 57, 159, 139, 225, 122, 237, 138, 171, 36, 56, 115, 63, 144, 154, 6,
230, 133, 215, 41, 184, 22, 104, 254, 234, 253, 187, 226, 247, 188, 156, 151, 40, 108, 51, 83, 178, 52, 3, 31, 255,
195, 53, 235, 126, 167, 120]]
def get_table(key):
m = hashlib.md5()
m.update(key)
s = m.digest()
(a, b) = struct.unpack('<QQ', s)
table = [c for c in string.maketrans('', '')]
for i in xrange(1, 1024):
table.sort(lambda x, y: int(a % (ord(x) + i) - a % (ord(y) + i)))
return table
encrypt_table = ''.join(get_table('foobar!'))
decrypt_table = string.maketrans(encrypt_table, string.maketrans('', ''))
for i in range(0, 256):
assert(target1[0][i] == ord(encrypt_table[i]))
assert(target1[1][i] == ord(decrypt_table[i]))
encrypt_table = ''.join(get_table('barfoo!'))
decrypt_table = string.maketrans(encrypt_table, string.maketrans('', ''))
for i in range(0, 256):
assert(target2[0][i] == ord(encrypt_table[i]))
assert(target2[1][i] == ord(decrypt_table[i]))
p1 = Popen(['python', 'shadowsocks/server.py', '-c', sys.argv[-1]], shell=False, bufsize=0, stdin=PIPE,
stdout=PIPE, stderr=PIPE, close_fds=True)
p2 = Popen(['python', 'shadowsocks/local.py', '-c', sys.argv[-1]], shell=False, bufsize=0, stdin=PIPE,
stdout=PIPE, stderr=PIPE, close_fds=True)
p3 = None
print 'encryption test passed'
try:
local_ready = False
server_ready = False
fdset = [p1.stdout, p2.stdout, p1.stderr, p2.stderr]
while True:
r, w, e = select.select(fdset, [], fdset)
if e:
break
for fd in r:
line = fd.readline()
sys.stdout.write(line)
if line.find('starting local') >= 0:
local_ready = True
if line.find('starting server') >= 0:
server_ready = True
if local_ready and server_ready and p3 is None:
time.sleep(1)
p3 = Popen(['curl', 'http://www.example.com/', '-v', '-L',
'--socks5-hostname', '127.0.0.1:1080'], shell=False,
bufsize=0, close_fds=True)
break
if p3 is not None:
r = p3.wait()
if r == 0:
print 'test passed'
sys.exit(r)
finally:
for p in [p1, p2]:
try:
os.kill(p.pid, signal.SIGTERM)
except OSError:
pass
sys.exit(-1)

@ -1,10 +0,0 @@
{
"server":"127.0.0.1",
"server_port":8388,
"local_port":1080,
"password":"barfoo!",
"timeout":300,
"method":"aes-256-cfb",
"local_address":"127.0.0.1",
"fast_open":false
}

@ -1,10 +0,0 @@
{
"server":"127.0.0.1",
"server_port":8388,
"local_port":1080,
"password":"barfoo!",
"timeout":300,
"method":"salsa20-ctr",
"local_address":"127.0.0.1",
"fast_open":false
}

@ -1,22 +0,0 @@
{
"server": "127.0.0.1",
"server_port": 8384,
"local_port": 1080,
"password": "foobar4",
"port_password": {
"8381": "foobar1",
"8382": "foobar2",
"8383": "foobar3",
"8384": "foobar4",
"8385": "foobar5",
"8386": "foobar6",
"8387": "foobar7",
"8388": "foobar8",
"8389": "foobar9",
"8390": "foobar10",
"8391": "foobar11",
"8392": "foobar12"
},
"timeout": 60,
"method": "aes-256-cfb"
}

@ -1,10 +0,0 @@
{
"server":"127.0.0.1",
"server_port":8388,
"local_port":1080,
"password":"barfoo!",
"timeout":300,
"method":"table",
"local_address":"127.0.0.1",
"fast_open":false
}

@ -1,10 +0,0 @@
{
"server":"127.0.0.1",
"server_port":8388,
"local_port":1080,
"password":"barfoo!",
"timeout":300,
"method":"aes-256-cfb",
"local_address":"127.0.0.1",
"workers": 4
}

@ -1,13 +0,0 @@
#!/usr/bin/python
import sys
import time
before = time.time()
for line in sys.stdin:
if 'HTTP/1.1 ' in line:
diff = time.time() - before
print 'headline %dms' % (diff * 1000)
Loading…
Cancel
Save