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:
@@ -453,8 +453,33 @@ class StudioMainWindow(QMainWindow):
|
||||
self.toolbar.set_record_checked(False)
|
||||
self._refresh_record_state()
|
||||
return
|
||||
# What the display actually did, while the writer is still accepting events:
|
||||
# the block in session.json knows the configuration, and only this moment knows
|
||||
# the totals. Logged before the stop so it cannot be lost to a closed queue.
|
||||
self._log_visualization3d_totals()
|
||||
self._publish_record_report(self.recording.stop(wait=wait))
|
||||
|
||||
def _log_visualization3d_totals(self) -> None:
|
||||
"""One event with the display-side counters. Never raises, never blocks."""
|
||||
try:
|
||||
view = self.mesh3d_panel.view
|
||||
if view is None:
|
||||
return
|
||||
coordinator = view.coordinator
|
||||
stats = view.render_stats()
|
||||
shown = int(getattr(stats, "displayed_frames", 0) or 0)
|
||||
dropped = int(
|
||||
coordinator.superseded_frames if coordinator is not None else 0
|
||||
)
|
||||
self.recorder.log_event(
|
||||
"visualization3d",
|
||||
f"shown={shown} dropped_display={dropped} "
|
||||
f"stale={int(getattr(coordinator, 'stale_frames', 0) or 0)} "
|
||||
f"invalid={int(getattr(coordinator, 'invalid_frames', 0) or 0)}",
|
||||
)
|
||||
except Exception: # noqa: BLE001 - a picture must not fail a recording
|
||||
logger.exception("Could not log the 3D display totals")
|
||||
|
||||
def _publish_record_report(self, report) -> None:
|
||||
"""Update the button and the summary from a recording report."""
|
||||
self.toolbar.set_record_status("")
|
||||
@@ -580,8 +605,99 @@ class StudioMainWindow(QMainWindow):
|
||||
"filter": self._filter_metadata(),
|
||||
"recording_mode": self.toolbar.record_mode(),
|
||||
"video_config": config.as_dict(),
|
||||
# What the 3D pane was, for a reader who has to decide whether a picture
|
||||
# was part of the observation. Display-only facts: no measurement, and no
|
||||
# counters (those are only known when the recording stops and travel as an
|
||||
# event).
|
||||
"visualization3d": self._visualization3d_metadata(),
|
||||
}
|
||||
|
||||
def _visualization3d_metadata(self) -> dict:
|
||||
"""The pane's state for ``session.json``. Must never block a recording.
|
||||
|
||||
Every read is guarded and every value is a plain JSON type: this method runs
|
||||
on the way into a recording, and a widget that has been torn down or a scene
|
||||
that was refused is not a reason to fail one.
|
||||
"""
|
||||
from orisys_app_shared.record import build_visualization3d_block
|
||||
|
||||
enabled = False
|
||||
available = False
|
||||
reason = ""
|
||||
scene: dict = {}
|
||||
gl: dict = {}
|
||||
display: dict = {}
|
||||
stream: dict = {}
|
||||
try:
|
||||
pane = self.mesh3d_panel
|
||||
view = pane.view
|
||||
enabled = bool(pane.enabled())
|
||||
available = bool(pane.is_available())
|
||||
diagnostic = pane.last_diagnostic
|
||||
assets = view.assets if view is not None else None
|
||||
if assets is None:
|
||||
reason = (
|
||||
diagnostic.message
|
||||
if diagnostic is not None
|
||||
else str(t("panels.mesh3d_no_scene"))
|
||||
)
|
||||
else:
|
||||
scene = {
|
||||
"path": str(pane.scene_path() or ""),
|
||||
"asset_id": str(getattr(assets, "asset_id", "")),
|
||||
"asset_version": str(getattr(assets, "asset_version", "")),
|
||||
"asset_hash": str(getattr(assets, "asset_hash", "")),
|
||||
"geometry_id": str(getattr(assets, "geometry_id", "")),
|
||||
"field_domain_id": str(getattr(assets, "field_domain_id", "")),
|
||||
"platform_lock": (
|
||||
assets.platform_lock.to_dict()
|
||||
if getattr(assets, "platform_lock", None) is not None
|
||||
else None
|
||||
),
|
||||
}
|
||||
widget = getattr(view, "gl_widget", None)
|
||||
capabilities = widget.capabilities() if widget is not None else None
|
||||
if capabilities is not None:
|
||||
gl = {
|
||||
"profile": str(capabilities.profile),
|
||||
"vendor": str(capabilities.vendor),
|
||||
"renderer": str(capabilities.renderer),
|
||||
"gl_version": str(capabilities.gl_version),
|
||||
"glsl_version": str(capabilities.glsl_version),
|
||||
"software_renderer": bool(capabilities.software_renderer),
|
||||
}
|
||||
settings = view.settings()
|
||||
scale = settings.color_scale
|
||||
display = {
|
||||
"deform_enabled": bool(settings.deform_enabled),
|
||||
"display_gain": float(settings.display_gain),
|
||||
"housing_visible": bool(settings.housing_visible),
|
||||
"max_fps": int(settings.max_fps),
|
||||
"scale_mode": str(scale.mode) if scale is not None else "none",
|
||||
"scale_lower": float(scale.lower) if scale is not None else None,
|
||||
"scale_upper": float(scale.upper) if scale is not None else None,
|
||||
}
|
||||
descriptor = view.last_descriptor
|
||||
if descriptor is not None:
|
||||
stream = {
|
||||
"quantity": str(descriptor.quantity),
|
||||
"unit": str(descriptor.unit),
|
||||
"quality": str(descriptor.quality),
|
||||
"signed": bool(descriptor.signed),
|
||||
}
|
||||
except Exception: # noqa: BLE001 - a recording must not fail over a picture
|
||||
logger.exception("Could not describe the 3D pane for the recording")
|
||||
reason = reason or "the 3D pane could not be described"
|
||||
return build_visualization3d_block(
|
||||
enabled=enabled,
|
||||
available=available,
|
||||
reason=reason,
|
||||
scene=scene or None,
|
||||
gl=gl or None,
|
||||
display=display or None,
|
||||
stream=stream or None,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _config_hash(config_ref: str) -> str:
|
||||
try:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -41,7 +41,9 @@ _REJECTED = "rejected"
|
||||
|
||||
#: Diagnostics that mean "this view cannot draw here", as opposed to "this one frame
|
||||
#: was refused". The first kind replaces the picture; the second must not.
|
||||
_TERMINAL_CODES = frozenset({"gl_unsupported", "shader_compile_failed"})
|
||||
_TERMINAL_CODES = frozenset(
|
||||
{"gl_unsupported", "shader_compile_failed", "platform_mismatch"}
|
||||
)
|
||||
|
||||
#: One locale key per state, so ``retranslate`` can rebuild whatever is on screen.
|
||||
_MESSAGE_KEYS = {
|
||||
|
||||
Reference in New Issue
Block a user