1#!/bin/sh 2# $FreeBSD$ 3 4. $(dirname $0)/conf.sh 5 6base=`basename $0` 7sectors=100 8rnd=`mktemp $base.XXXXXX` || exit 1 9keyfile1=`mktemp $base.XXXXXX` || exit 1 10keyfile2=`mktemp $base.XXXXXX` || exit 1 11keyfile3=`mktemp $base.XXXXXX` || exit 1 12keyfile4=`mktemp $base.XXXXXX` || exit 1 13keyfile5=`mktemp $base.XXXXXX` || exit 1 14mdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1 15 16echo "1..16" 17 18dd if=/dev/random of=${rnd} bs=512 count=${sectors} >/dev/null 2>&1 19hash1=`dd if=${rnd} bs=512 count=${sectors} 2>/dev/null | md5` 20dd if=/dev/random of=${keyfile1} bs=512 count=16 >/dev/null 2>&1 21dd if=/dev/random of=${keyfile2} bs=512 count=16 >/dev/null 2>&1 22dd if=/dev/random of=${keyfile3} bs=512 count=16 >/dev/null 2>&1 23dd if=/dev/random of=${keyfile4} bs=512 count=16 >/dev/null 2>&1 24dd if=/dev/random of=${keyfile5} bs=512 count=16 >/dev/null 2>&1 25 26geli init -B none -P -K $keyfile1 md${no} 27geli attach -p -k $keyfile1 md${no} 28 29dd if=${rnd} of=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null 30rm -f $rnd 31hash2=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5` 32 33# Change current key (0) for attached provider. 34geli setkey -P -K $keyfile2 md${no} 35if [ $? -eq 0 ]; then 36 echo "ok 1" 37else 38 echo "not ok 1" 39fi 40geli detach md${no} 41 42# We cannot use keyfile1 anymore. 43geli attach -p -k $keyfile1 md${no} 2>/dev/null 44if [ $? -ne 0 ]; then 45 echo "ok 2" 46else 47 echo "not ok 2" 48fi 49 50# Attach with new key. 51geli attach -p -k $keyfile2 md${no} 52if [ $? -eq 0 ]; then 53 echo "ok 3" 54else 55 echo "not ok 3" 56fi 57hash3=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5` 58 59# Change key 1 for attached provider. 60geli setkey -n 1 -P -K $keyfile3 md${no} 61if [ $? -eq 0 ]; then 62 echo "ok 4" 63else 64 echo "not ok 4" 65fi 66geli detach md${no} 67 68# Attach with key 1. 69geli attach -p -k $keyfile3 md${no} 70if [ $? -eq 0 ]; then 71 echo "ok 5" 72else 73 echo "not ok 5" 74fi 75hash4=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5` 76geli detach md${no} 77 78# Change current (1) key for detached provider. 79geli setkey -p -k $keyfile3 -P -K $keyfile4 md${no} 80if [ $? -eq 0 ]; then 81 echo "ok 6" 82else 83 echo "not ok 6" 84fi 85 86# We cannot use keyfile3 anymore. 87geli attach -p -k $keyfile3 md${no} 2>/dev/null 88if [ $? -ne 0 ]; then 89 echo "ok 7" 90else 91 echo "not ok 7" 92fi 93 94# Attach with key 1. 95geli attach -p -k $keyfile4 md${no} 96if [ $? -eq 0 ]; then 97 echo "ok 8" 98else 99 echo "not ok 8" 100fi 101hash5=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5` 102geli detach md${no} 103 104# Change key 0 for detached provider. 105geli setkey -n 0 -p -k $keyfile4 -P -K $keyfile5 md${no} 106if [ $? -eq 0 ]; then 107 echo "ok 9" 108else 109 echo "not ok 9" 110fi 111 112# We cannot use keyfile2 anymore. 113geli attach -p -k $keyfile2 md${no} 2>/dev/null 114if [ $? -ne 0 ]; then 115 echo "ok 10" 116else 117 echo "not ok 10" 118fi 119 120# Attach with key 0. 121geli attach -p -k $keyfile5 md${no} 122if [ $? -eq 0 ]; then 123 echo "ok 11" 124else 125 echo "not ok 11" 126fi 127hash6=`dd if=/dev/md${no}.eli bs=512 count=${sectors} 2>/dev/null | md5` 128geli detach md${no} 129 130if [ ${hash1} = ${hash2} ]; then 131 echo "ok 12" 132else 133 echo "not ok 12" 134fi 135if [ ${hash1} = ${hash3} ]; then 136 echo "ok 13" 137else 138 echo "not ok 13" 139fi 140if [ ${hash1} = ${hash4} ]; then 141 echo "ok 14" 142else 143 echo "not ok 14" 144fi 145if [ ${hash1} = ${hash5} ]; then 146 echo "ok 15" 147else 148 echo "not ok 15" 149fi 150if [ ${hash1} = ${hash6} ]; then 151 echo "ok 16" 152else 153 echo "not ok 16" 154fi 155 156rm -f $keyfile1 $keyfile2 $keyfile3 $keyfile4 $keyfile5 157