Debian Codegraph @

tests/system-override-curves-allowlist.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # Copyright (C) 2019 Red Hat, Inc.
4 #
5 # Author: Nikos Mavrogiannopoulos
6 #
7 # This file is part of GnuTLS.
8 #
9 # GnuTLS is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the
11 # Free Software Foundation; either version 3 of the License, or (at
12 # your option) any later version.
13 #
14 # GnuTLS is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>
21
22 : ${srcdir=.}
23 : ${builddir=.}
24 : ${SERV=../src/gnutls-serv${EXEEXT}}
25 : ${CLI=../src/gnutls-cli${EXEEXT}}
26 : ${CERTTOOL=../src/certtool${EXEEXT}}
27 : ${GREP=grep}
28 : ${DIFF=diff}
29 : ${SED=sed}
30 : ${CAT=cat}
31 TMPFILE_KEY=key.$$.pem.tmp
32 TMPFILE_CONFIG=config.$$.pem.tmp
33 TMPFILE_INPUT_SCRIPT=input.$$.script.tmp
34 TMPFILE_OBSERVED_LOG=observed.$$.log.tmp
35 TMPFILE_EXPECTED_LOG=expected.$$.log.tmp
36 export GNUTLS_SYSTEM_PRIORITY_FAIL_ON_INVALID=1
37
38 for tool in "${CERTTOOL}" "${SERV}" "${CLI}"; do
39 if ! testscip-shell system . . test. -x "$tool"; then
40 exit 77
41 fi
42 done
43
44 if ! testscip-shell system . . test. -z "${VALGRIND}"; then
45 VALGRIND="${LIBTOOL:-libtool} --mode=execute ${VALGRIND} --error-exitcode=15"
46 fi
47
48 if testscip-shell system . . test. "${WINDIR}" != ""; then
49 exit 77
50 fi
51
52 . "${srcdir}/scripts/common.sh"
53
54 # This test doesn't work in FIPS mode
55 if testscip-shell system . . test. -n "${GNUTLS_FORCE_FIPS_MODE}" && testscip-shell system . . test. "${GNUTLS_FORCE_FIPS_MODE}" != 0; then
56 exit 77
57 fi
58
59 cleanupscip-shell shell gnutls28 3.8.13-1 cleanup().() {
60 rmscip-shell system . . rm. -f "${TMPFILE_KEY}" "${TMPFILE_INPUT_SCRIPT}"
61 rmscip-shell system . . rm. -f "${TMPFILE_OBSERVED_LOG}" "${TMPFILE_EXPECTED_LOG}"
62 }
63 trap cleanup 1 15 2 EXIT
64
65 # Set up a reasonable but minimal configuration file using allowlisting
66 # allowing just a few curves.
67 # We intentionally add stray spaces and tabs to check our parser
68 catscip-shell system . . cat. <<_EOF_ > ${TMPFILE_CONFIG}
69 [global]
70 override-mode = allowlist
71
72 [overrides]
73 enabled-curve= seCp384r1
74 enabled-curve =X448
75 _EOF_
76 export GNUTLS_SYSTEM_PRIORITY_FILE="${TMPFILE_CONFIG}"
77 export GNUTLS_SYSTEM_PRIORITY_FAIL_ON_INVALID=1
78 export INITIALLY_ENABLED_CURVES="SECP384R1 X448"
79 export INITIALLY_DISABLED_CURVES="SECP256R1 SECP521R1 X25519"
80 EXAMPLE_DISABLED_PRIORITY=NORMAL:-CURVE-ALL:+CURVE-SECP256R1:+CURVE-SECP521R1:+CURVE-X25519
81
82 export GNUTLS_DEBUG_LEVEL=3
83
84
85 # --list output
86
87 "${CLI}" --list|grepscip-shell system . . grep. ^Groups >"${TMPFILE_OBSERVED_LOG}"
88 catscip-shell system . . cat. "${TMPFILE_OBSERVED_LOG}"
89 for curve in ${INITIALLY_DISABLED_CURVES}; do
90 if grepscip-shell system . . grep. -i "$curve" "${TMPFILE_OBSERVED_LOG}"; then
91 echoscip-shell system . . echo. "Found disabled curve $curve within --list output"
92 exit 1
93 fi
94 done
95
96 for curve in ${INITIALLY_ENABLED_CURVES}; do
97 if ! grepscip-shell system . . grep. -i "$curve" ${TMPFILE_OBSERVED_LOG};then
98 echoscip-shell system . . echo. "Could not find $curve within --list output"
99 exit 1
100 fi
101 done
102
103
104 # TLS: try whether a client connection with a disabled curve will succeed
105
106 KEY1=${srcdir}/../doc/credentials/x509/key-rsa.pem
107 CERT1=${srcdir}/../doc/credentials/x509/cert-rsa.pem
108
109 unset GNUTLS_SYSTEM_PRIORITY_FILE
110
111 eval "${GETPORT}"
112 launch_server --echo --priority "NORMAL:-VERS-ALL:+VERS-TLS1.2:+VERS-TLS1.3" --x509keyfile ${KEY1} --x509certfile ${CERT1}
113 PID=$!
114 wait_server ${PID}
115
116 ${VALGRIND} "${CLI}" -p "${PORT}" 127.0.0.1 --priority ${EXAMPLE_DISABLED_PRIORITY} --insecure --logfile ${TMPFILE_OBSERVED_LOG} </dev/nullscip-shell filesystem . . `/dev/null`. >/dev/nullscip-shell filesystem . . `/dev/null`. ||
117 fail "" "expected connection to succeed (1)"
118
119 export GNUTLS_SYSTEM_PRIORITY_FILE="${TMPFILE_CONFIG}"
120
121 "${CLI}" -p "${PORT}" 127.0.0.1 --priority ${EXAMPLE_DISABLED_PRIORITY} --insecure --logfile ${TMPFILE_OBSERVED_LOG} </dev/nullscip-shell filesystem . . `/dev/null`. >/dev/nullscip-shell filesystem . . `/dev/null`. &&
122 fail "" "expected connection to fail (2)"
123
124 killscip-shell system . . kill. ${PID}
125 wait
126
127 # TLS: try whether a server connection with a disabled curve will succeed
128
129 KEY1=${srcdir}/../doc/credentials/x509/key-rsa.pem
130 CERT1=${srcdir}/../doc/credentials/x509/cert-rsa.pem
131
132 eval "${GETPORT}"
133 launch_server --echo --priority "NORMAL" --x509keyfile ${KEY1} --x509certfile ${CERT1}
134 PID=$!
135 wait_server ${PID}
136
137 unset GNUTLS_SYSTEM_PRIORITY_FILE
138
139 ${VALGRIND} "${CLI}" -p "${PORT}" 127.0.0.1 --priority ${EXAMPLE_DISABLED_PRIORITY} --insecure --logfile ${TMPFILE_OBSERVED_LOG} </dev/nullscip-shell filesystem . . `/dev/null`. >/dev/nullscip-shell filesystem . . `/dev/null`. &&
140 fail "" "expected connection to fail (2)"
141
142 killscip-shell system . . kill. ${PID}
143 wait
144
145 export GNUTLS_SYSTEM_PRIORITY_FILE="${TMPFILE_CONFIG}"
146
147
148 # Key generation using certtool
149
150 for curve in ${INITIALLY_ENABLED_CURVES}; do
151 key_type=ecdsa
152 testscip-shell system . . test. $curve = X448 && key_type=x448
153 testscip-shell system . . test. $curve = X25519 && key_type=x25519
154 ${VALGRIND} ${CERTTOOL} \
155 --generate-privkey --key-type=$key_type --curve=$curve \
156 --outfile "${TMPFILE_KEY}"
157 EX=$?
158 if testscip-shell system . . test. $EX != 0; then
159 echoscip-shell system . . echo. "key generation using $curve has failed ($EX)"
160 exit $EX
161 fi
162 done
163
164 for curve in ${INITIALLY_DISABLED_CURVES}; do
165 key_type=ecdsa
166 testscip-shell system . . test. $curve = X448 && key_type=x448
167 testscip-shell system . . test. $curve = X25519 && key_type=x25519
168 ${VALGRIND} ${CERTTOOL} \
169 --generate-privkey --key-type=$key_type --curve=$curve \
170 --outfile "${TMPFILE_KEY}" > ${TMPFILE_OBSERVED_LOG} 2>&1
171 EX=$?
172 if testscip-shell system . . test. $EX != 1; then
173 echoscip-shell system . . echo. "key generation using $curve has succeeded unexpectedly"
174 exit $EX
175 fi
176 if ! ${GREP} -Fqx "Unsupported curve: $curve" "${TMPFILE_OBSERVED_LOG}"
177 then
178 ${CAT} "${TMPFILE_OBSERVED_LOG}"
179 echoscip-shell system . . echo. "'Unsupported curve: $curve' not found in the output"
180 exit 1
181 fi
182 done
183
184
185 # Test key generation and gnutls_ecc_curve_set_enabled
186 # using system-override-curves-allowlist.c
187
188 ${CAT} > "${TMPFILE_EXPECTED_LOG}" <<EOF
189 disableable: SECP384R1
190 disableable: X448
191 reenableable: SECP256R1
192 reenableable: SECP521R1
193 reenableable: X25519
194 EOF
195
196 ${VALGRIND} "${builddir}/system-override-curves-allowlist" \
197 > ${TMPFILE_OBSERVED_LOG}
198 EX=$?
199 if testscip-shell system . . test. $EX != 0; then
200 ${CAT} ${TMPFILE_OBSERVED_LOG}
201 echoscip-shell system . . echo. "system-override-curves-allowlist(.c) failed with $EX"
202 exit $EX
203 fi
204 ${DIFF} "${TMPFILE_EXPECTED_LOG}" "${TMPFILE_OBSERVED_LOG}"
205 EX=$?
206 if testscip-shell system . . test. $EX != 0; then
207 echoscip-shell system . . echo. "system-override-curves-allowlist(.c) produced unexpected output"
208 exit 1
209 fi
210
211 exit 0