Repository navigation
feat(remote): 远端服务按随应用签名的清单哈希校验后再上传(S17,#2231) - #146
Merged
Merged
Conversation
remote.connect 的每个服务构建改为 { target, path, sha256 },sha256 来自应用
随构建一起签名的清单,不再由 Core 从即将发送的文件现算。
- ServerArtifact 只读一次文件,与期望 SHA-256 比对后持有这份字节;发给主机的
哈希、上传的字节和被校验的字节是同一份,校验之后替换本地文件不影响上传。
- 文件读不了或哈希不符时,在向主机发送任何内容前结束,返回新错误码
remote_server_invalid;runtime_missing 只表示找不到 ssh,错误码一一对应。
- 请求里的 sha256 不是 64 位十六进制时,在启动 OpenSSH 前返回 invalid_request。
- 64 位十六进制判断合并为 methods::is_sha256_hex,服务端上传与客户端共用。
- 契约文档补上 sha256 字段、主机复用规则和错误码;application-boundary 的
错误码列表补齐到与 ErrorCode 一致。
This was referenced Nov 21, 2026
xiaoyumuxi
marked this pull request as ready for review
November 21, 2026 03:51
xiaoyumuxi
added a commit
that referenced
this pull request
Nov 21, 2026
七个文件冲突,都是两边各自在同一列表末尾追加条目,按并集保留: - protocol::ErrorCode 与 application-boundary.md:保留 forward_target_not_confirmed、forward_limit_reached,再加 main 的 remote_server_invalid;connection_closed 用本分支补全的说明。 - RemoteCommand、命令名映射、分发器与 rust-core-api.md 方法表:remote.startForward、remote.stopForward、remote.forwards 之后接 remote.connections、remote.editConnections。 - workspace lib.rs:connections 与 forwards 两个模块都保留。 - sessions.rs 的 import:同时引入 ArtifactError 与 ForwardSet。 端口转发经已有连接的服务端协议完成,不另起 ssh 进程,与 #148 的环境变量白名单不交叉。
1 task done
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.
关联 Issue
1lck/Lithe-IDEA#2231(远程开发完整设计),R0 的 S17:远端服务构建按随应用签名的清单校验后再上传。桌面端会在后续 PR 里把两个 musl 服务构建和清单打进应用,连接时把清单里的
sha256传给remote.connect。类型
remote.connect的服务构建带上期望的 SHA-256,Core 校验后只上传校验过的那份字节改动说明
问题
原来
remote.connect只收{ target, path },Core 自己读文件算 SHA-256,再把这个哈希发给主机做比对和复用判断,上传时又读了一遍文件。这样有两个缺口:ServerArtifact(crates/remote/src/client/bootstrap.rs)read_verified(target, path, version, expected_sha256):先检查期望值是 64 位十六进制,再把文件整个读进内存,算出的哈希与期望值不区分大小写地比较,不符就拒绝。from_bytes(target, binary, version):给自己生成字节的调用方用,比如构建服务的测试。Arc<[u8]>存在 artifact 里,launch直接上传这份字节,不再重新读文件。发给主机的哈希、上传的字节、被校验的字节是同一份。ArtifactError { InvalidHash, Io, Mismatch { actual } }。launch(crates/remote/src/client/launch.rs)read_artifact改为install_name:只检查调用方能随意填写的版本号,SHA-256 由 artifact 自己算出,一定是 64 位小写十六进制,不用再检查。deploy从 artifact 取字节,不再单独传参。新错误码
remote_server_invalid(crates/protocol/src/error.rs)runtime_missing,一个码两种意思,处理方式也不同。现在runtime_missing只表示找不到 ssh。remote_server_invalid:两种情况都是“应用自带的这份构建不能用”,处理方式相同(重新安装应用),所以共用一个码。details说明是哪种情况,哈希不符时附上 Core 算出的哈希,但不包含路径。remote.connect的请求(crates/workspace/src/sessions.rs)servers每项改为{ target, path, sha256 },sha256必填。sha256不是 64 位十六进制时,在启动 OpenSSH 前返回invalid_request,details是对应的 target。read_verified。顺手清理
upload.rs和这次的客户端各写了一遍,合并为lithe_remote::protocol::methods::is_sha256_hex,三处共用。不在
crates/remote里的改动包结构要求远程代码都在 remote 包;以下几处是错误码、命令入口和文档,只做接线:
crates/protocol/src/error.rs:新增RemoteServerInvalid,所有 Core 命令共用同一个错误码枚举,只能加在这里。crates/workspace/src/sessions.rs:remote.connect的请求结构、校验和错误码转换。crates/workspace/src/probe/tests.rs:remote.connect的命令级测试。rust/contracts/rust-core-api.md:remote.connect的字段、主机复用规则和错误码。rust/contracts/remote-workspace-protocol-v1.md:“Server identity” 一节补充期望哈希的来源。rust/contracts/application-boundary.md:错误码列表原来只列了一部分,这次补齐到与ErrorCode一致,并加上remote_server_invalid。兼容性
桌面端目前还没有调用
remote.connect,不受影响。主机端的启动脚本和协议没有变化,已经装在主机上的服务照常复用。本 PR 不改插件契约、能力版本或插件函数协议,不需要更新协议更新记录,也不需要运行
sdk-e2e.mjs。测试
crates/remote/src/client/bootstrap.rs新增 3 项单元测试:Mismatch,并带上实际哈希。InvalidHash;期望值合法但文件不存在时返回Io(NotFound)。crates/remote/tests/connection_log.rs:调用方已经不能构造“哈希与字节不一致”的 artifact,所以“主机端校验失败”的测试改为在传输途中翻转上传的第一个字节,仍然断言InstallFailed(Verify)和install-verify日志类别。crates/workspace/src/probe/tests.rs:unknown_server_targets_and_malformed_hashes_are_rejected:未知 target、63 位哈希、含非十六进制字符的哈希都返回invalid_request;缺少sha256字段的请求无法解析。a_server_build_that_is_not_the_expected_one_is_never_installed:用替身 ssh 在本机运行启动脚本,分别给一个内容不符的文件和一个不存在的文件。两种情况都返回remote_server_invalid,details说明原因且不含路径,安装目录始终不存在。本地验证(macOS arm64,Rust 1.100.0):
cargo fmt --all -- --checkcargo clippy --locked -p lithe-remote -p lithe-workspace -p lithe-protocol -p lithe-core --all-targets --all-features -- -D warnings--target x86_64-pc-windows-msvc(默认特性)cargo test --locked -p lithe-remote -p lithe-workspace -p lithe-protocol --all-features:全部通过cargo test --locked -p lithe-core --all-features remote:62 项通过scripts/rust-core/verify-rust-core-comments.sh remote workspace protocolnode scripts/logging/generate-log-events.mjs --check