Path: blob/main/tests/sys/geom/class/eli/delkey_test.sh
39636 views
#!/bin/sh12. $(atf_get_srcdir)/conf.sh34atf_test_case delkey cleanup5delkey_head()6{7atf_set "descr" "geli delkey can destroy the master key"8atf_set "require.user" "root"9}10delkey_body()11{12geli_test_setup1314sectors=10015attach_md md -t malloc -s `expr $sectors + 1`1617atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none18atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none19atf_check dd if=/dev/random of=keyfile3 bs=512 count=16 status=none20atf_check dd if=/dev/random of=keyfile4 bs=512 count=16 status=none2122atf_check geli init -B none -P -K keyfile1 ${md}23atf_check geli attach -p -k keyfile1 ${md}24atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile2 ${md}2526# Remove key 0 for attached provider.27atf_check geli delkey -n 0 ${md}28atf_check geli detach ${md}2930# We cannot use keyfile1 anymore.31atf_check -s not-exit:0 -e match:"Wrong key" \32geli attach -p -k keyfile1 ${md}3334# Attach with key 1.35atf_check geli attach -p -k keyfile2 ${md}3637# We cannot remove last key without -f option (for attached provider).38atf_check -s not-exit:0 -e match:"This is the last Master Key" \39geli delkey -n 1 ${md}4041# Remove last key for attached provider.42atf_check geli delkey -f -n 1 ${md}4344# If there are no valid keys, but provider is attached, we can save situation.45atf_check -s exit:0 -o ignore geli setkey -n 0 -P -K keyfile3 ${md}46atf_check geli detach ${md}4748# We cannot use keyfile2 anymore.49atf_check -s not-exit:0 -e match:"Wrong key" \50geli attach -p -k keyfile2 ${md}5152# Attach with key 0.53atf_check geli attach -p -k keyfile3 ${md}5455# Setup key 1.56atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile4 ${md}57atf_check geli detach ${md}5859# Remove key 1 for detached provider.60atf_check geli delkey -n 1 ${md}6162# We cannot use keyfile4 anymore.63atf_check -s not-exit:0 -e match:"Wrong key" \64geli attach -p -k keyfile4 ${md}6566# We cannot remove last key without -f option (for detached provider).67atf_check -s not-exit:0 -e match:"This is the last Master Key" \68geli delkey -n 0 ${md}6970# Remove last key for detached provider.71atf_check geli delkey -f -n 0 ${md}7273# We cannot use keyfile3 anymore.74atf_check -s not-exit:0 -e match:"No valid keys" \75geli attach -p -k keyfile3 ${md}76}77delkey_cleanup()78{79geli_test_cleanup80}8182atf_test_case delkey_readonly cleanup83delkey_readonly_head()84{85atf_set "descr" "geli delkey cannot work on a read-only provider"86atf_set "require.user" "root"87}88delkey_readonly_body()89{90geli_test_setup9192sectors=10093attach_md md -t malloc -s `expr $sectors + 1`94atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none9596atf_check geli init -B none -P -K keyfile ${md}97atf_check geli attach -r -p -k keyfile ${md}9899atf_check -s not-exit:0 -e match:"read-only" geli delkey -n 0 ${md}100# Even with -f (force) it should still fail101atf_check -s not-exit:0 -e match:"read-only" geli delkey -f -n 0 ${md}102}103delkey_readonly_cleanup()104{105geli_test_cleanup106}107108atf_init_test_cases()109{110atf_add_test_case delkey111atf_add_test_case delkey_readonly112}113114115