Codex/tuya app env self ca - #43
Open
xiongzh2000 wants to merge 9 commits into
Open
xiongzh2000 wants to merge 9 commits into
xiongzh2000 wants to merge 9 commits into
Conversation
Decode Tuya App registration keys from BLE tokens and MQTT activation messages so the SDK activates against the App-selected cloud. Preserve legacy token and configured-environment behavior for existing callers. Document the wire format and the returned client environment. Verified: 18/18 CTest cases, i18n parity check, ESP32-S3 firmware build. Co-Authored-By: Codex <codex@openai.com>
Direct BLE authTokens carry a four-byte App registration key, not a fixed environment enum. Resolve both Self endpoints before activation and reject incomplete or malformed DNS answers so activation cannot silently fall back to a legacy host. Preserve the QR/MQTT activation path. Tests: iot_on_boarding_test 15/15; targeted CTest 1/1. Co-Authored-By: Codex <noreply@openai.com>
ATOP uses a fixed /d.json path, so a different DNS path cannot be honored. Reject it before activation, and make on-boarding tests verify the exact on-wire App env plus absence of activation requests when DNS endpoints are invalid. Tests: iot_on_boarding_test 17/17; targeted CTest 1/1. Co-Authored-By: Codex <noreply@openai.com>
Reject Self HTTPS port 80 and non-443 ports without a CA or certificate bundle, because the HTTP transport would otherwise use plaintext. Reject JSON-special bytes in the eight-byte activation token before manual JSON formatting, while preserving opaque punctuation in the registration key. Stop logging the activation POST body and token prefix. Tests: iot_on_boarding_test 20/20; serial CTest 18/18. Co-Authored-By: Codex <noreply@openai.com>
Carry the opaque key through activated clients and re-resolve Self endpoints on reconnect. Fail closed for missing or unsafe endpoints so post-activation network faults preserve credentials without routing traffic to legacy hosts. Tests: 5/5 affected CTest; 18/18 prior full suite. Co-Authored-By: Codex <codex@openai.com>
Token onboarding always carries a registration key, which requires MQTT over TLS. Validate the transport before DNS or cloud activation so an unsupported configuration cannot consume an App token and discard issued credentials. Tests: 1/1 onboarding CTest; 18/18 full CTest. Co-Authored-By: Codex <codex@openai.com>
Use a trusted bootstrap CA for App-selected IoT DNS, retain the CA returned for Self endpoints, and apply it consistently to activation, MQTT, ATOP, OTA, version, and schema requests. Without authenticated DNS and its CA, token onboarding must fail closed rather than fall back to legacy TLS trust or unverified connections. Verified: full host CTest suite passes (18/18). Co-Authored-By: Codex <codex@openai.com>
The Tuya provisioning specification defines authToken as region(2) + token(8) + secret(4), and sends the secret unchanged as HTTPDNS env. Clarify that this opaque BLE secret is not a pre/pro/prod enum and does not override config.env; distinguish it from data.env in the separate QR/MQTT activation flow. Rename the QR activation env parser and assert the BLE secret leaves config.env unchanged. Verified: iot_on_boarding_test CTest suite passes (1/1); docs i18n parity passes. Co-Authored-By: Codex <codex@openai.com>
Match TuyaOpen MQTT activation: retain data.env as an opaque registration key, default to pro only when the field is absent, and reuse BLE Self DNS/CA discovery for activation. Reject unsupported plaintext QR configuration before activation. Accept bounded 1-4 byte keys without changing fixed-width BLE tokens or legacy clients with no key. Document application-owned persistence of credentials, region, legacy env and the raw registration key, including upgrades of already-bound devices. Add QR/default/invalid-key and restart regression coverage. Verified: complete host build and 18/18 serial CTest suites passed; i18n parity passed and 15/15 parity tests passed. Documentation-site build could not run because tsc/node_modules are missing. Co-Authored-By: OpenAI Codex <codex@openai.com>
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.
背景与目标
支持同一份设备固件随涂鸦 App 配网进入对应云环境,避免激活与后续 MQTT 使用不同环境,以及重启后丢失 App 选择的路由。参考 TuyaOpen 的
mqtt_bind.c、tuya_iot.c、iotdns.c:设备保存原始注册 key,原样传给 IoT DNS,由 DNS 返回地址和证书,不在固件里维护环境映射表。协议规则(以当前最终 diff 为准)
[region:2][token:8][secret:4];只用中间 8 字节发起激活,尾部 4 字节原样保存为registration_key。data.env原样保存为注册 key;仅字段缺省时使用pro,接受 1~4 个可打印字节,拒绝错误类型、空值、超长及非法字符。pr_0、da_0、普通四字节 secret、私有云 key 等均不映射成 PRE/PROD。config.env/client->env不被注册 key 改写;注册 key 存在时,实际业务路由以 DNS 结果为准。主要改动
httpsSelfUrl、mqttsSelfUrl(need_ca=true),用 DNS 返回的 HTTPS 地址和 CA 激活,不采用激活消息中的httpsUrl。兼容性与接入要求
env,继续旧路由;不清绑定、不要求重新配网,不自动补pro。devid、secret_key、local_key、region、env、registration_key一起安全保存,重启时填入iot_client_config_t。SDK 不代管 NVS/文件存储。pro与旧绑定的空 key 是不同语义。本轮 CR 补充修复
最新提交
07497a8修复 QR/MQTT 对pr_0/da_0的枚举解析错误,允许三字节pro,统一 DNS 激活入口,并补齐注册 key 持久化说明和重启恢复测试。前面提交包含迭代过程,审核协议语义请以当前最终 diff 为准,而非早期 commit 文案中的 pre/pro/prod 映射描述。验证与限制
07497a8上完成完整主机编译,串行 CTest 18/18 套件通过;包括 BLE、RTC、MQTT、DP、OTA,以及 DNS 32/32、onboarding 25/25 用例。pro、非法 key、DNS 决定激活地址、明文配置提前拒绝、凭据恢复后的 Self 路由。建议集成验收:分别用线上、预发、日常 App 配网,确认 DNS/激活/MQTT 路由一致;保存完整绑定记录后断电重启验证;升级旧版本已绑定设备验证无需重新配网;断网恢复验证凭据保留且不跨环境回退。