Debian Codegraph @

src/luks/tests/bind-luks1-avoid-luksmeta-corruption

raw
1 #!/bin/bash -ex
2 #
3 # Copyright (c) 2021 Red Hat, Inc.
4 # Author: Sergio Arroutbi Braojos <[email protected]>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 TEST=$(basename "${0}")
21 . luks-common-test-functions
22
23 on_exit() {
24 [ ! -d "${TMP}" ] && return 0
25 tang_stop "${TMP}"
26 rm -rf "${TMP}"
27 }
28
29 trap 'on_exit' EXIT
30
31 TMP="$(mktemp -d)"
32
33 ADV_AMOUNT=50
34
35 # Create LUKS1 device
36 DEV="${TMP}/luks1-device"
37 new_device "luks1" "${DEV}"
38
39 # TANG server specifics
40 tang_run "${TMP}"
41 port=$(tang_get_port "${TMP}")
42
43 url="http://localhost:${port}"
44
45 # Initial binding to ensure luksmeta gets corrupted
46 for ADV_NU in $(seq 0 ${ADV_AMOUNT}); do
47 "${TANGD_KEYGEN}" "${TMP}/db"
48 done
49 tang_new_keys "${TMP}"
50
51 CFG=$(printf '{"url":"%s"}' "${url}")
52
53 # At this point, luks bind must return an error. If not, test fails
54 if clevis luks bind -y -d "${DEV}" tang "${CFG}" <<< "${DEFAULT_PASS}"; then
55 error "${TEST}: Binding is expected to fail when given a too long adv"
56 fi