Downloads
- Source: dmcryptfs_0.3.3.tar.gz
- Debian package for Lenny: dmcryptfs_0.3.3_i386.deb
- License: GPLv2
Changelog
- 06.03.2004 0.1 tgz, deb
- First release
- 12.08.2005 0.2 tgz, deb
- Complete rewrite of the cryptfs tool
- 13.08.2005 0.2.1 tgz, deb
- Made the choice of a tty configurable.
- Added the possibility to chop or add a newline to a passphrase.
- Added manpages.
- 21.08.2005 0.2.2 tgz, deb
- Bugfix: Some environment variables were not cleared after a failed preexec command.
- 12.05.2006 0.2.3 tgz, deb
- Added pre/postexec elements for the key element.
- 17.05.2006 0.2.4 tgz, deb
- Removed the hotplug scripts (now that I use udev).
- 30.06.2006 0.2.5 tgz, deb
- Check if all necessary block devices exist.
- 07.11.2007 0.3.0 tgz, deb
- Cryptswap removed, can be done more flexibly by cryptfs.
- Added call element for actions.
- Implemented --only-map und --only-mount options to possibly separate decryption from fsck and mount.
- Treat fsck exit code 1 as success.
- When changing the UID also change the GID and supplemental groups.
- Added gid option for key, preexec and postexec elements.
- Added ro, mode, uid and gid option for map elements.
- Modified key-id behaviour: Only keys in the execution path are remembered (other keys can be included using calls).
- Added scripts for initramfs-tools.
- 21.11.2007 0.3.1 tgz, deb
- Implemented retries on wrong passwords.
- Added possibility to choose another device mapper name.
- Added overrides to the call element.
- Protect passphrase prompt against scrolling.
- 25.03.2008 0.3.2 tgz, deb
- Added --no-enc option.
- Bugfix: Possible crash if a part of a composite key failed.
- 03.03.2009 0.3.3 tgz, deb
- Implemented access control and made cryptfs setuid root.
- Bugfix: Don't retry an action when -n is in effect to avoid an infinite loop.
- Added --remove option.
- Added zsh completion script.
Encryption of partitions
These are some helper tools to make use of the device mapper crypt target which is available in the Linux kernel 2.6.4 and later. I wrote them mainly for my personal use, so they are especially designed for my needs, but perhaps you'll find them similarly useful.
The device mapper is used by LVM2 (logical volume management version 2), but can be utilized without it. It makes it possible to map sections of block devices (e.g. partitions) to new block devices, whose nodes normally will be created in /dev/mapper. dm-crypt encrypts and decrypts the data during the mapping using a specified algorithm (all ciphers of the kernel can be used) and a given key.
Warnings
I don't give any warranties. (See the GPLv2 for details about warranties.) However I use it daily for encrypting my swap and ext3 partitions (even my root partition) without any problems so far. But be careful and backup your data!
This encryption only protects against data acess after the computer has been powered off (e.g. after being stolen, simply shut down or being confiscated). If the computer was turned on and the password for decryption was given, an attacker can access the data like you. Everybody who can become root can also read out your key. So there have to be further security measures to prevent this (e.g. firewalls, regular updates).
Prerequisites
You need a kernel with the device mapper compiled in or as a module. (Kernel 2.6 has it and there is a patch available for kernel 2.4 - for example in the Debian package kernel-patch-device-mapper.) The kernel should also know the sysfs filesystem.
The following libraries are required: libdevmapper, libgcrypt11 and libxml2.
Mount sysfs on /sys with e.g. the following /etc/fstab entries:
sysfs /sys sysfs defaults 0 0
To encrypt the root filesystem initramfs-tools are recommended.
Installation
Extract the tarball and execute as root 'make install'. (On a Debian system install the .deb package instead.)
Encrypting filesystems
cryptfs allows you to encrypt some filesystems and offers a simple form of logical volume management.
All information about the encrypted filesystems have to be provided in a xml file. An example with explanations is provided in example/cryptfs.xml or on Debian systems in /usr/share/doc/dmcryptfs/cryptfs.xml.gz. A simple setup with one encrypted filesystem would be:
<?xml version="1.0" encoding="UTF-8"?> <dmcrypt> <!-- For the first setup these options can be overriden with the -m option to be able to create a filesystem on it. --> <option name="fsck" value="yes"/> <option name="mount" value="yes"/> <storage device="/dev/hda6"> <entry name="home" cipher="aes256-cbc-essiv:sha256"/> </storage> <action name="boot"> <key type="passphrase" retry="2"> /home filesystem encryption </key> <map name="home"/> </action> </dmcrypt>
As you can see this xml file consists of three parts:
- some options,
- the definition of the storage for the encrypted data and
- the definition of actions (i.e. asking for a key, decrypting the data, fscking and mounting the filesystem).
A complete description of these parts is given in example/cryptfs.xml resp. /usr/share/doc/dmcryptfs/cryptfs.xml.gz.
This xml file should be saved as /etc/cryptfs.xml. A call of 'cryptfs boot' will then activate this encrypted filesystem. ("boot" is the name of the action in the xml file.)
There is an init script called cryptfs, which will call 'cryptfs boot' during boot if there is such an action available. (On Debian systems this script will be installed automatically. So don't name your actions "boot" unless they should be started at boot time.)
If run for the first time you should call cryptfs with the -m option. The will prevent cryptfs from checking and mounting the filesystem (because there is none yet, only garbage). Then you can create the filesystem (using mke2fs and similar tools) in the corresponding devices in /dev/mapper/.
Root Filesystem
This does also work for the root filesystem. Cryptfs comes with some scripts for initramfs-tools, which will call the "root" action (if there is one) at boot time before the root filesystem is mounted.
Because the cryptfs.xml has to be included in the initramfs image each time you modify the xml file you have to call 'update-initramfs -u'. If there exists a /boot/cryptfs.key it will also be included in the initramfs image as /etc/cryptfs.key (to allow two factor authentication, see below).
Note that /etc/passwd, /etc/groups and the name service switch libraries are usually not present in the initramfs, so all "uid" and "gid" options won't work and will yield an error instead.
Hotplugging
My primary goal was to make it play nicely with hotplugging to implement two factor authentication (that means, that authentication is based on two things: something you have (e.g. an usb-stick) and something you know (your passphrase)). With udev you can easily call cryptfs with a rule like:
BUS=="scsi", SYSFS{vendor}=="USB", SYSFS{model}=="Flash Disk", \ KERNEL=="sd?1", SYMLINK+="usbstick", \ RUN+="/sbin/cryptfs usbstick"
In /etc/cryptfs.xml you need an action rule like this:
<action name="usbstick"> <key id="general" type="composite" length="256"> <key type="file"> <preexec> mount /media/usbstick </preexec> /media/usbstick/key <postexec onstate="always" ignorestatus="yes"> umount /media/usbstick </postexec> </key> <key type="passphrase" needtty="yes"> Filesystem encryption: Please enter the password. </key> </key> <map name="home"/> </action>
It creates a key from the bits in /media/usbstick/key (it should contain 32 random bytes) and the given password.
Encrypting a swap partition
A swap partition is encrypted the same way as the filesystems are. But instead of checking and mounting the filesystem we have to activate it as a swap partition.
First you have to specify where to store the swap data, for example in hda5:
<storage device="/dev/hda5"> <entry name="swap" cipher="twofish-cbc-essiv:sha256"/> </storage>
Be careful to write the correct device name in there. The contents of this device will be overwritten every time it is activated!
Then create an action called swap (or any other name you like):
<action name="swap"> <key type="composite"> <key type="file" length="256">/dev/hda5</key> <key type="file" length="256">/dev/random</key> </key> <map name="swap" fsck="no" mount="no"> <postexec onmode="map"> /sbin/mkswap /dev/mapper/swap /sbin/swapon /dev/mapper/swap </postexec> </map> </action>
This action uses a random key (256 bits from /dev/random and 256 encrypted bits from /dev/hda5, which should also be fairly random), sets up an encrypted block device /dev/mapper/swap and finally creates and activates a swap area in this block device.
Now all you need is an init script, that calls '/sbin/cryptfs swap' every reboot. /etc/init.d/cryptfs does that, so just link it in the corresponding rc directory. (For example in Debian this would be a symlink from /etc/rcS.d/S37cryptfs to ../init.d/cryptfs, but the .deb package will already take care of this.)
Either reboot, or deactivate your swap partition and start '/sbin/cryptfs swap' manually.
Contact
If you have questions, found bugs, have ideas for improvements, more features or if you just like it, please tell me. (Or if you like to write a better documentation. ;-)
My mail address is: a.motzkau@web.de
Credits
Thanks to Christophe Saout for the device mapper crypt target and for very fast bug fixing on New Year's eve.