Debian Codegraph @

src/luks/tests/assume-yes-luks2

raw
1 #!/bin/bash -ex
2 # vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
3 #
4 # Copyright (c) 2020 Red Hat, Inc.
5 # Author: Sergio Correia <[email protected]>
6 #
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 3 of the License, or
10 # (at your option) any later version.
11 #
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.
16 #
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/>.
19
20 TEST=$(basename "${0}")
21 . luks-common-test-functions
22
23 . clevis-luks-common-functions
24
25 on_exit() {
26 [ ! -d "${TMP}" ] && return 0
27 tang_stop "${TMP}"
28 rm -rf "${TMP}"
29 }
30
31 trap 'on_exit' EXIT
32 trap 'on_exit' ERR
33
34 TMP="$(mktemp -d)"
35
36 tang_run "${TMP}"
37 port=$(tang_get_port "${TMP}")
38
39 url="http://localhost:${port}"
40 cfg=$(printf '{"url":"%s"}' "$url")
41
42 # LUKS2.
43 DEV="${TMP}/luks2-device"
44 new_device "luks2" "${DEV}"
45
46 # tang.
47 if ! clevis luks bind -y -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
48 error "${TEST}: Bind should have succeeded (tang - $DEV)."
49 fi
50
51 if ! clevis_luks_unlock_device "${DEV}"; then
52 error "${TEST}: we were unable to unlock ${DEV} (tang)."
53 fi
54
55 # sss.
56 new_device "luks2" "${DEV}"
57
58 sss=$(printf '{"t":2, "pins": {"tang": [{"url": "%s"}, {"url": "%s"}]}}' \
59 "${url}" "${url}")
60
61 if ! clevis luks bind -y -d "${DEV}" sss "${sss}" <<< "${DEFAULT_PASS}"; then
62 error "${TEST}: Bind should have succeeded (sss - $DEV)."
63 fi
64
65 if ! clevis_luks_unlock_device "${DEV}"; then
66 error "${TEST}: we were unable to unlock ${DEV} (sss)."
67 fi
68