Skip to content

Commit

Permalink
ci: validate package signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
blocktrron committed Jul 28, 2024
1 parent 8d72a2c commit a0a88f2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ jobs:
name: build-packages
runs-on: ubuntu-24.04
needs: build-meta
outputs:
usign-private-key:
${{ steps.build-keypair.outputs.usign-private-key }}
usign-public-key:
${{ steps.build-keypair.outputs.usign-public-key }}
usign-fingerprint:
${{ steps.build-keypair.outputs.usign-singerprint }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -94,10 +101,19 @@ jobs:
with:
path: /tmp/openwrt-sdk
key: ${{ steps.cache-key-sdk.outputs.cache-key }}
- name: Get build keypair
id: build-keypair
env:
GHA_PRIVATE_KEY: ${{ secrets.USIGN_PRIVATE_KEY }}
GHA_PUBLIC_KEY: ${{ vars.USIGN_PUBLIC_KEY }}
run: |
bash $GITHUB_WORKSPACE/contrib/build-key.sh /tmp/openwrt-sdk/staging_dir/host/bin/usign
- name: Save secret build-key
run: |
echo "${{ steps.build-keypair.outputs.usign-private-key }}" > /tmp/openwrt-sdk/build-key
- name: Create SDK configuration
run: |
cd /tmp/openwrt-sdk
echo "# CONFIG_SIGNED_PACKAGES is not set" > /tmp/openwrt-sdk/.config
echo CONFIG_FFDA_OOB_FIRMWARE_VERSION=\"${{ needs.build-meta.outputs.firmware-version }}\" >> /tmp/openwrt-sdk/.config
make defconfig
- name: Build packages
Expand Down Expand Up @@ -161,9 +177,11 @@ jobs:
with:
path: /tmp/openwrt-imagebuilder
key: ${{ steps.cache-key-ib.outputs.cache-key }}
- name: Save pulic build-key
run: |
echo ${{ needs.build-packages.outputs.usign-public-key }} > /tmp/openwrt-imagebuilder/keys/${{ needs.build-packages.outputs.usign-fingerprint }}
- name: Link repositories
run: |
sed -i '/^option check_signature/d' /tmp/openwrt-imagebuilder/repositories.conf
echo "src oobfw file:///tmp/packages/packages-oobfw" >> /tmp/openwrt-imagebuilder/repositories.conf
echo "src oobpkgs file:///tmp/packages/packages-oobpkgs" >> /tmp/openwrt-imagebuilder/repositories.conf
- name: Set Version information
Expand Down
36 changes: 36 additions & 0 deletions contrib/build-key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

USIGN_PATH="$1"
KEY_PATH="$(mktemp -d)"

if [ -z "$USIGN_PATH" ] || [ -z "$KEY_PATH" ]; then
echo "Usage: $0 <usign_path> <key_path>"
exit 1
fi

$USIGN_PATH -G -p "$KEY_PATH/public.key" -s "$KEY_PATH/private.key"

if [ -n "$GHA_PRIVATE_KEY" ] && [ -n "$GHA_PUBLIC_KEY" ]; then
echo "GHA_PRIVATE_KEY and GHA_PUBLIC_KEY is set"

echo "$GHA_PRIVATE_KEY" > "$KEY_PATH/private.key"
echo "$GHA_PUBLIC_KEY" > "$KEY_PATH/public.key"
fi

USIGN_PRIVATE_KEY="$(cat $KEY_PATH/private.key)"
USIGN_PUBLIC_KEY="$(cat $KEY_PATH/public.key)"
USIGN_FINGERPRINT="$($USIGN_PATH -F -p $KEY_PATH/public.key)"

echo "usign-private-key<<EOF" >> "$GITHUB_OUTPUT"
echo "$USIGN_PRIVATE_KEY" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

echo "usign-public-key<<EOF" >> "$GITHUB_OUTPUT"
echo "$USIGN_PUBLIC_KEY" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

echo "usign-fingerprint<<EOF" >> "$GITHUB_OUTPUT"
echo "$USIGN_FINGERPRINT" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

rm -rf "$KEY_PATH"

0 comments on commit a0a88f2

Please sign in to comment.