~ubuntu-branches/debian/sid/ecryptfs-utils/sid

« back to all changes in this revision

Viewing changes to src/testcases/noninteractive.sh

  • Committer: Bazaar Package Importer
  • Author(s): William Lima
  • Date: 2007-05-09 16:21:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070509162123-b2ge8a5w7weqt5ea
Tags: upstream-15
ImportĀ upstreamĀ versionĀ 15

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
 
 
11
function mkdirs {
 
12
    mkdir -p $SRC_DIR
 
13
    mkdir -p $DST_DIR
 
14
    mkdir -p $PASSWD_DIR
 
15
}
 
16
 
 
17
function write_tmp_files {
 
18
    echo "passwd=t" > $PASSWD_PATH
 
19
}
 
20
 
 
21
function clean_src {
 
22
    if [ "x$SRC_DIR" == "x" ]; then
 
23
        echo "SRC_DIR is empty"
 
24
        exit 1
 
25
    else
 
26
        if [ "x$SRC_DIR" == "x/" ]; then
 
27
            echo "SRC_DIR is root; probably not what you want"
 
28
            exit 1
 
29
        else
 
30
            rm -rf $SRC_DIR/*
 
31
        fi
 
32
    fi
 
33
}
 
34
 
 
35
function mount_passphrase {
 
36
    mount -t ecryptfs $SRC_DIR $DST_DIR -o key=passphrase,cipher=aes,verbosity=0
 
37
}
 
38
 
 
39
function remount_ro {
 
40
    mount -i -o remount,ro $DST_DIR
 
41
}
 
42
 
 
43
function umount_ecryptfs {
 
44
    umount $DST_DIR
 
45
}
 
46
 
 
47
function mkdir_clean_mount_passphrase {
 
48
    for i in "passwd=t" "passfile=$HOME_DIR/.ecryptfs/pki/passwd"; do
 
49
            echo "Performing mount with passphrase option [$i]"
 
50
            /sbin/mount.ecryptfs $SRC_DIR $DST_DIR -o key=passphrase:$i,cipher=aes,verbosity=0 > /dev/null
 
51
            if [ $? -eq 0 ]
 
52
            then
 
53
                echo "ok"
 
54
            else
 
55
                echo "Error mounting ecryptfs with passphrase option [$i] [$?]"
 
56
                exit 1
 
57
            fi
 
58
            umount_ecryptfs
 
59
    done
 
60
}
 
61
 
 
62
#we should return errno from calls to libecryptfs functions.
 
63
function mkdir_clean_mount_bad_passphrase {
 
64
    for i in "passwd=" "passfile="; do
 
65
            echo "Performing mount with passphrase option [$i]"
 
66
            /sbin/mount.ecryptfs $SRC_DIR $DST_DIR -o key=passphrase:$i,cipher=aes,verbosity=0 > /dev/null
 
67
            if [ $? -eq 234 ]
 
68
            then
 
69
                echo "ok"
 
70
            else
 
71
                echo "Return code differed from what was expected [$i]"
 
72
                umount_ecryptfs
 
73
                exit 1
 
74
            fi
 
75
    done
 
76
}
 
77
 
 
78
function mkdir_clean_mount_ciphers {
 
79
    for i in "aes" "des" "cast5" "cast6" "blowfish" "twofish" "des3_ede" ""; do
 
80
            echo "Performing mount with cipher [$i]"
 
81
            /sbin/mount.ecryptfs $SRC_DIR $DST_DIR -o key=passphrase:passwd=t,cipher=$i,verbosity=0 > /dev/null
 
82
            if [ $? -eq 0 ]
 
83
            then
 
84
                echo "ok"
 
85
            else
 
86
                echo "Error mounting ecryptfs with cipher [$i]"
 
87
                exit 1
 
88
            fi
 
89
            umount_ecryptfs
 
90
    done
 
91
}
 
92
 
 
93
function mkdir_clean_mount_bad_ciphers {
 
94
    for i in "aesaaaaaaa" "bbbaes" "xxxaesyyy"; do
 
95
            echo "Performing mount with incorrect cipher [$i]"
 
96
            /sbin/mount.ecryptfs $SRC_DIR $DST_DIR -o key=passphrase:passwd=t,cipher=$i,verbosity=0 > /dev/null
 
97
            if [ $? -eq 234 ]
 
98
            then
 
99
                echo "ok"
 
100
            else
 
101
                echo "Mount should have failed with cipher [$i]"
 
102
                umount_ecryptfs
 
103
                exit
 
104
            fi
 
105
    done
 
106
}
 
107
 
 
108
#Salts need to be hex values if a non hex value is specified 0 is used
 
109
#we should probably clarify that we are requesting a hex value
 
110
function mkdir_clean_mount_salt {
 
111
    for i in "" "a" "12345678" "0xdeadbeefdeadbeefdeadbeef" "ghijklmn" "sdflajsdflksjdaflsdjk" ""; do
 
112
            echo "Performing mount with salt [$i]"
 
113
            /sbin/mount.ecryptfs $SRC_DIR $DST_DIR -o key=passphrase:passwd=t:salt=$i,cipher=aes,verbosity=0 > /dev/null
 
114
            if [ $? -eq 0 ]
 
115
            then
 
116
                echo "ok"
 
117
            else
 
118
                echo "Error mounting ecryptfs with salt [$i]"
 
119
                exit 1
 
120
            fi
 
121
            umount_ecryptfs
 
122
    done
 
123
}
 
124
 
 
125
function clean_up_tests {
 
126
    rm -f $PASSWD_PATH
 
127
}
 
128
 
 
129
echo "Running non-interactive mount tests"
 
130
echo "Passphrase mount"
 
131
 
 
132
echo "Making directories"
 
133
mkdirs
 
134
echo "Writing temporary files"
 
135
write_tmp_files
 
136
echo "Cleaning out source directory"
 
137
clean_src
 
138
echo "Testing Passphrase Modes"
 
139
mkdir_clean_mount_passphrase
 
140
mkdir_clean_mount_bad_passphrase
 
141
echo ""
 
142
echo "Testing Cipher Modes"
 
143
mkdir_clean_mount_ciphers
 
144
mkdir_clean_mount_bad_ciphers
 
145
echo ""
 
146
echo "Testing Salts"
 
147
mkdir_clean_mount_salt
 
148
echo ""
 
149
echo "Cleaning up"
 
150
clean_up_tests