1eb633035STom Caputi#!/bin/ksh -p 2eb633035STom Caputi# 3eb633035STom Caputi# CDDL HEADER START 4eb633035STom Caputi# 5eb633035STom Caputi# This file and its contents are supplied under the terms of the 6eb633035STom Caputi# Common Development and Distribution License ("CDDL"), version 1.0. 7eb633035STom Caputi# You may only use this file in accordance with the terms of version 8eb633035STom Caputi# 1.0 of the CDDL. 9eb633035STom Caputi# 10eb633035STom Caputi# A full copy of the text of the CDDL should have accompanied this 11eb633035STom Caputi# source. A copy of the CDDL is also available via the Internet at 12eb633035STom Caputi# http://www.illumos.org/license/CDDL. 13eb633035STom Caputi# 14eb633035STom Caputi# CDDL HEADER END 15eb633035STom Caputi# 16eb633035STom Caputi 17eb633035STom Caputi# 18eb633035STom Caputi# Copyright (c) 2017 Datto, Inc. All rights reserved. 19*e3bf7d5aSKody Kantor# Copyright 2020 Joyent, Inc. 20eb633035STom Caputi# 21eb633035STom Caputi 22eb633035STom Caputi. $STF_SUITE/include/libtest.shlib 23eb633035STom Caputi 24eb633035STom Caputi# 25eb633035STom Caputi# DESCRIPTION: 26eb633035STom Caputi# ZFS should receive an unencrypted stream from an encrypted dataset 27eb633035STom Caputi# 28eb633035STom Caputi# STRATEGY: 29eb633035STom Caputi# 1. Create an unencrypted dataset 30eb633035STom Caputi# 2. Create an encrypted dataset 31eb633035STom Caputi# 3. Create and checksum a file on the encrypted dataset 32eb633035STom Caputi# 4. Snapshot the encrypted dataset 33eb633035STom Caputi# 5. Attempt to receive the snapshot into an unencrypted child 34eb633035STom Caputi# 6. Verify encryption is not enabled 35eb633035STom Caputi# 7. Verify the cheksum of the file is the same as the original 36eb633035STom Caputi# 8. Attempt to receive the snapshot into an encrypted child 37eb633035STom Caputi# 9. Verify the cheksum of the file is the same as the original 38eb633035STom Caputi# 39eb633035STom Caputi 40eb633035STom Caputiverify_runnable "both" 41eb633035STom Caputi 42eb633035STom Caputifunction cleanup 43eb633035STom Caputi{ 44eb633035STom Caputi datasetexists $TESTPOOL/$TESTFS1 && \ 45eb633035STom Caputi log_must zfs destroy -r $TESTPOOL/$TESTFS1 46eb633035STom Caputi 47eb633035STom Caputi datasetexists $TESTPOOL/$TESTFS2 && \ 48eb633035STom Caputi log_must zfs destroy -r $TESTPOOL/$TESTFS2 49eb633035STom Caputi} 50eb633035STom Caputi 51eb633035STom Caputilog_onexit cleanup 52eb633035STom Caputi 53eb633035STom Caputilog_assert "ZFS should receive an unencrypted stream from an encrypted dataset" 54eb633035STom Caputi 55eb633035STom Caputitypeset passphrase="password" 56eb633035STom Caputitypeset snap="$TESTPOOL/$TESTFS2@snap" 57eb633035STom Caputi 58eb633035STom Caputilog_must zfs create $TESTPOOL/$TESTFS1 59eb633035STom Caputilog_must eval "echo $passphrase | zfs create -o encryption=on" \ 60eb633035STom Caputi "-o keyformat=passphrase $TESTPOOL/$TESTFS2" 61eb633035STom Caputi 62eb633035STom Caputilog_must mkfile 1M /$TESTPOOL/$TESTFS2/$TESTFILE0 63*e3bf7d5aSKody Kantortypeset checksum=$(digest -a md5 /$TESTPOOL/$TESTFS2/$TESTFILE0) 64eb633035STom Caputi 65eb633035STom Caputilog_must zfs snapshot $snap 66eb633035STom Caputi 67eb633035STom Caputilog_note "Verify ZFS can receive into an unencrypted child" 68eb633035STom Caputilog_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS1/c1" 69eb633035STom Caputi 70eb633035STom Caputicrypt=$(get_prop encryption $TESTPOOL/$TESTFS1/c1) 71eb633035STom Caputi[[ "$crypt" == "off" ]] || log_fail "Received unencrypted stream as encrypted" 72eb633035STom Caputi 73*e3bf7d5aSKody Kantortypeset cksum1=$(digest -a md5 /$TESTPOOL/$TESTFS1/c1/$TESTFILE0) 74eb633035STom Caputi[[ "$cksum1" == "$checksum" ]] || \ 75eb633035STom Caputi log_fail "Checksums differ ($cksum1 != $checksum)" 76eb633035STom Caputi 77eb633035STom Caputilog_note "Verify ZFS can receive into an encrypted child" 78eb633035STom Caputilog_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS2/c1" 79eb633035STom Caputi 80*e3bf7d5aSKody Kantortypeset cksum2=$(digest -a md5 /$TESTPOOL/$TESTFS2/c1/$TESTFILE0) 81eb633035STom Caputi[[ "$cksum2" == "$checksum" ]] || \ 82eb633035STom Caputi log_fail "Checksums differ ($cksum2 != $checksum)" 83eb633035STom Caputi 84eb633035STom Caputilog_pass "ZFS can receive an unencrypted stream from an encrypted dataset" 85