mirror of https://github.com/openssl/openssl.git
Add a recursive option to 'openssl storeutl'
Simply put, any NAME type OSS_STORE_INTO is a new object that can be looked into, and potentially lead to a whole tree of data to dive into. The recursive option allows someone to view the whole tree and its data in one go. Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/4336)
This commit is contained in:
parent
15a1bd0ab2
commit
fb43ddceda
|
@ -14,9 +14,12 @@
|
||||||
#include <openssl/pem.h>
|
#include <openssl/pem.h>
|
||||||
#include <openssl/store.h>
|
#include <openssl/store.h>
|
||||||
|
|
||||||
|
static int process(const char *uri, const UI_METHOD *uimeth, PW_CB_DATA *uidata,
|
||||||
|
int text, int noout, int recursive, int indent, BIO *out);
|
||||||
|
|
||||||
typedef enum OPTION_choice {
|
typedef enum OPTION_choice {
|
||||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ENGINE, OPT_OUT, OPT_PASSIN,
|
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ENGINE, OPT_OUT, OPT_PASSIN,
|
||||||
OPT_NOOUT, OPT_TEXT
|
OPT_NOOUT, OPT_TEXT, OPT_RECURSIVE
|
||||||
} OPTION_CHOICE;
|
} OPTION_CHOICE;
|
||||||
|
|
||||||
const OPTIONS storeutl_options[] = {
|
const OPTIONS storeutl_options[] = {
|
||||||
|
@ -29,13 +32,13 @@ const OPTIONS storeutl_options[] = {
|
||||||
#ifndef OPENSSL_NO_ENGINE
|
#ifndef OPENSSL_NO_ENGINE
|
||||||
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
|
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
|
||||||
#endif
|
#endif
|
||||||
|
{"r", OPT_RECURSIVE, '-', "Recurse through names"},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
int storeutl_main(int argc, char *argv[])
|
int storeutl_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
OSSL_STORE_CTX *store_ctx = NULL;
|
int ret = 1, noout = 0, text = 0, recursive = 0;
|
||||||
int ret = 1, noout = 0, text = 0, items = 0;
|
|
||||||
char *outfile = NULL, *passin = NULL, *passinarg = NULL;
|
char *outfile = NULL, *passin = NULL, *passinarg = NULL;
|
||||||
BIO *out = NULL;
|
BIO *out = NULL;
|
||||||
ENGINE *e = NULL;
|
ENGINE *e = NULL;
|
||||||
|
@ -66,6 +69,9 @@ int storeutl_main(int argc, char *argv[])
|
||||||
case OPT_TEXT:
|
case OPT_TEXT:
|
||||||
text = 1;
|
text = 1;
|
||||||
break;
|
break;
|
||||||
|
case OPT_RECURSIVE:
|
||||||
|
recursive = 1;
|
||||||
|
break;
|
||||||
case OPT_ENGINE:
|
case OPT_ENGINE:
|
||||||
e = setup_engine(opt_arg(), 0);
|
e = setup_engine(opt_arg(), 0);
|
||||||
break;
|
break;
|
||||||
|
@ -94,11 +100,40 @@ int storeutl_main(int argc, char *argv[])
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if ((store_ctx = OSSL_STORE_open(argv[0], get_ui_method(), &pw_cb_data,
|
ret = process(argv[0], get_ui_method(), &pw_cb_data, text, noout, recursive,
|
||||||
NULL, NULL)) == NULL) {
|
0, out);
|
||||||
BIO_printf(bio_err, "Couldn't open file or uri %s\n", argv[0]);
|
|
||||||
|
end:
|
||||||
|
BIO_free_all(out);
|
||||||
|
OPENSSL_free(passin);
|
||||||
|
release_engine(e);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int indent_printf(int indent, BIO *bio, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
|
||||||
|
ret = BIO_printf(bio, "%*s", indent, "") + BIO_vprintf(bio, format, args);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int process(const char *uri, const UI_METHOD *uimeth, PW_CB_DATA *uidata,
|
||||||
|
int text, int noout, int recursive, int indent, BIO *out)
|
||||||
|
{
|
||||||
|
OSSL_STORE_CTX *store_ctx = NULL;
|
||||||
|
int ret = 1, items = 0;
|
||||||
|
|
||||||
|
if ((store_ctx = OSSL_STORE_open(uri, uimeth, uidata, NULL, NULL))
|
||||||
|
== NULL) {
|
||||||
|
BIO_printf(bio_err, "Couldn't open file or uri %s\n", uri);
|
||||||
ERR_print_errors(bio_err);
|
ERR_print_errors(bio_err);
|
||||||
goto end;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* From here on, we count errors, and we'll return the count at the end */
|
/* From here on, we count errors, and we'll return the count at the end */
|
||||||
|
@ -115,7 +150,10 @@ int storeutl_main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (OSSL_STORE_error(store_ctx)) {
|
if (OSSL_STORE_error(store_ctx)) {
|
||||||
ERR_print_errors(bio_err);
|
if (recursive)
|
||||||
|
ERR_clear_error();
|
||||||
|
else
|
||||||
|
ERR_print_errors(bio_err);
|
||||||
ret++;
|
ret++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -132,11 +170,12 @@ int storeutl_main(int argc, char *argv[])
|
||||||
if (type == OSSL_STORE_INFO_NAME) {
|
if (type == OSSL_STORE_INFO_NAME) {
|
||||||
const char *name = OSSL_STORE_INFO_get0_NAME(info);
|
const char *name = OSSL_STORE_INFO_get0_NAME(info);
|
||||||
const char *desc = OSSL_STORE_INFO_get0_NAME_description(info);
|
const char *desc = OSSL_STORE_INFO_get0_NAME_description(info);
|
||||||
BIO_printf(bio_out, "%d: %s: %s\n", items, infostr, name);
|
indent_printf(indent, bio_out, "%d: %s: %s\n", items, infostr,
|
||||||
|
name);
|
||||||
if (desc != NULL)
|
if (desc != NULL)
|
||||||
BIO_printf(bio_out, "%s\n", desc);
|
indent_printf(indent, bio_out, "%s\n", desc);
|
||||||
} else {
|
} else {
|
||||||
BIO_printf(bio_out, "%d: %s\n", items, infostr);
|
indent_printf(indent, bio_out, "%d: %s\n", items, infostr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -146,6 +185,11 @@ int storeutl_main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case OSSL_STORE_INFO_NAME:
|
case OSSL_STORE_INFO_NAME:
|
||||||
|
if (recursive) {
|
||||||
|
const char *suburi = OSSL_STORE_INFO_get0_NAME(info);
|
||||||
|
ret += process(suburi, uimeth, uidata, text, noout, recursive,
|
||||||
|
indent + 2, out);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OSSL_STORE_INFO_PARAMS:
|
case OSSL_STORE_INFO_PARAMS:
|
||||||
if (text)
|
if (text)
|
||||||
|
@ -183,17 +227,12 @@ int storeutl_main(int argc, char *argv[])
|
||||||
items++;
|
items++;
|
||||||
OSSL_STORE_INFO_free(info);
|
OSSL_STORE_INFO_free(info);
|
||||||
}
|
}
|
||||||
BIO_printf(out, "Total found: %d\n", items);
|
indent_printf(indent, out, "Total found: %d\n", items);
|
||||||
|
|
||||||
if (!OSSL_STORE_close(store_ctx)) {
|
if (!OSSL_STORE_close(store_ctx)) {
|
||||||
ERR_print_errors(bio_err);
|
ERR_print_errors(bio_err);
|
||||||
ret++;
|
ret++;
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
|
||||||
BIO_free_all(out);
|
|
||||||
OPENSSL_free(passin);
|
|
||||||
release_engine(e);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue