Debian Codegraph @

src/luks/tests/assume-yes

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 test_tang() {
43 local url="${1}"
44 local cfg data pt
45 cfg=$(printf '{"url":"%s"}' "$url")
46
47 for data in "foo" "bar" "foo bar" "some-password-here"; do
48 if ! pt="$(echo "${data}" | clevis encrypt tang "${cfg}" -y \
49 | clevis decrypt)"; then
50 error "${TEST}: tang - encrypt should succeed."
51 fi
52 if [ "${pt}" != "${data}" ]; then
53 error "${TEST}: tang - pt(${pt}) != data("${data}")."
54 fi
55 done
56 }
57
58 test_sss() {
59 local url="${1}"
60 local sss1 sss2 data pt
61 sss1=$(printf '{"t":1, "pins": {"tang": [{"url": "%s"}]}}' "${url}")
62 sss2=$(printf '{"t":2, "pins": {"tang": [{"url": "%s"}, {"url": "%s"}]}}' \
63 "${url}" "${url}")
64
65 for data in "foo" "bar" "foo bar" "some-password-here"; do
66 if ! pt="$(echo "${data}" | clevis encrypt sss "${sss1}" -y \
67 | clevis decrypt)"; then
68 error "${TEST}: sss1 - encrypt should succeed."
69 fi
70 if [ "${pt}" != "${data}" ]; then
71 error "${TEST}: sss1 - pt(${pt}) != data("${data}")."
72 fi
73
74 if ! pt="$(echo "${data}" | clevis encrypt sss "${sss2}" -y \
75 | clevis decrypt)"; then
76 error "${TEST}: sss2 - encrypt should succeed."
77 fi
78 if [ "${pt}" != "${data}" ]; then
79 error "${TEST}: sss2 - pt(${pt}) != data("${data}")."
80 fi
81 done
82 }
83
84 test_tang "${url}"
85 test_sss "${url}"
86
87 # LUKS1.
88 DEV="${TMP}/luks1-device"
89 new_device "luks1" "${DEV}"
90
91 # tang.
92 if ! clevis luks bind -y -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
93 error "${TEST}: Bind should have succeeded (tang - $DEV)."
94 fi
95
96 if ! clevis_luks_unlock_device "${DEV}"; then
97 error "${TEST}: we were unable to unlock ${DEV} (tang)."
98 fi
99
100 # sss.
101 new_device "luks1" "${DEV}"
102
103 sss=$(printf '{"t":2, "pins": {"tang": [{"url": "%s"}, {"url": "%s"}]}}' \
104 "${url}" "${url}")
105
106 if ! clevis luks bind -y -d "${DEV}" sss "${sss}" <<< "${DEFAULT_PASS}"; then
107 error "${TEST}: Bind should have succeeded (sss - $DEV)."
108 fi
109
110 if ! clevis_luks_unlock_device "${DEV}"; then
111 error "${TEST}: we were unable to unlock ${DEV} (sss)."
112 fi