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# 'zfs load-key -L' should override keylocation with provided value.
27*eb633035STom Caputi#
28*eb633035STom Caputi# STRATEGY:
29*eb633035STom Caputi# 1. Create a key file
30*eb633035STom Caputi# 2. Copy the key file to another location
31*eb633035STom Caputi# 3. Create an encrypted dataset using the keyfile
32*eb633035STom Caputi# 4. Unmount the dataset and unload its key
33*eb633035STom Caputi# 5. Attempt to load the dataset specifying a keylocation of file
34*eb633035STom Caputi# 6. Verify the key is loaded
35*eb633035STom Caputi# 7. Verify the keylocation is the original key file
36*eb633035STom Caputi# 8. Unload the dataset's key
37*eb633035STom Caputi# 9. Attempt to load the dataset specifying a keylocation of prompt
38*eb633035STom Caputi# 10. Verify the key is loaded
39*eb633035STom Caputi# 11. Verify the keylocation is the original key file
40*eb633035STom Caputi#
41*eb633035STom Caputi
42*eb633035STom Caputiverify_runnable "both"
43*eb633035STom Caputi
44*eb633035STom Caputifunction cleanup
45*eb633035STom Caputi{
46*eb633035STom Caputi	datasetexists $TESTPOOL/$TESTFS1 && \
47*eb633035STom Caputi		log_must zfs destroy $TESTPOOL/$TESTFS1
48*eb633035STom Caputi}
49*eb633035STom Caputilog_onexit cleanup
50*eb633035STom Caputi
51*eb633035STom Caputilog_assert "'zfs load-key -L' should override keylocation with provided value"
52*eb633035STom Caputi
53*eb633035STom Caputitypeset key_location="/$TESTPOOL/pkey1"
54*eb633035STom Caputi
55*eb633035STom Caputilog_must eval "echo $PASSPHRASE > $key_location"
56*eb633035STom Caputilog_must cp $key_location /$TESTPOOL/pkey2
57*eb633035STom Caputi
58*eb633035STom Caputilog_must zfs create -o encryption=on -o keyformat=passphrase \
59*eb633035STom Caputi	-o keylocation=file://$key_location $TESTPOOL/$TESTFS1
60*eb633035STom Caputi
61*eb633035STom Caputilog_must zfs unmount $TESTPOOL/$TESTFS1
62*eb633035STom Caputilog_must zfs unload-key $TESTPOOL/$TESTFS1
63*eb633035STom Caputi
64*eb633035STom Caputilog_must zfs load-key -L file:///$TESTPOOL/pkey2 $TESTPOOL/$TESTFS1
65*eb633035STom Caputilog_must key_available $TESTPOOL/$TESTFS1
66*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS1 "file://$key_location"
67*eb633035STom Caputi
68*eb633035STom Caputilog_must zfs unload-key $TESTPOOL/$TESTFS1
69*eb633035STom Caputilog_must eval "echo $PASSPHRASE | zfs load-key -L prompt $TESTPOOL/$TESTFS1"
70*eb633035STom Caputilog_must key_available $TESTPOOL/$TESTFS1
71*eb633035STom Caputilog_must verify_keylocation $TESTPOOL/$TESTFS1 "file://$key_location"
72*eb633035STom Caputi
73*eb633035STom Caputilog_pass "'zfs load-key -L' overrides keylocation with provided value"
74