An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Load the certificate provider for automated release signing
Daniel746fae3c4a7b
diff --git a/scripts/build-release.py b/scripts/build-release.pyindex 0d5f8a7b7f..9832d7c894 100644--- a/scripts/build-release.py+++ b/scripts/build-release.py@@ -296,6 +296,9 @@ def check_signing_pin(pin, thumbprint):if result.returncode == 0:returnif result.returncode != 20 or attempt:+ diagnostic = re.search(r'SIGNING_DIAGNOSTIC:(request|certificate|authentication):((?:0x[0-9a-fA-F]{8},?)+)', result.stderr or '')+ if diagnostic:+ print(diagnostic.group(0), flush=True)raise BuildError("Windows 签名认证失败,请检查 PIN、设备和证书;PIN 错误不会自动重试")# 仅重试已识别的设备通信中断,不重试 PIN 错误。time.sleep(1)diff --git a/scripts/release-sign-windows.ps1 b/scripts/release-sign-windows.ps1index 63b47afcdf..00ed569595 100644--- a/scripts/release-sign-windows.ps1+++ b/scripts/release-sign-windows.ps1@@ -62,12 +62,15 @@ public static class SiYuanReleaseKey {$payload = $null$certificate = $null+$stage = "request"try {# PIN 仅通过标准输入传递,失败信息不包含请求内容。$payload = [Console]::ReadLine() | ConvertFrom-Jsonif ($payload.thumbprint -notmatch '^[0-9a-fA-F]{40}$' -or [string]::IsNullOrEmpty($payload.pin)) {throw "Invalid signing request"}+ $stage = "certificate"+ Import-Module (Join-Path $PSHOME 'Modules\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.psd1')$certificate = Get-Item -LiteralPath ("Cert:\CurrentUser\My\" + $payload.thumbprint)if (!$certificate.HasPrivateKey -or $certificate.NotAfter -le (Get-Date) -or$certificate.NotBefore -ge (Get-Date) -or@@ -78,6 +81,7 @@ try {if ($oid -notin @('1.2.840.113549.1.1.1', '1.2.840.10045.2.1')) {throw "The signing key must use RSA or ECDSA"}+ $stage = "authentication"[SiYuanReleaseKey]::Authenticate($certificate.Handle, $payload.pin, $oid -eq '1.2.840.113549.1.1.1')$payload.pin = $nullforeach ($file in $payload.files) {@@ -89,6 +93,9 @@ try {Write-Output ("Signed and verified: " + $file)}} catch {+ $codes = @([regex]::Matches($_.Exception.ToString(), '0x[0-9a-fA-F]{8}') | ForEach-Object { $_.Value })+ $codes += '0x' + $_.Exception.HResult.ToString('x8')+ [Console]::Error.WriteLine('SIGNING_DIAGNOSTIC:' + $stage + ':' + ($codes -join ','))[Console]::Error.WriteLine("Windows hardware signing failed; check the PIN, token, certificate and timestamp connection")# 仅标识设备通信中断,PIN 错误不重试,避免消耗智能卡重试次数。if ($_.Exception.ToString() -match '0x8010001f|0x80100068') { exit 20 }diff --git a/scripts/test_build_release.py b/scripts/test_build_release.pyindex f70cd7c0b3..a5fc65d99c 100644--- a/scripts/test_build_release.py+++ b/scripts/test_build_release.py@@ -89,6 +89,28 @@ class BuildTests(unittest.TestCase):self.assertNotIn("secret", str(error.exception))self.assertEqual(run.call_count, len(codes))+ def test_signing_diagnostic_does_not_echo_raw_stderr(self):+ result = subprocess.CompletedProcess([], 1, stdout="secret", stderr=+ "secret SIGNING_DIAGNOSTIC:authentication:0x8010006b,0x80131500 secret")+ output = io.StringIO()+ with patch.object(build.subprocess, "run", return_value=result), contextlib.redirect_stdout(output):+ with self.assertRaises(build.BuildError):+ build.check_signing_pin("secret", "A" * 40)+ self.assertEqual(output.getvalue().strip(),+ "SIGNING_DIAGNOSTIC:authentication:0x8010006b,0x80131500")++ @unittest.skipUnless(sys.platform == "win32", "Windows certificate provider")+ def test_signing_certificate_provider_loads_without_module_path(self):+ source = Path(__file__).with_name("release-sign-windows.ps1").read_text(encoding="utf-8")+ load = next(line.strip() for line in source.splitlines() if "Import-Module" in line)+ env = dict(build.os.environ)+ env.pop("PSModulePath", None)+ result = subprocess.run(["powershell.exe", "-NoProfile", "-NonInteractive", "-Command",+ "$ErrorActionPreference='Stop'; " + load ++ "; Get-PSDrive -Name Cert -ErrorAction Stop | Out-Null"],+ env=env, capture_output=True, timeout=30)+ self.assertEqual(result.returncode, 0, result.stderr)+@unittest.skipUnless(sys.platform == "win32", "需要 Windows 批处理")def test_batch_restores_missing_windows_environment_marker(self):batch = self.write(self.root / "environment.bat",