Testsuite for nvme in-band authentication
PATCH v4 5/10 nvme/rc: add more arguments to _nvme_connect_subsys()
In reply to Hannes ReineckeFrom: Hannes Reinecke <[email protected]>
Add optional arguments for setting 'hostnqn', 'hostid', 'hostkey', and 'ctrlkey' to _nvme_connect_subsys() to make it usable for testing nvme in-band authentication.
--- tests/nvme/rc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tests/nvme/rc +16 -0
@@ -188,11 +188,27 @@ _nvme_connect_subsys() { local subsysnqn="$2" local traddr="${3:-$def_traddr}" local trsvcid="${4:-$def_trsvcid}" + local hostnqn="${5:-$def_hostnqn}" + local hostid="${6:-$def_hostid}" + local hostkey="${7}" + local ctrlkey="${8}" ARGS=(-t "${trtype}" -n "${subsysnqn}") if [[ "${trtype}" != "loop" ]]; then ARGS+=(-a "${traddr}" -s "${trsvcid}") fi + if [[ "${hostnqn}" != "$def_hostnqn" ]]; then + ARGS+=(--hostnqn="${hostnqn}") + fi + if [[ "${hostid}" != "$def_hostid" ]]; then + ARGS+=(--hostid="${hostid}") + fi + if [[ -n "${hostkey}" ]]; then + ARGS+=(--dhchap-secret="${hostkey}") + fi + if [[ -n "${ctrlkey}" ]]; then + ARGS+=(--dhchap-ctrl-secret="${ctrlkey}") + fi nvme connect "${ARGS[@]}" }
Signature · 1 line
2.29.2
PATCH v4 6/10 nvme/039: create authenticated connections
In reply to Hannes Reinecke--- tests/nvme/039 | 83 ++++++++++++++++++++++++++++++++++++++++++++++ tests/nvme/039.out | 7 ++++ 2 files changed, 90 insertions(+) create mode 100644 tests/nvme/039 create mode 100644 tests/nvme/039.out
tests/nvme/039 new file +83 -0
@@ -0,0 +1,83 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2021 Hannes Reinecke, SUSE Labs +# +# Create authenticated connections + +. tests/nvme/rc + +DESCRIPTION="Create 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}" + + hostkey="$(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}" + + # Test unauthenticated connection (should fail) + echo "Test unauthenticated connection" + _nvme_connect_subsys "${nvme_trtype}" "${subsys}" \ + "${def_traddr}" "${def_trscvid}" \ + "${hostnqn}" "${hostid}" + + ctrldev=$(_find_nvme_dev "${subsys}") + if [ -n "$ctrldev" ] ; then + echo "nvme controller found" + fi + + _nvme_disconnect_subsys "${subsys}" + + # Test authenticated connection + echo "Test authenticated connection" + _nvme_connect_subsys "${nvme_trtype}" "${subsys}" \ + "${def_traddr}" "${def_trscvid}" \ + "${hostnqn}" "${hostid}" "${hostkey}" + + 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" +}
tests/nvme/039.out new file +7 -0
@@ -0,0 +1,7 @@ +Running nvme/039 +Test unauthenticated connection +no controller found +NQN:blktests-subsystem-1 disconnected 0 controller(s) +Test authenticated connection +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Test complete
Signature · 1 line
2.29.2
PATCH v4 2/10 nvme/rc: clear allowed_hosts subdirectory
In reply to Hannes ReineckeWhen removing a subsystem we need to clear out the allowed_hosts subdirectory, otherwise removal will fail.
--- tests/nvme/rc | 1 + 1 file changed, 1 insertion(+)
tests/nvme/rc +1 -0
@@ -262,6 +262,7 @@ _remove_nvmet_subsystem() { local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}" _remove_nvmet_ns "${nvmet_subsystem}" "1" + rm "${subsys_path}"/allowed_hosts/* rmdir "${subsys_path}" }
Signature · 1 line
2.29.2
PATCH v4 3/10 nvme/rc: clear hosts directory in _cleanup_nvmet()
In reply to Hannes ReineckeFrom: Hannes Reinecke <[email protected]>
When clearing out the configuration we need to clear the 'hosts' directory, too, as scripts might have added host configurations.
--- tests/nvme/rc | 6 ++++++ 1 file changed, 6 insertions(+)
tests/nvme/rc +6 -0
@@ -122,6 +122,12 @@ _cleanup_nvmet() { rmdir "${subsys}" done + for host in "${NVMET_CFS}"/hosts/*; do + name=$(basename "${host}") + echo "WARNING: Test did not clean up host: ${name}" + rmdir "${host}" + done + shopt -u nullglob trap SIGINT
Signature · 1 line
2.29.2
PATCH v4 4/10 nvme/rc: add functions for in-band authentication
In reply to Hannes ReineckeAdd functions to enable in-band authentication.
--- tests/nvme/rc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
tests/nvme/rc +73 -0
@@ -73,6 +73,17 @@ _require_nvme_trtype_is_fabrics() { return 0 } +_require_nvme_cli_auth() { + local hostkey + + hostkey="$(nvme gen-dhchap-key -n nvmf-test-subsys 2> /dev/null)" + if [ $? -ne 0 ] ; then + SKIP_REASON="nvme gen-dhchap-key command missing" + return 1 + fi + return 0 +} + _test_dev_nvme_ctrl() { echo "/dev/char/$(cat "${TEST_DEV_SYSFS}/device/dev")" }
@@ -253,6 +264,25 @@ _create_nvmet_subsystem() { _create_nvmet_ns "${nvmet_subsystem}" "1" "${blkdev}" "${uuid}" } +_create_nvmet_host() { + local nvmet_subsystem="$1" + local nvmet_hostnqn="$2" + local nvmet_hostkey="$3" + local nvmet_ctrlkey="$4" + local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}" + local host_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}" + + mkdir "${host_path}" + echo 0 > "${cfs_path}/attr_allow_any_host" + ln -s "${host_path}" "${cfs_path}/allowed_hosts/${nvmet_hostnqn}" + if [[ "${nvmet_hostkey}" ]] ; then + echo "${nvmet_hostkey}" > "${host_path}/dhchap_key" + fi + if [[ "${nvmet_ctrlkey}" ]] ; then + echo "${nvmet_ctrlkey}" > "${host_path}/dhchap_ctrl_key" + fi +} + _remove_nvmet_ns() { local nvmet_subsystem="$1" local nsid=$2
@@ -272,6 +302,13 @@ _remove_nvmet_subsystem() { rmdir "${subsys_path}" } +_remove_nvmet_host() { + local nvmet_host="$1" + local host_path="${NVMET_CFS}/hosts/${nvmet_host}" + + rmdir "${host_path}" +} + _create_nvmet_passthru() { local nvmet_subsystem="$1" local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
@@ -308,6 +345,42 @@ _remove_nvmet_subsystem_from_port() { rm "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}" } +_set_nvmet_hostkey() { + local nvmet_hostnqn="$1" + local nvmet_hostkey="$2" + local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}" + + echo "${nvmet_hostkey}" > \ + "${cfs_path}/dhchap_key" +} + +_set_nvmet_ctrlkey() { + local nvmet_hostnqn="$1" + local nvmet_ctrlkey="$2" + local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}" + + echo "${nvmet_ctrlkey}" > \ + "${cfs_path}/dhchap_ctrl_key" +} + +_set_nvmet_hash() { + local nvmet_hostnqn="$1" + local nvmet_hash="$2" + local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}" + + echo "${nvmet_hash}" > \ + "${cfs_path}/dhchap_hash" +} + +_set_nvmet_dhgroup() { + local nvmet_hostnqn="$1" + local nvmet_dhgroup="$2" + local cfs_path="${NVMET_CFS}/hosts/${nvmet_hostnqn}" + + echo "${nvmet_dhgroup}" > \ + "${cfs_path}/dhchap_dhgroup" +} + _find_nvme_dev() { local subsys=$1 local subsysnqn
Signature · 1 line
2.29.2
PATCH v4 8/10 nvme/041: test hash and dh group variations for authenticated connections
In reply to Hannes Reinecke--- tests/nvme/041 | 89 ++++++++++++++++++++++++++++++++++++++++++++++ tests/nvme/041.out | 18 ++++++++++ 2 files changed, 107 insertions(+) create mode 100644 tests/nvme/041 create mode 100644 tests/nvme/041.out
tests/nvme/041 new file +89 -0
@@ -0,0 +1,89 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2021 Hannes Reinecke, SUSE Labs +# +# Test hash and dh group variations for authenticated connections + +. tests/nvme/rc + +DESCRIPTION="Test hash and DH group variations 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}" "${hostkey}" + + for hash in "hmac(sha256)" "hmac(sha384)" "hmac(sha512)" ; do + + echo "Testing hash ${hash}" + + _set_nvmet_hash "${hostnqn}" "${hash}" + + _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 dhgroup in "ffdhe2048" "ffdhe3072" "ffdhe4096" "ffdhe6144" "ffdhe8192" ; do + + echo "Testing DH group ${dhgroup}" + + _set_nvmet_dhgroup "${hostnqn}" "${dhgroup}" + + _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" +}
tests/nvme/041.out new file +18 -0
@@ -0,0 +1,18 @@ +Running nvme/041 +Testing hash hmac(sha256) +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing hash hmac(sha384) +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing hash hmac(sha512) +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing DH group ffdhe2048 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing DH group ffdhe3072 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing DH group ffdhe4096 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing DH group ffdhe6144 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Testing DH group ffdhe8192 +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Test complete
Signature · 1 line
2.29.2
PATCH v4 1/10 nvme/rc: do not print error message when no nvme device is found
In reply to Hannes Reinecke_find_nvme_dev() will only print an nvme device node if one is found, so no point in printing an error message.
--- tests/nvme/rc | 1 + 1 file changed, 1 insertion(+)
tests/nvme/rc +1 -0
@@ -306,6 +306,7 @@ _find_nvme_dev() { local subsysnqn local dev for dev in /sys/class/nvme/nvme*; do + [ -e "$dev" ] || continue dev="$(basename "$dev")" subsysnqn="$(cat "/sys/class/nvme/${dev}/subsysnqn")" if [[ "$subsysnqn" == "$subsys" ]]; then
Signature · 1 line
2.29.2
v4 cover Testsuite for nvme in-band authentication
Hi all,
some people (Hi Sagi!) have complained that nvme in-band authentication provide far too many configuration options to test it with some easy commands. So here's a test suite for testing (most of) the various configuration options and features.
As usual, comments and reviews are welcome.
Changes to v3:
- Rebase to current HEAD
Changes to v2:
- Merge first two tests
- Add optional arguments to _nvme_connect_subsys()
- Convert to use _nvme_connect_subsys()
Changes to v1:
- Move tests to the 'nvme' directory
- Check for authentication failure on invalid keys
Hannes Reinecke (10):
nvme/rc: do not print error message when no nvme device is found nvme/rc: clear allowed_hosts subdirectory
nvme/rc: clear hosts directory in _cleanup_nvmet() nvme/rc: add functions for in-band authentication nvme/rc: add more arguments to _nvme_connect_subsys() nvme/039: create authenticated connections
nvme/040: test dhchap key types for authenticated connections nvme/041: test hash and dh group variations for authenticated
connections
nvme/042: test bi-directional authentication nvme/043: test re-authentication
tests/nvme/039 | 83 +++++++++++++++++++++++++++ tests/nvme/039.out | 7 +++ tests/nvme/040 | 95 +++++++++++++++++++++++++++++++ tests/nvme/040.out | 16 ++++++ tests/nvme/041 | 89 +++++++++++++++++++++++++++++ tests/nvme/041.out | 18 ++++++ tests/nvme/042 | 107 +++++++++++++++++++++++++++++++++++ tests/nvme/042.out | 8 +++ tests/nvme/043 | 136 +++++++++++++++++++++++++++++++++++++++++++++ tests/nvme/043.out | 12 ++++ tests/nvme/rc | 97 ++++++++++++++++++++++++++++++++ 11 files changed, 668 insertions(+) create mode 100644 tests/nvme/039 create mode 100644 tests/nvme/039.out create mode 100644 tests/nvme/040 create mode 100644 tests/nvme/040.out create mode 100644 tests/nvme/041 create mode 100644 tests/nvme/041.out create mode 100644 tests/nvme/042 create mode 100644 tests/nvme/042.out create mode 100644 tests/nvme/043 create mode 100644 tests/nvme/043.out
Signature · 1 line
2.29.2
PATCH v4 7/10 nvme/040: test dhchap key types for authenticated connections
--- 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
tests/nvme/040 new file +95 -0
@@ -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" +}
tests/nvme/040.out new file +16 -0
@@ -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
Signature · 1 line
2.29.2
PATCH v4 10/10 nvme/043: test re-authentication
In reply to Hannes Reinecke--- 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
tests/nvme/043 new file +136 -0
@@ -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" +}
tests/nvme/043.out new file +12 -0
@@ -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
Signature · 1 line
2.29.2
PATCH v4 9/10 nvme/042: test bi-directional authentication
In reply to Hannes Reinecke--- tests/nvme/042 | 107 +++++++++++++++++++++++++++++++++++++++++++++ tests/nvme/042.out | 8 ++++ 2 files changed, 115 insertions(+) create mode 100644 tests/nvme/042 create mode 100644 tests/nvme/042.out
tests/nvme/042 new file +107 -0
@@ -0,0 +1,107 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2021 Hannes Reinecke, SUSE Labs +# +# Test bi-directional authentication + +. tests/nvme/rc + +DESCRIPTION="Test bi-directional authentication" +QUICK=1 + +requires() { + _nvme_requires + _have_modules loop + _require_nvme_trtype_is_fabrics +} + + +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" + + # Step 1: Connect with host authentication only + echo "Test host authentication" + _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}" + + # Step 2: Connect with host authentication + # and invalid ctrl authentication + echo "Test host authentication and invalid ctrl authentication" + _nvme_connect_subsys "${nvme_trtype}" "${subsys}" \ + "${def_traddr}" "${def_trsvcid}" \ + "${hostnqn}" "${hostid}" \ + "${hostkey}" "${hostkey}" + ctrldev=$(_find_nvme_dev "${subsys}1") + if [ -n "${ctrldev}" ] ; then + echo "nvme controller found!" + _nvme_disconnect_subsys "${ctrldev}" + fi + + # Step 3: Connect with host authentication + # and valid ctrl authentication + echo "Test host authentication and valid ctrl authentication" + _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 + + _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" +}
tests/nvme/042.out new file +8 -0
@@ -0,0 +1,8 @@ +Running nvme/042 +Test host authentication +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Test host authentication and invalid ctrl authentication +no controller found +Test host authentication and valid ctrl authentication +NQN:blktests-subsystem-1 disconnected 1 controller(s) +Test complete
Signature · 1 line
2.29.2