Path: blob/main/tests/sys/geom/class/eli/setkey_test.sh
39635 views
#!/bin/sh12. $(atf_get_srcdir)/conf.sh34atf_test_case setkey cleanup5setkey_head()6{7atf_set "descr" "geli setkey can change the key for an existing provider"8atf_set "require.user" "root"9}10setkey_body()11{12geli_test_setup1314sectors=10015attach_md md -t malloc -s `expr $sectors + 1`1617atf_check dd if=/dev/random of=rnd bs=512 count=${sectors} status=none18hash1=`dd if=rnd bs=512 count=${sectors} status=none | md5`19atf_check_equal 0 $?20atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none21atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none22atf_check dd if=/dev/random of=keyfile3 bs=512 count=16 status=none23atf_check dd if=/dev/random of=keyfile4 bs=512 count=16 status=none24atf_check dd if=/dev/random of=keyfile5 bs=512 count=16 status=none2526atf_check geli init -B none -P -K keyfile1 ${md}27atf_check geli attach -p -k keyfile1 ${md}2829atf_check \30dd if=rnd of=/dev/${md}.eli bs=512 count=${sectors} status=none31hash2=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`32atf_check_equal 0 $?3334# Change current key (0) for attached provider.35atf_check -s exit:0 -o ignore geli setkey -P -K keyfile2 ${md}36atf_check geli detach ${md}3738# We cannot use keyfile1 anymore.39atf_check -s not-exit:0 -e match:"Wrong key" \40geli attach -p -k keyfile1 ${md}4142# Attach with new key.43atf_check geli attach -p -k keyfile2 ${md}44hash3=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`45atf_check_equal 0 $?4647# Change key 1 for attached provider.48atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile3 ${md}49atf_check geli detach ${md}5051# Attach with key 1.52atf_check geli attach -p -k keyfile3 ${md}53hash4=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`54atf_check_equal 0 $?55atf_check geli detach ${md}5657# Change current (1) key for detached provider.58atf_check -s exit:0 -o ignore geli setkey -p -k keyfile3 -P -K keyfile4 ${md}5960# We cannot use keyfile3 anymore.61atf_check -s not-exit:0 -e match:"Wrong key" \62geli attach -p -k keyfile3 ${md}6364# Attach with key 1.65atf_check geli attach -p -k keyfile4 ${md}66hash5=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`67atf_check_equal 0 $?68atf_check geli detach ${md}6970# Change key 0 for detached provider.71atf_check -s exit:0 -o ignore geli setkey -n 0 -p -k keyfile4 -P -K keyfile5 ${md}7273# We cannot use keyfile2 anymore.74atf_check -s not-exit:0 -e match:"Wrong key" \75geli attach -p -k keyfile2 ${md} 2>/dev/null7677# Attach with key 0.78atf_check geli attach -p -k keyfile5 ${md}79hash6=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`80atf_check_equal 0 $?81atf_check geli detach ${md}8283atf_check_equal ${hash1} ${hash2}84atf_check_equal ${hash1} ${hash3}85atf_check_equal ${hash1} ${hash4}86atf_check_equal ${hash1} ${hash5}87atf_check_equal ${hash1} ${hash6}88}89setkey_cleanup()90{91geli_test_cleanup92}9394atf_test_case setkey_passphrase cleanup95setkey_passphrase_head()96{97atf_set "descr" "geli setkey can change the passphrase for a provider"98atf_set "require.user" "root"99}100setkey_passphrase_body()101{102geli_test_setup103104sectors=100105attach_md md -t malloc -s `expr $sectors + 1`106107atf_check dd if=/dev/random of=rnd bs=512 count=${sectors} status=none108hash1=`dd if=rnd bs=512 count=${sectors} status=none | md5`109atf_check_equal 0 $?110atf_check dd if=/dev/random of=pass1 bs=512 count=1 status=none111atf_check dd if=/dev/random of=pass2 bs=512 count=1 status=none112atf_check dd if=/dev/random of=pass3 bs=512 count=1 status=none113114atf_check geli init -B none -J pass1 ${md}115atf_check geli attach -j pass1 ${md}116117atf_check \118dd if=rnd of=/dev/${md}.eli bs=512 count=${sectors} status=none119hash2=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`120atf_check_equal 0 $?121122atf_check geli detach ${md}123124# Change from passphrase 1 to passphrase 2 for the detached provider.125atf_check -s exit:0 -o ignore geli setkey -j pass1 -J pass2 ${md}126127# Make sure that we can attach with passphrase 2 but not with128# passphrase 1.129atf_check -s not-exit:0 -e match:"Wrong key" \130geli attach -j pass1 ${md}131atf_check -s exit:0 geli attach -j pass2 ${md}132hash3=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`133134# Change from passphrase 2 to passphrase 3 for the attached provider.135atf_check -s exit:0 -o ignore geli setkey -j pass2 -J pass3 ${md}136hash4=`dd if=/dev/${md}.eli bs=512 count=${sectors} 2>/dev/null | md5`137atf_check geli detach ${md}138139# Make sure that we cannot attach with passphrase 2 anymore.140atf_check -s not-exit:0 -e match:"Wrong key" \141geli attach -j pass2 ${md}142143atf_check_equal ${hash1} ${hash2}144atf_check_equal ${hash1} ${hash3}145atf_check_equal ${hash1} ${hash4}146}147setkey_passphrase_cleanup()148{149geli_test_cleanup150}151152atf_test_case setkey_readonly cleanup153setkey_readonly_head()154{155atf_set "descr" "geli setkey cannot change the keys of a readonly provider"156atf_set "require.user" "root"157}158setkey_readonly_body()159{160geli_test_setup161162sectors=100163attach_md md -t malloc -s `expr $sectors + 1`164atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none165166atf_check geli init -B none -P -K keyfile ${md}167atf_check geli attach -r -p -k keyfile ${md}168169atf_check -s not-exit:0 -e match:"read-only" \170geli setkey -n 1 -P -K /dev/null ${md}171}172setkey_readonly_cleanup()173{174geli_test_cleanup175}176177atf_test_case nokey cleanup178nokey_head()179{180atf_set "descr" "geli setkey can change the key for an existing provider"181atf_set "require.user" "root"182}183nokey_body()184{185geli_test_setup186187sectors=100188attach_md md -t malloc -s `expr $sectors + 1`189atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none190atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none191192atf_check geli init -B none -P -K keyfile1 ${md}193194# Try to set the key for a detached device without providing any195# components for the old key.196atf_check -s not-exit:0 -e match:"No key components given" \197geli setkey -n 0 -p -P -K keyfile2 ${md}198199# Try to set the key for a detached device without providing any200# components for the new key201atf_check -s not-exit:0 -e match:"No key components given" \202geli setkey -n 0 -p -k keyfile1 -P ${md}203204# Try to set a new key for an attached device with no components205atf_check geli attach -p -k keyfile1 ${md}206atf_check -s not-exit:0 -e match:"No key components given" \207geli setkey -n 0 -P ${md}208}209nokey_cleanup()210{211geli_test_cleanup212}213214atf_init_test_cases()215{216atf_add_test_case setkey217atf_add_test_case setkey_passphrase218atf_add_test_case setkey_readonly219atf_add_test_case nokey220}221222223