Skip to content

Commit e742ded

Browse files
committed
feat: Check hashes of Windows dependencies when cross-compiling
It's a disableable option since we allow the user to change versions of dependencies and we obviously have hashes only for the default versions, we are not able to verify hashes of any other version, so it might be handy to be able to disable the check in that case.
1 parent dfb9a0b commit e742ded

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

INSTALL.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,15 @@ Get the toxcore source code and navigate to `other/docker/windows`.
299299
Build the container image based on the Dockerfile. The following options are
300300
available to customize the building of the container image.
301301

302-
| Name | Description | Expected Value | Default Value |
303-
| --------------------- | ------------------------------------------- | ----------------------------------- | ------------- |
304-
| `SUPPORT_ARCH_i686` | Support building 32-bit toxcore. | "true" or "false" (case sensitive). | true |
305-
| `SUPPORT_ARCH_x86_64` | Support building 64-bit toxcore. | "true" or "false" (case sensitive). | true |
306-
| `SUPPORT_TEST` | Support running toxcore automated tests. | "true" or "false" (case sensitive). | false |
307-
| `VERSION_OPUS` | Version of libopus to build toxcore with. | Numeric version number. | 1.4 |
308-
| `VERSION_SODIUM` | Version of libsodium to build toxcore with. | Numeric version number. | 1.0.19 |
309-
| `VERSION_VPX` | Version of libvpx to build toxcore with. | Numeric version number. | 1.14.0 |
302+
| Name | Description | Expected Value | Default Value |
303+
| -------------------------- | ----------------------------------------------------- | ----------------------------------- | ------------- |
304+
| `SUPPORT_ARCH_i686` | Support building 32-bit toxcore. | "true" or "false" (case sensitive). | true |
305+
| `SUPPORT_ARCH_x86_64` | Support building 64-bit toxcore. | "true" or "false" (case sensitive). | true |
306+
| `SUPPORT_TEST` | Support running toxcore automated tests. | "true" or "false" (case sensitive). | false |
307+
| `VERSION_OPUS` | Version of libopus to build toxcore with. | Numeric version number. | 1.4 |
308+
| `VERSION_SODIUM` | Version of libsodium to build toxcore with. | Numeric version number. | 1.0.19 |
309+
| `VERSION_VPX` | Version of libvpx to build toxcore with. | Numeric version number. | 1.14.0 |
310+
| `ENABLE_HASH_VERIFICATION` | Verify the hashes of the default dependency versions. | "true" or "false" (case sensitive). | true |
310311

311312
Example of building a container image with options
312313

other/docker/windows/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FROM debian:bookworm-slim
77
ARG VERSION_OPUS=1.4 \
88
VERSION_SODIUM=1.0.19 \
99
VERSION_VPX=1.14.0 \
10+
ENABLE_HASH_VERIFICATION=true \
1011
\
1112
SUPPORT_TEST=false \
1213
SUPPORT_ARCH_i686=true \
@@ -20,6 +21,7 @@ ENV SUPPORT_TEST=${SUPPORT_TEST} \
2021
CROSS_COMPILE=${CROSS_COMPILE}
2122

2223
WORKDIR /work
24+
COPY check_sha256.sh .
2325
COPY get_packages.sh .
2426
RUN ./get_packages.sh
2527

other/docker/windows/build_dependencies.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ fi
77

88
#=== Cross-Compile Dependencies ===
99

10+
. ./check_sha256.sh
11+
1012
build() {
1113
ARCH=${1}
1214

@@ -41,6 +43,7 @@ build() {
4143
echo
4244
echo "=== Building Sodium $VERSION_SODIUM $ARCH ==="
4345
curl "${CURL_OPTIONS[@]}" -O "https://github.com/jedisct1/libsodium/releases/download/$VERSION_SODIUM-RELEASE/libsodium-$VERSION_SODIUM.tar.gz"
46+
check_sha256 "018d79fe0a045cca07331d37bd0cb57b2e838c51bc48fd837a1472e50068bbea" "libsodium-$VERSION_SODIUM.tar.gz"
4447
tar -xf "libsodium-$VERSION_SODIUM.tar.gz"
4548
cd "libsodium-stable"
4649
./configure \
@@ -65,6 +68,7 @@ build() {
6568
fi
6669

6770
curl "${CURL_OPTIONS[@]}" -O "https://ftp.osuosl.org/pub/xiph/releases/opus/opus-$VERSION_OPUS.tar.gz"
71+
check_sha256 "c9b32b4253be5ae63d1ff16eea06b94b5f0f2951b7a02aceef58e3a3ce49c51f" "opus-$VERSION_OPUS.tar.gz"
6872
tar -xf "opus-$VERSION_OPUS.tar.gz"
6973
cd "opus-$VERSION_OPUS"
7074
CFLAGS="$CFLAGS $LIB_OPUS_CFLAGS" \
@@ -93,6 +97,7 @@ build() {
9397
LIB_VPX_CFLAGS="-fno-asynchronous-unwind-tables"
9498
fi
9599
curl "${CURL_OPTIONS[@]}" "https://github.com/webmproject/libvpx/archive/v$VERSION_VPX.tar.gz" -o "libvpx-$VERSION_VPX.tar.gz"
100+
check_sha256 "5f21d2db27071c8a46f1725928a10227ae45c5cd1cad3727e4aafbe476e321fa" "libvpx-$VERSION_VPX.tar.gz"
96101
tar -xf "libvpx-$VERSION_VPX.tar.gz"
97102
cd "libvpx-$VERSION_VPX"
98103
CFLAGS="$CFLAGS $LIB_VPX_CFLAGS" \
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
check_sha256() {
4+
[ "$ENABLE_HASH_VERIFICATION" = "true" ] && _check_sha256 "$@"
5+
}
6+
7+
_check_sha256() {
8+
if ! (echo "$1 $2" | sha256sum -c --status -); then
9+
echo "Error: sha256 of $2 doesn't match the known one."
10+
echo "Expected: $1 $2"
11+
echo "Got: $(sha256sum "$2")"
12+
return 1
13+
fi
14+
echo "sha256 matches the expected one: $1"
15+
return 0
16+
}

other/docker/windows/get_packages.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ if [ "$SUPPORT_TEST" = "true" ]; then
5151
curl "${CURL_OPTIONS[@]}" -O --output-dir /etc/apt/sources.list.d/ \
5252
https://dl.winehq.org/wine-builds/debian/dists/bookworm/winehq-bookworm.sources
5353

54+
. ./check_sha256.sh
55+
check_sha256 "78b185fabdb323971d13bd329fefc8038e08559aa51c4996de18db0639a51df6" \
56+
"/etc/apt/keyrings/winehq-archive.key"
57+
check_sha256 "8dd8ef66c749d56e798646674c1c185a99b3ed6727ca0fbb5e493951e66c0f9e" \
58+
"/etc/apt/sources.list.d/winehq-bookworm.sources"
59+
5460
dpkg --add-architecture i386
5561
apt-get update
5662
apt-get install -y \

other/windows_build_script_toxcore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export VERSION_OPUS="1.4"
77
export VERSION_SODIUM="1.0.19"
88
export VERSION_VPX="1.14.0"
9+
export ENABLE_HASH_VERIFICATION=true
910

1011
export SUPPORT_TEST=false
1112
export SUPPORT_ARCH_i686=true

0 commit comments

Comments
 (0)