Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luks-list: show tang key thumbprints #375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/luks/clevis-luks-common-functions.in
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ clevis_luks_decode_jwe() {
clevis_luks_print_pin_config() {
local P="${1}"
local decoded="${2}"
local THP="${3}"

local content
if ! content="$(jose fmt -j- -g clevis -g "${P}" -o- <<< "${decoded}")" \
Expand All @@ -173,9 +174,15 @@ clevis_luks_print_pin_config() {
local pin=
case "${P}" in
tang)
local url
local url adv thp
url="$(jose fmt -j- -g url -u- <<< "${content}")"
pin=$(printf '{"url":"%s"}' "${url}")
if [ -z "${THP}" ]; then
pin=$(printf '{"url":"%s"}' "${url}")
else
adv="$(jose fmt -j- -g adv -o- <<< "${content}")"
thp="$(jose jwk thp -i- <<< "${adv}" | tail -n1)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct, as you will get thumbprints for both the exchange and signing keys. You should do something like tang-show-keys [1] does, with the jose jwk use -u verify, before getting the thumbprints.

It may be good to also specify the default hash algorithm for the thumbprints.

[1] https://github.com/latchset/tang/blob/master/src/tang-show-keys#L34

pin=$(printf '{"url":"%s","thp":"%s"}' "${url}" "${thp}")
fi
printf "tang '%s'" "${pin}"
;;
tpm2)
Expand All @@ -195,7 +202,7 @@ clevis_luks_print_pin_config() {
sss)
local threshold
threshold=$(jose fmt -j- -Og t -o- <<< "${content}")
clevis_luks_process_sss_pin "${content}" "${threshold}"
clevis_luks_process_sss_pin "${content}" "${threshold}" "${THP}"
;;
*)
printf "unknown pin '%s'" "${P}"
Expand All @@ -207,6 +214,7 @@ clevis_luks_print_pin_config() {
# from it.
clevis_luks_decode_pin_config() {
local jwe="${1}"
local THP="${2}"

local decoded
if ! decoded=$(clevis_luks_decode_jwe "${jwe}"); then
Expand All @@ -218,7 +226,7 @@ clevis_luks_decode_pin_config() {
return 1
fi

clevis_luks_print_pin_config "${P}" "${decoded}"
clevis_luks_print_pin_config "${P}" "${decoded}" "${THP}"
}

# clevis_luks_join_sss_cfg() will receive a list of configurations for a given
Expand All @@ -235,6 +243,7 @@ clevis_luks_join_sss_cfg() {
clevis_luks_process_sss_pin() {
local jwe="${1}"
local threshold="${2}"
local THP="${3}"

local sss_tang
local sss_tpm2
Expand All @@ -245,7 +254,7 @@ clevis_luks_process_sss_pin() {

local coded
for coded in $(jose fmt -j- -Og jwe -Af- <<< "${jwe}"| tr -d '"'); do
if ! pin_cfg="$(clevis_luks_decode_pin_config "${coded}")"; then
if ! pin_cfg="$(clevis_luks_decode_pin_config "${coded}" "${THP}")"; then
continue
fi
read -r pin cfg <<< "${pin_cfg}"
Expand Down Expand Up @@ -286,14 +295,15 @@ clevis_luks_process_sss_pin() {
clevis_luks_read_pins_from_slot() {
local DEV="${1}"
local SLOT="${2}"
local THP="${3}"

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

local cfg
if ! cfg="$(clevis_luks_decode_pin_config "${jwe}")"; then
if ! cfg="$(clevis_luks_decode_pin_config "${jwe}" "${THP}")"; then
return 1
fi
printf "%s: %s\n" "${SLOT}" "${cfg}"
Expand Down
11 changes: 7 additions & 4 deletions src/luks/clevis-luks-list
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ SUMMARY="Lists pins bound to a LUKSv1 or LUKSv2 device"

function usage() {
echo >&2
echo "Usage: clevis luks list -d DEV [-s SLT]" >&2
echo "Usage: clevis luks list -d DEV [-s SLT] [-t]" >&2
echo >&2
echo "$SUMMARY": >&2
echo >&2
echo " -d DEV The LUKS device to list bound pins" >&2
echo >&2
echo " -s SLOT The slot number to list" >&2
echo >&2
echo " -t show thumbprints in the output" >&2
echo >&2
exit 1
}

Expand All @@ -41,10 +43,11 @@ if [ ${#} -eq 1 ] && [ "${1}" = "--summary" ]; then
exit 0
fi

while getopts ":d:s:" o; do
while getopts ":d:s:t" o; do
case "$o" in
d) DEV=${OPTARG};;
s) SLT=${OPTARG};;
t) THP="true";;
*) usage;;
esac
done
Expand All @@ -62,15 +65,15 @@ if cryptsetup isLuks --type luks1 "${DEV}"; then
fi

if [ -n "${SLT}" ]; then
clevis_luks_read_pins_from_slot "${DEV}" "${SLT}"
clevis_luks_read_pins_from_slot "${DEV}" "${SLT}" "${THP}"
else
if ! used_slots=$(clevis_luks_used_slots "${DEV}"); then
echo "No used slots detected for device ${DEV}!" >&2
exit 1
fi

for s in ${used_slots}; do
if ! clevis_luks_read_pins_from_slot "${DEV}" "${s}"; then
if ! clevis_luks_read_pins_from_slot "${DEV}" "${s}" "${THP}"; then
continue
fi
done
Expand Down