1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
#!/bin/sh
# Run this script as root
SRC_DIR="/tmp/crypt"
DST_DIR="/mnt/crypt"
HOME_DIR="/root"
PASSWD_DIR="$HOME_DIR/.ecryptfs/pki"
PASSWD_PATH="$PASSWD_DIR/passwd"
ERROR=0
function usage {
echo "Usage:"
echo " `basename $0` [-v/--verbose | -s/--silent]"
echo ""
echo "Verbose and Silent modes are mutually exclusive"
exit 1
}
while [ $# -gt 0 ]; do
case $1 in
-v|--verbose)
VERBOSE=yes
shift
;;
-s|--silent)
SILENT=yes
shift
;;
*)
usage
;;
esac
done
if [ -n "$VERBOSE" -a -n "$SILENT" ]; then
usage
fi
function vecho {
NONL=""
if [ "$1" == "-n" ]; then
NONL="-n"
shift
fi
[ -z "$SILENT" ] && echo $NONL "$@"
return 0
}
function mkdirs {
mkdir -p $SRC_DIR
mkdir -p $DST_DIR
mkdir -p $PASSWD_DIR
}
function write_tmp_files {
echo "passwd=t" > $PASSWD_PATH
}
function clean_src {
if [ "x$SRC_DIR" == "x" ]; then
echo "SRC_DIR is empty"
exit 1
else
if [ "x$SRC_DIR" == "x/" ]; then
echo "SRC_DIR is root; probably not what you want"
exit 1
else
rm -rf $SRC_DIR/*
fi
fi
}
function mount_passphrase {
mount -t ecryptfs $SRC_DIR $DST_DIR -o key=passphrase,verbosity=0,ecryptfs_cipher=aes
}
function remount_ro {
mount -i -o remount,ro $DST_DIR
}
function umount_ecryptfs {
umount $DST_DIR
}
function do_mount {
mount_opts="$1"
expected_retval="$2"
mount_cmd="/sbin/mount.ecryptfs $SRC_DIR $DST_DIR -o $mount_opts"
if [ -z "$VERBOSE" ]; then
$mount_cmd > /dev/null
else
$mount_cmd
fi
retval=$?
if [ "$retval" -eq "$expected_retval" ]; then
vecho "ok"
return 0
fi
return $retval
}
function write_file {
string="$@"
echo "$string" > $DST_DIR/temp.txt
if [ $? -ne 0 ]; then
echo "Error writing to temp file"
exit 1
fi
}
function read_file {
string="$@"
grep "$string" $DST_DIR/temp.txt > /dev/null
if [ $? -ne 0 ]; then
echo "Error reading from temp file"
exit 1
fi
rm -f $DST_DIR/temp.txt
}
function mount_passphrase {
for i in "passwd=t" "passfile=$HOME_DIR/.ecryptfs/pki/passwd"; do
vecho "--"
vecho -n "Performing mount with passphrase option [$i]: "
mount_opts="key=passphrase:$i:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
expected_retval=0
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error mounting ecryptfs with passphrase option [$i] [$?]"
exit 1
fi
vecho -n "Writing file to ecryptfs..... "
write_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
vecho -n "Remounting ecryptfs.......... "
umount_ecryptfs
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error remounting ecryptfs with passphrase option [$i] [$?]"
exit 1
fi
vecho -n "Reading file from ecrytpfs... "
read_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
umount_ecryptfs
done
vecho "--"
echo "done"
}
# We should return errno from calls to libecryptfs functions.
function mount_bad_passphrase {
for i in "passwd=" "passfile="; do
vecho -n "Performing mount with bad passphrase option [$i]: "
mount_opts="key=passphrase:$i:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
expected_retval=234
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Return code differed from what was expected [$i]"
umount_ecryptfs
exit 1
fi
done
echo "done"
}
function mount_ciphers {
for i in "aes" "cast5" "cast6" "blowfish" "twofish" "des3_ede" ""; do
vecho "--"
vecho -n "Performing mount with cipher [$i]: "
if [ "$i" == "des3_ede" ]; then
keysize=24
else
keysize=16
fi
mount_opts="key=passphrase:passwd=t:verbosity=0,ecryptfs_key_bytes=$keysize,ecryptfs_cipher=$i"
expected_retval=0
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error mounting ecryptfs with cipher [$i]"
exit 1
fi
vecho -n "Writing file to ecryptfs..... "
write_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
vecho -n "Remounting ecryptfs.......... "
umount_ecryptfs
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error remounting ecryptfs with cipher [$i]"
exit 1
fi
vecho -n "Reading file from ecrytpfs... "
read_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
umount_ecryptfs
done
vecho "--"
echo "done"
}
function mount_bad_ciphers {
for i in "aesaaaaaaa" "bbbaes" "xxxaesyyy" "abcdefghijklmnopqrstuvwxyzabcdefghijkl"; do
vecho -n "Performing mount with incorrect cipher [$i]: "
mount_opts="key=passphrase:passwd=t:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=$i"
expected_retval=234
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Mount should have failed with cipher [$i]"
umount_ecryptfs
exit 1
fi
done
echo "done"
}
# Salts need to be hex values if a non hex value is specified 0 is used
# we should probably clarify that we are requesting a hex value
function mount_salt {
for i in "" "a" "12345678" "0xdeadbeefdeadbeefdeadbeef" "ghijklmn" "sdflajsdflksjdaflsdjk" ""; do
vecho "--"
vecho "Performing mount with salt [$i]"
mount_opts="key=passphrase:passwd=t:salt=$i:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
expected_retval=0
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error mounting ecryptfs with salt [$i]"
exit 1
fi
vecho -n "Writing file to ecryptfs..... "
write_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
vecho -n "Remounting ecryptfs.......... "
umount_ecryptfs
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error remounting ecryptfs with salt [$i]"
exit 1
fi
vecho -n "Reading file from ecrytpfs... "
read_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
umount_ecryptfs
done
vecho "--"
echo "done"
}
# SSL keyfile mounts
function mount_keyfile {
for i in "openssl" "openssl" "openssl"; do
vecho "--"
vecho -n "Performing mount with key file [$i]: "
keyfile=$PASSWD_DIR/$i/key.pem
if [ ! -e $keyfile ]; then
echo "FAILED"
echo "Error: no $i key file found. Please create $keyfile with password = t, by running ecryptfs-manager"
exit 1
fi
mount_opts="key=openssl:passwd=t:keyfile=$keyfile:verbosity=0,ecryptfs_key_bytes=16,ecryptfs_cipher=aes"
expected_retval=0
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error mounting ecryptfs with key file [$i]"
exit 1
fi
vecho -n "Writing file to ecryptfs..... "
write_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: write error" && exit 1)
vecho -n "Remounting ecryptfs.......... "
umount_ecryptfs
do_mount $mount_opts $expected_retval
if [ "$?" -ne 0 ]; then
echo "FAILED"
echo "Error remounting ecryptfs with key file [$i]"
exit 1
fi
vecho -n "Reading file from ecrytpfs... "
read_file $i
[ $? -eq 0 ] && vecho "ok" || (echo "FAILED: read error" && exit 1)
umount_ecryptfs
done
vecho "--"
echo "done"
}
function clean_up_tests {
rm -f $PASSWD_PATH
}
echo "Running non-interactive mount tests"
vecho "Making directories"
mkdirs
vecho "Writing temporary files"
write_tmp_files
vecho "Cleaning out source directory"
clean_src
echo -n "Testing Passphrase Modes....... "
vecho ""
mount_passphrase
vecho ""
echo -n "Testing Invalid Passphrases.... "
vecho ""
mount_bad_passphrase
vecho ""
echo -n "Testing Cipher Modes........... "
vecho ""
mount_ciphers
vecho ""
echo -n "Testing Invalid Ciphers........ "
vecho ""
mount_bad_ciphers
vecho ""
echo -n "Testing Salts.................. "
vecho ""
mount_salt
vecho ""
echo -n "Testing Keyfile Modes.......... "
vecho ""
mount_keyfile
vecho ""
vecho "Cleaning up"
clean_up_tests
echo "All tests completed successfully"
echo ""
|