Skip to content

Commit d969ee4

Browse files
Fix support for LUKS device with an empty password
Signed-off-by: Sergio Correia <[email protected]>
1 parent ea01ad0 commit d969ee4

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

src/luks/clevis-luks-common-functions.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,18 @@ clevis_luks_check_valid_key_or_keyfile() {
334334
local EXISTING_TOKEN_ID="${5:-}"
335335

336336
[ -z "${DEV}" ] && return 1
337-
[ -z "${EXISTING_TOKEN_ID}" ] && [ -z "${KEYFILE}" ] && [ -z "${KEY}" ] && return 1
338337

339338
local extra_args
340339
extra_args="$([ -n "${SLT}" ] && printf -- '--key-slot %s' "${SLT}")"
340+
341+
# We have an empty key here.
342+
if [ -z "${EXISTING_TOKEN_ID}" ] && [ -z "${KEYFILE}" ] \
343+
&& [ -z "${KEY}" ]; then
344+
echo | cryptsetup open --force-password --test-passphrase "${DEV}" \
345+
${extra_args}
346+
return
347+
fi
348+
341349
if [ -n "${KEYFILE}" ]; then
342350
cryptsetup open --test-passphrase "${DEV}" --key-file "${KEYFILE}" \
343351
${extra_args}
@@ -798,7 +806,6 @@ clevis_luks_add_key() {
798806

799807
[ -z "${DEV}" ] && return 1
800808
[ -z "${NEWKEY}" ] && return 1
801-
[ -z "${EXISTING_TOKEN_ID}" ] && [ -z "${KEY}" ] && [ -z "${KEYFILE}" ] && return 1
802809

803810
local extra_args='' input
804811
input="$(printf '%s\n%s' "${KEY}" "${NEWKEY}")"

src/luks/tests/bind-luks1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,30 @@ UUID="cb6e8904-81ff-40da-a84a-07ab9ab5715e"
4040
new_device "luks1" "${DEV}"
4141

4242
if ! clevis luks bind -f -d "${DEV}" tang "${CFG}" <<< "${DEFAULT_PASS}"; then
43-
error "${TEST}: Binding is expected to succeed when given a correct (${DEFAULT_PASS}) password." >&2
43+
error "${TEST}: Binding is expected to succeed when given a correct (${DEFAULT_PASS}) password."
4444
fi
4545

4646
SLT=1
4747
if ! read -r _ state uuid < <(luksmeta show -d "${DEV}" | grep "^${SLT} *"); then
48-
error "${TEST}: Error reading LUKSmeta info for slot ${SLT} of ${DEV}." >&2
48+
error "${TEST}: Error reading LUKSmeta info for slot ${SLT} of ${DEV}."
4949
fi
5050

5151
if [ "${state}" != "active" ]; then
52-
error "${TEST}: state (${state}) is expected to be 'active'." >&2
52+
error "${TEST}: state (${state}) is expected to be 'active'."
5353
fi
5454

5555
if [ "${uuid}" != "${UUID}" ]; then
56-
error "${TEST}: UUID ($uuid) is expected to be '${UUID}'." >&2
56+
error "${TEST}: UUID ($uuid) is expected to be '${UUID}'."
57+
fi
58+
59+
# Empty password (issue #494)
60+
DEV="${TMP}/luks1-device-empty-pw"
61+
new_device "luks1" "${DEV}"
62+
63+
# Let's create an empty password.
64+
printf '%s\n\n' "${DEFAULT_PASS}" | cryptsetup luksChangeKey \
65+
--force-password --batch-mode "${DEV}"
66+
67+
if ! clevis luks bind -f -d "${DEV}" tang "${CFG}" <<< ""; then
68+
error "${TEST}: Binding is expected to succeed when the password is empty."
5769
fi

src/luks/tests/bind-luks2

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,21 @@ TOKEN_ID=5
4545
new_device "luks2" "${DEV}"
4646

4747
if ! clevis luks bind -d "${DEV}" -t "$TOKEN_ID" tang "${CFG}" <<< "${DEFAULT_PASS}"; then
48-
error "${TEST}: Binding is expected to succeed when given a correct (${DEFAULT_PASS}) password." >&2
48+
error "${TEST}: Binding is expected to succeed when given a correct (${DEFAULT_PASS}) password."
4949
fi
5050

5151
if ! cryptsetup token export --token-id=5 "${DEV}"; then
52-
error "${TEST}: Clevis did not add the LUKS2 token to the correct slot." >&2
52+
error "${TEST}: Clevis did not add the LUKS2 token to the correct slot."
53+
fi
54+
55+
# Empty password (issue #494)
56+
DEV="${TMP}/luks2-device-empty-pw"
57+
new_device "luks2" "${DEV}"
58+
59+
# Let's create an empty password.
60+
printf '%s\n\n' "${DEFAULT_PASS}" | cryptsetup luksChangeKey \
61+
--force-password --batch-mode "${DEV}"
62+
63+
if ! clevis luks bind -d "${DEV}" tang "${CFG}" <<< ""; then
64+
error "${TEST}: Binding is expected to succeed when the password is empty."
5365
fi

0 commit comments

Comments
 (0)