Blame 0003-crypt-gpg-Rework-setup-for-CCID-smartcard-support.patch

Harald Hoyer 3763a8
From 0982fcb2e5ae334790851fa8ff7cf65281842ad1 Mon Sep 17 00:00:00 2001
Harald Hoyer 3763a8
From: Moritz Maxeiner <moritz@ucworks.org>
Harald Hoyer 3763a8
Date: Thu, 30 Mar 2017 14:17:05 +0200
Harald Hoyer 3763a8
Subject: [PATCH] crypt-gpg: Rework setup for CCID smartcard support
Harald Hoyer 3763a8
Harald Hoyer 3763a8
---
Harald Hoyer 3763a8
 modules.d/91crypt-gpg/module-setup.sh | 46 ++++++++++++++++++++++++++---------
Harald Hoyer 3763a8
 1 file changed, 35 insertions(+), 11 deletions(-)
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 1323a181..bb34676f 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,10 +5,11 @@
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
+    if sc_requested; then
Harald Hoyer 3763a8
+        if ! sc_supported; then
Harald Hoyer 3763a8
+            dwarning "crypt-gpg: GnuPG >= 2.1 with scdaemon and libusb required for ccid smartcard support"
Harald Hoyer 3763a8
+            return 1
Harald Hoyer 3763a8
+        fi
Harald Hoyer 3763a8
     fi
Harald Hoyer 3763a8
 
Harald Hoyer 3763a8
     return 255
Harald Hoyer 3763a8
@@ -24,14 +25,37 @@ 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
+    if sc_requested; 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
+        inst_multiple /usr/libexec/scdaemon
Harald Hoyer 3763a8
+        cp "$(sc_public_key)" "${initdir}/root/"
Harald Hoyer 3763a8
+    fi
Harald Hoyer 3763a8
+}
Harald Hoyer 3763a8
+
Harald Hoyer 3763a8
+sc_public_key() {
Harald Hoyer 3763a8
+    echo -n "/etc/dracut.conf.d/crypt-public-key.gpg"
Harald Hoyer 3763a8
+}
Harald Hoyer 3763a8
+
Harald Hoyer 3763a8
+# CCID Smartcard support requires GnuPG >= 2.1 with scdaemon and libusb
Harald Hoyer 3763a8
+sc_supported() {
Harald Hoyer 3763a8
+    local gpgMajor="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* ([0-9]*).*|\1|p')"
Harald Hoyer 3763a8
+    local gpgMinor="$(gpg --version | sed -n 1p | sed -n -r -e 's|.* [0-9]*\.([0-9]*).*|\1|p')"
Harald Hoyer 3763a8
+    if [[ "${gpgMajor}" -gt 2 || "${gpgMajor}" -eq 2 && "${gpgMinor}" -ge 1 ]] && \
Harald Hoyer 3763a8
+       require_binaries gpg-agent &&
Harald Hoyer 3763a8
+       require_binaries gpg-connect-agent &&
Harald Hoyer 3763a8
+       require_binaries /usr/libexec/scdaemon &&
Harald Hoyer 3763a8
+       (ldd /usr/libexec/scdaemon | grep libusb > /dev/null); then
Harald Hoyer 3763a8
+        return 0
Harald Hoyer 3763a8
+    else
Harald Hoyer 3763a8
+        return 1
Harald Hoyer 3763a8
+    fi
Harald Hoyer 3763a8
+}
Harald Hoyer 3763a8
+
Harald Hoyer 3763a8
+sc_requested() {
Harald Hoyer 3763a8
+    if [ -f "$(sc_public_key)" ]; then
Harald Hoyer 3763a8
+        return 0
Harald Hoyer 3763a8
+    else
Harald Hoyer 3763a8
+        return 1
Harald Hoyer 3763a8
     fi
Harald Hoyer 3763a8
 }