1#!/bin/sh
2
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# SPDX-License-Identifier: MPL-2.0
6#
7# This Source Code Form is subject to the terms of the Mozilla Public
8# License, v. 2.0.  If a copy of the MPL was not distributed with this
9# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10#
11# See the COPYRIGHT file distributed with this work for additional
12# information regarding copyright ownership.
13
14SYSTEMTESTTOP=..
15. $SYSTEMTESTTOP/conf.sh
16
17n=0
18status=0
19
20DIGOPTS="-p ${PORT}"
21RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
22
23getcookie() {
24	awk '$2 == "COOKIE:" {
25		print $3;
26	}' < $1
27}
28
29echo_i "checking that dig handles padding ($n)"
30ret=0
31n=`expr $n + 1`
32$DIG $DIGOPTS +qr +padding=128 foo.example @10.53.0.2 > dig.out.test$n
33grep "; PAD" dig.out.test$n > /dev/null || ret=1
34grep "; QUERY SIZE: 128" dig.out.test$n > /dev/null || ret=1
35if [ $ret != 0 ]; then echo_i "failed"; fi
36status=`expr $status + $ret`
37
38echo_i "checking that dig added padding ($n)"
39ret=0
40n=`expr $n + 1`
41nextpart ns2/named.stats > /dev/null
42$RNDCCMD 10.53.0.2 stats
43wait_for_log_peek 5 "--- Statistics Dump ---" ns2/named.stats || ret=1
44nextpart ns2/named.stats | grep "EDNS padding option received" > /dev/null || ret=1
45
46if [ $ret != 0 ]; then echo_i "failed"; fi
47status=`expr $status + $ret`
48
49echo_i "checking that padding is added for TCP responses ($n)"
50ret=0
51n=`expr $n + 1`
52$DIG $DIGOPTS +vc +padding=128 foo.example @10.53.0.2 > dig.out.test$n
53grep "; PAD" dig.out.test$n > /dev/null || ret=1
54grep "rcvd: 128" dig.out.test$n > /dev/null || ret=1
55if [ $ret != 0 ]; then echo_i "failed"; fi
56status=`expr $status + $ret`
57
58echo_i "checking that padding is added to valid cookie responses ($n)"
59ret=0
60n=`expr $n + 1`
61$DIG $DIGOPTS +cookie foo.example @10.53.0.2 > dig.out.testc
62cookie=`getcookie dig.out.testc`
63$DIG $DIGOPTS +cookie=$cookie +padding=128 foo.example @10.53.0.2 > dig.out.test$n
64grep "; PAD" dig.out.test$n > /dev/null || ret=1
65grep "rcvd: 128" dig.out.test$n > /dev/null || ret=1
66if [ $ret != 0 ]; then echo_i "failed"; fi
67status=`expr $status + $ret`
68
69echo_i "checking that padding must be requested (TCP) ($n)"
70ret=0
71n=`expr $n + 1`
72$DIG $DIGOPTS +vc foo.example @10.53.0.2 > dig.out.test$n
73grep "; PAD" dig.out.test$n > /dev/null && ret=1
74if [ $ret != 0 ]; then echo_i "failed"; fi
75status=`expr $status + $ret`
76
77echo_i "checking that padding must be requested (valid cookie) ($n)"
78ret=0
79n=`expr $n + 1`
80$DIG $DIGOPTS +cookie=$cookie foo.example @10.53.0.2 > dig.out.test$n
81grep "; PAD" dig.out.test$n > /dev/null && ret=1
82if [ $ret != 0 ]; then echo_i "failed"; fi
83status=`expr $status + $ret`
84
85echo_i "checking that padding can be filtered out ($n)"
86ret=0
87n=`expr $n + 1`
88$DIG $DIGOPTS +vc +padding=128 -b 10.53.0.8 foo.example @10.53.0.2 > dig.out.test$n
89grep "; PAD" dig.out.test$n > /dev/null && ret=1
90if [ $ret != 0 ]; then echo_i "failed"; fi
91status=`expr $status + $ret`
92
93echo_i "checking that a TCP and padding server config enables padding ($n)"
94ret=0
95n=`expr $n + 1`
96nextpart ns2/named.stats > /dev/null
97$RNDCCMD 10.53.0.2 stats
98wait_for_log_peek 5 "--- Statistics Dump ---" ns2/named.stats || ret=1
99opad=`nextpart ns2/named.stats | awk '/EDNS padding option received/ { print $1}'`
100$DIG $DIGOPTS foo.example @10.53.0.3 > dig.out.test$n
101$RNDCCMD 10.53.0.2 stats
102wait_for_log_peek 5 "--- Statistics Dump ---" ns2/named.stats || ret=1
103npad=`nextpart ns2/named.stats | awk '/EDNS padding option received/ { print $1}'`
104if [ "$opad" -eq "$npad" ]; then echo_i "error: opad ($opad) == npad ($npad)"; ret=1; fi
105if [ $ret != 0 ]; then echo_i "failed"; fi
106status=`expr $status + $ret`
107
108echo_i "checking that a padding server config should enforce TCP ($n)"
109ret=0
110n=`expr $n + 1`
111nextpart ns2/named.stats > /dev/null
112$RNDCCMD 10.53.0.2 stats
113wait_for_log_peek 5 "--- Statistics Dump ---" ns2/named.stats || ret=1
114opad=`nextpart ns2/named.stats | awk '/EDNS padding option received/ { print $1}'`
115$DIG $DIGOPTS foo.example @10.53.0.4 > dig.out.test$n
116$RNDCCMD 10.53.0.2 stats
117wait_for_log_peek 5 "--- Statistics Dump ---" ns2/named.stats || ret=1
118npad=`nextpart ns2/named.stats | awk '/EDNS padding option received/ { print $1}'`
119if [ "$opad" -ne "$npad" ]; then echo_i "error: opad ($opad) != npad ($npad)"; ret=1; fi
120if [ $ret != 0 ]; then echo_i "failed"; fi
121status=`expr $status + $ret`
122
123echo_i "checking that zero-length padding option has no effect ($n)"
124ret=0
125n=`expr $n + 1`
126$DIG $DIGOPTS +qr +ednsopt=12 foo.example @10.53.0.2 > dig.out.test$n.1
127grep "; PAD" dig.out.test$n.1 > /dev/null || ret=1
128$DIG $DIGOPTS +qr +ednsopt=12:00 foo.example @10.53.0.2 > dig.out.test$n.2
129grep "; PAD" dig.out.test$n.2 > /dev/null || ret=1
130if [ $ret != 0 ]; then echo_i "failed"; fi
131status=`expr $status + $ret`
132
133echo_i "exit status: $status"
134[ $status -eq 0 ] || exit 1
135