|
Harald Hoyer |
3763a8 |
From 2a1723ed83accdcb6871e12c722c03dac35dc35e Mon Sep 17 00:00:00 2001
|
|
Harald Hoyer |
3763a8 |
From: Moritz Maxeiner <moritz@ucworks.org>
|
|
Harald Hoyer |
3763a8 |
Date: Fri, 10 Jul 2015 15:38:59 +0200
|
|
Harald Hoyer |
3763a8 |
Subject: [PATCH] crypt-gpg: For GnuPG >= 2.1 support OpenPGP smartcards
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
---
|
|
Harald Hoyer |
3763a8 |
modules.d/91crypt-gpg/crypt-gpg-lib.sh | 34 ++++++++++++++++++++++++++++++++--
|
|
Harald Hoyer |
3763a8 |
modules.d/91crypt-gpg/module-setup.sh | 17 +++++++++++++++++
|
|
Harald Hoyer |
3763a8 |
2 files changed, 49 insertions(+), 2 deletions(-)
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
diff --git a/modules.d/91crypt-gpg/crypt-gpg-lib.sh b/modules.d/91crypt-gpg/crypt-gpg-lib.sh
|
|
Harald Hoyer |
3763a8 |
index 5c7ea855..b85ed2b8 100755
|
|
Harald Hoyer |
3763a8 |
--- a/modules.d/91crypt-gpg/crypt-gpg-lib.sh
|
|
Harald Hoyer |
3763a8 |
+++ b/modules.d/91crypt-gpg/crypt-gpg-lib.sh
|
|
Harald Hoyer |
3763a8 |
@@ -4,7 +4,7 @@ command -v ask_for_password >/dev/null || . /lib/dracut-crypt-lib.sh
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
# gpg_decrypt mnt_point keypath keydev device
|
|
Harald Hoyer |
3763a8 |
#
|
|
Harald Hoyer |
3763a8 |
-# Decrypts encrypted symmetrically key to standard output.
|
|
Harald Hoyer |
3763a8 |
+# Decrypts symmetrically encrypted (password or OpenPGP smartcard) key to standard output.
|
|
Harald Hoyer |
3763a8 |
#
|
|
Harald Hoyer |
3763a8 |
# mnt_point - mount point where <keydev> is already mounted
|
|
Harald Hoyer |
3763a8 |
# keypath - GPG encrypted key path relative to <mnt_point>
|
|
Harald Hoyer |
3763a8 |
@@ -22,10 +22,40 @@ gpg_decrypt() {
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
mkdir -m 0700 -p "$gpghome"
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
+ # Setup GnuPG home and gpg-agent for usage of OpenPGP smartcard.
|
|
Harald Hoyer |
3763a8 |
+ # This requires GnuPG >= 2.1, as it uses the new ,,pinentry-mode´´
|
|
Harald Hoyer |
3763a8 |
+ # feature, which - when set to ,,loopback´´ - allows us to pipe
|
|
Harald Hoyer |
3763a8 |
+ # the smartcard's pin to GnuPG (instead of using a normal pinentry
|
|
Harald Hoyer |
3763a8 |
+ # program needed with GnuPG < 2.1), making for uncomplicated
|
|
Harald Hoyer |
3763a8 |
+ # integration with the existing codebase.
|
|
Harald Hoyer |
3763a8 |
+ local useSmartcard="0"
|
|
Harald Hoyer |
3763a8 |
+ local gpgMajorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* ([0-9]*).*|\1|p')"
|
|
Harald Hoyer |
3763a8 |
+ local gpgMinorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* [0-9]*\.([0-9]*).*|\1|p')"
|
|
Harald Hoyer |
3763a8 |
+
|
|
Harald Hoyer |
3763a8 |
+ if [ "${gpgMajorVersion}" -ge 2 ] && [ "${gpgMinorVersion}" -ge 1 ] \
|
|
Harald Hoyer |
3763a8 |
+ && [ -f /root/crypt-public-key.gpg ] && getargbool 1 rd.luks.smartcard ; then
|
|
Harald Hoyer |
3763a8 |
+ useSmartcard="1"
|
|
Harald Hoyer |
3763a8 |
+ echo "allow-loopback-pinentry" >> "$gpghome/gpg-agent.conf"
|
|
Harald Hoyer |
3763a8 |
+ GNUPGHOME="$gpghome" gpg-agent --quiet --daemon
|
|
Harald Hoyer |
3763a8 |
+ GNUPGHOME="$gpghome" gpg --quiet --no-tty --import < /root/crypt-public-key.gpg
|
|
Harald Hoyer |
3763a8 |
+ local smartcardSerialNumber="$(GNUPGHOME=$gpghome gpg --no-tty --card-status \
|
|
Harald Hoyer |
3763a8 |
+ | sed -n -r -e 's|Serial number.*: ([0-9]*)|\1|p' | tr -d '\n')"
|
|
Harald Hoyer |
3763a8 |
+ if [ -n "${smartcardSerialNumber}" ]; then
|
|
Harald Hoyer |
3763a8 |
+ inputPrompt="PIN (OpenPGP card ${smartcardSerialNumber})"
|
|
Harald Hoyer |
3763a8 |
+ fi
|
|
Harald Hoyer |
3763a8 |
+ GNUPGHOME="$gpghome" gpg-connect-agent 1>/dev/null learn /bye
|
|
Harald Hoyer |
3763a8 |
+ opts="$opts --pinentry-mode=loopback"
|
|
Harald Hoyer |
3763a8 |
+ fi
|
|
Harald Hoyer |
3763a8 |
+
|
|
Harald Hoyer |
3763a8 |
ask_for_password \
|
|
Harald Hoyer |
3763a8 |
--cmd "gpg $opts --decrypt $mntp/$keypath" \
|
|
Harald Hoyer |
3763a8 |
- --prompt "Password ($keypath on $keydev for $device)" \
|
|
Harald Hoyer |
3763a8 |
+ --prompt "${inputPrompt:-Password ($keypath on $keydev for $device)}" \
|
|
Harald Hoyer |
3763a8 |
--tries 3 --tty-echo-off
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
+ # Clean up the smartcard gpg-agent
|
|
Harald Hoyer |
3763a8 |
+ if [ "${useSmartcard}" == "1" ]; then
|
|
Harald Hoyer |
3763a8 |
+ GNUPGHOME="$gpghome" gpg-connect-agent 1>/dev/null killagent /bye
|
|
Harald Hoyer |
3763a8 |
+ fi
|
|
Harald Hoyer |
3763a8 |
+
|
|
Harald Hoyer |
3763a8 |
rm -rf -- "$gpghome"
|
|
Harald Hoyer |
3763a8 |
}
|
|
Harald Hoyer |
3763a8 |
diff --git a/modules.d/91crypt-gpg/module-setup.sh b/modules.d/91crypt-gpg/module-setup.sh
|
|
Harald Hoyer |
3763a8 |
index d328c04c..1323a181 100755
|
|
Harald Hoyer |
3763a8 |
--- a/modules.d/91crypt-gpg/module-setup.sh
|
|
Harald Hoyer |
3763a8 |
+++ b/modules.d/91crypt-gpg/module-setup.sh
|
|
Harald Hoyer |
3763a8 |
@@ -5,6 +5,12 @@
|
|
Harald Hoyer |
3763a8 |
check() {
|
|
Harald Hoyer |
3763a8 |
require_binaries gpg || return 1
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
+ if [ -f "${initdir}/root/crypt-public-key.gpg" ]; then
|
|
Harald Hoyer |
3763a8 |
+ require_binaries gpg-agent || return 1
|
|
Harald Hoyer |
3763a8 |
+ require_binaries gpg-connect-agent || return 1
|
|
Harald Hoyer |
3763a8 |
+ require_binaries /usr/libexec/scdaemon || return 1
|
|
Harald Hoyer |
3763a8 |
+ fi
|
|
Harald Hoyer |
3763a8 |
+
|
|
Harald Hoyer |
3763a8 |
return 255
|
|
Harald Hoyer |
3763a8 |
}
|
|
Harald Hoyer |
3763a8 |
|
|
Harald Hoyer |
3763a8 |
@@ -17,4 +23,15 @@ depends() {
|
|
Harald Hoyer |
3763a8 |
install() {
|
|
Harald Hoyer |
3763a8 |
inst_multiple gpg
|
|
Harald Hoyer |
3763a8 |
inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
|
|
Harald Hoyer |
3763a8 |
+
|
|
Harald Hoyer |
3763a8 |
+ local gpgMajorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* ([0-9]*).*|\1|p')"
|
|
Harald Hoyer |
3763a8 |
+ local gpgMinorVersion="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* [0-9]*\.([0-9]*).*|\1|p')"
|
|
Harald Hoyer |
3763a8 |
+ if [ "${gpgMajorVersion}" -ge 2 ] && [ "${gpgMinorVersion}" -ge 1 ] && [ -f /etc/dracut.conf.d/crypt-public-key.gpg ]; then
|
|
Harald Hoyer |
3763a8 |
+ inst_multiple gpg-agent
|
|
Harald Hoyer |
3763a8 |
+ inst_multiple gpg-connect-agent
|
|
Harald Hoyer |
3763a8 |
+ inst_multiple /usr/libexec/scdaemon || derror "crypt-gpg: gnugpg with scdaemon required for smartcard support in the initramfs"
|
|
Harald Hoyer |
3763a8 |
+ cp "/etc/dracut.conf.d/crypt-public-key.gpg" "${initdir}/root/"
|
|
Harald Hoyer |
3763a8 |
+ elif [ -f /etc/dracut.conf.d/crypt-public-key.gpg ]; then
|
|
Harald Hoyer |
3763a8 |
+ dwarning "crypt-gpg: gnupg >= 2.1 required for smartcard support in the initramfs"
|
|
Harald Hoyer |
3763a8 |
+ fi
|
|
Harald Hoyer |
3763a8 |
}
|