| 1 |
#!/bin/bash -e |
| 2 |
# vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: |
| 3 |
# |
| 4 |
# Copyright (c) 2019 Red Hat, Inc. |
| 5 |
# Author: Sergio Correia <[email protected]> |
| 6 |
# |
| 7 |
# This program is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# This program is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
|
| 21 |
. clevis-luks-common-functions |
| 22 |
|
| 23 |
SUMMARY="Returns the LUKS passphrase used for binding a particular slot." |
| 24 |
|
| 25 |
usage() { |
| 26 |
exec >&2 |
| 27 |
echo "Usage: clevis luks pass -d DEV -s SLT" |
| 28 |
echo |
| 29 |
echo "$SUMMARY" |
| 30 |
echo |
| 31 |
echo " -d DEV The LUKS device to extract the LUKS passphrase used for binding" |
| 32 |
echo |
| 33 |
echo " -s SLOT The slot number to extract the LUKS passphrase" |
| 34 |
echo |
| 35 |
exit 1 |
| 36 |
} |
| 37 |
|
| 38 |
if [ ${#} -eq 1 ] && [ "${1}" = "--summary" ]; then |
| 39 |
echo "${SUMMARY}" |
| 40 |
exit 0 |
| 41 |
fi |
| 42 |
|
| 43 |
while getopts ":d:s:" o; do |
| 44 |
case "$o" in |
| 45 |
d) DEV=${OPTARG};; |
| 46 |
s) SLT=${OPTARG};; |
| 47 |
*) usage;; |
| 48 |
esac |
| 49 |
done |
| 50 |
|
| 51 |
if [ -z "${DEV}" ]; then |
| 52 |
echo "Did not specify a device!" >&2 |
| 53 |
usage |
| 54 |
fi |
| 55 |
|
| 56 |
if [ -z "${SLT}" ]; then |
| 57 |
echo "Did not specify a slot!" >&2 |
| 58 |
usage |
| 59 |
fi |
| 60 |
|
| 61 |
if ! clevis_luks_unlock_device_by_slot "${DEV}" "${SLT}"; then |
| 62 |
echo "It was not possible to decrypt the passphrase associated to slot ${SLT} in ${DEV}!" >&2 |
| 63 |
exit 1 |
| 64 |
fi |