From a43f52788a0185f6ce968582df7e386ddba9f3c3 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 18 Nov 2026 09:24:47 +0000 Subject: [PATCH 1/3] [boring] Pin NASM and the macOS cross-toolchain, and attest in a separate job - ilammy/setup-nasm downloads NASM from a mutable branch of its repository, and only then from nasm.us, without checking the download, so its pinned commit doesn't pin the NASM that assembles the released Windows libraries. A local composite action, .github/actions/setup-nasm, downloads NASM 2.16.01 from nasm.us instead and checks it against a pinned SHA-256. - The `test` job of boring.yaml installed the macOS Linux cross-toolchain from a Homebrew tap, which can't be pinned. It now downloads the v15.2.0 release tarball and checks its SHA-256, like the Windows cross-toolchain. - The `precompile` job had `id-token: write` and `attestations: write` to attest the libraries, so every step in it, including compilers and third-party actions, could mint OIDC tokens. A new `attest` job downloads the libraries and attests them, and `precompile` only gets `contents: read`. --- .github/actions/setup-nasm/action.yml | 33 ++++++++++++++++++++++++ .github/workflows/boring.yaml | 35 ++++++++++++++++++++++---- .github/workflows/boring_binaries.yaml | 30 +++++++++++++++++----- 3 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 .github/actions/setup-nasm/action.yml diff --git a/.github/actions/setup-nasm/action.yml b/.github/actions/setup-nasm/action.yml new file mode 100644 index 000000000..26a008420 --- /dev/null +++ b/.github/actions/setup-nasm/action.yml @@ -0,0 +1,33 @@ +# Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +name: Set up NASM +description: >- + Installs NASM on Windows, which assembles the x86-64 assembly of the BoringSSL + that pkgs/boring vendors. Downloads the release from nasm.us and checks it + against a pinned SHA-256, instead of trusting a third-party action and its + mirror. + +runs: + using: composite + steps: + - name: Install NASM + shell: bash + env: + NASM_VERSION: 2.16.01 + # nasm.us doesn't publish checksums. This is the SHA-256 of + # nasm-2.16.01-win64.zip from nasm.us, which matches the hash in Scoop's + # manifest of NASM 2.16.01. + NASM_SHA256: 029eed31faf0d2c5f95783294432cbea6c15bf633430f254bb3c1f195c67ca3a + run: | + url="https://www.nasm.us/pub/nasm/releasebuilds/$NASM_VERSION/win64/nasm-$NASM_VERSION-win64.zip" + curl -fsSL -o "$RUNNER_TEMP/nasm.zip" "$url" + actual="$(sha256sum < "$RUNNER_TEMP/nasm.zip" | cut -d' ' -f1)" + if [ "$actual" != "$NASM_SHA256" ]; then + echo "::error::Expected SHA-256 $NASM_SHA256 for $url, got $actual." + exit 1 + fi + 7z x "$RUNNER_TEMP/nasm.zip" -o"$RUNNER_TEMP" -y > /dev/null + "$RUNNER_TEMP/nasm-$NASM_VERSION/nasm.exe" -v + cygpath -w "$RUNNER_TEMP/nasm-$NASM_VERSION" >> "$GITHUB_PATH" diff --git a/.github/workflows/boring.yaml b/.github/workflows/boring.yaml index 89a85f287..b8166f732 100644 --- a/.github/workflows/boring.yaml +++ b/.github/workflows/boring.yaml @@ -7,11 +7,13 @@ on: push: branches: [ main ] paths: + - '.github/actions/setup-nasm/**' - '.github/workflows/boring.yaml' - 'pkgs/boring/**' pull_request: branches: [ main ] paths: + - '.github/actions/setup-nasm/**' - '.github/workflows/boring.yaml' - 'pkgs/boring/**' schedule: @@ -78,16 +80,39 @@ jobs: sdk: ${{ matrix.sdk }} - name: Setup NASM if: runner.os == 'Windows' - uses: ilammy/setup-nasm@72793074d3c8cdda771dba85f6deafe00623038b + uses: ./.github/actions/setup-nasm - name: Install Linux cross toolchain (Linux) if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - # A third-party tap, which Homebrew can't pin, unlike the Windows download - # below. It only links the test's cross-compiled example, never anything - # that is released. + # The release of messense/homebrew-macos-cross-toolchains that its + # Homebrew tap installs, downloaded directly to pin its SHA-256, like the + # Windows download below. - name: Install Linux cross toolchain (macOS) if: runner.os == 'macOS' - run: brew install messense/macos-cross-toolchains/aarch64-unknown-linux-gnu + shell: bash + run: | + case "$(uname -m)" in + arm64) + url="https://github.com/messense/homebrew-macos-cross-toolchains/releases/download/v15.2.0/aarch64-unknown-linux-gnu-aarch64-darwin.tar.gz" + expected="0f224db36d8572489f09ed5bce39f189eee998f9ab4f8ea07f510d6c7078caa3" + ;; + x86_64) + url="https://github.com/messense/homebrew-macos-cross-toolchains/releases/download/v15.2.0/aarch64-unknown-linux-gnu-x86_64-darwin.tar.gz" + expected="7fa485313b7049d57c5de56bf876d5c4648ebfd736f86a8f4739596218523127" + ;; + *) + echo "::error::Unsupported macOS architecture: $(uname -m)" + exit 1 + ;; + esac + curl -fSL -o "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" "$url" + actual="$(shasum -a 256 < "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" | cut -d' ' -f1)" + if [ "$actual" != "$expected" ]; then + echo "::error::Expected SHA-256 $expected for $url, got $actual." + exit 1 + fi + tar -xzf "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" -C "$RUNNER_TEMP" + echo "$RUNNER_TEMP/aarch64-unknown-linux-gnu/bin" >> "$GITHUB_PATH" - name: Install Linux cross toolchain (Windows) if: runner.os == 'Windows' shell: bash diff --git a/.github/workflows/boring_binaries.yaml b/.github/workflows/boring_binaries.yaml index 8ed7bdace..d0fce6d3d 100644 --- a/.github/workflows/boring_binaries.yaml +++ b/.github/workflows/boring_binaries.yaml @@ -20,6 +20,7 @@ on: push: branches: [ main ] paths: + - '.github/actions/setup-nasm/**' - '.github/workflows/boring_binaries.yaml' - 'pkgs/boring/src/**' - 'pkgs/boring/third_party/boringssl/**' @@ -28,6 +29,7 @@ on: pull_request: branches: [ main ] paths: + - '.github/actions/setup-nasm/**' - '.github/workflows/boring_binaries.yaml' - 'pkgs/boring/src/**' - 'pkgs/boring/tool/precompile_binaries.dart' @@ -40,13 +42,13 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + # Runs compilers and other build tools, so it only gets `contents: read` and + # cannot mint OIDC tokens. The `attest` job attests the libraries. precompile: name: Precompile (${{ matrix.target-os }}-${{ matrix.target-arch }}${{ matrix.ios-sdk && format('-{0}', matrix.ios-sdk) || '' }}) runs-on: ${{ matrix.os }} permissions: contents: read - id-token: write # To sign the provenance attestations of the libraries. - attestations: write # To store the attestations with the repository. defaults: run: working-directory: pkgs/boring/ @@ -116,7 +118,7 @@ jobs: sdk: stable - name: Setup NASM if: matrix.target-os == 'windows' - uses: ilammy/setup-nasm@72793074d3c8cdda771dba85f6deafe00623038b + uses: ./.github/actions/setup-nasm - name: Install dependencies run: dart pub get # Builds the dynamic library, which is bundled when linking is disabled, @@ -202,16 +204,32 @@ jobs: name: binaries-${{ matrix.target-os }}-${{ matrix.target-arch }}${{ matrix.ios-sdk && format('-{0}', matrix.ios-sdk) || '' }} path: pkgs/boring/bin/* if-no-files-found: error + + # Attests the provenance of the libraries that `precompile` built. Only + # downloads and attests them, so no build tool runs with `id-token: write`. + attest: + name: Attest the provenance of the release libraries + needs: precompile + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + permissions: + id-token: write # To sign the provenance attestations of the libraries. + attestations: write # To store the attestations with the repository. + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 + with: + pattern: binaries-* + path: release-assets + merge-multiple: true # Verify with `gh attestation verify --repo dart-lang/tools`. - name: Attest the provenance of the release libraries - if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 with: - subject-path: pkgs/boring/bin/* + subject-path: release-assets/* release: name: Attach the binaries to a GitHub release - needs: precompile + needs: attest if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest permissions: From 699f4cd9e369a0ad8a34fa7038cf5238bd3f14b3 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 18 Nov 2026 09:28:43 +0000 Subject: [PATCH 2/3] [boring] Pass the downloads to sha256sum by path instead of via stdin Avoids any text-mode stdin handling on Windows. --- .github/actions/setup-nasm/action.yml | 2 +- .github/workflows/boring.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-nasm/action.yml b/.github/actions/setup-nasm/action.yml index 26a008420..36a93fd3b 100644 --- a/.github/actions/setup-nasm/action.yml +++ b/.github/actions/setup-nasm/action.yml @@ -23,7 +23,7 @@ runs: run: | url="https://www.nasm.us/pub/nasm/releasebuilds/$NASM_VERSION/win64/nasm-$NASM_VERSION-win64.zip" curl -fsSL -o "$RUNNER_TEMP/nasm.zip" "$url" - actual="$(sha256sum < "$RUNNER_TEMP/nasm.zip" | cut -d' ' -f1)" + actual="$(sha256sum "$RUNNER_TEMP/nasm.zip" | cut -d' ' -f1)" if [ "$actual" != "$NASM_SHA256" ]; then echo "::error::Expected SHA-256 $NASM_SHA256 for $url, got $actual." exit 1 diff --git a/.github/workflows/boring.yaml b/.github/workflows/boring.yaml index b8166f732..177f0a035 100644 --- a/.github/workflows/boring.yaml +++ b/.github/workflows/boring.yaml @@ -106,7 +106,7 @@ jobs: ;; esac curl -fSL -o "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" "$url" - actual="$(shasum -a 256 < "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" | cut -d' ' -f1)" + actual="$(shasum -a 256 "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" | cut -d' ' -f1)" if [ "$actual" != "$expected" ]; then echo "::error::Expected SHA-256 $expected for $url, got $actual." exit 1 @@ -122,7 +122,7 @@ jobs: TOOLCHAIN_SHA256: 9428b2039923916418ec7037025be8cec3202926d65db9452519977834ad2a89 run: | curl -fSL -o "$RUNNER_TEMP/arm-gnu-toolchain.zip" "$TOOLCHAIN_URL" - actual="$(sha256sum < "$RUNNER_TEMP/arm-gnu-toolchain.zip" | cut -d' ' -f1)" + actual="$(sha256sum "$RUNNER_TEMP/arm-gnu-toolchain.zip" | cut -d' ' -f1)" if [ "$actual" != "$TOOLCHAIN_SHA256" ]; then echo "::error::Expected SHA-256 $TOOLCHAIN_SHA256 for $TOOLCHAIN_URL, got $actual." exit 1 From 3a43ff46dc7477d511cc4dbc55e109a83ac835d5 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 18 Nov 2026 09:38:57 +0000 Subject: [PATCH 3/3] [boring] Hash the downloads via stdin again With a path argument, GNU sha256sum escapes the backslashes of a Windows path such as D:\a\_temp and prefixes its output with `\`, so the hash didn't match. --- .github/actions/setup-nasm/action.yml | 2 +- .github/workflows/boring.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-nasm/action.yml b/.github/actions/setup-nasm/action.yml index 36a93fd3b..26a008420 100644 --- a/.github/actions/setup-nasm/action.yml +++ b/.github/actions/setup-nasm/action.yml @@ -23,7 +23,7 @@ runs: run: | url="https://www.nasm.us/pub/nasm/releasebuilds/$NASM_VERSION/win64/nasm-$NASM_VERSION-win64.zip" curl -fsSL -o "$RUNNER_TEMP/nasm.zip" "$url" - actual="$(sha256sum "$RUNNER_TEMP/nasm.zip" | cut -d' ' -f1)" + actual="$(sha256sum < "$RUNNER_TEMP/nasm.zip" | cut -d' ' -f1)" if [ "$actual" != "$NASM_SHA256" ]; then echo "::error::Expected SHA-256 $NASM_SHA256 for $url, got $actual." exit 1 diff --git a/.github/workflows/boring.yaml b/.github/workflows/boring.yaml index 177f0a035..b8166f732 100644 --- a/.github/workflows/boring.yaml +++ b/.github/workflows/boring.yaml @@ -106,7 +106,7 @@ jobs: ;; esac curl -fSL -o "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" "$url" - actual="$(shasum -a 256 "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" | cut -d' ' -f1)" + actual="$(shasum -a 256 < "$RUNNER_TEMP/aarch64-linux-gnu.tar.gz" | cut -d' ' -f1)" if [ "$actual" != "$expected" ]; then echo "::error::Expected SHA-256 $expected for $url, got $actual." exit 1 @@ -122,7 +122,7 @@ jobs: TOOLCHAIN_SHA256: 9428b2039923916418ec7037025be8cec3202926d65db9452519977834ad2a89 run: | curl -fSL -o "$RUNNER_TEMP/arm-gnu-toolchain.zip" "$TOOLCHAIN_URL" - actual="$(sha256sum "$RUNNER_TEMP/arm-gnu-toolchain.zip" | cut -d' ' -f1)" + actual="$(sha256sum < "$RUNNER_TEMP/arm-gnu-toolchain.zip" | cut -d' ' -f1)" if [ "$actual" != "$TOOLCHAIN_SHA256" ]; then echo "::error::Expected SHA-256 $TOOLCHAIN_SHA256 for $TOOLCHAIN_URL, got $actual." exit 1