tests/acceptance: Ignore binary data sent on serial console
[qemu/ar7.git] / tests / qemu-iotests / common.tls
blob6ba28a78d3c801a6978ac39d318e08a552b67997
1 #!/usr/bin/env bash
3 # Helpers for TLS related config
5 # Copyright (C) 2018 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 tls_dir="${TEST_DIR}/tls"
23 tls_x509_cleanup()
25 rm -f "${tls_dir}"/*.pem
26 rm -f "${tls_dir}"/*/*.pem
27 rmdir "${tls_dir}"/*
28 rmdir "${tls_dir}"
32 tls_certtool()
34 certtool "$@" 1>"${tls_dir}"/certtool.log 2>&1
35 if test "$?" = 0; then
36 head -1 "${tls_dir}"/certtool.log
37 else
38 cat "${tls_dir}"/certtool.log
40 rm -f "${tls_dir}"/certtool.log
43 tls_x509_init()
45 (certtool --help) >/dev/null 2>&1 || \
46 _notrun "certtool utility not found, skipping test"
48 mkdir -p "${tls_dir}"
50 # use a fixed key so we don't waste system entropy on
51 # each test run
52 cat > "${tls_dir}/key.pem" <<EOF
53 -----BEGIN RSA PRIVATE KEY-----
54 MIIG5AIBAAKCAYEAyjWyLSNm5PZvYUKUcDWGqbLX10b2ood+YaFjWSnJrqx/q3qh
55 rVGBJglD25AJENJsmZF3zPP1oMhfIxsXu63Hdkb6Rdlc2RUoUP34x9VC1izH25mR
56 6c8DPDp1d6IraZ/llDMI1HsBFz0qGWtvOHgm815XG4PAr/N8rDsuqfv/cJ01KlnO
57 0OdO5QRXCJf9g/dYd41MPu7wOXk9FqjQlmRoP59HgtJ+zUpE4z+Keruw9cMT9VJj
58 0oT+pQ9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qV9SSjUg4iBXwVSoag1iDJ1K8Qg/L7Semgg==
91 -----END RSA PRIVATE KEY-----
92 EOF
96 tls_x509_create_root_ca()
98 name=${1:-ca-cert}
100 cat > "${tls_dir}/ca.info" <<EOF
101 cn = Cthulhu Dark Lord Enterprises $name
103 cert_signing_key
106 tls_certtool \
107 --generate-self-signed \
108 --load-privkey "${tls_dir}/key.pem" \
109 --template "${tls_dir}/ca.info" \
110 --outfile "${tls_dir}/$name-cert.pem"
112 rm -f "${tls_dir}/ca.info"
116 tls_x509_create_server()
118 caname=$1
119 name=$2
121 mkdir -p "${tls_dir}/$name"
122 cat > "${tls_dir}/cert.info" <<EOF
123 organization = Cthulhu Dark Lord Enterprises $name
124 cn = localhost
125 dns_name = localhost
126 dns_name = localhost.localdomain
127 ip_address = 127.0.0.1
128 ip_address = ::1
129 tls_www_server
130 encryption_key
131 signing_key
134 tls_certtool \
135 --generate-certificate \
136 --load-ca-privkey "${tls_dir}/key.pem" \
137 --load-ca-certificate "${tls_dir}/$caname-cert.pem" \
138 --load-privkey "${tls_dir}/key.pem" \
139 --template "${tls_dir}/cert.info" \
140 --outfile "${tls_dir}/$name/server-cert.pem"
142 ln -s "${tls_dir}/$caname-cert.pem" "${tls_dir}/$name/ca-cert.pem"
143 ln -s "${tls_dir}/key.pem" "${tls_dir}/$name/server-key.pem"
145 rm -f "${tls_dir}/cert.info"
149 tls_x509_create_client()
151 caname=$1
152 name=$2
154 mkdir -p "${tls_dir}/$name"
155 cat > "${tls_dir}/cert.info" <<EOF
156 country = South Pacific
157 locality = R'lyeh
158 organization = Cthulhu Dark Lord Enterprises $name
159 cn = localhost
160 tls_www_client
161 encryption_key
162 signing_key
165 tls_certtool \
166 --generate-certificate \
167 --load-ca-privkey "${tls_dir}/key.pem" \
168 --load-ca-certificate "${tls_dir}/$caname-cert.pem" \
169 --load-privkey "${tls_dir}/key.pem" \
170 --template "${tls_dir}/cert.info" \
171 --outfile "${tls_dir}/$name/client-cert.pem"
173 ln -s "${tls_dir}/$caname-cert.pem" "${tls_dir}/$name/ca-cert.pem"
174 ln -s "${tls_dir}/key.pem" "${tls_dir}/$name/client-key.pem"
176 rm -f "${tls_dir}/cert.info"