transparent-tor-proxy 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- transparent_tor_proxy-0.1.1/.dockerignore +20 -0
- transparent_tor_proxy-0.1.1/.github/workflows/ci.yml +56 -0
- transparent_tor_proxy-0.1.1/.gitignore +221 -0
- transparent_tor_proxy-0.1.1/CHANGELOG.md +59 -0
- transparent_tor_proxy-0.1.1/CONTRIBUTING.md +70 -0
- transparent_tor_proxy-0.1.1/LICENSE +21 -0
- transparent_tor_proxy-0.1.1/Makefile +60 -0
- transparent_tor_proxy-0.1.1/PKG-INFO +378 -0
- transparent_tor_proxy-0.1.1/README.md +361 -0
- transparent_tor_proxy-0.1.1/SECURITY.md +27 -0
- transparent_tor_proxy-0.1.1/assets/gif/demo.gif +0 -0
- transparent_tor_proxy-0.1.1/docs/architecture.md +318 -0
- transparent_tor_proxy-0.1.1/packaging/PKGBUILD +88 -0
- transparent_tor_proxy-0.1.1/packaging/build_deb.sh +136 -0
- transparent_tor_proxy-0.1.1/packaging/build_rpm.sh +103 -0
- transparent_tor_proxy-0.1.1/packaging/release.sh +119 -0
- transparent_tor_proxy-0.1.1/packaging/ttp.service +40 -0
- transparent_tor_proxy-0.1.1/packaging/ttp.spec +116 -0
- transparent_tor_proxy-0.1.1/pyproject.toml +38 -0
- transparent_tor_proxy-0.1.1/scripts/install.sh +94 -0
- transparent_tor_proxy-0.1.1/scripts/restore-network.sh +63 -0
- transparent_tor_proxy-0.1.1/scripts/uninstall.sh +51 -0
- transparent_tor_proxy-0.1.1/scripts/vm/Dockerfile.arch.test +32 -0
- transparent_tor_proxy-0.1.1/scripts/vm/Dockerfile.debian.test +33 -0
- transparent_tor_proxy-0.1.1/scripts/vm/Dockerfile.fedora.test +33 -0
- transparent_tor_proxy-0.1.1/scripts/vm/run_integration_tests.sh +75 -0
- transparent_tor_proxy-0.1.1/scripts/vm/send.sh +75 -0
- transparent_tor_proxy-0.1.1/scripts/vm/snapshot.sh +65 -0
- transparent_tor_proxy-0.1.1/scripts/vm/start.sh +76 -0
- transparent_tor_proxy-0.1.1/tests/__init__.py +1 -0
- transparent_tor_proxy-0.1.1/tests/test_cli.py +287 -0
- transparent_tor_proxy-0.1.1/tests/test_dns.py +116 -0
- transparent_tor_proxy-0.1.1/tests/test_firewall.py +121 -0
- transparent_tor_proxy-0.1.1/tests/test_firewall_rules.py +64 -0
- transparent_tor_proxy-0.1.1/tests/test_integration.py +80 -0
- transparent_tor_proxy-0.1.1/tests/test_resources.py +31 -0
- transparent_tor_proxy-0.1.1/tests/test_selinux_strategy.py +160 -0
- transparent_tor_proxy-0.1.1/tests/test_state.py +98 -0
- transparent_tor_proxy-0.1.1/tests/test_system_info.py +130 -0
- transparent_tor_proxy-0.1.1/tests/test_tor_control.py +224 -0
- transparent_tor_proxy-0.1.1/tests/test_tor_detect.py +229 -0
- transparent_tor_proxy-0.1.1/tests/test_tor_install.py +195 -0
- transparent_tor_proxy-0.1.1/ttp/__init__.py +3 -0
- transparent_tor_proxy-0.1.1/ttp/cli.py +471 -0
- transparent_tor_proxy-0.1.1/ttp/dns.py +126 -0
- transparent_tor_proxy-0.1.1/ttp/exceptions.py +36 -0
- transparent_tor_proxy-0.1.1/ttp/firewall.py +156 -0
- transparent_tor_proxy-0.1.1/ttp/resources/__init__.py +0 -0
- transparent_tor_proxy-0.1.1/ttp/resources/selinux/__init__.py +0 -0
- transparent_tor_proxy-0.1.1/ttp/resources/selinux/ttp_tor_policy.te +13 -0
- transparent_tor_proxy-0.1.1/ttp/state.py +120 -0
- transparent_tor_proxy-0.1.1/ttp/system_info.py +145 -0
- transparent_tor_proxy-0.1.1/ttp/tor_control.py +207 -0
- transparent_tor_proxy-0.1.1/ttp/tor_detect.py +230 -0
- transparent_tor_proxy-0.1.1/ttp/tor_install.py +277 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Ignore git directory
|
|
2
|
+
.git/
|
|
3
|
+
.github/
|
|
4
|
+
|
|
5
|
+
# Ignore virtual environments
|
|
6
|
+
.venv/
|
|
7
|
+
venv/
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.pyc
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
|
|
12
|
+
# Ignore massive VM files and snapshots
|
|
13
|
+
**/*.iso
|
|
14
|
+
**/*.qcow2
|
|
15
|
+
**/*.img
|
|
16
|
+
**/vms/
|
|
17
|
+
|
|
18
|
+
# Ignore lock files and logs
|
|
19
|
+
*.lock
|
|
20
|
+
*.log
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: TTP CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["main"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["main"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
name: Lint & Security Scan
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Set up Python 3.12
|
|
17
|
+
uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
cache: "pip"
|
|
21
|
+
|
|
22
|
+
- name: Install Linting Tools
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade pip
|
|
25
|
+
pip install ruff
|
|
26
|
+
|
|
27
|
+
- name: Run Ruff (Python Linting)
|
|
28
|
+
run: ruff check ttp/ tests/
|
|
29
|
+
|
|
30
|
+
- name: Run ShellCheck (Script Linting)
|
|
31
|
+
run: find scripts -name "*.sh" -exec shellcheck {} +
|
|
32
|
+
|
|
33
|
+
unit-tests:
|
|
34
|
+
name: Unit Tests (Python ${{ matrix.python-version }})
|
|
35
|
+
needs: lint
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
strategy:
|
|
38
|
+
matrix:
|
|
39
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
40
|
+
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/checkout@v4
|
|
43
|
+
|
|
44
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
45
|
+
uses: actions/setup-python@v5
|
|
46
|
+
with:
|
|
47
|
+
python-version: ${{ matrix.python-version }}
|
|
48
|
+
cache: "pip"
|
|
49
|
+
|
|
50
|
+
- name: Install dependencies
|
|
51
|
+
run: |
|
|
52
|
+
python -m pip install --upgrade pip
|
|
53
|
+
pip install -e ".[dev]"
|
|
54
|
+
|
|
55
|
+
- name: Run unit tests
|
|
56
|
+
run: pytest tests/ -v -m "not integration"
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.nox/
|
|
42
|
+
.coverage
|
|
43
|
+
.coverage.*
|
|
44
|
+
.cache
|
|
45
|
+
nosetests.xml
|
|
46
|
+
coverage.xml
|
|
47
|
+
*.cover
|
|
48
|
+
*.py.cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
cover/
|
|
52
|
+
|
|
53
|
+
# Translations
|
|
54
|
+
*.mo
|
|
55
|
+
*.pot
|
|
56
|
+
|
|
57
|
+
# Django stuff:
|
|
58
|
+
*.log
|
|
59
|
+
local_settings.py
|
|
60
|
+
db.sqlite3
|
|
61
|
+
db.sqlite3-journal
|
|
62
|
+
|
|
63
|
+
# Flask stuff:
|
|
64
|
+
instance/
|
|
65
|
+
.webassets-cache
|
|
66
|
+
|
|
67
|
+
# Scrapy stuff:
|
|
68
|
+
.scrapy
|
|
69
|
+
|
|
70
|
+
# Sphinx documentation
|
|
71
|
+
docs/_build/
|
|
72
|
+
|
|
73
|
+
# PyBuilder
|
|
74
|
+
.pybuilder/
|
|
75
|
+
target/
|
|
76
|
+
|
|
77
|
+
# Jupyter Notebook
|
|
78
|
+
.ipynb_checkpoints
|
|
79
|
+
|
|
80
|
+
# IPython
|
|
81
|
+
profile_default/
|
|
82
|
+
ipython_config.py
|
|
83
|
+
|
|
84
|
+
# pyenv
|
|
85
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
86
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
87
|
+
# .python-version
|
|
88
|
+
|
|
89
|
+
# pipenv
|
|
90
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
91
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
92
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
93
|
+
# install all needed dependencies.
|
|
94
|
+
#Pipfile.lock
|
|
95
|
+
|
|
96
|
+
# UV
|
|
97
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
98
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
99
|
+
# commonly ignored for libraries.
|
|
100
|
+
#uv.lock
|
|
101
|
+
|
|
102
|
+
# poetry
|
|
103
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
104
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
105
|
+
# commonly ignored for libraries.
|
|
106
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
107
|
+
#poetry.lock
|
|
108
|
+
#poetry.toml
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
113
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
114
|
+
#pdm.lock
|
|
115
|
+
#pdm.toml
|
|
116
|
+
.pdm-python
|
|
117
|
+
.pdm-build/
|
|
118
|
+
|
|
119
|
+
# pixi
|
|
120
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
121
|
+
#pixi.lock
|
|
122
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
123
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
124
|
+
.pixi
|
|
125
|
+
|
|
126
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
127
|
+
__pypackages__/
|
|
128
|
+
|
|
129
|
+
# Celery stuff
|
|
130
|
+
celerybeat-schedule
|
|
131
|
+
celerybeat.pid
|
|
132
|
+
|
|
133
|
+
# SageMath parsed files
|
|
134
|
+
*.sage.py
|
|
135
|
+
|
|
136
|
+
# Package artifacts
|
|
137
|
+
packaging/*.deb
|
|
138
|
+
packaging/*.rpm
|
|
139
|
+
packaging/*.pkg.tar.*
|
|
140
|
+
packaging/*.tar.gz
|
|
141
|
+
packaging/SHA256SUMS.txt
|
|
142
|
+
|
|
143
|
+
# SELinux
|
|
144
|
+
**/*.pp
|
|
145
|
+
|
|
146
|
+
# Other
|
|
147
|
+
.vscode
|
|
148
|
+
tmp
|
|
149
|
+
vms
|
|
150
|
+
|
|
151
|
+
# Environments
|
|
152
|
+
.env
|
|
153
|
+
.envrc
|
|
154
|
+
.venv
|
|
155
|
+
env/
|
|
156
|
+
venv/
|
|
157
|
+
ENV/
|
|
158
|
+
env.bak/
|
|
159
|
+
venv.bak/
|
|
160
|
+
|
|
161
|
+
# Spyder project settings
|
|
162
|
+
.spyderproject
|
|
163
|
+
.spyproject
|
|
164
|
+
|
|
165
|
+
# Rope project settings
|
|
166
|
+
.ropeproject
|
|
167
|
+
|
|
168
|
+
# mkdocs documentation
|
|
169
|
+
/site
|
|
170
|
+
|
|
171
|
+
# mypy
|
|
172
|
+
.mypy_cache/
|
|
173
|
+
.dmypy.json
|
|
174
|
+
dmypy.json
|
|
175
|
+
|
|
176
|
+
# Pyre type checker
|
|
177
|
+
.pyre/
|
|
178
|
+
|
|
179
|
+
# pytype static type analyzer
|
|
180
|
+
.pytype/
|
|
181
|
+
|
|
182
|
+
# Cython debug symbols
|
|
183
|
+
cython_debug/
|
|
184
|
+
|
|
185
|
+
# PyCharm
|
|
186
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
187
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
188
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
189
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
190
|
+
#.idea/
|
|
191
|
+
|
|
192
|
+
# Abstra
|
|
193
|
+
# Abstra is an AI-powered process automation framework.
|
|
194
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
195
|
+
# Learn more at https://abstra.io/docs
|
|
196
|
+
.abstra/
|
|
197
|
+
|
|
198
|
+
# Visual Studio Code
|
|
199
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
200
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
201
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
202
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
203
|
+
# .vscode/
|
|
204
|
+
|
|
205
|
+
# Ruff stuff:
|
|
206
|
+
.ruff_cache/
|
|
207
|
+
|
|
208
|
+
# PyPI configuration file
|
|
209
|
+
.pypirc
|
|
210
|
+
|
|
211
|
+
# Cursor
|
|
212
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
213
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
214
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
215
|
+
.cursorignore
|
|
216
|
+
.cursorindexingignore
|
|
217
|
+
|
|
218
|
+
# Marimo
|
|
219
|
+
marimo/_static/
|
|
220
|
+
marimo/_lsp/
|
|
221
|
+
__marimo__/
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.1] - 2026-05-01
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **CI/CD Automation (Makefile)**: Introduced a root-level `Makefile` to provide a unified entry point for unit tests and multi-distro Docker integration tests (`make verify`).
|
|
13
|
+
- **Call for Contributors**: Added a dedicated section in README.md to attract new developers and experts to the project.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **Repository Reorganization**: Professionalized the project structure:
|
|
18
|
+
- Moved system scripts (`install.sh`, `uninstall.sh`, `restore-network.sh`) to `scripts/`.
|
|
19
|
+
- Consolidated QEMU VM and Docker testing assets into `scripts/vm/`.
|
|
20
|
+
- Integrated internal assets into the Python package namespace under `ttp/resources/`.
|
|
21
|
+
- **Modern Asset Management**: Transitioned from manual path manipulation to `importlib.resources` for accessing the SELinux policy source, ensuring compatibility with all installation methods (pip, venv, native packages).
|
|
22
|
+
- **Documentation Overhaul**: Renamed `TDD.md` to `architecture.md` and updated all documentation to reflect the new architecture and modern packaging standards.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- **Path Robustness**: All shell scripts and Makefiles now resolve the project root absolutely, allowing execution from any working directory without breaking relative paths.
|
|
27
|
+
- **CLI Help Accuracy**: Updated internal CLI help messages to point to the new script locations.
|
|
28
|
+
|
|
29
|
+
## [0.1.0] - 2026-04-27
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- **Exception Hierarchy**: Introduced `TTPError` base class and specialized exceptions (`FirewallError`, `DNSError`, `StateError`, `TorError`) for professional error handling and selective recovery.
|
|
34
|
+
- **CI/CD Pipeline**: Integrated GitHub Actions for automated quality assurance:
|
|
35
|
+
- **Ruff**: Static analysis and linting for Python.
|
|
36
|
+
- **ShellCheck**: Security and syntax auditing for shell scripts.
|
|
37
|
+
- **Pytest**: Automated testing across Python 3.10, 3.11, 3.12, and 3.13.
|
|
38
|
+
- **Resilient Verification**: Tor verification now queries multiple endpoints (`check.torproject.org`, `ipify`, `ifconfig.me`) to prevent failures if one service is down.
|
|
39
|
+
- **Settling Delay**: Added a tactical 2-second delay between Tor reaching 100% bootstrap and the initial IP verification to allow circuits to stabilize.
|
|
40
|
+
- **Native Packaging**: Fully automated build scripts (`build_deb.sh`, `build_rpm.sh`) and PKGBUILD for Arch Linux, including complete metadata and license files.
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
- **Transparent SELinux Compilation**: TTP no longer ships pre-compiled opaque `.pp` binaries. The custom `ttp_tor_policy` module for RHEL/Fedora families is now compiled on-the-fly from its `.te` source during installation.
|
|
45
|
+
- **Hardened DNS Logic**: Transitioned from "best-effort" execution to strict verification. DNS configuration failures now trigger immediate alerts and automatic rollback to prevent IP leaks.
|
|
46
|
+
- **Stateless Firewall Architecture**: Transitioned to a dedicated `inet ttp` table. This eliminates the need for complex system ruleset backups and ensures atomic, risk-free cleanup via `nft destroy`.
|
|
47
|
+
- **Crash-Safe State Management**: Hardened session locking to handle read-only filesystems and unexpected process terminations.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- Fixed a bug where the emergency recovery script `restore-network.sh` was deployed without content.
|
|
52
|
+
- Resolved multiple ShellCheck warnings related to word splitting and unquoted variables in `install.sh` and `uninstall.sh`.
|
|
53
|
+
- Corrected unused imports and linting errors identified by the new CI pipeline.
|
|
54
|
+
|
|
55
|
+
## [0.0.1] - 2026-04-10
|
|
56
|
+
|
|
57
|
+
- Initial internal release candidate.
|
|
58
|
+
- Core logic for firewall redirection (nftables) and DNS management (resolvectl).
|
|
59
|
+
- Basic Typer CLI interface.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Contributing to TTP
|
|
2
|
+
|
|
3
|
+
First off, thank you for considering contributing to TTP! It's people like you who make TTP such a great tool for the privacy community.
|
|
4
|
+
|
|
5
|
+
## ๐ Code of Conduct
|
|
6
|
+
|
|
7
|
+
By participating in this project, you agree to maintain a professional and respectful environment. Please be kind to others.
|
|
8
|
+
|
|
9
|
+
## ๐ How to Report Bugs
|
|
10
|
+
|
|
11
|
+
- **Check existing issues**: Someone might have already reported it.
|
|
12
|
+
- **Use the template**: Provide as much detail as possible.
|
|
13
|
+
- **Diagnostics**: Always include the output of `sudo ttp diagnose` if the bug is related to connectivity or system configuration.
|
|
14
|
+
|
|
15
|
+
## ๐ก How to Propose Features
|
|
16
|
+
|
|
17
|
+
- Open an issue titled `[Feature Request] Your idea`.
|
|
18
|
+
- Explain why this feature is needed and how it fits the project's goal of simplicity and crash-safety.
|
|
19
|
+
|
|
20
|
+
## ๐ ๏ธ Development Setup
|
|
21
|
+
|
|
22
|
+
1. **Clone the repo**:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
git clone https://github.com/onyks-os/TransparentTorProxy.git
|
|
26
|
+
cd TransparentTorProxy
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
2. **Create a virtual environment**:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
python -m venv venv
|
|
33
|
+
source venv/bin/activate
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
3. **Install in editable mode with dev dependencies**:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -e ".[dev]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
4. **Run tests**:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pytest tests/ -v
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## ๐๏ธ Architectural Principles
|
|
49
|
+
|
|
50
|
+
When writing code for TTP, please adhere to these core principles:
|
|
51
|
+
|
|
52
|
+
1. **Single Responsibility Principle (SRP)**: Each module should do one thing. Keep UI logic (`rich`/`typer`) in `cli.py` and system logic in dedicated modules.
|
|
53
|
+
2. **No UI Coupling**: Modules like `tor_control.py` or `firewall.py` should NOT import `rich` or `typer`. Use callbacks or return raw data.
|
|
54
|
+
3. **Atomic Operations**: System changes (like firewall rules) must be atomic. We use `nft -f` to ensure the firewall is never in a half-configured state.
|
|
55
|
+
4. **Crash-Safety**: Always consider what happens if the power goes out mid-operation. Use the lock file system in `state.py` to track changes that need rolling back.
|
|
56
|
+
5. **TDD (Test Driven Development)**: Every new feature or bug fix should include a corresponding unit test in `tests/`.
|
|
57
|
+
|
|
58
|
+
## ๐งช Testing
|
|
59
|
+
|
|
60
|
+
- **Unit Tests**: Must pass on every PR. They are fully mocked and run without root.
|
|
61
|
+
- **Integration Tests**: Should be run in a VM (see `README.md`) to verify actual network behavior.
|
|
62
|
+
|
|
63
|
+
## ๐ Pull Request Process
|
|
64
|
+
|
|
65
|
+
1. Create a branch from `main`.
|
|
66
|
+
2. Ensure all tests pass.
|
|
67
|
+
3. Update the documentation (`README.md`, `TDD.md`) if needed.
|
|
68
|
+
4. Submit the PR and wait for review.
|
|
69
|
+
|
|
70
|
+
Thank you for your help! ๐ก๏ธ
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 onyks-os
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# TTP (Transparent Tor Proxy) - Local CI/CD Pipeline
|
|
3
|
+
# ==============================================================================
|
|
4
|
+
# This Makefile automates the testing process for TTP.
|
|
5
|
+
# It allows developers to quickly run unit tests and isolated integration tests
|
|
6
|
+
# in Docker containers before committing code.
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
# make test - Runs only the fast unit tests locally.
|
|
10
|
+
# make integration-all - Runs full system tests inside Docker (Debian, Fedora, Arch).
|
|
11
|
+
# make verify - Runs EVERYTHING (Unit tests + All integration tests).
|
|
12
|
+
# ==============================================================================
|
|
13
|
+
|
|
14
|
+
# .PHONY tells Make that these are command names, not actual files or directories.
|
|
15
|
+
.PHONY: test integration-debian integration-fedora integration-arch integration-all verify
|
|
16
|
+
|
|
17
|
+
# ------------------------------------------------------------------------------
|
|
18
|
+
# 1. LOCAL UNIT TESTS
|
|
19
|
+
# ------------------------------------------------------------------------------
|
|
20
|
+
# Runs standard Python tests using pytest. This checks the basic logic
|
|
21
|
+
# of the code without needing a real Tor connection or root privileges.
|
|
22
|
+
test:
|
|
23
|
+
@echo "==> Running local Unit Tests..."
|
|
24
|
+
pytest tests/ -v
|
|
25
|
+
|
|
26
|
+
# ------------------------------------------------------------------------------
|
|
27
|
+
# 2. INTEGRATION TESTS (DOCKER)
|
|
28
|
+
# ------------------------------------------------------------------------------
|
|
29
|
+
# These tests run the actual TTP software inside a privileged Docker container.
|
|
30
|
+
# They verify that TTP correctly interacts with systemd, nftables, and Tor.
|
|
31
|
+
#
|
|
32
|
+
# NOTE: Integration tests sometimes fail due to temporary network timeouts
|
|
33
|
+
# (e.g., Tor bootstrap delays). To prevent false negatives, if a test fails,
|
|
34
|
+
# it will automatically wait 5 seconds and retry exactly once.
|
|
35
|
+
|
|
36
|
+
integration-debian:
|
|
37
|
+
@echo "==> Starting integration tests on Debian..."
|
|
38
|
+
./scripts/vm/run_integration_tests.sh debian || (sleep 5 && ./scripts/vm/run_integration_tests.sh debian)
|
|
39
|
+
|
|
40
|
+
integration-fedora:
|
|
41
|
+
@echo "==> Starting integration tests on Fedora..."
|
|
42
|
+
./scripts/vm/run_integration_tests.sh fedora || (sleep 5 && ./scripts/vm/run_integration_tests.sh fedora)
|
|
43
|
+
|
|
44
|
+
integration-arch:
|
|
45
|
+
@echo "==> Starting integration tests on Arch Linux..."
|
|
46
|
+
./scripts/vm/run_integration_tests.sh arch || (sleep 5 && ./scripts/vm/run_integration_tests.sh arch)
|
|
47
|
+
|
|
48
|
+
# A convenience command to run all three integration tests in sequence.
|
|
49
|
+
integration-all: integration-debian integration-fedora integration-arch
|
|
50
|
+
|
|
51
|
+
# ------------------------------------------------------------------------------
|
|
52
|
+
# 3. FULL VERIFICATION PIPELINE
|
|
53
|
+
# ------------------------------------------------------------------------------
|
|
54
|
+
# The ultimate command to run before a git commit.
|
|
55
|
+
# It runs local unit tests first. If they pass, it moves on to Docker tests.
|
|
56
|
+
verify: test integration-all
|
|
57
|
+
@echo "======================================================================"
|
|
58
|
+
@echo "โ
SUCCESS: All local tests and Docker integration tests passed!"
|
|
59
|
+
@echo "โ
You can now proceed with QEMU VM testing or safely commit your code."
|
|
60
|
+
@echo "======================================================================"
|