feat(studio-3d): 阶段 5 —— 发布保护(签名/可选加密/平台锁定)与性能长时报告
- What: 新增 `scene3d/protect.py`(封套 v2:Ed25519 签名 + 可选 AES-256-GCM,nonce/salt 每包唯一、 元数据作 AAD、明文摘要进签名、KeyProvider 只问 get_content_key)与 `record/visualization3d.py` (session.json 的 visualization3d 块:写入版本化、读取时缺块=不支持);`package.py` 支持 v2 (payload=plain 仅签名 / aes-gcm 签名+加密)并继续读 v1,新增解压比上限与"写入后自读回"校验; `contracts.py` 新增 PlatformLock/PlatformInfo/check_platform_lock、Sealing、platform_mismatch 诊断码; `Scene3DView` 在装配前查 OS/架构、拿到 capabilities 后查图形半区,违反即撤下场景并在面板显示原因; 工具 `compile_scene.py` 新增 --sign-key/--write-verify-key/--encrypt-key-id/--key-file/--lock-from-probe, `validate_scene.py` 新增 --key-file/--key-id/--verify-key/--require-signature(发布门禁), 新增 `bench_scene.py`(p50/p95 分阶段 + --cpu-only + --vertices N + --package)与 `soak_scene.py`(RSS 四分位速率 + 队列上界 + 抽稀采样);两份报告落到 docs/architecture/。 - Why: 规格 §5.2 的保护目标是"提高复制成本"而不是"防提取",所以要的是签名(来源)+ 可选认证加密(机密性) + 密钥隔离,而不是自制加密或把 ZIP 当加密;§12 的"包保护/性能/长时"三行需要可复现的数字与判定标准, 而不是一次性的观感。平台锁定还必须只降级三维:锁定不通过时二维照常。 - Verification: shared 全量通过(新增 test_scene3d_protect.py 35 项:封套往返/篡改/密钥/锁定/记录块/ compile→validate 端到端发布流程;test_scene3d_package.py 20 项含 v1↔v2 兼容);apps/studio 全量通过 (test_scene3d_view.py 30 项含锁定拒绝与 session.json 块);ui_check 566 项 0 失败;locale_check 0 缺失; 真实资产端到端:1032 顶点编译出 signed+sealed+locked 包(56 927 B 密文),validate --require-signature 退出 0, 改一个字节退出 2;性能报告(perf-report-windows-dev.json):1032 顶点 compose p50 0.50 ms(30 fps 上限内), 20022 顶点/39480 三角形 compose p50 6.15 ms(约 33 ms 帧的 18%),采集线程 submit p95 < 0.4 ms(合成器被人为放慢到 50 ms); 长时报告(soak-report-windows-dev.json):无窗口 10 min/60 fps 尾段 0.354 MB/min,GUI 4 min/30 fps 尾段 0.809 MB/min, 队列上界(mailbox=1、单飞行合成)两者均成立。过程中修掉:GUI 进程里的合成器计时被 GIL/vsync 污染(98.8 ms vs 真值 6.1 ms)、 跨线程读 last_stats 撕裂、key id 无 provider 时会静默写明文包、soak 工具自身记时间列表会无界增长、RSS 读取失败伪装成零增长、 平台锁定不是终态诊断。 - Not in this change: ARM 板卡的能力报告与 2 小时门禁运行(按用户要求暂缓;命令与判定标准已写入阶段 5 文档); GPU 显存随时间的测量(无可移植 API,报告说明渲染器缓冲估计恒定且更新路径不新建 GPU 对象); `cryptography` 在此环境无法联网安装,本机验收用的是本机已有的 cp310 构建(pyproject 里已声明为可选 extra `protected-assets`)。
This commit is contained in:
@@ -38,9 +38,11 @@ from orisys_app_shared.scene3d.contracts import (
|
||||
ExpectedGeometry,
|
||||
FieldDescriptor,
|
||||
FrameIdentity,
|
||||
PlatformInfo,
|
||||
RenderStats,
|
||||
SceneAssets,
|
||||
SceneState,
|
||||
check_platform_lock,
|
||||
diagnostic,
|
||||
validate_assets,
|
||||
)
|
||||
@@ -170,6 +172,8 @@ class Scene3DView(QWidget):
|
||||
snapshot = self._make_snapshot(assets, expected)
|
||||
if snapshot is None:
|
||||
return False
|
||||
if not self._lock_allows(assets):
|
||||
return False
|
||||
self._assets = assets
|
||||
self._expected = expected
|
||||
self._snapshot = snapshot
|
||||
@@ -180,6 +184,19 @@ class Scene3DView(QWidget):
|
||||
self._panel.set_scene(assets)
|
||||
return True
|
||||
|
||||
def _lock_allows(self, assets: SceneAssets) -> bool:
|
||||
"""The half of the platform lock that can be checked before a context exists.
|
||||
|
||||
Operating system and architecture are known now; the graphics fields only after
|
||||
Qt has made a context, which is why the check is split (see
|
||||
``_check_lock_capabilities``). Refusing here is what keeps a package released
|
||||
for one operating system from being drawn on another at all.
|
||||
"""
|
||||
violations = check_platform_lock(assets.platform_lock, PlatformInfo.here())
|
||||
for item in violations:
|
||||
self._on_diagnostic(item)
|
||||
return not violations
|
||||
|
||||
def _make_snapshot(
|
||||
self, assets: SceneAssets, expected: Optional[ExpectedGeometry]
|
||||
) -> Optional[Callable[[Any, FrameIdentity], Any]]:
|
||||
@@ -373,13 +390,50 @@ class Scene3DView(QWidget):
|
||||
self.stateChanged.emit(state)
|
||||
|
||||
def _on_capabilities(self, capabilities: Any) -> None:
|
||||
if self._panel is not None and getattr(capabilities, "software_renderer", False):
|
||||
software = bool(getattr(capabilities, "software_renderer", False))
|
||||
if software and self._panel is not None:
|
||||
self._panel.set_diagnostic(
|
||||
diagnostic(
|
||||
"gl_unsupported",
|
||||
"the OpenGL context is a software rasteriser: expect a slow view",
|
||||
)
|
||||
)
|
||||
self._check_lock_capabilities(capabilities)
|
||||
|
||||
def _check_lock_capabilities(self, capabilities: Any) -> None:
|
||||
"""The graphics half of the platform lock, checked the moment it is knowable.
|
||||
|
||||
A locked package whose lock this machine violates is *withdrawn*: the scene is
|
||||
dropped and the pane shows the reason. Half a lock (the OS matched, the GPU did
|
||||
not) is not a partial success — the package was qualified somewhere else.
|
||||
"""
|
||||
assets = self._assets
|
||||
if assets is None or assets.platform_lock is None:
|
||||
return
|
||||
if capabilities is None:
|
||||
return
|
||||
info = PlatformInfo.here(capabilities)
|
||||
violations = check_platform_lock(assets.platform_lock, info)
|
||||
if not violations:
|
||||
return
|
||||
for item in violations:
|
||||
self._on_diagnostic(item)
|
||||
self._withdraw_scene()
|
||||
|
||||
def _withdraw_scene(self) -> None:
|
||||
"""Drop the scene, keep the pane: a lock violation is not a crash."""
|
||||
self._assets = None
|
||||
self._snapshot = None
|
||||
if self._coordinator is not None:
|
||||
self._coordinator.close()
|
||||
if self._widget is not None:
|
||||
try:
|
||||
self._widget.release_resources()
|
||||
except Exception: # noqa: BLE001 - withdrawal must not raise
|
||||
logger.exception("releasing the GPU resources after a refusal failed")
|
||||
if self._panel is not None:
|
||||
self._panel.set_scene(None)
|
||||
self._enabled = False
|
||||
|
||||
def _on_descriptor(self, descriptor: Any) -> None:
|
||||
"""The frame on screen changed what it claims to be.
|
||||
|
||||
Reference in New Issue
Block a user