[PATCH 10/10] nvme/043: test re-authentication
Hannes Reinecke
hare at suse.de
Mon Mar 28 03:18:55 PDT 2022
Signed-off-by: Hannes Reinecke <hare at suse.de>
---
tests/nvme/043 | 136 +++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/043.out | 12 ++++
2 files changed, 148 insertions(+)
create mode 100644 tests/nvme/043
create mode 100644 tests/nvme/043.out
diff --git a/tests/nvme/043 b/tests/nvme/043
new file mode 100644
index 0000000..c217ade
--- /dev/null
+++ b/tests/nvme/043
@@ -0,0 +1,136 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2021 Hannes Reinecke, SUSE Labs
+#
+# Test re-authentication
+
+. tests/nvme/rc
+
+DESCRIPTION="Test re-authentication"
+QUICK=1
+
+requires() {
+ _nvme_requires
+ _have_modules loop
+ _require_nvme_trtype_is_fabrics
+ _require_nvme_cli_auth
+}
+
+
+test() {
+ local port
+ local subsys="blktests-subsystem-1"
+ local hostid="$(uuidgen)"
+ local hostnqn="nqn.2014-08.org.nvmexpress:uuid:${hostid}"
+ local scratch="/tmp/blktest-ns1.img"
+ local hostkey
+ local ctrlkey
+ local ctrldev
+
+ echo "Running ${TEST_NAME}"
+
+ hostkey="$(nvme gen-dhchap-key -n ${subsys} 2> /dev/null)"
+ if [ $? -ne 0 ] ; then
+ echo "nvme gen-dhchap-key command missing"
+ return 1
+ fi
+
+ ctrlkey="$(nvme gen-dhchap-key -n ${subsys} 2> /dev/null)"
+ if [ $? -ne 0 ] ; then
+ echo "nvme gen-dhchap-key command missing"
+ return 1
+ fi
+
+ _setup_nvmet
+
+ truncate -s 512M "${scratch}"
+
+ port="$(_create_nvmet_port "${nvme_trtype}")"
+
+ _create_nvmet_subsystem "${subsys}" "${scratch}"
+ _add_nvmet_subsys_to_port "${port}" "${subsys}"
+ _create_nvmet_host "${subsys}" "${hostnqn}" "${hostkey}" "${ctrlkey}"
+
+ _set_nvmet_dhgroup "${hostnqn}" "ffdhe2048"
+
+ _nvme_connect_subsys "${nvme_trtype}" "${subsys}" \
+ "${def_traddr}" "${def_trsvcid}" \
+ "${hostnqn}" "${hostid}" \
+ "${hostkey}" "${ctrlkey}"
+
+ ctrldev=$(_find_nvme_dev "${subsys}")
+ if [ -z "$ctrldev" ] ; then
+ echo "nvme controller not found"
+ fi
+
+ echo "Re-authenticate with original host key"
+
+ echo "${hostkey}" > /sys/class/nvme/${ctrldev}/dhchap_secret
+
+ echo "Renew host key on the controller"
+
+ new_hostkey="$(nvme gen-dhchap-key -n ${subsys} 2> /dev/null)"
+
+ _set_nvmet_hostkey "${hostnqn}" "${new_hostkey}"
+
+ echo "Re-authenticate with new host key"
+
+ echo "${new_hostkey}" > /sys/class/nvme/${ctrldev}/dhchap_secret
+
+ ctrldev=$(_find_nvme_dev "${subsys}")
+ if [ -z "$ctrldev" ] ; then
+ echo "nvme controller not found"
+ fi
+
+ echo "Renew ctrl key on the controller"
+
+ new_ctrlkey="$(nvme gen-dhchap-key -n ${subsys} 2> /dev/null)"
+
+ _set_nvmet_ctrlkey "${hostnqn}" "${new_ctrlkey}"
+
+ echo "Re-authenticate with new ctrl key"
+
+ echo "${new_ctrlkey}" > /sys/class/nvme/${ctrldev}/dhchap_ctrl_secret
+
+ ctrldev=$(_find_nvme_dev "${subsys}")
+ if [ -z "$ctrldev" ] ; then
+ echo "nvme controller not found"
+ fi
+
+ echo "Change DH group to ffdhe8192"
+
+ _set_nvmet_dhgroup "${hostnqn}" "ffdhe8192"
+
+ echo "Re-authenticate with changed DH group"
+ echo "${new_hostkey}" > /sys/class/nvme/${ctrldev}/dhchap_secret
+
+ ctrldev=$(_find_nvme_dev "${subsys}")
+ if [ -z "$ctrldev" ] ; then
+ echo "nvme controller not found"
+ fi
+
+ echo "Change hash to hmac(sha512)"
+
+ _set_nvmet_hash "${hostnqn}" "hmac(sha512)"
+
+ echo "Re-authenticate with changed hash"
+ echo "${new_hostkey}" > /sys/class/nvme/${ctrldev}/dhchap_secret
+
+ ctrldev=$(_find_nvme_dev "${subsys}")
+ if [ -z "$ctrldev" ] ; then
+ echo "nvme controller not found"
+ fi
+
+ _nvme_disconnect_subsys "${subsys}"
+
+ _remove_nvmet_subsystem_from_port "${port}" "${subsys}"
+ _remove_nvmet_subsystem "${subsys}"
+
+ _remove_nvmet_port "${port}"
+
+ _remove_nvmet_host "${hostnqn}"
+
+ rm ${scratch}
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/043.out b/tests/nvme/043.out
new file mode 100644
index 0000000..a0c5022
--- /dev/null
+++ b/tests/nvme/043.out
@@ -0,0 +1,12 @@
+Running nvme/043
+Re-authenticate with original host key
+Renew host key on the controller
+Re-authenticate with new host key
+Renew ctrl key on the controller
+Re-authenticate with new ctrl key
+Change DH group to ffdhe8192
+Re-authenticate with changed DH group
+Change hash to hmac(sha512)
+Re-authenticate with changed hash
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Test complete
--
2.29.2
More information about the Linux-nvme
mailing list