Skip to content

6.4.0: Android open ports for TCP from the tunnel (#225) - #226

Merged
compot-dev merged 2 commits into
masterfrom
android-open-ports
Dec 2, 2026
Merged

compot-dev merged 2 commits into
masterfrom
android-open-ports

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Closes #225.

Since #187 the Android library let a new TCP connection from the tunnel through only to the app's own web port. A TV box with the camex app had no web port, so another client could reach it neither over adb nor over ssh: Connection refused, and the app logged TCP from the tunnel refused … not this app's web port.

  • Library: a new value open_ports, labelled Open ports (TCP from the tunnel). It holds up to 16 ports split by commas or blanks. A new connection to a listed port passes whoever listens there, because adbd and an ssh app are not the app's own sockets. The web port keeps its owner check even when it is listed. Other ports are still refused. An app that does not set the key opens none, as before. The list goes to the JNI gate with each start, not into camex's command line: camex on Linux has no gate.
  • camex app: the field is in the CAMEX section and starts as 5555, 2222, for adb over the network and SimpleSSH and similar (an app cannot listen below 1024). Empty closes all of them.
  • Settings link: o=5555,2222, checked and shown by the link's page as well. An empty o= closes all ports.
  • Docs: android.md (the field, the link's o) and android-library.md (the value, the gate, a note on client_isolation and adb).
  • Tests: unit tests for the values and the link, the jsdom test of the link's page, and an open port in the emulator test of the library. That test's network step now sets weak_name = yes for its short network name, which a server refuses without it since 5.0.

Checked locally:

  • gradle testReleaseUnitTest lintDebug assembleRelease, and the native build with -Werror.
  • docker/test-connect-page.sh passes.
  • tests/android/tunnel-e2e.sh 34: 18 passed, 0 failed. Open port 8083 with the shell's nc listening is reached; the app's other port 8081 and port 8082 (the web port, with another process listening) are still refused.
  • The camex app on the API 34 emulator, against a camex server and a Linux client in Docker:
    • with the default list, adbd on 5555 is reached and other ports are refused;
    • a link with o=8099%2C5555 fills the field, and Save stores it;
    • an empty o= closes 5555 after the next start.

6.4.0: a new setting (MINOR).

…r listens (adb 5555, ssh 2222 in the camex app; o= in the link) (#225)
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

6.4.0: Android open ports for TCP from the tunnel (#225)

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Adds open_ports setting: new TCP connections from the tunnel reach listed ports whoever listens.
• camex app starts with 5555 and 2222 for adb over network and SSH apps.
• Settings link gains o= parameter; web port keeps its owner check; docs and tests updated.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed settings, link parsing, service handoff and native gate jointly implement one end-to-end behavior: a tunnel peer reaches a configured TCP service on the Android device.
  • The web listener check is a preserved branch of this same tunnel access capability, not an independent functional scope.
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Compatibility cases

  • Before, non-web TCP SYNs were refused and only the app-owned web listener could pass.
  • After, a validated multi-port list is parsed, persisted or imported, transferred through the service restart loop, and checked in native code, while the web-port owner rule remains dominant.
  • The new correctness conditions are that malformed lists remain rejected, the active native run uses the matching list after restarts, open non-web ports bypass only the intended owner check, and all other ports remain refused.
  • These are interacting branches and compatibility cases across old clients with no key, app defaults, empty values, and connect-link imports; the implementation uses existing validation and tunnel machinery rather than introducing a new algorithm.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the changed configuration or Java/native handoff regresses, configured adb or SSH-style services may become unreachable through the tunnel; reverting the code restores admission for future runs.
  • A configured port is intentionally allowed to reach whichever local process listens there, but no source-supported fault shows unintended additional ports being admitted.
  • A code revert restores the previous gate behavior for new runs.
  • Existing tunnel sessions must reconnect or restart to receive the reverted configuration; no persistent data repair is required.
Assessed commit bbfc474
Diagram

graph TD
  A["Settings link o="] --> B["Values.openPorts"] --> C["CamexVpnService"] --> D["JNI TCP gate"]
  G["Tunnel client"] --> D
  D --> E["Web port: owner check"]
  D --> F["Open port: any listener"]
Loading
High-Level Assessment

The PR's approach is sound. It passes the ports to the JNI gate on each start, which works on Android where the gate exists, and it keeps the owner check for the web port. Two alternatives were considered and rejected. Passing the ports on camex's command line would have no effect on Linux, where the gate is absent. An owner check for open ports is impossible because adbd and SSH servers run under other UIDs.

Files changed (18) +241 / -35

Enhancement (9) +126 / -14
Prefs.javaStores and loads the open_ports preference +4/-1

Stores and loads the open_ports preference

• Loads open_ports with 5555, 2222 as the default when unset, and saves the trimmed value. An empty saved value means no ports open.

android/app/src/main/java/org/openipc/camex/Prefs.java

SettingsActivity.javaAccepts o= in the settings link and labels it +2/-1

Accepts o= in the settings link and labels it

• Adds OPEN_PORTS to the keys taken from a link and maps the letter o to its field label in the link summary.

android/app/src/main/java/org/openipc/camex/SettingsActivity.java

camex-jni.cGate allows listed ports whoever listens there +40/-6

Gate allows listed ports whoever listens there

• Stores up to 16 open ports from a jint array on each nativeRun call. The gate lets a new connection through to a listed port without an owner check. The web port still requires the owner check even when listed. The refusal log message now names both conditions.

android/tunnel/src/main/cpp/camex-jni.c

CamexTunnel.javaExposes OPEN_PORTS and its default; sends ports on start +9/-0

Exposes OPEN_PORTS and its default; sends ports on start

• Adds public OPEN_PORTS and DEFAULT_OPEN_PORTS constants with Javadoc. The start intent now carries the parsed port array as an extra.

android/tunnel/src/main/java/org/openipc/camex/tunnel/CamexTunnel.java

CamexVpnService.javaPasses open ports to nativeRun on each start +8/-2

Passes open ports to nativeRun on each start

• Adds an EXTRA_OPEN_PORTS intent extra and stores the array with the latest start. The worker thread reads it under the lock and passes it to nativeRun. The native signature gains an int[] parameter.

android/tunnel/src/main/java/org/openipc/camex/tunnel/CamexVpnService.java

ConnectLink.javaParses the o= link key into open ports +13/-1

Parses the o= link key into open ports

• Accepts o in the link's key set, validates it, and stores it as a comma-and-space joined list. A new join helper is added, but it sits between decode's Javadoc and decode, so that Javadoc now documents join.

android/tunnel/src/main/java/org/openipc/camex/tunnel/ConnectLink.java

Field.javaAdds a text field factory with an initial value +5/-0

Adds a text field factory with an initial value

• Adds an overload of text() that takes an initial value and a hint, used for the open ports field.

android/tunnel/src/main/java/org/openipc/camex/tunnel/Field.java

Values.javaAdds open_ports value, default, validation and parser +35/-1

Adds open_ports value, default, validation and parser

• Defines the OPEN_PORTS key, the default 5555, 2222, and a 16-port cap. openPorts() splits on commas and blanks, deduplicates, and rejects out-of-range values. check() reports malformed lists by field. The field is added to FIELDS with a hint of empty none.

android/tunnel/src/main/java/org/openipc/camex/tunnel/Values.java

index.htmlShows and validates the o= field on the link page +10/-2

Shows and validates the o= field on the link page

• Adds o to the field names and validates it with the same rules as the app: empty is valid, up to 16 ports, each 1 to 65535. The label is 'Open ports (Android)'.

docs/connect/index.html

Tests (5) +61 / -4
TunnelE2eTest.javaPasses an open-ports argument into the emulator test +1/-0

Passes an open-ports argument into the emulator test

• Reads an optional open argument from the instrumentation args into the OPEN_PORTS value, defaulting to empty.

android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java

ConnectLinkTest.javaTests o= parsing, empty close and rejection +12/-0

Tests o= parsing, empty close and rejection

• Checks that o=5555%2C2222 becomes 5555, 2222, that an empty o= closes all ports, and that an out-of-range port is reported.

android/tunnel/src/test/java/org/openipc/camex/tunnel/ConnectLinkTest.java

ValuesTest.javaTests open-ports validation, parsing and field order +21/-1

Tests open-ports validation, parsing and field order

• Extends the field list assertion and adds cases for malformed, out-of-range and too many ports. Also checks the parser's dedupe and whitespace handling, and that camex argv never includes the ports.

android/tunnel/src/test/java/org/openipc/camex/tunnel/ValuesTest.java

tunnel-e2e.shAdds open-port check to the emulator tunnel test +17/-3

Adds open-port check to the emulator tunnel test

• Starts an nc listener on 8083 in the shell, then checks that a tunnel peer reaches it. Also sets weak_name = yes on the test network, which camex 5.0 and later require for a short name.

tests/android/tunnel-e2e.sh

connect-test.jsAdds jsdom cases for o= on the link page +10/-0

Adds jsdom cases for o= on the link page

• Covers an open o= link shown and passed to the app, an empty o= as ready, and an out-of-range port reported as malformed.

tests/connect-page/connect-test.js

Documentation (3) +53 / -16
CHANGELOG.mdAdds 6.4.0 changelog entry for open ports +16/-0

Adds 6.4.0 changelog entry for open ports

• Records the #225 change: open_ports for TCP from the tunnel, the camex default list, the o= link key, and the client_isolation note. Also notes the weak_name fix in the emulator test.

CHANGELOG.md

android-library.mdDocuments open_ports value and gate behaviour +30/-16

Documents open_ports value and gate behaviour

• Adds the open_ports row to the values table. Describes the gate's new open-port rule, the adb and SSH use cases, and the client_isolation caveat.

docs/android-library.md

android.mdDocuments the Open ports field and the o= link key +7/-0

Documents the Open ports field and the o= link key

• Adds the Open ports field with its default and empty meaning to the CAMEX section, and adds the o row to the link table.

docs/android.md

Other (1) +1 / -1
version.hBumps camex version to 6.4.0 +1/-1

Bumps camex version to 6.4.0

• Sets CAMEX_VERSION to 6.4.0 from 6.3.0.

src/version.h

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. The link page approves ports the app rejects ✓ Resolved Bug Correctness
Description
CAMEX.valid('o') treats nonbreaking spaces as separators, but Android's Values.openPorts does
not. A link with o=5555%C2%A02222 is shown as ready and passed to the app, where the open-port
value is rejected and left out of the imported settings.

2. The open-port test can pass without a listener ✓ Resolved Bug Reliability
Description
tunnel-e2e.sh skips the new reachability assertion when its background nc command does not leave
port 8083 listening. Because that command's failure is unchecked and a skip does not increase the
failure count, a run can pass without testing the new gate behavior.

3. Every app built on the library opens adb by default ✓ Resolved Bug Security
Description
The shared Values.FIELDS entry for open_ports now starts as DEFAULT_OPEN_PORTS ("5555, 2222"),
so any app that builds its settings screen from fields() and saves the initial values (the
documented way to use fields()) passes those ports to start(). As a result, Decoder,
MicroSNANDer and any other app on the library expose adbd and whatever listens on 2222 to every
client of the network once they upgrade, without opting in. That contradicts the PR's claim that "an
app that does not set the key opens none", and it undoes part of #187's isolation for apps that only
meant to publish their web page.


Informational

4. The URL decoder loses its doc comment ✓ Resolved Bug Maintainability
Description
The new join helper and its javadoc were inserted between decode's existing javadoc and decode
itself, so that comment now sits directly above join's own comment. IDEs and javadoc show nothing
for decode, and a reader sees the URL-decoding rules ('+' stays '+', null on malformed UTF-8)
right before a port-joining helper.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

…x app opts in), the link page splits on ASCII blanks only, the e2e fails without a listener on the open port, decode keeps its comment
@compot-dev

Copy link
Copy Markdown
Collaborator Author

The review of 60f03fe, all four fixed in bbfc474:

  1. The link page and U+00A0: fixed. The page now trims and splits on ASCII blanks only, as the app's trim() and \s do. o=5555%C2%A02222 is malformed on the page and in the app (a jsdom test and a unit test).
  2. The open-port e2e without a listener: fixed. No listener on 8083 is now a failure, not a skip. On Android 5 and 6, which have no nc -L, the test listens with the busybox it already pushes for 8082. tests/android/tunnel-e2e.sh: 18 passed, 0 failed on API 34 and on API 21.
  3. Every app on the library opening adb: fixed. The library's open_ports field starts empty, so an app that does not set it opens nothing. DEFAULT_OPEN_PORTS stays as a constant for an app that opts in, and only the camex app does, through its own saved settings. Docs and CHANGELOG say so.
  4. decode's comment: fixed. join moved above reason, and decode keeps its javadoc.

Also run: gradle testReleaseUnitTest lintDebug assembleRelease and docker/test-connect-page.sh.

@compot-dev
compot-dev merged commit d24eca2 into master Dec 2, 2026
18 checks passed
@compot-dev
compot-dev deleted the android-open-ports branch December 2, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: open ports for TCP from the tunnel (adb, ssh)

1 participant