Commit 3eee286a authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

nvme/auth: make get_{digest,dhgroup}_name() functions public



Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I63da019d2d53e76a7533a74a824623faa4b4edba
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22018


Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent ab93bb4e
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -4061,6 +4061,24 @@ void spdk_nvme_print_command(uint16_t qid, struct spdk_nvme_cmd *cmd);
 */
void spdk_nvme_print_completion(uint16_t qid, struct spdk_nvme_cpl *cpl);

/**
 * Return the name of a digest.
 *
 * \param id Digest identifier (see `enum spdk_nvmf_dhchap_hash`).
 *
 * \return Name of the digest.
 */
const char *spdk_nvme_dhchap_get_digest_name(int id);

/**
 * Return the name of a Diffie-Hellman group.
 *
 * \param id Diffie-Hellman group identifier (see `enum spdk_nvmf_dhchap_dhgroup`).
 *
 * \return Name of the Diffie-Hellman group.
 */
const char *spdk_nvme_dhchap_get_dhgroup_name(int id);

struct ibv_context;
struct ibv_pd;
struct ibv_mr;
+1 −2
Original line number Diff line number Diff line
@@ -14,11 +14,10 @@ C_SRCS = nvme_ctrlr_cmd.c nvme_ctrlr.c nvme_fabric.c nvme_ns_cmd.c \
	nvme_quirks.c nvme_transport.c nvme_discovery.c \
	nvme_ctrlr_ocssd_cmd.c nvme_ns_ocssd_cmd.c nvme_tcp.c \
	nvme_opal.c nvme_io_msg.c nvme_poll_group.c nvme_zns.c \
	nvme_stubs.c
	nvme_stubs.c nvme_auth.c
C_SRCS-$(CONFIG_NVME_CUSE) += nvme_cuse.c
C_SRCS-$(CONFIG_VFIO_USER) += nvme_vfio_user.c
C_SRCS-$(CONFIG_RDMA) += nvme_rdma.c
C_SRCS-$(CONFIG_HAVE_EVP_MAC) += nvme_auth.c

LIBNAME = nvme
LOCAL_SYS_LIBS =
+29 −23
Original line number Diff line number Diff line
@@ -9,9 +9,12 @@
#include "spdk/string.h"
#include "spdk/util.h"
#include "nvme_internal.h"

#ifdef SPDK_CONFIG_HAVE_EVP_MAC
#include <openssl/dh.h>
#include <openssl/evp.h>
#include <openssl/param_build.h>
#endif

struct nvme_auth_digest {
	uint8_t		id;
@@ -67,24 +70,16 @@ nvme_auth_get_digest(int id)
	return NULL;
}

static const char *
nvme_auth_get_digest_name(int id)
const char *
spdk_nvme_dhchap_get_digest_name(int id)
{
	const struct nvme_auth_digest *digest = nvme_auth_get_digest(id);

	return digest != NULL ? digest->name : NULL;
}

static uint8_t
nvme_auth_get_digest_len(int id)
{
	const struct nvme_auth_digest *digest = nvme_auth_get_digest(id);

	return digest != NULL ? digest->len : 0;
}

static const char *
nvme_auth_get_dhgroup_name(int id)
const char *
spdk_nvme_dhchap_get_dhgroup_name(int id)
{
	size_t i;

@@ -97,6 +92,15 @@ nvme_auth_get_dhgroup_name(int id)
	return NULL;
}

#ifdef SPDK_CONFIG_HAVE_EVP_MAC
static uint8_t
nvme_auth_get_digest_len(int id)
{
	const struct nvme_auth_digest *digest = nvme_auth_get_digest(id);

	return digest != NULL ? digest->len : 0;
}

static bool
nvme_auth_digest_allowed(struct spdk_nvme_qpair *qpair, uint8_t digest)
{
@@ -188,7 +192,7 @@ nvme_auth_transform_key(struct spdk_key *key, int hash, const char *nqn,
		goto out;
	}
	params[0] = OSSL_PARAM_construct_utf8_string("digest",
			(char *)nvme_auth_get_digest_name(hash), 0);
			(char *)spdk_nvme_dhchap_get_digest_name(hash), 0);
	params[1] = OSSL_PARAM_construct_end();

	if (EVP_MAC_init(ctx, keyin, keylen, params) != 1) {
@@ -297,7 +301,7 @@ nvme_auth_augment_challenge(const void *cval, size_t clen, const void *key, size
		return 0;
	}

	md = EVP_MD_fetch(NULL, nvme_auth_get_digest_name(hash), NULL);
	md = EVP_MD_fetch(NULL, spdk_nvme_dhchap_get_digest_name(hash), NULL);
	if (!md) {
		SPDK_ERRLOG("Failed to fetch digest function: %d\n", hash);
		return -EINVAL;
@@ -318,7 +322,7 @@ nvme_auth_augment_challenge(const void *cval, size_t clen, const void *key, size
		goto out;
	}
	params[0] = OSSL_PARAM_construct_utf8_string("digest",
			(char *)nvme_auth_get_digest_name(hash), 0);
			(char *)spdk_nvme_dhchap_get_digest_name(hash), 0);
	params[1] = OSSL_PARAM_construct_end();

	if (EVP_MAC_init(ctx, keydgst, dgstlen, params) != 1) {
@@ -379,7 +383,7 @@ nvme_auth_calc_response(struct spdk_key *key, enum spdk_nvmf_dhchap_hash hash,
	}

	params[0] = OSSL_PARAM_construct_utf8_string("digest",
			(char *)nvme_auth_get_digest_name(hash), 0);
			(char *)spdk_nvme_dhchap_get_digest_name(hash), 0);
	params[1] = OSSL_PARAM_construct_end();

	rc = -EIO;
@@ -440,11 +444,11 @@ nvme_auth_generate_dhkey(void *pub, size_t *len, enum spdk_nvmf_dhchap_dhgroup d
	}

	params[0] = OSSL_PARAM_construct_utf8_string("group",
			(char *)nvme_auth_get_dhgroup_name(dhgroup), 0);
			(char *)spdk_nvme_dhchap_get_dhgroup_name(dhgroup), 0);
	params[1] = OSSL_PARAM_construct_end();
	if (EVP_PKEY_CTX_set_params(ctx, params) != 1) {
		SPDK_ERRLOG("Failed to set dhkey's dhgroup: %s\n",
			    nvme_auth_get_dhgroup_name(dhgroup));
			    spdk_nvme_dhchap_get_dhgroup_name(dhgroup));
		goto error;
	}
	if (EVP_PKEY_generate(ctx, &key) != 1) {
@@ -504,7 +508,7 @@ nvme_auth_get_peerkey(const void *peerkey, size_t len, enum spdk_nvmf_dhchap_dhg
		goto error;
	}
	if (OSSL_PARAM_BLD_push_utf8_string(bld, "group",
					    (char *)nvme_auth_get_dhgroup_name(dhgroup), 0) != 1) {
					    (char *)spdk_nvme_dhchap_get_dhgroup_name(dhgroup), 0) != 1) {
		goto error;
	}

@@ -705,7 +709,7 @@ nvme_auth_send_negotiate(struct spdk_nvme_qpair *qpair)
			continue;
		}
		AUTH_DEBUGLOG(qpair, "digest: %u (%s)\n", g_digests[i].id,
			      nvme_auth_get_digest_name(g_digests[i].id));
			      spdk_nvme_dhchap_get_digest_name(g_digests[i].id));
		desc->hash_id_list[desc->halen++] = g_digests[i].id;
	}
	for (i = 0; i < SPDK_COUNTOF(g_dhgroups); ++i) {
@@ -713,7 +717,7 @@ nvme_auth_send_negotiate(struct spdk_nvme_qpair *qpair)
			continue;
		}
		AUTH_DEBUGLOG(qpair, "dhgroup: %u (%s)\n", g_dhgroups[i].id,
			      nvme_auth_get_dhgroup_name(g_dhgroups[i].id));
			      spdk_nvme_dhchap_get_dhgroup_name(g_dhgroups[i].id));
		desc->dhg_id_list[desc->dhlen++] = g_dhgroups[i].id;
	}

@@ -790,13 +794,13 @@ nvme_auth_check_challenge(struct spdk_nvme_qpair *qpair)

	if (!nvme_auth_digest_allowed(qpair, challenge->hash_id)) {
		AUTH_ERRLOG(qpair, "received disallowed digest: %u (%s)\n", challenge->hash_id,
			    nvme_auth_get_digest_name(challenge->hash_id));
			    spdk_nvme_dhchap_get_digest_name(challenge->hash_id));
		goto error;
	}

	if (!nvme_auth_dhgroup_allowed(qpair, challenge->dhg_id)) {
		AUTH_ERRLOG(qpair, "received disallowed dhgroup: %u (%s)\n", challenge->dhg_id,
			    nvme_auth_get_dhgroup_name(challenge->dhg_id));
			    spdk_nvme_dhchap_get_dhgroup_name(challenge->dhg_id));
		goto error;
	}

@@ -1071,4 +1075,6 @@ nvme_fabric_qpair_authenticate_async(struct spdk_nvme_qpair *qpair)
	rc = nvme_fabric_qpair_authenticate_poll(qpair);
	return rc != -EAGAIN ? rc : 0;
}
#endif /* SPDK_CONFIG_EVP_MAC */

SPDK_LOG_REGISTER_COMPONENT(nvme_auth)
+3 −0
Original line number Diff line number Diff line
@@ -207,6 +207,9 @@
	spdk_nvme_poll_group_get_stats;
	spdk_nvme_poll_group_free_stats;

	spdk_nvme_dhchap_get_digest_name;
	spdk_nvme_dhchap_get_dhgroup_name;

	# public functions from nvme_zns.h
	spdk_nvme_zns_ns_get_data;
	spdk_nvme_zns_ns_get_zone_size_sectors;