nvme-cli authentication support
Subsystems (3)
PATCH v5 1/3 Add 'gen-dhchap-key' command
In reply to Hannes ReineckeAdd command 'gen-dhchap-key' to generate an DH-HMAC-CHAP host key for NVMe in-band authentication.
--- Documentation/nvme-gen-dhchap-key.txt | 52 ++++++++ Makefile | 17 ++- nvme-builtin.h | 1 + nvme.c | 178 ++++++++++++++++++++++++++ util/argconfig.h | 1 + util/base64.c | 62 +++++++++ util/base64.h | 6 + 7 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 Documentation/nvme-gen-dhchap-key.txt create mode 100644 util/base64.c create mode 100644 util/base64.h
Documentation/nvme-gen-dhchap-key.txt new file +52 -0
@@ -0,0 +1,52 @@ +nvme-gen-dhchap-key(1) +=================== + +NAME +---- +nvme-gen-dhchap-key - Generate a host DH-HMAC-CHAP key + +SYNOPSIS +-------- +[verse] +'nvme gen-dhchap-key' [--hmac=<hmac-id> | -h <hmac-id>] + [--secret=<secret> | -s <secret> ] + [--key-length=<len> | -l <len> ] + [--nqn=<host-nqn> | -n <host-nqn> ] + +DESCRIPTION +----------- +Generate a base64-encoded DH-HMAC-CHAP host key in the form: +DHHC-1:00:ia6zGodOr4SEG0Zzaw398rpY0wqipUWj4jWjUh4HWUz6aQ2n: +and prints it to stdout. + +OPTIONS +------- +-h <hmac-id>:: +--hmac=<hmac-id>:: + Select a HMAC algorithm to use. Possible values are: + 0 - No HMAC algorithm + 1 - SHA-256 + 2 - SHA-384 + 3 - SHA-512 + +-s <secret>:: +--secret=<secret>:: + Secret value (in hexadecimal) to be used for the key. If none are + provided a random value is used. + +-l <len>:: +--key-length=<len>:: + Length of the resulting key. Possible values are 32, 48, or 64. + +-n <hostnqn>:: +--nqn=<hostnqn>:: + Host-NQN to be used for the transformation. This parameter is only + valid if a non-zero HMAC function has been specified. + +EXAMPLES +-------- +No Examples + +NVME +---- +Part of the nvme-user suite
Makefile +16 -1
@@ -5,6 +5,8 @@ LIBUUID = $(shell $(LD) -o /dev/null -luuid >/dev/null 2>&1; echo $$?) LIBHUGETLBFS = $(shell $(LD) -o /dev/null -lhugetlbfs >/dev/null 2>&1; echo $$?) HAVE_SYSTEMD = $(shell pkg-config --exists libsystemd --atleast-version=242; echo $$?) LIBJSONC = $(shell $(LD) -o /dev/null -ljson-c >/dev/null 2>&1; echo $$?) +LIBZ = $(shell $(LD) -o /dev/null -lz >/dev/null 2>&1; echo $$?) +LIBOPENSSL = $(shell $(LD) -o /dev/null -lssl >/dev/null 2>&1; echo $$?) NVME = nvme INSTALL ?= install DESTDIR =
@@ -37,6 +39,18 @@ ifeq ($(LIBHUGETLBFS),0) override LIB_DEPENDS += hugetlbfs endif +ifeq ($(LIBZ),0) + override LDFLAGS += -lz + override CFLAGS += -DLIBZ + override LIB_DEPENDS += zlib +endif + +ifeq ($(LIBOPENSSL),0) + override LDFLAGS += -lssl -lcrypto + override CFLAGS += -DOPENSSL + override LIB_DEPENDS += openssl +endif + INC=-Iutil ifeq ($(HAVE_SYSTEMD),0)
@@ -88,7 +102,8 @@ OBJS := nvme-print.o nvme-rpmb.o \ fabrics.o nvme-models.o plugin.o UTIL_OBJS := util/argconfig.o util/suffix.o util/parser.o \ - util/cleanup.o + util/cleanup.o util/base64.o + ifneq ($(LIBJSONC), 0) override UTIL_OBJS += util/json.o endif
nvme-builtin.h +1 -0
@@ -81,6 +81,7 @@ COMMAND_LIST( ENTRY("disconnect-all", "Disconnect from all connected NVMeoF subsystems", disconnect_all_cmd) ENTRY("gen-hostnqn", "Generate NVMeoF host NQN", gen_hostnqn_cmd) ENTRY("show-hostnqn", "Show NVMeoF host NQN", show_hostnqn_cmd) + ENTRY("gen-dhchap-key", "Generate NVMeoF DH-HMAC-CHAP host key", gen_dhchap_key) ENTRY("dir-receive", "Submit a Directive Receive command, return results", dir_receive) ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send)ENTRY ("virt-mgmt" ,"Manage Flexible Resources between Primary and Secondary Controller " , virtual_mgmt)
nvme.c +178 -0
206 lines not on this page · raw message
util/argconfig.h +1 -0
@@ -100,6 +100,7 @@ enum argconfig_types {#define OPT_FMT (l, s, v, d) OPT_STRING(l, s, "FMT", v, d)#define OPT_FILE (l, s, v, d) OPT_STRING(l, s, "FILE", v, d)#define OPT_LIST (l, s, v, d) OPT_STRING(l, s, "LIST", v, d) +#define OPT_STR (l, s, v, d) OPT_STRING(l, s, "STRING", v, d)struct argconfig_commandline_options {const char *option;
util/base64.c new file +62 -0
62 lines not on this page · raw message
util/base64.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _BASE64_H +#define _BASE64_H + +int base64_encode (const unsigned char *src,int len,char *dst); + +#endif /* _BASE64_H */
Signature · 1 line
2.31.1
PATCH v5 3/3 nvme-connect: Add 'dhchap-secret' and 'dhchap-ctrl-secret' arguments
In reply to Hannes ReineckeAdd 'dhchap-secret' and 'dhchap-ctrl-secret' arguments for nvme-connect to enable NVMe In-Band authentication.
--- Documentation/nvme-connect.txt | 17 +++++++++++++++++ fabrics.c | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-)
Documentation/nvme-connect.txt +17 -0
@@ -17,6 +17,8 @@ SYNOPSIS [--host-iface=<iface> | -f <iface>] [--hostnqn=<hostnqn> | -q <hostnqn>] [--hostid=<hostid> | -I <hostid>] + [--dhchap-secret=<secret> | -S <secret>] + [--dhchap-ctrl-secret=<secret> | -C <secret>] [--nr-io-queues=<#> | -i <#>] [--nr-write-queues=<#> | -W <#>] [--nr-poll-queues=<#> | -P <#>]
@@ -92,6 +94,21 @@ OPTIONS UUID(Universally Unique Identifier) to be discovered which should be formatted. +-S <secret>:: +--dhchap-secret=<secret>:: + NVMe In-band authentication secret; needs to be in ASCII format as + specified in NVMe 2.0 section 8.13.5.8 'Secret representation'. + If this option is not specified, the default is read from + /etc/nvme/hostkey. If that does not exist no in-band authentication + is attempted. + +-C <secret>:: +--dhchap-ctrl-secret=<secret>:: + NVMe In-band authentication controller secret for bi-directional + authentication; needs to be in ASCII format as + specified in NVMe 2.0 section 8.13.5.8 'Secret representation'. + If not present bi-directional authentication is not attempted. + -i <#>:: --nr-io-queues=<#>:: Overrides the default number of I/O queues create by the driver.
fabrics.c +14 -3
@@ -60,6 +60,8 @@ static const char *nvmf_htraddr = "host traddr (e.g. FC WWN's)";static const char *nvmf_hiface ="host interface (for tcp transport)" ;static const char *nvmf_hostnqn ="user-defined hostnqn" ;static const char *nvmf_hostid ="user-defined hostid (if default not used)" ; +static const char *nvmf_hostkey ="user-defined dhchap key (if default not used)" ; +static const char *nvmf_ctrlkey ="user-defined dhchap controller key (for bi-directional authentication)" ;static const char *nvmf_nr_io_queues ="number of io queues to use (default is core count)" ;static const char *nvmf_nr_write_queues ="number of write queues to use (default 0)" ;static const char *nvmf_nr_poll_queues ="number of poll queues to use (default 0)" ;
@@ -82,6 +84,8 @@ static const char *nvmf_config_file = "Use specified JSON configuration file orOPT_STRING ("host-iface" ,'f' ,"STR" , &host_iface, nvmf_hiface), \OPT_STRING ("hostnqn" ,'q' ,"STR" , &hostnqn, nvmf_hostnqn), \OPT_STRING ("hostid" ,'I' ,"STR" , &hostid, nvmf_hostid), \ +OPT_STRING ("dhchap-secret" ,'S' ,"STR" , &hostkey, nvmf_hostkey), \ +OPT_STRING ("dhchap-ctrl-secret" ,'C' ,"STR" , &ctrlkey, nvmf_ctrlkey), \OPT_INT ("nr-io-queues" ,'i' , &c.nr_io_queues, nvmf_nr_io_queues), \OPT_INT ("nr-write-queues" ,'W' , &c.nr_write_queues, nvmf_nr_write_queues),\ OPT_INT("nr-poll-queues", 'P', &c.nr_poll_queues, nvmf_nr_poll_queues), \
@@ -93,7 +97,7 @@ static const char *nvmf_config_file = "Use specified JSON configuration file orOPT_FLAG ("duplicate-connect" ,'D' , &c.duplicate_connect, nvmf_dup_connect), \OPT_FLAG ("disable-sqflow" ,'d' , &c.disable_sqflow, nvmf_disable_sqflow), \OPT_FLAG ("hdr-digest" ,'g' , &c.hdr_digest, nvmf_hdr_digest), \ - OPT_FLAG("data-digest", 'G', &c.data_digest, nvmf_data_digest) \ + OPT_FLAG("data-digest", 'G', &c.data_digest, nvmf_data_digest) \static void space_strip_len (int max,char *str)
@@ -296,7 +300,7 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc, {char *transport =NULL , *traddr =NULL , *trsvcid =NULL ;char *host_traddr =NULL , *host_iface =NULL ; -char *hostnqn =NULL , *hostid =NULL ; +char *hostnqn =NULL , *hostid =NULL , *hostkey =NULL , *ctrlkey =NULL ;char *ptr, **argv, *p, line[4096 ];int argc, ret =0 ;unsigned int verbose =0 ;
@@ -383,7 +387,7 @@ out:int nvmf_discover (const char *desc,int argc,char **argv,bool connect) {char *nqn =NVME_DISC_SUBSYS_NAME ; -char *hostnqn =NULL , *hostid =NULL ; +char *hostnqn =NULL , *hostid =NULL , *hostkey =NULL , *ctrlkey =NULL ;char *host_traddr =NULL , *host_iface =NULL ;char *transport =NULL , *traddr =NULL , *trsvcid =NULL ;char *hnqn =NULL , *hid =NULL ;
@@ -459,6 +463,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)else if (!strncmp (device,"/dev/" ,5 )) device +=5 ; } +if (hostkey) +nvme_host_set_dhchap_key (h, hostkey);if (!device && !transport && !traddr) { ret =discover_from_conf_file (h, desc, connect, &cfg);
@@ -546,6 +552,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)char *transport =NULL , *traddr =NULL ;char *host_traddr =NULL , *host_iface =NULL ;char *trsvcid =NULL , *hostnqn =NULL , *hostid =NULL ; +char *hostkey =NULL , *ctrlkey =NULL ;char *config_file =PATH_NVMF_CONFIG ;unsigned int verbose =0 ;nvme_root_t r;
@@ -618,12 +625,16 @@ int nvmf_connect(const char *desc, int argc, char **argv) errno =ENOMEM ; goto out_free; } +if (hostkey) +nvme_host_set_dhchap_key (h, hostkey); c =nvme_create_ctrl (subsysnqn, transport, traddr, host_traddr, host_iface, trsvcid);if (!c) { errno =ENOMEM ; goto out_free; } +if (ctrlkey) +nvme_ctrl_set_dhchap_key (c, ctrlkey); errno =0 ; ret =nvmf_add_ctrl (h, c, &cfg, cfg.disable_sqflow);
Signature · 1 line
2.31.1
v5 cover nvme-cli authentication support
Hi all,
this patchset implements support for nvme in-band authentication. It is cut against the current nvme-cli master branch, and requires a libnvme patch 'Implement dhchap_key host and controller attributes'.
The implementation corresponds to the v5 version of the kernel patches for implementing nvme in-band authentication.
As usual, comments and reviews are welcome.
Hannes Reinecke (3):
Add 'gen-dhchap-key' command
Add 'check-dhchap-key' function
nvme-connect: Add 'dhchap-secret' and 'dhchap-ctrl-secret' arguments
Documentation/nvme-check-dhchap-key.txt | 31 +++ Documentation/nvme-connect.txt | 17 ++ Documentation/nvme-gen-dhchap-key.txt | 52 +++++ Makefile | 17 +- fabrics.c | 17 +- nvme-builtin.h | 2 + nvme.c | 276 ++++++++++++++++++++++++ util/argconfig.h | 1 + util/base64.c | 105 +++++++++ util/base64.h | 7 + 10 files changed, 521 insertions(+), 4 deletions(-) create mode 100644 Documentation/nvme-check-dhchap-key.txt create mode 100644 Documentation/nvme-gen-dhchap-key.txt create mode 100644 util/base64.c create mode 100644 util/base64.h
Signature · 1 line
2.31.1
PATCH v5 2/3 Add 'check-dhchap-key' function
Add a function to validate a given DH-HMAC-CHAP key in transport encoding for NVMe in-band authentication.
--- Documentation/nvme-check-dhchap-key.txt | 31 ++++++++ nvme-builtin.h | 1 + nvme.c | 98 +++++++++++++++++++++++++ util/base64.c | 43 +++++++++++ util/base64.h | 1 + 5 files changed, 174 insertions(+) create mode 100644 Documentation/nvme-check-dhchap-key.txt
Documentation/nvme-check-dhchap-key.txt new file +31 -0
@@ -0,0 +1,31 @@ +nvme-check-dhchap-key(1) +=================== + +NAME +---- +nvme-check-dhchap-key - Check a generated host DH-HMAC-CHAP key + +SYNOPSIS +-------- +[verse] +'nvme check-dhchap-key' [--key=<key> ] + +DESCRIPTION +----------- +Checks if the key is a valid DH-HMAC-CHAP host key of the form: +DHHC-1:00:ia6zGodOr4SEG0Zzaw398rpY0wqipUWj4jWjUh4HWUz6aQ2n: +and prints it to stdout. + +OPTIONS +------- +-k <key>:: +--key=<key>:: + Key to be checked. + +EXAMPLES +-------- +No Examples + +NVME +---- +Part of the nvme-user suite
nvme-builtin.h +1 -0
@@ -82,6 +82,7 @@ COMMAND_LIST( ENTRY("gen-hostnqn", "Generate NVMeoF host NQN", gen_hostnqn_cmd) ENTRY("show-hostnqn", "Show NVMeoF host NQN", show_hostnqn_cmd) ENTRY("gen-dhchap-key", "Generate NVMeoF DH-HMAC-CHAP host key", gen_dhchap_key) + ENTRY("check-dhchap-key", "Validate NVMeoF DH-HMAC-CHAP host key", check_dhchap_key) ENTRY("dir-receive", "Submit a Directive Receive command, return results", dir_receive) ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send)ENTRY ("virt-mgmt" ,"Manage Flexible Resources between Primary and Secondary Controller " , virtual_mgmt)
nvme.c +98 -0
104 lines not on this page · raw message
util/base64.c +43 -0
52 lines not on this page · raw message
util/base64.h +1 -0
@@ -2,5 +2,6 @@#define _BASE64_Hint base64_encode (const unsigned char *src,int len,char *dst); +int base64_decode (const char *src,int len,unsigned char *dst);#endif /* _BASE64_H */
Signature · 1 line
2.31.1