Loop-AESThis is a step by step tutorial on creating an encrypted partition using Loop-AES (using AES-256). This tutorial is known to work under sarge. Loop-AES is more secure than dm-crypt (and possibly faster), although it requires a custom kernel module and is more work to install than dm-crypt.prepare the systemnote: this is old. for post-sarge distros, there is package for the modules. for sarge, you can now do this:Building loop-AES requires a full kernel source tree, the headers from kernel-headers packages are not sufficient. Supposedly this could all be simplified with module-assistant, but it doesn't seem to work with loop-aes. Get the necessary packages (note: you do not need loop-aes-ciphers-source unless you want to use twofish, serpent or blowfish): # apt-get install kernel-source-2.6.8 loop-aes-source kernel-tree-2.6.8 kernel-headers-2.6.8-2-686-smp kernel-image-2.6.8-2-686-smp loop-aes-utils
# cd /usr/src
# apt-get install kernel-package
# cd ..
# rmmod loop
create key fileCreate 64 random encryption keys and encrypt those keys using gpg. Reading from /dev/random may take indefinitely long if kernel's random entropy pool is empty. If that happens, do some other work on some other console (use keyboard, mouse and disks). Use of gpg encrypted key file depends on encrypted swap. Make sure your /tmp is mounted as a memory filesystem, you dont want to be writing the loop-aes gpg key to an unencrypted disk, so get that setup before you continue.# apt-get install gnupg sharutils
fill partitionFill the partition with random looking data. "dd" command may take a while to execute if partition is large. (replace /dev/md4 with whatever partition you want to encrypt. replace /dev/loop3 with whichever loop device you wish to use).# head -c 15 /dev/urandom | uuencode -m - | head -n 2 | tail -n 1 | losetup -p 0 -e AES256 /dev/loop3 /dev/md4
set up fstabAdd this to your /etc/fstab file:/dev/md4 /var/maildir reiserfs defaults,noauto,loop=/dev/loop3,encryption=AES256,gpgkey=/tmp/keyfile.gpg 0 0
create the filesystemThe "losetup -F" command asks for passphrase to unlock your key file. Losetup -F option reads loop related options from /etc/fstab. Partition name /dev/md4, encryption=AES256 and gpgkey=/root/keyfile.gpg come from /etc/fstab.# losetup -F /dev/loop3
mount filesystemNow you should be able to mount the file system like this. The "mount" command asks for passphrase to unlock your key file.# mkdir /var/maildir
setup loop-aes encrypted swapstop any running swap# swapoff -a
configure your fstab/dev/hdaxxx none swap sw,loop=/dev/loop6,encryption=AES256 0 0
Scrub old unencrypted data from swap# dd if=/dev/zero of=/dev/hda666 bs=64k conv=notrunc
Make new swap and enable it# mkswap /dev/hdaxxx
how to change a loop-aes key passphraseIt doesn't seem to be documented anywhere how you change the passphrase of a gpg multi-key loop-aes setup. I guess thats because the actual passphrase is the passphrase which unlocks the gpg key, so if you change that key you actually are changing the password. This is relatively easy to do if you just run gpg -d on the keyfile, this will give you the unencrypted 64 random encryption keys which are used to unlock the keyphrase. Once you have this, you just re-encrypt it with a new passphrase. Thats easy enough. The hard part is to do it without writing the unencrypted encryption keys to a disk, as writing the keys to disk is what makes it a defacto insecure system. I suppose it might be argued that if you write them to an encrypted partition you might be fine, although you have to be sure that nobody has access to that filesystem while it is mounted (aka. unencrypted). So, you just need to do this by using regular ole unix pipes, and do it all in memory, right? Well.... not so simple, gpg doesn't really let you do a simple: gpg -d /tmp/foobar.gpg | gpg --symmetric -a -o /tmp/newfoo.gpg -- try it and you will see. The passphrase for the first decryption is somehow... lost and instead it asks you for the second right away. The reason it does this is because both gpg instances are fighting for the tty, if you use --no-tty (a gpg option) then it asks on stdin, and that gets screwed up. There is a way to do it using --passphrase-fd, but then your passphrase is in your shell history. You can of course turn that off if you manage to remember to set the right variable before executing it (in bash: typeset HISTCONTROL=ignoreboth; in zsh: setopt HIST_IGNORE_SPACE, and then prepend the command with a space). This seems ugly and prone to human error. So how do you do it?! Well, first make sure you have backups of your keyfile. Don't mess with this file, you loose a lot of data if you screw up. There are two ways, the first is to make a fifo, decrypt the keyfile into the fifo and then encrypt the data from the fifo, thats kinda ugly and requires the creation of the fifo, the two commands to decrypt and then encrypt and then you need to destroy the fifo, if you want to know how this is done you do this:/tmp$ mkfifo fifo
/tmp$ gpg --symmetric < fifo > blubb2
/tmp$ read -p "Enter passphrase: " -s p1; echo ""; \
otherCheck that loop is really in multi-key mode. Losetup -a output should include string "multi-key" indicating that loop is really in multi-key mode. If no "multi-key" string shows up, you somehow managed to mess up gpg key file generation part or you are trying to use old losetup/mount programs that only understand single-key mode.# losetup -a
# umount /var/maildir
/dev/md4, encryption=AES256 and gpgkey=/root/keyfile.gpg come from /etc/fstab. # losetup -F /dev/loop3
see alsowww.debian-administration.org/?article=81 |
