Skip to content

fix(devices): accept the V2 header signature of device info uploads - #293

Merged
Lash-L merged 4 commits into
Python-roborock:mainfrom
Hoeze:fix/device-info-v2-signature
Nov 28, 2026
Merged

Lash-L merged 4 commits into
Python-roborock:mainfrom
Hoeze:fix/device-info-v2-signature

Conversation

@Hoeze

@Hoeze Hoeze commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

POST /devices/<did>/info now accepts the V2 form of the Saros 20 Flow (roborock.vacuum.a307). That form carries its signature in the headers v, n, t and s instead of a signature field. Before, the handler answered malformed_fields and discarded the signed sn, featureSet and newFeatureSet. 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, pid and sn. It has no signature part. Four headers carry the signature:

  • v is v2.
  • n is a nonce of 6 characters.
  • t is a Unix timestamp.
  • s is 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:

did=<numeric DID>&featureset=<decimal flags>&newfeatureset=<hex flags>&pid=<model>&sn=<serial>:<n>:<t>

The key is the device public key that onboarding recovers from the V2 /region signatures. The handler required a signature field, so it answered malformed_fields. The inventory then had no sn, featureSet or newFeatureSet for 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

  • Route builders get no request headers. The server now passes v, n, t and s to the routes as the pseudo-params __header_v, __header_n, __header_t and __header_s, like __host. Client-supplied __header_ keys in the query are dropped, so a query cannot set them.
  • The handler accepts the V2 form when the body has exactly the five fields, all four headers are present and v is v2. It runs the same checks as for the old form and has the same outcomes. A five-field body without these headers counts as malformed_fields.
  • The form with a signature field behaves as before, and it ignores V2 headers.
  • The outcome line goes to ctx.loggers["api"], like the routine runner. That logger writes to api_server.log and stdout.
  • docs/device-info.md describes 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>/info in 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)

  • I checked for duplicates. I searched open PRs and issues and nobody else is already working on this.
  • I reviewed 1-2 other open PRs and tested whether they work on my vacuum.

PRs I reviewed:

Proof that it works

Tested on:

  • Vacuum model: Roborock Saros 20 Flow (roborock.vacuum.a307)
  • Firmware version: 02.17.50
  • Server version / commit: the device test ran on e839839 of my fork's a307-plugin branch. 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.
  • Install method (Docker / Home Assistant add-on / other): built from source

What I did and what happened:

Before: the vacuum's own upload reached the device_info route and got HTTP 200. The inventory still had no sn, featureSet or newFeatureSet afterwards, 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, t and s headers. The server logged:

[real_stack.api] Device info did=<did> outcome=stored updated=1

The inventory record of the a307 then had its real sn, its featureSet and its newFeatureSet.

Tests:

  • New tests in tests/test_device_info.py:
    • A signed V2 upload updates sn, featureSet and newFeatureSet.
    • 17 broken V2 uploads are acknowledged without writes, each with its outcome logged. They cover a tampered field, another key, SHA-256, bad base64, a signature one byte short or long, a changed nonce or timestamp, each missing header, a wrong v, a duplicate field, a wrong DID, an unsafe value and an unknown device key.
    • The old form ignores V2 headers.
    • A query cannot supply the header pseudo-params.
    • A real multipart V2 upload through the HTTP stack gets stored.
  • Full suite: uv run --extra dev pytest -q passes (742 tests).

Screenshots (required for any UI change)

No UI changes.

Copilot AI balanced review requested due to automatic review settings November 21, 2026 20:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/s headers reach the route only as __header_* pseudo-params, and with_route_headers drops any the client put in the query string. A test covers this.
  • Same scheme as the V2 /region code. It signs did=..&featureset=..&newfeatureset=..&pid=..&sn=..:<n>:<t> and verifies with SHA-384 and PKCS#1 v1.5 against ctx.device_public_key(did), matching split_v2_region_sample / _emsa_pkcs1_v1_5 on main.
  • 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_signature rather than a 500.
  • No mixing of forms. With a signature field 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_contract doesn't check that the decoded s is 512 bytes, unlike split_v2_region_sample.
  • route_header reads only v/n/t/s, while the key-capture code accepts aliases like sign/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.

@Lash-L Lash-L added the passed auto review Automated review found no blocking issues label Nov 22, 2026
@Hoeze

Hoeze commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author
  • No 512-byte check in _signature_contract: key.verify already rejects a signature whose length differs from the key size, and the route maps that to invalid_signature. A fixed 512 would also tie the route to 4096-bit keys, while the tests sign with 2048-bit keys. 7b46eb6 adds cases for a signature one byte short and one byte long.
  • route_header reads only v/n/t/s: d4f803d adds a comment. The recorded upload of the a307, which the body replays, carries exactly these names. No device info upload is known to use the aliases of the key capture.
  • "In the same order": d4f803d drops that claim from the docs and says that the server rebuilds the signed text in its own field order.
  • Replay: no change, as the docs describe it.

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.
@Hoeze
Hoeze force-pushed the fix/device-info-v2-signature branch from 7b46eb6 to b6976cb Compare November 22, 2026 21:50

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.verify rejects any signature whose length differs from the key size. The new short_signature / long_signature cases in tests/test_device_info.py:197-199 show that both return invalid_signature and write nothing.
  • route_header reads only v/n/t/s: fixed. shared/http_helpers.py:37-41 now 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-39 now 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 writes sn/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_headers drops any __header_* key the client put in the query string (http_helpers.py:51), and test_query_cannot_supply_route_headers covers this.
    • No other route iterates over query_params, so the extra keys can't leak into another route's logic.
    • _signature_contract returns None unless the body has exactly the V1 field set or exactly the five V2 fields with v == "v2" and non-empty n, t and s (device_info.py:37-52). Duplicate fields still give malformed_fields.
    • Non-ASCII header values raise UnicodeEncodeError, a subclass of ValueError, which is caught as invalid_signature.
  • 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). The v/n/t/s headers 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 signature field 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 /region recovery on main (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.

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Hoeze!

@Lash-L
Lash-L merged commit 8852a9a into Python-roborock:main Nov 28, 2026
3 checks passed
@Hoeze

Hoeze commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for review and merging (Also for my other PRs 😄)
And for starting this project in general 👍 Having a self-hosted RR endpoint is absolutely amazing!! 😁
This project is the only reason why I got that robot ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

passed auto review Automated review found no blocking issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants