Repository navigation
Don't crash the TcpUsb bridge on a signature no known key verifies - #554
Merged
Merged
Conversation
node-forge's verify() throws instead of returning false when it can't verify a
signature: one made by another key ('Encryption block is invalid'), or one with
the wrong length or no bytes ('Encrypted message length is invalid'). The
known-public-keys loop (DeviceFarmer#540) calls it for every key, so a client whose
signature isn't from the first known key gets an error instead of a new
challenge. The socket emits that error and the server re-emits it; STF treats
any error from the bridge as fatal and restarts the device. STF passes all of
the device owner's adb keys, so anyone with two keys hits it.
Treat a throw as a mismatch, in the loop and in the RSAPUBLICKEY check, and
reject a missing signature as an AuthError, which only closes the connection.
Signed-off-by: Arthur Yazhevich <[email protected]>
koral--
approved these changes
Oct 13, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Since #540, the TcpUsb bridge checks an
AUTH_SIGNATUREagainst each ofknownPublicKeys. node-forge'sverify()throws instead of returningfalsewhen it can't verify a signature:Encryption block is invalid.for a signature made by another key,Encrypted message length is invalid.for one of the wrong length. So a client whose signature isn't from the first known key gets an error instead of a newAUTH_TOKENchallenge. The socket emits it aserror, and the server re-emits it.In STF this restarts the device: the connect plugin shares the bridge with
lifecycle.share(), which treats any error as fatal. STF passes all of the device owner's adb keys asknownPublicKeys, so anyone with two adb keys registered (for example one per OS on a dual-boot or WSL machine) crashes the device they connect to. The user sees "Someone stole your device", and the remote debug port changes.Change
verifies(): a small helper wrapskey.verify()and returnsfalse(with a debug line) when it throws. It is used in the known-keys loop and in theAUTH_RSAPUBLICKEYcheck.AUTH_SIGNATUREpacket without data is rejected with anAuthError, which closes only that connection. Before,this.signature.toString()threw aTypeError, which became anerrorevent the same way.Behaviour change: a client that sends an
AUTH_SIGNATUREwith no data is now disconnected instead of challenged again. adb never sends one.Tests
test/adb/tcpusb/socket.ts, newknown public keysblock (4 tests, all fail without the change):error;error;error.Note:
npm test's unquotedtest/**/*.tsglob doesn't reachtest/adb/tcpusb/, so these tests (and the earlier tcpusb ones) only run when named. Quoting the glob would fix that; I've left it for a separate change.Found on an STF 3.8.0 provider:
Remote ADB had an error Error: Encryption block is invalid.followed byShutting down due to fatal error, reproduced with node-forge 1.4.0 from thedevicefarmer/stf:3.8.0image.