Skip to content

Commit b9f08d5

Browse files
dwsuseigaw
authored andcommitted
tree: read tls_configured_key and tls_keyring from sysfs
Newer kernels expose the key which is used to setup the connection as tls_configured_key. During operations the kernel is going to update the tls_key thus the tls_key is not going to be useful from user point of view. Also the keyring used to store the keys is exposed via sysfs. Signed-off-by: Daniel Wagner <[email protected]>
1 parent f23ae8c commit b9f08d5

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

src/nvme/tree.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,18 +1960,38 @@ static void nvme_read_sysfs_dhchap(nvme_root_t r, nvme_ctrl_t c)
19601960

19611961
static void nvme_read_sysfs_tls(nvme_root_t r, nvme_ctrl_t c)
19621962
{
1963-
char *tls_psk;
1964-
1965-
tls_psk = nvme_get_ctrl_attr(c, "tls_key");
1966-
if (tls_psk) {
1967-
char *endptr;
1968-
long key_id = strtol(tls_psk, &endptr, 16);
1963+
char *endptr;
1964+
long key_id;
1965+
char *key, *keyring;
19691966

1970-
if (endptr != tls_psk) {
1971-
c->cfg.tls_key = key_id;
1972-
c->cfg.tls = true;
1973-
}
1967+
key = nvme_get_ctrl_attr(c, "tls_key");
1968+
if (!key) {
1969+
/* tls_key is only present if --tls has been used. */
1970+
return;
19741971
}
1972+
c->cfg.tls = true;
1973+
1974+
keyring = nvme_get_ctrl_attr(c, "tls_keyring");
1975+
nvme_ctrl_set_keyring(c, keyring);
1976+
free(keyring);
1977+
1978+
/* the sysfs entry is not prefixing the id but it's in hex */
1979+
key_id = strtol(key, &endptr, 16);
1980+
if (endptr != key)
1981+
c->cfg.tls_key = key_id;
1982+
1983+
free(key);
1984+
1985+
key = nvme_get_ctrl_attr(c, "tls_configured_key");
1986+
if (!key)
1987+
return;
1988+
1989+
/* the sysfs entry is not prefixing the id but it's in hex */
1990+
key_id = strtol(key, &endptr, 16);
1991+
if (endptr != key)
1992+
c->cfg.tls_configured_key = key_id;
1993+
1994+
free(key);
19751995
}
19761996

19771997
static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,

0 commit comments

Comments
 (0)