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. $STF_SUITE/include/libtest.shlib
18. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
19
20#
21# DESCRIPTION:
22# 'zfs load-key' should load a dataset's key from an https:// URL,
23# but fail to do so if the domain doesn't exist or the file 404s.
24#
25# STRATEGY:
26# 1. Try to create a dataset pointing to an RFC6761-guaranteed unresolvable domain,
27#    one to the sshd port (which will be either unoccupied (ECONNREFUSED)
28#                          or have sshd on it ("wrong version number")).
29#    and one pointing to an URL that will always 404.
30# 2. Create encrypted datasets with keylocation=https://address
31# 3. Unmount the datasets and unload their keys
32# 4. Attempt to load the keys
33# 5. Verify the keys are loaded
34# 6. Attempt to mount the datasets
35#
36
37verify_runnable "both"
38
39function cleanup
40{
41	for fs in "$TESTFS1" "$TESTFS2" "$TESTFS3"; do
42		datasetexists $TESTPOOL/$fs && \
43			log_must zfs destroy $TESTPOOL/$fs
44	done
45}
46log_onexit cleanup
47
48log_assert "'zfs load-key' should load a key from a file"
49
50log_mustnot zfs create -o encryption=on -o keyformat=passphrase \
51	-o keylocation=https://invalid./where-ever $TESTPOOL/$TESTFS1
52
53log_mustnot zfs create -o encryption=on -o keyformat=passphrase \
54	-o keylocation=https://$HTTPS_HOSTNAME:22 $TESTPOOL/$TESTFS1
55
56log_mustnot zfs create -o encryption=on -o keyformat=passphrase \
57	-o keylocation=$(get_https_base_url)/ENOENT $TESTPOOL/$TESTFS1
58
59log_must zfs create -o encryption=on -o keyformat=passphrase \
60	-o keylocation=$(get_https_base_url)/PASSPHRASE $TESTPOOL/$TESTFS1
61
62log_must zfs create -o encryption=on -o keyformat=hex \
63	-o keylocation=$(get_https_base_url)/HEXKEY $TESTPOOL/$TESTFS2
64
65log_must zfs create -o encryption=on -o keyformat=raw \
66	-o keylocation=$(get_https_base_url)/RAWKEY $TESTPOOL/$TESTFS3
67
68for fs in "$TESTFS1" "$TESTFS2" "$TESTFS3"; do
69	log_must zfs unmount $TESTPOOL/$fs
70	log_must zfs unload-key $TESTPOOL/$fs
71done
72for fs in "$TESTFS1" "$TESTFS2" "$TESTFS3"; do
73	log_must zfs load-key $TESTPOOL/$fs
74	log_must key_available $TESTPOOL/$fs
75	log_must zfs mount $TESTPOOL/$fs
76done
77
78log_pass "'zfs load-key' loads a key from a file"
79