Subject: [alpine-aports] [PATCH] main/gnupg: Enabled smartcard support as subpackage

From: Marian Buschsieweke <[email-masked]>
Date: Sat, 7 Apr 2018 17:32:47 +0200

- Added gnupg-scdaemon as subpackage
- Enabled internal CCID driver (support for Gnuk, NitroKey, YubiKey, ...)
- Added 60-scdaemon.rules udev rules to provide access to group gnupg
- Added pre-install for subpackage to create group gnupg

This feature was requested here: https://bugs.alpinelinux.org/issues/8621
---
 main/gnupg/60-scdaemon.rules          | 63 +++++++++++++++++++++++++++
 main/gnupg/APKBUILD                   | 30 ++++++++++---
 main/gnupg/gnupg-scdaemon.pre-install |  2 +
 3 files changed, 89 insertions(+), 6 deletions(-)
 create mode 100644 main/gnupg/60-scdaemon.rules
 create mode 100644 main/gnupg/gnupg-scdaemon.pre-install

diff --git a/main/gnupg/60-scdaemon.rules b/main/gnupg/60-scdaemon.rules
new file mode 100644
index 0000000000..55ca5c1663
--- /dev/null
+++ b/main/gnupg/60-scdaemon.rules
@@ -0,0 +1,63 @@
+# do not edit this file, it will be overwritten on update
+
+SUBSYSTEM!="usb", GOTO="gnupg_rules_end"
+ACTION!="add", GOTO="gnupg_rules_end"
+
+# USB SmartCard Readers
+## Cherry GmbH (XX33, ST2000)
+ATTR{idVendor}=="046a", ATTR{idProduct}=="0005", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="046a", ATTR{idProduct}=="0010", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="046a", ATTR{idProduct}=="003e", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## SCM Microsystems, Inc (SCR331-DI, SCR335, SCR3320, SCR331, SCR3310 and SPR532)
+ATTR{idVendor}=="04e6", ATTR{idProduct}=="5111", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="04e6", ATTR{idProduct}=="5115", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="04e6", ATTR{idProduct}=="5116", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="04e6", ATTR{idProduct}=="5117", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="04e6", ATTR{idProduct}=="e001", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="04e6", ATTR{idProduct}=="e003", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Omnikey AG (CardMan 3821, CardMan 6121)
+ATTR{idVendor}=="076b", ATTR{idProduct}=="3821", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="076b", ATTR{idProduct}=="6622", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Gemalto
+ATTR{idVendor}=="08e6", ATTR{idProduct}=="3437", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="08e6", ATTR{idProduct}=="3438", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="08e6", ATTR{idProduct}=="3478", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="08e6", ATTR{idProduct}=="34c2", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="08e6", ATTR{idProduct}=="34ec", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Reiner (SCT cyberJack)
+ATTR{idVendor}=="0c4b", ATTR{idProduct}=="0500", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Kobil (KAAN)
+ATTR{idVendor}=="0d46", ATTR{idProduct}=="2012", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## VASCO (DIGIPASS 920)
+ATTR{idVendor}=="1a44", ATTR{idProduct}=="0920", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Crypto Stick
+ATTR{idVendor}=="20a0", ATTR{idProduct}=="4107", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Nitrokey
+ATTR{idVendor}=="20a0", ATTR{idProduct}=="4108", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="20a0", ATTR{idProduct}=="4109", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+ATTR{idVendor}=="20a0", ATTR{idProduct}=="4211", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Gnuk Token
+ATTR{idVendor}=="234b", ATTR{idProduct}=="0000", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Alcor Micro Corp cardreader (in ThinkPad X250)
+ATTR{idVendor}=="058f", ATTR{idProduct}=="9540", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Fujitsu Siemens
+ATTR{idVendor}=="0bf8", ATTR{idProduct}=="1006", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+## Yubico
+# Yubikey NEO OTP+CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0111", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+# Yubikey NEO CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0112", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+# Yubikey NEO U2F+CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0115", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+# Yubikey NEO OTP+U2F+CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0116", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+# Yubikey 4 CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0404", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+# Yubikey 4 OTP+CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0405", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+# Yubikey 4 U2F+CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0406", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+# Yubikey 4 OTP+U2F+CCID
+ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0407", ENV{ID_SMARTCARD_READER}="1", ENV{ID_SMARTCARD_READER_DRIVER}="gnupg", GROUP+="gnupg"
+
+LABEL="gnupg_rules_end"
diff --git a/main/gnupg/APKBUILD b/main/gnupg/APKBUILD
index 666cd0a275..05a05bec42 100644
--- a/main/gnupg/APKBUILD
+++ b/main/gnupg/APKBUILD
@@ -3,7 +3,7 @@
 pkgname=gnupg
 pkgver=2.2.5
 _ver=${pkgver/_beta/-beta}
-pkgrel=0
+pkgrel=1
 pkgdesc="GNU Privacy Guard 2 - a PGP replacement tool"
 url="https://www.gnupg.org/"
 arch="all"
@@ -12,11 +12,13 @@ options=""
 depends="pinentry"
 makedepends="gnutls-dev libksba-dev libgcrypt-dev libgpg-error-dev
 	npth-dev zlib-dev libassuan-dev openldap-dev bzip2-dev
-	sqlite-dev"
-subpackages="$pkgname-doc"
+	sqlite-dev libusb-dev"
+subpackages="$pkgname-doc $pkgname-scdaemon"
 source="https://gnupg.org/ftp/gcrypt/$pkgname/$pkgname-$_ver.tar.bz2
 	0001-Include-sys-select.h-for-FD_SETSIZE.patch
-	fix-i18n.patch"
+	fix-i18n.patch
+	60-scdaemon.rules"
+install="$pkgname-scdaemon.pre-install"
 builddir="$srcdir"/$pkgname-$_ver
 
 build() {
@@ -31,7 +33,9 @@ build() {
 		--localstatedir=/var \
 		--disable-nls \
 		--enable-bzip2 \
-		--enable-tofu
+		--enable-tofu \
+		--enable-scdaemon \
+		--enable-ccid-driver
 	make
 }
 
@@ -49,6 +53,20 @@ package() {
 	ln -s gpgv "$pkgdir"/usr/bin/gpgv2
 }
 
+scdaemon() {
+	pkgdesc="GNU Privacy Guard 2 - smart card support"
+	depends="gnupg"
+
+	mkdir -p "${subpkgdir}/usr/libexec"
+	mkdir -p "${subpkgdir}/lib/udev/rules.d"
+
+	install -Dm644 -t "${subpkgdir}/lib/udev/rules.d/" \
+		"${srcdir}/60-scdaemon.rules"
+	mv "${pkgdir}/usr/libexec/scdaemon" "${subpkgdir}/usr/libexec/"
+
+}
+
 sha512sums="675d2acc2ba95d14b14f4c83364663d88c982332fb4c35a4cf32af19a6bd4453ad89905c80d45007adb50c01816247df84d1f525e94bb668b962a84815e49bf1  gnupg-2.2.5.tar.bz2
 c6cc4595081c5b025913fa3ebecf0dff87a84f3c669e3fef106e4fa040f1d4314ee52dd4c0e0002b213034fb0810221cfdd0033eae5349b6e3978f05d08bcac7  0001-Include-sys-select.h-for-FD_SETSIZE.patch
-b19a44dacf061dd02b439ab8bd820e3c721aab77168f705f5ce65661f26527b03ea88eec16d78486a633c474120589ec8736692ebff57ab9b95f52f57190ba6b  fix-i18n.patch"
+b19a44dacf061dd02b439ab8bd820e3c721aab77168f705f5ce65661f26527b03ea88eec16d78486a633c474120589ec8736692ebff57ab9b95f52f57190ba6b  fix-i18n.patch
+4bfb9742279c2d1c872d63cd4bcb01f6a2a13d94618eff954d3a37451fa870a9bb29687330854ee47e8876d6e60dc81cb2569c3931beaefacda33db23c464402  60-scdaemon.rules"
diff --git a/main/gnupg/gnupg-scdaemon.pre-install b/main/gnupg/gnupg-scdaemon.pre-install
new file mode 100644
index 0000000000..8d8262ceea
--- /dev/null
+++ b/main/gnupg/gnupg-scdaemon.pre-install
@@ -0,0 +1,2 @@
+#!/bin/sh
+addgroup -S gnupg 2> /dev/null
-- 
2.17.0

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---