delkey_test.sh revision 328811
1148459Spjd#!/bin/sh 2148459Spjd# $FreeBSD: stable/11/tests/sys/geom/class/eli/delkey_test.sh 328811 2018-02-02 21:57:00Z asomers $ 3148459Spjd 4328811Sasomersatf_test_case delkey cleanup 5328811Sasomersdelkey_head() 6328811Sasomers{ 7328811Sasomers atf_set "descr" "geli delkey can destroy the master key" 8328811Sasomers atf_set "require.user" "root" 9328811Sasomers} 10328811Sasomersdelkey_body() 11328811Sasomers{ 12328811Sasomers . $(atf_get_srcdir)/conf.sh 13293436Sngie 14328811Sasomers sectors=100 15328811Sasomers md=$(attach_md -t malloc -s `expr $sectors + 1`) 16148459Spjd 17328811Sasomers atf_check dd if=/dev/random of=keyfile1 bs=512 count=16 status=none 18328811Sasomers atf_check dd if=/dev/random of=keyfile2 bs=512 count=16 status=none 19328811Sasomers atf_check dd if=/dev/random of=keyfile3 bs=512 count=16 status=none 20328811Sasomers atf_check dd if=/dev/random of=keyfile4 bs=512 count=16 status=none 21148459Spjd 22328811Sasomers atf_check geli init -B none -P -K keyfile1 ${md} 23328811Sasomers atf_check geli attach -p -k keyfile1 ${md} 24328811Sasomers atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile2 ${md} 25148459Spjd 26328811Sasomers # Remove key 0 for attached provider. 27328811Sasomers atf_check geli delkey -n 0 ${md} 28328811Sasomers atf_check geli detach ${md} 29148459Spjd 30328811Sasomers # We cannot use keyfile1 anymore. 31328811Sasomers atf_check -s not-exit:0 -e match:"Wrong key" \ 32328811Sasomers geli attach -p -k keyfile1 ${md} 33148459Spjd 34328811Sasomers # Attach with key 1. 35328811Sasomers atf_check geli attach -p -k keyfile2 ${md} 36148459Spjd 37328811Sasomers # We cannot remove last key without -f option (for attached provider). 38328811Sasomers atf_check -s not-exit:0 -e match:"This is the last Master Key" \ 39328811Sasomers geli delkey -n 1 ${md} 40148459Spjd 41328811Sasomers # Remove last key for attached provider. 42328811Sasomers atf_check geli delkey -f -n 1 ${md} 43148459Spjd 44328811Sasomers # If there are no valid keys, but provider is attached, we can save situation. 45328811Sasomers atf_check -s exit:0 -o ignore geli setkey -n 0 -P -K keyfile3 ${md} 46328811Sasomers atf_check geli detach ${md} 47148459Spjd 48328811Sasomers # We cannot use keyfile2 anymore. 49328811Sasomers atf_check -s not-exit:0 -e match:"Wrong key" \ 50328811Sasomers geli attach -p -k keyfile2 ${md} 51148459Spjd 52328811Sasomers # Attach with key 0. 53328811Sasomers atf_check geli attach -p -k keyfile3 ${md} 54148459Spjd 55328811Sasomers # Setup key 1. 56328811Sasomers atf_check -s exit:0 -o ignore geli setkey -n 1 -P -K keyfile4 ${md} 57328811Sasomers atf_check geli detach ${md} 58148459Spjd 59328811Sasomers # Remove key 1 for detached provider. 60328811Sasomers atf_check geli delkey -n 1 ${md} 61148459Spjd 62328811Sasomers # We cannot use keyfile4 anymore. 63328811Sasomers atf_check -s not-exit:0 -e match:"Wrong key" \ 64328811Sasomers geli attach -p -k keyfile4 ${md} 65148459Spjd 66328811Sasomers # We cannot remove last key without -f option (for detached provider). 67328811Sasomers atf_check -s not-exit:0 -e match:"This is the last Master Key" \ 68328811Sasomers geli delkey -n 0 ${md} 69148459Spjd 70328811Sasomers # Remove last key for detached provider. 71328811Sasomers atf_check geli delkey -f -n 0 ${md} 72148459Spjd 73328811Sasomers # We cannot use keyfile3 anymore. 74328811Sasomers atf_check -s not-exit:0 -e match:"No valid keys" \ 75328811Sasomers geli attach -p -k keyfile3 ${md} 76328811Sasomers} 77328811Sasomersdelkey_cleanup() 78328811Sasomers{ 79328811Sasomers . $(atf_get_srcdir)/conf.sh 80328811Sasomers geli_test_cleanup 81328811Sasomers} 82148459Spjd 83328811Sasomersatf_test_case delkey_readonly cleanup 84328811Sasomersdelkey_readonly_head() 85328811Sasomers{ 86328811Sasomers atf_set "descr" "geli delkey cannot work on a read-only provider" 87328811Sasomers atf_set "require.user" "root" 88328811Sasomers} 89328811Sasomersdelkey_readonly_body() 90328811Sasomers{ 91328811Sasomers . $(atf_get_srcdir)/conf.sh 92148459Spjd 93328811Sasomers sectors=100 94328811Sasomers md=$(attach_md -t malloc -s `expr $sectors + 1`) 95328811Sasomers atf_check dd if=/dev/random of=keyfile bs=512 count=16 status=none 96328811Sasomers 97328811Sasomers atf_check geli init -B none -P -K keyfile ${md} 98328811Sasomers atf_check geli attach -r -p -k keyfile ${md} 99328811Sasomers 100328811Sasomers atf_check -s not-exit:0 -e match:"read-only" geli delkey -n 0 ${md} 101328811Sasomers # Even with -f (force) it should still fail 102328811Sasomers atf_check -s not-exit:0 -e match:"read-only" geli delkey -f -n 0 ${md} 103328811Sasomers} 104328811Sasomersdelkey_readonly_cleanup() 105328811Sasomers{ 106328811Sasomers . $(atf_get_srcdir)/conf.sh 107328811Sasomers geli_test_cleanup 108328811Sasomers} 109328811Sasomers 110328811Sasomersatf_init_test_cases() 111328811Sasomers{ 112328811Sasomers atf_add_test_case delkey 113328811Sasomers atf_add_test_case delkey_readonly 114328811Sasomers} 115