|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: GPL-3.0+ |
| 3 | +# Copyright (C) 2022 Hannes Reinecke, SUSE Labs |
| 4 | +# |
| 5 | +# Create secure concatenation for TCP connections |
| 6 | + |
| 7 | +. tests/nvme/rc |
| 8 | + |
| 9 | +DESCRIPTION="Create authenticated TCP connections with secure concatenation" |
| 10 | +QUICK=1 |
| 11 | + |
| 12 | +requires() { |
| 13 | + _nvme_requires |
| 14 | + _have_loop |
| 15 | + _have_kernel_option NVME_AUTH |
| 16 | + _have_kernel_option NVME_TCP_TLS |
| 17 | + _have_kernel_option NVME_TARGET_AUTH |
| 18 | + _have_kernel_option NVME_TARGET_TCP_TLS |
| 19 | + _require_kernel_nvme_fabrics_feature dhchap_ctrl_secret |
| 20 | + _require_kernel_nvme_fabrics_feature concat |
| 21 | + _require_nvme_trtype tcp |
| 22 | + _require_nvme_cli_auth |
| 23 | + if ! _have_systemctl_unit tlshd; then |
| 24 | + SKIP_REASONS+=("Install ktls-utils for tlshd") |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +set_conditions() { |
| 29 | + _set_nvme_trtype "$@" |
| 30 | +} |
| 31 | + |
| 32 | +test() { |
| 33 | + echo "Running ${TEST_NAME}" |
| 34 | + |
| 35 | + _setup_nvmet |
| 36 | + |
| 37 | + local hostkey |
| 38 | + |
| 39 | + systemctl restart tlshd |
| 40 | + |
| 41 | + hostkey=$(nvme gen-dhchap-key -m 1 -n "${def_hostnqn}" 2> /dev/null) |
| 42 | + if [ -z "$hostkey" ] ; then |
| 43 | + echo "nvme gen-dhchap-key failed" |
| 44 | + return 1 |
| 45 | + fi |
| 46 | + |
| 47 | + _nvmet_target_setup --blkdev file --hostkey "${hostkey}" --tls |
| 48 | + _set_nvmet_hash "${def_hostnqn}" "hmac(sha256)" |
| 49 | + _set_nvmet_dhgroup "${def_hostnqn}" "ffdhe2048" |
| 50 | + |
| 51 | + echo "Test secure concatenation with SHA256" |
| 52 | + _nvme_connect_subsys --dhchap-secret "${hostkey}" --concat |
| 53 | + |
| 54 | + ctrl=$(_find_nvme_dev "${def_subsysnqn}") |
| 55 | + if [[ -z "$ctrl" ]]; then |
| 56 | + echo "WARNING: connection failed" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + tlskey=$(_nvme_ctrl_tls_key "$ctrl" || true) |
| 60 | + if [[ -z "$tlskey" ]]; then |
| 61 | + echo "WARNING: connection is not encrypted" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + |
| 65 | + # Reset controller to force re-negotiation |
| 66 | + echo "Reset controller" |
| 67 | + if ! nvme reset "/dev/${ctrl}" ; then |
| 68 | + echo "WARNING: failed to reset controller" |
| 69 | + fi |
| 70 | + |
| 71 | + new_tlskey=$(_nvme_ctrl_tls_key "$ctrl" || true) |
| 72 | + if [[ -z "$new_tlskey" ]]; then |
| 73 | + echo "WARNING: connection is not encrypted" |
| 74 | + elif [[ "$new_tlskey" = "$tlskey" ]]; then |
| 75 | + echo "WARNING: TLS key has not been renegotiated" |
| 76 | + fi |
| 77 | + |
| 78 | + _nvme_disconnect_subsys |
| 79 | + |
| 80 | + hostkey=$(nvme gen-dhchap-key -m 2 -n "${def_hostnqn}" 2> /dev/null) |
| 81 | + if [ -z "$hostkey" ] ; then |
| 82 | + echo "nvme gen-dhchap-key failed" |
| 83 | + return 1 |
| 84 | + fi |
| 85 | + |
| 86 | + _set_nvmet_hostkey "${def_hostnqn}" "${hostkey}" |
| 87 | + _set_nvmet_hash "${def_hostnqn}" "hmac(sha384)" |
| 88 | + _set_nvmet_dhgroup "${def_hostnqn}" "ffdhe3072" |
| 89 | + |
| 90 | + echo "Test secure concatenation with SHA384" |
| 91 | + _nvme_connect_subsys --dhchap-secret "${hostkey}" --concat |
| 92 | + |
| 93 | + ctrl=$(_find_nvme_dev "${def_subsysnqn}") |
| 94 | + if _nvme_ctrl_tls_key "$ctrl" > /dev/null ; then |
| 95 | + echo "WARNING: connection is not encrypted" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + |
| 99 | + _nvme_disconnect_subsys |
| 100 | + |
| 101 | + _nvmet_target_cleanup |
| 102 | + |
| 103 | + echo "Test complete" |
| 104 | +} |
0 commit comments