Repository navigation
fix(devices): accept the V2 header signature of device info uploads - #293
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the V2 device-info signature changes.
No open issues 🎉
What changed in this PR
Extends signed device-info uploads to support the Saros 20 Flow’s V2 header signature, allowing verified serial and feature metadata to reach the inventory while preserving the existing signature-field format.
Changes:
- Passes signature headers to routes through pseudo-parameters that cannot be supplied by query strings.
- Verifies V2 uploads with SHA-384 and sends outcome logs to the API logger.
- Adds validation and HTTP integration tests, plus documentation of the V2 format and replay limitations.
| File | Description |
|---|---|
tests/test_device_info.py |
Tests V2 verification, rejection cases, legacy compatibility, header isolation, and multipart uploads. |
src/roborock_local_server/server.py |
Forwards signature headers to route handlers. |
src/roborock_local_server/bundled_backend/shared/http_helpers.py |
Adds header pseudo-parameter helpers and filters query-supplied equivalents. |
src/roborock_local_server/bundled_backend/https_server/routes/bootstrap/device_info.py |
Supports V2 signatures and routes outcome logs to the API logger. |
docs/device-info.md |
Documents the V2 signature contract and replay limitations. |
Review effort: Balanced
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: passed (nits)
Now that this has passed the automated review, I'll do a human review and then either request changes or merge it.
Confirmed from the code:
- Header-only signature. The
v/n/t/sheaders reach the route only as__header_*pseudo-params, andwith_route_headersdrops any the client put in the query string. A test covers this. - Same scheme as the V2
/regioncode. It signsdid=..&featureset=..&newfeatureset=..&pid=..&sn=..:<n>:<t>and verifies with SHA-384 and PKCS#1 v1.5 againstctx.device_public_key(did), matchingsplit_v2_region_sample/_emsa_pkcs1_v1_5onmain. - Safe rejections. Each of these returns no report and writes nothing:
- malformed, duplicate or extra fields;
- a DID mismatch, a missing key, bad base64 or a bad signature;
- a non-ASCII header value, which gives
invalid_signaturerather than a 500.
- No mixing of forms. With a
signaturefield the V1 path runs; without one, only V2 is accepted. - Cheap verify: a single RSA public-key verify per request.
Unverifiable: the a307's exact header names, field order and SHA-384 for /devices/<did>/info. There's no captured fixture, and robot-side signing isn't in RR_API or the firmware dump. It's plausible, since it matches the verified /region contract.
Nits:
_signature_contractdoesn't check that the decodedsis 512 bytes, unlikesplit_v2_region_sample.route_headerreads onlyv/n/t/s, while the key-capture code accepts aliases likesign/nonce/ts. A comment would help.- Replay isn't mitigated. That's documented and low impact.
- The docs say the parts come "in the same order", but the server rebuilds the order itself.
Checks: all 521 tests pass, and it merges cleanly with #292, #294 and #295.
This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles, refreshed 2026-11-21), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.
|
The a307 uploads its device info without a signature field. It sends the five fields as multipart parts and signs them in the V2 headers v, n, t and s: SHA-384 over the canonical form, followed by the nonce and the timestamp. The handler required a signature field, so it answered malformed_fields and discarded the signed sn and feature sets. Route builders get no headers. The server now passes v, n, t and s to the routes as "__header_<name>" query pseudo-params, like "__host". A query cannot supply them. The handler accepts this form with the same checks and outcomes. The form with a signature field behaves as before. There is no freshness check, so a recorded upload stays replayable, as with the old form.
The outcome line went to the module logger. The root logger has no handler, so the INFO line was dropped and no upload left a trace. The handler now logs through ctx.loggers["api"], like the routine runner. That logger writes to api_server.log and stdout.
The server rebuilds the signed text in its own field order, so the order of the multipart parts does not matter. A comment in http_helpers names why the route reads only the headers v, n, t and s.
key.verify rejects a signature whose length differs from the key size, so the route needs no length check of its own.
7b46eb6 to
b6976cb
Compare
Lash-L
left a comment
There was a problem hiding this comment.
Automated review: passed
Now that this has passed the automated review, I'll do a human review and then either request changes or merge it.
Since the last review (6d4e026 → b6976cb)
The branch was rebased onto main (f1e49fd). The two reviewed commits are unchanged apart from rebase context in server.py, and there are two new commits. The four nits from the last review:
- No 512-byte check on
s: handled by tests rather than code, and that's fine.key.verifyrejects any signature whose length differs from the key size. The newshort_signature/long_signaturecases intests/test_device_info.py:197-199show that both returninvalid_signatureand write nothing. route_headerreads onlyv/n/t/s: fixed.shared/http_helpers.py:37-41now has a comment explaining why the aliases used by key capture are not read.- "In the same order" in the docs: fixed.
docs/device-info.md:36-39now says the server rebuilds the signed text in its own field order. - Replay: unchanged and documented (
docs/device-info.md:63-67). Low impact, because the handler only writessn/featureSet/newFeatureSet.
Checked again on the current head
- Signature check can't be bypassed.
- The V2 headers reach the route only as
__header_*pseudo-params.with_route_headersdrops any__header_*key the client put in the query string (http_helpers.py:51), andtest_query_cannot_supply_route_headerscovers this. - No other route iterates over
query_params, so the extra keys can't leak into another route's logic. _signature_contractreturnsNoneunless the body has exactly the V1 field set or exactly the five V2 fields withv == "v2"and non-emptyn,tands(device_info.py:37-52). Duplicate fields still givemalformed_fields.- Non-ASCII header values raise
UnicodeEncodeError, a subclass ofValueError, which is caught asinvalid_signature.
- The V2 headers reach the route only as
- Constant time. This is an RSA public-key verify (PKCS#1 v1.5) over public data, done by
cryptography. No secret MAC is compared, so there is no timing oracle to protect. - No secrets logged. The new outcome line logs only the DID, the outcome and a count (
device_info.py:134). Thev/n/t/sheaders were already written to the HTTP jsonl before this PR. They are a public signature and a nonce, not credentials. - V1 still accepted. A body with a
signaturefield takes the unchanged SHA-256 path with an empty suffix, and it ignores V2 headers (test_v1_form_ignores_v2_headers). The existing V1 tests pass unmodified. - SHA-384 / 512-byte keys match the V2
/regionrecovery onmain(shared/device_key_recovery.py:73,87,281-285).
Unverifiable: the a307's real header names, its field set and its use of SHA-384 for /devices/<did>/info. Robot-side HTTP requests are not in the decompiled app or python-roborock. The Q7 flash dump in vac_firmware is encrypted and has no strings for this upload. The PR author reports a replay of a real a307 upload that was stored.
Checks: all 742 tests pass, including the 43 tests in tests/test_device_info.py. CI is green. It merges cleanly with main and with #294, and #294 touches none of the same files.
This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.
|
Thanks for review and merging (Also for my other PRs 😄) |
What does this PR do?
POST /devices/<did>/infonow accepts the V2 form of the Saros 20 Flow (roborock.vacuum.a307). That form carries its signature in the headersv,n,tandsinstead of asignaturefield. Before, the handler answeredmalformed_fieldsand discarded the signedsn,featureSetandnewFeatureSet. This extends #153.Problem
The a307 posts its device info once a day as
multipart/form-data. The body has five parts:did,featureset,newfeatureset,pidandsn. It has nosignaturepart. Four headers carry the signature:visv2.nis a nonce of 6 characters.tis a Unix timestamp.sis the base64 signature of 512 bytes.The device signs the canonical form of #153, followed by the nonce and the timestamp. It uses PKCS#1 v1.5 with SHA-384:
The key is the device public key that onboarding recovers from the V2
/regionsignatures. The handler required asignaturefield, so it answeredmalformed_fields. The inventory then had nosn,featureSetornewFeatureSetfor the device.The log did not show this either. The handler wrote the outcome line to its module logger. The root logger has no handler, so the INFO line was dropped.
Change
v,n,tandsto the routes as the pseudo-params__header_v,__header_n,__header_tand__header_s, like__host. Client-supplied__header_keys in the query are dropped, so a query cannot set them.visv2. It runs the same checks as for the old form and has the same outcomes. A five-field body without these headers counts asmalformed_fields.signaturefield behaves as before, and it ignores V2 headers.ctx.loggers["api"], like the routine runner. That logger writes toapi_server.logand stdout.docs/device-info.mddescribes the V2 form.The V2 form has a nonce and a timestamp, but the server does not check them for freshness or reuse. So a recorded upload stays replayable, as with the old form. The docs say so.
Related
#217 (Saros 20 Sonic, a279) lists
POST /devices/<duid>/infoin the startup sequence of the vacuum. I have not seen the body of that upload, so I do not know whether the a279 uses the V2 form too.Before you open this PR (optional, but very helpful)
PRs I reviewed:
Proof that it works
Tested on:
roborock.vacuum.a307)02.17.50a307-pluginbranch. That build is upstream main 32608dd plus this PR, feat(api): enable scene tiles via productTags and category cardSpec #208 and my other fixes for the a307. The tests ran on this branch, rebased on upstream main f1e49fd.What I did and what happened:
Before: the vacuum's own upload reached the
device_inforoute and got HTTP 200. The inventory still had nosn,featureSetornewFeatureSetafterwards, and the log had no outcome line.After the deploy, I replayed the vacuum's recorded upload with its original multipart body and its
v,n,tandsheaders. The server logged:The inventory record of the a307 then had its real
sn, itsfeatureSetand itsnewFeatureSet.Tests:
tests/test_device_info.py:sn,featureSetandnewFeatureSet.v, a duplicate field, a wrong DID, an unsafe value and an unknown device key.uv run --extra dev pytest -qpasses (742 tests).Screenshots (required for any UI change)
No UI changes.