|
|
fbd758 |
From aa52396c35e76aabd085a819b08167d559042a20 Mon Sep 17 00:00:00 2001
|
|
|
fbd758 |
From: rpm-build <rpm-build>
|
|
|
fbd758 |
Date: Tue, 3 Nov 2020 08:42:48 -0300
|
|
|
fbd758 |
Subject: [PATCH 2/2] Add the option to extract luks passphrase used for
|
|
|
95204d |
binding
|
|
|
566fbd |
|
|
|
566fbd |
Usage:
|
|
|
566fbd |
|
|
|
566fbd |
clevis luks pass -d /dev/sda1 -s 1
|
|
|
566fbd |
<passphrase here>
|
|
|
566fbd |
---
|
|
|
fbd758 |
src/luks/clevis-luks-pass | 64 ++++++++++++++++++++++++++++++++
|
|
|
fbd758 |
src/luks/clevis-luks-pass.1.adoc | 43 +++++++++++++++++++++
|
|
|
566fbd |
src/luks/meson.build | 3 ++
|
|
|
fbd758 |
src/luks/tests/meson.build | 2 +
|
|
|
fbd758 |
src/luks/tests/pass-tang-luks1 | 59 +++++++++++++++++++++++++++++
|
|
|
fbd758 |
src/luks/tests/pass-tang-luks2 | 59 +++++++++++++++++++++++++++++
|
|
|
fbd758 |
6 files changed, 230 insertions(+)
|
|
|
566fbd |
create mode 100755 src/luks/clevis-luks-pass
|
|
|
566fbd |
create mode 100644 src/luks/clevis-luks-pass.1.adoc
|
|
|
566fbd |
create mode 100755 src/luks/tests/pass-tang-luks1
|
|
|
566fbd |
create mode 100755 src/luks/tests/pass-tang-luks2
|
|
|
566fbd |
|
|
|
566fbd |
diff --git a/src/luks/clevis-luks-pass b/src/luks/clevis-luks-pass
|
|
|
566fbd |
new file mode 100755
|
|
|
fbd758 |
index 0000000..1f59b39
|
|
|
566fbd |
--- /dev/null
|
|
|
566fbd |
+++ b/src/luks/clevis-luks-pass
|
|
|
fbd758 |
@@ -0,0 +1,64 @@
|
|
|
566fbd |
+#!/bin/bash -e
|
|
|
fbd758 |
+# vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# Copyright (c) 2019 Red Hat, Inc.
|
|
|
566fbd |
+# Author: Sergio Correia <scorreia@redhat.com> - LUKS2 support.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# This program is free software: you can redistribute it and/or modify
|
|
|
566fbd |
+# it under the terms of the GNU General Public License as published by
|
|
|
566fbd |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
566fbd |
+# (at your option) any later version.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# This program is distributed in the hope that it will be useful,
|
|
|
566fbd |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
566fbd |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
566fbd |
+# GNU General Public License for more details.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# You should have received a copy of the GNU General Public License
|
|
|
566fbd |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+
|
|
|
566fbd |
+. clevis-luks-common-functions
|
|
|
566fbd |
+
|
|
|
566fbd |
+SUMMARY="Returns the LUKS passphrase used for binding a particular slot."
|
|
|
566fbd |
+
|
|
|
fbd758 |
+usage() {
|
|
|
fbd758 |
+ exec >&2
|
|
|
fbd758 |
+ echo "Usage: clevis luks pass -d DEV -s SLT"
|
|
|
fbd758 |
+ echo
|
|
|
fbd758 |
+ echo "$SUMMARY"
|
|
|
fbd758 |
+ echo
|
|
|
fbd758 |
+ echo " -d DEV The LUKS device to extract the LUKS passphrase used for binding"
|
|
|
fbd758 |
+ echo
|
|
|
fbd758 |
+ echo " -s SLOT The slot number to extract the LUKS passphrase"
|
|
|
fbd758 |
+ echo
|
|
|
566fbd |
+ exit 1
|
|
|
566fbd |
+}
|
|
|
566fbd |
+
|
|
|
566fbd |
+if [ ${#} -eq 1 ] && [ "${1}" = "--summary" ]; then
|
|
|
566fbd |
+ echo "${SUMMARY}"
|
|
|
566fbd |
+ exit 0
|
|
|
566fbd |
+fi
|
|
|
566fbd |
+
|
|
|
566fbd |
+while getopts ":d:s:" o; do
|
|
|
566fbd |
+ case "$o" in
|
|
|
566fbd |
+ d) DEV=${OPTARG};;
|
|
|
566fbd |
+ s) SLT=${OPTARG};;
|
|
|
566fbd |
+ *) usage;;
|
|
|
566fbd |
+ esac
|
|
|
566fbd |
+done
|
|
|
566fbd |
+
|
|
|
566fbd |
+if [ -z "${DEV}" ]; then
|
|
|
566fbd |
+ echo "Did not specify a device!" >&2
|
|
|
566fbd |
+ usage
|
|
|
566fbd |
+fi
|
|
|
566fbd |
+
|
|
|
566fbd |
+if [ -z "${SLT}" ]; then
|
|
|
566fbd |
+ echo "Did not specify a slot!" >&2
|
|
|
566fbd |
+ usage
|
|
|
566fbd |
+fi
|
|
|
566fbd |
+
|
|
|
fbd758 |
+if ! clevis_luks_unlock_device_by_slot "${DEV}" "${SLT}"; then
|
|
|
fbd758 |
+ echo "It was not possible to decrypt the passphrase associated to slot ${SLT} in ${DEV}!" >&2
|
|
|
566fbd |
+ exit 1
|
|
|
566fbd |
+fi
|
|
|
566fbd |
diff --git a/src/luks/clevis-luks-pass.1.adoc b/src/luks/clevis-luks-pass.1.adoc
|
|
|
566fbd |
new file mode 100644
|
|
|
566fbd |
index 0000000..fa9526a
|
|
|
566fbd |
--- /dev/null
|
|
|
566fbd |
+++ b/src/luks/clevis-luks-pass.1.adoc
|
|
|
566fbd |
@@ -0,0 +1,43 @@
|
|
|
566fbd |
+CLEVIS-LUKS-PASS(1)
|
|
|
566fbd |
+===================
|
|
|
566fbd |
+:doctype: manpage
|
|
|
566fbd |
+
|
|
|
566fbd |
+
|
|
|
566fbd |
+== NAME
|
|
|
566fbd |
+
|
|
|
566fbd |
+clevis-luks-pass - Extracts the passphrase used for binding a particular slot in a LUKS device
|
|
|
566fbd |
+
|
|
|
566fbd |
+== SYNOPSIS
|
|
|
566fbd |
+
|
|
|
566fbd |
+*clevis luks pass* -d DEV -s SLT
|
|
|
566fbd |
+
|
|
|
566fbd |
+== OVERVIEW
|
|
|
566fbd |
+
|
|
|
566fbd |
+The *clevis luks pass* command extracts the passphrase used for binding a particular slot in a LUKS device.
|
|
|
566fbd |
+For example:
|
|
|
566fbd |
+
|
|
|
566fbd |
+ clevis luks pass -d /dev/sda1 -s 1
|
|
|
566fbd |
+
|
|
|
566fbd |
+== OPTIONS
|
|
|
566fbd |
+
|
|
|
566fbd |
+* *-d* _DEV_ :
|
|
|
566fbd |
+ The LUKS device on which to extract a passphrase from
|
|
|
566fbd |
+
|
|
|
566fbd |
+* *-s* _SLT_ :
|
|
|
566fbd |
+ The slot to use for extracting the passphrase
|
|
|
566fbd |
+
|
|
|
566fbd |
+== EXAMPLE
|
|
|
566fbd |
+
|
|
|
566fbd |
+ clevis luks pass -d /dev/sda1 -s 1
|
|
|
566fbd |
+ <passphrase here>
|
|
|
566fbd |
+
|
|
|
566fbd |
+Note that the output of *clevis luks pass* might be non-printable, in which case it would be better to redirect its output to a file and use it as a key
|
|
|
566fbd |
+file together with cryptsetup. For instance:
|
|
|
566fbd |
+
|
|
|
566fbd |
+ clevis luks pass -d /dev/sda1 -s 1 > slot1-passphrase
|
|
|
566fbd |
+
|
|
|
566fbd |
+And the file slot1-passphrase will contain the passphrase associated with slot #1 in /dev/sda1.
|
|
|
566fbd |
+
|
|
|
566fbd |
+== SEE ALSO
|
|
|
566fbd |
+
|
|
|
566fbd |
+link:clevis-luks-unlock.1.adoc[*clevis-luks-unlock*(1)],
|
|
|
566fbd |
diff --git a/src/luks/meson.build b/src/luks/meson.build
|
|
|
fbd758 |
index 12f5a0d..008736e 100644
|
|
|
566fbd |
--- a/src/luks/meson.build
|
|
|
566fbd |
+++ b/src/luks/meson.build
|
|
|
fbd758 |
@@ -50,6 +50,9 @@ if libcryptsetup.found() and luksmeta.found() and pwmake.found()
|
|
|
566fbd |
|
|
|
fbd758 |
bins += join_paths(meson.current_source_dir(), 'clevis-luks-edit')
|
|
|
fbd758 |
mans += join_paths(meson.current_source_dir(), 'clevis-luks-edit.1')
|
|
|
95204d |
+
|
|
|
566fbd |
+ bins += join_paths(meson.current_source_dir(), 'clevis-luks-pass')
|
|
|
566fbd |
+ mans += join_paths(meson.current_source_dir(), 'clevis-luks-pass.1')
|
|
|
95204d |
else
|
|
|
95204d |
warning('Will not install LUKS support due to missing dependencies!')
|
|
|
95204d |
endif
|
|
|
566fbd |
diff --git a/src/luks/tests/meson.build b/src/luks/tests/meson.build
|
|
|
fbd758 |
index c22a069..f4584aa 100644
|
|
|
566fbd |
--- a/src/luks/tests/meson.build
|
|
|
566fbd |
+++ b/src/luks/tests/meson.build
|
|
|
fbd758 |
@@ -84,6 +84,7 @@ if has_tang
|
|
|
fbd758 |
test('report-tang-luks1', find_program('report-tang-luks1'), env: env, timeout: 90)
|
|
|
fbd758 |
test('report-sss-luks1', find_program('report-sss-luks1'), env: env, timeout: 90)
|
|
|
fbd758 |
test('edit-tang-luks1', find_program('edit-tang-luks1'), env: env, timeout: 150)
|
|
|
fbd758 |
+ test('pass-tang-luks1', find_program('pass-tang-luks1'), env: env, timeout: 60)
|
|
|
566fbd |
endif
|
|
|
566fbd |
|
|
|
fbd758 |
test('backup-restore-luks1', find_program('backup-restore-luks1'), env: env, timeout: 60)
|
|
|
fbd758 |
@@ -111,6 +112,7 @@ if luksmeta_data.get('OLD_CRYPTSETUP') == '0'
|
|
|
fbd758 |
test('report-tang-luks2', find_program('report-tang-luks2'), env: env, timeout: 120)
|
|
|
fbd758 |
test('report-sss-luks2', find_program('report-sss-luks2'), env: env, timeout: 120)
|
|
|
fbd758 |
test('edit-tang-luks2', find_program('edit-tang-luks2'), env: env, timeout: 210)
|
|
|
fbd758 |
+ test('pass-tang-luks2', find_program('pass-tang-luks2'), env: env, timeout: 60)
|
|
|
95204d |
endif
|
|
|
fbd758 |
|
|
|
fbd758 |
test('backup-restore-luks2', find_program('backup-restore-luks2'), env: env, timeout: 120)
|
|
|
566fbd |
diff --git a/src/luks/tests/pass-tang-luks1 b/src/luks/tests/pass-tang-luks1
|
|
|
566fbd |
new file mode 100755
|
|
|
fbd758 |
index 0000000..0d91e6c
|
|
|
566fbd |
--- /dev/null
|
|
|
566fbd |
+++ b/src/luks/tests/pass-tang-luks1
|
|
|
fbd758 |
@@ -0,0 +1,59 @@
|
|
|
566fbd |
+#!/bin/bash -x
|
|
|
566fbd |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# Copyright (c) 2019 Red Hat, Inc.
|
|
|
566fbd |
+# Author: Sergio Correia <scorreia@redhat.com>
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# This program is free software: you can redistribute it and/or modify
|
|
|
566fbd |
+# it under the terms of the GNU General Public License as published by
|
|
|
566fbd |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
566fbd |
+# (at your option) any later version.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# This program is distributed in the hope that it will be useful,
|
|
|
566fbd |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
566fbd |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
566fbd |
+# GNU General Public License for more details.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# You should have received a copy of the GNU General Public License
|
|
|
566fbd |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+
|
|
|
566fbd |
+TEST="${0}"
|
|
|
566fbd |
+. tests-common-functions
|
|
|
fbd758 |
+. clevis-luks-common-functions
|
|
|
566fbd |
+
|
|
|
566fbd |
+function on_exit() {
|
|
|
fbd758 |
+ [ ! -d "${TMP}" ] && return 0
|
|
|
fbd758 |
+ tang_stop "${TMP}"
|
|
|
fbd758 |
+ rm -rf "${TMP}"
|
|
|
566fbd |
+}
|
|
|
566fbd |
+
|
|
|
566fbd |
+trap 'on_exit' EXIT
|
|
|
566fbd |
+
|
|
|
fbd758 |
+TMP=$(mktemp -d)
|
|
|
fbd758 |
+
|
|
|
fbd758 |
+port=$(get_random_port)
|
|
|
fbd758 |
+tang_run "${TMP}" "${port}" &
|
|
|
fbd758 |
+tang_wait_until_ready "${port}"
|
|
|
566fbd |
+
|
|
|
566fbd |
+url="http://localhost:${port}"
|
|
|
566fbd |
+adv="${TMP}/adv"
|
|
|
fbd758 |
+tang_get_adv "${port}" "${adv}"
|
|
|
566fbd |
+
|
|
|
566fbd |
+cfg=$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")
|
|
|
566fbd |
+
|
|
|
566fbd |
+# LUKS1.
|
|
|
566fbd |
+DEV="${TMP}/luks1-device"
|
|
|
566fbd |
+new_device "luks1" "${DEV}"
|
|
|
566fbd |
+
|
|
|
566fbd |
+if ! clevis luks bind -f -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
|
|
|
566fbd |
+ error "${TEST}: Bind should have succeeded."
|
|
|
566fbd |
+fi
|
|
|
566fbd |
+
|
|
|
fbd758 |
+# Now let's test the passphrase.
|
|
|
566fbd |
+SLT=1
|
|
|
566fbd |
+PASS=$(clevis luks pass -d "${DEV}" -s "${SLT}")
|
|
|
566fbd |
+echo $PASS >&2
|
|
|
fbd758 |
+if ! clevis_luks_check_valid_key_or_keyfile "${DEV}" "${PASS}" "" "${SLT}"; then
|
|
|
566fbd |
+ error "Passphrase obtained from clevis luks pass failed."
|
|
|
566fbd |
+fi
|
|
|
566fbd |
diff --git a/src/luks/tests/pass-tang-luks2 b/src/luks/tests/pass-tang-luks2
|
|
|
566fbd |
new file mode 100755
|
|
|
fbd758 |
index 0000000..2d50413
|
|
|
566fbd |
--- /dev/null
|
|
|
566fbd |
+++ b/src/luks/tests/pass-tang-luks2
|
|
|
fbd758 |
@@ -0,0 +1,59 @@
|
|
|
566fbd |
+#!/bin/bash -x
|
|
|
566fbd |
+# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# Copyright (c) 2019 Red Hat, Inc.
|
|
|
566fbd |
+# Author: Sergio Correia <scorreia@redhat.com>
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# This program is free software: you can redistribute it and/or modify
|
|
|
566fbd |
+# it under the terms of the GNU General Public License as published by
|
|
|
566fbd |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
566fbd |
+# (at your option) any later version.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# This program is distributed in the hope that it will be useful,
|
|
|
566fbd |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
566fbd |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
566fbd |
+# GNU General Public License for more details.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+# You should have received a copy of the GNU General Public License
|
|
|
566fbd |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
566fbd |
+#
|
|
|
566fbd |
+
|
|
|
566fbd |
+TEST="${0}"
|
|
|
566fbd |
+. tests-common-functions
|
|
|
fbd758 |
+. clevis-luks-common-functions
|
|
|
566fbd |
+
|
|
|
566fbd |
+function on_exit() {
|
|
|
fbd758 |
+ [ ! -d "${TMP}" ] && return 0
|
|
|
fbd758 |
+ tang_stop "${TMP}"
|
|
|
fbd758 |
+ rm -rf "${TMP}"
|
|
|
566fbd |
+}
|
|
|
566fbd |
+
|
|
|
566fbd |
+trap 'on_exit' EXIT
|
|
|
566fbd |
+
|
|
|
fbd758 |
+TMP=$(mktemp -d)
|
|
|
fbd758 |
+
|
|
|
fbd758 |
+port=$(get_random_port)
|
|
|
fbd758 |
+tang_run "${TMP}" "${port}" &
|
|
|
fbd758 |
+tang_wait_until_ready "${port}"
|
|
|
566fbd |
+
|
|
|
566fbd |
+url="http://localhost:${port}"
|
|
|
566fbd |
+adv="${TMP}/adv"
|
|
|
fbd758 |
+tang_get_adv "${port}" "${adv}"
|
|
|
566fbd |
+
|
|
|
566fbd |
+cfg=$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")
|
|
|
566fbd |
+
|
|
|
566fbd |
+# LUKS2.
|
|
|
566fbd |
+DEV="${TMP}/luks2-device"
|
|
|
566fbd |
+new_device "luks2" "${DEV}"
|
|
|
566fbd |
+
|
|
|
566fbd |
+if ! clevis luks bind -f -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
|
|
|
566fbd |
+ error "${TEST}: Bind should have succeeded."
|
|
|
566fbd |
+fi
|
|
|
566fbd |
+
|
|
|
fbd758 |
+# Now let's test the passphrase.
|
|
|
566fbd |
+SLT=1
|
|
|
566fbd |
+PASS=$(clevis luks pass -d "${DEV}" -s "${SLT}")
|
|
|
566fbd |
+echo $PASS >&2
|
|
|
fbd758 |
+if ! clevis_luks_check_valid_key_or_keyfile "${DEV}" "${PASS}" "" "${SLT}"; then
|
|
|
566fbd |
+ error "Passphrase obtained from clevis luks pass failed."
|
|
|
566fbd |
+fi
|
|
|
566fbd |
--
|
|
|
fbd758 |
2.29.2
|
|
|
566fbd |
|