3
# Run this script as root
8
PASSWD_DIR="$HOME_DIR/.ecryptfs/pki"
9
PASSWD_PATH="$PASSWD_DIR/passwd"
14
echo " `basename $0` [-v/--verbose | -s/--silent]"
16
echo "Verbose and Silent modes are mutually exclusive"
20
while [ $# -gt 0 ]; do
36
if [ -n "$VERBOSE" -a -n "$SILENT" ]; then
42
if [ "$1" == "-n" ]; then
46
[ -z "$SILENT" ] && echo $NONL "$@"
56
function write_tmp_files {
57
echo "passwd=t" > $PASSWD_PATH
61
if [ "x$SRC_DIR" == "x" ]; then
62
echo "SRC_DIR is empty"
65
if [ "x$SRC_DIR" == "x/" ]; then
66
echo "SRC_DIR is root; probably not what you want"
74
function mount_passphrase {
75
mount -t ecryptfs $SRC_DIR $DST_DIR -o key=passphrase,verbosity=0,ecryptfs_cipher=aes
79
mount -i -o remount,ro $DST_DIR
82
function umount_ecryptfs {
89
mount_cmd="/sbin/mount.ecryptfs $SRC_DIR $DST_DIR -o $mount_opts"
90
if [ -z "$VERBOSE" ]; then
91
$mount_cmd > /dev/null
96
if [ "$retval" -eq "$expected_retval" ]; then
103
function write_file {
105
echo "$string" > $DST_DIR/temp.txt
106
if [ $? -ne 0 ]; then
107
echo "Error writing to temp file"
114
grep "$string" $DST_DIR/temp.txt > /dev/null
115
if [ $? -ne 0 ]; then
116
echo "Error reading from temp file"
119
rm -f $DST_DIR/temp.txt
122
function mount_passphrase {
123
for i in "passwd=t" "passfile=$HOME_DIR/.ecryptfs/pki/passwd"; do
125
vecho -n "Performing mount with passphrase option [$i]: "
126
mount_opts="key=passphrase:$i:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
128
do_mount $mount_opts $expected_retval
129
if [ "$?" -ne 0 ]; then
131
echo "Error mounting ecryptfs with passphrase option [$i] [$?]"
134
vecho -n "Writing file to ecryptfs..... "
136
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
137
vecho -n "Remounting ecryptfs.......... "
139
do_mount $mount_opts $expected_retval
140
if [ "$?" -ne 0 ]; then
142
echo "Error remounting ecryptfs with passphrase option [$i] [$?]"
145
vecho -n "Reading file from ecrytpfs... "
147
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
154
# We should return errno from calls to libecryptfs functions.
155
function mount_bad_passphrase {
156
for i in "passwd=" "passfile="; do
157
vecho -n "Performing mount with bad passphrase option [$i]: "
158
mount_opts="key=passphrase:$i:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
160
do_mount $mount_opts $expected_retval
161
if [ "$?" -ne 0 ]; then
163
echo "Return code differed from what was expected [$i]"
171
function mount_ciphers {
172
for i in "aes" "cast5" "cast6" "blowfish" "twofish" "des3_ede" ""; do
174
vecho -n "Performing mount with cipher [$i]: "
175
if [ "$i" == "des3_ede" ]; then
180
mount_opts="key=passphrase:passwd=t:verbosity=0,ecryptfs_key_bytes=$keysize,ecryptfs_cipher=$i"
182
do_mount $mount_opts $expected_retval
183
if [ "$?" -ne 0 ]; then
185
echo "Error mounting ecryptfs with cipher [$i]"
188
vecho -n "Writing file to ecryptfs..... "
190
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
191
vecho -n "Remounting ecryptfs.......... "
193
do_mount $mount_opts $expected_retval
194
if [ "$?" -ne 0 ]; then
196
echo "Error remounting ecryptfs with cipher [$i]"
199
vecho -n "Reading file from ecrytpfs... "
201
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
208
function mount_bad_ciphers {
209
for i in "aesaaaaaaa" "bbbaes" "xxxaesyyy" "abcdefghijklmnopqrstuvwxyzabcdefghijkl"; do
210
vecho -n "Performing mount with incorrect cipher [$i]: "
211
mount_opts="key=passphrase:passwd=t:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=$i"
213
do_mount $mount_opts $expected_retval
214
if [ "$?" -ne 0 ]; then
216
echo "Mount should have failed with cipher [$i]"
224
# Salts need to be hex values if a non hex value is specified 0 is used
225
# we should probably clarify that we are requesting a hex value
226
function mount_salt {
227
for i in "" "a" "12345678" "0xdeadbeefdeadbeefdeadbeef" "ghijklmn" "sdflajsdflksjdaflsdjk" ""; do
229
vecho "Performing mount with salt [$i]"
230
mount_opts="key=passphrase:passwd=t:salt=$i:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
232
do_mount $mount_opts $expected_retval
233
if [ "$?" -ne 0 ]; then
235
echo "Error mounting ecryptfs with salt [$i]"
238
vecho -n "Writing file to ecryptfs..... "
240
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
241
vecho -n "Remounting ecryptfs.......... "
243
do_mount $mount_opts $expected_retval
244
if [ "$?" -ne 0 ]; then
246
echo "Error remounting ecryptfs with salt [$i]"
249
vecho -n "Reading file from ecrytpfs... "
251
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
259
function mount_keyfile {
260
for i in "openssl" "openssl" "openssl"; do
262
vecho -n "Performing mount with key file [$i]: "
263
keyfile=$PASSWD_DIR/$i/key.pem
264
if [ ! -e $keyfile ]; then
266
echo "Error: no $i key file found. Please create $keyfile with password = t, by running ecryptfs-manager"
269
mount_opts="key=openssl:passwd=t:keyfile=$keyfile:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
271
do_mount $mount_opts $expected_retval
272
if [ "$?" -ne 0 ]; then
274
echo "Error mounting ecryptfs with key file [$i]"
277
vecho -n "Writing file to ecryptfs..... "
279
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
280
vecho -n "Remounting ecryptfs.......... "
282
do_mount $mount_opts $expected_retval
283
if [ "$?" -ne 0 ]; then
285
echo "Error remounting ecryptfs with key file [$i]"
288
vecho -n "Reading file from ecrytpfs... "
290
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
297
function clean_up_tests {
301
echo "Running non-interactive mount tests"
303
vecho "Making directories"
305
vecho "Writing temporary files"
307
vecho "Cleaning out source directory"
309
echo -n "Testing Passphrase Modes....... "
313
echo -n "Testing Invalid Passphrases.... "
317
echo -n "Testing Cipher Modes........... "
321
echo -n "Testing Invalid Ciphers........ "
325
echo -n "Testing Salts.................. "
329
echo -n "Testing Keyfile Modes.......... "
335
echo "All tests completed successfully"