| 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 |
TEST=$(basename "${0}") |
| 20 |
. luks-common-test-functions |
| 21 |
|
| 22 |
. clevis-luks-common-functions |
| 23 |
|
| 24 |
on_exit() { |
| 25 |
local d |
| 26 |
for d in "${TMP}" "${TMP2}"; do |
| 27 |
[ ! -d "${d}" ] && continue |
| 28 |
tang_stop "${d}" |
| 29 |
rm -rf "${d}" |
| 30 |
done |
| 31 |
} |
| 32 |
|
| 33 |
trap 'on_exit' EXIT |
| 34 |
trap 'on_exit' ERR |
| 35 |
|
| 36 |
TMP="$(mktemp -d)" |
| 37 |
|
| 38 |
tang_run "${TMP}" |
| 39 |
port=$(tang_get_port "${TMP}") |
| 40 |
|
| 41 |
url="http://localhost:${port}" |
| 42 |
|
| 43 |
cfg=$(printf '{"url":"%s"}' "${url}") |
| 44 |
|
| 45 |
# LUKS1 with sha512. |
| 46 |
DEV="${TMP}/luks1-device-sha512" |
| 47 |
new_device_hash "luks1" "${DEV}" "sha512" |
| 48 |
|
| 49 |
# Verify the device was created with sha512. |
| 50 |
hash_before=$(cryptsetup luksDump "${DEV}" \ |
| 51 |
| sed -rn 's|^Hash spec:\s+(\S+)$|\1|p') |
| 52 |
if [ "${hash_before}" != "sha512" ]; then |
| 53 |
error "${TEST}: Device should have been formatted with sha512, got ${hash_before}." |
| 54 |
fi |
| 55 |
|
| 56 |
if ! clevis luks bind -y -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then |
| 57 |
error "${TEST}: Bind should have succeeded." |
| 58 |
fi |
| 59 |
|
| 60 |
# Verify hash is still sha512 after binding. |
| 61 |
hash_after_bind=$(cryptsetup luksDump "${DEV}" \ |
| 62 |
| sed -rn 's|^Hash spec:\s+(\S+)$|\1|p') |
| 63 |
if [ "${hash_after_bind}" != "sha512" ]; then |
| 64 |
error "${TEST}: After binding, hash should be sha512, got ${hash_after_bind}." |
| 65 |
fi |
| 66 |
|
| 67 |
# Now let's have another tang instance running and change the config to use |
| 68 |
# the new one. |
| 69 |
TMP2="$(mktemp -d)" |
| 70 |
tang_run "${TMP2}" |
| 71 |
port2=$(tang_get_port "${TMP2}") |
| 72 |
new_url="http://localhost:${port2}" |
| 73 |
new_cfg=$(printf '{"url":"%s"}' "${new_url}") |
| 74 |
|
| 75 |
if ! clevis luks edit -d "${DEV}" -s 1 -c "${new_cfg}"; then |
| 76 |
error "${TEST}: edit should have succeeded." |
| 77 |
fi |
| 78 |
|
| 79 |
# Verify hash is still sha512 after edit. |
| 80 |
hash_after_edit=$(cryptsetup luksDump "${DEV}" \ |
| 81 |
| sed -rn 's|^Hash spec:\s+(\S+)$|\1|p') |
| 82 |
if [ "${hash_after_edit}" != "sha512" ]; then |
| 83 |
error "${TEST}: After edit, hash should be sha512, got ${hash_after_edit}." |
| 84 |
fi |
| 85 |
|
| 86 |
# Also check via clevis_luks_get_hash. |
| 87 |
hash_fn=$(clevis_luks_get_hash "${DEV}") |
| 88 |
if [ "${hash_fn}" != "sha512" ]; then |
| 89 |
error "${TEST}: clevis_luks_get_hash should return sha512, got ${hash_fn}." |
| 90 |
fi |
| 91 |
|
| 92 |
# Make sure we can still unlock the device. |
| 93 |
if ! clevis_luks_unlock_device "${DEV}" >/dev/null; then |
| 94 |
error "${TEST}: we should have been able to unlock the device" |
| 95 |
fi |