Skip to content

Commit ae9bc4d

Browse files
authored
Fixed #1870 - Update expire sectxt PGP test (#1877)
1 parent e5cf358 commit ae9bc4d

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ help:
4242
@echo ' make frontend (re)generate CSS and Javascript'
4343
@echo ' make update_cert_fingerprints update certificate fingerprint information'
4444
@echo ' make update_container_documentation update container table for documentation'
45+
@echo ' make update_expire_sectxt_pgp_test test if security.txt or PGP key needs an update'
4546
@echo ' make update_padded_macs update padded MAC information'
4647
@echo ' make update_root_key_file update DNS root key file'
4748

@@ -82,6 +83,9 @@ update_cert_fingerprints:
8283
update_container_documentation:
8384
${DOCKER_COMPOSE_TOOLS_CMD} run --rm tools bin/update_container_documentation.sh
8485

86+
update_expire_sectxt_pgp_test:
87+
${DOCKER_COMPOSE_TOOLS_CMD} run --rm tools bin/update_expire_sectxt_pgp_test.sh
88+
8589
update_padded_macs:
8690
chmod +x $(MACSDIR)/update-macs.sh
8791
cd $(MACSDIR); ./update-macs.sh
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env sh
2+
3+
set -u
4+
5+
SECTXT_PATH_PROD=".well-known/security.txt"
6+
SECTXT_PATH_TEST="docker/integration-tests/www/well-known/security.txt"
7+
8+
PGP_PUBKEY_PATH="interface/static/question@internet.nl_0x45028563.asc"
9+
10+
NOW_TS=$(date +%s)
11+
SECONDS_IN_DAY=86400
12+
13+
SECTXT_THRESHOLD_MONTHS=6
14+
SECTXT_THRESHOLD_DAYS=$(printf "%.0f\n" $(( SECTXT_THRESHOLD_MONTHS * 31 )) )
15+
16+
SECTXT_EXPIRE_DATE=$(sed -nr 's/^Expires: ([0-9-]+).*/\1/p' "$SECTXT_PATH_PROD")
17+
SECTXT_EXPIRE_TS=$(date +%s -d"$SECTXT_EXPIRE_DATE")
18+
SECTXT_EXPIRE_DAYS_LEFT=$(( ( SECTXT_EXPIRE_TS - NOW_TS ) / SECONDS_IN_DAY ))
19+
20+
if [ -n "$(sed -nrz 's/.*[^\r]\n.*/error\n/p' "$SECTXT_PATH_PROD")" ]; then
21+
echo "\e[41mNot all newlines in security.txt are CRLF\e[0m, see Unicode Format for Network Interchange (RFC 5198), please run \$ perl -i -pe 's/(?<!\\\r)\\\n/\\\r\\\n/g' \"$SECTXT_PATH_PROD\""
22+
else
23+
echo "\e[42mVerified all newlines in security.txt are CRLF\e[0m conform Unicode Format for Network Interchange (RFC 5198)"
24+
fi
25+
26+
if [ "$SECTXT_EXPIRE_DAYS_LEFT" -lt "$SECTXT_THRESHOLD_DAYS" ]; then
27+
echo "\e[41mPlease PGP re-sign security.txt\e[0m, expire within $SECTXT_THRESHOLD_MONTHS months on \e[1;41m${SECTXT_EXPIRE_DATE}\e[0m (\e[1;41m${SECTXT_EXPIRE_DAYS_LEFT}\e[0m days valid)\e[0m"
28+
else
29+
echo "\e[42mNo security.txt re-sign needed\e[0m, expire after more than $SECTXT_THRESHOLD_MONTHS months on \e[1;42m${SECTXT_EXPIRE_DATE}\e[0m (\e[1;42m${SECTXT_EXPIRE_DAYS_LEFT}\e[0m days valid)\e[0m"
30+
fi
31+
32+
if [ -n "$(diff "$SECTXT_PATH_PROD" "$SECTXT_PATH_TEST")" ]; then
33+
echo "\e[41mTest failure\e[0m security.txt in production ($SECTXT_PATH_PROD) is different than integration test ($SECTXT_PATH_TEST)"
34+
else
35+
echo "\e[42mTest OK\e[0m security.txt in production is the same as integration test"
36+
fi
37+
38+
GNUPGHOME=$(mktemp -d /tmp/.gnupgXXXXXX)
39+
export GNUPGHOME
40+
PGP_PUBKEY_EXPIRE_TS_LINES=$(gpg --batch --no-tty -q --with-colons --show-keys "$PGP_PUBKEY_PATH" | awk -F: '/^[ps]ub/{print$7}')
41+
echo "$PGP_PUBKEY_EXPIRE_TS_LINES" | while read -r PGP_PUBKEY_EXPIRE_TS; do
42+
PGP_PUBKEY_EXPIRE_DATE=$(date -d"@$PGP_PUBKEY_EXPIRE_TS" -I)
43+
PGP_PUBKEY_EXPIRE_DAYS_LEFT=$(( ( PGP_PUBKEY_EXPIRE_TS - NOW_TS ) / SECONDS_IN_DAY ))
44+
if [ "$PGP_PUBKEY_EXPIRE_TS" -lt "$SECTXT_EXPIRE_TS" ]; then
45+
echo "\e[41mPlease extend the PGP expire\e[0m, PGP key expires on \e[1;41m${PGP_PUBKEY_EXPIRE_DATE}\e[0m (\e[1;41m${PGP_PUBKEY_EXPIRE_DAYS_LEFT}\e[0m days valid) before security.txt expires\e[0m"
46+
else
47+
echo "\e[42mNo PGP extend expire needed\e[0m, expires on \e[1;42m${PGP_PUBKEY_EXPIRE_DATE}\e[0m (\e[1;42m${PGP_PUBKEY_EXPIRE_DAYS_LEFT}\e[0m days valid) after security.txt expires\e[0m"
48+
fi
49+
done
50+
51+
gpg --batch --no-tty -q --import "$PGP_PUBKEY_PATH"
52+
gpg --batch --no-tty -q --verify "$SECTXT_PATH_PROD"
53+
if [ $? -eq 0 ]
54+
then
55+
echo "\e[42mPGP signature can be verified.\e[0m"
56+
else
57+
echo "\e[41mPGP signature verification failed.\e[0m"
58+
fi
59+
rm -rf "$GNUPGHOME"

docker/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ RUN apt update && \
242242
make \
243243
python3-pip \
244244
docker.io \
245+
gpg \
246+
gpg-agent \
245247
shellcheck \
246248
bsdmainutils \
247249
# since this stage ends up in the final image we care about size and remove cache files

documentation/github_release_steps.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ code changes for the next release are already in the main branch.
1212
make update_container_documentation
1313
make update_padded_macs
1414
make update_root_key_file
15+
make update_expire_sectxt_pgp_test
1516
make translate_content_to_main
1617
```
1718
4. Make a release branch for the x.y version if not already present (e.g., release/1.8.x).

0 commit comments

Comments
 (0)