|
|
ef20f4 |
From 70d3da5ce8d68e8ff258122592670eb70da0c839 Mon Sep 17 00:00:00 2001
|
|
|
ef20f4 |
From: Sergio Correia <scorreia@redhat.com>
|
|
|
ef20f4 |
Date: Wed, 16 Oct 2019 09:14:58 -0300
|
|
|
ef20f4 |
Subject: [PATCH 2/2] Add clevis luks report/regen
|
|
|
ef20f4 |
|
|
|
ef20f4 |
---
|
|
|
ef20f4 |
src/luks/clevis-luks-common-functions | 143 ++++++++++++++++++++
|
|
|
ef20f4 |
src/luks/clevis-luks-regen | 186 ++++++++++++++++++++++++++
|
|
|
ef20f4 |
src/luks/clevis-luks-regen.1.adoc | 36 +++++
|
|
|
ef20f4 |
src/luks/clevis-luks-report | 95 +++++++++++++
|
|
|
ef20f4 |
src/luks/clevis-luks-report-compare | 71 ++++++++++
|
|
|
ef20f4 |
src/luks/clevis-luks-report-decode | 59 ++++++++
|
|
|
ef20f4 |
src/luks/clevis-luks-report-sss | 53 ++++++++
|
|
|
ef20f4 |
src/luks/clevis-luks-report-tang | 67 ++++++++++
|
|
|
ef20f4 |
src/luks/clevis-luks-report.1.adoc | 41 ++++++
|
|
|
ef20f4 |
src/luks/meson.build | 12 ++
|
|
|
ef20f4 |
10 files changed, 763 insertions(+)
|
|
|
ef20f4 |
create mode 100644 src/luks/clevis-luks-common-functions
|
|
|
ef20f4 |
create mode 100755 src/luks/clevis-luks-regen
|
|
|
ef20f4 |
create mode 100644 src/luks/clevis-luks-regen.1.adoc
|
|
|
ef20f4 |
create mode 100755 src/luks/clevis-luks-report
|
|
|
ef20f4 |
create mode 100755 src/luks/clevis-luks-report-compare
|
|
|
ef20f4 |
create mode 100755 src/luks/clevis-luks-report-decode
|
|
|
ef20f4 |
create mode 100755 src/luks/clevis-luks-report-sss
|
|
|
ef20f4 |
create mode 100755 src/luks/clevis-luks-report-tang
|
|
|
ef20f4 |
create mode 100644 src/luks/clevis-luks-report.1.adoc
|
|
|
ef20f4 |
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-common-functions b/src/luks/clevis-luks-common-functions
|
|
|
ef20f4 |
new file mode 100644
|
|
|
ef20f4 |
index 0000000..d676253
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-common-functions
|
|
|
ef20f4 |
@@ -0,0 +1,143 @@
|
|
|
ef20f4 |
+#!/bin/bash -e
|
|
|
ef20f4 |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# Copyright (c) 2019 Red Hat, Inc.
|
|
|
ef20f4 |
+# Author: Sergio Correia <scorreia@redhat.com>
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is free software: you can redistribute it and/or modify
|
|
|
ef20f4 |
+# it under the terms of the GNU General Public License as published by
|
|
|
ef20f4 |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
ef20f4 |
+# (at your option) any later version.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is distributed in the hope that it will be useful,
|
|
|
ef20f4 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ef20f4 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
ef20f4 |
+# GNU General Public License for more details.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# You should have received a copy of the GNU General Public License
|
|
|
ef20f4 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+# valid_slot() will check whether a given slot is possibly valid, i.e., if it
|
|
|
ef20f4 |
+# is a numeric value within the specified range.
|
|
|
ef20f4 |
+valid_slot() {
|
|
|
ef20f4 |
+ local SLT="${1}"
|
|
|
ef20f4 |
+ local MAX_SLOTS="${2}"
|
|
|
ef20f4 |
+ case "${SLT}" in
|
|
|
ef20f4 |
+ ''|*[!0-9]*)
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ ;;
|
|
|
ef20f4 |
+ *)
|
|
|
ef20f4 |
+ # We got an integer, now let's make sure it is within the
|
|
|
ef20f4 |
+ # supported range.
|
|
|
ef20f4 |
+ if [ "${SLT}" -ge "${MAX_SLOTS}" ]; then
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ ;;
|
|
|
ef20f4 |
+ esac
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+# clevis_luks_read_slot() will read a particular slot of a given device, which
|
|
|
ef20f4 |
+# should be either LUKS1 or LUKS2. Returns 1 in case of failure; 0 in case of
|
|
|
ef20f4 |
+# success.
|
|
|
ef20f4 |
+clevis_luks_read_slot() {
|
|
|
ef20f4 |
+ local DEV="${1}"
|
|
|
ef20f4 |
+ local SLT="${2}"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if [ -z "${DEV}" ] || [ -z "${SLT}" ]; then
|
|
|
ef20f4 |
+ echo "Need both a device and a slot as arguments." >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ local DATA_CODED=''
|
|
|
ef20f4 |
+ local MAX_LUKS1_SLOTS=8
|
|
|
ef20f4 |
+ local MAX_LUKS2_SLOTS=32
|
|
|
ef20f4 |
+ if cryptsetup isLuks --type luks1 "${DEV}"; then
|
|
|
ef20f4 |
+ if ! valid_slot "${SLT}" "${MAX_LUKS1_SLOTS}"; then
|
|
|
ef20f4 |
+ echo "Please, provide a valid key slot number; 0-7 for LUKS1" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if ! luksmeta test -d "${DEV}"; then
|
|
|
ef20f4 |
+ echo "The ${DEV} device is not valid!" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ local uuid
|
|
|
ef20f4 |
+ # Pattern from luksmeta: active slot uuid.
|
|
|
ef20f4 |
+ read -r _ _ uuid <<< "$(luksmeta show -d "${DEV}" | grep "^${SLT} *")"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if [ "${uuid}" = "empty" ]; then
|
|
|
ef20f4 |
+ echo "The LUKSMeta slot ${SLT} on device ${DEV} is already empty." >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if ! DATA_CODED="$(luksmeta load -d "${DEV}" -s "${SLT}")"; then
|
|
|
ef20f4 |
+ echo "Cannot load data from ${DEV} slot:${SLT}!" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ elif cryptsetup isLuks --type luks2 "${DEV}"; then
|
|
|
ef20f4 |
+ if ! valid_slot "${SLT}" "${MAX_LUKS2_SLOTS}"; then
|
|
|
ef20f4 |
+ echo "Please, provide a valid key slot number; 0-31 for LUKS2" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ local token_id
|
|
|
ef20f4 |
+ token_id=$(cryptsetup luksDump "${DEV}" \
|
|
|
ef20f4 |
+ | grep -E -B1 "^\s+Keyslot:\s+${SLT}$" \
|
|
|
ef20f4 |
+ | head -n 1 | sed -rn 's|^\s+([0-9]+): clevis|\1|p')
|
|
|
ef20f4 |
+ if [ -z "${token_id}" ]; then
|
|
|
ef20f4 |
+ echo "Cannot load data from ${DEV} slot:${SLT}. No token found!" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ local token
|
|
|
ef20f4 |
+ token=$(cryptsetup token export --token-id "${token_id}" "${DEV}")
|
|
|
ef20f4 |
+ DATA_CODED=$(jose fmt -j- -Og jwe -o- <<< "${token}" \
|
|
|
ef20f4 |
+ | jose jwe fmt -i- -c)
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if [ -z "${DATA_CODED}" ]; then
|
|
|
ef20f4 |
+ echo "Cannot load data from ${DEV} slot:${SLT}!" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ else
|
|
|
ef20f4 |
+ echo "${DEV} is not a supported LUKS device!" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ echo "${DATA_CODED}"
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+# Generate a key with the same entropy as the LUKS Master key of a given
|
|
|
ef20f4 |
+# device.
|
|
|
ef20f4 |
+generate_key() {
|
|
|
ef20f4 |
+ local DEV="${1}"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if [ -z "${DEV}" ]; then
|
|
|
ef20f4 |
+ echo "Please, specify a device." >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ local dump
|
|
|
ef20f4 |
+ local filter
|
|
|
ef20f4 |
+ dump=$(cryptsetup luksDump "${DEV}")
|
|
|
ef20f4 |
+ if cryptsetup isLuks --type luks1 "${DEV}"; then
|
|
|
ef20f4 |
+ filter=$(sed -rn 's|MK bits:[ \t]*([0-9]+)|\1|p' <<< "${dump}")
|
|
|
ef20f4 |
+ elif cryptsetup isLuks --type luks2 "${DEV}"; then
|
|
|
ef20f4 |
+ filter=$(sed -rn 's|^\s+Key:\s+([0-9]+) bits\s*$|\1|p' <<< "${dump}")
|
|
|
ef20f4 |
+ else
|
|
|
ef20f4 |
+ echo "${DEV} is not a supported LUKS device!" >&2
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ local bits
|
|
|
ef20f4 |
+ bits=$(sort -n <<< "${filter}" | tail -n 1)
|
|
|
ef20f4 |
+ pwmake "${bits}"
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+findexe() {
|
|
|
ef20f4 |
+ while read -r -d: path; do
|
|
|
ef20f4 |
+ [ -f "${path}/${1}" ] && [ -x "${path}/${1}" ] && \
|
|
|
ef20f4 |
+ echo "${path}/${1}" && return 0
|
|
|
ef20f4 |
+ done <<< "${PATH}:"
|
|
|
ef20f4 |
+ return 1
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-regen b/src/luks/clevis-luks-regen
|
|
|
ef20f4 |
new file mode 100755
|
|
|
ef20f4 |
index 0000000..9535ba3
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-regen
|
|
|
ef20f4 |
@@ -0,0 +1,186 @@
|
|
|
ef20f4 |
+#!/usr/bin/env bash
|
|
|
ef20f4 |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# Copyright (c) 2018 Red Hat, Inc.
|
|
|
ef20f4 |
+# Author: Radovan Sroka <rsroka@redhat.com>
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is free software: you can redistribute it and/or modify
|
|
|
ef20f4 |
+# it under the terms of the GNU General Public License as published by
|
|
|
ef20f4 |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
ef20f4 |
+# (at your option) any later version.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is distributed in the hope that it will be useful,
|
|
|
ef20f4 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ef20f4 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
ef20f4 |
+# GNU General Public License for more details.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# You should have received a copy of the GNU General Public License
|
|
|
ef20f4 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+. clevis-luks-common-functions
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+SUMMARY="Regenerate LUKS metadata"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$1" == "--summary" ]; then
|
|
|
ef20f4 |
+ echo "$SUMMARY"
|
|
|
ef20f4 |
+ exit 0
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+function usage_and_exit () {
|
|
|
ef20f4 |
+ echo >&2
|
|
|
ef20f4 |
+ echo "Usage: clevis luks regen -d DEV -s SLOT" >&2
|
|
|
ef20f4 |
+ echo >&2
|
|
|
ef20f4 |
+ echo "$SUMMARY" >&2
|
|
|
ef20f4 |
+ echo >&2
|
|
|
ef20f4 |
+ exit "$1"
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$#" -ne "4" ]; then
|
|
|
ef20f4 |
+ usage_and_exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+while getopts "hd:s:" o; do
|
|
|
ef20f4 |
+ case "$o" in
|
|
|
ef20f4 |
+ d) DEV="$OPTARG";;
|
|
|
ef20f4 |
+ h) usage_and_exit 0;;
|
|
|
ef20f4 |
+ s) SLT="$OPTARG";;
|
|
|
ef20f4 |
+ *) usage_and_exit 1;;
|
|
|
ef20f4 |
+ esac
|
|
|
ef20f4 |
+done
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+function decode_luks_header () {
|
|
|
ef20f4 |
+ if DATA_CODED="$(jose jwe fmt -i- <<< "$1")"; then
|
|
|
ef20f4 |
+ DATA_CODED="$(jose fmt -j- -g protected -u- <<< "$DATA_CODED")"
|
|
|
ef20f4 |
+ DATA_DECODED="$(jose b64 dec -i- <<< "$DATA_CODED")"
|
|
|
ef20f4 |
+ else
|
|
|
ef20f4 |
+ echo "Error decoding JWE protected header!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ echo "$DATA_DECODED"
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+function generate_cfg () {
|
|
|
ef20f4 |
+ echo -n "{"
|
|
|
ef20f4 |
+ DATA="$(decode_luks_header "$1")"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if ! P="$(jose fmt -j- -g clevis -g pin -u- <<< "$DATA")" || [ -z "$P" ]; then
|
|
|
ef20f4 |
+ echo "Pin wasn't found in LUKS metadata!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if ! CONTENT="$(jose fmt -j- -g clevis -g "$P" -o- <<< "$DATA")" || [ -z "$CONTENT" ]; then
|
|
|
ef20f4 |
+ echo "Content was not found!" >&2
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ # echo -n "\"$P\": ["
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if [ "$P" = "tang" ] || [ "$P" = "http" ]; then
|
|
|
ef20f4 |
+ URL="$(jose fmt -j- -g url -u- <<< "$CONTENT")"
|
|
|
ef20f4 |
+ echo -n "\"url\":\"$URL\""
|
|
|
ef20f4 |
+ elif [ "$P" = "sss" ]; then
|
|
|
ef20f4 |
+ THRESHOLD="$(jose fmt -j- -g t -o- <<< "$CONTENT")"
|
|
|
ef20f4 |
+ if [ -n "$THRESHOLD" ]; then
|
|
|
ef20f4 |
+ echo -n "\"t\":$THRESHOLD,"
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ echo -n "\"pins\":{"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ CNT=0
|
|
|
ef20f4 |
+ PREV=""
|
|
|
ef20f4 |
+ while ITEM="$(jose fmt -j- -g jwe -g"$CNT" -u- <<< "$CONTENT")"; do
|
|
|
ef20f4 |
+ if [ -z "$ITEM" ]; then
|
|
|
ef20f4 |
+ CNT=$(( CNT + 1 ))
|
|
|
ef20f4 |
+ continue # in some cases it can be empty string
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ DD="$(decode_luks_header "$ITEM")"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if ! PP="$(jose fmt -j- -g clevis -g pin -u- <<< "$DD")" || [ -z "$PP" ]; then
|
|
|
ef20f4 |
+ echo "Pin wasn't found in LUKS metadata!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if [ "$CNT" -eq 0 ]; then
|
|
|
ef20f4 |
+ PREV="$PP"
|
|
|
ef20f4 |
+ echo -n "\"$PP\":["
|
|
|
ef20f4 |
+ echo -n "$(generate_cfg "$ITEM")"
|
|
|
ef20f4 |
+ else
|
|
|
ef20f4 |
+ if ! [ "$PREV" = "$PP" ]; then
|
|
|
ef20f4 |
+ echo -n "],\"$PP\":["
|
|
|
ef20f4 |
+ echo -n "$(generate_cfg "$ITEM")"
|
|
|
ef20f4 |
+ else
|
|
|
ef20f4 |
+ echo -n ",$(generate_cfg "$ITEM")"
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ PREV="$PP"
|
|
|
ef20f4 |
+ CNT=$(( CNT + 1 ))
|
|
|
ef20f4 |
+ done
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ echo -n "]}"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ else
|
|
|
ef20f4 |
+ echo "Unknown pin $P!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ echo -n "}"
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### get luks metadata
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$DEV" ]; then
|
|
|
ef20f4 |
+ echo "Did not specify a device!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$SLT" ]; then
|
|
|
ef20f4 |
+ echo "Did not specify a slot!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! OLD_LUKS_CODED="$(clevis_luks_read_slot "$DEV" "$SLT")"; then
|
|
|
ef20f4 |
+ echo "Error reading metadata from LUKS device!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### ----------------------------------------------------------------------
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+DECODED="$(decode_luks_header "$OLD_LUKS_CODED")"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! PIN="$(jose fmt -j- -g clevis -g pin -u- <<< "$DECODED")" || [ -z "$PIN" ]; then
|
|
|
ef20f4 |
+ echo "Pin wasn't found in LUKS metadata!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+CFG="$(generate_cfg "$OLD_LUKS_CODED")"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### ----------------------------------------------------------------------
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+echo "Regenerating with:"
|
|
|
ef20f4 |
+echo "PIN: $PIN"
|
|
|
ef20f4 |
+echo "CONFIG: $CFG"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+trap 'echo "Ignoring CONTROL-C!"' INT TERM
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+# Get the existing key.
|
|
|
ef20f4 |
+read -r -s -p "Enter existing LUKS password: " existing_key; echo
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+# Check if the key is valid.
|
|
|
ef20f4 |
+if ! cryptsetup luksOpen --test-passphrase "${DEV}" <<< "${existing_key}"; then
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! clevis luks unbind -d "${DEV}" -s "${SLT}" -f; then
|
|
|
ef20f4 |
+ echo "Error during unbind of rotated key from slot:$SLT in $DEV" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! clevis luks bind -d "${DEV}" -s "${SLT}" "${PIN}" "${CFG}" -k - <<< "${existing_key}"; then
|
|
|
ef20f4 |
+ echo "Error during bind of new key from slot:$SLT in $DEV" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+echo "Keys were succesfully rotated."
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-regen.1.adoc b/src/luks/clevis-luks-regen.1.adoc
|
|
|
ef20f4 |
new file mode 100644
|
|
|
ef20f4 |
index 0000000..3cd6b7c
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-regen.1.adoc
|
|
|
ef20f4 |
@@ -0,0 +1,36 @@
|
|
|
ef20f4 |
+CLEVIS-LUKS-REGEN(1)
|
|
|
ef20f4 |
+=====================
|
|
|
ef20f4 |
+:doctype: manpage
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== NAME
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+clevis-luks-regen - Regenerates LUKS metadata
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== SYNOPSIS
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+*clevis luks regen* -d DEV -s SLT
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== OVERVIEW
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+The *clevis luks regen* command regenerates the LUKS metadata for a given slot in a LUKS device. It effectively
|
|
|
ef20f4 |
+performs an operation equivalent to *clevis luks unbind* and *clevis luks bind* for rebinding said slot and device.
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== OPTIONS
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+* *-d* _DEV_ :
|
|
|
ef20f4 |
+ The bound LUKS device
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+* *-s* _SLT_ :
|
|
|
ef20f4 |
+ The slot or key slot number for rebinding. Note that it requires that such slot is currently bound by clevis.
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== EXAMPLE
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ Regenerate the binding of slot 1 from /dev/sda1:
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ # clevis luks regen -d /dev/sda1 -s 1
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== SEE ALSO
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+link:clevis-luks-bind.1.adoc[*clevis-luks-bind*(1)]
|
|
|
ef20f4 |
+link:clevis-luks-unbind.1.adoc[*clevis-luks-unbind*(1)]
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-report b/src/luks/clevis-luks-report
|
|
|
ef20f4 |
new file mode 100755
|
|
|
ef20f4 |
index 0000000..f047256
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-report
|
|
|
ef20f4 |
@@ -0,0 +1,95 @@
|
|
|
ef20f4 |
+#!/usr/bin/bash -e
|
|
|
ef20f4 |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# Copyright (c) 2018 Red Hat, Inc.
|
|
|
ef20f4 |
+# Author: Radovan Sroka <rsroka@redhat.com>
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is free software: you can redistribute it and/or modify
|
|
|
ef20f4 |
+# it under the terms of the GNU General Public License as published by
|
|
|
ef20f4 |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
ef20f4 |
+# (at your option) any later version.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is distributed in the hope that it will be useful,
|
|
|
ef20f4 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ef20f4 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
ef20f4 |
+# GNU General Public License for more details.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# You should have received a copy of the GNU General Public License
|
|
|
ef20f4 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+. clevis-luks-common-functions
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+SUMMARY="Report any key rotation on the server side"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$1" == "--summary" ]; then
|
|
|
ef20f4 |
+ echo "$SUMMARY"
|
|
|
ef20f4 |
+ exit 0
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+function usage_and_exit () {
|
|
|
ef20f4 |
+ echo >&2
|
|
|
ef20f4 |
+ echo "Usage: clevis luks report [-qr] -d DEV -s SLOT" >&2
|
|
|
ef20f4 |
+ echo >&2
|
|
|
ef20f4 |
+ echo -e " -q\t Quiet mode" >&2
|
|
|
ef20f4 |
+ echo -e " -r\t Regenerate luks metadata with \"clevis luks regen -d DEV -s SLOT\"" >&2
|
|
|
ef20f4 |
+ echo >&2
|
|
|
ef20f4 |
+ echo "$SUMMARY" >&2
|
|
|
ef20f4 |
+ echo >&2
|
|
|
ef20f4 |
+ exit "$1"
|
|
|
ef20f4 |
+}
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+while getopts "hd:s:rq" o; do
|
|
|
ef20f4 |
+ case "$o" in
|
|
|
ef20f4 |
+ d) DEV="$OPTARG";;
|
|
|
ef20f4 |
+ h) usage_and_exit 0;;
|
|
|
ef20f4 |
+ r) ROPT="regen";;
|
|
|
ef20f4 |
+ s) SLT="$OPTARG";;
|
|
|
ef20f4 |
+ q) QOPT="quiet";;
|
|
|
ef20f4 |
+ *) usage_and_exit 1;;
|
|
|
ef20f4 |
+ esac
|
|
|
ef20f4 |
+done
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### get luks metadata
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$DEV" ]; then
|
|
|
ef20f4 |
+ echo "Did not specify a device!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$SLT" ]; then
|
|
|
ef20f4 |
+ echo "Did not specify a slot!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! DATA_CODED=$(clevis_luks_read_slot "${DEV}" "${SLT}"); then
|
|
|
ef20f4 |
+ # Error message was already displayed by clevis_luks_read_slot(),
|
|
|
ef20f4 |
+ # at this point.
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+EXE="$(findexe clevis-luks-report-decode)"
|
|
|
ef20f4 |
+RESULT="$($EXE "${DATA_CODED}")"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -n "$RESULT" ]; then
|
|
|
ef20f4 |
+ echo "$RESULT"
|
|
|
ef20f4 |
+ echo "Report detected that some keys were rotated."
|
|
|
ef20f4 |
+ if [ -z "$QOPT" ]; then
|
|
|
ef20f4 |
+ if [ -z "$ROPT" ]; then
|
|
|
ef20f4 |
+ read -r -p "Do you want to regenerate luks metadata with \"clevis luks regen -d $DEV -s $SLT\"? [ynYN] " ans < /dev/tty
|
|
|
ef20f4 |
+ [[ "$ans" =~ ^[yY]$ ]] && ROPT="regen"
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+else
|
|
|
ef20f4 |
+ exit 0
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$ROPT" = "regen" ]; then
|
|
|
ef20f4 |
+ EXE="$(findexe clevis-luks-regen)"
|
|
|
ef20f4 |
+ exec "$EXE" -d "$DEV" -s "$SLT"
|
|
|
ef20f4 |
+else
|
|
|
ef20f4 |
+ if [ -n "${RESULT}" ]; then
|
|
|
ef20f4 |
+ # Keys were rotated.
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-report-compare b/src/luks/clevis-luks-report-compare
|
|
|
ef20f4 |
new file mode 100755
|
|
|
ef20f4 |
index 0000000..2ba5132
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-report-compare
|
|
|
ef20f4 |
@@ -0,0 +1,71 @@
|
|
|
ef20f4 |
+#!/usr/bin/bash -e
|
|
|
ef20f4 |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# Copyright (c) 2018 Red Hat, Inc.
|
|
|
ef20f4 |
+# Author: Radovan Sroka <rsroka@redhat.com>
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is free software: you can redistribute it and/or modify
|
|
|
ef20f4 |
+# it under the terms of the GNU General Public License as published by
|
|
|
ef20f4 |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
ef20f4 |
+# (at your option) any later version.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is distributed in the hope that it will be useful,
|
|
|
ef20f4 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ef20f4 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
ef20f4 |
+# GNU General Public License for more details.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# You should have received a copy of the GNU General Public License
|
|
|
ef20f4 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+SUMMARY="Compare two sets of keys"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$1" == "--summary" ]; then
|
|
|
ef20f4 |
+ echo "$SUMMARY"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$1" ]; then
|
|
|
ef20f4 |
+ echo "$0 missing the first argument!"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$2" ]; then
|
|
|
ef20f4 |
+ echo "$0 missing the second argument!"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ADV_KEYS="$1" # keys from advertisement
|
|
|
ef20f4 |
+LUKS_KEYS="$2" # keys from luks metadata
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### iterate over adv keys and make thumbprints
|
|
|
ef20f4 |
+CNT=0
|
|
|
ef20f4 |
+declare -a ADV_KEYS_ARRAY
|
|
|
ef20f4 |
+while res="$(jose fmt -j- -g keys -g"$CNT" -o- <<< "$ADV_KEYS")"; do
|
|
|
ef20f4 |
+ thp="$(echo "$res" | jose jwk thp -i-)"
|
|
|
ef20f4 |
+ ADV_KEYS_ARRAY["$CNT"]="$thp"
|
|
|
ef20f4 |
+ CNT=$(( CNT + 1 ))
|
|
|
ef20f4 |
+done
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+CNT=0
|
|
|
ef20f4 |
+while key="$(jose fmt -j- -g keys -g"$CNT" -o- <<< "$LUKS_KEYS")"; do
|
|
|
ef20f4 |
+ thp="$(echo "$key" | jose jwk thp -i-)"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ FOUND=0
|
|
|
ef20f4 |
+ for k in "${ADV_KEYS_ARRAY[@]}"
|
|
|
ef20f4 |
+ do
|
|
|
ef20f4 |
+ if [ "$k" = "$thp" ]; then
|
|
|
ef20f4 |
+ FOUND=1
|
|
|
ef20f4 |
+ break
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ done
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ if [ "$FOUND" -eq "0" ]; then
|
|
|
ef20f4 |
+ echo "Key \"$thp\" is not in the advertisement and was probably rotated!"
|
|
|
ef20f4 |
+ echo "$key"
|
|
|
ef20f4 |
+ echo
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+ CNT=$(( CNT + 1 ))
|
|
|
ef20f4 |
+done
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+exit 0
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-report-decode b/src/luks/clevis-luks-report-decode
|
|
|
ef20f4 |
new file mode 100755
|
|
|
ef20f4 |
index 0000000..f39d1e9
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-report-decode
|
|
|
ef20f4 |
@@ -0,0 +1,59 @@
|
|
|
ef20f4 |
+#!/usr/bin/bash -e
|
|
|
ef20f4 |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# Copyright (c) 2018 Red Hat, Inc.
|
|
|
ef20f4 |
+# Author: Radovan Sroka <rsroka@redhat.com>
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is free software: you can redistribute it and/or modify
|
|
|
ef20f4 |
+# it under the terms of the GNU General Public License as published by
|
|
|
ef20f4 |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
ef20f4 |
+# (at your option) any later version.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is distributed in the hope that it will be useful,
|
|
|
ef20f4 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ef20f4 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
ef20f4 |
+# GNU General Public License for more details.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# You should have received a copy of the GNU General Public License
|
|
|
ef20f4 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+. clevis-luks-common-functions
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+SUMMARY="Decode luks header"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$1" == "--summary" ]; then
|
|
|
ef20f4 |
+ echo "$SUMMARY"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$1" ]; then
|
|
|
ef20f4 |
+ echo "$0 missing the first argument!"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+DATA_CODED="$1"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if DATA_CODED="$(jose jwe fmt -i- <<< "$DATA_CODED")"; then
|
|
|
ef20f4 |
+ DATA_CODED="$(jose fmt -j- -g protected -u- <<< "$DATA_CODED")"
|
|
|
ef20f4 |
+ DATA_DECODED="$(jose b64 dec -i- <<< "$DATA_CODED")"
|
|
|
ef20f4 |
+else
|
|
|
ef20f4 |
+ echo "Error decoding JWE protected header!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### get pin and url
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! PIN="$(jose fmt -j- -g clevis -g pin -u- <<< "$DATA_DECODED")" || [ -z "$PIN" ]; then
|
|
|
ef20f4 |
+ echo "Pin wasn't found in luks metadata!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! CONTENT="$(jose fmt -j- -g clevis -g "$PIN" -o- <<< "$DATA_DECODED")" || [ -z "$CONTENT" ]; then
|
|
|
ef20f4 |
+ echo "Content wasn't found!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+EXE="$(findexe clevis-luks-report-"$PIN")"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+exec "$EXE" "$CONTENT"
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-report-sss b/src/luks/clevis-luks-report-sss
|
|
|
ef20f4 |
new file mode 100755
|
|
|
ef20f4 |
index 0000000..1dba4c1
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-report-sss
|
|
|
ef20f4 |
@@ -0,0 +1,53 @@
|
|
|
ef20f4 |
+#!/bin/bash -e
|
|
|
ef20f4 |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# Copyright (c) 2018 Red Hat, Inc.
|
|
|
ef20f4 |
+# Author: Radovan Sroka <rsroka@redhat.com>
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is free software: you can redistribute it and/or modify
|
|
|
ef20f4 |
+# it under the terms of the GNU General Public License as published by
|
|
|
ef20f4 |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
ef20f4 |
+# (at your option) any later version.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is distributed in the hope that it will be useful,
|
|
|
ef20f4 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ef20f4 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
ef20f4 |
+# GNU General Public License for more details.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# You should have received a copy of the GNU General Public License
|
|
|
ef20f4 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+. clevis-luks-common-functions
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+SUMMARY="SSS report plugin"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$1" == "--summary" ]; then
|
|
|
ef20f4 |
+ echo "$SUMMARY"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$1" ]; then
|
|
|
ef20f4 |
+ echo "$0 missing the first argument!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+CONTENT="$1" # sss content
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+CNT=0
|
|
|
ef20f4 |
+while DATA_CODED="$(jose fmt -j- -g jwe -g"$CNT" -u- <<< "$CONTENT")"; do
|
|
|
ef20f4 |
+ if [ -z "$DATA_CODED" ]; then
|
|
|
ef20f4 |
+ CNT=$(( CNT + 1 ))
|
|
|
ef20f4 |
+ continue # in some cases it can be empty string
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ EXE="$(findexe clevis-luks-report-decode)"
|
|
|
ef20f4 |
+ if ! $EXE "$DATA_CODED"; then
|
|
|
ef20f4 |
+ echo "Failed" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+ fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ CNT=$(( CNT + 1 ))
|
|
|
ef20f4 |
+done
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+exit 0
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-report-tang b/src/luks/clevis-luks-report-tang
|
|
|
ef20f4 |
new file mode 100755
|
|
|
ef20f4 |
index 0000000..07f2a72
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-report-tang
|
|
|
ef20f4 |
@@ -0,0 +1,67 @@
|
|
|
ef20f4 |
+#!/usr/bin/bash -e
|
|
|
ef20f4 |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# Copyright (c) 2018 Red Hat, Inc.
|
|
|
ef20f4 |
+# Author: Radovan Sroka <rsroka@redhat.com>
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is free software: you can redistribute it and/or modify
|
|
|
ef20f4 |
+# it under the terms of the GNU General Public License as published by
|
|
|
ef20f4 |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
ef20f4 |
+# (at your option) any later version.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# This program is distributed in the hope that it will be useful,
|
|
|
ef20f4 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
ef20f4 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
ef20f4 |
+# GNU General Public License for more details.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+# You should have received a copy of the GNU General Public License
|
|
|
ef20f4 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
ef20f4 |
+#
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+. clevis-luks-common-functions
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+SUMMARY="Tang report plugin"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ "$1" == "--summary" ]; then
|
|
|
ef20f4 |
+ echo "$SUMMARY"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if [ -z "$1" ]; then
|
|
|
ef20f4 |
+ echo "$0 missing the first argument!"
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+CONTENT="$1"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### Get the advertisement
|
|
|
ef20f4 |
+if ! URL="$(jose fmt -j- -g url -u- <<< "$CONTENT")" || [ -z "$URL" ]; then
|
|
|
ef20f4 |
+ echo "URL was not found!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! jws="$(curl -sfg "$URL/adv")"; then
|
|
|
ef20f4 |
+ echo "Unable to fetch advertisement: $URL/adv!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! TANG_KEYS="$(jose fmt -j- -Og payload -SyOg keys -AUo- <<< "$jws")"; then
|
|
|
ef20f4 |
+ echo "Advertisement is malformed!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+### Check advertisement validity
|
|
|
ef20f4 |
+ver="$(jose jwk use -i- -r -u verify -o- <<< "$TANG_KEYS")"
|
|
|
ef20f4 |
+if ! jose jws ver -i "$jws" -k- -a <<< "$ver"; then
|
|
|
ef20f4 |
+ echo "Advertisement is missing signatures!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+if ! LUKS_KEYS="$(jose fmt -j- -g adv -o- <<< "$CONTENT")" || [ -z "$LUKS_KEYS" ]; then
|
|
|
ef20f4 |
+ echo "LUKS keys from LUKS metadata were not found!" >&2
|
|
|
ef20f4 |
+ exit 1
|
|
|
ef20f4 |
+fi
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+EXE="$(findexe clevis-luks-report-compare)"
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+exec "$EXE" "$TANG_KEYS" "$LUKS_KEYS"
|
|
|
ef20f4 |
diff --git a/src/luks/clevis-luks-report.1.adoc b/src/luks/clevis-luks-report.1.adoc
|
|
|
ef20f4 |
new file mode 100644
|
|
|
ef20f4 |
index 0000000..cf42afe
|
|
|
ef20f4 |
--- /dev/null
|
|
|
ef20f4 |
+++ b/src/luks/clevis-luks-report.1.adoc
|
|
|
ef20f4 |
@@ -0,0 +1,41 @@
|
|
|
ef20f4 |
+CLEVIS-LUKS-REPORT(1)
|
|
|
ef20f4 |
+=====================
|
|
|
ef20f4 |
+:doctype: manpage
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== NAME
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+clevis-luks-report - Reports whether a pin bound to a LUKS1 or LUKS2 volume has been rotated
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== SYNOPSIS
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+*clevis luks report* -d DEV -s SLT
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== OVERVIEW
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+The *clevis luks report* command checks a given slot of a LUKS device and reports whether the pin bound to it
|
|
|
ef20f4 |
+-- if any -- has been rotated.
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== OPTIONS
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+* *-d* _DEV_ :
|
|
|
ef20f4 |
+ The bound LUKS device
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+* *-s* _SLT_ :
|
|
|
ef20f4 |
+ The slot or key slot number for the pin to be verified
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+* *-q* :
|
|
|
ef20f4 |
+ Quiet mode. If used, we will not prompt whether to regenerate data with *clevis luks regen*
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+* *-r* :
|
|
|
ef20f4 |
+ Regenerates LUKS metadata with *clevis luks regen -d DEV -s SLOT*
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== EXAMPLE
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ Check whether the pin bound to slot 1 in /dev/sda1 has been rotated:
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ # clevis luks report -d /dev/sda1 -s 1
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+== SEE ALSO
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+link:clevis-luks-regen.1.adoc[*clevis-luks-regen*(1)]
|
|
|
ef20f4 |
diff --git a/src/luks/meson.build b/src/luks/meson.build
|
|
|
ef20f4 |
index 1f64ab0..7c045c4 100644
|
|
|
ef20f4 |
--- a/src/luks/meson.build
|
|
|
ef20f4 |
+++ b/src/luks/meson.build
|
|
|
ef20f4 |
@@ -15,6 +15,18 @@ if libcryptsetup.found() and luksmeta.found() and pwmake.found()
|
|
|
ef20f4 |
bins += join_paths(meson.current_source_dir(), 'clevis-luks-bind')
|
|
|
ef20f4 |
mans += join_paths(meson.current_source_dir(), 'clevis-luks-bind.1')
|
|
|
ef20f4 |
|
|
|
ef20f4 |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-common-functions')
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-regen')
|
|
|
ef20f4 |
+ mans += join_paths(meson.current_source_dir(), 'clevis-luks-regen.1')
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-report')
|
|
|
ef20f4 |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-report-compare')
|
|
|
ef20f4 |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-report-decode')
|
|
|
ef20f4 |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-report-sss')
|
|
|
ef20f4 |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-report-tang')
|
|
|
ef20f4 |
+ mans += join_paths(meson.current_source_dir(), 'clevis-luks-report.1')
|
|
|
ef20f4 |
+
|
|
|
ef20f4 |
mans += join_paths(meson.current_source_dir(), 'clevis-luks-unlockers.7')
|
|
|
ef20f4 |
else
|
|
|
ef20f4 |
warning('Will not install LUKS support due to missing dependencies!')
|
|
|
ef20f4 |
--
|
|
|
ef20f4 |
2.21.0
|
|
|
ef20f4 |
|