Skip to content

Commit 9aa2023

Browse files
hreineckekawasaki
authored andcommitted
nvme: add testcase for secure concatenation
NVMe-TCP has a 'secure concatenation' mode, where the TLS PSK is generated from the secret negotiated by the DH-HMAC-CHAP authentication, and the TLS connection is started after authentication. [Shin'ichiro: used _systemctl_start and _systemctl_stop] Signed-off-by: Hannes Reinecke <[email protected]> [Shin'ichiro: added _have_systemd_tlshd_service, avoided "exit 1"] Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 5d4e204 commit 9aa2023

2 files changed

Lines changed: 116 additions & 0 deletions

File tree

tests/nvme/063

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

tests/nvme/063.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Running nvme/063
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)