Skip to content

Commit af79d92

Browse files
authored
Merge pull request #94 from gendx/reproducible-check
Add GitHub workflow to check that binaries are reproducible.
2 parents a2eff7c + 0604be6 commit af79d92

9 files changed

+144
-9
lines changed

.github/workflows/reproducible.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: Check that binaries are reproducible
3+
on:
4+
push:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
check_hashes:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-18.04, macos-10.15]
13+
fail-fast: false
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions-rs/toolchain@v1
18+
with:
19+
target: thumbv7em-none-eabi
20+
- uses: actions/setup-python@v1
21+
with:
22+
python-version: 3.7
23+
- name: Install Python dependencies
24+
run: python -m pip install --upgrade pip setuptools wheel
25+
- name: Set up OpenSK
26+
run: ./setup.sh
27+
28+
- name: Use sample cryptographic material
29+
run: rm -R crypto_data/ && cp -r reproducible/sample_crypto_data crypto_data
30+
- name: Computing cryptographic hashes
31+
run: ./reproduce_hashes.sh
32+
33+
- name: Upload reproduced binaries
34+
uses: actions/upload-artifact@v1
35+
with:
36+
name: reproduced-${{ matrix.os }}
37+
path: reproducible/reproduced.tar
38+
39+
- name: Comparing cryptographic hashes
40+
run: git diff --no-index reproducible/reference_binaries_${{ matrix.os }}.sha256sum reproducible/binaries.sha256sum

deploy.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,18 @@ def create_tab_file(self, binaries):
392392
assert self.args.application
393393
info("Generating Tock TAB file for application/example {}".format(
394394
self.args.application))
395-
package_parameter = "-n"
396395
elf2tab_ver = self.checked_command_output(["elf2tab", "--version"]).split(
397-
" ", maxsplit=1)[1]
398-
# Starting from v0.5.0-dev the parameter changed.
399-
# Current pyblished crate is 0.4.0 but we don't want developers
400-
# running the HEAD from github to be stuck
401-
if "0.5.0-dev" in elf2tab_ver:
402-
package_parameter = "--package-name"
396+
"\n", maxsplit=1)[0]
397+
if elf2tab_ver != "elf2tab 0.5.0":
398+
error(
399+
("Detected unsupported elf2tab version {!a}. The following "
400+
"commands may fail. Please use 0.5.0 instead.").format(elf2tab_ver))
403401
os.makedirs(self.tab_folder, exist_ok=True)
404402
tab_filename = os.path.join(self.tab_folder,
405403
"{}.tab".format(self.args.application))
406404
elf2tab_args = [
407-
"elf2tab", package_parameter, self.args.application, "-o", tab_filename
405+
"elf2tab", "--deterministic", "--package-name", self.args.application,
406+
"-o", tab_filename
408407
]
409408
if self.args.verbose_build:
410409
elf2tab_args.append("--verbose")

reproduce_board.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -ex
17+
18+
echo "Board: $BOARD"
19+
./deploy.py --verbose-build --board=$BOARD --no-app --programmer=none
20+
./third_party/tock/tools/sha256sum/target/debug/sha256sum third_party/tock/target/thumbv7em-none-eabi/release/$BOARD.bin >> reproducible/binaries.sha256sum
21+
tar -rvf reproducible/reproduced.tar third_party/tock/target/thumbv7em-none-eabi/release/$BOARD.bin
22+
23+
./deploy.py --verbose-build --board=$BOARD --opensk --programmer=none
24+
./third_party/tock/tools/sha256sum/target/debug/sha256sum target/${BOARD}_merged.hex >> reproducible/binaries.sha256sum
25+
tar -rvf reproducible/reproduced.tar target/${BOARD}_merged.hex

reproduce_hashes.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -ex
17+
18+
rm -f reproducible/binaries.sha256sum
19+
20+
echo "Creating reproducible/reproduced.tar"
21+
touch empty_file
22+
tar -cvf reproducible/reproduced.tar empty_file
23+
rm empty_file
24+
25+
echo "Building sha256sum tool..."
26+
cargo build --manifest-path third_party/tock/tools/sha256sum/Cargo.toml
27+
28+
echo "Computing SHA-256 sums of the boards..."
29+
for board in nrf52840dk nrf52840_dongle nrf52840_dongle_dfu nrf52840_mdk_dfu
30+
do
31+
BOARD=$board ./reproduce_board.sh
32+
done
33+
34+
echo "Computing SHA-256 sum of the TAB file..."
35+
./third_party/tock/tools/sha256sum/target/debug/sha256sum target/tab/ctap2.tab >> reproducible/binaries.sha256sum
36+
tar -rvf reproducible/reproduced.tar target/tab/ctap2.tab
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
b113945b033eb229e3821542f5889769e5fd2e2ae3cb85c6d13a4e05a44a9866 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
2+
d81264ffbce075a78067b666db1988cd0e44e25c0e3f708ada28e90ff29f7339 target/nrf52840dk_merged.hex
3+
346016903ddf244a239162b7c703aafe7ec70a115175e2204892e874f930f6be third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
4+
0c50decccd94e93612f3342ab833a73959d96a754aa6845b755a779a2240c484 target/nrf52840_dongle_merged.hex
5+
adcc4caaea86f7b0d54111d3080802e7389a4e69a8f17945d026ee732ea8daa4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
6+
bbcbd0e72e40257cea94a2fee829d6b2c365e8473f2fb8b6ae685cda4d925f7d target/nrf52840_dongle_dfu_merged.hex
7+
97a7dbdb7c3caa345307d5ff7f7607dad5c2cdc523b43c68d3b741ddce318e92 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
8+
d42f1ec737bd945ae2ddc74a5c179573b36fa720f9a7149b2af67a0e3667fac7 target/nrf52840_mdk_dfu_merged.hex
9+
166523347144bcf9b936f5c265dfb2d7de9ab28569881276df344a6a42423f1b target/tab/ctap2.tab
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
921d6fc31f7235456dd41abc7e634a37ee87b5016b80c979d20ac5d3fcfc6b6b third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
2+
776dab253e0903bffc54a9aeb09323717a4d69e6f1db8a4d88641378a89e47fe target/nrf52840dk_merged.hex
3+
aab5bdc406b1e874b83872c9358d310070b3ce948ec0e20c054fb923ec879249 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
4+
945bfb77e7852d5d6425436208517c478af4ef66a675eded14f768de81512ab4 target/nrf52840_dongle_merged.hex
5+
26b8513e76058e86a01a4b408411ce429834eb2843993eb1671f2487b160bc9a third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
6+
55efa672a5fce6f8757efe16a2c3444d11f8f5a575fc0fedbc2892b587c6ecac target/nrf52840_dongle_dfu_merged.hex
7+
7cc558a66505e8cf8170aab50e6ddcb28f349fd7ced35ce841ccec33a533bea1 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
8+
ed2beb9efd3bab6c91f7d0c6e3c1622d4920f5476844bd7551d51ba524ad4a71 target/nrf52840_mdk_dfu_merged.hex
9+
ee12b35c75402db7fe191f2793209c51657c98662be2b6ff41ae09bccdc7e62a target/tab/ctap2.tab
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-----BEGIN EC PARAMETERS-----
2+
BggqhkjOPQMBBw==
3+
-----END EC PARAMETERS-----
4+
-----BEGIN EC PRIVATE KEY-----
5+
MHcCAQEEICMfnFy7L3y5p2MOGezavAeS+noKYtT21mDcWllN7Y1zoAoGCCqGSM49
6+
AwEHoUQDQgAEhZflF2Fq4xmAofKOxG/0sx8bucdpJPRLR4HXArAFXJzdLF9ofkpn
7+
gzsVWzTYFr+nNiyxySyJsdkH/qQv4rCV0A==
8+
-----END EC PRIVATE KEY-----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIBPDCB4wIUTEbgPPL3tr2rLkI83EyzyQJQmYEwCgYIKoZIzj0EAwIwGzEZMBcG
3+
A1UEAwwQR29vZ2xlIE9wZW5TSyBDQTAeFw0yMDA0MTQxNTM5MDRaFw0zMDA0MTQx
4+
NTM5MDRaMCcxJTAjBgNVBAMMHEdvb2dsZSBPcGVuU0sgSGFja2VyIEVkaXRpb24w
5+
WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASFl+UXYWrjGYCh8o7Eb/SzHxu5x2kk
6+
9EtHgdcCsAVcnN0sX2h+SmeDOxVbNNgWv6c2LLHJLImx2Qf+pC/isJXQMAoGCCqG
7+
SM49BAMCA0gAMEUCIBKkHijpTbjlPDv3oFw/nW/ta8jEMhY8iNCBp9N0+NNYAiEA
8+
ywzrGpmc0reEUFCGHBBdvC2E2SxIlvaefz7umT8ajy4=
9+
-----END CERTIFICATE-----

setup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ pip3 install --user --upgrade 'tockloader~=1.4' six intelhex
9090
rustup target add thumbv7em-none-eabi
9191

9292
# Install dependency to create applications.
93-
cargo install elf2tab
93+
cargo install elf2tab --version 0.5.0

0 commit comments

Comments
 (0)