Today I am using a fully encrypted hard drive with kernel and gpg-encrypted LUKS keyfile on a USB stick. The initramsfs and boot script where created with LFDE.
But I'd rather do the LUKS unlocking with a Feitian PKI card.
A rather outdated Ubuntu howto exists. The howto also depends on the script cryptosmartcard.sh which seem not to work with the Feitian devices(?).
I'd love to see a howto on accomplishing this task :)
Best regards
- 1590 reads
Printer-friendly version
PDF version





Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Sure, we did some test too and we would love to see this feature.
The problem with the Debian script if pkcs15_crypt which is broken in OpenSC and needs some work.
I will get back to you with more information soon.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
After study, pkcs15-crypt is working fine with the Feitian PKI.
You should not use gpg-encrypted LUKS keyfile but rather a more simple PKCS#11 mechanism.
Booting a fully encrypted system with smartcard is quite problematic as you need to include OpenSC in initramfs.
I encourage you to make an encrypted /home partition at first.
Debian offers standard LUKS PKCS#11 commands.
I don't have time to publish a HOWTO in the next days, probably only next week.
Then you can try embedding OpenSC in initramfs.
To unlock the key for LUKS, you may find information here:
http://keitin.net/jarpatus/projects/usbtoken/index.shtml#encrypt
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
This is the diff of the relevant things in my /etc for luks setup.
Yes, the hook for the opensc related stuff is called "strace" in my system.
Look at the comments of the last two files.
This with the relevant howto should help you to bootstrap an ubuntu 11.10.
diff --git a/crypttab b/crypttab
index 99080be..f6e3e29 100644
--- a/crypttab
+++ b/crypttab
@@ -1 +1,2 @@
-sda2_crypt UUID=dcbd71cb-d637-422c-985f-39c7c3903b61 none luks
+#sda2_crypt UUID=dcbd71cb-d637-422c-985f-39c7c3903b61 none luks
+sda2_crypt UUID=dcbd71cb-d637-422c-985f-39c7c3903b61 /etc/keys/lukskey.enc luks,keyscript=decrypt_opensc
diff --git a/initramfs-tools/hooks/strace b/initramfs-tools/hooks/strace
new file mode 100755
index 0000000..af49aea
--- /dev/null
+++ b/initramfs-tools/hooks/strace
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+set -e
+
+PREREQ=""
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case $1 in
+ prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /usr/share/initramfs-tools/hook-functions
+
+# Hooks for loading smartcard reading software into the initramfs
+
+copy_exec /usr/bin/strace
+copy_exec /lib/libpcsclite.so.1
+copy_exec /lib/x86_64-linux-gnu/libgcc_s.so.1
+copy_exec /lib/x86_64-linux-gnu/libusb-1.0.so.0
+copy_exec /etc/libccid_Info.plist
+
diff --git a/initramfs-tools/modules b/initramfs-tools/modules
index 9aa4646..c38b76d 100644
--- a/initramfs-tools/modules
+++ b/initramfs-tools/modules
@@ -8,3 +8,4 @@
#
# raid1
# sd_mod
+cryptopensc
diff --git a/initramfs-tools/scripts/local-bottom/cryptopensc2 b/initramfs-tools/scripts/local-bottom/cryptopensc2
new file mode 100755
index 0000000..475250c
--- /dev/null
+++ b/initramfs-tools/scripts/local-bottom/cryptopensc2
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+set -e
+
+PREREQ=""
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case $1 in
+ prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /scripts/functions
+
+# Hook for stopping smartcard reading software
+
+if [ ! -e /usr/sbin/pcscd ]; then
+ echo "no pcscd"
+ exit 0
+fi
+
+# Start pcscd daemon nomrally. If it was started in foregound, chances are
+# it'll harmlessly complain about missing /var/run/pcscd* files due to the root
+# filessytem being remounted.
+kill -9 `ps ax |grep pcsc|grep -v grep|awk '{print $1}'`
+
diff --git a/keys/lukskey.enc b/keys/lukskey.enc
new file mode 100644
index 0000000..77c93c7
--- /dev/null
+++ b/keys/lukskey.enc
@@ -0,0 +1,3 @@
#you want to place the luks key encrypted with your encryption key here.
\ No newline at end of file
diff --git a/reader.conf b/reader.conf
new file mode 100644
index 0000000..e69de29
#just touch /etc/reader.conf
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Dear mag, from a previous post, it seems that you are not using Free Software, at least not using pristine OpenSC. Please follow our guidelines and then submit a trace back.
We are very interested in this LUKS issue.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Maybe I wasn't clear: luks encryption is workinig for me with the above detailed changes to a ubuntu 10.10.
Dear gooze,
You are insulting me.
I am very close to be saint of emacs. Only I use vi and the following non-free software:
- adobe flash plugin
- The Incredible Machine
And none of the above have anything to do with smart cards.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
I got so upset ;) I remembered sending my notes to a friend on LUKS. So here is the howto.
(c) CC-BY-SA
#initialisation:
touch /etc/reader.conf
dd if=/dev/random of=lukskey count=128 bs=1
pkcs15-tool --read-public-key 4eb1183931207562af8669945bd5ca6f8e74bf26 >4eb1183931207562af8669945bd5ca6f8e74bf26_pubkey.pem
openssl rsautl -encrypt -pubin -inkey 4eb1183931207562af8669945bd5ca6f8e74bf26_pubkey.pem -in lukskey -pkcs -out lukskey.enc
cryptsetup luksDump /dev/sda2
cryptsetup luksAddKey /dev/sda2 lukskey --key-slot=1
rm lukskey
mkdir /etc/keys
cp lukskey.enc /etc/keys
#to remove key from slot 1: cryptsetup luksKillSlot /dev/sda2 1
#add to /etc/crypttab:
#sda2_crypt UUID=dcbd71cb-d637-422c-985f-39c7c3903b61 /etc/keys/lukskey.enc luks,keyscript=decrypt_opensc
# add the hook and the init script listed below
# see https://bugs.launchpad.net/cryptsetup/+bug/899971
update-initramfs -u
#-vu 2>&1 |tee /tmo/foo to see details
#test, do it on console (not xterm)
/lib/cryptsetup/scripts/decrypt_opensc /etc/key/lukskey.enc >lukskey
cryptsetup luksOpen /dev/sda2 testvol --readonly --key-file=lukskey
ls /dev/disk/by-id/dm-name-testvol
rm lukskey
#see if we have the key installed. if we have, probably other things got there as well
lsinitramfs /boot/initrd.img-3.0.0-13-generic |grep lukskey
---------------------------hook-------------
$cat /etc/initramfs-tools/hooks/strace
#!/bin/sh
set -e
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
# Hooks for loading smartcard reading software into the initramfs
copy_exec /usr/bin/strace
copy_exec /lib/libpcsclite.so.1
copy_exec /lib/x86_64-linux-gnu/libgcc_s.so.1
copy_exec /lib/x86_64-linux-gnu/libusb-1.0.so.0
copy_exec /etc/libccid_Info.plist
---------------------------- init script ------------------------
$ cat /etc/initramfs-tools/scripts/local-bottom/cryptopensc2
#!/bin/sh
set -e
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
# Hook for stopping smartcard reading software
if [ ! -e /usr/sbin/pcscd ]; then
echo "no pcscd"
exit 0
fi
# Start pcscd daemon nomrally. If it was started in foregound, chances are
# it'll harmlessly complain about missing /var/run/pcscd* files due to the root
# filessytem being remounted.
kill -9 `ps ax |grep pcsc|grep -v grep|awk '{print $1}'`
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Sorry, we didn't mean to insult you :)
Thanks for your solution.
You are the happy winner of one free ePass2003 for submitting us a solution for using LUKS.
Let the force be with you!
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Thank you, I will test this as soon as possible!
I suggest that you copy this how-to to the tutorial section so that more people will find it.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Hi,
thanks for the script!
I made some improvements (working here on Ubuntu oneiric), like splash screen integration for pin entry, and fallback to passphrase unlock in case smartcard unlock fails.
If you are too slow while inserting the card or typed in a wrong PIN, simply let the passphrase prompt fail (i.e. by pressing return). Smart card unlock will be offered again.
Edit: new decrypt_opensc diff
###------- /etc/initramfs-tools/modules -------
### Added depencies for libccidtwin.so based PCMCIA readers
###
--- a/etc/initramfs-tools/modules
+++ b/etc/initramfs-tools/modules
@@ -9,3 +9,5 @@
#
# raid1
# sd_mod
+pcmcia
+serial_cs
###------- /etc/initramfs-tools/hooks/strace -------
### Added depencies for libccidtwin.so based PCMCIA readers
###
### Please exec: ln -s /etc/reader.conf /etc/reader.conf.d/reader.conf
### And don't forget to make this script executable.
###
--- a/etc/initramfs-tools/hooks/strace
+++ b/etc/initramfs-tools/hooks/strace
@@ -20,6 +20,8 @@ esac
# Hooks for loading smartcard reading software into the initramfs
+copy_exec /etc/pcmcia/config.opts
+copy_exec /etc/reader.conf.d/reader.conf
copy_exec /usr/bin/strace
copy_exec /lib/libpcsclite.so.1
copy_exec /lib/i386-linux-gnu/libgcc_s.so.1
###------- /lib/cryptsetup/scripts/decrypt_opensc -------
### Added support for splash screens, use only a specific key, reduced reader timeout (5 seconds).
###
### IMPORTANT: Replace ENTER_YOUR_KEY_ID_HERE with the key id to use!
###
--- a/lib/cryptsetup/scripts/decrypt_opensc
+++ b/lib/cryptsetup/scripts/decrypt_opensc
@@ -9,6 +9,9 @@
# Although opensc-tool --help reports that there is a --wait option, it doesn't
# seem to be implemented.
+# Set key id to unlock here
+keyid=ENTER_YOUR_KEY_ID_HERE
+
check_card() {
cardfound=0
@@ -23,7 +26,7 @@ wait_card() {
if [ $cardfound = 0 ] ; then
echo "Waiting for Smart Card..." >&2
tries=0
- while [ $cardfound = 0 -a $tries -lt 60 ] ; do
+ while [ $cardfound = 0 -a $tries -lt 5 ] ; do
sleep 1
check_card
tries=$(($tries + 1))
@@ -39,9 +42,16 @@ wait_card
if [ -p /dev/.initramfs/usplash_outfifo ] && [ -x /sbin/usplash_write ]; then
# Get pin number from usplash
/sbin/usplash_write "INPUTQUIET Enter pin for $crypttarget ($cryptsource): "
- /usr/bin/pkcs15-crypt --decipher --input $1 --pkcs1 --raw --pin "$(cat /dev/.initramfs/usplash_outfifo)"
+ /usr/bin/pkcs15-crypt --decipher --key $keyid --input $1 --pkcs1 --raw --pin "$(cat /dev/.initramfs/usplash_outfifo)"
else
- # Get pin number from console
- /usr/bin/pkcs15-crypt --decipher --input $1 --pkcs1 --raw < /dev/console 2> /dev/console
+ askprompt="Enter smart card PIN for $crypttarget ($cryptsource): "
+ if [ -x /bin/plymouth ] && plymouth --ping; then
+ /bin/plymouth ask-for-password --prompt "$askprompt" | /usr/bin/pkcs15-crypt --decipher --key $keyid --input $1 --pkcs1 --raw -
+ elif [ -x /lib/udev/watershed ] && [ -x /lib/cryptsetup/askpass ]; then
+ /lib/udev/watershed /lib/cryptsetup/askpass "$askprompt" | /usr/bin/pkcs15-crypt --decipher --key $keyid --input $1 --pkcs1 --r
+ else
+ # Get pin number from console
+ /usr/bin/pkcs15-crypt --decipher --input $1 --pkcs1 --raw < /dev/console 2> /dev/console
+ fi
fi
exit $?
###------- /usr/share/initramfs-tools/scripts/local-top/cryptroot -------
### Added support for splash screens, fallback to passphrase if smart card unlock fails.
###
--- a/usr/share/initramfs-tools/scripts/local-top/cryptroot
+++ b/usr/share/initramfs-tools/scripts/local-top/cryptroot
@@ -69,6 +69,7 @@ parse_options()
cryptkeyscript=""
cryptkey="" # This is only used as an argument to an eventual keyscript
crypttries=3
+ cryptfallback=1
cryptrootdev=""
CRYPTTAB_OPTIONS=""
@@ -283,8 +284,28 @@ setup_mapping()
if ! crypttarget="$crypttarget" cryptsource="$cryptsource" \
$cryptkeyscript "$cryptkey" | $cryptcreate --key-file=- ; then
- message "cryptsetup: cryptsetup failed, bad password or options?"
- continue
+ if [ $cryptfallback -le 0 ]; then
+ message "cryptsetup: cryptsetup failed, bad password or options?"
+ continue;
+ else
+ message "cryptsetup: cryptsetup failed, falling back to passphrase unlock!"
+ /bin/sleep 3
+
+ FB_cryptkey="Unlocking the disk $cryptsource ($crypttarget)\nEnter passphrase: "
+ if [ -x /bin/plymouth ] && plymouth --ping; then
+ FB_cryptkeyscript="plymouth ask-for-password --prompt"
+ FB_cryptkey=$(echo -e "$FB_cryptkey")
+ else
+ FB_cryptkeyscript="/lib/cryptsetup/askpass"
+ fi
+
+
+ if ! crypttarget="$crypttarget" cryptsource="$cryptsource" \
+ $FB_cryptkeyscript "$FB_cryptkey" | $cryptcreate --key-file=- ; then
+ message "cryptsetup: cryptsetup failed, bad password or options?"
+ continue;
+ fi
+ fi
fi
if [ ! -e "$NEWROOT" ]; then
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
This is really fantastic.
Could you publish the complete script?
degrunert , you are the happy winner of an ePass2003.
It was shipped today.
Many thanks!
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Thank you,
I have sent you a package containing a readme and example files.
Some modified files like /usr/share/initramfs-tools/scripts/local-top/cryptroot are very long, posting it here looks a bit chaotic.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
degrunert, can you send me the files as well?
< email removed >
Thanks :)
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Could you please upload & share your patch with us via dropbox/box.net or similia ? Thank you .
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Based on the work from mag & degrunert I made my own decrypt_opensc version with some improvements and a bugfix.
-It seems pkcs15-crypt treats every parameter passed after "--input " as files, so I changed the command to have "--input" as last parameter.
-Switched from polling to hotplug: much cleaner and functional, there are no more timeouts and no time/speed penalties, splash informs you that is waiting for card insertion and it asks for a pin as soon as a token is inserted; as of now it will wait forever for a card, I'm trying to add hotkey recognition to fall back to passphrase unlocking.
-No more hardcoded parameters like key-id and so on; if a key sealed with your smart card exists it will get used regardless of its key-id.
You'll find my script at: http://dl.dropbox.com/u/35396310/decrypt_opensc
I tested it on Ubuntu Oneiric 11.10 and it works for me, hope you enjoy.
Alex
P.S. please be safe and always have a fallback passphrase for drive unlocking in case you lose your pin, you lock your card or you destroy it; I take no responsibility for ANY loss of data. This script is provided as is, with no warranty.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Hi, continuing my work I fixed a bug in "cryptroot" script preventing it from honoring the "tries" option in /etc/crypttab (the times it should ask for password before giving up).
However I can't add passphrase unlocking fallback in case of script assisted drive unlocking (as with decrypt_opensc); anyone willing to help please?
You can find my revised scripts here:
http://dl.dropbox.com/u/35396310/decrypt_opensc
http://dl.dropbox.com/u/35396310/cryptroot
copy "decrypt_opensc" in "/lib/cryptsetup/scripts/"
copy "cryptroot" in "/usr/share/initramfs-tools/scripts/local-top/"
set them executable with "chmod +x [file]"
then do "update-initramfs -u"
Alex
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
I've uploaded my package now:
http://www.box.com/s/0zr6boxih9aec69y90ov
Btw. there is a reason why I included the key id into the script - think of cards with multiple keys.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Thank you so much degrunert, you are perfectly right about key id, maybe that should be passed as a parameter from /etc/crypttab rather than hardcoded every time in the script by the user; also I think there should be some checking about smart card/ key identification (maybe serial number), however I don't know where to start with, I don't even know if it's currently feasible with the current plymouth/upstart infrastructure.
Re: Full disk encryption with Feitian PKI Card/Token and LUKS
Hi Folks,
i've had the issue with a PKI Token with multiple keys on it, using an other than the first key for decrypt a luks key. Here is what i've made:
- extension to crypttab: changed keyscript to decrypt_opensc_multikey and added argument keyid
- modified decrypt_opensc to decrypt_opensc_multikey (see diff below)
- modified cryptdisks.funkctions to parse keyid and pass it to keyscript (see diff below)
At the first sight: it solved the problem, keyid is added through crypttab parameter.
At a second sight: there are some issues:
- the keyid is badly passed to the command line of the keyscript: makes presumption on the tool (pkcs15-crypt) used inside
- it is not working for initrd (that was out of my scope)
- needs documentation
- needs testing
Comments are welcome.
-- here are the diffs against Debian (squeeze/wheezy) packages cryptsetup 2:1.1.3-4squeeze2 and opensc 0.12.2-2
$ diff cryptdisks.functions cryptdisks.functions_orig
39d38
< KEYID=""
179,189d177
< keyid)
< if [ -z "$KEYSCRIPT" ]; then
< log_warning_msg "$dst: keyid only valid after keyscript, skipping"
< return 1
< elif [ -z "$VALUE" ]; then
< log_warning_msg "$dst: empty keyid not allowed, skipping"
< return 1
< else
< KEYID="$VALUE"
< fi
< ;;
331,334d318
< if [ -n $KEYID ]; then
< keyscriptarg="$keyscriptarg --key $KEYID"
< fi
<
$ diff decrypt_opensc_multikey decrypt_opensc
45,51c45
< if [ -z "$2" ]; then
< /usr/bin/pkcs15-crypt --decipher --input $1 --pkcs1 --raw < /dev/console 2> /dev/console
< else
< input=$1
< shift
< /usr/bin/pkcs15-crypt --decipher --input $input --pkcs1 --raw $* < /dev/console 2> /dev/console
< fi
---
> /usr/bin/pkcs15-crypt --decipher --input $1 --pkcs1 --raw < /dev/console 2> /dev/console