crypt-gpg: For GnuPG >= 2.1 support OpenPGP smartcards
parent
bd4aa25741
commit
2a1723ed83
|
@ -4,7 +4,7 @@ command -v ask_for_password >/dev/null || . /lib/dracut-crypt-lib.sh
|
||||||
|
|
||||||
# gpg_decrypt mnt_point keypath keydev device
|
# gpg_decrypt mnt_point keypath keydev device
|
||||||
#
|
#
|
||||||
# Decrypts encrypted symmetrically key to standard output.
|
# Decrypts symmetrically encrypted (password or OpenPGP smartcard) key to standard output.
|
||||||
#
|
#
|
||||||
# mnt_point - mount point where <keydev> is already mounted
|
# mnt_point - mount point where <keydev> is already mounted
|
||||||
# keypath - GPG encrypted key path relative to <mnt_point>
|
# keypath - GPG encrypted key path relative to <mnt_point>
|
||||||
|
@ -22,10 +22,40 @@ gpg_decrypt() {
|
||||||
|
|
||||||
mkdir -m 0700 -p "$gpghome"
|
mkdir -m 0700 -p "$gpghome"
|
||||||
|
|
||||||
|
# Setup GnuPG home and gpg-agent for usage of OpenPGP smartcard.
|
||||||
|
# This requires GnuPG >= 2.1, as it uses the new ,,pinentry-mode´´
|
||||||
|
# feature, which - when set to ,,loopback´´ - allows us to pipe
|
||||||
|
# the smartcard's pin to GnuPG (instead of using a normal pinentry
|
||||||
|
# program needed with GnuPG < 2.1), making for uncomplicated
|
||||||
|
# integration with the existing codebase.
|
||||||
|
local useSmartcard="0"
|
||||||
|
local gpgMajorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* ([0-9]*).*|\1|p')"
|
||||||
|
local gpgMinorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* [0-9]*\.([0-9]*).*|\1|p')"
|
||||||
|
|
||||||
|
if [ "${gpgMajorVersion}" -ge 2 ] && [ "${gpgMinorVersion}" -ge 1 ] \
|
||||||
|
&& [ -f /root/crypt-public-key.gpg ] && getargbool 1 rd.luks.smartcard ; then
|
||||||
|
useSmartcard="1"
|
||||||
|
echo "allow-loopback-pinentry" >> "$gpghome/gpg-agent.conf"
|
||||||
|
GNUPGHOME="$gpghome" gpg-agent --quiet --daemon
|
||||||
|
GNUPGHOME="$gpghome" gpg --quiet --no-tty --import < /root/crypt-public-key.gpg
|
||||||
|
local smartcardSerialNumber="$(GNUPGHOME=$gpghome gpg --no-tty --card-status \
|
||||||
|
| sed -n -r -e 's|Serial number.*: ([0-9]*)|\1|p' | tr -d '\n')"
|
||||||
|
if [ -n "${smartcardSerialNumber}" ]; then
|
||||||
|
inputPrompt="PIN (OpenPGP card ${smartcardSerialNumber})"
|
||||||
|
fi
|
||||||
|
GNUPGHOME="$gpghome" gpg-connect-agent 1>/dev/null learn /bye
|
||||||
|
opts="$opts --pinentry-mode=loopback"
|
||||||
|
fi
|
||||||
|
|
||||||
ask_for_password \
|
ask_for_password \
|
||||||
--cmd "gpg $opts --decrypt $mntp/$keypath" \
|
--cmd "gpg $opts --decrypt $mntp/$keypath" \
|
||||||
--prompt "Password ($keypath on $keydev for $device)" \
|
--prompt "${inputPrompt:-Password ($keypath on $keydev for $device)}" \
|
||||||
--tries 3 --tty-echo-off
|
--tries 3 --tty-echo-off
|
||||||
|
|
||||||
|
# Clean up the smartcard gpg-agent
|
||||||
|
if [ "${useSmartcard}" == "1" ]; then
|
||||||
|
GNUPGHOME="$gpghome" gpg-connect-agent 1>/dev/null killagent /bye
|
||||||
|
fi
|
||||||
|
|
||||||
rm -rf -- "$gpghome"
|
rm -rf -- "$gpghome"
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,12 @@
|
||||||
check() {
|
check() {
|
||||||
require_binaries gpg || return 1
|
require_binaries gpg || return 1
|
||||||
|
|
||||||
|
if [ -f "${initdir}/root/crypt-public-key.gpg" ]; then
|
||||||
|
require_binaries gpg-agent || return 1
|
||||||
|
require_binaries gpg-connect-agent || return 1
|
||||||
|
require_binaries /usr/libexec/scdaemon || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
return 255
|
return 255
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,4 +23,15 @@ depends() {
|
||||||
install() {
|
install() {
|
||||||
inst_multiple gpg
|
inst_multiple gpg
|
||||||
inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
|
inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
|
||||||
|
|
||||||
|
local gpgMajorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* ([0-9]*).*|\1|p')"
|
||||||
|
local gpgMinorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* [0-9]*\.([0-9]*).*|\1|p')"
|
||||||
|
if [ "${gpgMajorVersion}" -ge 2 ] && [ "${gpgMinorVersion}" -ge 1 ] && [ -f /etc/dracut.conf.d/crypt-public-key.gpg ]; then
|
||||||
|
inst_multiple gpg-agent
|
||||||
|
inst_multiple gpg-connect-agent
|
||||||
|
inst_multiple /usr/libexec/scdaemon || derror "crypt-gpg: gnugpg with scdaemon required for smartcard support in the initramfs"
|
||||||
|
cp "/etc/dracut.conf.d/crypt-public-key.gpg" "${initdir}/root/"
|
||||||
|
elif [ -f /etc/dracut.conf.d/crypt-public-key.gpg ]; then
|
||||||
|
dwarning "crypt-gpg: gnupg >= 2.1 required for smartcard support in the initramfs"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue