1*eb633035STom Caputi#!/bin/ksh -p
2*eb633035STom Caputi#
3*eb633035STom Caputi# CDDL HEADER START
4*eb633035STom Caputi#
5*eb633035STom Caputi# This file and its contents are supplied under the terms of the
6*eb633035STom Caputi# Common Development and Distribution License ("CDDL"), version 1.0.
7*eb633035STom Caputi# You may only use this file in accordance with the terms of version
8*eb633035STom Caputi# 1.0 of the CDDL.
9*eb633035STom Caputi#
10*eb633035STom Caputi# A full copy of the text of the CDDL should have accompanied this
11*eb633035STom Caputi# source.  A copy of the CDDL is also available via the Internet at
12*eb633035STom Caputi# http://www.illumos.org/license/CDDL.
13*eb633035STom Caputi#
14*eb633035STom Caputi# CDDL HEADER END
15*eb633035STom Caputi#
16*eb633035STom Caputi
17*eb633035STom Caputi#
18*eb633035STom Caputi# Copyright (c) 2017, Datto, Inc. All rights reserved.
19*eb633035STom Caputi#
20*eb633035STom Caputi
21*eb633035STom Caputi. $STF_SUITE/include/libtest.shlib
22*eb633035STom Caputi. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
23*eb633035STom Caputi
24*eb633035STom Caputi#
25*eb633035STom Caputi# DESCRIPTION:
26*eb633035STom Caputi# 'zpool create' should create an encrypted dataset only if it has a valid
27*eb633035STom Caputi# combination of encryption properties set.
28*eb633035STom Caputi#
29*eb633035STom Caputi# enc	= encryption
30*eb633035STom Caputi# loc	= keylocation provided
31*eb633035STom Caputi# fmt	= keyformat provided
32*eb633035STom Caputi#
33*eb633035STom Caputi# U = unspecified
34*eb633035STom Caputi# N = off
35*eb633035STom Caputi# Y = on
36*eb633035STom Caputi#
37*eb633035STom Caputi# enc	fmt	loc	valid	notes
38*eb633035STom Caputi# -------------------------------------------
39*eb633035STom Caputi# U	0	1	no	no crypt specified
40*eb633035STom Caputi# U	1	0	no	no crypt specified
41*eb633035STom Caputi# U	1	1	no	no crypt specified
42*eb633035STom Caputi# N	0	0	yes	explicit no encryption
43*eb633035STom Caputi# N	0	1	no	keylocation given, but crypt off
44*eb633035STom Caputi# N	1	0	no	keyformat given, but crypt off
45*eb633035STom Caputi# N	1	1	no	keyformat given, but crypt off
46*eb633035STom Caputi# Y	0	0	no	no keyformat specified for new key
47*eb633035STom Caputi# Y	0	1	no	no keyformat specified for new key
48*eb633035STom Caputi# Y	1	0	yes	new encryption root
49*eb633035STom Caputi# Y	1	1	yes	new encryption root
50*eb633035STom Caputi#
51*eb633035STom Caputi# STRATEGY:
52*eb633035STom Caputi# 1. Attempt to create a dataset using all combinations of encryption
53*eb633035STom Caputi#    properties
54*eb633035STom Caputi#
55*eb633035STom Caputi
56*eb633035STom Caputiverify_runnable "global"
57*eb633035STom Caputi
58*eb633035STom Caputifunction cleanup
59*eb633035STom Caputi{
60*eb633035STom Caputi	poolexists $TESTPOOL && destroy_pool $TESTPOOL
61*eb633035STom Caputi}
62*eb633035STom Caputilog_onexit cleanup
63*eb633035STom Caputi
64*eb633035STom Caputilog_assert "'zpool create' should create an encrypted dataset only if it" \
65*eb633035STom Caputi	"has a valid combination of encryption properties set."
66*eb633035STom Caputi
67*eb633035STom Caputilog_mustnot zpool create -O keylocation=prompt $TESTPOOL $DISKS
68*eb633035STom Caputilog_mustnot zpool create -O keyformat=passphrase $TESTPOOL $DISKS
69*eb633035STom Caputilog_mustnot zpool create -O keyformat=passphrase -O keylocation=prompt \
70*eb633035STom Caputi	$TESTPOOL $DISKS
71*eb633035STom Caputi
72*eb633035STom Caputilog_must zpool create -O encryption=off $TESTPOOL $DISKS
73*eb633035STom Caputilog_must zpool destroy $TESTPOOL
74*eb633035STom Caputi
75*eb633035STom Caputilog_mustnot zpool create -O encryption=off -O keylocation=prompt \
76*eb633035STom Caputi	$TESTPOOL $DISKS
77*eb633035STom Caputilog_mustnot zpool create -O encryption=off -O keyformat=passphrase \
78*eb633035STom Caputi	$TESTPOOL $DISKS
79*eb633035STom Caputilog_mustnot zpool create -O encryption=off -O keyformat=passphrase \
80*eb633035STom Caputi	-O keylocation=prompt $TESTPOOL $DISKS
81*eb633035STom Caputi
82*eb633035STom Caputilog_mustnot zpool create -O encryption=on $TESTPOOL $DISKS
83*eb633035STom Caputilog_mustnot zpool create -O encryption=on -O keylocation=prompt \
84*eb633035STom Caputi	$TESTPOOL $DISKS
85*eb633035STom Caputi
86*eb633035STom Caputilog_must eval "echo $PASSPHRASE | zpool create -O encryption=on" \
87*eb633035STom Caputi	"-O keyformat=passphrase $TESTPOOL $DISKS"
88*eb633035STom Caputilog_must zpool destroy $TESTPOOL
89*eb633035STom Caputi
90*eb633035STom Caputilog_must eval "echo $PASSPHRASE | zpool create -O encryption=on" \
91*eb633035STom Caputi	"-O keyformat=passphrase -O keylocation=prompt $TESTPOOL $DISKS"
92*eb633035STom Caputilog_must zpool destroy $TESTPOOL
93*eb633035STom Caputi
94*eb633035STom Caputilog_pass "'zpool create' creates an encrypted dataset only if it has a" \
95*eb633035STom Caputi	"valid combination of encryption properties set."
96