-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test case for the PSK API to ensure that the generated JSON is correct. Signed-off-by: Daniel Wagner <dwagner@suse.de>
- Loading branch information
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[ | ||
{ | ||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36", | ||
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b6", | ||
"subsystems":[ | ||
{ | ||
"nqn":"nqn.io-1", | ||
"ports":[ | ||
{ | ||
"transport":"tcp", | ||
"traddr":"192.168.154.148", | ||
"trsvcid":"4420", | ||
"dhchap_key":"none", | ||
"tls":true, | ||
"tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[ | ||
{ | ||
"hostnqn":"nqn.2014-08.org.nvmexpress:uuid:befdec4c-2234-11b2-a85c-ca77c773af36", | ||
"hostid":"2cd2c43b-a90a-45c1-a8cd-86b33ab273b6", | ||
"subsystems":[ | ||
{ | ||
"nqn":"nqn.io-1", | ||
"ports":[ | ||
{ | ||
"transport":"tcp", | ||
"traddr":"192.168.154.148", | ||
"trsvcid":"4420", | ||
"dhchap_key":"none", | ||
"tls":true, | ||
"tls_key":"NVMeTLSkey-1:01:Hhc5sFjwSZ6w5hPY19tqprajYtuYci3tN+Z2wGViDk3rpSR+:" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
/** | ||
* This file is part of libnvme. | ||
* Copyright (c) 2024 Daniel Wagner, SUSE LLC | ||
*/ | ||
|
||
#include "nvme/linux.h" | ||
#include "nvme/tree.h" | ||
#include <string.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
|
||
#include <libnvme.h> | ||
|
||
static bool import_export_key(nvme_ctrl_t c) | ||
{ | ||
unsigned char version, hmac, *key; | ||
char *encoded_key; | ||
size_t len; | ||
|
||
key = nvme_import_tls_key_versioned(nvme_ctrl_get_tls_key(c), | ||
&version, &hmac, &len); | ||
if (!key) { | ||
printf("ERROR: nvme_import_tls_key_versioned failed with %d\n", | ||
errno); | ||
return false; | ||
|
||
} | ||
|
||
encoded_key = nvme_export_tls_key_versioned(version, hmac, | ||
key, len); | ||
if (!encoded_key) { | ||
printf("ERROR: nvme_export_tls_key_versioned failed with %d\n", | ||
errno); | ||
return false; | ||
} | ||
|
||
nvme_ctrl_set_tls_key(c, encoded_key); | ||
return true; | ||
} | ||
|
||
static bool psk_json_test(char *file) | ||
{ | ||
bool pass = false; | ||
nvme_root_t r; | ||
nvme_host_t h; | ||
nvme_subsystem_t s; | ||
nvme_ctrl_t c; | ||
int err; | ||
|
||
r = nvme_create_root(stderr, LOG_ERR); | ||
if (!r) | ||
return false; | ||
|
||
err = nvme_read_config(r, file); | ||
if (err) | ||
goto out; | ||
|
||
|
||
nvme_for_each_host(r, h) | ||
nvme_for_each_subsystem(h, s) | ||
nvme_subsystem_for_each_ctrl(s, c) | ||
if (!import_export_key(c)) | ||
goto out; | ||
|
||
err = nvme_dump_config(r); | ||
if (err) | ||
goto out; | ||
|
||
pass = true; | ||
|
||
out: | ||
nvme_free_tree(r); | ||
return pass; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
bool pass; | ||
|
||
pass = psk_json_test(argv[1]); | ||
fflush(stdout); | ||
|
||
exit(pass ? EXIT_SUCCESS : EXIT_FAILURE); | ||
} |