Skip to content

Commit 3c9f959

Browse files
Harden APT repository metadata publishing
1 parent a307075 commit 3c9f959

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

update_apt_repo.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ UPSTREAM_SIGNATURE_KEY_URL="${UPSTREAM_SIGNATURE_KEY_URL:-https://keys.openpgp.o
2626
APT_REPO_URL="${APT_REPO_URL%/}"
2727
APT_KEYRING_URL="${APT_REPO_URL}/${APT_KEYRING_FILE}"
2828

29+
write_by_hash_copy() {
30+
local file_path="$1"
31+
local hash_dir
32+
local sha256_value
33+
34+
hash_dir="$(dirname "$file_path")/by-hash/SHA256"
35+
sha256_value="$(sha256sum "$file_path" | awk '{print $1}')"
36+
mkdir -p "$hash_dir"
37+
cp -f "$file_path" "$hash_dir/$sha256_value"
38+
}
39+
2940
require_cmd() {
3041
local cmd="$1"
3142
if ! command -v "$cmd" >/dev/null 2>&1; then
@@ -68,6 +79,15 @@ if [[ ${#deb_assets[@]} -eq 0 ]]; then
6879
exit 1
6980
fi
7081

82+
release_date="$(LC_ALL=C date -Ru)"
83+
release_published_at="$(jq -r '.published_at // .created_at // empty' "$RELEASE_FILE")"
84+
if [[ -n "$release_published_at" ]]; then
85+
parsed_release_date="$(LC_ALL=C date -Ru -d "$release_published_at" 2>/dev/null || true)"
86+
if [[ -n "$parsed_release_date" ]]; then
87+
release_date="$parsed_release_date"
88+
fi
89+
fi
90+
7191
pool_dir="$APT_REPO_ROOT/pool/$APT_COMPONENT"
7292
dist_component_dir="$APT_REPO_ROOT/dists/$APT_SUITE/$APT_COMPONENT"
7393

@@ -155,7 +175,9 @@ for arch in "${arches[@]}"; do
155175
}
156176
}
157177
' "$all_packages_file" > "$dist_component_dir/binary-$arch/Packages"
158-
gzip -9c "$dist_component_dir/binary-$arch/Packages" > "$dist_component_dir/binary-$arch/Packages.gz"
178+
gzip -n -9c "$dist_component_dir/binary-$arch/Packages" > "$dist_component_dir/binary-$arch/Packages.gz"
179+
write_by_hash_copy "$dist_component_dir/binary-$arch/Packages"
180+
write_by_hash_copy "$dist_component_dir/binary-$arch/Packages.gz"
159181
done
160182

161183
rm -f "$all_packages_file"
@@ -169,7 +191,8 @@ mapfile -t index_files < <(find "$release_dir/$APT_COMPONENT" -type f \( -name "
169191
echo "Label: Bitcoin Safe"
170192
echo "Suite: $APT_SUITE"
171193
echo "Codename: $APT_SUITE"
172-
echo "Date: $(LC_ALL=C date -Ru)"
194+
echo "Date: $release_date"
195+
echo "Acquire-By-Hash: yes"
173196
echo "Architectures: ${arches[*]}"
174197
echo "Components: $APT_COMPONENT"
175198
echo "Description: Bitcoin Safe APT repository"

0 commit comments

Comments
 (0)