diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index 5589315491..1aa14d9810 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -27,6 +27,7 @@ on: - 'scripts/test_prune_cached_presets.ps1' - 'scripts/flatpak/**' - 'scripts/msix/**' + - 'scripts/sign_windows.ps1' - 'tests/**' pull_request: @@ -53,6 +54,7 @@ on: - 'scripts/test_prune_cached_presets.ps1' - 'scripts/flatpak/**' - 'scripts/msix/**' + - 'scripts/sign_windows.ps1' - 'tests/**' @@ -128,6 +130,12 @@ jobs: && '[{"arch":"x64","os":"orca-win-server","compiler":"clang"}]' || '[{"arch":"x64","os":"windows-latest","compiler":"clang"},{"arch":"arm64","os":"windows-11-vs2026-arm","compiler":"clang"}]') }} needs: check_build_script + # id-token lets release builds sign through Google Cloud Workload Identity Federation (see + # "Configure code signing" in build_orca.yml); the rest is what the build already used. + permissions: + actions: write + contents: write + id-token: write # Don't run scheduled builds on forks: if: ${{ !cancelled() && needs.check_build_script.result == 'success' && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} uses: ./.github/workflows/build_check_cache.yml diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index 9a4afb63a5..15293ff970 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -35,6 +35,8 @@ jobs: ORCA_UPDATER_SIG_KEY: ${{ secrets.ORCA_UPDATER_SIG_KEY }} NSIS_VERSION: '3.13' NSIS_SHA256: BA63DFFC4410EE89193E1CB5A41989991BD77C61068DA17E3156D136B7B0B3D8 + JSIGN_VERSION: '7.6' + JSIGN_SHA256: 6CF58AA080E7FF82656F320CFF8D4A3BFF30408DF8766806DCBA3740DD839FA5 steps: - name: Checkout @@ -473,6 +475,38 @@ jobs: path: ${{ runner.temp }}/nsis key: nsis-${{ env.NSIS_VERSION }} + # Windows release builds are Authenticode-signed with the company's key in Google Cloud KMS + # (README, Code Signing Policy): pushes, schedules and manual runs of main and release/* in + # this repository, once the WINDOWS_SIGN_* variables are set. The Workload Identity provider + # accepts tokens from nothing else. This runs before the build so that CMake wires signing + # into the NSIS installer. + - name: Configure code signing + id: codesign + if: runner.os == 'Windows' && github.repository == 'OrcaSlicer/OrcaSlicer' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) && github.event_name != 'pull_request' && vars.WINDOWS_SIGN_KMS_KEY != '' + shell: pwsh + env: + CERT_CHAIN: ${{ vars.WINDOWS_SIGN_CERT_CHAIN }} + KMS_KEY: ${{ vars.WINDOWS_SIGN_KMS_KEY }} + run: | + $jar = Join-Path $env:RUNNER_TEMP "jsign-$env:JSIGN_VERSION.jar" + curl.exe -fsSL --retry 5 --retry-all-errors --retry-delay 15 -o $jar "https://github.com/ebourg/jsign/releases/download/$env:JSIGN_VERSION/jsign-$env:JSIGN_VERSION.jar" + if ($LASTEXITCODE -ne 0) { throw "Jsign $env:JSIGN_VERSION download failed." } + if ((Get-FileHash $jar -Algorithm SHA256).Hash -ne $env:JSIGN_SHA256) { + throw "Jsign $env:JSIGN_VERSION does not match its pinned SHA256." + } + $cert = Join-Path $env:RUNNER_TEMP 'codesign-chain.pem' + Set-Content -LiteralPath $cert -Value $env:CERT_CHAIN + "ORCA_SIGN_JSIGN=$jar" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + "ORCA_SIGN_CERTFILE=$cert" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + "ORCA_SIGN_KMS_KEY=$env:KMS_KEY" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + + - name: Set up Java for code signing + if: steps.codesign.outcome == 'success' + uses: actions/setup-java@v6 + with: + distribution: microsoft + java-version: '21' + - name: Build slicer Win if: runner.os == 'Windows' working-directory: ${{ github.workspace }} @@ -492,6 +526,33 @@ jobs: # the checkout cpack re-installs from when it builds the NSIS installer. run: scripts\build_preset_cache.bat --prune-source "%BUILD_DIR%" "resources\profiles" "%BUILD_DIR%\OrcaSlicer\resources\profiles" + # Taken after the build because the token lasts an hour, which covers signing, the installer + # build and the checks. + - name: Authenticate to Google Cloud for code signing + id: codesign_auth + if: steps.codesign.outcome == 'success' + uses: google-github-actions/auth@v3 + with: + workload_identity_provider: ${{ vars.WINDOWS_SIGN_WIF_PROVIDER }} + service_account: ${{ vars.WINDOWS_SIGN_SERVICE_ACCOUNT }} + token_format: access_token + create_credentials_file: false + + # Signs what the portable zip, the artifact and the MSIX package ship, the profile validator, + # and the NSIS plugins the installer carries. The installer build signs its own copy of the + # app, since cpack installs the files again. + - name: Sign Windows binaries + if: steps.codesign.outcome == 'success' + shell: pwsh + env: + ORCA_SIGN_TOKEN: ${{ steps.codesign_auth.outputs.access_token }} + run: | + $paths = @("$env:BUILD_DIR/OrcaSlicer") + foreach ($extra in 'build/src/Release/OrcaSlicer_profile_validator.exe', "$env:RUNNER_TEMP/nsis/Plugins") { + if (Test-Path $extra) { $paths += $extra } + } + ./scripts/sign_windows.ps1 -Path $paths + - name: Pack unit tests Win if: runner.os == 'Windows' working-directory: ${{ github.workspace }} @@ -513,8 +574,37 @@ jobs: - name: Create installer Win if: runner.os == 'Windows' && !vars.SELF_HOSTED working-directory: ${{ github.workspace }}/${{ env.BUILD_DIR }} + # Read by scripts/sign_windows.ps1 when CMake wired signing into the installer. + env: + ORCA_SIGN_TOKEN: ${{ steps.codesign_auth.outputs.access_token }} run: | cpack -G NSIS + if ($LASTEXITCODE -ne 0) { + # makensis writes its errors, and the signing hook's output, only to this log. + Get-Content _CPack_Packages/*/NSIS/NSISOutput.log -Tail 80 + exit 1 + } + + # Checks the shipped files, the installer, the payload inside it (7-Zip unpacks NSIS + # installers) and the uninstaller a silent install writes. + - name: Verify Windows signatures + if: steps.codesign.outcome == 'success' + timeout-minutes: 20 + shell: pwsh + run: | + $paths = @("$env:BUILD_DIR/OrcaSlicer") + $validator = 'build/src/Release/OrcaSlicer_profile_validator.exe' + if (Test-Path $validator) { $paths += $validator } + $installer = Get-ChildItem "$env:BUILD_DIR/OrcaSlicer_Windows_Installer_*.exe" | Select-Object -First 1 + if ($installer) { + $payload = Join-Path $env:RUNNER_TEMP 'installer-payload' + & 'C:/Program Files/7-Zip/7z.exe' x -y "-o$payload" $installer.FullName | Out-Null + if ($LASTEXITCODE -ne 0) { throw "7-Zip could not unpack $($installer.Name)." } + $installed = Join-Path $env:RUNNER_TEMP 'installer-test' + Start-Process -Wait -FilePath $installer.FullName -ArgumentList '/S', "/D=$installed" + $paths += $installer.FullName, $payload, (Join-Path $installed 'Uninstall.exe') + } + ./scripts/sign_windows.ps1 -Verify -Path $paths - name: Pack app if: runner.os == 'Windows' diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c13b50cec..6a3405b015 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1389,6 +1389,33 @@ set(CPACK_PACKAGE_EXECUTABLES "orca-slicer;OrcaSlicer") set(CPACK_CREATE_DESKTOP_LINKS "orca-slicer") set (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE.txt) # must also include in install command +# CI release builds Authenticode-sign the installer as makensis builds it: the payload before it is +# compressed, the uninstaller the installer writes, and the installer itself. Only a configure run +# with ORCA_SIGN_KMS_KEY in its environment (build_orca.yml) wires this in; scripts/sign_windows.ps1 +# lists what signing needs. The commands go into an included file because CPack writes +# CPACK_NSIS_* values into CPackConfig.cmake unescaped. !include needs a native path, with its +# backslashes doubled for CPackConfig.cmake. PowerShell 7 is preferred: Windows PowerShell started +# under a PowerShell 7 session (CI runs cpack from one) inherits its module path and cannot load +# Get-AuthenticodeSignature. +if (WIN32 AND DEFINED ENV{ORCA_SIGN_KMS_KEY}) + find_program(ORCA_SIGN_PWSH pwsh) + if (ORCA_SIGN_PWSH) + set(_orca_sign_shell pwsh) + else () + set(_orca_sign_shell powershell) + endif () + set(ORCA_SIGN_COMMAND "${_orca_sign_shell} -NoProfile -ExecutionPolicy Bypass -File \"${CMAKE_SOURCE_DIR}/scripts/sign_windows.ps1\" -Path") + string(CONFIGURE [=[ +!system '@ORCA_SIGN_COMMAND@ "${INST_DIR}"' = 0 +!uninstfinalize '@ORCA_SIGN_COMMAND@ "%1"' = 0 +!finalize '@ORCA_SIGN_COMMAND@ "%1"' = 0 +]=] _orca_sign_nsh @ONLY) + file(WRITE "${CMAKE_BINARY_DIR}/sign_windows.nsh" "${_orca_sign_nsh}") + file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/sign_windows.nsh" _orca_sign_nsh_path) + string(REPLACE "\\" "\\\\" _orca_sign_nsh_path "${_orca_sign_nsh_path}") + set(CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS "!include \\\"${_orca_sign_nsh_path}\\\"") +endif () + set(CPACK_WIX_UPGRADE_GUID "058245e8-20e0-4a95-9ab7-1acfe17ad511") set(CPACK_GENERATOR NSIS) include(CPack) diff --git a/README.md b/README.md index 1c87cd00b8..c14ff19a7b 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ The [wiki](https://www.orcaslicer.com/wiki) aims to provide a detailed explanati 📥 **[Download the Latest Stable Release](https://github.com/OrcaSlicer/OrcaSlicer/releases/latest)** Visit our GitHub Releases page for the latest stable version of OrcaSlicer, recommended for most users. -Windows release binaries are code signed; see our [Code signing policy](#code-signing-policy). +Windows and macOS release and nightly builds are code signed. ## Nightly Builds @@ -245,16 +245,6 @@ OrcaSlicer began in that same spirit, drawing from BambuStudio, PrusaSlicer, and The OrcaSlicer logo was designed by community member [Justin Levine](https://github.com/jal-co). -# Code Signing Policy - -Free code signing provided by [SignPath.io](https://about.signpath.io), certificate by [SignPath Foundation](https://signpath.org). - -Windows release binaries are built by GitHub Actions from this repository and signed through the SignPath Foundation program. Every signing request is manually approved. - -**Team roles:** [SoftFever](https://github.com/SoftFever) is the committer, reviewer and approver for all signed releases. - -**Privacy policy:** See the [OrcaSlicer privacy policy](https://www.orcaslicer.com/privacy-policy/). - # License - **OrcaSlicer** is licensed under the GNU Affero General Public License, version 3. diff --git a/scripts/sign_windows.ps1 b/scripts/sign_windows.ps1 new file mode 100644 index 0000000000..c900f52d9c --- /dev/null +++ b/scripts/sign_windows.ps1 @@ -0,0 +1,157 @@ +<# +.SYNOPSIS + Authenticode-signs the Windows binaries OrcaSlicer ships, or checks that they are signed. + +.DESCRIPTION + Signs with Jsign (https://github.com/ebourg/jsign) and the release key in Google Cloud KMS. The + private key never leaves the HSM: Jsign sends each file's digest to Cloud KMS and builds the + signature from the result and the certificate chain. Every signature is timestamped (RFC 3161), + so it stays valid after the certificate expires. + + A directory is searched recursively for .exe, .dll and .pyd files. A file named directly is + handled whatever its name, which covers the temporary files makensis passes for the uninstaller + and the installer. Files that already carry a signature are left alone: they are vendor-signed + redistributables such as the Microsoft runtime, and signing them again would nest a second + signature under the vendor's. + + With -Verify nothing is signed. The check fails if any of those files is unsigned or has a + damaged signature, if a file named directly is not signed with the release certificate, or if + a signature made with the release certificate has no timestamp. + + build_orca.yml sets the environment. CMakeLists.txt wires the script into the NSIS installer + build when ORCA_SIGN_KMS_KEY is set at configure time. + + Environment: + ORCA_SIGN_KMS_KEY Cloud KMS key version: + projects/
/locations/