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# 20 21. $STF_SUITE/include/libtest.shlib 22 23# 24# DESCRIPTION: 25# ZFS should receive an unencrypted stream from an encrypted dataset 26# 27# STRATEGY: 28# 1. Create an unencrypted dataset 29# 2. Create an encrypted dataset 30# 3. Create and checksum a file on the encrypted dataset 31# 4. Snapshot the encrypted dataset 32# 5. Attempt to receive the snapshot into an unencrypted child 33# 6. Verify encryption is not enabled 34# 7. Verify the checksum of the file is the same as the original 35# 8. Attempt to receive the snapshot into an encrypted child 36# 9. Verify the checksum of the file is the same as the original 37# 38 39verify_runnable "both" 40 41function cleanup 42{ 43 datasetexists $TESTPOOL/$TESTFS1 && \ 44 destroy_dataset $TESTPOOL/$TESTFS1 -r 45 46 datasetexists $TESTPOOL/$TESTFS2 && \ 47 destroy_dataset $TESTPOOL/$TESTFS2 -r 48} 49 50log_onexit cleanup 51 52log_assert "ZFS should receive an unencrypted stream from an encrypted dataset" 53 54typeset passphrase="password" 55typeset snap="$TESTPOOL/$TESTFS2@snap" 56 57log_must zfs create $TESTPOOL/$TESTFS1 58log_must eval "echo $passphrase | zfs create -o encryption=on" \ 59 "-o keyformat=passphrase $TESTPOOL/$TESTFS2" 60 61log_must mkfile 1M /$TESTPOOL/$TESTFS2/$TESTFILE0 62typeset checksum=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0) 63 64log_must zfs snapshot $snap 65 66log_note "Verify ZFS can receive into an unencrypted child" 67log_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS1/c1" 68 69crypt=$(get_prop encryption $TESTPOOL/$TESTFS1/c1) 70[[ "$crypt" == "off" ]] || log_fail "Received unencrypted stream as encrypted" 71 72typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS1/c1/$TESTFILE0) 73[[ "$cksum1" == "$checksum" ]] || \ 74 log_fail "Checksums differ ($cksum1 != $checksum)" 75 76log_note "Verify ZFS can receive into an encrypted child" 77log_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS2/c1" 78 79typeset cksum2=$(md5digest /$TESTPOOL/$TESTFS2/c1/$TESTFILE0) 80[[ "$cksum2" == "$checksum" ]] || \ 81 log_fail "Checksums differ ($cksum2 != $checksum)" 82 83log_pass "ZFS can receive an unencrypted stream from an encrypted dataset" 84