4 . $(atf_get_srcdir)/conf.sh
6 atf_test_case delkey cleanup
9 atf_set "descr" "geli delkey can destroy the master key"
10 atf_set "require.user" "root"
17 md=$(attach_md -t malloc -s `expr $sectors + 1`)
19 atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none
20 atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none
21 atf_check dd if=/dev/random of=keyfile3 bs=512 count=16 status=none
22 atf_check dd if=/dev/random of=keyfile4 bs=512 count=16 status=none
24 atf_check geli init -B none -P -K keyfile1 ${md}
25 atf_check geli attach -p -k keyfile1 ${md}
26 atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile2 ${md}
28 # Remove key 0 for attached provider.
29 atf_check geli delkey -n 0 ${md}
30 atf_check geli detach ${md}
32 # We cannot use keyfile1 anymore.
33 atf_check -s not-exit:0 -e match:"Wrong key" \
34 geli attach -p -k keyfile1 ${md}
37 atf_check geli attach -p -k keyfile2 ${md}
39 # We cannot remove last key without -f option (for attached provider).
40 atf_check -s not-exit:0 -e match:"This is the last Master Key" \
41 geli delkey -n 1 ${md}
43 # Remove last key for attached provider.
44 atf_check geli delkey -f -n 1 ${md}
46 # If there are no valid keys, but provider is attached, we can save situation.
47 atf_check -s exit:0 -o ignore geli setkey -n 0 -P -K keyfile3 ${md}
48 atf_check geli detach ${md}
50 # We cannot use keyfile2 anymore.
51 atf_check -s not-exit:0 -e match:"Wrong key" \
52 geli attach -p -k keyfile2 ${md}
55 atf_check geli attach -p -k keyfile3 ${md}
58 atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile4 ${md}
59 atf_check geli detach ${md}
61 # Remove key 1 for detached provider.
62 atf_check geli delkey -n 1 ${md}
64 # We cannot use keyfile4 anymore.
65 atf_check -s not-exit:0 -e match:"Wrong key" \
66 geli attach -p -k keyfile4 ${md}
68 # We cannot remove last key without -f option (for detached provider).
69 atf_check -s not-exit:0 -e match:"This is the last Master Key" \
70 geli delkey -n 0 ${md}
72 # Remove last key for detached provider.
73 atf_check geli delkey -f -n 0 ${md}
75 # We cannot use keyfile3 anymore.
76 atf_check -s not-exit:0 -e match:"No valid keys" \
77 geli attach -p -k keyfile3 ${md}
84 atf_test_case delkey_readonly cleanup
85 delkey_readonly_head()
87 atf_set "descr" "geli delkey cannot work on a read-only provider"
88 atf_set "require.user" "root"
90 delkey_readonly_body()
95 md=$(attach_md -t malloc -s `expr $sectors + 1`)
96 atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none
98 atf_check geli init -B none -P -K keyfile ${md}
99 atf_check geli attach -r -p -k keyfile ${md}
101 atf_check -s not-exit:0 -e match:"read-only" geli delkey -n 0 ${md}
102 # Even with -f (force) it should still fail
103 atf_check -s not-exit:0 -e match:"read-only" geli delkey -f -n 0 ${md}
105 delkey_readonly_cleanup()
110 atf_init_test_cases()
112 atf_add_test_case delkey
113 atf_add_test_case delkey_readonly