[PATCH 6/9] nvme/041: test different key types
Hannes Reinecke
hare at suse.de
Sun Nov 21 23:55:21 PST 2021
Signed-off-by: Hannes Reinecke <hare at suse.de>
---
tests/nvme/041 | 102 +++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/041.out | 36 ++++++++++++++++
2 files changed, 138 insertions(+)
create mode 100644 tests/nvme/041
create mode 100644 tests/nvme/041.out
diff --git a/tests/nvme/041 b/tests/nvme/041
new file mode 100644
index 0000000..8fc4ab9
--- /dev/null
+++ b/tests/nvme/041
@@ -0,0 +1,102 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2021 Hannes Reinecke, SUSE Labs
+#
+# Test nvme over tcp dhchap keys
+
+. tests/nvme/rc
+
+DESCRIPTION="Test dhchap keys for authenticated TCP connection via localhost"
+QUICK=1
+
+requires() {
+ _nvme_requires
+ _have_modules loop
+ _require_nvme_trtype_is_fabrics
+}
+
+
+test() {
+ local port
+ local genctr
+ local subsys="blktests-subsystem-"
+ local hostid="$(uuidgen)"
+ local hostnqn="nqn.2014-08.org.nvmexpress:uuid:${hostid}"
+ local scratch="/tmp/blktest-ns1.img"
+ local nvme_trtype="tcp"
+ local hostkey
+
+ echo "Running ${TEST_NAME}"
+
+ hostkey="$(nvme gen-dhchap-key -n ${subsys}1 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}1" "${scratch}"
+ _add_nvmet_subsys_to_port "${port}" "${subsys}1"
+ _create_nvmet_host "${subsys}1" "${hostnqn}"
+ _set_nvmet_hostkey "${hostnqn}" "${hostkey}"
+
+ nvme connect -t "${nvme_trtype}" -n "${subsys}1" \
+ -a "${def_traddr}" -s "${def_trsvcid}" -S "${hostkey}" \
+ --hostnqn="${hostnqn}" --hostid="${hostid}"
+
+ nvme list-subsys
+
+ nvme disconnect -n "${subsys}1"
+
+ for hmac in 1 2 3; do
+ echo "Testing hmac ${hmac}"
+ hostkey="$(nvme gen-dhchap-key --hmac=${hmac} -n ${subsys}1 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 -t "${nvme_trtype}" -n "${subsys}1" \
+ -a "${def_traddr}" -s "${def_trsvcid}" -S "${hostkey}" \
+ --hostnqn="${hostnqn}" --hostid="${hostid}"
+
+ nvme list-subsys
+
+ nvme disconnect -n "${subsys}1"
+ 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}1 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 -t "${nvme_trtype}" -n "${subsys}1" \
+ -a "${def_traddr}" -s "${def_trsvcid}" -S "${hostkey}" \
+ --hostnqn="${hostnqn}" --hostid="${hostid}"
+
+ nvme list-subsys
+
+ nvme disconnect -n "${subsys}1"
+ done
+
+ _remove_nvmet_subsystem_from_port "${port}" "${subsys}1"
+ _remove_nvmet_subsystem "${subsys}1"
+
+ _remove_nvmet_port "${port}"
+
+ _remove_nvmet_host "${hostnqn}"
+
+ rm ${scratch}
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/041.out b/tests/nvme/041.out
new file mode 100644
index 0000000..037c434
--- /dev/null
+++ b/tests/nvme/041.out
@@ -0,0 +1,36 @@
+Running nvme/041
+nvme-subsys0 - NQN=blktests-subsystem-1
+\
+ +- nvme0 tcp traddr=127.0.0.1,trsvcid=4420 live
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Testing hmac 1
+nvme-subsys0 - NQN=blktests-subsystem-1
+\
+ +- nvme0 tcp traddr=127.0.0.1,trsvcid=4420 live
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Testing hmac 2
+nvme-subsys0 - NQN=blktests-subsystem-1
+\
+ +- nvme0 tcp traddr=127.0.0.1,trsvcid=4420 live
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Testing hmac 3
+nvme-subsys0 - NQN=blktests-subsystem-1
+\
+ +- nvme0 tcp traddr=127.0.0.1,trsvcid=4420 live
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Testing key length 32
+nvme-subsys0 - NQN=blktests-subsystem-1
+\
+ +- nvme0 tcp traddr=127.0.0.1,trsvcid=4420 live
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Testing key length 48
+nvme-subsys0 - NQN=blktests-subsystem-1
+\
+ +- nvme0 tcp traddr=127.0.0.1,trsvcid=4420 live
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Testing key length 64
+nvme-subsys0 - NQN=blktests-subsystem-1
+\
+ +- nvme0 tcp traddr=127.0.0.1,trsvcid=4420 live
+NQN:blktests-subsystem-1 disconnected 1 controller(s)
+Test complete
--
2.26.2
More information about the Linux-nvme
mailing list