| 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 |
adv="${TMP}/adv" |
| 41 |
tang_get_adv "${port}" "${adv}" |
| 42 |
|
| 43 |
cfg=$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv") |
| 44 |
|
| 45 |
# LUKS1. |
| 46 |
DEV="${TMP}/luks1-device" |
| 47 |
new_device "luks1" "${DEV}" |
| 48 |
|
| 49 |
if ! clevis luks bind -f -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then |
| 50 |
error "${TEST}: Bind should have succeeded." |
| 51 |
fi |
| 52 |
|
| 53 |
if ! clevis_luks_unlock_device "${DEV}"; then |
| 54 |
error "${TEST}: we were unable to unlock ${DEV}." |
| 55 |
fi |
| 56 |
|
| 57 |
# Let's rotate the tang keys and add another binding with the new key. |
| 58 |
tang_new_keys "${TMP}" "rotate-keys" |
| 59 |
|
| 60 |
# Unlock should still work now. |
| 61 |
if ! clevis_luks_unlock_device "${DEV}"; then |
| 62 |
error "${TEST}: we should still be able to unlock ${DEV}" |
| 63 |
fi |
| 64 |
|
| 65 |
# Now let's remove the rotated keys. |
| 66 |
tang_remove_rotated_keys "${TMP}" |
| 67 |
|
| 68 |
# Unlock should not work anymore. |
| 69 |
if clevis_luks_unlock_dev "${DEV}"; then |
| 70 |
error "${TEST}: we should not be able to unlock ${DEV}" |
| 71 |
fi |
| 72 |
|
| 73 |
# Now let's add another binding with the new keys. |
| 74 |
tang_get_adv "${port}" "${adv}" # Updating the advertisement. |
| 75 |
if ! clevis luks bind -f -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then |
| 76 |
error "${TEST}: Bind should have succeeded." |
| 77 |
fi |
| 78 |
|
| 79 |
# Unlock should work again, using the new keys. |
| 80 |
if ! clevis_luks_unlock_device "${DEV}"; then |
| 81 |
error "${TEST}: we should be able to unlock ${DEV} with the new keys" |
| 82 |
fi |