Skip to content

Commit 0a77b32

Browse files
author
Ronan Pigott
committed
luks-list: add arg to show thumbprint
1 parent ebdc5e8 commit 0a77b32

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ clevis_luks_decode_jwe() {
163163
clevis_luks_print_pin_config() {
164164
local P="${1}"
165165
local decoded="${2}"
166+
local THP="${3}"
166167

167168
local content
168169
if ! content="$(jose fmt -j- -g clevis -g "${P}" -o- <<< "${decoded}")" \
@@ -175,9 +176,13 @@ clevis_luks_print_pin_config() {
175176
tang)
176177
local url adv thp
177178
url="$(jose fmt -j- -g url -u- <<< "${content}")"
178-
adv="$(jose fmt -j- -g adv -o- <<< "${content}")"
179-
thp="$(jose jwk thp -i- <<< "${adv}" | tail -n1)"
180-
pin=$(printf '{"url":"%s","thp":"%s"}' "${url}" "${thp}")
179+
if [ -z "${THP}" ]; then
180+
pin=$(printf '{"url":"%s"}' "${url}")
181+
else
182+
adv="$(jose fmt -j- -g adv -o- <<< "${content}")"
183+
thp="$(jose jwk thp -i- <<< "${adv}" | tail -n1)"
184+
pin=$(printf '{"url":"%s","thp":"%s"}' "${url}" "${thp}")
185+
fi
181186
printf "tang '%s'" "${pin}"
182187
;;
183188
tpm2)
@@ -209,6 +214,7 @@ clevis_luks_print_pin_config() {
209214
# from it.
210215
clevis_luks_decode_pin_config() {
211216
local jwe="${1}"
217+
local THP="${2}"
212218

213219
local decoded
214220
if ! decoded=$(clevis_luks_decode_jwe "${jwe}"); then
@@ -220,7 +226,7 @@ clevis_luks_decode_pin_config() {
220226
return 1
221227
fi
222228

223-
clevis_luks_print_pin_config "${P}" "${decoded}"
229+
clevis_luks_print_pin_config "${P}" "${decoded}" "${THP}"
224230
}
225231

226232
# clevis_luks_join_sss_cfg() will receive a list of configurations for a given
@@ -288,14 +294,15 @@ clevis_luks_process_sss_pin() {
288294
clevis_luks_read_pins_from_slot() {
289295
local DEV="${1}"
290296
local SLOT="${2}"
297+
local THP="${3}"
291298

292299
local jwe
293300
if ! jwe=$(clevis_luks_read_slot "${DEV}" "${SLOT}" 2>/dev/null); then
294301
return 1
295302
fi
296303

297304
local cfg
298-
if ! cfg="$(clevis_luks_decode_pin_config "${jwe}")"; then
305+
if ! cfg="$(clevis_luks_decode_pin_config "${jwe}" "${THP}")"; then
299306
return 1
300307
fi
301308
printf "%s: %s\n" "${SLOT}" "${cfg}"

src/luks/clevis-luks-list

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ SUMMARY="Lists pins bound to a LUKSv1 or LUKSv2 device"
2525

2626
function usage() {
2727
echo >&2
28-
echo "Usage: clevis luks list -d DEV [-s SLT]" >&2
28+
echo "Usage: clevis luks list -d DEV [-s SLT] [-t]" >&2
2929
echo >&2
3030
echo "$SUMMARY": >&2
3131
echo >&2
3232
echo " -d DEV The LUKS device to list bound pins" >&2
3333
echo >&2
3434
echo " -s SLOT The slot number to list" >&2
3535
echo >&2
36+
echo " -t show thumbprints in the output" >&2
37+
echo >&2
3638
exit 1
3739
}
3840

@@ -45,6 +47,7 @@ while getopts ":d:s:" o; do
4547
case "$o" in
4648
d) DEV=${OPTARG};;
4749
s) SLT=${OPTARG};;
50+
t) THP="true";;
4851
*) usage;;
4952
esac
5053
done
@@ -62,15 +65,15 @@ if cryptsetup isLuks --type luks1 "${DEV}"; then
6265
fi
6366

6467
if [ -n "${SLT}" ]; then
65-
clevis_luks_read_pins_from_slot "${DEV}" "${SLT}"
68+
clevis_luks_read_pins_from_slot "${DEV}" "${SLT}" "${THP}"
6669
else
6770
if ! used_slots=$(clevis_luks_used_slots "${DEV}"); then
6871
echo "No used slots detected for device ${DEV}!" >&2
6972
exit 1
7073
fi
7174

7275
for s in ${used_slots}; do
73-
if ! clevis_luks_read_pins_from_slot "${DEV}" "${s}"; then
76+
if ! clevis_luks_read_pins_from_slot "${DEV}" "${s}" "${THP}"; then
7477
continue
7578
fi
7679
done

0 commit comments

Comments
 (0)