diff --git a/Makefile b/Makefile index 93ee40c..023d501 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ PREFIX=/usr/local -PYTHON_EXE_MSYS=${PREFIX}/bin/python3.bash +PYTHON_EXE_MSYS=${PREFIX}/bin/python3.sh +PIP_EXE_MSYS=${PREFIX}/bin/pip3.sh LOCAL_DOCTEST=${PREFIX}/bin/toxcore_run_doctest3.bash DOCTEST=${LOCAL_DOCTEST} MOD=exclude_badExits @@ -11,21 +12,20 @@ lint:: sh .pylint.sh install:: - pip3.sh install --target ${PREFIX}/lib/python3.11/site-packages/ --upgrade . + ${PIP_EXE_MSYS} install --target ${PREFIX}/lib/python3.11/site-packages/ --upgrade . rsync:: bash .rsync.sh - test:: - ${PYTHON_EXE_MSYS} exclude_badExits.py --help - TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/torcontactinfo.py +test:: + env PYTHONPATH=${PWD}/src ${PYTHON_EXE_MSYS} ${PWD}/src/${MOD}/exclude_badExits.py --help + env PYTHONPATH=${PWD}/src TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/torcontactinfo.py doctest:: - export PYTHONPATH=${PWD}/src/${MOD} - ${DOCTEST} ${MOD}.txt + env PYTHONPATH=${PWD}/src ${DOCTEST} ${MOD}.txt veryclean:: clean - rm -rf build dist + rm -rf build dist src/exclude_badExits.egg-info/ clean:: find * -name \*~ -delete diff --git a/README.md b/README.md index 0fee17c..ae692d4 100644 --- a/README.md +++ b/README.md @@ -140,4 +140,4 @@ For usage, do ```python3 exclude_badExits.py --help``` See [exclude_badExits.hlp](./exclude_badExits.hlp) or there's a doctest file in [exclude_badExits.txt](./exclude_badExits.txt) - +Up-to-date code is on https://git.plastiras.org/emdee/exclude_badExits diff --git a/pyproject.toml b/pyproject.toml index cc95c4d..b374fea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,19 +17,15 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: CPython", ] -dynamic = ["version", "readme", ] # cannot be dynamic ['license'] -dependencies = [ -# 'qasync >= 0.27.1', - 'cryptography >= 41.0.7', - 'rsa >= 4.9', - 'stem >= 1.8.2'] +dynamic = ["version", "readme", "dependencies"] # cannot be dynamic ['license'] -[project.scripts +[project.scripts] exclude_badExits = "exclude_badExits.exclude_badExits:iMain" [tool.setuptools.dynamic] version = {attr = "exclude_badExits.__version__"} readme = {file = ["README.md"]} +dependencies = {file = ["requirements.txt"]} [project.license] file = "LICENSE.md" @@ -42,8 +38,6 @@ requires = ["setuptools >= 61.0"] build-backend = "setuptools.build_meta" # Either or both of these don't work -#[tool.setuptools] -#packages = ["exclude_badExits"] +[tool.setuptools] +packages = ["exclude_badExits"] -#[tool.setuptools.packages.find] -#include = ["src"] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..35f0ff0 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,64 @@ +[metadata] +classifiers = + License :: OSI Approved + Intended Audience :: Web Developers + Operating System :: POSIX :: BSD :: FreeBSD + Operating System :: POSIX :: Linux + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: Implementation :: CPython + Framework :: AsyncIO +description='Tox ctypes wrapping into Python' +long_description='A program to exclude bad exits on the Tor network' +url='https://git.plastiras.org/emdee/exclude_badExits/' +keywords='rotten-onions tor' + +[options] +zip_safe = false +#python_requires = >=3.6 +include_package_data = + "*" = ["*.txt"] +package_dir= + =src +packages = ["exclude_badExits"] + + +[options.packages.find] +where=src + +[options.entry_points] +console_scripts = + exclude_badExits = exclude_badExits.exclude_badExits:iMain + +[easy_install] +zip_ok = false + +[flake8] +jobs = 1 +max-line-length = 88 +ignore = + E111 + E114 + E128 + E225 + E261 + E302 + E305 + E402 + E501 + E502 + E541 + E701 + E702 + E704 + E722 + E741 + F508 + F541 + W503 + W601 diff --git a/src/exclude_badExits/support_onions.py b/src/exclude_badExits/support_onions.py index 52acaf3..c079a54 100644 --- a/src/exclude_badExits/support_onions.py +++ b/src/exclude_badExits/support_onions.py @@ -9,16 +9,10 @@ import socket import sys import time -if False: - import cepa as stem - from cepa.connection import MissingPassword - from cepa.control import Controller - from cepa.util.tor_tools import is_valid_fingerprint -else: - import stem - from stem.connection import MissingPassword - from stem.control import Controller - from stem.util.tor_tools import is_valid_fingerprint +import stem +from stem.connection import MissingPassword +from stem.control import Controller +from stem.util.tor_tools import is_valid_fingerprint global LOG import logging diff --git a/src/exclude_badExits/torcontactinfo.py b/src/exclude_badExits/torcontactinfo.py index 624ffef..169bfe8 100644 --- a/src/exclude_badExits/torcontactinfo.py +++ b/src/exclude_badExits/torcontactinfo.py @@ -24,20 +24,20 @@ import logging import warnings import requests import textwrap -try: - from rich import print as rprint - HAS_RICH = True -except ImportError: + +# from rich import print as rprintxxx +# HAS_RICH = True +if True: def rprint(value='', *args, **kwargs): - if value not in [None, False, True] and isinstance(value, (dict, list, set, tuple)): + if value not in [None, False, True] and + isinstance(value, (dict, list, set, tuple)): value = json.dumps(value, indent=4) - return print(value, *args, **kwargs) + return LOG.debug(value, *args, **kwargs) # rprint = print - HAS_RICH = False +# HAS_RICH = False warnings.filterwarnings('ignore') - -from exclude_badExits.exclude_utils import vsetup_logging +LOG = logging.getLogger() class TorContactInfoParser(object): email_regex = "^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$" @@ -448,7 +448,7 @@ def cmd_scan(opts: argparse.Namespace, adata=None) -> int: if opts.pretty: rprint(result) else: - print(result) + LOG.debug(result) return 0 ETC_DIR = '/etc/tor/yaml' @@ -544,7 +544,7 @@ def oparser(): return cparser -def iMain(lArgs=None) +def iMain(lArgs=None): cparser = oparser() opts = cparser.parse_args(lArgs) data = None @@ -554,11 +554,11 @@ def iMain(lArgs=None) return i if __name__ == "__main__": + from exclude_utils import vsetup_logging if os.environ.get('DEBUG', ''): - log_level = 10 + log_level = 10 # logging.DEBUG else: - log_level = 20 - LOG = logging.getLogger() + log_level = 20 # logging.INFO vsetup_logging(LOG, log_level) try: i = iMain(sys.argv[1:]) diff --git a/src/exclude_badExits/trustor_poc.py b/src/exclude_badExits/trustor_poc.py index ad4ff7f..d78388f 100644 --- a/src/exclude_badExits/trustor_poc.py +++ b/src/exclude_badExits/trustor_poc.py @@ -218,7 +218,7 @@ def find_validation_candidates(controller, result[domain] = {prooftype: [fingerprint]} return result -def oDownloadUrlRequests(uri, sCAfile, timeout=30, host='127.0.0.1', port=9050, content_type='text/plain', session=None): +def oDownloadUrlRequests(uri, sCAfile: str, timeout: int = 30, host: str = '127.0.0.1', port:int = 9050, content_type: str = 'text/plain', session=None): import requests # socks proxy used for outbound web requests (for validation of proofs) proxy = {'https': "socks5h://{host}:{port}"} @@ -266,7 +266,7 @@ def oDownloadUrlRequests(uri, sCAfile, timeout=30, host='127.0.0.1', port=9050, return oReqResp # There's no point in using asyncio because of duplicate urls in the tasks -async def oDownloadUrlHttpx(uri, sCAfile, timeout=30, host='127.0.0.1', port=9050, content_type='text/plain'): +async def oDownloadUrlHttpx(uri:str, sCAfile:str, timeout;int = 30, host:str = '127.0.0.1', port:int = 9050, content_type:str = 'text/plain'): import httpcore import asyncio import httpx @@ -502,7 +502,8 @@ def lDownloadUrlFps(domain, sCAfile, timeout=30, host='127.0.0.1', port=9050): well_known_content = [i for i in well_known_content if i and len(i) == 40] return well_known_content -def validate_proofs(candidates, validation_cache_file, timeout=20, host='127.0.0.1', port=9050): +def validate_proofs(candidates, validation_cache_file, timeout=20, host='127.0.0.1', port=9050, CAfile:str = '/etc/ssl/certs/ca-certificates.crt'): + ''' This function takes the return value of find_validation_candidates() and validated them according to their proof type (uri-rsa, dns-rsa) @@ -619,7 +620,8 @@ if __name__ == '__main__': validate_proofs(r, validation_cache_file, timeout=timeout, host=controller_address, - port=port) + port=port, + CAfile=CAfile) # refresh list with newly validated fingerprints trusted_fingerprints = read_local_validation_cache(validation_cache_file,