Debian Codegraph @

src/luks/tests/bind-hash-luks1

raw
1 #!/bin/bash -ex
2 #
3 # Copyright (c) 2026 Red Hat, Inc.
4 # Author: Sergio Arroutbi <[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 . clevis-luks-common-functions
24
25 on_exit() {
26 [ -d "${TMP}" ] && rm -rf "${TMP}"
27 }
28
29 trap 'on_exit' EXIT
30 trap 'exit' ERR
31
32 TMP="$(mktemp -d)"
33
34 ADV="${TMP}/adv.jws"
35 tang_create_adv "${TMP}" "${ADV}"
36 CFG="$(printf '{"url":"foobar","adv":"%s"}' "$ADV")"
37
38 # LUKS1 with sha512.
39 DEV="${TMP}/luks1-device-sha512"
40 new_device_hash "luks1" "${DEV}" "sha512"
41
42 # Verify the device was created with sha512.
43 hash_before=$(cryptsetup luksDump "${DEV}" \
44 | sed -rn 's|^Hash spec:\s+(\S+)$|\1|p')
45 if [ "${hash_before}" != "sha512" ]; then
46 error "${TEST}: Device should have been formatted with sha512, got ${hash_before}."
47 fi
48
49 if ! clevis luks bind -f -d "${DEV}" tang "${CFG}" <<< "${DEFAULT_PASS}"; then
50 error "${TEST}: Binding is expected to succeed."
51 fi
52
53 # Verify the clevis slot also uses sha512.
54 hash_after=$(cryptsetup luksDump "${DEV}" \
55 | sed -rn 's|^Hash spec:\s+(\S+)$|\1|p')
56 if [ "${hash_after}" != "sha512" ]; then
57 error "${TEST}: After binding, hash should be sha512, got ${hash_after}."
58 fi
59
60 # Also check individual key slot hash via clevis_luks_get_hash.
61 hash_fn=$(clevis_luks_get_hash "${DEV}")
62 if [ "${hash_fn}" != "sha512" ]; then
63 error "${TEST}: clevis_luks_get_hash should return sha512, got ${hash_fn}."
64 fi