The PC is the authority. A phone can control the mouse only after:
- the PC user approves a pairing request locally, and
- the phone proves possession of the 256-bit token issued at that approval.
Nothing about discovery is trusted for authorization. A hostile device on the LAN can advertise a PC identity but cannot approve itself, read the trust file or answer an HMAC challenge without the token.
phone -> {"type":"hello","proto":3,"device_id":UUID,"device_name":NAME,"pair":true}
server -> {"type":"pair_required","request_id":...,"code":"123456","expires_in":90}
PC -> APPROVE / DENY in the control panel (the code is shown for cross-check)
server -> {"type":"pair_result","approved":true,"token":"<64 hex>"} # once
server -> {"type":"auth_ok","pc_id":UUID,"pc_name":NAME,...}
- Tokens are 256 bits from
secrets.token_hex(32). - Requests expire after 90 s, at most 3 are pending, and one peer is limited to 3 attempts per minute.
- Denial or expiry closes the socket with an auth error; no trust is created.
- Revoking a device deletes its token on the PC. The phone's next connection is answered with a fresh pairing request and it re-pairs once automatically.
server -> {"type":"auth_challenge","nonce":"<32 hex>"}
phone -> {"type":"auth_response","response":"HMAC-SHA256(token, nonce)"}
server -> {"type":"auth_ok",...}
The token itself is never sent again. A packet capture yields a nonce and an
HMAC that cannot be replayed because the next connection uses a new nonce.
Comparison uses hmac.compare_digest.
| Location | Contents | Protection |
|---|---|---|
%APPDATA%/MobileMouse/device.json |
PC UUID and display name | user profile |
%APPDATA%/MobileMouse/trusted_devices.json |
phone UUID/name, token, timestamps | atomic write, owner-only bits where supported |
| Android SharedPreferences | phone UUID/name, remembered PC id/address | app sandbox |
| Android secure storage | device_token.<pc uuid> |
Keystore-backed |
The PC trust file must remain readable by the server because it needs the token to verify HMAC responses. It is plaintext JSON protected by OS permissions.
- Plaintext transport. Pairing delivers the token once over
ws://. A passive LAN attacker present during that exchange could capture it. Later connections are HMAC-protected, but there is no TLS and no PAKE yet. - No mutual TLS or certificate pinning.
- The six-digit code is a human cross-check, not a second factor typed into the phone. The PC-side approval is the authorization step.
- Debug-signed APK. The release APK uses the debug keystore.
- Rate limits are in-memory. Restarting the server resets pairing attempt counters (the trust store itself persists).
- Discovery is unauthenticated by design. It reveals the PC name, UUID, protocol version and LAN addresses to the local link; it never reveals credentials.
Keyboard input is the most sensitive data this application handles, so it is kept deliberately narrow:
text_begin,text_edit,text_endand the oldertype_textare only accepted after the HMAC handshake, on the same single authenticated session that owns the mouse. Pre-authentication text frames are ignored like any other pre-auth frame.- The text is never logged, stored, written to disk, replayed or included in an acknowledgement. The ack carries only sequence/count numbers or a short error code, and the malformed-frame warning no longer echoes frame content either.
- The server enforces a 4,000-code-point limit per insert, a 4,000-character limit per deletion, rejects invalid Unicode and control characters, and rate limits text separately from mouse traffic (60 edits/s, 1,200 inserted characters/s) on top of the per-frame ceiling.
- A deletion cannot reach text the session did not type. The session keeps
an in-memory shadow of its own typing and answers
out_of_rangeinstead of pressing Backspace beyond it, so a malformed or buggy edit cannot erase the user's document. The shadow is dropped ontext_end, on disconnect and when the interface closes; it is never logged or persisted. - Windows receives literal
KEYEVENTF_UNICODEkeyboard events plus Backspace, Return and Tab. No clipboard is read or written, and no modifiers are synthesised, so received content cannot become a shortcut or a shell command. - MobileMouse never activates its own window to receive text; the text goes to the window that already has focus. Windows itself blocks synthetic input to elevated windows from a non-elevated process, which is a limitation rather than a bypass.
- The phone keeps the text only in the keyboard screen's text controller and one in-memory acknowledged baseline, and clears both when the mode closes. There is no typing history on either side.
Diagnostics log the connection stage, PC UUID/name, selected address and port, discovery transport and failure category. They never log device tokens, HMAC responses, nonces, pairing codes, trust-file contents or typed text (not even the raw frame of a malformed message).