[PATCH 07/10] nvme/040: test dhchap key types for authenticated connections
From: Hannes Reinecke <hare@suse.de>
Date: 2021-11-23 07:53:44
Subsystem:
the rest · Maintainer:
Linus Torvalds
Signed-off-by: Hannes Reinecke <hare@suse.de> --- tests/nvme/040 | 95 ++++++++++++++++++++++++++++++++++++++++++++++ tests/nvme/040.out | 16 ++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/nvme/040 create mode 100644 tests/nvme/040.out
diff --git a/tests/nvme/040 b/tests/nvme/040
new file mode 100644
index 0000000..cebc58b
--- /dev/null
+++ b/tests/nvme/040@@ -0,0 +1,95 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2021 Hannes Reinecke, SUSE Labs +# +# Test dhchap key types for authenticated connections + +. tests/nvme/rc + +DESCRIPTION="Test dhchap key types for authenticated connections" +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 ctrldev + + echo "Running ${TEST_NAME}" + + _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}" + + for hmac in 0 1 2 3; do + echo "Testing hmac ${hmac}" + hostkey="$(nvme gen-dhchap-key --hmac=${hmac} -n ${subsys} 2> /dev/null)" + if [ $? -ne 0 ] ; then + echo "couldn't generate host key for hmac ${hmac}" + return 1 + fi + _set_nvmet_hostkey "${hostnqn}" "${hostkey}" + + _nvme_connect_subsys "${nvme_trtype}" "${subsys}" \ + "${def_traddr}" "${def_trsvcid}" \ + "${hostnqn}" "${hostid}" \ + "${hostkey}" + + ctrldev=$(_find_nvme_dev "${subsys}") + if [ -z "$ctrldev" ] ; then + echo "nvme controller not found" + fi + + _nvme_disconnect_subsys "${subsys}" + done + + for key_len in 32 48 64; do + echo "Testing key length ${key_len}" + hostkey="$(nvme gen-dhchap-key --key-length=${key_len} -n ${subsys} 2> /dev/null)" + if [ $? -ne 0 ] ; then + echo "couldn't generate host key for length ${key_len}" + return 1 + fi + _set_nvmet_hostkey "${hostnqn}" "${hostkey}" + + _nvme_connect_subsys "${nvme_trtype}" "${subsys}" \ + "${def_traddr}" "${def_trsvcid}" \ + "${hostnqn}" "${hostid}" \ + "${hostkey}" + + ctrldev=$(_find_nvme_dev "${subsys}") + if [ -z "$ctrldev" ] ; then + echo "nvme controller not found" + fi + + _nvme_disconnect_subsys "${subsys}" + done + + _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/040.out b/tests/nvme/040.out
new file mode 100644
index 0000000..3643da4
--- /dev/null
+++ b/tests/nvme/040.out@@ -0,0 +1,16 @@ +Running nvme/040 +Testing hmac 0 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing hmac 1 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing hmac 2 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing hmac 3 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing key length 32 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing key length 48 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing key length 64 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Test complete
--
2.29.2