-
Notifications
You must be signed in to change notification settings - Fork 1
/
TLSARR.sh
executable file
·176 lines (124 loc) · 3.96 KB
/
TLSARR.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
#!/bin/bash
alias echo="echo -e"
#!/bin/bash
export flgport=0
export flgprotocol=0
export flgdomain=0
export flgusage=0
export flgselector=0
export flgmatching=0
export flgcert=0
export port=""
export protocol=""
export domain=""
export usage=""
export selector=""
export matching=""
export cert=""
for arg in "$@"
do
if [ "$flgport" == 1 ]; then
port=$arg
flgport=0
fi
if [ "$flgdomain" == 1 ]; then
domain=$arg
flgdomain=0
fi
if [ "$flgusage" == 1 ]; then
usage=$arg
flgusage=0
fi
if [ "$flgselector" == 1 ]; then
selector=$arg
flgselector=0
fi
if [ "$flgmatching" == 1 ]; then
matching=$arg
flgmatching=0
fi
if [ "$flgcert" == 1 ]; then
cert=$arg
flgcert=0
fi
if [ "$arg" == "--device" ] || [ "$arg" == "-device" ]; then
flgport=1
fi
if [ "$arg" == "--domain" ] || [ "$arg" == "-domain" ]; then
flgdomain=1
fi
if [ "$arg" == "--usage" ] || [ "$arg" == "-usage" ]; then
flgusage=1
fi
if [ "$arg" == "--selector" ] || [ "$arg" == "-selector" ]; then
flgselector=1
fi
if [ "$arg" == "--matching" ] || [ "$arg" == "-matching" ]; then
flgmatching=1
fi
if [ "$arg" == "--cert" ] || [ "$arg" == "-cert" ]; then
flgcert=1
fi
done
export label="_device"
export usagecode=0
export selectorcode=0
export matchingTypecode=0
if [ "$usage" == "PKIX-TA" ] ; then
usagecode=0
elif [ "$usage" == "PKIX-EE" ]; then
usagecode=1
elif [ "$usage" == "DANE-TA" ]; then
usagecode=2
else [ "$usage" == "DANE-EE" ];
usagecode=3
fi
if [ "$selector" == "full-cert" ] || [ "$selector" == "cert" ] ; then
selectorcode=0
if [ "$matching" == "sha256" ] ; then
matchingTypecode=1
passtest=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in $cert)
arrdgst509=(${passtest//=/ })
dgst=${arrdgst509[2]//:}
printf $port.$label.$domain.${empty_space}$' IN TLSA (\n'$usagecode$' '$selectorcode$' '$matchingTypecode$' '$dgst$' )\n'
fi
if [ "$matching" == "sha512" ] ; then
matchingTypecode=2
passtest=$(openssl x509 -noout -fingerprint -sha512 -inform pem -in $cert)
arrdgst509=(${passtest//=/ })
dgst=${arrdgst509[2]//:}
printf $port.$label.$domain.${empty_space}$' IN TLSA (\n'$usagecode$' '$selectorcode$' '$matchingTypecode$' '$dgst$' )\n'
fi
if [ "$matching" == "no-hash" ] ; then
matchingTypecode=0
passtest=$(openssl x509 -in $cert | openssl enc -base64 -d > temp.der)
der=$(xxd -p temp.der)
printf -v der '%s' $der
rm temp.der
printf $port.$label.$domain.${empty_space}$' IN TLSA (\n'$usagecode$' '$selectorcode$' '$matchingTypecode$' '$der$' )\n'
fi
fi
if [ "$selector" == "subject-public-key" ] || [ "$selector" == "spk" ] ; then
selectorcode=1
passtest=$(openssl x509 -in test/iDevID/certs/DevID.cert.pem -pubkey -noout | openssl enc -base64 -d > temppubkey.der)
if [ "$matching" == "no-hash" ] ; then
matchingTypecode=0
der=$(xxd -p temppubkey.der)
dernws=${der// }
printf -v der '%s' $der
printf $port.$label.$domain.${empty_space}$' IN TLSA (\n'$usagecode$' '$selectorcode$' '$matchingTypecode$' '$der$' )\n'
fi
if [ "$matching" == "sha256" ] ; then
matchingTypecode=1
passtest=$(openssl dgst -sha256 temppubkey.der)
arrdgst509=(${passtest//=/ })
printf $port.$label.$domain.${empty_space}$' IN TLSA (\n'$usagecode$' '$selectorcode$' '$matchingTypecode$' '${arrdgst509[1]}$' )\n'
fi
if [ "$matching" == "sha512" ] ; then
matchingTypecode=2
passtest=$(openssl dgst -sha512 temppubkey.der)
arrdgst509=(${passtest//=/ })
printf $port.$label.$domain.${empty_space}$' IN TLSA (\n'$usagecode$' '$selectorcode$' '$matchingTypecode$' '${arrdgst509[1]}$' )\n'
fi
rm temppubkey.der
fi