1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# This file and its contents are supplied under the terms of the 6# Common Development and Distribution License ("CDDL"), version 1.0. 7# You may only use this file in accordance with the terms of version 8# 1.0 of the CDDL. 9# 10# A full copy of the text of the CDDL should have accompanied this 11# source. A copy of the CDDL is also available via the Internet at 12# http://www.illumos.org/license/CDDL. 13# 14# CDDL HEADER END 15# 16 17# 18# Copyright (c) 2017, Datto, Inc. All rights reserved. 19# Copyright (c) 2023, Rob Norris <robn@despairlabs.com> 20# 21 22. $STF_SUITE/include/libtest.shlib 23. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib 24 25# 26# DESCRIPTION: 27# 'zdb -K ...' should enable reading from an encrypt dataset 28# 29# STRATEGY: 30# 1. Create an encrypted dataset 31# 2. Write some data to a file 32# 3. Run zdb -dddd on the file, confirm it can't be read 33# 4. Run zdb -K ... -ddddd on the file, confirm it can be read 34# 35 36verify_runnable "both" 37 38dataset="$TESTPOOL/$TESTFS2" 39file="$TESTDIR2/somefile" 40 41function cleanup 42{ 43 datasetexists $dataset && destroy_dataset $dataset -f 44 default_cleanup_noexit 45} 46 47log_onexit cleanup 48 49log_must default_setup_noexit $DISKS 50 51log_assert "'zdb -K' should enable reading from an encrypted dataset" 52 53log_must eval "echo $PASSPHRASE | zfs create -o mountpoint=$TESTDIR2" \ 54 "-o encryption=on -o keyformat=passphrase $dataset" 55 56echo 'my great encrypted text' > $file 57 58obj="$(ls -i $file | cut -d' ' -f1)" 59size="$(wc -c < $file)" 60 61log_note "test file $file is objid $obj, size $size" 62 63sync_pool $TESTPOOL true 64 65log_must eval "zdb -dddd $dataset $obj | grep -q 'object encrypted'" 66 67log_must eval "zdb -K $PASSPHRASE -dddd $dataset $obj | grep -q 'size\s$size$'" 68 69log_pass "'zdb -K' enables reading from an encrypted dataset" 70