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