Skip to content

Commit 0294f2f

Browse files
committed
Drop PQ support if fragments are blocked
But if fragments are blocked, the server is not going to be reliable anyway
1 parent cc8829c commit 0294f2f

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ENV SERIAL=1
55

66
ENV CFLAGS=-O3
77
ENV BUILD_DEPS="curl make build-essential git libevent-dev libexpat1-dev autoconf file libssl-dev flex bison"
8-
ENV RUNTIME_DEPS="bash util-linux coreutils findutils grep libssl3 ldnsutils libevent-2.1 expat ca-certificates runit runit-helper jed"
8+
ENV RUNTIME_DEPS="bash util-linux coreutils findutils grep libssl3 ldnsutils bind9-dnsutils libevent-2.1 expat ca-certificates runit runit-helper jed"
99

1010
RUN apt-get update && apt-get -qy dist-upgrade && apt-get -qy clean && \
1111
apt-get install -qy --no-install-recommends $RUNTIME_DEPS && \

entrypoint.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ init() {
8080
-e "s#@METRICS_ADDRESS@#${metrics_address}#" \
8181
"$CONFIG_FILE_TEMPLATE" >"$CONFIG_FILE"
8282

83+
update_pq_enabled
84+
8385
mkdir -p -m 700 "${STATE_DIR}"
8486
chown _encrypted-dns:_encrypted-dns "${STATE_DIR}"
8587

@@ -160,6 +162,39 @@ ensure_initialized() {
160162
fi
161163
}
162164

165+
fragmented_udp_supported() {
166+
if ! command -v dig >/dev/null 2>&1; then
167+
echo "Cannot check fragmented UDP support: dig is not installed" >&2
168+
return 1
169+
fi
170+
171+
for server in 198.41.0.4 199.9.14.201 192.33.4.12 199.7.91.13; do
172+
if dig +notcp +dnssec +bufsize=4096 +ignore +time=3 +tries=1 "@$server" . DNSKEY 2>/dev/null |
173+
awk '
174+
/^;; flags:/ && /[ ;]tc[ ;]/ { truncated = 1 }
175+
/^[.][[:space:]]+[0-9]+[[:space:]]+IN[[:space:]]+DNSKEY[[:space:]]/ { dnskey = 1 }
176+
/^;; MSG SIZE rcvd:/ && $5 > 512 { large = 1 }
177+
END { exit !(dnskey && large && !truncated) }
178+
'; then
179+
return 0
180+
fi
181+
done
182+
183+
return 1
184+
}
185+
186+
update_pq_enabled() {
187+
if fragmented_udp_supported; then
188+
pq_enabled="true"
189+
echo "Fragmented UDP support detected; enabling post-quantum DNSCrypt certificates"
190+
else
191+
pq_enabled="false"
192+
echo "Fragmented UDP support not detected; disabling post-quantum DNSCrypt certificates" >&2
193+
fi
194+
195+
sed -i -E "s/^[[:space:]]*pq_enabled[[:space:]]*=.*/pq_enabled = ${pq_enabled}/" "$CONFIG_FILE"
196+
}
197+
163198
start() {
164199
ensure_initialized
165200
if [ -f "${KEYS_DIR}/secret.key" ]; then
@@ -170,6 +205,8 @@ start() {
170205
--dry-run >/dev/null || exit 1
171206
mv -f "${KEYS_DIR}/secret.key" "${KEYS_DIR}/secret.key.migrated"
172207
fi
208+
update_pq_enabled
209+
173210
/opt/encrypted-dns/sbin/encrypted-dns \
174211
--config "$CONFIG_FILE" --dry-run |
175212
tee "${KEYS_DIR}/provider-info.txt"

0 commit comments

Comments
 (0)