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# Copyright (c) 2019, DilOS
20*eb633035STom Caputi#
21*eb633035STom Caputi
22*eb633035STom Caputi. $STF_SUITE/include/libtest.shlib
23*eb633035STom Caputi. $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib
24*eb633035STom Caputi. $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib
25*eb633035STom Caputi
26*eb633035STom Caputi#
27*eb633035STom Caputi# DESCRIPTION:
28*eb633035STom Caputi# 'zfs create' should create an encrypted dataset with a valid encryption
29*eb633035STom Caputi# algorithm, key format, key location, and key.
30*eb633035STom Caputi#
31*eb633035STom Caputi# STRATEGY:
32*eb633035STom Caputi# 1. Create a filesystem for each combination of encryption type and key format
33*eb633035STom Caputi# 2. Verify that each filesystem has the correct properties set
34*eb633035STom Caputi#
35*eb633035STom Caputi
36*eb633035STom Caputiverify_runnable "both"
37*eb633035STom Caputi
38*eb633035STom Caputifunction cleanup
39*eb633035STom Caputi{
40*eb633035STom Caputi	datasetexists $TESTPOOL/$TESTFS1 && \
41*eb633035STom Caputi		log_must zfs destroy -f $TESTPOOL/$TESTFS1
42*eb633035STom Caputi}
43*eb633035STom Caputi
44*eb633035STom Caputilog_onexit cleanup
45*eb633035STom Caputi
46*eb633035STom Caputiset -A ENCRYPTION_ALGS \
47*eb633035STom Caputi	"encryption=on" \
48*eb633035STom Caputi	"encryption=aes-128-ccm" \
49*eb633035STom Caputi	"encryption=aes-192-ccm" \
50*eb633035STom Caputi	"encryption=aes-256-ccm" \
51*eb633035STom Caputi	"encryption=aes-128-gcm" \
52*eb633035STom Caputi	"encryption=aes-192-gcm" \
53*eb633035STom Caputi	"encryption=aes-256-gcm"
54*eb633035STom Caputi
55*eb633035STom Caputiset -A ENCRYPTION_PROPS \
56*eb633035STom Caputi	"encryption=aes-256-ccm" \
57*eb633035STom Caputi	"encryption=aes-128-ccm" \
58*eb633035STom Caputi	"encryption=aes-192-ccm" \
59*eb633035STom Caputi	"encryption=aes-256-ccm" \
60*eb633035STom Caputi	"encryption=aes-128-gcm" \
61*eb633035STom Caputi	"encryption=aes-192-gcm" \
62*eb633035STom Caputi	"encryption=aes-256-gcm"
63*eb633035STom Caputi
64*eb633035STom Caputiset -A KEYFORMATS "keyformat=raw" \
65*eb633035STom Caputi	"keyformat=hex" \
66*eb633035STom Caputi	"keyformat=passphrase"
67*eb633035STom Caputi
68*eb633035STom Caputiset -A USER_KEYS "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" \
69*eb633035STom Caputi	"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" \
70*eb633035STom Caputi	"abcdefgh"
71*eb633035STom Caputi
72*eb633035STom Caputilog_assert "'zfs create' should create encrypted datasets using all" \
73*eb633035STom Caputi	"combinations of supported properties"
74*eb633035STom Caputi
75*eb633035STom Caputitypeset -i i=0
76*eb633035STom Caputiwhile (( i < ${#ENCRYPTION_ALGS[*]} )); do
77*eb633035STom Caputi	typeset -i j=0
78*eb633035STom Caputi	while (( j < ${#KEYFORMATS[*]} )); do
79*eb633035STom Caputi		log_must eval "echo ${USER_KEYS[j]} | tr -d '\n' | zfs create" \
80*eb633035STom Caputi			"-o ${ENCRYPTION_ALGS[i]} -o ${KEYFORMATS[j]}" \
81*eb633035STom Caputi			"$TESTPOOL/$TESTFS1"
82*eb633035STom Caputi
83*eb633035STom Caputi		datasetexists $TESTPOOL/$TESTFS1 || \
84*eb633035STom Caputi			log_fail "Failed to create dataset using" \
85*eb633035STom Caputi			"${ENCRYPTION_ALGS[i]} and ${KEYFORMATS[j]}"
86*eb633035STom Caputi
87*eb633035STom Caputi		propertycheck $TESTPOOL/$TESTFS1 ${ENCRYPTION_PROPS[i]} || \
88*eb633035STom Caputi			log_fail "failed to set ${ENCRYPTION_ALGS[i]}"
89*eb633035STom Caputi		propertycheck $TESTPOOL/$TESTFS1 ${KEYFORMATS[j]} || \
90*eb633035STom Caputi			log_fail "failed to set ${KEYFORMATS[j]}"
91*eb633035STom Caputi
92*eb633035STom Caputi		log_must zfs destroy -f $TESTPOOL/$TESTFS1
93*eb633035STom Caputi		(( j = j + 1 ))
94*eb633035STom Caputi	done
95*eb633035STom Caputi	(( i = i + 1 ))
96*eb633035STom Caputidone
97*eb633035STom Caputi
98*eb633035STom Caputilog_pass "'zfs create' creates encrypted datasets using all combinations of" \
99*eb633035STom Caputi	"supported properties"
100