summaryrefslogtreecommitdiffstats
path: root/apps/cmp.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-12-03 17:58:26 +0100
committerHugo Landau <hlandau@openssl.org>2022-07-01 07:41:13 +0100
commitd9650648821aadabf2d9f3de321f344230b13a4a (patch)
treecf0ad932663afaabced639906db1c83a66d67cda /apps/cmp.c
parentbbaabd16e9fd090ecdc9688f3364c3dbc56512d4 (diff)
apps/cmp.c: improve print_itavs()
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18657)
Diffstat (limited to 'apps/cmp.c')
-rw-r--r--apps/cmp.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/apps/cmp.c b/apps/cmp.c
index a433f2b324..25c32f69cd 100644
--- a/apps/cmp.c
+++ b/apps/cmp.c
@@ -2047,28 +2047,35 @@ static int save_free_certs(OSSL_CMP_CTX *ctx,
return n;
}
-static void print_itavs(STACK_OF(OSSL_CMP_ITAV) *itavs)
+static int print_itavs(const STACK_OF(OSSL_CMP_ITAV) *itavs)
{
- OSSL_CMP_ITAV *itav = NULL;
- char buf[128];
- int i, r;
- int n = sk_OSSL_CMP_ITAV_num(itavs); /* itavs == NULL leads to 0 */
+ int i, ret = 1;
+ int n = sk_OSSL_CMP_ITAV_num(itavs);
- if (n == 0) {
- CMP_info("genp contains no ITAV");
- return;
+ if (n <= 0) { /* also in case itavs == NULL */
+ CMP_info("genp does not contain any ITAV");
+ return ret;
}
- for (i = 0; i < n; i++) {
- itav = sk_OSSL_CMP_ITAV_value(itavs, i);
- r = OBJ_obj2txt(buf, 128, OSSL_CMP_ITAV_get0_type(itav), 0);
- if (r < 0)
- CMP_err("could not get ITAV details");
- else if (r == 0)
- CMP_info("genp contains empty ITAV");
- else
- CMP_info1("genp contains ITAV of type: %s", buf);
+ for (i = 1; i <= n; i++) {
+ OSSL_CMP_ITAV *itav = sk_OSSL_CMP_ITAV_value(itavs, i - 1);
+ ASN1_OBJECT *type = OSSL_CMP_ITAV_get0_type(itav);
+ char name[80];
+
+ if (itav == NULL) {
+ CMP_err1("could not get ITAV #%d from genp", i);
+ ret = 0;
+ continue;
+ }
+ if (i2t_ASN1_OBJECT(name, sizeof(name), type) <= 0) {
+ CMP_err1("error parsing type of ITAV #%d from genp", i);
+ ret = 0;
+ }
+ else {
+ CMP_info2("ITAV #%d from genp type=%s", i, name);
+ }
}
+ return ret;
}
static char opt_item[SECTION_NAME_MAX + 1];
@@ -2942,9 +2949,10 @@ int cmp_main(int argc, char **argv)
}
if ((itavs = OSSL_CMP_exec_GENM_ses(cmp_ctx)) != NULL) {
- print_itavs(itavs);
+ ret = print_itavs(itavs);
sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free);
- ret = 1;
+ } else {
+ CMP_err("could not obtain ITAVs from genp");
}
break;
}