Skip to content

Commit 990fc84

Browse files
committed
nvme: add testcase for secure concatenation
The patchset 'nvme: implement secure concatenaion' implements secure concatenation for NVMe-over-TCP, and we should have a testcase exercising that. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent f8a0bd1 commit 990fc84

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

tests/nvme/060

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
}
24+
25+
set_conditions() {
26+
_set_nvme_trtype "$@"
27+
}
28+
29+
test() {
30+
echo "Running ${TEST_NAME}"
31+
32+
_setup_nvmet
33+
34+
local hostkey
35+
36+
systemctl restart tlshd
37+
38+
hostkey=$(nvme gen-dhchap-key -m 1 -n "${def_hostnqn}" 2> /dev/null)
39+
if [ -z "$hostkey" ] ; then
40+
echo "nvme gen-dhchap-key failed"
41+
return 1
42+
fi
43+
44+
_nvmet_target_setup --blkdev file --hostkey "${hostkey}" --tls
45+
_set_nvmet_hash "${def_hostnqn}" "hmac(sha256)"
46+
_set_nvmet_dhgroup "${def_hostnqn}" "ffdhe2048"
47+
48+
echo "Test secure concatenation with SHA256"
49+
_nvme_connect_subsys --dhchap-secret "${hostkey}" --concat
50+
51+
ctrl=$(_find_nvme_dev "${def_subsysnqn}")
52+
if [[ -z "$ctrl" ]]; then
53+
echo "WARNING: connection failed"
54+
exit 1
55+
fi
56+
tlskey=$(_check_ctrl_tls "$ctrl" 2> /dev/null || true)
57+
if [[ -z "$tlskey" ]]; then
58+
echo "WARNING: connection is not encrypted"
59+
exit 1
60+
fi
61+
62+
# Reset controller to force re-negotiation
63+
echo "Reset controller"
64+
if ! nvme reset "/dev/${ctrl}" ; then
65+
echo "WARNING: failed to reset controller"
66+
fi
67+
68+
new_tlskey=$(_check_ctrl_tls "$ctrl" 2> /dev/null || true)
69+
if [[ -z "$new_tlskey" ]]; then
70+
echo "WARNING: connection is not encrypted"
71+
elif [[ "$new_tlskey" = "$tlskey" ]]; then
72+
echo "WARNING: TLS key has not been renegotiated"
73+
fi
74+
75+
_nvme_disconnect_subsys
76+
77+
hostkey=$(nvme gen-dhchap-key -m 2 -n "${def_hostnqn}" 2> /dev/null)
78+
if [ -z "$hostkey" ] ; then
79+
echo "nvme gen-dhchap-key failed"
80+
return 1
81+
fi
82+
83+
_set_nvmet_hostkey "${def_hostnqn}" "${hostkey}"
84+
_set_nvmet_hash "${def_hostnqn}" "hmac(sha384)"
85+
_set_nvmet_dhgroup "${def_hostnqn}" "ffdhe3072"
86+
87+
echo "Test secure concatenation with SHA384"
88+
_nvme_connect_subsys --dhchap-secret "${hostkey}" --concat
89+
90+
ctrl=$(_find_nvme_dev "${def_subsysnqn}")
91+
if [[ -z "$ctrl" ]]; then
92+
echo "WARNING: connection failed"
93+
exit 1
94+
fi
95+
tlskey=$(_check_ctrl_tls "$ctrl" 2> /dev/null || true)
96+
if [[ -z "$tlskey" ]]; then
97+
echo "WARNING: connection is not encrypted"
98+
exit 1
99+
fi
100+
101+
_nvme_disconnect_subsys
102+
103+
_nvmet_target_cleanup
104+
105+
echo "Test complete"
106+
}

tests/nvme/060.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Running nvme/060
2+
Test secure concatenation with SHA256
3+
Reset controller
4+
disconnected 1 controller(s)
5+
Test secure concatenation with SHA384
6+
disconnected 1 controller(s)
7+
Test complete

0 commit comments

Comments
 (0)