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 streams from raw sends.
27eb633035STom Caputi#
28eb633035STom Caputi# STRATEGY:
29eb633035STom Caputi# 1. Create an encrypted dataset
30eb633035STom Caputi# 2. Create a file and get its checksum
31eb633035STom Caputi# 3. Snapshot the dataset
32eb633035STom Caputi# 4. Attempt to receive a raw send stream as a child of an unencrypted dataset
33eb633035STom Caputi# 5. Verify the key is unavailable
34eb633035STom Caputi# 6. Attempt to load the key and mount the dataset
35eb633035STom Caputi# 7. Verify the cheksum of the file is the same as the original
36eb633035STom Caputi# 8. Attempt to receive a raw send stream as a child of an encrypted dataset
37eb633035STom Caputi# 9. Verify the key is unavailable
38eb633035STom Caputi# 10. Attempt to load the key and mount the dataset
39eb633035STom Caputi# 11. Verify the cheksum of the file is the same as the original
40eb633035STom Caputi#
41eb633035STom Caputi
42eb633035STom Caputiverify_runnable "both"
43eb633035STom Caputi
44eb633035STom Caputifunction cleanup
45eb633035STom Caputi{
46eb633035STom Caputi	datasetexists $TESTPOOL/$TESTFS1 && \
47eb633035STom Caputi		log_must zfs destroy -r $TESTPOOL/$TESTFS1
48eb633035STom Caputi
49eb633035STom Caputi	datasetexists $TESTPOOL/$TESTFS2 && \
50eb633035STom Caputi		log_must zfs destroy -r $TESTPOOL/$TESTFS2
51eb633035STom Caputi}
52eb633035STom Caputi
53eb633035STom Caputilog_onexit cleanup
54eb633035STom Caputi
55eb633035STom Caputilog_assert "ZFS should receive streams from raw sends"
56eb633035STom Caputi
57eb633035STom Caputitypeset passphrase="password"
58eb633035STom Caputitypeset snap="$TESTPOOL/$TESTFS1@snap"
59eb633035STom Caputi
60eb633035STom Caputilog_must eval "echo $passphrase | zfs create -o encryption=on" \
61eb633035STom Caputi	"-o keyformat=passphrase $TESTPOOL/$TESTFS1"
62eb633035STom Caputi
63eb633035STom Caputilog_must mkfile 1M /$TESTPOOL/$TESTFS1/$TESTFILE0
64*e3bf7d5aSKody Kantortypeset checksum=$(digest -a md5 /$TESTPOOL/$TESTFS1/$TESTFILE0)
65eb633035STom Caputi
66eb633035STom Caputilog_must zfs snapshot $snap
67eb633035STom Caputi
68eb633035STom Caputilog_note "Verify ZFS can receive a raw send stream from an encrypted dataset"
69eb633035STom Caputilog_must eval "zfs send -w $snap | zfs receive $TESTPOOL/$TESTFS2"
70eb633035STom Caputi
71eb633035STom Caputikeystatus=$(get_prop keystatus $TESTPOOL/$TESTFS2)
72eb633035STom Caputi[[ "$keystatus" == "unavailable" ]] || \
73eb633035STom Caputi	log_fail "Expected keystatus unavailable, got $keystatus"
74eb633035STom Caputi
75eb633035STom Caputilog_must eval "echo $passphrase | zfs mount -l $TESTPOOL/$TESTFS2"
76eb633035STom Caputi
77*e3bf7d5aSKody Kantortypeset cksum1=$(digest -a md5 /$TESTPOOL/$TESTFS2/$TESTFILE0)
78eb633035STom Caputi[[ "$cksum1" == "$checksum" ]] || \
79eb633035STom Caputi	log_fail "Checksums differ ($cksum1 != $checksum)"
80eb633035STom Caputi
81eb633035STom Caputilog_must eval "zfs send -w $snap | zfs receive $TESTPOOL/$TESTFS1/c1"
82eb633035STom Caputi
83eb633035STom Caputikeystatus=$(get_prop keystatus $TESTPOOL/$TESTFS1/c1)
84eb633035STom Caputi[[ "$keystatus" == "unavailable" ]] || \
85eb633035STom Caputi	log_fail "Expected keystatus unavailable, got $keystatus"
86eb633035STom Caputi
87eb633035STom Caputilog_must eval "echo $passphrase | zfs mount -l $TESTPOOL/$TESTFS1/c1"
88*e3bf7d5aSKody Kantortypeset cksum2=$(digest -a md5 /$TESTPOOL/$TESTFS1/c1/$TESTFILE0)
89eb633035STom Caputi[[ "$cksum2" == "$checksum" ]] || \
90eb633035STom Caputi	log_fail "Checksums differ ($cksum2 != $checksum)"
91eb633035STom Caputi
92eb633035STom Caputilog_pass "ZFS can receive streams from raw sends"
93