-----------
Generate a base64-encoded NVMe TLS pre-shared key (PSK).
The resulting key is either printed in the PSK interchange format
-'NVMeTLSkey-1:01:<base64 encoded data>:',
-inserted as a 'retained' key into the specified keyring, or both.
+'NVMeTLSkey-1:01:<base64 encoded data>:' or inserted as a
+'retained' key into the specified keyring if the '--insert' option
+is given.
When the PSK should be inserted into the keyring a 'retained' key
is derived from the secret key material. The resulting 'retained'
key is stored with the identity
cfg.identity);
return -EINVAL;
}
- if (cfg.insert && !cfg.subsysnqn) {
- nvme_show_error("No subsystem NQN specified");
- return -EINVAL;
+ if (cfg.insert) {
+ if (!cfg.subsysnqn) {
+ nvme_show_error("No subsystem NQN specified");
+ return -EINVAL;
+ }
+ if (!cfg.hostnqn) {
+ cfg.hostnqn = nvmf_hostnqn_from_file();
+ if (!cfg.hostnqn) {
+ nvme_show_error("Failed to read host NQN");
+ return -EINVAL;
+ }
+ }
}
if (cfg.hmac == 2)
key_len = 48;
}
}
- if (cfg.hostnqn && !cfg.subsysnqn) {
- nvme_show_error("Need to specify subsystem NQN to insert a TLS key");
- return -EINVAL;
- }
- if (cfg.subsysnqn) {
- if (!cfg.hostnqn) {
- cfg.hostnqn = nvmf_hostnqn_from_file();
- if (!cfg.hostnqn) {
- nvme_show_error("Failed to read host NQN");
- return -EINVAL;
- }
- }
-
+ if (cfg.insert) {
tls_key = nvme_insert_tls_key_versioned(cfg.keyring,
cfg.keytype, cfg.hostnqn,
cfg.subsysnqn, cfg.identity,
return -errno;
}
- if (cfg.insert) {
- printf("Inserted TLS key %08x\n", (unsigned int)tls_key);
- return 0;
- }
+ printf("Inserted TLS key %08x\n", (unsigned int)tls_key);
+ return 0;
}
crc = crc32(crc, raw_secret, key_len);
raw_secret[key_len++] = crc & 0xff;