~mrooney/ecryptfs/nautilus-integration

« back to all changes in this revision

Viewing changes to src/testcases/ecryptfs-noninteractive-tests.sh

  • Committer: mhalcrow@us.ibm.com
  • Date: 2007-11-06 22:56:01 UTC
  • Revision ID: git-v1:f8357de9d554b274497b5cce9db4347254b7e7eb
Initial import of eCryptfs filesystem userspace utilities (mount helper, daemon component,
etc.)

Show diffs side-by-side

added added

removed removed

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