forked from openssl/openssl
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsmoke_ech.sh
executable file
·202 lines (179 loc) · 4.51 KB
/
smoke_ech.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# Script to run smokeping like tests against CF, defo.ie and my-own.net
# using echcli.sh
# set -x
# structure is host:port mapped to pathname
declare -A targets=(
[my-own.net]="ech-check.php"
[my-own.net:8443]="ech-check.php"
[defo.ie]="ech-check.php"
[cover.defo.ie]=""
[draft-13.esni.defo.ie:8413]="stats"
[draft-13.esni.defo.ie:8414]="stats"
[draft-13.esni.defo.ie:9413]=""
[draft-13.esni.defo.ie:10413]=""
[draft-13.esni.defo.ie:11413]=""
[draft-13.esni.defo.ie:12413]=""
[draft-13.esni.defo.ie:12414]=""
[crypto.cloudflare.com]="cdn-cgi/trace"
[tls-ech.dev]=""
[epochbelt.com]=""
[myechtest.site]=""
[hidden.hoba.ie]=""
)
# place to stash outputs when things go wrong
: ${bad_dir:="$HOME/logs/smoke_ech_baddies"}
# time to wait for a remote access to work, 10 seconds
: ${tout:="10s"}
: ${OSSL:="$HOME/code/openssl"}
: ${DOMAIL:="no"}
DEFPORT=443
function whenisitagain()
{
/bin/date -u +%Y%m%d-%H%M%S
}
function fileage()
{
echo $(($(date +%s) - $(date +%s -r "$1")))
}
function hostport2host()
{
case $1 in
*:*) host=${1%:*} port=${1##*:};;
*) host=$1 port=$DEFPORT;;
esac
echo $host
}
function hostport2port()
{
case $1 in
*:*) host=${1%:*} port=${1##*:};;
*) host=$1 port=$DEFPORT;;
esac
echo $port
}
TMPD=`mktemp -d`
allgood="yes"
digcmd="dig https"
NOW=$(whenisitagain)
cd $TMPD
logfile=$TMPD/$NOW.log
echo "-----" >>$logfile
echo "Running $0 at $NOW" >>$logfile
echo "Running $0 at $NOW"
# check we have binaries
if [ ! -d $OSSL ]
then
allgood="no"
echo "Can't see $OSSL - exiting" >>$logfile
fi
echcli=$OSSL/esnistuff/echcli.sh
if [ ! -f $echcli ]
then
allgood="no"
echo "Can't see $OSSL/esnistuff/echcli.sh - exiting" >>$logfile
fi
if [ ! -f $OSSL/apps/openssl ]
then
allgood="no"
echo "Can't see $OSSL/apps/openssl - exiting" >>$logfile
fi
# check if dig knows https or not
digcmd="dig https"
dout=`dig +short https defo.ie`
if [[ $dout != "1 . ech="* ]]
then
digcmd="dig -t TYPE65"
fi
if [[ "$allgood" == "yes" ]]
then
for targ in "${!targets[@]}"
do
host=$(hostport2host $targ)
port=$(hostport2port $targ)
path=${targets[$targ]}
pathstr=""
if [[ "$path" != "" ]]
then
pathstr="-f $path"
fi
wkurl="https://$host:$port/.well-known/origin-svcb"
qname=$host
if [[ "$port" != "$DEFPORT" ]]
then
qname="_$port._https.$host"
fi
echo "Checking $host:$port/$path and $wkurl" >>$logfile
# get wkurl
if [[ "$host" != "crypto.cloudflare.com" && "$host" != "tls-ech.dev" ]]
then
timeout $tout curl -o $host.$port.json -s $wkurl
cres=$?
if [[ "$cres" == "124" ]]
then
allgood="no"
echo "Timeout getting $wkurl" >>$logfile
fi
else
echo "{ \"No .well-known for $host \"}" >$host.$port.json
fi
# grab DNS
$digcmd $qname >$host.$port.dig 2>&1
# try ECH
timeout $tout $echcli -H $host -p $port $pathstr -d >$host.$port.echcli.log
eres=$?
if [[ "$eres" == "124" ]]
then
allgood="no"
echo "Timeout running echcli.sh for $host:$port/$path" >>$logfile
fi
if [[ "$eres" != "0" ]]
then
allgood="no"
echo "Error ($eres) from echcli.sh for $host:$port/$path" >>$logfile
fi
done
fi
END=$(whenisitagain)
echo "Finished $0 at $END" >>$logfile
echo "-----" >>$logfile
cd -
if [[ "$allgood" == "yes" ]]
then
rm -rf $TMPD
echo "Finished $0 at $END"
echo "All good"
exit 0
fi
# stash bad stuff
if [ ! -d $bad_dir ]
then
mkdir -p $bad_dir
if [ ! -d $bad_dir ]
then
echo "Can't create $bad_dir - exiting"
exit 1
fi
fi
# stash logs of bad run and info about bad runs
mv $TMPD $bad_dir/$NOW
# send a mail to root (will be fwd'd) but just once every 24 hours
# 'cause we only really need "new" news
itsnews="yes"
age_of_news=0
if [ -f $bad_dir/bad_runs ]
then
age_of_news=$(fileage $bad_dir/bad_runs)
# only consider news "new" if we haven't mailed today
if ((age_of_news < 24*3600))
then
itsnews="no"
fi
fi
if [[ "$DOMAIL" == "yes" && "$itsnews" == "yes" ]]
then
echo "ECH badness at $NOW" | mail -s "ECH badness at $NOW" root
fi
# add to list of bad runs (updating file age)
echo "ECH badness at $NOW" >>$bad_dir/bad_runs
exit 2