Compare commits
4 Commits
v0.6
...
omkar1117/
Author | SHA1 | Date | |
---|---|---|---|
|
c2c7f674a0 | ||
|
43e1c0149b | ||
|
d0c115ed57 | ||
|
408c033338 |
|
@ -15,9 +15,9 @@ from fabvenv import virtualenv
|
||||||
|
|
||||||
|
|
||||||
FABRIC_ROOT = os.path.dirname(__file__)
|
FABRIC_ROOT = os.path.dirname(__file__)
|
||||||
PROJECT_ROOT = os.path.dirname(FABRIC_ROOT)
|
project_root = os.path.dirname(FABRIC_ROOT)
|
||||||
VENV_ROOT = os.path.expanduser(os.path.join('~', '.virtualenvs', 'pybitmessage-devops'))
|
VENV_ROOT = os.path.expanduser(os.path.join('~', '.virtualenvs', 'pybitmessage-devops'))
|
||||||
PYTHONPATH = os.path.join(PROJECT_ROOT, 'src',)
|
PYTHONPATH = os.path.join(project_root, 'src',)
|
||||||
|
|
||||||
|
|
||||||
def coerce_list(value):
|
def coerce_list(value):
|
||||||
|
@ -72,7 +72,7 @@ def filelist_from_git(rev=None):
|
||||||
else:
|
else:
|
||||||
cmd += ' -r {}'.format(rev)
|
cmd += ' -r {}'.format(rev)
|
||||||
|
|
||||||
with cd(PROJECT_ROOT):
|
with cd(project_root):
|
||||||
with hide('running', 'stdout'):
|
with hide('running', 'stdout'):
|
||||||
results = []
|
results = []
|
||||||
ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
|
ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
|
||||||
|
@ -92,7 +92,7 @@ def pycodestyle(path_to_file):
|
||||||
return run(
|
return run(
|
||||||
'pycodestyle --config={0} {1}'.format(
|
'pycodestyle --config={0} {1}'.format(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
PROJECT_ROOT,
|
project_root,
|
||||||
'setup.cfg',
|
'setup.cfg',
|
||||||
),
|
),
|
||||||
path_to_file,
|
path_to_file,
|
||||||
|
@ -108,7 +108,7 @@ def flake8(path_to_file):
|
||||||
return run(
|
return run(
|
||||||
'flake8 --config={0} {1}'.format(
|
'flake8 --config={0} {1}'.format(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
PROJECT_ROOT,
|
project_root,
|
||||||
'setup.cfg',
|
'setup.cfg',
|
||||||
),
|
),
|
||||||
path_to_file,
|
path_to_file,
|
||||||
|
@ -125,7 +125,7 @@ def pylint(path_to_file):
|
||||||
return run(
|
return run(
|
||||||
'pylint --rcfile={0} {1}'.format(
|
'pylint --rcfile={0} {1}'.format(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
PROJECT_ROOT,
|
project_root,
|
||||||
'setup.cfg',
|
'setup.cfg',
|
||||||
),
|
),
|
||||||
path_to_file,
|
path_to_file,
|
||||||
|
|
|
@ -15,7 +15,7 @@ from fabric.contrib.project import rsync_project
|
||||||
from fabvenv import virtualenv
|
from fabvenv import virtualenv
|
||||||
|
|
||||||
from fabfile.lib import (
|
from fabfile.lib import (
|
||||||
autopep8, PROJECT_ROOT, VENV_ROOT, coerce_bool, flatten, filelist_from_git, default_hosts,
|
autopep8, project_root, VENV_ROOT, coerce_bool, flatten, filelist_from_git, default_hosts,
|
||||||
get_filtered_pycodestyle_output, get_filtered_flake8_output, get_filtered_pylint_output,
|
get_filtered_pycodestyle_output, get_filtered_flake8_output, get_filtered_pylint_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,16 +28,18 @@ def get_tool_results(file_list):
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for path_to_file in file_list:
|
for path_to_file in file_list:
|
||||||
result = {}
|
result = {
|
||||||
result['pycodestyle_violations'] = get_filtered_pycodestyle_output(path_to_file)
|
'pycodestyle_violations': get_filtered_pycodestyle_output(path_to_file),
|
||||||
result['flake8_violations'] = get_filtered_flake8_output(path_to_file)
|
'flake8_violations': get_filtered_flake8_output(path_to_file),
|
||||||
result['pylint_violations'] = get_filtered_pylint_output(path_to_file)
|
'pylint_violations': get_filtered_pylint_output(path_to_file),
|
||||||
result['path_to_file'] = path_to_file
|
'path_to_file': path_to_file
|
||||||
|
}
|
||||||
result['total_violations'] = sum([
|
result['total_violations'] = sum([
|
||||||
len(result['pycodestyle_violations']),
|
len(result['pycodestyle_violations']),
|
||||||
len(result['flake8_violations']),
|
len(result['flake8_violations']),
|
||||||
len(result['pylint_violations']),
|
len(result['pylint_violations'])
|
||||||
])
|
])
|
||||||
|
|
||||||
results.append(result)
|
results.append(result)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
@ -46,13 +48,13 @@ def print_results(results, top, verbose, details):
|
||||||
"""Print an item with the appropriate verbosity / detail"""
|
"""Print an item with the appropriate verbosity / detail"""
|
||||||
|
|
||||||
if verbose and results:
|
if verbose and results:
|
||||||
print ''.join(
|
print(''.join(
|
||||||
[
|
[
|
||||||
os.linesep,
|
os.linesep,
|
||||||
'total pycodestyle flake8 pylint path_to_file',
|
'total pycodestyle flake8 pylint path_to_file',
|
||||||
os.linesep,
|
os.linesep,
|
||||||
]
|
]
|
||||||
)
|
))
|
||||||
|
|
||||||
for item in sort_and_slice(results, top):
|
for item in sort_and_slice(results, top):
|
||||||
|
|
||||||
|
@ -66,23 +68,23 @@ def print_results(results, top, verbose, details):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
line = item['path_to_file']
|
line = item['path_to_file']
|
||||||
print line
|
print(line)
|
||||||
|
|
||||||
if details:
|
if details:
|
||||||
print "pycodestyle:"
|
print("pycodestyle:")
|
||||||
for detail in flatten(item['pycodestyle_violations']):
|
for detail in flatten(item['pycodestyle_violations']):
|
||||||
print detail
|
print(detail)
|
||||||
print
|
print()
|
||||||
|
|
||||||
print "flake8:"
|
print("flake8:")
|
||||||
for detail in flatten(item['flake8_violations']):
|
for detail in flatten(item['flake8_violations']):
|
||||||
print detail
|
print(detail)
|
||||||
print
|
print()
|
||||||
|
|
||||||
print "pylint:"
|
print("pylint:")
|
||||||
for detail in flatten(item['pylint_violations']):
|
for detail in flatten(item['pylint_violations']):
|
||||||
print detail
|
print(detail)
|
||||||
print
|
print()
|
||||||
|
|
||||||
|
|
||||||
def sort_and_slice(results, top):
|
def sort_and_slice(results, top):
|
||||||
|
@ -107,13 +109,13 @@ def generate_file_list(filename):
|
||||||
if filename:
|
if filename:
|
||||||
filename = os.path.abspath(filename)
|
filename = os.path.abspath(filename)
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
print "Bad filename, specify a Python file"
|
print("Bad filename, specify a Python file")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
file_list = [filename]
|
file_list = [filename]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with cd(PROJECT_ROOT):
|
with cd(project_root):
|
||||||
file_list = [
|
file_list = [
|
||||||
os.path.abspath(i.rstrip('\r'))
|
os.path.abspath(i.rstrip('\r'))
|
||||||
for i in run('find . -name "*.py"').split(os.linesep)
|
for i in run('find . -name "*.py"').split(os.linesep)
|
||||||
|
@ -137,15 +139,15 @@ def create_dependency_graphs():
|
||||||
with hide('running', 'stdout'):
|
with hide('running', 'stdout'):
|
||||||
|
|
||||||
# .. todo:: consider a better place to put this, use a particular commit
|
# .. todo:: consider a better place to put this, use a particular commit
|
||||||
with cd(PROJECT_ROOT):
|
with cd(project_root):
|
||||||
with settings(warn_only=True):
|
with settings(warn_only=True):
|
||||||
if run('stat pyan').return_code:
|
if run('stat pyan').return_code:
|
||||||
run('git clone https://github.com/davidfraser/pyan.git')
|
run('git clone https://github.com/davidfraser/pyan.git')
|
||||||
with cd(os.path.join(PROJECT_ROOT, 'pyan')):
|
with cd(os.path.join(project_root, 'pyan')):
|
||||||
run('git checkout pre-python3')
|
run('git checkout pre-python3')
|
||||||
|
|
||||||
# .. todo:: Use better settings. This is MVP to make a diagram
|
# .. todo:: Use better settings. This is MVP to make a diagram
|
||||||
with cd(PROJECT_ROOT):
|
with cd(project_root):
|
||||||
file_list = run("find . -type f -name '*.py' ! -path './src/.eggs/*'").split('\r\n')
|
file_list = run("find . -type f -name '*.py' ! -path './src/.eggs/*'").split('\r\n')
|
||||||
for cmd in [
|
for cmd in [
|
||||||
'neato -Goverlap=false -Tpng > deps-neato.png',
|
'neato -Goverlap=false -Tpng > deps-neato.png',
|
||||||
|
@ -215,7 +217,7 @@ def code_quality(verbose=True, details=False, fix=False, filename=None, top=10,
|
||||||
def test():
|
def test():
|
||||||
"""Run tests on the code"""
|
"""Run tests on the code"""
|
||||||
|
|
||||||
with cd(PROJECT_ROOT):
|
with cd(project_root):
|
||||||
with virtualenv(VENV_ROOT):
|
with virtualenv(VENV_ROOT):
|
||||||
|
|
||||||
run('pip uninstall -y pybitmessage')
|
run('pip uninstall -y pybitmessage')
|
||||||
|
@ -264,14 +266,14 @@ def build_docs(dep_graph=False, apidoc=True):
|
||||||
|
|
||||||
apidoc_result = 0
|
apidoc_result = 0
|
||||||
if apidoc:
|
if apidoc:
|
||||||
run('mkdir -p {}'.format(os.path.join(PROJECT_ROOT, 'docs', 'autodoc')))
|
run('mkdir -p {}'.format(os.path.join(project_root, 'docs', 'autodoc')))
|
||||||
with cd(os.path.join(PROJECT_ROOT, 'docs', 'autodoc')):
|
with cd(os.path.join(project_root, 'docs', 'autodoc')):
|
||||||
with settings(warn_only=True):
|
with settings(warn_only=True):
|
||||||
run('rm *.rst')
|
run('rm *.rst')
|
||||||
with cd(os.path.join(PROJECT_ROOT, 'docs')):
|
with cd(os.path.join(project_root, 'docs')):
|
||||||
apidoc_result = run('sphinx-apidoc -o autodoc ..').return_code
|
apidoc_result = run('sphinx-apidoc -o autodoc ..').return_code
|
||||||
|
|
||||||
with cd(os.path.join(PROJECT_ROOT, 'docs')):
|
with cd(os.path.join(project_root, 'docs')):
|
||||||
make_result = run('make html').return_code
|
make_result = run('make html').return_code
|
||||||
return_code = apidoc_result + make_result
|
return_code = apidoc_result + make_result
|
||||||
|
|
||||||
|
@ -294,16 +296,16 @@ def push_docs(path=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Making assumptions
|
# Making assumptions
|
||||||
WEB_ROOT = path if path is not None else os.path.join('var', 'www', 'html', 'pybitmessage', 'en', 'latest')
|
web_root = path if path is not None else os.path.join('var', 'www', 'html', 'pybitmessage', 'en', 'latest')
|
||||||
VERSION_ROOT = os.path.join(os.path.dirname(WEB_ROOT), softwareVersion)
|
version_root = os.path.join(os.path.dirname(web_root), softwareVersion)
|
||||||
|
|
||||||
rsync_project(
|
rsync_project(
|
||||||
remote_dir=VERSION_ROOT,
|
remote_dir=version_root,
|
||||||
local_dir=os.path.join(PROJECT_ROOT, 'docs', '_build', 'html')
|
local_dir=os.path.join(project_root, 'docs', '_build', 'html')
|
||||||
)
|
)
|
||||||
result = run('ln -sf {0} {1}'.format(WEB_ROOT, VERSION_ROOT))
|
result = run('ln -sf {0} {1}'.format(web_root, version_root))
|
||||||
if result.return_code:
|
if result.return_code:
|
||||||
print 'Linking the new release failed'
|
print('Linking the new release failed')
|
||||||
|
|
||||||
# More assumptions
|
# More assumptions
|
||||||
sudo('systemctl restart apache2')
|
sudo('systemctl restart apache2')
|
||||||
|
@ -314,5 +316,5 @@ def push_docs(path=None):
|
||||||
def clean():
|
def clean():
|
||||||
"""Clean up files generated by fabric commands."""
|
"""Clean up files generated by fabric commands."""
|
||||||
with hide('running', 'stdout'):
|
with hide('running', 'stdout'):
|
||||||
with cd(PROJECT_ROOT):
|
with cd(project_root):
|
||||||
run(r"find . -name '*.pyc' -exec rm '{}' \;")
|
run(r"find . -name '*.pyc' -exec rm '{}' \;")
|
||||||
|
|
|
@ -7,18 +7,20 @@ import xmlrpclib
|
||||||
pybmurl = ""
|
pybmurl = ""
|
||||||
api = ""
|
api = ""
|
||||||
|
|
||||||
|
|
||||||
def init_callback():
|
def init_callback():
|
||||||
global api
|
global api
|
||||||
api = xmlrpclib.ServerProxy(pybmurl)
|
api = xmlrpclib.ServerProxy(pybmurl)
|
||||||
collectd.info('pybitmessagestatus.py init done')
|
collectd.info('pybitmessagestatus.py init done')
|
||||||
|
|
||||||
def config_callback(ObjConfiguration):
|
|
||||||
|
def config_callback(obj_configuration):
|
||||||
global pybmurl
|
global pybmurl
|
||||||
apiUsername = ""
|
apiUsername = ""
|
||||||
apiPassword = ""
|
apiPassword = ""
|
||||||
apiInterface = "127.0.0.1"
|
apiInterface = "127.0.0.1"
|
||||||
apiPort = 8445
|
apiPort = 8445
|
||||||
for node in ObjConfiguration.children:
|
for node in obj_configuration.children:
|
||||||
key = node.key.lower()
|
key = node.key.lower()
|
||||||
if key.lower() == "apiusername" and node.values:
|
if key.lower() == "apiusername" and node.values:
|
||||||
apiUsername = node.values[0]
|
apiUsername = node.values[0]
|
||||||
|
@ -31,14 +33,17 @@ def config_callback(ObjConfiguration):
|
||||||
pybmurl = "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface+ ":" + str(int(apiPort)) + "/"
|
pybmurl = "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface+ ":" + str(int(apiPort)) + "/"
|
||||||
collectd.info('pybitmessagestatus.py config done')
|
collectd.info('pybitmessagestatus.py config done')
|
||||||
|
|
||||||
|
|
||||||
def read_callback():
|
def read_callback():
|
||||||
try:
|
try:
|
||||||
clientStatus = json.loads(api.clientStatus())
|
client_status = json.loads(api.clientStatus())
|
||||||
except:
|
except:
|
||||||
collectd.info("Exception loading or parsing JSON")
|
collectd.info("Exception loading or parsing JSON")
|
||||||
return
|
return
|
||||||
|
|
||||||
for i in ["networkConnections", "numberOfPubkeysProcessed", "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
|
con_data = ["networkConnections", "numberOfPubkeysProcessed",
|
||||||
|
"numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]
|
||||||
|
for i in con_data:
|
||||||
metric = collectd.Values()
|
metric = collectd.Values()
|
||||||
metric.plugin = "pybitmessagestatus"
|
metric.plugin = "pybitmessagestatus"
|
||||||
if i[0:6] == "number":
|
if i[0:6] == "number":
|
||||||
|
@ -47,11 +52,12 @@ def read_callback():
|
||||||
metric.type = 'gauge'
|
metric.type = 'gauge'
|
||||||
metric.type_instance = i.lower()
|
metric.type_instance = i.lower()
|
||||||
try:
|
try:
|
||||||
metric.values = [clientStatus[i]]
|
metric.values = [client_status[i]]
|
||||||
except:
|
except:
|
||||||
collectd.info("Value for %s missing" % (i))
|
collectd.info("Value for %s missing" % (i))
|
||||||
metric.dispatch()
|
metric.dispatch()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -45,10 +45,10 @@ def dns():
|
||||||
for port in [8080, 8444]:
|
for port in [8080, 8444]:
|
||||||
logger.debug("Resolving %i through SOCKS...", port)
|
logger.debug("Resolving %i through SOCKS...", port)
|
||||||
address_family = socket.AF_INET
|
address_family = socket.AF_INET
|
||||||
sock = socks.socksocket(address_family, socket.SOCK_STREAM)
|
sock = socks.SockSocket(address_family, socket.SOCK_STREAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
sock.settimeout(20)
|
sock.settimeout(20)
|
||||||
proxytype = socks.PROXY_TYPE_SOCKS5
|
proxytype = socks.proxy_type_socks5
|
||||||
sockshostname = BMConfigParser().get(
|
sockshostname = BMConfigParser().get(
|
||||||
'bitmessagesettings', 'sockshostname')
|
'bitmessagesettings', 'sockshostname')
|
||||||
socksport = BMConfigParser().getint(
|
socksport = BMConfigParser().getint(
|
||||||
|
|
|
@ -74,7 +74,7 @@ def base10_add(a, b):
|
||||||
m = ((b[1] - a[1]) * inv(b[0] - a[0], P)) % P
|
m = ((b[1] - a[1]) * inv(b[0] - a[0], P)) % P
|
||||||
x = (m * m - a[0] - b[0]) % P
|
x = (m * m - a[0] - b[0]) % P
|
||||||
y = (m * (a[0] - x) - a[1]) % P
|
y = (m * (a[0] - x) - a[1]) % P
|
||||||
return (x, y)
|
return x, y
|
||||||
|
|
||||||
|
|
||||||
def base10_double(a):
|
def base10_double(a):
|
||||||
|
@ -83,7 +83,7 @@ def base10_double(a):
|
||||||
m = ((3 * a[0] * a[0] + A) * inv(2 * a[1], P)) % P
|
m = ((3 * a[0] * a[0] + A) * inv(2 * a[1], P)) % P
|
||||||
x = (m * m - 2 * a[0]) % P
|
x = (m * m - 2 * a[0]) % P
|
||||||
y = (m * (a[0] - x) - a[1]) % P
|
y = (m * (a[0] - x) - a[1]) % P
|
||||||
return (x, y)
|
return x, y
|
||||||
|
|
||||||
|
|
||||||
def base10_multiply(a, n):
|
def base10_multiply(a, n):
|
||||||
|
@ -99,7 +99,7 @@ def base10_multiply(a, n):
|
||||||
|
|
||||||
|
|
||||||
def hex_to_point(h):
|
def hex_to_point(h):
|
||||||
return (decode(h[2:66], 16), decode(h[66:], 16))
|
return decode(h[2:66], 16), decode(h[66:], 16)
|
||||||
|
|
||||||
|
|
||||||
def point_to_hex(p):
|
def point_to_hex(p):
|
||||||
|
|
|
@ -21,17 +21,17 @@ class Cipher:
|
||||||
ctx2 = pyelliptic.Cipher("secretkey", iv, 0, ciphername='aes-256-cfb')
|
ctx2 = pyelliptic.Cipher("secretkey", iv, 0, ciphername='aes-256-cfb')
|
||||||
print ctx2.ciphering(ciphertext)
|
print ctx2.ciphering(ciphertext)
|
||||||
"""
|
"""
|
||||||
def __init__(self, key, iv, do, ciphername='aes-256-cbc'):
|
def __init__(self, key, iv, do, cipher_name='aes-256-cbc'):
|
||||||
"""
|
"""
|
||||||
do == 1 => Encrypt; do == 0 => Decrypt
|
do == 1 => Encrypt; do == 0 => Decrypt
|
||||||
"""
|
"""
|
||||||
self.cipher = OpenSSL.get_cipher(ciphername)
|
self.cipher = OpenSSL.get_cipher(cipher_name)
|
||||||
self.ctx = OpenSSL.EVP_CIPHER_CTX_new()
|
self.ctx = OpenSSL.EVP_CIPHER_CTX_new()
|
||||||
if do == 1 or do == 0:
|
if do == 1 or do == 0:
|
||||||
k = OpenSSL.malloc(key, len(key))
|
k = OpenSSL.malloc(key, len(key))
|
||||||
IV = OpenSSL.malloc(iv, len(iv))
|
iv1 = OpenSSL.malloc(iv, len(iv))
|
||||||
OpenSSL.EVP_CipherInit_ex(
|
OpenSSL.EVP_CipherInit_ex(
|
||||||
self.ctx, self.cipher.get_pointer(), 0, k, IV, do)
|
self.ctx, self.cipher.get_pointer(), 0, k, iv1, do)
|
||||||
else:
|
else:
|
||||||
raise Exception("RTFM ...")
|
raise Exception("RTFM ...")
|
||||||
|
|
||||||
|
@ -43,21 +43,21 @@ class Cipher:
|
||||||
return OpenSSL.cipher_algo.keys()
|
return OpenSSL.cipher_algo.keys()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_blocksize(ciphername):
|
def get_blocksize(cipher_name):
|
||||||
cipher = OpenSSL.get_cipher(ciphername)
|
cipher = OpenSSL.get_cipher(cipher_name)
|
||||||
return cipher.get_blocksize()
|
return cipher.get_blocksize()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def gen_IV(ciphername):
|
def gen_IV(cipher_name):
|
||||||
cipher = OpenSSL.get_cipher(ciphername)
|
cipher = OpenSSL.get_cipher(cipher_name)
|
||||||
return OpenSSL.rand(cipher.get_blocksize())
|
return OpenSSL.rand(cipher.get_blocksize())
|
||||||
|
|
||||||
def update(self, input):
|
def update(self, in_put):
|
||||||
i = OpenSSL.c_int(0)
|
i = OpenSSL.c_int(0)
|
||||||
buffer = OpenSSL.malloc(b"", len(input) + self.cipher.get_blocksize())
|
buffer = OpenSSL.malloc(b"", len(in_put) + self.cipher.get_blocksize())
|
||||||
inp = OpenSSL.malloc(input, len(input))
|
inp = OpenSSL.malloc(in_put, len(in_put))
|
||||||
if OpenSSL.EVP_CipherUpdate(self.ctx, OpenSSL.byref(buffer),
|
if OpenSSL.EVP_CipherUpdate(self.ctx, OpenSSL.byref(buffer),
|
||||||
OpenSSL.byref(i), inp, len(input)) == 0:
|
OpenSSL.byref(i), inp, len(in_put)) == 0:
|
||||||
raise Exception("[OpenSSL] EVP_CipherUpdate FAIL ...")
|
raise Exception("[OpenSSL] EVP_CipherUpdate FAIL ...")
|
||||||
return buffer.raw[0:i.value]
|
return buffer.raw[0:i.value]
|
||||||
|
|
||||||
|
@ -69,11 +69,11 @@ class Cipher:
|
||||||
raise Exception("[OpenSSL] EVP_CipherFinal_ex FAIL ...")
|
raise Exception("[OpenSSL] EVP_CipherFinal_ex FAIL ...")
|
||||||
return buffer.raw[0:i.value]
|
return buffer.raw[0:i.value]
|
||||||
|
|
||||||
def ciphering(self, input):
|
def ciphering(self, in_put):
|
||||||
"""
|
"""
|
||||||
Do update and final in one method
|
Do update and final in one method
|
||||||
"""
|
"""
|
||||||
buff = self.update(input)
|
buff = self.update(in_put)
|
||||||
return buff + self.final()
|
return buff + self.final()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
|
|
@ -175,9 +175,9 @@ class ECC(object):
|
||||||
group, pub_key, pub_key_x, pub_key_y, 0) == 0:
|
group, pub_key, pub_key_x, pub_key_y, 0) == 0:
|
||||||
raise Exception("[OpenSSL] EC_POINT_get_affine_coordinates_GFp FAIL ...")
|
raise Exception("[OpenSSL] EC_POINT_get_affine_coordinates_GFp FAIL ...")
|
||||||
|
|
||||||
privkey = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(priv_key))
|
privkey = OpenSSL.malloc(0, OpenSSL.bn_num_bytes(priv_key))
|
||||||
pubkeyx = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(pub_key_x))
|
pubkeyx = OpenSSL.malloc(0, OpenSSL.bn_num_bytes(pub_key_x))
|
||||||
pubkeyy = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(pub_key_y))
|
pubkeyy = OpenSSL.malloc(0, OpenSSL.bn_num_bytes(pub_key_y))
|
||||||
OpenSSL.BN_bn2bin(priv_key, privkey)
|
OpenSSL.BN_bn2bin(priv_key, privkey)
|
||||||
privkey = privkey.raw
|
privkey = privkey.raw
|
||||||
OpenSSL.BN_bn2bin(pub_key_x, pubkeyx)
|
OpenSSL.BN_bn2bin(pub_key_x, pubkeyx)
|
||||||
|
|
|
@ -19,7 +19,9 @@ class CipherName:
|
||||||
self._blocksize = blocksize
|
self._blocksize = blocksize
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Cipher : " + self._name + " | Blocksize : " + str(self._blocksize) + " | Fonction pointer : " + str(self._pointer)
|
return "Cipher : {} | Blocksize : {} | Fonction pointer : {}".format(
|
||||||
|
self._name, str(self._blocksize), str(self._pointer)
|
||||||
|
)
|
||||||
|
|
||||||
def get_pointer(self):
|
def get_pointer(self):
|
||||||
return self._pointer()
|
return self._pointer()
|
||||||
|
@ -33,33 +35,33 @@ class CipherName:
|
||||||
|
|
||||||
def get_version(library):
|
def get_version(library):
|
||||||
version = None
|
version = None
|
||||||
hexversion = None
|
hex_version = None
|
||||||
cflags = None
|
cflags = None
|
||||||
try:
|
try:
|
||||||
#OpenSSL 1.1
|
# OpenSSL 1.1
|
||||||
OPENSSL_VERSION = 0
|
openssl_version = 0
|
||||||
OPENSSL_CFLAGS = 1
|
openssl_cflags = 1
|
||||||
library.OpenSSL_version.argtypes = [ctypes.c_int]
|
library.OpenSSL_version.argtypes = [ctypes.c_int]
|
||||||
library.OpenSSL_version.restype = ctypes.c_char_p
|
library.OpenSSL_version.restype = ctypes.c_char_p
|
||||||
version = library.OpenSSL_version(OPENSSL_VERSION)
|
version = library.OpenSSL_version(openssl_version)
|
||||||
cflags = library.OpenSSL_version(OPENSSL_CFLAGS)
|
cflags = library.OpenSSL_version(openssl_cflags)
|
||||||
library.OpenSSL_version_num.restype = ctypes.c_long
|
library.OpenSSL_version_num.restype = ctypes.c_long
|
||||||
hexversion = library.OpenSSL_version_num()
|
hex_version = library.OpenSSL_version_num()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
try:
|
||||||
#OpenSSL 1.0
|
# OpenSSL 1.0
|
||||||
SSLEAY_VERSION = 0
|
ssleay_version = 0
|
||||||
SSLEAY_CFLAGS = 2
|
ssleay_cflags = 2
|
||||||
library.SSLeay.restype = ctypes.c_long
|
library.SSLeay.restype = ctypes.c_long
|
||||||
library.SSLeay_version.restype = ctypes.c_char_p
|
library.SSLeay_version.restype = ctypes.c_char_p
|
||||||
library.SSLeay_version.argtypes = [ctypes.c_int]
|
library.SSLeay_version.argtypes = [ctypes.c_int]
|
||||||
version = library.SSLeay_version(SSLEAY_VERSION)
|
version = library.SSLeay_version(ssleay_version)
|
||||||
cflags = library.SSLeay_version(SSLEAY_CFLAGS)
|
cflags = library.SSLeay_version(ssleay_cflags)
|
||||||
hexversion = library.SSLeay()
|
hex_version = library.SSLeay()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
#raise NotImplementedError('Cannot determine version of this OpenSSL library.')
|
# raise NotImplementedError('Cannot determine version of this OpenSSL library.')
|
||||||
pass
|
pass
|
||||||
return (version, hexversion, cflags)
|
return version, hex_version, cflags
|
||||||
|
|
||||||
|
|
||||||
class _OpenSSL:
|
class _OpenSSL:
|
||||||
|
@ -130,7 +132,8 @@ class _OpenSSL:
|
||||||
|
|
||||||
self.EC_POINT_get_affine_coordinates_GFp = self._lib.EC_POINT_get_affine_coordinates_GFp
|
self.EC_POINT_get_affine_coordinates_GFp = self._lib.EC_POINT_get_affine_coordinates_GFp
|
||||||
self.EC_POINT_get_affine_coordinates_GFp.restype = ctypes.c_int
|
self.EC_POINT_get_affine_coordinates_GFp.restype = ctypes.c_int
|
||||||
self.EC_POINT_get_affine_coordinates_GFp.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
self.EC_POINT_get_affine_coordinates_GFp.argtypes = [
|
||||||
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
||||||
self.EC_KEY_set_private_key.restype = ctypes.c_int
|
self.EC_KEY_set_private_key.restype = ctypes.c_int
|
||||||
|
@ -148,7 +151,8 @@ class _OpenSSL:
|
||||||
|
|
||||||
self.EC_POINT_set_affine_coordinates_GFp = self._lib.EC_POINT_set_affine_coordinates_GFp
|
self.EC_POINT_set_affine_coordinates_GFp = self._lib.EC_POINT_set_affine_coordinates_GFp
|
||||||
self.EC_POINT_set_affine_coordinates_GFp.restype = ctypes.c_int
|
self.EC_POINT_set_affine_coordinates_GFp.restype = ctypes.c_int
|
||||||
self.EC_POINT_set_affine_coordinates_GFp.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
self.EC_POINT_set_affine_coordinates_GFp.argtypes = [
|
||||||
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_POINT_new = self._lib.EC_POINT_new
|
self.EC_POINT_new = self._lib.EC_POINT_new
|
||||||
self.EC_POINT_new.restype = ctypes.c_void_p
|
self.EC_POINT_new.restype = ctypes.c_void_p
|
||||||
|
@ -164,7 +168,8 @@ class _OpenSSL:
|
||||||
|
|
||||||
self.EC_POINT_mul = self._lib.EC_POINT_mul
|
self.EC_POINT_mul = self._lib.EC_POINT_mul
|
||||||
self.EC_POINT_mul.restype = None
|
self.EC_POINT_mul.restype = None
|
||||||
self.EC_POINT_mul.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
self.EC_POINT_mul.argtypes = [
|
||||||
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||||
|
|
||||||
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
|
||||||
self.EC_KEY_set_private_key.restype = ctypes.c_int
|
self.EC_KEY_set_private_key.restype = ctypes.c_int
|
||||||
|
@ -223,13 +228,13 @@ class _OpenSSL:
|
||||||
self.EVP_aes_256_cbc.restype = ctypes.c_void_p
|
self.EVP_aes_256_cbc.restype = ctypes.c_void_p
|
||||||
self.EVP_aes_256_cbc.argtypes = []
|
self.EVP_aes_256_cbc.argtypes = []
|
||||||
|
|
||||||
#self.EVP_aes_128_ctr = self._lib.EVP_aes_128_ctr
|
# self.EVP_aes_128_ctr = self._lib.EVP_aes_128_ctr
|
||||||
#self.EVP_aes_128_ctr.restype = ctypes.c_void_p
|
# self.EVP_aes_128_ctr.restype = ctypes.c_void_p
|
||||||
#self.EVP_aes_128_ctr.argtypes = []
|
# self.EVP_aes_128_ctr.argtypes = []
|
||||||
|
|
||||||
#self.EVP_aes_256_ctr = self._lib.EVP_aes_256_ctr
|
# self.EVP_aes_256_ctr = self._lib.EVP_aes_256_ctr
|
||||||
#self.EVP_aes_256_ctr.restype = ctypes.c_void_p
|
# self.EVP_aes_256_ctr.restype = ctypes.c_void_p
|
||||||
#self.EVP_aes_256_ctr.argtypes = []
|
# self.EVP_aes_256_ctr.argtypes = []
|
||||||
|
|
||||||
self.EVP_aes_128_ofb = self._lib.EVP_aes_128_ofb
|
self.EVP_aes_128_ofb = self._lib.EVP_aes_128_ofb
|
||||||
self.EVP_aes_128_ofb.restype = ctypes.c_void_p
|
self.EVP_aes_128_ofb.restype = ctypes.c_void_p
|
||||||
|
@ -266,8 +271,8 @@ class _OpenSSL:
|
||||||
|
|
||||||
self.EVP_CipherUpdate = self._lib.EVP_CipherUpdate
|
self.EVP_CipherUpdate = self._lib.EVP_CipherUpdate
|
||||||
self.EVP_CipherUpdate.restype = ctypes.c_int
|
self.EVP_CipherUpdate.restype = ctypes.c_int
|
||||||
self.EVP_CipherUpdate.argtypes = [ctypes.c_void_p,
|
self.EVP_CipherUpdate.argtypes = [
|
||||||
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int]
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int]
|
||||||
|
|
||||||
self.EVP_CipherFinal_ex = self._lib.EVP_CipherFinal_ex
|
self.EVP_CipherFinal_ex = self._lib.EVP_CipherFinal_ex
|
||||||
self.EVP_CipherFinal_ex.restype = ctypes.c_int
|
self.EVP_CipherFinal_ex.restype = ctypes.c_int
|
||||||
|
@ -388,11 +393,11 @@ class _OpenSSL:
|
||||||
'aes-256-cfb': CipherName('aes-256-cfb', self.EVP_aes_256_cfb128, 16),
|
'aes-256-cfb': CipherName('aes-256-cfb', self.EVP_aes_256_cfb128, 16),
|
||||||
'aes-128-ofb': CipherName('aes-128-ofb', self._lib.EVP_aes_128_ofb, 16),
|
'aes-128-ofb': CipherName('aes-128-ofb', self._lib.EVP_aes_128_ofb, 16),
|
||||||
'aes-256-ofb': CipherName('aes-256-ofb', self._lib.EVP_aes_256_ofb, 16),
|
'aes-256-ofb': CipherName('aes-256-ofb', self._lib.EVP_aes_256_ofb, 16),
|
||||||
#'aes-128-ctr': CipherName('aes-128-ctr', self._lib.EVP_aes_128_ctr, 16),
|
# 'aes-128-ctr': CipherName('aes-128-ctr', self._lib.EVP_aes_128_ctr, 16),
|
||||||
#'aes-256-ctr': CipherName('aes-256-ctr', self._lib.EVP_aes_256_ctr, 16),
|
# 'aes-256-ctr': CipherName('aes-256-ctr', self._lib.EVP_aes_256_ctr, 16),
|
||||||
'bf-cfb': CipherName('bf-cfb', self.EVP_bf_cfb64, 8),
|
'bf-cfb': CipherName('bf-cfb', self.EVP_bf_cfb64, 8),
|
||||||
'bf-cbc': CipherName('bf-cbc', self.EVP_bf_cbc, 8),
|
'bf-cbc': CipherName('bf-cbc', self.EVP_bf_cbc, 8),
|
||||||
'rc4': CipherName('rc4', self.EVP_rc4, 128), # 128 is the initialisation size not block size
|
'rc4': CipherName('rc4', self.EVP_rc4, 128), # 128 is the initialisation size not block size
|
||||||
}
|
}
|
||||||
|
|
||||||
def _set_curves(self):
|
def _set_curves(self):
|
||||||
|
@ -430,9 +435,9 @@ class _OpenSSL:
|
||||||
'sect571r1': 734,
|
'sect571r1': 734,
|
||||||
}
|
}
|
||||||
|
|
||||||
def BN_num_bytes(self, x):
|
def bn_num_bytes(self, x):
|
||||||
"""
|
"""
|
||||||
returns the length of a BN (OpenSSl API)
|
returns the length of a BN (OpenSSl API)
|
||||||
"""
|
"""
|
||||||
return int((self.BN_num_bits(x) + 7) / 8)
|
return int((self.BN_num_bits(x) + 7) / 8)
|
||||||
|
|
||||||
|
@ -452,13 +457,13 @@ class _OpenSSL:
|
||||||
raise Exception("Unknown curve")
|
raise Exception("Unknown curve")
|
||||||
return self.curves[name]
|
return self.curves[name]
|
||||||
|
|
||||||
def get_curve_by_id(self, id):
|
def get_curve_by_id(self, curve_id):
|
||||||
"""
|
"""
|
||||||
returns the name of a elliptic curve with his id
|
returns the name of a elliptic curve with his id
|
||||||
"""
|
"""
|
||||||
res = None
|
res = None
|
||||||
for i in self.curves:
|
for i in self.curves:
|
||||||
if self.curves[i] == id:
|
if self.curves[i] == curve_id:
|
||||||
res = i
|
res = i
|
||||||
break
|
break
|
||||||
if res is None:
|
if res is None:
|
||||||
|
@ -485,7 +490,6 @@ class _OpenSSL:
|
||||||
"""
|
"""
|
||||||
returns a create_string_buffer (ctypes)
|
returns a create_string_buffer (ctypes)
|
||||||
"""
|
"""
|
||||||
buffer = None
|
|
||||||
if data != 0:
|
if data != 0:
|
||||||
if sys.version_info.major == 3 and isinstance(data, type('')):
|
if sys.version_info.major == 3 and isinstance(data, type('')):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
|
@ -494,26 +498,27 @@ class _OpenSSL:
|
||||||
buffer = self.create_string_buffer(size)
|
buffer = self.create_string_buffer(size)
|
||||||
return buffer
|
return buffer
|
||||||
|
|
||||||
def loadOpenSSL():
|
|
||||||
|
def load_open_ssl():
|
||||||
global OpenSSL
|
global OpenSSL
|
||||||
from os import path, environ
|
from os import path, environ
|
||||||
from ctypes.util import find_library
|
from ctypes.util import find_library
|
||||||
|
|
||||||
libdir = []
|
lib_dir = []
|
||||||
if getattr(sys,'frozen', None):
|
if getattr(sys, 'frozen', None):
|
||||||
if 'darwin' in sys.platform:
|
if 'darwin' in sys.platform:
|
||||||
libdir.extend([
|
lib_dir.extend([
|
||||||
path.join(environ['RESOURCEPATH'], '..', 'Frameworks','libcrypto.dylib'),
|
path.join(environ['RESOURCEPATH'], '..', 'Frameworks', 'libcrypto.dylib'),
|
||||||
path.join(environ['RESOURCEPATH'], '..', 'Frameworks','libcrypto.1.1.0.dylib'),
|
path.join(environ['RESOURCEPATH'], '..', 'Frameworks', 'libcrypto.1.1.0.dylib'),
|
||||||
path.join(environ['RESOURCEPATH'], '..', 'Frameworks','libcrypto.1.0.2.dylib'),
|
path.join(environ['RESOURCEPATH'], '..', 'Frameworks', 'libcrypto.1.0.2.dylib'),
|
||||||
path.join(environ['RESOURCEPATH'], '..', 'Frameworks','libcrypto.1.0.1.dylib'),
|
path.join(environ['RESOURCEPATH'], '..', 'Frameworks', 'libcrypto.1.0.1.dylib'),
|
||||||
path.join(environ['RESOURCEPATH'], '..', 'Frameworks','libcrypto.1.0.0.dylib'),
|
path.join(environ['RESOURCEPATH'], '..', 'Frameworks', 'libcrypto.1.0.0.dylib'),
|
||||||
path.join(environ['RESOURCEPATH'], '..', 'Frameworks','libcrypto.0.9.8.dylib'),
|
path.join(environ['RESOURCEPATH'], '..', 'Frameworks', 'libcrypto.0.9.8.dylib'),
|
||||||
])
|
])
|
||||||
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
||||||
libdir.append(path.join(sys._MEIPASS, 'libeay32.dll'))
|
lib_dir.append(path.join(sys._MEIPASS, 'libeay32.dll'))
|
||||||
else:
|
else:
|
||||||
libdir.extend([
|
lib_dir.extend([
|
||||||
path.join(sys._MEIPASS, 'libcrypto.so'),
|
path.join(sys._MEIPASS, 'libcrypto.so'),
|
||||||
path.join(sys._MEIPASS, 'libssl.so'),
|
path.join(sys._MEIPASS, 'libssl.so'),
|
||||||
path.join(sys._MEIPASS, 'libcrypto.so.1.1.0'),
|
path.join(sys._MEIPASS, 'libcrypto.so.1.1.0'),
|
||||||
|
@ -528,19 +533,19 @@ def loadOpenSSL():
|
||||||
path.join(sys._MEIPASS, 'libssl.so.0.9.8'),
|
path.join(sys._MEIPASS, 'libssl.so.0.9.8'),
|
||||||
])
|
])
|
||||||
if 'darwin' in sys.platform:
|
if 'darwin' in sys.platform:
|
||||||
libdir.extend(['libcrypto.dylib', '/usr/local/opt/openssl/lib/libcrypto.dylib'])
|
lib_dir.extend(['libcrypto.dylib', '/usr/local/opt/openssl/lib/libcrypto.dylib'])
|
||||||
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
||||||
libdir.append('libeay32.dll')
|
lib_dir.append('libeay32.dll')
|
||||||
else:
|
else:
|
||||||
libdir.append('libcrypto.so')
|
lib_dir.append('libcrypto.so')
|
||||||
libdir.append('libssl.so')
|
lib_dir.append('libssl.so')
|
||||||
libdir.append('libcrypto.so.1.0.0')
|
lib_dir.append('libcrypto.so.1.0.0')
|
||||||
libdir.append('libssl.so.1.0.0')
|
lib_dir.append('libssl.so.1.0.0')
|
||||||
if 'linux' in sys.platform or 'darwin' in sys.platform or 'bsd' in sys.platform:
|
if 'linux' in sys.platform or 'darwin' in sys.platform or 'bsd' in sys.platform:
|
||||||
libdir.append(find_library('ssl'))
|
lib_dir.append(find_library('ssl'))
|
||||||
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
||||||
libdir.append(find_library('libeay32'))
|
lib_dir.append(find_library('libeay32'))
|
||||||
for library in libdir:
|
for library in lib_dir:
|
||||||
try:
|
try:
|
||||||
OpenSSL = _OpenSSL(library)
|
OpenSSL = _OpenSSL(library)
|
||||||
return
|
return
|
||||||
|
@ -548,4 +553,5 @@ def loadOpenSSL():
|
||||||
pass
|
pass
|
||||||
raise Exception("Couldn't find and load the OpenSSL library. You must install it.")
|
raise Exception("Couldn't find and load the OpenSSL library. You must install it.")
|
||||||
|
|
||||||
loadOpenSSL()
|
|
||||||
|
load_open_ssl()
|
||||||
|
|
|
@ -31,6 +31,9 @@ for tunneling connections through SOCKS proxies.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Minor modifications made by Christopher Gilbert (http://motomastyle.com/)
|
Minor modifications made by Christopher Gilbert (http://motomastyle.com/)
|
||||||
|
@ -41,65 +44,82 @@ mainly to merge bug fixes found in Sourceforge
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import socket
|
|
||||||
import struct
|
|
||||||
import sys
|
|
||||||
|
|
||||||
PROXY_TYPE_SOCKS4 = 1
|
proxy_type_socks4 = 1
|
||||||
PROXY_TYPE_SOCKS5 = 2
|
proxy_type_socks5 = 2
|
||||||
PROXY_TYPE_HTTP = 3
|
proxy_type_http = 3
|
||||||
|
|
||||||
_defaultproxy = None
|
_default_proxy = None
|
||||||
_orgsocket = socket.socket
|
_org_socket = socket.socket
|
||||||
|
|
||||||
|
|
||||||
|
class ProxyError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GeneralProxyError(ProxyError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Socks5AuthError(ProxyError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Socks5Error(ProxyError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Socks4Error(ProxyError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPError(ProxyError):
|
||||||
|
pass
|
||||||
|
|
||||||
class ProxyError(Exception): pass
|
|
||||||
class GeneralProxyError(ProxyError): pass
|
|
||||||
class Socks5AuthError(ProxyError): pass
|
|
||||||
class Socks5Error(ProxyError): pass
|
|
||||||
class Socks4Error(ProxyError): pass
|
|
||||||
class HTTPError(ProxyError): pass
|
|
||||||
|
|
||||||
_generalerrors = ("success",
|
_generalerrors = ("success",
|
||||||
"invalid data",
|
"invalid data",
|
||||||
"not connected",
|
"not connected",
|
||||||
"not available",
|
"not available",
|
||||||
"bad proxy type",
|
"bad proxy type",
|
||||||
"bad input",
|
"bad input",
|
||||||
"timed out",
|
"timed out",
|
||||||
"network unreachable",
|
"network unreachable",
|
||||||
"connection refused",
|
"connection refused",
|
||||||
"host unreachable")
|
"host unreachable")
|
||||||
|
|
||||||
_socks5errors = ("succeeded",
|
_socks5errors = ("succeeded",
|
||||||
"general SOCKS server failure",
|
"general SOCKS server failure",
|
||||||
"connection not allowed by ruleset",
|
"connection not allowed by ruleset",
|
||||||
"Network unreachable",
|
"Network unreachable",
|
||||||
"Host unreachable",
|
"Host unreachable",
|
||||||
"Connection refused",
|
"Connection refused",
|
||||||
"TTL expired",
|
"TTL expired",
|
||||||
"Command not supported",
|
"Command not supported",
|
||||||
"Address type not supported",
|
"Address type not supported",
|
||||||
"Unknown error")
|
"Unknown error")
|
||||||
|
|
||||||
_socks5autherrors = ("succeeded",
|
_socks5autherrors = ("succeeded",
|
||||||
"authentication is required",
|
"authentication is required",
|
||||||
"all offered authentication methods were rejected",
|
"all offered authentication methods were rejected",
|
||||||
"unknown username or invalid password",
|
"unknown username or invalid password",
|
||||||
"unknown error")
|
"unknown error")
|
||||||
|
|
||||||
_socks4errors = ("request granted",
|
_socks4errors = ("request granted",
|
||||||
"request rejected or failed",
|
"request rejected or failed",
|
||||||
"request rejected because SOCKS server cannot connect to identd on the client",
|
"request rejected because SOCKS server cannot connect to identd on the client",
|
||||||
"request rejected because the client program and identd report different user-ids",
|
"request rejected because the client program and identd report different user-ids",
|
||||||
"unknown error")
|
"unknown error")
|
||||||
|
|
||||||
|
|
||||||
def setdefaultproxy(proxytype=None, addr=None, port=None, rdns=True, username=None, password=None):
|
def setdefaultproxy(proxytype=None, addr=None, port=None, rdns=True, username=None, password=None):
|
||||||
"""setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
|
"""setdefaultproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
|
||||||
Sets a default proxy which all further socksocket objects will use,
|
Sets a default proxy which all further socksocket objects will use,
|
||||||
unless explicitly changed.
|
unless explicitly changed.
|
||||||
"""
|
"""
|
||||||
global _defaultproxy
|
global _default_proxy
|
||||||
_defaultproxy = (proxytype, addr, port, rdns, username, password)
|
_default_proxy = (proxytype, addr, port, rdns, username, password)
|
||||||
|
|
||||||
|
|
||||||
def wrapmodule(module):
|
def wrapmodule(module):
|
||||||
"""wrapmodule(module)
|
"""wrapmodule(module)
|
||||||
|
@ -108,12 +128,13 @@ def wrapmodule(module):
|
||||||
This will only work on modules that import socket directly into the namespace;
|
This will only work on modules that import socket directly into the namespace;
|
||||||
most of the Python Standard Library falls into this category.
|
most of the Python Standard Library falls into this category.
|
||||||
"""
|
"""
|
||||||
if _defaultproxy != None:
|
if _default_proxy is not None:
|
||||||
module.socket.socket = socksocket
|
module.socket.socket = SockSocket
|
||||||
else:
|
else:
|
||||||
raise GeneralProxyError((4, "no proxy specified"))
|
raise GeneralProxyError((4, "no proxy specified"))
|
||||||
|
|
||||||
class socksocket(socket.socket):
|
|
||||||
|
class SockSocket(socket.socket):
|
||||||
"""socksocket([family[, type[, proto]]]) -> socket object
|
"""socksocket([family[, type[, proto]]]) -> socket object
|
||||||
Open a SOCKS enabled socket. The parameters are the same as
|
Open a SOCKS enabled socket. The parameters are the same as
|
||||||
those of the standard socket init. In order for SOCKS to work,
|
those of the standard socket init. In order for SOCKS to work,
|
||||||
|
@ -121,13 +142,13 @@ class socksocket(socket.socket):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, _sock=None):
|
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, _sock=None):
|
||||||
_orgsocket.__init__(self, family, type, proto, _sock)
|
_org_socket.__init__(self, family, type, proto, _sock)
|
||||||
if _defaultproxy != None:
|
if _default_proxy is not None:
|
||||||
self.__proxy = _defaultproxy
|
self.__proxy = _default_proxy
|
||||||
else:
|
else:
|
||||||
self.__proxy = (None, None, None, None, None, None)
|
self.__proxy = (None, None, None, None, None, None)
|
||||||
self.__proxysockname = None
|
self.__proxy_sock_name = None
|
||||||
self.__proxypeername = None
|
self.__proxy_peer_name = None
|
||||||
|
|
||||||
def __recvall(self, count):
|
def __recvall(self, count):
|
||||||
"""__recvall(count) -> data
|
"""__recvall(count) -> data
|
||||||
|
@ -139,8 +160,9 @@ class socksocket(socket.socket):
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
raise GeneralProxyError((6, "timed out"))
|
raise GeneralProxyError((6, "timed out"))
|
||||||
while len(data) < count:
|
while len(data) < count:
|
||||||
d = self.recv(count-len(data))
|
d = self.recv(count - len(data))
|
||||||
if not d: raise GeneralProxyError((0, "connection closed unexpectedly"))
|
if not d:
|
||||||
|
raise GeneralProxyError((0, "connection closed unexpectedly"))
|
||||||
data = data + d
|
data = data + d
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -181,7 +203,7 @@ class socksocket(socket.socket):
|
||||||
Negotiates a connection through a SOCKS5 server.
|
Negotiates a connection through a SOCKS5 server.
|
||||||
"""
|
"""
|
||||||
# First we'll send the authentication packages we support.
|
# First we'll send the authentication packages we support.
|
||||||
if (self.__proxy[4]!=None) and (self.__proxy[5]!=None):
|
if self.__proxy[4] is not None and self.__proxy[5] is not None:
|
||||||
# The username/password details were supplied to the
|
# The username/password details were supplied to the
|
||||||
# setproxy method so we support the USERNAME/PASSWORD
|
# setproxy method so we support the USERNAME/PASSWORD
|
||||||
# authentication (in addition to the standard none).
|
# authentication (in addition to the standard none).
|
||||||
|
@ -203,7 +225,10 @@ class socksocket(socket.socket):
|
||||||
elif chosenauth[1:2] == chr(0x02).encode():
|
elif chosenauth[1:2] == chr(0x02).encode():
|
||||||
# Okay, we need to perform a basic username/password
|
# Okay, we need to perform a basic username/password
|
||||||
# authentication.
|
# authentication.
|
||||||
self.sendall(chr(0x01).encode() + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5])
|
self.sendall(
|
||||||
|
chr(0x01).encode() + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(
|
||||||
|
len(self.__proxy[5])) + self.__proxy[5]
|
||||||
|
)
|
||||||
authstat = self.__recvall(2)
|
authstat = self.__recvall(2)
|
||||||
if authstat[0:1] != chr(0x01).encode():
|
if authstat[0:1] != chr(0x01).encode():
|
||||||
# Bad response
|
# Bad response
|
||||||
|
@ -250,7 +275,7 @@ class socksocket(socket.socket):
|
||||||
elif resp[1:2] != chr(0x00).encode():
|
elif resp[1:2] != chr(0x00).encode():
|
||||||
# Connection failed
|
# Connection failed
|
||||||
self.close()
|
self.close()
|
||||||
if ord(resp[1:2])<=8:
|
if ord(resp[1:2]) <= 8:
|
||||||
raise Socks5Error((ord(resp[1:2]), _socks5errors[ord(resp[1:2])]))
|
raise Socks5Error((ord(resp[1:2]), _socks5errors[ord(resp[1:2])]))
|
||||||
else:
|
else:
|
||||||
raise Socks5Error((9, _socks5errors[9]))
|
raise Socks5Error((9, _socks5errors[9]))
|
||||||
|
@ -262,13 +287,13 @@ class socksocket(socket.socket):
|
||||||
boundaddr = self.__recvall(ord(resp[4:5]))
|
boundaddr = self.__recvall(ord(resp[4:5]))
|
||||||
else:
|
else:
|
||||||
self.close()
|
self.close()
|
||||||
raise GeneralProxyError((1,_generalerrors[1]))
|
raise GeneralProxyError((1, _generalerrors[1]))
|
||||||
boundport = struct.unpack(">H", self.__recvall(2))[0]
|
boundport = struct.unpack(">H", self.__recvall(2))[0]
|
||||||
self.__proxysockname = (boundaddr, boundport)
|
self.__proxy_sock_name = (boundaddr, boundport)
|
||||||
if ipaddr != None:
|
if ipaddr:
|
||||||
self.__proxypeername = (socket.inet_ntoa(ipaddr), destport)
|
self.__proxy_peer_name = (socket.inet_ntoa(ipaddr), destport)
|
||||||
else:
|
else:
|
||||||
self.__proxypeername = (destaddr, destport)
|
self.__proxy_peer_name = (destaddr, destport)
|
||||||
|
|
||||||
def __resolvesocks5(self, host):
|
def __resolvesocks5(self, host):
|
||||||
# Now we can request the actual connection
|
# Now we can request the actual connection
|
||||||
|
@ -277,7 +302,7 @@ class socksocket(socket.socket):
|
||||||
req = req + struct.pack(">H", 8444)
|
req = req + struct.pack(">H", 8444)
|
||||||
self.sendall(req)
|
self.sendall(req)
|
||||||
# Get the response
|
# Get the response
|
||||||
ip = ""
|
|
||||||
resp = self.__recvall(4)
|
resp = self.__recvall(4)
|
||||||
if resp[0:1] != chr(0x05).encode():
|
if resp[0:1] != chr(0x05).encode():
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -285,7 +310,7 @@ class socksocket(socket.socket):
|
||||||
elif resp[1:2] != chr(0x00).encode():
|
elif resp[1:2] != chr(0x00).encode():
|
||||||
# Connection failed
|
# Connection failed
|
||||||
self.close()
|
self.close()
|
||||||
if ord(resp[1:2])<=8:
|
if ord(resp[1:2]) <= 8:
|
||||||
raise Socks5Error((ord(resp[1:2]), _socks5errors[ord(resp[1:2])]))
|
raise Socks5Error((ord(resp[1:2]), _socks5errors[ord(resp[1:2])]))
|
||||||
else:
|
else:
|
||||||
raise Socks5Error((9, _socks5errors[9]))
|
raise Socks5Error((9, _socks5errors[9]))
|
||||||
|
@ -297,65 +322,64 @@ class socksocket(socket.socket):
|
||||||
ip = self.__recvall(ord(resp[4:5]))
|
ip = self.__recvall(ord(resp[4:5]))
|
||||||
else:
|
else:
|
||||||
self.close()
|
self.close()
|
||||||
raise GeneralProxyError((1,_generalerrors[1]))
|
raise GeneralProxyError((1, _generalerrors[1]))
|
||||||
boundport = struct.unpack(">H", self.__recvall(2))[0]
|
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
def getproxysockname(self):
|
def getproxysockname(self):
|
||||||
"""getsockname() -> address info
|
"""getsockname() -> address info
|
||||||
Returns the bound IP address and port number at the proxy.
|
Returns the bound IP address and port number at the proxy.
|
||||||
"""
|
"""
|
||||||
return self.__proxysockname
|
return self.__proxy_sock_name
|
||||||
|
|
||||||
def getproxypeername(self):
|
def getproxypeername(self):
|
||||||
"""getproxypeername() -> address info
|
"""getproxypeername() -> address info
|
||||||
Returns the IP and port number of the proxy.
|
Returns the IP and port number of the proxy.
|
||||||
"""
|
"""
|
||||||
return _orgsocket.getpeername(self)
|
return _org_socket.getpeername(self)
|
||||||
|
|
||||||
def getpeername(self):
|
def getpeername(self):
|
||||||
"""getpeername() -> address info
|
"""getpeername() -> address info
|
||||||
Returns the IP address and port number of the destination
|
Returns the IP address and port number of the destination
|
||||||
machine (note: getproxypeername returns the proxy)
|
machine (note: getproxypeername returns the proxy)
|
||||||
"""
|
"""
|
||||||
return self.__proxypeername
|
return self.__proxy_peer_name
|
||||||
|
|
||||||
def getproxytype(self):
|
def getproxytype(self):
|
||||||
return self.__proxy[0]
|
return self.__proxy[0]
|
||||||
|
|
||||||
def __negotiatesocks4(self,destaddr,destport):
|
def __negotiatesocks4(self, destination_address, destination_port):
|
||||||
"""__negotiatesocks4(self,destaddr,destport)
|
"""__negotiatesocks4(self,destaddr,destport)
|
||||||
Negotiates a connection through a SOCKS4 server.
|
Negotiates a connection through a SOCKS4 server.
|
||||||
"""
|
"""
|
||||||
# Check if the destination address provided is an IP address
|
# Check if the destination address provided is an IP address
|
||||||
rmtrslv = False
|
rmtrslv = False
|
||||||
try:
|
try:
|
||||||
ipaddr = socket.inet_aton(destaddr)
|
ipaddr = socket.inet_aton(destination_address)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
# It's a DNS name. Check where it should be resolved.
|
# It's a DNS name. Check where it should be resolved.
|
||||||
if self.__proxy[3]:
|
if self.__proxy[3]:
|
||||||
ipaddr = struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01)
|
ipaddr = struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01)
|
||||||
rmtrslv = True
|
rmtrslv = True
|
||||||
else:
|
else:
|
||||||
ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
|
ipaddr = socket.inet_aton(socket.gethostbyname(destination_address))
|
||||||
# Construct the request packet
|
# Construct the request packet
|
||||||
req = struct.pack(">BBH", 0x04, 0x01, destport) + ipaddr
|
req = struct.pack(">BBH", 0x04, 0x01, destination_port) + ipaddr
|
||||||
# The username parameter is considered userid for SOCKS4
|
# The username parameter is considered userid for SOCKS4
|
||||||
if self.__proxy[4] != None:
|
if self.__proxy[4] is not None:
|
||||||
req = req + self.__proxy[4]
|
req = req + self.__proxy[4]
|
||||||
req = req + chr(0x00).encode()
|
req = req + chr(0x00).encode()
|
||||||
# DNS name if remote resolving is required
|
# DNS name if remote resolving is required
|
||||||
# NOTE: This is actually an extension to the SOCKS4 protocol
|
# NOTE: This is actually an extension to the SOCKS4 protocol
|
||||||
# called SOCKS4A and may not be supported in all cases.
|
# called SOCKS4A and may not be supported in all cases.
|
||||||
if rmtrslv:
|
if rmtrslv:
|
||||||
req = req + destaddr + chr(0x00).encode()
|
req = req + destination_address + chr(0x00).encode()
|
||||||
self.sendall(req)
|
self.sendall(req)
|
||||||
# Get the response from the server
|
# Get the response from the server
|
||||||
resp = self.__recvall(8)
|
resp = self.__recvall(8)
|
||||||
if resp[0:1] != chr(0x00).encode():
|
if resp[0:1] != chr(0x00).encode():
|
||||||
# Bad data
|
# Bad data
|
||||||
self.close()
|
self.close()
|
||||||
raise GeneralProxyError((1,_generalerrors[1]))
|
raise GeneralProxyError((1, _generalerrors[1]))
|
||||||
if resp[1:2] != chr(0x5A).encode():
|
if resp[1:2] != chr(0x5A).encode():
|
||||||
# Server returned an error
|
# Server returned an error
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -365,44 +389,48 @@ class socksocket(socket.socket):
|
||||||
else:
|
else:
|
||||||
raise Socks4Error((94, _socks4errors[4]))
|
raise Socks4Error((94, _socks4errors[4]))
|
||||||
# Get the bound address/port
|
# Get the bound address/port
|
||||||
self.__proxysockname = (socket.inet_ntoa(resp[4:]), struct.unpack(">H", resp[2:4])[0])
|
self.__proxy_sock_name = (socket.inet_ntoa(resp[4:]), struct.unpack(">H", resp[2:4])[0])
|
||||||
if rmtrslv != None:
|
if rmtrslv is not None:
|
||||||
self.__proxypeername = (socket.inet_ntoa(ipaddr), destport)
|
self.__proxy_peer_name = (socket.inet_ntoa(ipaddr), destination_port)
|
||||||
else:
|
else:
|
||||||
self.__proxypeername = (destaddr, destport)
|
self.__proxy_peer_name = (destination_address, destination_port)
|
||||||
|
|
||||||
def __negotiatehttp(self, destaddr, destport):
|
def __negotiatehttp(self, destination_address, destination_port):
|
||||||
"""__negotiatehttp(self,destaddr,destport)
|
"""__negotiatehttp(self,destaddr,destport)
|
||||||
Negotiates a connection through an HTTP server.
|
Negotiates a connection through an HTTP server.
|
||||||
"""
|
"""
|
||||||
# If we need to resolve locally, we do this now
|
# If we need to resolve locally, we do this now
|
||||||
if not self.__proxy[3]:
|
if not self.__proxy[3]:
|
||||||
addr = socket.gethostbyname(destaddr)
|
addr = socket.gethostbyname(destination_address)
|
||||||
else:
|
else:
|
||||||
addr = destaddr
|
addr = destination_address
|
||||||
self.sendall(("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n").encode())
|
self.sendall(
|
||||||
|
("CONNECT {} : {} HTTP/1.1\r\n Host: {} \r\n\r\n".format(
|
||||||
|
addr, str(destination_port), destination_address)).encode())
|
||||||
# We read the response until we get the string "\r\n\r\n"
|
# We read the response until we get the string "\r\n\r\n"
|
||||||
resp = self.recv(1)
|
resp = self.recv(1)
|
||||||
while resp.find("\r\n\r\n".encode()) == -1:
|
while resp.find("\r\n\r\n".encode()) == -1:
|
||||||
resp = resp + self.recv(1)
|
resp = resp + self.recv(1)
|
||||||
# We just need the first line to check if the connection
|
# We just need the first line to check if the connection
|
||||||
# was successful
|
# was successful
|
||||||
statusline = resp.splitlines()[0].split(" ".encode(), 2)
|
status_line = resp.splitlines()[0].split(" ".encode(), 2)
|
||||||
if statusline[0] not in ("HTTP/1.0".encode(), "HTTP/1.1".encode()):
|
|
||||||
|
if status_line[0] not in ("HTTP/1.0".encode(), "HTTP/1.1".encode()):
|
||||||
self.close()
|
self.close()
|
||||||
raise GeneralProxyError((1, _generalerrors[1]))
|
raise GeneralProxyError((1, _generalerrors[1]))
|
||||||
try:
|
try:
|
||||||
statuscode = int(statusline[1])
|
statuscode = int(status_line[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.close()
|
self.close()
|
||||||
raise GeneralProxyError((1, _generalerrors[1]))
|
raise GeneralProxyError((1, _generalerrors[1]))
|
||||||
|
|
||||||
if statuscode != 200:
|
if statuscode != 200:
|
||||||
self.close()
|
self.close()
|
||||||
raise HTTPError((statuscode, statusline[2]))
|
raise HTTPError((statuscode, status_line[2]))
|
||||||
self.__proxysockname = ("0.0.0.0", 0)
|
self.__proxy_sock_name = ("0.0.0.0", 0)
|
||||||
self.__proxypeername = (addr, destport)
|
self.__proxy_peer_name = (addr, destination_port)
|
||||||
|
|
||||||
def connect(self, destpair):
|
def connect(self, destination_pair):
|
||||||
"""connect(self, despair)
|
"""connect(self, despair)
|
||||||
Connects to the specified destination through a proxy.
|
Connects to the specified destination through a proxy.
|
||||||
destpar - A tuple of the IP/DNS address and the port number.
|
destpar - A tuple of the IP/DNS address and the port number.
|
||||||
|
@ -410,15 +438,14 @@ class socksocket(socket.socket):
|
||||||
To select the proxy server use setproxy().
|
To select the proxy server use setproxy().
|
||||||
"""
|
"""
|
||||||
# Do a minimal input check first
|
# Do a minimal input check first
|
||||||
if (not type(destpair) in (list,tuple)) or (len(destpair) < 2) or (type(destpair[0]) != type('')) or (type(destpair[1]) != int):
|
if (not isinstance(destination_pair, (list, tuple))) or (len(destination_pair) < 2) \
|
||||||
|
or not isinstance(destination_pair[0], str) or not isinstance(destination_pair[1], int):
|
||||||
raise GeneralProxyError((5, _generalerrors[5]))
|
raise GeneralProxyError((5, _generalerrors[5]))
|
||||||
if self.__proxy[0] == PROXY_TYPE_SOCKS5:
|
|
||||||
if self.__proxy[2] != None:
|
if self.__proxy[0] == proxy_type_socks5:
|
||||||
portnum = self.__proxy[2]
|
port_number = self.__proxy[2] if self.__proxy[2] is not None else 1080
|
||||||
else:
|
|
||||||
portnum = 1080
|
|
||||||
try:
|
try:
|
||||||
_orgsocket.connect(self, (self.__proxy[1], portnum))
|
_org_socket.connect(self, (self.__proxy[1], port_number))
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
# ENETUNREACH, WSAENETUNREACH
|
# ENETUNREACH, WSAENETUNREACH
|
||||||
if e[0] in [101, 10051]:
|
if e[0] in [101, 10051]:
|
||||||
|
@ -431,21 +458,17 @@ class socksocket(socket.socket):
|
||||||
raise GeneralProxyError((9, _generalerrors[9]))
|
raise GeneralProxyError((9, _generalerrors[9]))
|
||||||
raise
|
raise
|
||||||
self.__negotiatesocks5()
|
self.__negotiatesocks5()
|
||||||
self.__connectsocks5(destpair[0], destpair[1])
|
self.__connectsocks5(destination_pair[0], destination_pair[1])
|
||||||
elif self.__proxy[0] == PROXY_TYPE_SOCKS4:
|
|
||||||
if self.__proxy[2] != None:
|
elif self.__proxy[0] == proxy_type_socks4:
|
||||||
portnum = self.__proxy[2]
|
port_number = self.__proxy[2] if self.__proxy[2] is not None else 1080
|
||||||
else:
|
_org_socket.connect(self, (self.__proxy[1], port_number))
|
||||||
portnum = 1080
|
self.__negotiatesocks4(destination_pair[0], destination_pair[1])
|
||||||
_orgsocket.connect(self,(self.__proxy[1], portnum))
|
|
||||||
self.__negotiatesocks4(destpair[0], destpair[1])
|
elif self.__proxy[0] == proxy_type_http:
|
||||||
elif self.__proxy[0] == PROXY_TYPE_HTTP:
|
port_number = self.__proxy[2] if self.__proxy[2] is not None else 8080
|
||||||
if self.__proxy[2] != None:
|
|
||||||
portnum = self.__proxy[2]
|
|
||||||
else:
|
|
||||||
portnum = 8080
|
|
||||||
try:
|
try:
|
||||||
_orgsocket.connect(self,(self.__proxy[1], portnum))
|
_org_socket.connect(self, (self.__proxy[1], port_number))
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
# ENETUNREACH, WSAENETUNREACH
|
# ENETUNREACH, WSAENETUNREACH
|
||||||
if e[0] in [101, 10051]:
|
if e[0] in [101, 10051]:
|
||||||
|
@ -457,19 +480,17 @@ class socksocket(socket.socket):
|
||||||
if e[0] in [113, 10065]:
|
if e[0] in [113, 10065]:
|
||||||
raise GeneralProxyError((9, _generalerrors[9]))
|
raise GeneralProxyError((9, _generalerrors[9]))
|
||||||
raise
|
raise
|
||||||
self.__negotiatehttp(destpair[0], destpair[1])
|
self.__negotiatehttp(destination_pair[0], destination_pair[1])
|
||||||
elif self.__proxy[0] == None:
|
|
||||||
_orgsocket.connect(self, (destpair[0], destpair[1]))
|
elif not self.__proxy[0]:
|
||||||
|
_org_socket.connect(self, (destination_pair[0], destination_pair[1]))
|
||||||
else:
|
else:
|
||||||
raise GeneralProxyError((4, _generalerrors[4]))
|
raise GeneralProxyError((4, _generalerrors[4]))
|
||||||
|
|
||||||
def resolve(self, host):
|
def resolve(self, host):
|
||||||
if self.__proxy[0] == PROXY_TYPE_SOCKS5:
|
if self.__proxy[0] == proxy_type_socks5:
|
||||||
if self.__proxy[2] != None:
|
port_number = self.__proxy[2] if self.__proxy[2] is not None else 1080
|
||||||
portnum = self.__proxy[2]
|
_org_socket.connect(self, (self.__proxy[1], port_number))
|
||||||
else:
|
|
||||||
portnum = 1080
|
|
||||||
_orgsocket.connect(self, (self.__proxy[1], portnum))
|
|
||||||
self.__negotiatesocks5()
|
self.__negotiatesocks5()
|
||||||
return self.__resolvesocks5(host)
|
return self.__resolvesocks5(host)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user