setkey_test.sh revision 182452
1#!/bin/sh
2# $FreeBSD: head/tools/regression/geom_eli/setkey.t 182452 2008-08-29 18:10:18Z pjd $
3
4base=`basename $0`
5no=45
6sectors=100
7rnd=`mktemp /tmp/$base.XXXXXX` || exit 1
8keyfile1=`mktemp /tmp/$base.XXXXXX` || exit 1
9keyfile2=`mktemp /tmp/$base.XXXXXX` || exit 1
10keyfile3=`mktemp /tmp/$base.XXXXXX` || exit 1
11keyfile4=`mktemp /tmp/$base.XXXXXX` || exit 1
12keyfile5=`mktemp /tmp/$base.XXXXXX` || exit 1
13mdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1
14
15echo "1..16"
16
17dd if=/dev/random of=${rnd} bs=512 count=${sectors} >/dev/null 2>&1
18hash1=`dd if=${rnd} bs=512 count=${sectors} 2>/dev/null | md5`
19dd if=/dev/random of=${keyfile1} bs=512 count=16 >/dev/null 2>&1
20dd if=/dev/random of=${keyfile2} bs=512 count=16 >/dev/null 2>&1
21dd if=/dev/random of=${keyfile3} bs=512 count=16 >/dev/null 2>&1
22dd if=/dev/random of=${keyfile4} bs=512 count=16 >/dev/null 2>&1
23dd if=/dev/random of=${keyfile5} bs=512 count=16 >/dev/null 2>&1
24
25geli init -B none -P -K $keyfile1 md${no}
26geli attach -p -k $keyfile1 md${no}
27
28dd if=${rnd} of=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null
29rm -f $rnd
30hash2=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
31
32# Change current key (0) for attached provider.
33geli setkey -P -K $keyfile2 md${no}
34if [ $? -eq 0 ]; then
35	echo "ok 1"
36else
37	echo "not ok 1"
38fi
39geli detach md${no}
40
41# We cannot use keyfile1 anymore.
42geli attach -p -k $keyfile1 md${no} 2>/dev/null
43if [ $? -ne 0 ]; then
44	echo "ok 2"
45else
46	echo "not ok 2"
47fi
48
49# Attach with new key.
50geli attach -p -k $keyfile2 md${no}
51if [ $? -eq 0 ]; then
52	echo "ok 3"
53else
54	echo "not ok 3"
55fi
56hash3=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
57
58# Change key 1 for attached provider.
59geli setkey -n 1 -P -K $keyfile3 md${no}
60if [ $? -eq 0 ]; then
61	echo "ok 4"
62else
63	echo "not ok 4"
64fi
65geli detach md${no}
66
67# Attach with key 1.
68geli attach -p -k $keyfile3 md${no}
69if [ $? -eq 0 ]; then
70	echo "ok 5"
71else
72	echo "not ok 5"
73fi
74hash4=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
75geli detach md${no}
76
77# Change current (1) key for detached provider.
78geli setkey -p -k $keyfile3 -P -K $keyfile4 md${no}
79if [ $? -eq 0 ]; then
80	echo "ok 6"
81else
82	echo "not ok 6"
83fi
84
85# We cannot use keyfile3 anymore.
86geli attach -p -k $keyfile3 md${no} 2>/dev/null
87if [ $? -ne 0 ]; then
88	echo "ok 7"
89else
90	echo "not ok 7"
91fi
92
93# Attach with key 1.
94geli attach -p -k $keyfile4 md${no}
95if [ $? -eq 0 ]; then
96	echo "ok 8"
97else
98	echo "not ok 8"
99fi
100hash5=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
101geli detach md${no}
102
103# Change key 0 for detached provider.
104geli setkey -n 0 -p -k $keyfile4 -P -K $keyfile5 md${no}
105if [ $? -eq 0 ]; then
106	echo "ok 9"
107else
108	echo "not ok 9"
109fi
110
111# We cannot use keyfile2 anymore.
112geli attach -p -k $keyfile2 md${no} 2>/dev/null
113if [ $? -ne 0 ]; then
114	echo "ok 10"
115else
116	echo "not ok 10"
117fi
118
119# Attach with key 0.
120geli attach -p -k $keyfile5 md${no}
121if [ $? -eq 0 ]; then
122	echo "ok 11"
123else
124	echo "not ok 11"
125fi
126hash6=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5`
127geli detach md${no}
128
129if [ ${hash1} = ${hash2} ]; then
130	echo "ok 12"
131else
132	echo "not ok 12"
133fi
134if [ ${hash1} = ${hash3} ]; then
135	echo "ok 13"
136else
137	echo "not ok 13"
138fi
139if [ ${hash1} = ${hash4} ]; then
140	echo "ok 14"
141else
142	echo "not ok 14"
143fi
144if [ ${hash1} = ${hash5} ]; then
145	echo "ok 15"
146else
147	echo "not ok 15"
148fi
149if [ ${hash1} = ${hash6} ]; then
150	echo "ok 16"
151else
152	echo "not ok 16"
153fi
154
155mdconfig -d -u $no
156rm -f $keyfile1 $keyfile2 $keyfile3 $keyfile4 $keyfile5
157