Files
excel-search-tool/go/sign.bat
T
2026-09-28 10:15:35 +08:00

56 lines
1.9 KiB
Batchfile

@echo off
REM ============================================================
REM Excel Keyword Search Tool - code signing script
REM Signs every exe in bin\ with Authenticode + RFC3161 timestamp
REM (timestamp keeps signature valid after cert expiry).
REM
REM Usage:
REM sign.bat sign bin\*.exe with default pfx password
REM set SIGN_PASSWORD=xxx && sign.bat use custom pfx password
REM
REM Prerequisites:
REM certs\codesign.pfx must exist (private key material, gitignored)
REM tools\osslsigncode\ portable build must be present
REM NOTE: keep this file pure ASCII to avoid cmd codepage garbling.
REM ============================================================
setlocal enabledelayedexpansion
set "ROOT=%~dp0"
set "PFX=%ROOT%certs\codesign.pfx"
set "SIGNEXE=%ROOT%tools\osslsigncode\osslsigncode.exe"
if "%SIGN_PASSWORD%"=="" set "SIGN_PASSWORD=ExcelSearch2026"
set "TS_SERVER=http://timestamp.digicert.com"
set "APPNAME=Excel Keyword Search Tool"
if not exist "%PFX%" (
echo [sign] ERROR: certificate not found at %PFX%
exit /b 1
)
if not exist "%SIGNEXE%" (
echo [sign] ERROR: osslsigncode not found at %SIGNEXE%
exit /b 1
)
set "COUNT=0"
set "FAILED=0"
for %%f in ("%ROOT%bin\*.exe") do (
if exist "%%f" (
"%SIGNEXE%" sign -pkcs12 "%PFX%" -pass "%SIGN_PASSWORD%" -n "%APPNAME%" -t "%TS_SERVER%" -in "%%f" -out "%%~dpnf.signed.exe" >nul 2>&1
if errorlevel 1 (
echo [sign] FAILED : %%~nxf
set /a FAILED+=1
) else (
move /y "%%~dpnf.signed.exe" "%%f" >nul 2>&1
echo [sign] SIGNED : %%~nxf
set /a COUNT+=1
)
)
)
echo.
if %FAILED% gtr 0 (
echo [sign] Done: %COUNT% signed, %FAILED% failed.
exit /b 1
)
echo [sign] Done: %COUNT% executable(s) signed and timestamped.
exit /b 0