1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2017 Datto, Inc. All rights reserved.
19# Copyright (c) 2019 DilOS
20#
21
22. $STF_SUITE/include/libtest.shlib
23. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
24
25#
26# DESCRIPTION:
27# 'zfs change-key -o' should change the key format.
28#
29# STRATEGY:
30# 1. Create an encryption dataset with a passphrase key format
31# 2. Unmount the dataset
32# 3. Verify the key format is passphrase
33# 4. Change the key format to hex
34# 5. Verify the key format is hex
35# 6. Attempt to reload the dataset's key
36# 7. Change the key format to raw
37# 8. Verify the key format is raw
38# 9. Attempt to reload the dataset's key
39#
40
41verify_runnable "both"
42
43function cleanup
44{
45	datasetexists $TESTPOOL/$TESTFS1 && \
46		log_must zfs destroy -f $TESTPOOL/$TESTFS1
47}
48log_onexit cleanup
49
50log_assert "'zfs change-key -o' should change the key format"
51
52log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \
53	"-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1"
54log_must zfs unmount $TESTPOOL/$TESTFS1
55
56log_must verify_keyformat $TESTPOOL/$TESTFS1 "passphrase"
57
58log_must eval "echo $HEXKEY | zfs change-key -o keyformat=hex" \
59	"$TESTPOOL/$TESTFS1"
60log_must verify_keyformat $TESTPOOL/$TESTFS1 "hex"
61
62log_must zfs unload-key $TESTPOOL/$TESTFS1
63log_must eval "echo $HEXKEY | zfs load-key $TESTPOOL/$TESTFS1"
64
65log_must eval "echo $RAWKEY | tr -d '\n' | zfs change-key -o keyformat=raw" \
66	"$TESTPOOL/$TESTFS1"
67log_must verify_keyformat $TESTPOOL/$TESTFS1 "raw"
68
69log_must zfs unload-key $TESTPOOL/$TESTFS1
70log_must eval "echo $RAWKEY | tr -d '\n' | zfs load-key $TESTPOOL/$TESTFS1"
71
72log_pass "'zfs change-key -o' changes the key format"
73