103
103
filename_encryption_available() {
104
104
version=$(cat /sys/fs/ecryptfs/version 2>/dev/null)
105
[ -z "$version" ] && error `gettext "Can't get ecryptfs version, ecryptfs kernel module not loaded?"`
105
[ -z "$version" ] && error "$(gettext 'Cannot get ecryptfs version, ecryptfs kernel module not loaded?')"
106
106
[ $(($version & 0x100)) -eq 0 ] && return 1
172
172
# Prompt for the USER name, if not on the command line and not in the env
173
173
if [ -z "$USER" ]; then
174
174
while [ true ]; do
175
echo -n gettext `"Enter the username: "`
175
echo -n "$(gettext 'Enter the username: ')"
178
178
if [ -z "$USER" ]; then
179
echo `gettext "ERROR: "` `gettext "You must provide a username"`
179
echo "$(gettext 'ERROR: ')" "$(gettext 'You must provide a username')"
182
182
# Verify that the user exists
183
183
if ! id "$USER" >/dev/null; then
184
echo `gettext "ERROR: "` `gettext "User does not exist"` " [$USER]"
184
echo "$(gettext 'ERROR: ')" "$(gettext 'User does not exist')" " [$USER]"
198
198
# Check if the ecryptfs group exists, and user is member of ecryptfs group
199
199
if grep -qs "^ecryptfs:" /etc/group; then
200
200
if ! id "$USER" | grep -qs "\(ecryptfs\)"; then
201
error `gettext "User needs to be a member of ecryptfs group"`
201
error "$(gettext 'User needs to be a member of ecryptfs group')"
205
205
# Obtain the user's home directory
206
206
HOME=`getent passwd "$USER" | awk -F: '{print $6}'`
207
207
if [ ! -d "$HOME" ]; then
208
error `gettext "User home directory does not exist"` "[$HOME]"
208
error "$(gettext 'User home directory does not exist')" "[$HOME]"
211
211
if [ "$BOOTSTRAP" = "1" ]; then
225
225
# Check for previously setup private directory
226
226
if [ -s "$HOME/.ecryptfs/wrapped-passphrase" -a "$FORCE" != "1" ]; then
227
error `gettext "wrapped-passphrase file already exists, use --force to overwrite."`
227
error "$(gettext 'wrapped-passphrase file already exists, use --force to overwrite.')"
229
229
if [ -s "$HOME/.ecryptfs/$PRIVATE_DIR.sig" -a "$FORCE" != "1" ]; then
230
error "$PRIVATE_DIR.sig" `gettext "file already exists, use --force to overwrite."`
230
error "$PRIVATE_DIR.sig" "$(gettext 'file already exists, use --force to overwrite.')"
233
233
# Check for active mounts
234
grep -qs "$MOUNTPOINT " /proc/mounts && error "[$MOUNTPOINT]" `gettext "is already mounted"`
235
grep -qs "$CRYPTDIR " /proc/mounts && error "[$CRYPTDIR]" `gettext "is already mounted"`
234
grep -qs "$MOUNTPOINT " /proc/mounts && error "[$MOUNTPOINT]" "$(gettext 'is already mounted')"
235
grep -qs "$CRYPTDIR " /proc/mounts && error "[$CRYPTDIR]" "$(gettext 'is already mounted')"
237
237
# Check that the mount point and encrypted directory are empty (skip symlinks).
238
238
# Perhaps one day we could provide a migration mode (using rsync or something),
239
239
# but this would be VERY hard to do safely.
240
240
count=`ls -Al "$MOUNTPOINT" 2>/dev/null | egrep -c "^[drwx-]{10}"`
241
241
if [ "$count" != "0" ]; then
242
error "$MOUNTPOINT" `gettext "must be empty before proceeding"`
242
error "$MOUNTPOINT" "$(gettext 'must be empty before proceeding')"
244
244
count=`ls -Al "$CRYPTDIR" 2>/dev/null | egrep -c "^[dlrwx-]{10}"`
245
245
if [ "$count" != "0" ]; then
246
error "$CRYPTDIR" `gettext "must be empty before proceeding"`
246
error "$CRYPTDIR" "$(gettext 'must be empty before proceeding')"
249
249
stty_orig=`stty -g`
275
275
if [ -z "$LOGINPASS" ]; then
276
echo `gettext "ERROR:"` `gettext "You must provide a login passphrase"`
276
echo "$(gettext 'ERROR: ')" "$(gettext 'You must provide a login passphrase')"
277
277
tries=$(($tries + 1))
279
279
if [ "$NOPWCHECK" = "1" ]; then
280
echo `gettext "INFO:"` `gettext "Skipping password verification"`
280
echo "$(gettext 'INFO:')" "$(gettext 'Skipping password verification')"
283
283
if printf "%s\0" "$LOGINPASS" | /sbin/unix_chkpwd "$USER" nullok; then
286
echo `gettext "ERROR:"` `gettext "Your login passphrase is incorrect"`
286
echo "$(gettext 'ERROR: ')" "$(gettext 'Your login passphrase is incorrect')"
287
287
tries=$(($tries + 1))
292
292
if [ $tries -ge $PW_ATTEMPTS ]; then
293
error `gettext "Too many incorrect password attempts, exiting"`
293
error "$(gettext 'Too many incorrect password attempts, exiting')"
312
echo -n `gettext "Enter your mount passphrase (again): "`
312
echo -n "$(gettext 'Enter your mount passphrase (again): ')"
313
313
MOUNTPASS2=`head -n1`
316
316
if [ "$MOUNTPASS" != "$MOUNTPASS2" ]; then
317
echo `gettext "ERROR:"` `gettext "Mount passphrases do not match"`
317
echo "$(gettext 'ERROR: ')" "$(gettext 'Mount passphrases do not match')"
318
318
tries=$(($tries + 1))
324
324
if [ $tries -ge $PW_ATTEMPTS ]; then
325
error `gettext "Too many incorrect passphrase attempts, exiting"`
325
error "$(gettext 'Too many incorrect passphrase attempts, exiting')"
330
330
echo "************************************************************************"
331
echo `gettext "YOU SHOULD RECORD YOUR MOUNT PASSPHRASE AND STORE IT IN A SAFE LOCATION."`
331
echo "$(gettext 'YOU SHOULD RECORD YOUR MOUNT PASSPHRASE AND STORE IT IN A SAFE LOCATION.')"
332
332
echo " ecryptfs-unwrap-passphrase ~/.ecryptfs/wrapped-passphrase"
333
echo `gettext "THIS WILL BE REQUIRED IF YOU NEED TO RECOVER YOUR DATA AT A LATER TIME."`
333
echo "$(gettext 'THIS WILL BE REQUIRED IF YOU NEED TO RECOVER YOUR DATA AT A LATER TIME.')"
334
334
echo "************************************************************************"
337
337
###############################################################################
339
339
# Setup private directory in home
340
mkdir -m 700 -p "$CRYPTDIR" || error `gettext "Could not create crypt directory"` "[$CRYPTDIR]"
341
mkdir -m 700 -p "$MOUNTPOINT" || error `gettext "Could not create mount directory"` "[$MOUNTPOINT]"
340
mkdir -m 700 -p "$CRYPTDIR" || error "$(gettext 'Could not create crypt directory')" "[$CRYPTDIR]"
341
mkdir -m 700 -p "$MOUNTPOINT" || error "$(gettext 'Could not create mount directory')" "[$MOUNTPOINT]"
342
342
ln -sf /usr/share/ecryptfs-utils/ecryptfs-mount-private.txt "$MOUNTPOINT"/README.txt
343
343
ln -sf /usr/share/ecryptfs-utils/ecryptfs-mount-private.desktop "$MOUNTPOINT"/Access-Your-Private-Data.desktop
344
344
chmod 500 "$MOUNTPOINT"
346
346
# Setup ~/.ecryptfs directory
347
347
if [ "$NOAUTOMOUNT" = "1" ]; then
348
echo `gettext "INFO:"` "$HOME/$PRIVATE_DIR" `gettext "will not be mounted on login"`
348
echo "$(gettext 'INFO:')" "$HOME/$PRIVATE_DIR" "$(gettext 'will not be mounted on login')"
350
touch $HOME/.ecryptfs/auto-mount || error `gettext "Could not setup ecryptfs auto-mount"`
350
touch $HOME/.ecryptfs/auto-mount || error "$(gettext 'Could not setup ecryptfs auto-mount')"
352
352
if [ "$NOAUTOUMOUNT" = "1" ]; then
353
echo `gettext "INFO:"` "$HOME/$PRIVATE_DIR" `gettext "will not be unmounted on logout"`
353
echo "$(gettext 'INFO:')" "$HOME/$PRIVATE_DIR" "$(gettext 'will not be unmounted on logout')"
355
touch $HOME/.ecryptfs/auto-umount || error `gettext "Could not setup ecryptfs auto-umount"`
355
touch $HOME/.ecryptfs/auto-umount || error "$(gettext 'Could not setup ecryptfs auto-umount')"
358
358
if [ "$WRAPPING_PASS" = "LOGIN" ]; then
359
rm -f $HOME/.ecryptfs/wrapping-independent || error `gettext "Could not remove ecryptfs wrapping-independent"`
359
rm -f $HOME/.ecryptfs/wrapping-independent || error "$(gettext 'Could not remove ecryptfs wrapping-independent')"
361
touch $HOME/.ecryptfs/wrapping-independent || error `gettext "Could not setup ecryptfs wrapping-independent"`
361
touch $HOME/.ecryptfs/wrapping-independent || error "$(gettext 'Could not setup ecryptfs wrapping-independent')"
382
382
printf "%s" "$MOUNTPASS" > "$temp"
383
383
mv "$temp" "/dev/shm/.ecryptfs-$USER"
385
printf "%s\n%s" "$MOUNTPASS" "$LOGINPASS" | ecryptfs-wrap-passphrase "$HOME/.ecryptfs/wrapped-passphrase" - || error `gettext "Could not wrap passphrase"`
385
printf "%s\n%s" "$MOUNTPASS" "$LOGINPASS" | ecryptfs-wrap-passphrase "$HOME/.ecryptfs/wrapped-passphrase" - || error "$(gettext 'Could not wrap passphrase')"
390
390
# On subsequent logins, this should be handled by "pam_ecryptfs.so unwrap"
391
391
response=`printf "%s" "$MOUNTPASS" | ecryptfs-add-passphrase $FNEK -`
392
392
if [ $? -ne 0 ]; then
393
error `gettext "Could not add passphrase to the current keyring"`
393
error "$(gettext 'Could not add passphrase to the current keyring')"
395
395
sig=`echo "$response" | grep "Inserted auth tok" | sed "s/^.*\[//" | sed "s/\].*$//"`
396
396
if ! echo "$sig" | egrep -qs "^[0-9a-fA-F]{$KEYBYTES,$KEYBYTES}$"; then
397
error `gettext "Could not obtain the key signature"`
397
error "$(gettext 'Could not obtain the key signature')"
400
echo "$sig" > "$temp" || error `gettext "Could not create signature file"` "[$HOME/.ecryptfs/$PRIVATE_DIR.sig]"
400
echo "$sig" > "$temp" || error "$(gettext 'Could not create signature file')" "[$HOME/.ecryptfs/$PRIVATE_DIR.sig]"
401
401
mv "$temp" "$HOME/.ecryptfs/$PRIVATE_DIR.sig"
403
echo "$MOUNTPOINT" > "$temp" || error `gettext "Could not create mountpoint file"` "[$HOME/.ecryptfs/$PRIVATE_DIR.mnt]"
403
echo "$MOUNTPOINT" > "$temp" || error "$(gettext 'Could not create mountpoint file')" "[$HOME/.ecryptfs/$PRIVATE_DIR.mnt]"
404
404
mv "$temp" "$HOME/.ecryptfs/$PRIVATE_DIR.mnt"
407
echo `gettext "Done configuring."`
407
echo "$(gettext 'Done configuring.')"
410
410
# Skip the tests if we're in bootstrap mode, but exit with the encrypted
436
436
# Now let's perform some basic mount/write/umount/read sanity testing...
437
echo `gettext "Testing mount/write/umount/read..."`
438
/sbin/mount.ecryptfs_private || error `gettext "Could not mount private ecryptfs directory"`
439
temp=`mktemp "$MOUNTPOINT/ecryptfs.test.XXXXXX"` || error_testing "$temp" `gettext "Could not create empty file"`
440
random_data=`head -c 16000 /dev/urandom | od -x` || error_testing "$temp" `gettext "Could not generate random data"`
441
echo "$random_data" > "$temp" || error_testing "$temp" `gettext "Could not write encrypted file"`
442
md5sum1=`md5sum "$temp"` || error_testing "$temp" `gettext "Could not read encrypted file"`
443
/sbin/umount.ecryptfs_private || error_testing "$temp" `gettext "Could not unmount private ecryptfs directory"`
444
/sbin/mount.ecryptfs_private || error_testing "$temp" `gettext "Could not mount private ecryptfs directory (2)"`
445
md5sum2=`md5sum "$temp"` || error_testing "$temp" `gettext "Could not read encrypted file (2)"`
437
echo "$(gettext 'Testing mount/write/umount/read...')"
438
/sbin/mount.ecryptfs_private || error "$(gettext 'Could not mount private ecryptfs directory')"
439
temp=`mktemp "$MOUNTPOINT/ecryptfs.test.XXXXXX"` || error_testing "$temp" "$(gettext 'Could not create empty file')"
440
random_data=`head -c 16000 /dev/urandom | od -x` || error_testing "$temp" "$(gettext 'Could not generate random data')"
441
echo "$random_data" > "$temp" || error_testing "$temp" "$(gettext 'Could not write encrypted file')"
442
md5sum1=`md5sum "$temp"` || error_testing "$temp" "$(gettext 'Could not read encrypted file')"
443
/sbin/umount.ecryptfs_private || error_testing "$temp" "$(gettext 'Could not unmount private ecryptfs directory')"
444
/sbin/mount.ecryptfs_private || error_testing "$temp" "$(gettext 'Could not mount private ecryptfs directory (2)')"
445
md5sum2=`md5sum "$temp"` || error_testing "$temp" "$(gettext 'Could not read encrypted file (2)')"
447
447
# Use ecryptfs-umount-private on the final run, to clear the used keys
448
448
# out of the keyring
449
ecryptfs-umount-private || error_testing "$temp" `gettext "Could not unmount private ecryptfs directory (2)"`
449
ecryptfs-umount-private || error_testing "$temp" "$(gettext 'Could not unmount private ecryptfs directory (2)')"
450
450
if [ "$md5sum1" != "$md5sum2" ]; then
451
error `gettext "Testing failed."`
451
error "$(gettext 'Testing failed.')"
453
echo `gettext "Testing succeeded."`
453
echo "$(gettext 'Testing succeeded.')"
457
echo `gettext "Logout, and log back in to begin using your encrypted directory."`
457
echo "$(gettext 'Logout, and log back in to begin using your encrypted directory.')"