Two different approaches to encrypting user data on a disk image
have been posted on the web. One approach is to encrypt only the most
sensitive files, and symlink them back to their default locations as
required for applications with hard-coded file paths. The user mounts
the image after logging in, and it's unmounted when she logs out. This
was what I did myself until recently. There are quite a few problems
with this method. It's a lot of work to set up and maintain, as
sensitive data can be stored in many different places, and the links
tend to get overwritten by installer scripts. Some applications can't be
launched at login because their default files are not yet available.
Some Carbon apps just don't resolve symlinks or aliases, and files in
their hard-coded paths can't be encrypted this way.
A more advanced
method involves changing the entry in the NetInfo database for the
user's home directory to an encrypted image. Then the user can't log in
unless the image is already mounted. An admin user has to log in first
and mount it as root. If she doesn't have admin privileges, the
encryption user has to trust someone who does with her passphrase.
This procedure is posted for information only. Use it at your own
risk. No system configuration files are modified. All changes are
confined to the /Users directory.
The implications of encrypting data are far from clear to many
people. If a user wants to use his login password as an encryption
passphrase, if he wants to save it in the Keychain, or if he's otherwise
unequipped to create and protect a strong passphrase, he should not
encrypt his data.
Don't put much trust in encryption on any platform that, like
Darwin, has a plaintext backing store for virtual memory. Anything you
load in memory may be written to disk in the clear. If you need real
security, run OpenBSD, which can encrypt its swapfiles
with random, volatile keys.
First create a simple shell script to be
installed as a Login Item by any user with an encrypted home volume.
This only has to be done once, if you're encrypting more than one user's
data. The script mounts the volume over the existing home directory,
then notifies the user and logs her out. Login Items are opened rather
than executed, so the script must be saved as a double-clickable
document. This can be done with the Terminal or AppleScript, but I
prefer the open-source application iHook from
Research Systems Unix Group at the University of Michigan. The script
below needs iHook to run. You can easily modify it for a different front
end.
sudo -s
Open a text buffer as follows:
#! /bin/sh
echo %ENDPOLE
echo %WINDOWSIZE 320 200
echo "Enter the passphrase for
your home volume"
echo %RESIGNKEY
cd $HOME
hdid -nomount "/Users/Shared/Disk
Images/${USER}.dmg" > DevFile || exit 0
Dev=`cat DevFile`; rm DevFile
mount -t hfs $Dev . || exit 1
echo "You will now be logged out"
sleep 2
echo "Log in again to access your
data"
sleep 2
ps -cx | grep -w loginwindow |
awk '{ print $1 }' | xargs kill
exit 1
chmod 755 MountHomeVolume.hook
Launch Disk Copy and create a new blank image large enough to hold
the contents of ~Squeeze with room for growth. Name the image file
"Squeeze.dmg" and save it in /Users/Shared/Disk Images, creating this
folder if necessary. Make the volume name "Squeeze", the image format
default, and encryption selected. Squeeze should choose a passphrase
that matches the strength of the encryption algorithm.
set theUser=Squeeze
set theVol=/Volumes/$theUser
vsdbutil -a $theVol
cd /Users/Shared/Disk\ Images
chown 0 .
chown ${theUser}:staff $theVol
${theUser}.dmg
chmod 755 $theVol
chmod 600 ${theUser}.dmg
/Developer/Tools/SetFile -a V $theVol
ditto -rsrcFork ~$theUser
$theVol
hdiutil info | grep -w $theVol |
awk '{ print $1 }' | xargs hdiutil detach
Log in as Squeeze, and open the Login Items preference pane. If
there are any remaining entries, remove them. Add MountHomeVolume.hook.
Log out. The setup is complete. Have Squeeze log in to test it.