Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Code style

The conventions for each language in the repository and the security rules that apply to all code. “Enforced by CI” means a pull request fails without it. Everything else is checked in review.

All code

RuleDetail
LicenceGPL-3.0-or-later. A new source file starts with the line SPDX-License-Identifier: GPL-3.0-or-later in the comment syntax of the language, as the existing ones do.
Third-party codeOnly under licences compatible with GPL-3.0, credited in NOTICE. A file that follows a technique of another project says so in its header.
Reverse engineeringNo code or knowledge obtained by reverse engineering proprietary software. See About the licence and distribution.
SpellingBritish, in documentation and in user interface text: licence (noun), set-up (noun), colour.
Protocol constantsPorts, timeouts and limits are defined in one place per side and match the wire protocol reference.

Logging

Never log message contents, keys, nonces or short authentication string (SAS) values above the trace level. This covers notification text, SMS and MMS bodies, clipboard text, contact data, pairing secrets and tokens.

SideFacilityNotes
Rusttracing (trace!, debug!, info!, warn!, error!)The level is set with RUST_LOG. The packaged service runs with RUST_LOG=info.
Android appTLog (android/app/src/main/java/org/tether/android/core/TLog.kt): TLog.d, TLog.i, TLog.w, TLog.e with a short tagTags appear in logcat with the prefix Tether.. TLog.d is dropped in release builds.
Shell helperShellLog (android/app/src/main/java/org/tether/shell/ShellLog.kt)Writes tether-helper: <I|W|E> text to stderr, which the daemon reads.

Log identifiers in shortened form where the full value is not needed (the core logs the first eight characters of a device id).

Rust (desktop/)

Toolchain and build

ItemValueWhere
Edition2021desktop/Cargo.toml, [workspace.package]
Minimum supported Rust version1.85 (rust-version)desktop/Cargo.toml
Toolchain in CIlatest stable (dtolnay/rust-toolchain@stable).github/workflows/desktop.yml
Nightly featuresnot used
Dependency versionsdeclared once in [workspace.dependencies], used in crates as name.workspace = truedesktop/Cargo.toml
Release profilelto = "thin", codegen-units = 1, strip = truedesktop/Cargo.toml
Protobuf code generationprotox and prost-build in tether-proto/build.rs, without protoc

There is no rust-toolchain.toml, rustfmt.toml or clippy.toml, and no [lints] table in any Cargo.toml. Formatting and lints are the tools’ defaults.

Formatting and lints

RuleEnforced by CI
rustfmt defaults: cargo fmt --all --check passesyes
cargo clippy --workspace --all-targets -- -D warnings passesyes
No compiler warnings (RUSTFLAGS="-D warnings")yes
Fix a lint in preference to #[allow]. An #[allow] carries a comment that says why.no
#![forbid(unsafe_code)] in tether-core, tetherd and tether-cliby the compiler

tether-proto contains only generated code and sets #![allow(clippy::all)]. tether-gtk does not forbid unsafe. A new Rust release can add clippy lints that an older local toolchain does not report.

Conventions

TopicRule
Errorsthiserror in libraries, anyhow in binaries.
unwrap()Not outside tests, except where a comment proves that it cannot fail.
Asynctokio everywhere. No blocking calls on the runtime. Use spawn_blocking for bursts of file I/O and for key generation.
DocumentationEvery public item in tether-core has a doc comment. Modules start with a //! comment that says what they own and names the ADR or reference section they implement.
TestsUnit tests next to the code (#[cfg(test)] mod tests), integration tests in the crate’s tests/ directory.
Test vectorsChanges to pairing and framing keep the shared test vectors of the protocol reference green.
Test fixturesFixtures for external tools (pw-dump, adb output) come from a real capture, not from an assumed shape.
External commandsParse the output of adb. Its exit code is 0 on some failures (Platform findings).

Kotlin (android/)

Toolchain and build

ItemValueWhere
Kotlin2.1.21android/gradle/libs.versions.toml
Android Gradle Plugin8.10.1android/gradle/libs.versions.toml
Gradle8.11.1, through the wrapperandroid/gradle/wrapper/gradle-wrapper.properties
JDK in CI21 (Temurin).github/workflows/android.yml
JVM target17android/app/build.gradle.kts
compileSdk / targetSdk / minSdk35 / 35 / 34android/app/build.gradle.kts
Protobuf code generationWire 5.3.11, plain Kotlin classes in org.tether.proto.v1android/app/build.gradle.kts
Dependency versionsversion catalogueandroid/gradle/libs.versions.toml
Release buildsR8 minification and resource shrinkingandroid/app/proguard-rules.pro

Formatting and lints

RuleEnforced by CI
Official Kotlin style (kotlin.code.style=official in android/gradle.properties)no
ktlint-compatible formatting: four-space indent, trailing commas in multi-line declarations, no wildcard importsno
Soft limit of 120 columnsno
Unit tests pass and the debug build assembles (:app:testDebugUnitTest :app:assembleDebug)yes

There is no ktlint or detekt Gradle task and no .editorconfig. Run ktlint yourself if you have it installed. Android lint is configured not to fail the build (abortOnError = false).

Conventions

TopicRule
User interfaceJetpack Compose with Material 3 only. Composables are stateless, with state hoisted out of them. Screens read StateFlows of the singletons in AppGraph.
ConcurrencyCoroutines. Every coroutine runs in a scope that is passed in. No GlobalScope.
Dependency injectionManual: constructor parameters and the AppGraph object. Adding Hilt or Dagger needs an ADR.
DependenciesNo Google Play Services and no Firebase (ADR-0008).
PermissionsEvery new permission has a comment in AndroidManifest.xml that says why it is needed. If the user sees a prompt, it is described in Grant Android permissions.
ComponentsA new exported activity, service or receiver is explained in the pull request: who can call it and what it can do.
CapabilitiesA capability is announced only while its permission is held (transport/Protocol.kt).
TestsJUnit 4 unit tests under android/app/src/test/, with the shared vectors from the protocol reference.
Shell helperCode in org.tether.shell uses no resources, no AndroidX and no JNI.

Protobuf (proto/)

RuleDetail
Syntax and packageproto3, package tether.v1, option java_package = "org.tether.proto.v1", option java_multiple_files = true.
Field numbersNever reuse or renumber a field. Reserve the number of a removed field.
EnvelopeA new message goes into the oneof msg in the block of its feature area, or in the next free block for a new area. The blocks are listed in Add or change a protocol feature.
EnumsThe zero value is <PREFIX>_UNSPECIFIED. Values carry the enum’s name as prefix (DND_FILTER_PRIORITY).
NamesMessages in UpperCamelCase, fields in snake_case.
CommentsState the direction (Desktop -> phone) and the semantics above each message, and units in field comments (ts_ms).
DocumentationBehaviour is described in the wire protocol reference in the same pull request.
NegotiationNew frames are enabled by a capability in Hello.capabilities.

Shell and packaging (desktop/packaging/)

RuleDetail
ShellPOSIX sh (#!/bin/sh), no bash features.
Static analysisshellcheck-clean. CI does not run shellcheck; run it yourself.
Error handlingset -eu in build scripts (build-deb.sh). The maintainer scripts use set -e and guard every step with `
Maintainer scriptspostinst, prerm and postrm must never fail the installation or removal of the package: a missing tool or a failed step is skipped.
Root helpersA script that runs as root takes a fixed set of words and no free-form arguments, and sets its own PATH (webcam/tether-webcam-setup).
Install-time side effectsThe package does not load kernel modules or copy files into a user’s configuration at install time (ADR-0019).
Package checklintian runs in the release workflow for information and does not fail the build.

The rules for documentation are in Write documentation.

Hardening checklist

Every change is reviewed against this list from SECURITY.md.

  • Validate every length and index that comes off the wire. Frames are capped at 4 MiB and inline blobs at 256 KiB.
  • Treat Hello from an unpaired peer as untrusted input. Never show its name in user interface or notification markup without escaping. The TLS handshake and Hello can be reached by anyone on the local network before pairing.
  • Use logging levels so that message bodies, nonces and SAS digits never appear above trace.
  • A new permission, exported Android component or D-Bus method gets a note in the pull request about who can call it and what it can do.

Further rules that follow from the threat model in the same file:

  • Identifiers from the peer that end up in file names must be plain tokens (Protocol.isValidRefId on Android). Received files must not escape their directory or overwrite other files.
  • Secrets do not go into process arguments, which other processes can read. The shell helper receives its token on stdin (ADR-0016).
  • The daemon runs as the logged-in user, never as root. The one privileged action goes through polkit with a fixed script.
  • No telemetry and no connection to a server that the user did not configure.

The reasoning behind these rules is in the security model.