Repository navigation
fix(android): authenticate and bound persistent snapshot helper sessions #4729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
61e7178
fix(android-helper): defensive bounded session protocol over an admit…
thymikee 811e7a1
fix(android): preflight helper framing and preserve SDK compatibility
thymikee 4ee65e1
fix(android): buffer session reads and require authenticated readiness
thymikee 55bc5ee
fix(android): separate helper request reads from response writes
thymikee 00236cd
fix(android): preserve snapshot connection timeout and test session r…
thymikee f5f830b
fix(android-helper): separate command read and capture deadlines
thymikee 1925572
fix(android-helper): remember unsupported session transports by helpe…
thymikee 178a45b
fix(android-helper): diagnose verified unsupported builds and check t…
thymikee 3efebd6
fix(android-helper): consolidate capture option type imports
thymikee 799e636
test(android-helper): keep the real command byte cap in the session l…
thymikee 834b0be
refactor(android-helper): remember verified unsupported builds in the…
thymikee dc2dd72
fix(android-helper): key the unsupported-build decision by helper build
thymikee c7b6e8f
test(android-helper): cover the five session transport defects before…
thymikee dbaba3d
fix(android-helper): close incomplete session reads and write each re…
thymikee 6085510
fix(android): keep remembered installs out of the unsupported-build d…
thymikee ffc943d
docs(android-helper): note how LocalSocket reports a read timeout
thymikee f6c662f
fix(android): record the declined over-limit session frame
thymikee 3ed1de1
test(android-helper): cover repeated unverified starts and a slow max…
thymikee dd49ec6
fix(android-helper): extend the read deadline per received byte and e…
thymikee b2ee5c5
fix(android): mark an unsupported session transport by helper build u…
thymikee ccf41b6
test(android): cover interleaved readiness output and an unverified u…
thymikee 30632ac
fix(android-helper): bound each response by one deadline and keep enc…
thymikee e7e71cc
fix(android): classify session readiness from one complete stdout record
thymikee 8953878
refactor(android-helper): share one capture step between one-shot and…
thymikee 9821674
fix(android-helper): wait for send room only as long as the frame dea…
thymikee 7e8be5e
fix(android): never mark a helper build unsupported for good
thymikee 9d0c373
fix(android-helper): read commands nonblocking against the accept dea…
thymikee 652c465
fix(android): require the launched session port in the readiness record
thymikee 639d6f8
refactor(android-helper): activate sessions by versioned mode, not by…
thymikee d51238b
refactor(android-helper): drop the artifact capability gate and thin …
thymikee 1a79bce
fix(android-helper): poll in short slices so a pause cannot overrun t…
thymikee 8043156
fix(android-helper): prove a per-session secret on every connection
thymikee 23ff71b
fix(android): send session commands only after the helper proves the …
thymikee 68adbe9
fix(android): back off a session whose peer did not prove the secret
thymikee e15bc9d
fix(android): call a peer unverified only after it answered without a…
thymikee 8eaec9b
fix(android): accept the session hello only as one nonce and one proof
thymikee 2496202
fix(android): keep at most one hello line from an unverified peer
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...shot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/SessionPeerPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package com.callstack.agentdevice.snapshothelper; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| /** | ||
| * Pure admission and bound decisions for persistent-session connections. Every decision is a | ||
| * function of its inputs only, so the test suite drives it with synthetic peers: no socket, no | ||
| * clock, no Android runtime. | ||
| * | ||
| * <p>The session transport is an abstract {@code localabstract:} socket reached through | ||
| * {@code adb forward tcp:<host port> localabstract:<name>}. The forwarded peer of such a | ||
| * connection is adbd, which runs as root when adb is rooted and as shell otherwise; both uids are | ||
| * the adb operator trust boundary, and the forwarded uid is not the original host user's identity. | ||
| * Any other uid is an untrusted co-installed peer and is rejected before any command byte is read. | ||
| */ | ||
| final class SessionPeerPolicy { | ||
| /** adbd with {@code adb root} (a supported adb mode); the root-mode adb operator. */ | ||
| static final int PEER_UID_ROOT = 0; | ||
| /** adbd in its default shell configuration. */ | ||
| static final int PEER_UID_SHELL = 2000; | ||
|
|
||
| /** | ||
| * Prefix of the abstract socket name, shared with the host's forward spec. The name is derived | ||
| * from the session port and carries no secret: admission is the peer uid, not name secrecy. | ||
| */ | ||
| static final String SESSION_SOCKET_PREFIX = "agentdevice-snapshot-helper-"; | ||
|
|
||
| /** | ||
| * The per-connection command-line byte cap. Derived from the largest supported producer of this | ||
| * channel, measured with the repository's own plan builders: a 10 s two-contact gesture carries | ||
| * 1,252 densified samples (2 pointers x 626 samples on the 16 ms grid), whose base64 command line | ||
| * is at most ~130 KB, and the documented 64 KiB {@code fill --text-stdin} contract encodes to | ||
| * ~88 KB. 256 KiB bounds both with at least 2x headroom. The IME helper's 64,000-base64-char | ||
| * cap belongs to its separate am/broadcast channel and is deliberately not reused here. | ||
| */ | ||
| static final int MAX_COMMAND_LINE_BYTES = 256 * 1024; | ||
|
|
||
| enum Admission { | ||
| ADMITTED, | ||
| REJECTED_UNAUTHORIZED_PEER | ||
| } | ||
|
|
||
| enum LineDecision { | ||
| ACCEPTED, | ||
| REJECTED_EMPTY, | ||
| REJECTED_OVER_LIMIT | ||
| } | ||
|
|
||
| private SessionPeerPolicy() {} | ||
|
|
||
| static Admission admitPeer(int uid) { | ||
| return uid == PEER_UID_ROOT || uid == PEER_UID_SHELL | ||
| ? Admission.ADMITTED | ||
| : Admission.REJECTED_UNAUTHORIZED_PEER; | ||
| } | ||
|
|
||
| /** | ||
| * The abstract socket name for a session port. Deterministic and secret-free, so the host and | ||
| * the helper derive the same name from the same port without passing anything sensitive in argv. | ||
| */ | ||
| static String sessionSocketName(int sessionPort) { | ||
| return SESSION_SOCKET_PREFIX + sessionPort; | ||
| } | ||
|
|
||
| /** | ||
| * The per-connection command read budget, owned by the session's own configured timeout: a host | ||
| * sends its command immediately after connecting, so a peer silent past that budget is rejected | ||
| * instead of occupying the command reader. Zero or negative falls back to the caller's default | ||
| * timeout, never to an unbounded read. | ||
| */ | ||
| static long commandReadDeadlineMs(long sessionTimeoutMs, long fallbackTimeoutMs) { | ||
| long budgetMs = sessionTimeoutMs > 0 ? sessionTimeoutMs : Math.max(0, fallbackTimeoutMs); | ||
| return Math.min(Integer.MAX_VALUE, budgetMs); | ||
| } | ||
|
|
||
| /** | ||
| * The absolute deadline instant for one connection's command read, fixed at accept time. The | ||
| * remaining budget shrinks toward zero no matter how many reads the peer forces, unlike a | ||
| * rolling SO_TIMEOUT that resets on every read. | ||
| */ | ||
| static long commandReadDeadlineAtMs(long acceptedAtMs, long budgetMs) { | ||
| return acceptedAtMs + Math.max(0, budgetMs); | ||
| } | ||
|
|
||
| /** The budget left before {@code deadlineAtMs}, never negative. */ | ||
| static long remainingBudgetMs(long deadlineAtMs, long nowMs) { | ||
| return Math.max(0, deadlineAtMs - nowMs); | ||
| } | ||
|
|
||
| static LineDecision commandLineDecision(String line, int maxLineBytes) { | ||
| if (line == null || line.isEmpty()) { | ||
| return LineDecision.REJECTED_EMPTY; | ||
| } | ||
| return line.getBytes(StandardCharsets.UTF_8).length > maxLineBytes | ||
| ? LineDecision.REJECTED_OVER_LIMIT | ||
| : LineDecision.ACCEPTED; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.