Skip to content

Commit

Permalink
Merge pull request linux-nvme#749 from hreinecke/TP8018-fixes
Browse files Browse the repository at this point in the history
Fixes for TP8018 support
  • Loading branch information
hreinecke authored Nov 20, 2023
2 parents f284041 + b43d921 commit 4fe9e40
Showing 1 changed file with 38 additions and 47 deletions.
85 changes: 38 additions & 47 deletions src/nvme/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ static int derive_retained_key(int hmac, const char *hostnqn,
{
nvme_msg(NULL, LOG_ERR, "NVMe TLS is not supported; "
"recompile with OpenSSL support.\n");
errno = NOTSUP;
errno = ENOTSUP;
return -1;
}

Expand All @@ -561,7 +561,7 @@ static int gen_tls_identity(const char *hostnqn, const char *subsysnqn,
if (version != 0) {
nvme_msg(NULL, LOG_ERR, "NVMe TLS 2.0 is not supported; "
"recompile with OpenSSL support.\n");
errno = NOTSUP;
errno = ENOTSUP;
return -1;
}
sprintf(identity, "NVMe0R%02d %s %s",
Expand All @@ -575,7 +575,7 @@ static int derive_tls_key(int hmac, const char *identity,
{
nvme_msg(NULL, LOG_ERR, "NVMe TLS is not supported; "
"recompile with OpenSSL support.\n");
errno = NOTSUP;
errno = ENOTSUP;
return -1;
}
#else /* CONFIG_OPENSSL */
Expand Down Expand Up @@ -1092,7 +1092,6 @@ static int gen_tls_identity(const char *hostnqn, const char *subsysnqn,
}
#endif /* !CONFIG_OPENSSL_3 */

#ifdef CONFIG_KEYUTILS
static int derive_nvme_keys(const char *hostnqn, const char *subsysnqn,
char *identity, int version,
int hmac, unsigned char *configured,
Expand All @@ -1101,7 +1100,7 @@ static int derive_nvme_keys(const char *hostnqn, const char *subsysnqn,
unsigned char *retained;
int ret = -1;

if (!hostnqn || !subsysnqn || !identity) {
if (!hostnqn || !subsysnqn || !identity || !psk) {
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -1141,6 +1140,40 @@ static size_t nvme_identity_len(int hmac, int version, const char *hostnqn,
return len;
}

char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
int version, int hmac,
unsigned char *configured_key, int key_len)
{
char *identity;
size_t identity_len;
unsigned char *psk;
int ret = -1;

identity_len = nvme_identity_len(hmac, version, hostnqn, subsysnqn);
if (identity_len < 0)
return NULL;

identity = malloc(identity_len);
if (!identity)
return NULL;

psk = malloc(key_len);
if (!psk)
goto out_free_identity;

memset(psk, 0, key_len);
ret = derive_nvme_keys(hostnqn, subsysnqn, identity, version, hmac,
configured_key, psk, key_len);
free(psk);
out_free_identity:
if (ret < 0) {
free(identity);
identity = NULL;
}
return identity;
}

#ifdef CONFIG_KEYUTILS
long nvme_lookup_keyring(const char *keyring)
{
key_serial_t keyring_id;
Expand Down Expand Up @@ -1233,38 +1266,6 @@ long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type,
return key;
}

char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
int version, int hmac,
unsigned char *configured_key, int key_len)
{
char *identity;
size_t identity_len;
unsigned char *psk;
int ret = -1;

identity_len = nvme_identity_len(hmac, version, hostnqn, subsysnqn);
if (identity_len < 0)
return NULL;

identity = malloc(identity_len);
if (!identity)
return NULL;

psk = malloc(key_len);
if (!psk)
goto out_free_identity;

memset(psk, 0, key_len);
ret = derive_nvme_keys(hostnqn, subsysnqn, identity, version, hmac,
configured_key, psk, key_len);
free(psk);
out_free_identity:
if (ret < 0) {
free(identity);
identity = NULL;
}
return identity;
}
#else
long nvme_lookup_keyring(const char *keyring)
{
Expand Down Expand Up @@ -1308,16 +1309,6 @@ long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type,
errno = ENOTSUP;
return -1;
}

char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
int version, int hmac,
unsigned char *configured_key, int key_len)
{
nvme_msg(NULL, LOG_ERR, "key operations not supported; "
"recompile with keyutils support.\n");
errno = ENOTSUP;
return -1;
}
#endif

long nvme_insert_tls_key(const char *keyring, const char *key_type,
Expand Down

0 comments on commit 4fe9e40

Please sign in to comment.