Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
271 additions
and 104 deletions.
- +21 −0 scripts/codegen.py
- +15 −10 txsocksx/auth.py
- +56 −14 txsocksx/errors.py
- +73 −53 txsocksx/parser.py
- +106 −27 txsocksx/test/test_parser.py
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -0,0 +1,21 @@ | ||
|
|
||
|
|
||
| def makeTestFailure(): | ||
| l = ['ServerFailure', | ||
| 'ConnectionNotAllowed', | ||
| 'NetworkUnreachable', | ||
| 'HostUnreachable', | ||
| 'ConnectionRefused', | ||
| 'TTLExpired', | ||
| 'CommandNotSupported', | ||
| 'AddressNotSupported'] | ||
|
|
||
| base = """ | ||
| def test_ServerReply%(error_name)s(self): | ||
| p = SOCKSGrammar(dummyServerReplyFail%(idx)sIPV4) | ||
| failure, addr, port = p.serverReply() | ||
| self.assertIs(failure, e.%(error_name)s) | ||
| """ | ||
| for i, v in enumerate(l): | ||
| print base % {'idx': i+1, 'error_name': v} | ||
| makeTestFailure() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -1,28 +1,33 @@ | ||
| from twisted.internet import defer | ||
| from txsocksx.errors import SocksError | ||
| from txsocksx.errors import SOCKSError | ||
|
|
||
| class Anonymous(object): | ||
| method = '\x00' | ||
| """ | ||
| ( 0 ) | ||
| """ | ||
| def negotiate(self, proto): | ||
| pass | ||
|
|
||
| class GSSAPI(object): | ||
| """ | ||
| ( 1 ) | ||
| """ | ||
| def negotiate(self, proto): | ||
| return defer.succeed(None) | ||
| raise NotImplemented | ||
|
|
||
| class UsernamePasswordAuthFailed(SocksError): | ||
| class UsernamePasswordAuthFailed(SOCKSError): | ||
| pass | ||
|
|
||
| class UsernamePassword(object): | ||
| method = '\x02' | ||
|
|
||
| """ | ||
| ( 2 ) | ||
| """ | ||
| def __init__(self, uname, passwd): | ||
| self.uname = uname | ||
| self.passwd = passwd | ||
|
|
||
| @defer.inlineCallbacks | ||
| def negotiate(self, proto): | ||
| proto.transport.write( | ||
| '\x01' | ||
| + chr(len(self.uname)) + self.uname | ||
| + chr(len(self.passwd)) + self.passwd) | ||
| resp, = yield proto.unpack('!xB') | ||
| if resp != 0: | ||
| raise UsernamePasswordAuthFailed(resp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -1,25 +1,67 @@ | ||
| from twisted.internet import error | ||
| import txsocksx.constants as c | ||
|
|
||
| class SocksError(Exception): | ||
| class SOCKSError(Exception): | ||
| pass | ||
|
|
||
| class MethodsNotAcceptedError(SocksError): | ||
| class MethodsNotAcceptedError(SOCKSError): | ||
| pass | ||
|
|
||
| class ConnectionError(SocksError): | ||
| class ConnectionError(SOCKSError): | ||
| pass | ||
|
|
||
| class ConnectionLostEarly(SocksError, error.ConnectionLost): | ||
| class ConnectionLostEarly(SOCKSError, error.ConnectionLost): | ||
| pass | ||
|
|
||
| socks5ErrorMap = { | ||
| c.SOCKS5_GENERAL_FAILURE: "general SOCKS server failure", | ||
| c.SOCKS5_REJECTED: "connection not allowed by ruleset", | ||
| c.SOCKS5_NETWORK_UNREACHABLE: "network unreachable", | ||
| c.SOCKS5_HOST_UNREACHABLE: "host unreachable", | ||
| c.SOCKS5_CONNECTION_REFUSED: "connection refused", | ||
| c.SOCKS5_TTL_EXPIRED: "TTL expired", | ||
| c.SOCKS5_COMMAND_NOT_SUPPORTED: "command not supported", | ||
| c.SOCKS5_ADDRESS_NOT_SUPPORTED: "address type not supported", | ||
| } | ||
| class StateError(Exception): | ||
| """ | ||
| There was a problem with the State. | ||
| """ | ||
| pass | ||
|
|
||
| class NoAcceptableMethods(SOCKSError): | ||
| """ | ||
| No Acceptable Methods ( FF ) | ||
| """ | ||
|
|
||
| class ServerFailure(SOCKSError): | ||
| """ | ||
| General SOCKS server failure ( 1 ) | ||
| """ | ||
|
|
||
| class ConnectionNotAllowed(SOCKSError): | ||
| """ | ||
| Connection not allowed ( 2 ) | ||
| """ | ||
|
|
||
| class NetworkUnreachable(SOCKSError): | ||
| """ | ||
| Network unreachable ( 3 ) | ||
| """ | ||
|
|
||
| class HostUnreachable(SOCKSError): | ||
| """ | ||
| Host unreachable ( 4 ) | ||
| """ | ||
|
|
||
| class ConnectionRefused(SOCKSError): | ||
| """ | ||
| Connection refused ( 5 ) | ||
| """ | ||
|
|
||
| class TTLExpired(SOCKSError): | ||
| """ | ||
| TTL expired ( 6 ) | ||
| """ | ||
|
|
||
| class CommandNotSupported(SOCKSError): | ||
| """ | ||
| Command Not Supported ( 7 ) | ||
| """ | ||
|
|
||
| class AddressNotSupported(SOCKSError): | ||
| """ | ||
| Address type not supported ( 8 ) | ||
| """ | ||
|
|
||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.