From: Hannes Reinecke Date: Thu, 30 Sep 2021 12:57:40 +0000 (+0200) Subject: nvme/042: test dhchap key types for authenticated connections X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4ea6c923b831b62b30b36c3dd3f423bfb3efb19c;p=users%2Fsagi%2Fblktests.git nvme/042: test dhchap key types for authenticated connections Signed-off-by: Hannes Reinecke --- diff --git a/tests/nvme/042 b/tests/nvme/042 new file mode 100755 index 0000000..06e5d3d --- /dev/null +++ b/tests/nvme/042 @@ -0,0 +1,97 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2022 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_loop + _have_kernel_option NVME_AUTH + _have_kernel_option NVME_TARGET_AUTH + _require_nvme_trtype_is_fabrics + _require_nvme_cli_auth +} + + +test() { + local port + local subsys_name="blktests-subsystem-1" + local hostid + local hostnqn="nqn.2014-08.org.nvmexpress:uuid:${hostid}" + local file_path="${TMPDIR}/img" + local hmac + local key_len + local hostkey + local ctrldev + + echo "Running ${TEST_NAME}" + + hostid="$(uuidgen)" + if [ -z "$hostid" ] ; then + echo "uuidgen failed" + return 1 + fi + + _setup_nvmet + + truncate -s 512M "${file_path}" + + _create_nvmet_subsystem "${subsys_name}" "${file_path}" + port="$(_create_nvmet_port "${nvme_trtype}")" + _add_nvmet_subsys_to_port "${port}" "${subsys_name}" + _create_nvmet_host "${subsys_name}" "${hostnqn}" + + for hmac in 0 1 2 3; do + echo "Testing hmac ${hmac}" + hostkey="$(nvme gen-dhchap-key --hmac=${hmac} -n ${subsys_name} 2> /dev/null)" + if [ -z "$hostkey" ] ; then + echo "couldn't generate host key for hmac ${hmac}" + return 1 + fi + _set_nvmet_hostkey "${hostnqn}" "${hostkey}" + + _nvme_connect_subsys "${nvme_trtype}" "${subsys_name}" \ + "${def_traddr}" "${def_trsvcid}" \ + "${hostnqn}" "${hostid}" \ + "${hostkey}" + udevadm settle + + _nvme_disconnect_subsys "${subsys_name}" + 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_name} 2> /dev/null)" + if [ -z "$hostkey" ] ; 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_name}" \ + "${def_traddr}" "${def_trsvcid}" \ + "${hostnqn}" "${hostid}" \ + "${hostkey}" + + udevadm settle + + _nvme_disconnect_subsys "${subsys_name}" + done + + _remove_nvmet_subsystem_from_port "${port}" "${subsys_name}" + _remove_nvmet_subsystem "${subsys_name}" + + _remove_nvmet_port "${port}" + + _remove_nvmet_host "${hostnqn}" + + rm "${file_path}" + + echo "Test complete" +} diff --git a/tests/nvme/042.out b/tests/nvme/042.out new file mode 100644 index 0000000..7d3d21a --- /dev/null +++ b/tests/nvme/042.out @@ -0,0 +1,16 @@ +Running nvme/042 +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