4 atf_test_case setkey cleanup
7 atf_set "descr" "geli setkey can change the key for an existing provider"
8 atf_set "require.user" "root"
12 . $(atf_get_srcdir)/conf.sh
15 md=$(attach_md -t malloc -s `expr $sectors + 1`)
17 atf_check dd if=/dev/random of=rnd bs=512 count=${sectors} status=none
18 hash1=`dd if=rnd bs=512 count=${sectors} status=none | md5`
20 atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
21 atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
22 atf_check dd if=/dev/random of=keyfile3 bs=512 count=16 status=none
23 atf_check dd if=/dev/random of=keyfile4 bs=512 count=16 status=none
24 atf_check dd if=/dev/random of=keyfile5 bs=512 count=16 status=none
26 atf_check geli init -B none -P -K keyfile1 ${md}
27 atf_check geli attach -p -k keyfile1 ${md}
30 dd if=rnd of=/dev/${md}.eli bs=512 count=${sectors} status=none
31 hash2=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`
34 # Change current key (0) for attached provider.
35 atf_check -s exit:0 -o ignore geli setkey -P -K keyfile2 ${md}
36 atf_check geli detach ${md}
38 # We cannot use keyfile1 anymore.
39 atf_check -s not-exit:0 -e match:"Wrong key" \
40 geli attach -p -k keyfile1 ${md}
42 # Attach with new key.
43 atf_check geli attach -p -k keyfile2 ${md}
44 hash3=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`
47 # Change key 1 for attached provider.
48 atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile3 ${md}
49 atf_check geli detach ${md}
52 atf_check geli attach -p -k keyfile3 ${md}
53 hash4=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`
55 atf_check geli detach ${md}
57 # Change current (1) key for detached provider.
58 atf_check -s exit:0 -o ignore geli setkey -p -k keyfile3 -P -K keyfile4 ${md}
60 # We cannot use keyfile3 anymore.
61 atf_check -s not-exit:0 -e match:"Wrong key" \
62 geli attach -p -k keyfile3 ${md}
65 atf_check geli attach -p -k keyfile4 ${md}
66 hash5=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`
68 atf_check geli detach ${md}
70 # Change key 0 for detached provider.
71 atf_check -s exit:0 -o ignore geli setkey -n 0 -p -k keyfile4 -P -K keyfile5 ${md}
73 # We cannot use keyfile2 anymore.
74 atf_check -s not-exit:0 -e match:"Wrong key" \
75 geli attach -p -k keyfile2 ${md} 2>/dev/null
78 atf_check geli attach -p -k keyfile5 ${md}
79 hash6=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`
81 atf_check geli detach ${md}
83 atf_check_equal ${hash1} ${hash2}
84 atf_check_equal ${hash1} ${hash3}
85 atf_check_equal ${hash1} ${hash4}
86 atf_check_equal ${hash1} ${hash5}
87 atf_check_equal ${hash1} ${hash6}
91 . $(atf_get_srcdir)/conf.sh
95 atf_test_case setkey_readonly cleanup
96 setkey_readonly_head()
98 atf_set "descr" "geli setkey cannot change the keys of a readonly provider"
99 atf_set "require.user" "root"
101 setkey_readonly_body()
103 . $(atf_get_srcdir)/conf.sh
106 md=$(attach_md -t malloc -s `expr $sectors + 1`)
107 atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
109 atf_check geli init -B none -P -K keyfile ${md}
110 atf_check geli attach -r -p -k keyfile ${md}
112 atf_check -s not-exit:0 -e match:"read-only" \
113 geli setkey -n 1 -P -K /dev/null ${md}
115 setkey_readonly_cleanup()
117 . $(atf_get_srcdir)/conf.sh
121 atf_test_case nokey cleanup
124 atf_set "descr" "geli setkey can change the key for an existing provider"
125 atf_set "require.user" "root"
129 . $(atf_get_srcdir)/conf.sh
132 md=$(attach_md -t malloc -s `expr $sectors + 1`)
133 atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
134 atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
136 atf_check geli init -B none -P -K keyfile1 ${md}
138 # Try to set the key for a detached device without providing any
139 # components for the old key.
140 atf_check -s not-exit:0 -e match:"No key components given" \
141 geli setkey -n 0 -p -P -K keyfile2 ${md}
143 # Try to set the key for a detached device without providing any
144 # components for the new key
145 atf_check -s not-exit:0 -e match:"No key components given" \
146 geli setkey -n 0 -p -k keyfile1 -P ${md}
148 # Try to set a new key for an attached device with no components
149 atf_check geli attach -p -k keyfile1 ${md}
150 atf_check -s not-exit:0 -e match:"No key components given" \
151 geli setkey -n 0 -P ${md}
155 . $(atf_get_srcdir)/conf.sh
159 atf_init_test_cases()
161 atf_add_test_case setkey
162 atf_add_test_case setkey_readonly
163 atf_add_test_case nokey