Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ jobs:
compile:
name: ${{matrix.buildname}}
runs-on: ${{matrix.os}}
# id-token and contents are what SignPath's trusted build verification needs
permissions:
id-token: write
contents: read
env:
SIGNPATH_SIGNING_ENABLED: ${{ secrets.SIGNPATH_API_TOKEN != '' && github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' && github.repository == 'Mudlet/bootstrap' }}
# Unlike Mudlet, where only tags and PTBs are signed, every non-PR build
# here can end up in a release: a push to development that adds a game
# cuts one without ever being tagged. So they all get the production
# certificate, and test-signing is left for verifying a SignPath
# configuration change by hand.
SIGNPATH_POLICY_SLUG: 'release-signing'
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -166,25 +178,43 @@ jobs:
shell: msys2 {0}
run: $GITHUB_WORKSPACE/CI/package-win.sh

- name: (Windows) Login to Azure
uses: azure/login@v2
if: runner.os == 'Windows' && github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' && github.repository == 'Mudlet/bootstrap'
- name: (Windows) Prepare launchers for signing
if: runner.os == 'Windows'
shell: msys2 {0}
run: $GITHUB_WORKSPACE/CI/prepare-signing-win.sh

# Every game's launcher goes up in one artifact, and the artifact
# configuration's MudletInstaller-*.exe wildcard covers the lot, so a
# GameList of any length still costs a single signing request.
- name: (Windows) Upload unsigned launchers for signing
id: upload-unsigned-launchers
if: runner.os == 'Windows' && env.SIGNPATH_SIGNING_ENABLED == 'true'
uses: actions/upload-artifact@v6
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Get Azure access token for code signing
shell: pwsh
if: runner.os == 'Windows' && github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' && github.repository == 'Mudlet/bootstrap'
run: |
$token = (az account get-access-token --resource https://codesigning.azure.net | ConvertFrom-Json).accessToken
"::add-mask::$token"
"AZURE_ACCESS_TOKEN=$token" | Add-Content -Path $env:GITHUB_ENV
name: unsigned-launchers
path: ${{env.SIGNING_DIR}}
retention-days: 1

# Writes the signed launchers back over the staged copies, which is where
# deploy-win.sh picks them up from.
- name: (Windows) Sign launchers with SignPath
id: sign-launchers
if: steps.upload-unsigned-launchers.outcome == 'success'
uses: signpath/github-action-submit-signing-request@v2
with:
api-token: ${{secrets.SIGNPATH_API_TOKEN}}
organization-id: ${{secrets.SIGNPATH_ORGANIZATION_ID}}
project-slug: 'bootstrap'
signing-policy-slug: ${{env.SIGNPATH_POLICY_SLUG}}
artifact-configuration-slug: 'launchers'
github-artifact-id: ${{steps.upload-unsigned-launchers.outputs.artifact-id}}
wait-for-completion: true
output-artifact-directory: ${{github.workspace}}/signing-launchers
wait-for-completion-timeout-in-seconds: 3600

- name: (Windows) Deploy
if: runner.os == 'Windows'
shell: msys2 {0}
env:
AZURE_ACCESS_TOKEN: ${{ env.AZURE_ACCESS_TOKEN }}
run: $GITHUB_WORKSPACE/CI/deploy-win.sh

- name: (macOS) Prep for Artifact Upload
Expand Down
12 changes: 12 additions & 0 deletions .signpath/artifact-configuration-launchers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- GitHub Actions packages artifacts as ZIP files, so zip-file is the root element -->
<artifact-configuration xmlns="http://signpath.io/artifact-configuration/v1">
<zip-file>
<!-- One launcher per game in GameList.txt, all built from the same source
and gathered into a single artifact by CI/prepare-signing-win.sh, so
the whole list is covered by one signing request -->
<pe-file path="MudletInstaller-*.exe">
<authenticode-sign/>
</pe-file>
</zip-file>
</artifact-configuration>
12 changes: 12 additions & 0 deletions .signpath/policies/bootstrap/release-signing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SignPath Policy for Release Signing
# This policy is used with the production certificate for official releases
#
# Policy enforcements:
# - Artifacts must be built by GitHub Actions workflows
# - Build must originate from the Mudlet/bootstrap repository
# - Only GitHub-hosted runners are allowed (for open source verification)

github-policies:
runners:
allowed_groups:
- 'GitHub Actions'
12 changes: 12 additions & 0 deletions .signpath/policies/bootstrap/test-signing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SignPath Policy for Test Signing
# This policy is used with the self-signed test certificate during setup verification
#
# Policy enforcements:
# - Artifacts must be built by GitHub Actions workflows
# - Build must originate from the Mudlet/bootstrap repository
# - Only GitHub-hosted runners are allowed (for open source verification)

github-policies:
runners:
allowed_groups:
- 'GitHub Actions'
53 changes: 26 additions & 27 deletions CI/deploy-win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
###########################################################################

# Version: 2.0.0 Rework to build on an MSYS2 MINGW64 Github workflow
# Version: 3.0.0 Windows signing moved from Azure Trusted Signing to
# SignPath. jsign ran here and signed each launcher in place;
# SignPath instead signs an artifact the workflow uploads
# between prepare-signing-win.sh and this script, so all
# that is left to do here is pick the signed launchers back
# up before publishing them.
# 2.0.0 Rework to build on an MSYS2 MINGW64 Github workflow

# Exit codes:
# 0 - Everything is fine. 8-)
Expand All @@ -28,6 +34,7 @@
# 3 - Not used
# 4 - nuget error
# 5 - squirrel error
# 7 - A launcher that should have been signed came back unsigned

if [ "${MSYSTEM}" != "CLANG64" ]; then
echo "Please run this script from a CLANG64 type bash terminal."
Expand Down Expand Up @@ -58,17 +65,14 @@ else
echo "=== Building for regular build ==="
fi

# Set up Java for code signing if Azure token is available
if [ -n "${AZURE_ACCESS_TOKEN}" ]; then
echo "=== Setting up Java 21 for signing ==="
# Java is installed by default, we just need to select which version to use:
JAVA_HOME="$(cygpath -au "${JAVA_HOME_21_X64}")"
export JAVA_HOME
export PATH="${JAVA_HOME}/bin:${PATH}"
JAVA_JAR_WINPATHFILE="$(cygpath -aw "${GITHUB_WORKSPACE}/CI/jsign-7.0-SNAPSHOT.jar")"
echo "Java setup complete for code signing"
# prepare-signing-win.sh staged a copy of every launcher here; where the
# workflow's SignPath steps ran, the copies in here are the signed ones.
signingDir="${GITHUB_WORKSPACE_UNIX_PATH}/signing-launchers"

if [ "${SIGNPATH_SIGNING_ENABLED}" = "true" ]; then
echo "=== Publishing SignPath-signed launchers ==="
else
echo "=== Code signing skipped - no Azure token provided ==="
echo "=== Code signing skipped - publishing unsigned launchers ==="
fi

while IFS= read -r line || [[ -n "$line" ]]; do
Expand All @@ -79,22 +83,17 @@ while IFS= read -r line || [[ -n "$line" ]]; do

cd "$PACKAGE_DIR" || exit 1

# Remove specific file types from the directory
rm ./*.cpp ./*.o

mv "$PACKAGE_DIR/MudletInstaller.exe" "MudletInstaller-${gameName}.exe"

# Sign the executable if Azure token is available
if [ -n "${AZURE_ACCESS_TOKEN}" ]; then
echo "=== Signing MudletInstaller-${gameName}.exe ==="
EXECUTABLE_WINPATH="$(cygpath -aw "${PACKAGE_DIR}/MudletInstaller-${gameName}.exe")"
java.exe -jar "${JAVA_JAR_WINPATHFILE}" \
--storetype TRUSTEDSIGNING \
--keystore eus.codesigning.azure.net \
--storepass "${AZURE_ACCESS_TOKEN}" \
--alias Mudlet/Mudlet \
"${EXECUTABLE_WINPATH}"
echo "Signing completed for MudletInstaller-${gameName}.exe"
# A launcher missing from here means the artifact configuration's wildcard
# did not match it, which SignPath reports as a success while quietly
# handing back fewer files than it was given - so check rather than ship an
# unsigned launcher under a signed release.
signedLauncher="${signingDir}/MudletInstaller-${gameName}.exe"
if [ -f "${signedLauncher}" ]; then
cp "${signedLauncher}" "${PACKAGE_DIR}/MudletInstaller-${gameName}.exe"
elif [ "${SIGNPATH_SIGNING_ENABLED}" = "true" ]; then
echo "ERROR: signing was enabled but SignPath returned no"
echo "MudletInstaller-${gameName}.exe - check the artifact configuration."
exit 7
fi

# Move packaged files to the upload directory
Expand Down
Binary file removed CI/jsign-7.0-SNAPSHOT.jar
Binary file not shown.
90 changes: 90 additions & 0 deletions CI/prepare-signing-win.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
###########################################################################
# Copyright (C) 2024-2024 by John McKisson - [email protected] #
# Copyright (C) 2023-2024 by Stephen Lyons - [email protected] #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
###########################################################################

# Version: 1.0.0 Split out of deploy-win.sh when Windows signing moved from
# Azure Trusted Signing to SignPath. jsign signed each
# launcher in place; SignPath signs an uploaded artifact, so
# the launchers have to be named and gathered up first.

# Gives each launcher its release name and gathers them all into one directory
# for the workflow to hand to SignPath. One artifact for the whole GameList
# means one signing request rather than one per game.

# To be used AFTER package-win.sh has been run; deploy-win.sh then picks the
# signed launchers back up.

# Exit codes:
# 0 - Everything is fine. 8-)
# 1 - Failure to change to a directory
# 2 - Unsupported MSYS2/MINGW shell type
# 6 - No MudletInstaller.exe file found to work with

if [ "${MSYSTEM}" != "CLANG64" ]; then
echo "Please run this script from a CLANG64 type bash terminal."
echo "Current MSYSTEM is: ${MSYSTEM}"
exit 2
fi

cd "$GITHUB_WORKSPACE" || exit 1

GITHUB_WORKSPACE_UNIX_PATH=$(echo "${GITHUB_WORKSPACE}" | sed 's|\\|/|g' | sed 's|D:|/d|g')

# Rebuilt from scratch: SignPath extracts the signed artifact back over this
# directory, so anything stale left here would be published as though it had
# been signed.
signingDir="${GITHUB_WORKSPACE_UNIX_PATH}/signing-launchers"
rm -rf "${signingDir}"
mkdir -p "${signingDir}"

while IFS= read -r line || [[ -n "$line" ]]; do

gameName=$(echo "$line" | tr -cd '[:alnum:]_-')

PACKAGE_DIR="${GITHUB_WORKSPACE_UNIX_PATH}/package-${gameName}"

cd "$PACKAGE_DIR" || exit 1

# Remove specific file types from the directory
rm -f ./*.cpp ./*.o

if [ ! -f "${PACKAGE_DIR}/MudletInstaller.exe" ]; then
echo "ERROR: no MudletInstaller executable found in ${PACKAGE_DIR} - did"
echo "package-win.sh complete successfully?"
exit 6
fi

mv "${PACKAGE_DIR}/MudletInstaller.exe" "MudletInstaller-${gameName}.exe"

cp "${PACKAGE_DIR}/MudletInstaller-${gameName}.exe" "${signingDir}/"

cd "$GITHUB_WORKSPACE" || exit 1

done < "${GITHUB_WORKSPACE}/GameList.txt"

echo "=== Launchers staged for signing ==="
ls -l "${signingDir}"
echo "Total staged: $(du -sh "${signingDir}" | cut -f1)"

# actions/upload-artifact runs in Node.js outside MSYS2 and misinterprets Unix
# paths like /d/a/... as D:\d\a\..., so hand it a native Windows path:
echo "SIGNING_DIR=$(cygpath -aw "${signingDir}")" >> "$GITHUB_ENV"

exit 0
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ cmake -B build
cmake --build build
```

## Acknowledgements

Windows code signing provided by [SignPath.io](https://about.signpath.io), certificate by [SignPath Foundation](https://signpath.org).

## License

See the [Mudlet repository](https://github.com/Mudlet/Mudlet) for license information.
Loading