proxy-lab 1.0.1__py3-none-any.whl

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.
proxy_lab/__init__.py ADDED
File without changes
@@ -0,0 +1,279 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Start a mitmproxy for the Android emulator: pre-flight checks, one-time
4
+ # device trust setup, then mitmdump — alive only while this script is alive.
5
+ #
6
+ # ./android/start-proxy.sh # stop with Ctrl-C (or kill this script)
7
+ # AVD=Pixel_10a PORT=8081 ./android/start-proxy.sh
8
+ #
9
+ # The debug build trusts user-installed CAs (see README), so the mitmproxy CA
10
+ # goes into the user trust store — no root remounts, no /system writes,
11
+ # survives reboots. An emulator booted here keeps running after the proxy stops.
12
+
13
+ set -euo pipefail
14
+
15
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
16
+ ROUTER="$(cd "$SCRIPT_DIR/.." && pwd)/local_router.py"
17
+ CONFIG="${PROXY_LAB_CONFIG:-$(cd "$SCRIPT_DIR/.." && pwd)/domains.yaml}"
18
+ MITMPROXY_VERSION="12.2.3"
19
+ MITMDUMP=(uv tool run --from "mitmproxy==$MITMPROXY_VERSION" mitmdump)
20
+ PORT="${PORT:-8080}"
21
+ DEVICE_PROXY="10.0.2.2:${PORT}" # 10.0.2.2 = the host, from the emulator's view
22
+ CERT="$HOME/.mitmproxy/mitmproxy-ca-cert.pem"
23
+ USER_CA_DIR="/data/misc/user/0/cacerts-added"
24
+ BOOT_TIMEOUT="${BOOT_TIMEOUT:-240}"
25
+ LOCK="${TMPDIR:-/tmp}/start-proxy-${PORT}.lock"
26
+ EMULATOR_LOG=""
27
+
28
+ # Later runs overwrite this. cleanup() only clears the device's proxy setting
29
+ # when no live instance owns the port, so taking over from a running copy
30
+ # doesn't leave the emulator without a proxy.
31
+ printf '%s\n' "$$" >"$LOCK"
32
+
33
+ info() { printf ' %s %-11s %s\n' "$1" "$2" "$3"; }
34
+
35
+ fail() {
36
+ local label="$1" msg="$2" hint
37
+ shift 2
38
+ printf ' ✗ %-11s %s\n' "$label" "$msg" >&2
39
+ for hint in "$@"; do printf ' ↳ %s\n' "$hint" >&2; done
40
+ exit 1
41
+ }
42
+
43
+ find_emulator() {
44
+ adb devices | awk '$2 == "device" && $1 ~ /^emulator-/ { print $1; exit }'
45
+ }
46
+
47
+ wait_boot() {
48
+ local deadline=$((SECONDS + BOOT_TIMEOUT))
49
+ until [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = "1" ]; do
50
+ [ "$SECONDS" -lt "$deadline" ] || fail 'emulator' "not finished booting after ${BOOT_TIMEOUT}s" \
51
+ 'Watch the emulator window, check: adb devices' \
52
+ "Log: ${EMULATOR_LOG:-n/a}"
53
+ sleep 2
54
+ done
55
+ }
56
+
57
+ preflight_tools() {
58
+ local missing=() hints=() c warm_pid t
59
+ for c in adb uv openssl lsof; do
60
+ command -v "$c" >/dev/null 2>&1 || missing+=("$c")
61
+ done
62
+ if [ ${#missing[@]} -gt 0 ]; then
63
+ for c in "${missing[@]}"; do
64
+ # shellcheck disable=SC2016 # hint is copy-paste text — $PATH must stay literal
65
+ case "$c" in
66
+ uv) hints+=('uv: brew install uv — https://docs.astral.sh/uv/getting-started/installation/') ;;
67
+ adb) hints+=('adb: install Android Studio, then export PATH="$PATH:$HOME/Library/Android/sdk/platform-tools" — https://developer.android.com/studio') ;;
68
+ *) hints+=("$c: not found — check your PATH") ;;
69
+ esac
70
+ done
71
+ fail 'tools' "missing: ${missing[*]}" "${hints[@]}"
72
+ fi
73
+ [ -f "$ROUTER" ] ||
74
+ fail 'tools' 'local_router.py missing (repo root)' 'use a complete checkout of this repo'
75
+ [ -f "$CONFIG" ] ||
76
+ fail 'tools' "config missing: $CONFIG" 'use a complete checkout of this repo'
77
+ # Warm uv's mitmproxy cache so start_proxy's up-poll never races a
78
+ # first-time download; announce it only when the run is actually slow.
79
+ "${MITMDUMP[@]}" --version >/dev/null 2>&1 &
80
+ warm_pid=$!
81
+ t=0
82
+ while kill -0 "$warm_pid" 2>/dev/null && [ "$t" -lt 15 ]; do sleep 0.1; t=$((t + 1)); done
83
+ if kill -0 "$warm_pid" 2>/dev/null; then
84
+ info '…' 'mitmproxy' "$MITMPROXY_VERSION via uv — downloading (first run)"
85
+ fi
86
+ wait "$warm_pid" ||
87
+ fail 'tools' "uv could not run mitmproxy $MITMPROXY_VERSION" \
88
+ "check: ${MITMDUMP[*]} --version" \
89
+ 'https://docs.mitmproxy.org/stable/'
90
+ info '✓' 'tools' 'adb, uv, openssl, lsof'
91
+ }
92
+
93
+ ensure_host_ca() {
94
+ if [ ! -f "$CERT" ]; then
95
+ info '…' 'host CA' 'generating ~/.mitmproxy (first run)'
96
+ # Any mitmproxy tool mints the CA on startup; port 0 = OS-assigned, no conflicts.
97
+ "${MITMDUMP[@]}" --listen-port 0 >/dev/null 2>&1 &
98
+ local gen=$!
99
+ for _ in {1..25}; do [ -f "$CERT" ] && break; sleep 0.2; done
100
+ kill "$gen" 2>/dev/null || true
101
+ wait "$gen" 2>/dev/null || true
102
+ [ -f "$CERT" ] || fail 'host CA' 'could not generate the mitmproxy CA' \
103
+ "Run once: ${MITMDUMP[*]}" \
104
+ 'https://docs.mitmproxy.org/stable/concepts/certificates/'
105
+ fi
106
+ # shellcheck disable=SC2088 # display path — the literal ~ is what we mean
107
+ info '✓' 'host CA' '~/.mitmproxy/mitmproxy-ca-cert.pem'
108
+ }
109
+
110
+ boot_emulator() {
111
+ local serial pending avd start root_out deadline
112
+ serial="$(find_emulator)"
113
+ if [ -n "$serial" ]; then
114
+ export ANDROID_SERIAL="$serial"
115
+ info '✓' 'emulator' "$serial running"
116
+ else
117
+ pending="$(adb devices | awk '$1 ~ /^emulator-/ && $2 != "device" { print $1; exit }')"
118
+ if [ -n "$pending" ]; then
119
+ export ANDROID_SERIAL="$pending"
120
+ info '…' 'emulator' "waiting for $pending"
121
+ wait_boot
122
+ info '✓' 'emulator' "$pending ready"
123
+ else
124
+ # shellcheck disable=SC2016 # hint is copy-paste text — $PATH must stay literal
125
+ command -v emulator >/dev/null 2>&1 || fail 'emulator' 'not on PATH' \
126
+ 'Install Android Studio, then: export PATH="$PATH:$HOME/Library/Android/sdk/emulator" — https://developer.android.com/studio'
127
+ if [ -n "${AVD:-}" ]; then
128
+ avd="$AVD"
129
+ emulator -list-avds 2>/dev/null | grep -Fxq "$avd" ||
130
+ fail 'emulator' "AVD '$avd' does not exist" "Available: $(emulator -list-avds 2>/dev/null | paste -sd', ' -)"
131
+ else
132
+ avd="$(emulator -list-avds 2>/dev/null | sed '/^$/d' | head -1)"
133
+ [ -n "$avd" ] || fail 'emulator' 'no AVDs found' \
134
+ 'Create one: Android Studio → Tools → Device Manager (Google APIs image)' \
135
+ 'https://developer.android.com/studio/run/managing-avds'
136
+ fi
137
+ EMULATOR_LOG="${TMPDIR:-/tmp}/emulator-${avd}.log"
138
+ start=$SECONDS
139
+ info '…' 'emulator' "booting $avd"
140
+ { set -m; } 2>/dev/null # own process group, so Ctrl-C doesn't kill the emulator
141
+ emulator -avd "$avd" >"$EMULATOR_LOG" 2>&1 &
142
+ { set +m; } 2>/dev/null
143
+ serial=''
144
+ deadline=$((SECONDS + 60))
145
+ while [ -z "$serial" ]; do
146
+ serial="$(find_emulator)"
147
+ [ -n "$serial" ] && break
148
+ [ "$SECONDS" -lt "$deadline" ] || fail 'emulator' 'never showed up in adb devices' \
149
+ "Log: $EMULATOR_LOG"
150
+ sleep 1
151
+ done
152
+ export ANDROID_SERIAL="$serial"
153
+ wait_boot
154
+ info '✓' 'emulator' "$avd booted in $((SECONDS - start))s"
155
+ fi
156
+ fi
157
+ # Root is only needed to install the CA into the user trust store.
158
+ root_out="$(adb root 2>&1 || true)"
159
+ case "$root_out" in
160
+ *'cannot run as root'*)
161
+ fail 'root' 'this AVD image refuses adb root' \
162
+ 'Use a "Google APIs" image, not "Google APIs Play Store" — see README.md, Requirements' ;;
163
+ esac
164
+ adb wait-for-device
165
+ }
166
+
167
+ ensure_device_ca() {
168
+ local hash remote out
169
+ hash="$(openssl x509 -inform PEM -subject_hash_old -in "$CERT" | head -1)" ||
170
+ fail 'device CA' "could not hash $CERT"
171
+ remote="$USER_CA_DIR/${hash}.0"
172
+ if adb shell "test -f $remote" 2>/dev/null; then
173
+ info '✓' 'device CA' "${hash}.0 in user store"
174
+ return 0
175
+ fi
176
+ info '…' 'device CA' "installing ${hash}.0 — one reboot, once per AVD"
177
+ adb shell "mkdir -p $USER_CA_DIR && chmod 755 $USER_CA_DIR" ||
178
+ fail 'device CA' "cannot create $USER_CA_DIR" 'check: adb root'
179
+ out="$(adb push "$CERT" "$remote" 2>&1)" ||
180
+ fail 'device CA' "could not push ${hash}.0" "${out##*$'\n'}"
181
+ out="$(adb shell "chmod 644 $remote && restorecon $remote $USER_CA_DIR" 2>&1)" || {
182
+ adb shell "rm -f $remote" >/dev/null 2>&1 || true # never leave an unlabeled cert behind
183
+ fail 'device CA' 'permissions/SELinux label failed (rolled back)' "${out##*$'\n'}"
184
+ }
185
+ adb reboot
186
+ wait_boot
187
+ adb root >/dev/null 2>&1 || true # adbd drops back to shell after a reboot,
188
+ adb wait-for-device # and shell can't read the user trust store
189
+ adb shell "test -f $remote" 2>/dev/null ||
190
+ fail 'device CA' 'cert did not survive reboot' "check: adb root && adb shell ls $USER_CA_DIR"
191
+ info '✓' 'device CA' "${hash}.0 trusted"
192
+ }
193
+
194
+ set_device_proxy() {
195
+ local current
196
+ current="$(adb shell settings get global http_proxy 2>/dev/null | tr -d '\r')" || current=""
197
+ if [ "$current" = "$DEVICE_PROXY" ]; then
198
+ info '✓' 'proxy' "$DEVICE_PROXY"
199
+ else
200
+ adb shell settings put global http_proxy "$DEVICE_PROXY" ||
201
+ fail 'proxy' "could not set $DEVICE_PROXY" 'try: adb shell settings get global http_proxy'
202
+ info '✓' 'proxy' "$DEVICE_PROXY set"
203
+ fi
204
+ }
205
+
206
+ free_port() {
207
+ local pid args pids
208
+ local stale=() foreign=()
209
+ pids="$(lsof -t -nP -iTCP:"$PORT" -sTCP:LISTEN 2>/dev/null || true)"
210
+ while IFS= read -r pid; do
211
+ [ -n "$pid" ] || continue
212
+ args="$(ps -p "$pid" -o args= 2>/dev/null || true)"
213
+ case "$args" in
214
+ *mitmdump*) stale+=("$pid") ;;
215
+ *) foreign+=("$pid ${args:-unknown}") ;;
216
+ esac
217
+ done <<<"$pids"
218
+ if [ ${#foreign[@]} -gt 0 ]; then
219
+ fail "port $PORT" "used by: ${foreign[*]}" \
220
+ 'Stop that process, or run: PORT=<other> ./android/start-proxy.sh'
221
+ fi
222
+ if [ ${#stale[@]} -gt 0 ]; then
223
+ for pid in "${stale[@]}"; do kill "$pid" 2>/dev/null || true; done
224
+ for _ in {1..15}; do # give them a moment before forcing
225
+ lsof -t -nP -iTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1 || break
226
+ sleep 0.2
227
+ done
228
+ for pid in "${stale[@]}"; do kill -9 "$pid" 2>/dev/null || true; done
229
+ lsof -t -nP -iTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1 &&
230
+ fail "port $PORT" 'still busy after stopping stale proxies' "try: lsof -nP -iTCP:$PORT"
231
+ info '✓' "port $PORT" "stopped ${#stale[@]} previous run(s)"
232
+ else
233
+ info '✓' "port $PORT" 'free'
234
+ fi
235
+ }
236
+
237
+ cleanup() {
238
+ trap - EXIT INT TERM
239
+ kill "$PROXY_PID" 2>/dev/null || true
240
+ wait "$PROXY_PID" 2>/dev/null || true
241
+ local owner=''
242
+ owner="$(cat "$LOCK" 2>/dev/null || true)"
243
+ if [ -z "$owner" ] || [ "$owner" = "$$" ] || ! kill -0 "$owner" 2>/dev/null; then
244
+ adb shell settings delete global http_proxy >/dev/null 2>&1 || true
245
+ info '✓' 'mitmdump' 'stopped — device proxy cleared'
246
+ else
247
+ info '✓' 'mitmdump' "stopped — instance $owner owns the port now"
248
+ fi
249
+ }
250
+
251
+ start_proxy() {
252
+ "${MITMDUMP[@]}" --listen-host 0.0.0.0 --listen-port "$PORT" --set ssl_insecure=true \
253
+ -s "$ROUTER" &
254
+ PROXY_PID=$!
255
+ trap cleanup EXIT
256
+ trap 'cleanup; exit 130' INT
257
+ trap 'cleanup; exit 143' TERM
258
+ local up=''
259
+ for _ in {1..20}; do
260
+ lsof -t -nP -iTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1 && { up=1; break; }
261
+ kill -0 "$PROXY_PID" 2>/dev/null || break
262
+ sleep 0.25
263
+ done
264
+ if [ -z "$up" ]; then
265
+ wait "$PROXY_PID" 2>/dev/null || true
266
+ fail 'mitmdump' "exited before listening on :$PORT" 'the output above says why'
267
+ fi
268
+ info '✓' 'mitmdump' "0.0.0.0:$PORT — Ctrl-C to stop"
269
+ printf '\n'
270
+ wait "$PROXY_PID"
271
+ }
272
+
273
+ preflight_tools
274
+ ensure_host_ca
275
+ boot_emulator
276
+ ensure_device_ca
277
+ free_port
278
+ set_device_proxy
279
+ start_proxy
proxy_lab/cli.py ADDED
@@ -0,0 +1,40 @@
1
+ # Entry point for `uvx --from git+https://github.com/kibotu/proxy-lab.sh proxy-lab`.
2
+ # The actual work stays in android/ and ios/ — this only dispatches and passes
3
+ # the domains file through.
4
+ import argparse
5
+ import os
6
+ from pathlib import Path
7
+
8
+ PACKAGE_DIR = Path(__file__).resolve().parent
9
+
10
+
11
+ def main() -> None:
12
+ parser = argparse.ArgumentParser(
13
+ prog="proxy-lab",
14
+ description="Start a mitmproxy for the Android emulator or the iOS simulator.",
15
+ )
16
+ commands = parser.add_subparsers(dest="command", required=True)
17
+ start = commands.add_parser(
18
+ "start", help="run the platform's proxy — stop with Ctrl-C"
19
+ )
20
+ start.add_argument(
21
+ "platform", choices=("android", "ios"), help="which device to proxy"
22
+ )
23
+ start.add_argument(
24
+ "config",
25
+ nargs="?",
26
+ metavar="domains.yml",
27
+ help="domain list to log (default: the bundled domains.yaml)",
28
+ )
29
+ args = parser.parse_args()
30
+
31
+ if args.config is not None:
32
+ config = Path(args.config).expanduser()
33
+ if not config.is_file():
34
+ parser.error(f"config not found: {config}")
35
+ os.environ["PROXY_LAB_CONFIG"] = str(config.resolve())
36
+
37
+ script = PACKAGE_DIR / args.platform / "start-proxy.sh"
38
+ # exec: this process becomes the script, so Ctrl-C and the exit code
39
+ # propagate exactly as if the script had been run directly.
40
+ os.execvp("bash", ["bash", str(script)])
proxy_lab/domains.yaml ADDED
@@ -0,0 +1,5 @@
1
+ # Host suffixes logged as [local_router] … — read by local_router.py,
2
+ # shared by android/ and ios/. Leading dot = subdomains only;
3
+ # without it ("example.com") the apex matches too.
4
+ domains:
5
+ - ".example.com"
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Start mitmdump for the iOS simulator with the shared local_router addon.
4
+ # The simulator shares the host's network — no device changes, no root.
5
+ # Stop with Ctrl-C (or kill this script); uv takes the proxy down with it.
6
+ #
7
+ # ./ios/start-proxy.sh # PORT=8081 ./ios/start-proxy.sh
8
+ #
9
+ # Point your debug build at localhost:8080. If HTTPS reports a trust error,
10
+ # install the CA once in the simulator: http://mitm.it
11
+
12
+ set -euo pipefail
13
+
14
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
15
+ ROUTER="$(cd "$SCRIPT_DIR/.." && pwd)/local_router.py"
16
+ CONFIG="${PROXY_LAB_CONFIG:-$(cd "$SCRIPT_DIR/.." && pwd)/domains.yaml}"
17
+ PORT="${PORT:-8080}"
18
+ MITMPROXY_VERSION="12.2.3"
19
+ MITMDUMP=(uv tool run --from "mitmproxy==$MITMPROXY_VERSION" mitmdump)
20
+
21
+ fail() {
22
+ printf ' ✗ %s\n' "$1" >&2
23
+ exit 1
24
+ }
25
+
26
+ command -v uv >/dev/null ||
27
+ fail 'uv not found — brew install uv — https://docs.astral.sh/uv/getting-started/installation/'
28
+ [ -f "$ROUTER" ] ||
29
+ fail "router missing: $ROUTER — use a complete checkout of this repo"
30
+ [ -f "$CONFIG" ] ||
31
+ fail "config missing: $CONFIG — use a complete checkout of this repo, or pass an existing domains file"
32
+
33
+ # exec: this script becomes mitmdump (via uv), so killing it kills the proxy.
34
+ exec "${MITMDUMP[@]}" \
35
+ --listen-host 0.0.0.0 \
36
+ --listen-port "$PORT" \
37
+ --set ssl_insecure=true \
38
+ -s "$ROUTER"
@@ -0,0 +1,26 @@
1
+ # Shared by android/ and ios/ — loads the domain list from domains.yaml
2
+ # once at startup. Edit domains.yaml, not this file.
3
+ import os
4
+ from pathlib import Path
5
+
6
+ import ruamel.yaml
7
+ from mitmproxy import http
8
+
9
+ # PROXY_LAB_CONFIG is set by the proxy-lab CLI when a domains file is passed;
10
+ # without it, the domains.yaml next to this file (repo checkout or package).
11
+ CONFIG = Path(os.environ.get("PROXY_LAB_CONFIG") or Path(__file__).with_name("domains.yaml"))
12
+
13
+ with CONFIG.open() as fh:
14
+ _config = ruamel.yaml.YAML(typ="safe").load(fh) or {}
15
+ LOCAL_DOMAIN_SUFFIXES = tuple(_config["domains"])
16
+
17
+
18
+ def request(flow: http.HTTPFlow) -> None:
19
+ host = flow.request.pretty_host
20
+
21
+ if not any(host.endswith(s) for s in LOCAL_DOMAIN_SUFFIXES):
22
+ return
23
+
24
+ # flush: this marker must be visible the moment the request happens —
25
+ # stdout is block-buffered when redirected (CI logs, | grep pipelines).
26
+ print(f"[local_router] {flow.request.scheme}://{host}{flow.request.path}", flush=True)
@@ -0,0 +1,284 @@
1
+ Metadata-Version: 2.5
2
+ Name: proxy-lab
3
+ Version: 1.0.1
4
+ Summary: One command to see your app's HTTPS traffic: a mitmproxy setup for the Android emulator and the iOS simulator.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+
10
+ # proxy-lab.sh
11
+
12
+ [![CI](https://github.com/kibotu/proxy-lab.sh/actions/workflows/ci.yml/badge.svg)](https://github.com/kibotu/proxy-lab.sh/actions/workflows/ci.yml)
13
+ [![Release](https://github.com/kibotu/proxy-lab.sh/actions/workflows/release.yml/badge.svg)](https://github.com/kibotu/proxy-lab.sh/actions/workflows/release.yml)
14
+ [![GitHub Release](https://img.shields.io/github/v/release/kibotu/proxy-lab.sh)](https://github.com/kibotu/proxy-lab.sh/releases)
15
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
16
+ [![Platform: macOS](https://img.shields.io/badge/platform-macOS-lightgrey)](#requirements)
17
+ [![Shell](https://img.shields.io/badge/shell-bash-informational)](#project-layout)
18
+
19
+ **See your app's HTTPS traffic with one command.** proxy-lab.sh starts [mitmproxy](https://www.mitmproxy.org/) for the **Android emulator** and the **iOS simulator**, and it does the certificate work for you. No `/system` remount, no Magisk, no stale proxy setting.
20
+
21
+ ```bash
22
+ # iOS
23
+ uvx --from git+https://github.com/kibotu/proxy-lab.sh proxy-lab start ios domains.yml
24
+
25
+ # android
26
+ uvx --from git+https://github.com/kibotu/proxy-lab.sh proxy-lab start android domains.yml
27
+ ```
28
+
29
+ ![proxy-lab.sh terminal output showing intercepted HTTPS requests](docs/teaser.png)
30
+
31
+ ## Contents
32
+
33
+ - [Quickstart](#quickstart) — [Android](#android), [iOS](#ios)
34
+ - [Choose the domains to log](#choose-the-domains-to-log)
35
+ - [Options](#options)
36
+ - [Run from a clone](#run-from-a-clone)
37
+ - [Requirements](#requirements)
38
+ - [Troubleshooting](#troubleshooting)
39
+ - [How it works](#how-it-works)
40
+ - [Why Android needs this](#why-android-needs-this)
41
+ - [Scope and alternatives](#scope-and-alternatives)
42
+ - [Versions and releases](#versions-and-releases)
43
+ - [Project layout](#project-layout)
44
+ - [Contributing](#contributing)
45
+ - [License](#license)
46
+ - [Support](#support)
47
+
48
+ ## Quickstart
49
+
50
+ Install [uv](https://docs.astral.sh/uv/). It runs mitmproxy at a pinned version for you, so there is no Python setup and nothing global to install:
51
+
52
+ ```bash
53
+ brew install uv
54
+ ```
55
+
56
+ Then follow the path for your platform. The first run takes a few minutes, because it downloads mitmproxy and prepares the device. Later runs start in seconds.
57
+
58
+ ### Android
59
+
60
+ **1. Let your debug build trust user-installed certificates.** Android apps ignore them by default, so your app must opt in. Add `res/xml/network_security_config.xml` to your **debug** source set:
61
+
62
+ ```xml
63
+ <?xml version="1.0" encoding="utf-8"?>
64
+ <network-security-config>
65
+ <debug-overrides>
66
+ <trust-anchors>
67
+ <certificates src="user" />
68
+ </trust-anchors>
69
+ </debug-overrides>
70
+ </network-security-config>
71
+ ```
72
+
73
+ Point to it from the `<application>` tag in `AndroidManifest.xml`:
74
+
75
+ ```xml
76
+ <application
77
+ android:networkSecurityConfig="@xml/network_security_config"
78
+ ... >
79
+ ```
80
+
81
+ `<debug-overrides>` applies only when the build is debuggable, so it cannot weaken a release build. Keep it in the debug source set anyway. See the [network security config docs](https://developer.android.com/privacy-and-security/security-config) and [why this is necessary](#why-android-needs-this).
82
+
83
+ **2. Start the proxy:**
84
+
85
+ ```bash
86
+ uvx --from git+https://github.com/kibotu/proxy-lab.sh@ proxy-lab start android
87
+ ```
88
+
89
+ The script checks your tools, reuses a running emulator or boots one, installs the mitmproxy CA into the user trust store, and sets the emulator proxy to `10.0.2.2:8080`. The CA install reboots the emulator one time per AVD.
90
+
91
+ **3. Start your debug build.** Requests print in the terminal as they happen.
92
+
93
+ **4. Press `Ctrl-C`.** The proxy stops and the emulator's proxy setting is cleared. The emulator keeps running.
94
+
95
+ > Use a **Google APIs** AVD image. "Google APIs Play Store" images refuse `adb root`, and the CA install needs it.
96
+
97
+ ### iOS
98
+
99
+ **1. Start the proxy:**
100
+
101
+ ```bash
102
+ uvx --from git+https://github.com/kibotu/proxy-lab.sh@ proxy-lab start ios
103
+ ```
104
+
105
+ **2. Send the simulator's traffic through it.** The simulator uses your Mac's network stack, so it has no proxy setting of its own. Pick one:
106
+
107
+ - **System proxy** — **System Settings → Network → (your interface) → Details → Proxies**. Turn on *Web proxy* and *Secure web proxy*, both `127.0.0.1` port `8080`. Every app on the Mac goes through the proxy while this is on.
108
+ - **App only** — point your debug build at `localhost:8080`, for example with `URLSessionConfiguration.connectionProxyDictionary`.
109
+
110
+ **3. Trust the CA, one time per simulator:**
111
+
112
+ 1. Open [`mitm.it`](http://mitm.it) in the simulator's Safari and download the profile. The page is served by the proxy, so step 2 must work first.
113
+ 2. Install it: **Settings → General → VPN & Device Management**.
114
+ 3. Turn on full trust: **Settings → General → About → Certificate Trust Settings**.
115
+
116
+ **4. Start your app.** Press `Ctrl-C` to stop the proxy.
117
+
118
+ No root, no reboot, nothing to undo in the app.
119
+
120
+ ## Choose the domains to log
121
+
122
+ Every request goes through the proxy and appears in the mitmdump output. On top of that, hosts you list get a `[local_router]` line, which makes your own API easy to find in a busy log.
123
+
124
+ Write your list in a YAML file:
125
+
126
+ ```yaml
127
+ domains:
128
+ - ".example.com" # subdomains only: api.example.com yes, example.com no
129
+ - "acme.dev" # the host itself and its subdomains
130
+ ```
131
+
132
+ Entries match the end of the host name. A leading dot excludes the apex domain.
133
+
134
+ Pass the file as the last argument:
135
+
136
+ ```bash
137
+ uvx --from git+https://github.com/kibotu/proxy-lab.sh@ proxy-lab start android my-domains.yml
138
+ ```
139
+
140
+ Without an argument you get the [bundled `domains.yaml`](domains.yaml), which lists `.example.com` only. Keep your own file next to your project and commit it, so the team logs the same hosts.
141
+
142
+ ## Options
143
+
144
+ The command surface is one line:
145
+
146
+ ```
147
+ proxy-lab start <android|ios> [domains.yml]
148
+ ```
149
+
150
+ Environment variables cover the rest:
151
+
152
+ | Variable | Default | Effect |
153
+ | --- | --- | --- |
154
+ | `PORT` | `8080` | Port for mitmdump on the host. Android points the emulator at `10.0.2.2:$PORT`. |
155
+ | `AVD` | first entry of `emulator -list-avds` | AVD to boot when none is running. Android only. |
156
+ | `BOOT_TIMEOUT` | `240` | Seconds to wait for the emulator to finish booting. Android only. |
157
+ | `PROXY_LAB_CONFIG` | bundled `domains.yaml` | Path to your domains file. Same effect as the argument above. |
158
+
159
+ ```bash
160
+ PORT=8081 AVD=Pixel_10a uvx --from git+https://github.com/kibotu/proxy-lab.sh@ proxy-lab start android
161
+ ```
162
+
163
+ If you run this daily, install the command once and keep the line short:
164
+
165
+ ```bash
166
+ uv tool install git+https://github.com/kibotu/proxy-lab.sh@
167
+ proxy-lab start android
168
+ ```
169
+
170
+ Move to a newer version with `uv tool install --force git+https://github.com/kibotu/proxy-lab.sh@<X.Y.Z>`.
171
+
172
+ ## Run from a clone
173
+
174
+ Use a clone when you change the scripts or the addon:
175
+
176
+ ```bash
177
+ git clone https://github.com/kibotu/proxy-lab.sh
178
+ cd proxy-lab.sh
179
+ ./android/start-proxy.sh # or ./ios/start-proxy.sh
180
+ ```
181
+
182
+ The scripts are the same code that `uvx` runs. Edit [`domains.yaml`](domains.yaml) in place, or set `PROXY_LAB_CONFIG`. All environment variables above apply.
183
+
184
+ ## Requirements
185
+
186
+ - **macOS.** The iOS Simulator needs Xcode, and Xcode needs macOS. The Android script uses portable tools only, so Linux probably works, but nobody tests it there.
187
+ - **[uv](https://docs.astral.sh/uv/getting-started/installation/)** — `brew install uv`. It runs [mitmproxy](https://www.mitmproxy.org/) at a pinned version. No Python install of your own is necessary.
188
+ - **Android:** [Android Studio](https://developer.android.com/studio) with `adb` and `emulator` on your `$PATH`, plus a Google APIs AVD. Your debug build must trust user CAs, as shown in [the Android quickstart](#android).
189
+ - **iOS:** Xcode.
190
+
191
+ The Android script also uses `openssl` and `lsof`, which macOS ships. It tells you if something is missing, and it prints the command that fixes it.
192
+
193
+ ## Troubleshooting
194
+
195
+ The scripts fail loudly, and the error line usually contains the answer. These are the recurring ones:
196
+
197
+ - **`adbd cannot run as root in production builds`** — the AVD uses a Play Store image. Check with `grep image.sysdir ~/.android/avd/<AVD>.avd/config.ini` and create a Google APIs AVD instead.
198
+ - **`net::ERR_CERT_AUTHORITY_INVALID`** — the app does not trust the CA. Confirm the [network security config](#android) is in the build you are running, and that it is a debug build. To reinstall the certificate: `adb root && adb shell rm /data/misc/user/0/cacerts-added/<hash>.0`, then run the script again. Restart the app afterwards, because a running process keeps its trust anchors.
199
+ - **Requests time out** — the proxy stopped while the emulator still points at it. `adb shell settings get global http_proxy` prints `10.0.2.2:8080` when the script runs, and `null` after a clean exit. If it prints an address and nothing listens, start the script again, or clear it with `adb shell settings delete global http_proxy`.
200
+ - **"No internet connection" while proxied** — Android's connectivity check does not trust user CAs, so the system reports partial connectivity. Your app traffic works. Ignore it.
201
+ - **Nothing shows up on iOS** — the simulator does not use the proxy. Go back to [step 2 of the iOS quickstart](#ios).
202
+ - **No `[local_router]` lines** — the host is not in the domains file in use. See [Choose the domains to log](#choose-the-domains-to-log).
203
+
204
+ Still stuck? [Open an issue](https://github.com/kibotu/proxy-lab.sh/issues) with the exact error line.
205
+
206
+ ## How it works
207
+
208
+ ```
209
+ Android emulator ──▶ 10.0.2.2:$PORT ─┐
210
+ ├──▶ mitmdump on the host ──▶ upstream, or 127.0.0.1 for local dev domains
211
+ iOS simulator ─────▶ 127.0.0.1:$PORT ┘
212
+ ```
213
+
214
+ `mitmdump` terminates TLS with its own CA, prints what it sees, and forwards the request. `10.0.2.2` is the host address as the emulator sees it ([emulator networking](https://developer.android.com/studio/run/emulator-networking)). Name resolution happens on the host, so an `/etc/hosts` entry sends a dev domain to a server on your machine.
215
+
216
+ `local_router.py` is a [mitmproxy addon](https://docs.mitmproxy.org/stable/addons/overview/). The name promises more than it delivers: it logs matching hosts, it does not route. Both platforms load it.
217
+
218
+ ## Why Android needs this
219
+
220
+ Since Android 7, apps that target API 24 and higher ignore user-installed CAs unless they opt in ([Android Developers Blog](https://android-developers.googleblog.com/2016/07/changes-to-trusted-certificate.html)). The common answer is to put the CA in the *system* store. That answer keeps getting more expensive:
221
+
222
+ - The [mitmproxy guide](https://docs.mitmproxy.org/stable/howto/install-system-trusted-ca-android/) hashes the certificate by hand, remounts `/system`, and needs `-writable-system` on every boot.
223
+ - Android 14 moved the store into the immutable Conscrypt APEX ([AOSP](https://source.android.com/docs/core/ota/modular-system/conscrypt)). That mount is private per process, so even root edits stay invisible to apps ([HTTP Toolkit](https://httptoolkit.com/blog/android-14-breaks-system-certificate-installation/)). The known workarounds are a Magisk module, or `nsenter` into Zygote's mount namespace.
224
+
225
+ proxy-lab.sh takes the other door: your debug build opts into the **user** store, and the script installs the CA there (`/data/misc/user/0/cacerts-added/`). That needs `adb root` once and one reboot per AVD. The certificate survives later reboots. Release builds are unaffected.
226
+
227
+ The second half of the problem is routing. The emulator must point at `10.0.2.2`, not `localhost`, through a setting that goes stale in silence. The script writes that setting after it owns the port, and clears it on exit.
228
+
229
+ iOS has neither problem. The iOS side is a thin mitmdump wrapper, and this repo will not pretend otherwise.
230
+
231
+ What you get for the Android run:
232
+
233
+ | Step | Behaviour |
234
+ | --- | --- |
235
+ | Tools | Checks `adb`, `uv`, `openssl`, `lsof` and the addon, with install hints. Warms the mitmproxy download. |
236
+ | Host CA | Generates `~/.mitmproxy/` on the first run. |
237
+ | Emulator | Reuses a running emulator, or boots one and waits for it. |
238
+ | Device CA | Installs the certificate if it is missing. One reboot, one time per AVD. Rolls back a failed install. |
239
+ | Port | Stops stale proxies from earlier runs. Refuses to touch a process it does not own. |
240
+ | Proxy setting | Writes `10.0.2.2:$PORT` after the port is confirmed. Clears it on exit. |
241
+
242
+ Re-run it as often as you want. The steps are idempotent.
243
+
244
+ ## Scope and alternatives
245
+
246
+ Out of scope, on purpose:
247
+
248
+ - **Physical devices.** Emulator and simulator only.
249
+ - **Release builds.** They do not trust user CAs, and that is correct.
250
+ - **Certificate pinning.** A pinning app rejects the proxy CA. Turn pinning off in debug builds, or use a pin bypass.
251
+ - **Response rewriting and mocking.** mitmproxy does all of that. Write your own [addon](https://docs.mitmproxy.org/stable/addons/overview/) next to `local_router.py`.
252
+
253
+ If you need those, or a GUI, look at [HTTP Toolkit](https://httptoolkit.com/), [Proxyman](https://proxyman.io/), or [Charles](https://www.charlesproxy.com/). proxy-lab.sh stays a small, scriptable, reviewable pile of bash instead.
254
+
255
+ ## Versions and releases
256
+
257
+ - **mitmproxy** is pinned to `12.2.3` inside the scripts, so the whole team sees the same behaviour.
258
+ - **proxy-lab.sh** is pinned by you: `@1.0.0` in the `uvx` command. Without a tag you get `main`. Put the pinned command in your project README or a Makefile, and the team runs one version.
259
+ - Tags are `X.Y.Z`, with no `v` prefix. A tag push builds the wheel and sdist at that version and publishes a [GitHub Release](https://github.com/kibotu/proxy-lab.sh/releases). [CHANGELOG.md](CHANGELOG.md) has the per-version detail.
260
+
261
+ ## Project layout
262
+
263
+ | Path | What it is |
264
+ | --- | --- |
265
+ | [`android/start-proxy.sh`](android/start-proxy.sh) | The full Android flow: checks, CA, emulator, port, proxy setting, mitmdump. |
266
+ | [`ios/start-proxy.sh`](ios/start-proxy.sh) | mitmdump with the shared addon. |
267
+ | [`local_router.py`](local_router.py) | mitmproxy addon. Logs hosts from the domains file. |
268
+ | [`domains.yaml`](domains.yaml) | Default host list. |
269
+ | [`proxy_lab/cli.py`](proxy_lab/cli.py) | The `proxy-lab` entry point for `uvx`. Dispatches to the scripts. |
270
+ | [`.github/workflows/ci.yml`](.github/workflows/ci.yml) | shellcheck, plus a proxy smoke test on macOS and Ubuntu. |
271
+
272
+ ## Contributing
273
+
274
+ Issues and pull requests are welcome, in particular real failure modes the pre-flight checks miss.
275
+
276
+ Run [shellcheck](https://www.shellcheck.net/) on the scripts before you push, because CI does. Add notable changes to [CHANGELOG.md](CHANGELOG.md) under `Unreleased`.
277
+
278
+ ## License
279
+
280
+ Apache License 2.0. See [LICENSE](LICENSE).
281
+
282
+ ## Support
283
+
284
+ If proxy-lab.sh saved you an afternoon, or one `ERR_CERT_AUTHORITY_INVALID` hunt, consider [buying me a coffee](https://buymeacoffee.com/kibotu).
@@ -0,0 +1,11 @@
1
+ proxy_lab/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ proxy_lab/cli.py,sha256=CTzYd66l3gsS6C3R-FklSA8gZrHR_evDsqCy3HsxZOg,1432
3
+ proxy_lab/android/start-proxy.sh,sha256=xave6zaFQgPAYR_CxODTDzDTQNDAybOVPQN8BHk3kXo,10913
4
+ proxy_lab/domains.yaml,sha256=hC1-omwcxDROW1dlgp__H2tzlYVRzngKF3iXrCS4H3Q,215
5
+ proxy_lab/ios/start-proxy.sh,sha256=HIhzOBQXdbV9pgfMOwrXP2vh_bwZZ5tRgfGY_xRisY0,1372
6
+ proxy_lab/local_router.py,sha256=TKTbtU3k6Ps8m7JJ1U1nyuJFqb3tOxx_LMpNFMBSWr0,999
7
+ proxy_lab-1.0.1.dist-info/METADATA,sha256=woJQopnQfvm0klyYK8nfgDlzvRjkX8aNSe6JQiZ_Y5I,15158
8
+ proxy_lab-1.0.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
9
+ proxy_lab-1.0.1.dist-info/entry_points.txt,sha256=0VKG3FLp8EEJmOQhGxjwD4v3ZULib-9ECtl2G9QDQ0I,49
10
+ proxy_lab-1.0.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
11
+ proxy_lab-1.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ proxy-lab = proxy_lab.cli:main
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.