From f6316111df106778e34fb28754b4bce0531d6ba1 Mon Sep 17 00:00:00 2001 From: Roman Khlopkov <roman.khlopkov@demlabs.net> Date: Tue, 12 May 2020 14:52:01 +0300 Subject: [PATCH] [+] Metadata read & tool --- cellframe-sdk | 2 +- sources/main_node_tool.c | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cellframe-sdk b/cellframe-sdk index c7d8dc243..ca871a2bf 160000 --- a/cellframe-sdk +++ b/cellframe-sdk @@ -1 +1 @@ -Subproject commit c7d8dc243f489bdd3e95df9f45c41f89a1f7df7c +Subproject commit ca871a2bf1a314d0672cd11a0d8e6e3e3eec3d62 diff --git a/sources/main_node_tool.c b/sources/main_node_tool.c index 329705c28..c7de233a8 100644 --- a/sources/main_node_tool.c +++ b/sources/main_node_tool.c @@ -283,13 +283,11 @@ int main(int argc, const char **argv) exit(-7021); } } - } - else if ( strcmp( argv[2],"create" ) == 0 ) { + } else if ( strcmp( argv[2],"create" ) == 0 ) { if ( argc < 5 ) { s_help(); exit(-500); } - size_t l_key_length = 0; const char *l_cert_name = argv[3]; size_t l_cert_path_length = strlen(argv[3])+8+strlen(s_system_ca_dir); char *l_cert_path = DAP_NEW_Z_SIZE(char,l_cert_path_length); @@ -316,7 +314,6 @@ int main(int argc, const char **argv) } if ( l_key_type != DAP_ENC_KEY_TYPE_NULL ) { - int l_key_length = argc >=6 ? atoi(argv[5]) : 0; dap_cert_t * l_cert = dap_cert_generate(l_cert_name,l_cert_path,l_key_type ); // key length ignored! if (l_cert == NULL){ log_it(L_ERROR, "Can't create %s",l_cert_path); @@ -328,7 +325,28 @@ int main(int argc, const char **argv) exit(-500); } DAP_DELETE(l_cert_path); - + } else if (strcmp(argv[2], "add_meta") == 0) { + if (argc >= 5) { + const char *l_cert_name = argv[3]; + dap_cert_t *l_cert = dap_cert_add_file(l_cert_name, s_system_ca_dir); + if ( l_cert ) { + char **l_params = dap_strsplit(argv[3], ":", 4); + dap_cert_metadata_type_t l_type = (dap_cert_metadata_type_t)atoi(l_params[1]); + if (l_type == DAP_CERT_META_STRING || l_type == DAP_CERT_META_SIGN || l_type == DAP_CERT_META_CUSTOM) { + dap_cert_add_meta(l_cert, l_params[0], l_type, (void *)l_params[3], strtoul(l_params[2], NULL, 10)); + } else { + dap_cert_add_meta_scalar(l_cert, l_params[0], l_type, + strtoull(l_params[3], NULL, 10), strtoul(l_params[2], NULL, 10)); + } + dap_strfreev(l_params); + dap_cert_save_to_folder(l_cert, s_system_ca_dir); + dap_cert_delete_by_name(l_cert_name); + ret = 0; + } + else { + exit(-800); + } + } } else { log_it(L_ERROR,"Wrong params"); s_help(); -- GitLab