Home | History | Annotate | Line # | Download | only in apps
      1      1.1  christos /*
      2      1.1  christos  * Copyright 2000-2025 The OpenSSL Project Authors. All Rights Reserved.
      3      1.1  christos  *
      4      1.1  christos  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5      1.1  christos  * this file except in compliance with the License.  You can obtain a copy
      6      1.1  christos  * in the file LICENSE in the source distribution or at
      7      1.1  christos  * https://www.openssl.org/source/license.html
      8      1.1  christos  */
      9      1.1  christos 
     10      1.1  christos /* We need to use some engine deprecated APIs */
     11      1.1  christos #define OPENSSL_SUPPRESS_DEPRECATED
     12      1.1  christos 
     13      1.1  christos #include <openssl/opensslconf.h>
     14      1.1  christos 
     15      1.1  christos #include "apps.h"
     16      1.1  christos #include "progs.h"
     17      1.1  christos #include <stdio.h>
     18      1.1  christos #include <stdlib.h>
     19      1.1  christos #include <string.h>
     20      1.1  christos #include <openssl/err.h>
     21      1.1  christos #include <openssl/engine.h>
     22      1.1  christos #include <openssl/ssl.h>
     23      1.1  christos #include <openssl/store.h>
     24      1.1  christos 
     25      1.1  christos typedef enum OPTION_choice {
     26      1.1  christos     OPT_COMMON,
     27  1.1.1.2  christos     OPT_C,
     28  1.1.1.2  christos     OPT_T,
     29  1.1.1.2  christos     OPT_TT,
     30  1.1.1.2  christos     OPT_PRE,
     31  1.1.1.2  christos     OPT_POST,
     32  1.1.1.2  christos     OPT_V = 100,
     33  1.1.1.2  christos     OPT_VV,
     34  1.1.1.2  christos     OPT_VVV,
     35  1.1.1.2  christos     OPT_VVVV
     36      1.1  christos } OPTION_CHOICE;
     37      1.1  christos 
     38      1.1  christos const OPTIONS engine_options[] = {
     39  1.1.1.2  christos     { OPT_HELP_STR, 1, '-', "Usage: %s [options] engine...\n" },
     40      1.1  christos 
     41      1.1  christos     OPT_SECTION("General"),
     42  1.1.1.2  christos     { "help", OPT_HELP, '-', "Display this summary" },
     43  1.1.1.2  christos     { "t", OPT_T, '-', "Check that specified engine is available" },
     44  1.1.1.2  christos     { "pre", OPT_PRE, 's', "Run command against the ENGINE before loading it" },
     45  1.1.1.2  christos     { "post", OPT_POST, 's', "Run command against the ENGINE after loading it" },
     46      1.1  christos 
     47      1.1  christos     OPT_SECTION("Output"),
     48  1.1.1.2  christos     { "v", OPT_V, '-', "List 'control commands' For each specified engine" },
     49  1.1.1.2  christos     { "vv", OPT_VV, '-', "Also display each command's description" },
     50  1.1.1.2  christos     { "vvv", OPT_VVV, '-', "Also add the input flags for each command" },
     51  1.1.1.2  christos     { "vvvv", OPT_VVVV, '-', "Also show internal input flags" },
     52  1.1.1.2  christos     { "c", OPT_C, '-', "List the capabilities of specified engine" },
     53  1.1.1.2  christos     { "tt", OPT_TT, '-', "Display error trace for unavailable engines" },
     54  1.1.1.2  christos     { OPT_MORE_STR, OPT_EOF, 1,
     55  1.1.1.2  christos         "Commands are like \"SO_PATH:/lib/libdriver.so\"" },
     56      1.1  christos 
     57      1.1  christos     OPT_PARAMETERS(),
     58  1.1.1.2  christos     { "engine", 0, 0, "ID of engine(s) to load" },
     59  1.1.1.2  christos     { NULL }
     60      1.1  christos };
     61      1.1  christos 
     62      1.1  christos static int append_buf(char **buf, int *size, const char *s)
     63      1.1  christos {
     64      1.1  christos     const int expand = 256;
     65      1.1  christos     int len = strlen(s) + 1;
     66      1.1  christos     char *p = *buf;
     67      1.1  christos 
     68      1.1  christos     if (p == NULL) {
     69      1.1  christos         *size = ((len + expand - 1) / expand) * expand;
     70      1.1  christos         p = *buf = app_malloc(*size, "engine buffer");
     71      1.1  christos     } else {
     72      1.1  christos         const int blen = strlen(p);
     73      1.1  christos 
     74      1.1  christos         if (blen > 0)
     75      1.1  christos             len += 2 + blen;
     76      1.1  christos 
     77      1.1  christos         if (len > *size) {
     78      1.1  christos             *size = ((len + expand - 1) / expand) * expand;
     79      1.1  christos             p = OPENSSL_realloc(p, *size);
     80      1.1  christos             if (p == NULL) {
     81      1.1  christos                 OPENSSL_free(*buf);
     82      1.1  christos                 *buf = NULL;
     83      1.1  christos                 return 0;
     84      1.1  christos             }
     85      1.1  christos             *buf = p;
     86      1.1  christos         }
     87      1.1  christos 
     88      1.1  christos         if (blen > 0) {
     89      1.1  christos             p += blen;
     90      1.1  christos             *p++ = ',';
     91      1.1  christos             *p++ = ' ';
     92      1.1  christos         }
     93      1.1  christos     }
     94      1.1  christos 
     95      1.1  christos     strcpy(p, s);
     96      1.1  christos     return 1;
     97      1.1  christos }
     98      1.1  christos 
     99      1.1  christos static int util_flags(BIO *out, unsigned int flags, const char *indent)
    100      1.1  christos {
    101      1.1  christos     int started = 0, err = 0;
    102      1.1  christos     /* Indent before displaying input flags */
    103      1.1  christos     BIO_printf(out, "%s%s(input flags): ", indent, indent);
    104      1.1  christos     if (flags == 0) {
    105      1.1  christos         BIO_printf(out, "<no flags>\n");
    106      1.1  christos         return 1;
    107      1.1  christos     }
    108      1.1  christos     /*
    109      1.1  christos      * If the object is internal, mark it in a way that shows instead of
    110      1.1  christos      * having it part of all the other flags, even if it really is.
    111      1.1  christos      */
    112      1.1  christos     if (flags & ENGINE_CMD_FLAG_INTERNAL) {
    113      1.1  christos         BIO_printf(out, "[Internal] ");
    114      1.1  christos     }
    115      1.1  christos 
    116      1.1  christos     if (flags & ENGINE_CMD_FLAG_NUMERIC) {
    117      1.1  christos         BIO_printf(out, "NUMERIC");
    118      1.1  christos         started = 1;
    119      1.1  christos     }
    120      1.1  christos     /*
    121      1.1  christos      * Now we check that no combinations of the mutually exclusive NUMERIC,
    122      1.1  christos      * STRING, and NO_INPUT flags have been used. Future flags that can be
    123      1.1  christos      * OR'd together with these would need to added after these to preserve
    124      1.1  christos      * the testing logic.
    125      1.1  christos      */
    126      1.1  christos     if (flags & ENGINE_CMD_FLAG_STRING) {
    127      1.1  christos         if (started) {
    128      1.1  christos             BIO_printf(out, "|");
    129      1.1  christos             err = 1;
    130      1.1  christos         }
    131      1.1  christos         BIO_printf(out, "STRING");
    132      1.1  christos         started = 1;
    133      1.1  christos     }
    134      1.1  christos     if (flags & ENGINE_CMD_FLAG_NO_INPUT) {
    135      1.1  christos         if (started) {
    136      1.1  christos             BIO_printf(out, "|");
    137      1.1  christos             err = 1;
    138      1.1  christos         }
    139      1.1  christos         BIO_printf(out, "NO_INPUT");
    140      1.1  christos         started = 1;
    141      1.1  christos     }
    142      1.1  christos     /* Check for unknown flags */
    143  1.1.1.2  christos     flags = flags & ~ENGINE_CMD_FLAG_NUMERIC & ~ENGINE_CMD_FLAG_STRING & ~ENGINE_CMD_FLAG_NO_INPUT & ~ENGINE_CMD_FLAG_INTERNAL;
    144      1.1  christos     if (flags) {
    145      1.1  christos         if (started)
    146      1.1  christos             BIO_printf(out, "|");
    147      1.1  christos         BIO_printf(out, "<0x%04X>", flags);
    148      1.1  christos     }
    149      1.1  christos     if (err)
    150      1.1  christos         BIO_printf(out, "  <illegal flags!>");
    151      1.1  christos     BIO_printf(out, "\n");
    152      1.1  christos     return 1;
    153      1.1  christos }
    154      1.1  christos 
    155      1.1  christos static int util_verbose(ENGINE *e, int verbose, BIO *out, const char *indent)
    156      1.1  christos {
    157      1.1  christos     static const int line_wrap = 78;
    158      1.1  christos     int num;
    159      1.1  christos     int ret = 0;
    160      1.1  christos     char *name = NULL;
    161      1.1  christos     char *desc = NULL;
    162      1.1  christos     int flags;
    163      1.1  christos     int xpos = 0;
    164      1.1  christos     STACK_OF(OPENSSL_STRING) *cmds = NULL;
    165  1.1.1.2  christos     if (!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) || ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE, 0, NULL, NULL)) <= 0)) {
    166      1.1  christos         return 1;
    167      1.1  christos     }
    168      1.1  christos 
    169      1.1  christos     cmds = sk_OPENSSL_STRING_new_null();
    170      1.1  christos     if (cmds == NULL)
    171      1.1  christos         goto err;
    172      1.1  christos 
    173      1.1  christos     do {
    174      1.1  christos         int len;
    175      1.1  christos         /* Get the command input flags */
    176      1.1  christos         if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
    177  1.1.1.2  christos                  NULL, NULL))
    178  1.1.1.2  christos             < 0)
    179      1.1  christos             goto err;
    180      1.1  christos         if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4) {
    181      1.1  christos             /* Get the command name */
    182      1.1  christos             if ((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, num,
    183  1.1.1.2  christos                      NULL, NULL))
    184  1.1.1.2  christos                 <= 0)
    185      1.1  christos                 goto err;
    186      1.1  christos             name = app_malloc(len + 1, "name buffer");
    187      1.1  christos             if (ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_FROM_CMD, num, name,
    188  1.1.1.2  christos                     NULL)
    189  1.1.1.2  christos                 <= 0)
    190      1.1  christos                 goto err;
    191      1.1  christos             /* Get the command description */
    192      1.1  christos             if ((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, num,
    193  1.1.1.2  christos                      NULL, NULL))
    194  1.1.1.2  christos                 < 0)
    195      1.1  christos                 goto err;
    196      1.1  christos             if (len > 0) {
    197      1.1  christos                 desc = app_malloc(len + 1, "description buffer");
    198      1.1  christos                 if (ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_FROM_CMD, num, desc,
    199  1.1.1.2  christos                         NULL)
    200  1.1.1.2  christos                     <= 0)
    201      1.1  christos                     goto err;
    202      1.1  christos             }
    203      1.1  christos             /* Now decide on the output */
    204      1.1  christos             if (xpos == 0)
    205      1.1  christos                 /* Do an indent */
    206      1.1  christos                 xpos = BIO_puts(out, indent);
    207      1.1  christos             else
    208      1.1  christos                 /* Otherwise prepend a ", " */
    209      1.1  christos                 xpos += BIO_printf(out, ", ");
    210      1.1  christos             if (verbose == 1) {
    211      1.1  christos                 /*
    212      1.1  christos                  * We're just listing names, comma-delimited
    213      1.1  christos                  */
    214  1.1.1.2  christos                 if ((xpos > (int)strlen(indent)) && (xpos + (int)strlen(name) > line_wrap)) {
    215      1.1  christos                     BIO_printf(out, "\n");
    216      1.1  christos                     xpos = BIO_puts(out, indent);
    217      1.1  christos                 }
    218      1.1  christos                 xpos += BIO_printf(out, "%s", name);
    219      1.1  christos             } else {
    220      1.1  christos                 /* We're listing names plus descriptions */
    221      1.1  christos                 BIO_printf(out, "%s: %s\n", name,
    222  1.1.1.2  christos                     (desc == NULL) ? "<no description>" : desc);
    223      1.1  christos                 /* ... and sometimes input flags */
    224      1.1  christos                 if ((verbose >= 3) && !util_flags(out, flags, indent))
    225      1.1  christos                     goto err;
    226      1.1  christos                 xpos = 0;
    227      1.1  christos             }
    228      1.1  christos         }
    229      1.1  christos         OPENSSL_free(name);
    230      1.1  christos         name = NULL;
    231      1.1  christos         OPENSSL_free(desc);
    232      1.1  christos         desc = NULL;
    233      1.1  christos         /* Move to the next command */
    234      1.1  christos         num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE, num, NULL, NULL);
    235      1.1  christos     } while (num > 0);
    236      1.1  christos     if (xpos > 0)
    237      1.1  christos         BIO_printf(out, "\n");
    238      1.1  christos     ret = 1;
    239  1.1.1.2  christos err:
    240      1.1  christos     sk_OPENSSL_STRING_free(cmds);
    241      1.1  christos     OPENSSL_free(name);
    242      1.1  christos     OPENSSL_free(desc);
    243      1.1  christos     return ret;
    244      1.1  christos }
    245      1.1  christos 
    246      1.1  christos static void util_do_cmds(ENGINE *e, STACK_OF(OPENSSL_STRING) *cmds,
    247  1.1.1.2  christos     BIO *out, const char *indent)
    248      1.1  christos {
    249      1.1  christos     int loop, res, num = sk_OPENSSL_STRING_num(cmds);
    250      1.1  christos 
    251      1.1  christos     if (num < 0) {
    252      1.1  christos         BIO_printf(out, "[Error]: internal stack error\n");
    253      1.1  christos         return;
    254      1.1  christos     }
    255      1.1  christos     for (loop = 0; loop < num; loop++) {
    256      1.1  christos         char buf[256];
    257      1.1  christos         const char *cmd, *arg;
    258      1.1  christos         cmd = sk_OPENSSL_STRING_value(cmds, loop);
    259  1.1.1.2  christos         res = 1; /* assume success */
    260      1.1  christos         /* Check if this command has no ":arg" */
    261      1.1  christos         if ((arg = strchr(cmd, ':')) == NULL) {
    262      1.1  christos             if (!ENGINE_ctrl_cmd_string(e, cmd, NULL, 0))
    263      1.1  christos                 res = 0;
    264      1.1  christos         } else {
    265      1.1  christos             if ((int)(arg - cmd) > 254) {
    266      1.1  christos                 BIO_printf(out, "[Error]: command name too long\n");
    267      1.1  christos                 return;
    268      1.1  christos             }
    269      1.1  christos             memcpy(buf, cmd, (int)(arg - cmd));
    270      1.1  christos             buf[arg - cmd] = '\0';
    271  1.1.1.2  christos             arg++; /* Move past the ":" */
    272      1.1  christos             /* Call the command with the argument */
    273      1.1  christos             if (!ENGINE_ctrl_cmd_string(e, buf, arg, 0))
    274      1.1  christos                 res = 0;
    275      1.1  christos         }
    276      1.1  christos         if (res) {
    277      1.1  christos             BIO_printf(out, "[Success]: %s\n", cmd);
    278      1.1  christos         } else {
    279      1.1  christos             BIO_printf(out, "[Failure]: %s\n", cmd);
    280      1.1  christos             ERR_print_errors(out);
    281      1.1  christos         }
    282      1.1  christos     }
    283      1.1  christos }
    284      1.1  christos 
    285      1.1  christos struct util_store_cap_data {
    286      1.1  christos     ENGINE *engine;
    287      1.1  christos     char **cap_buf;
    288      1.1  christos     int *cap_size;
    289      1.1  christos     int ok;
    290      1.1  christos };
    291      1.1  christos static void util_store_cap(const OSSL_STORE_LOADER *loader, void *arg)
    292      1.1  christos {
    293      1.1  christos     struct util_store_cap_data *ctx = arg;
    294      1.1  christos 
    295      1.1  christos     if (OSSL_STORE_LOADER_get0_engine(loader) == ctx->engine) {
    296      1.1  christos         char buf[256];
    297      1.1  christos         BIO_snprintf(buf, sizeof(buf), "STORE(%s)",
    298  1.1.1.2  christos             OSSL_STORE_LOADER_get0_scheme(loader));
    299      1.1  christos         if (!append_buf(ctx->cap_buf, ctx->cap_size, buf))
    300      1.1  christos             ctx->ok = 0;
    301      1.1  christos     }
    302      1.1  christos }
    303      1.1  christos 
    304      1.1  christos int engine_main(int argc, char **argv)
    305      1.1  christos {
    306      1.1  christos     int ret = 1, i;
    307      1.1  christos     int verbose = 0, list_cap = 0, test_avail = 0, test_avail_noise = 0;
    308      1.1  christos     ENGINE *e;
    309      1.1  christos     STACK_OF(OPENSSL_CSTRING) *engines = sk_OPENSSL_CSTRING_new_null();
    310      1.1  christos     STACK_OF(OPENSSL_STRING) *pre_cmds = sk_OPENSSL_STRING_new_null();
    311      1.1  christos     STACK_OF(OPENSSL_STRING) *post_cmds = sk_OPENSSL_STRING_new_null();
    312      1.1  christos     BIO *out;
    313      1.1  christos     const char *indent = "     ";
    314      1.1  christos     OPTION_CHOICE o;
    315      1.1  christos     char *prog;
    316      1.1  christos     char *argv1;
    317      1.1  christos 
    318      1.1  christos     out = dup_bio_out(FORMAT_TEXT);
    319      1.1  christos     if (engines == NULL || pre_cmds == NULL || post_cmds == NULL)
    320      1.1  christos         goto end;
    321      1.1  christos 
    322      1.1  christos     /* Remember the original command name, parse/skip any leading engine
    323      1.1  christos      * names, and then setup to parse the rest of the line as flags. */
    324      1.1  christos     prog = argv[0];
    325      1.1  christos     while ((argv1 = argv[1]) != NULL && *argv1 != '-') {
    326      1.1  christos         if (!sk_OPENSSL_CSTRING_push(engines, argv1))
    327      1.1  christos             goto end;
    328      1.1  christos         argc--;
    329      1.1  christos         argv++;
    330      1.1  christos     }
    331      1.1  christos     argv[0] = prog;
    332      1.1  christos     opt_init(argc, argv, engine_options);
    333      1.1  christos 
    334      1.1  christos     while ((o = opt_next()) != OPT_EOF) {
    335      1.1  christos         switch (o) {
    336      1.1  christos         case OPT_EOF:
    337      1.1  christos         case OPT_ERR:
    338      1.1  christos             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
    339      1.1  christos             goto end;
    340      1.1  christos         case OPT_HELP:
    341      1.1  christos             opt_help(engine_options);
    342      1.1  christos             ret = 0;
    343      1.1  christos             goto end;
    344      1.1  christos         case OPT_VVVV:
    345      1.1  christos         case OPT_VVV:
    346      1.1  christos         case OPT_VV:
    347      1.1  christos         case OPT_V:
    348      1.1  christos             /* Convert to an integer from one to four. */
    349      1.1  christos             i = (int)(o - OPT_V) + 1;
    350      1.1  christos             if (verbose < i)
    351      1.1  christos                 verbose = i;
    352      1.1  christos             break;
    353      1.1  christos         case OPT_C:
    354      1.1  christos             list_cap = 1;
    355      1.1  christos             break;
    356      1.1  christos         case OPT_TT:
    357      1.1  christos             test_avail_noise++;
    358      1.1  christos             /* fall through */
    359      1.1  christos         case OPT_T:
    360      1.1  christos             test_avail++;
    361      1.1  christos             break;
    362      1.1  christos         case OPT_PRE:
    363      1.1  christos             if (sk_OPENSSL_STRING_push(pre_cmds, opt_arg()) <= 0)
    364      1.1  christos                 goto end;
    365      1.1  christos             break;
    366      1.1  christos         case OPT_POST:
    367      1.1  christos             if (sk_OPENSSL_STRING_push(post_cmds, opt_arg()) <= 0)
    368      1.1  christos                 goto end;
    369      1.1  christos             break;
    370      1.1  christos         }
    371      1.1  christos     }
    372      1.1  christos 
    373      1.1  christos     /* Any remaining arguments are engine names. */
    374      1.1  christos     argc = opt_num_rest();
    375      1.1  christos     argv = opt_rest();
    376  1.1.1.2  christos     for (; *argv; argv++) {
    377      1.1  christos         if (**argv == '-') {
    378      1.1  christos             BIO_printf(bio_err, "%s: Cannot mix flags and engine names.\n",
    379  1.1.1.2  christos                 prog);
    380      1.1  christos             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
    381      1.1  christos             goto end;
    382      1.1  christos         }
    383      1.1  christos         if (!sk_OPENSSL_CSTRING_push(engines, *argv))
    384      1.1  christos             goto end;
    385      1.1  christos     }
    386      1.1  christos 
    387      1.1  christos     if (sk_OPENSSL_CSTRING_num(engines) == 0) {
    388      1.1  christos         for (e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e)) {
    389      1.1  christos             if (!sk_OPENSSL_CSTRING_push(engines, ENGINE_get_id(e)))
    390      1.1  christos                 goto end;
    391      1.1  christos         }
    392      1.1  christos     }
    393      1.1  christos 
    394      1.1  christos     ret = 0;
    395      1.1  christos     for (i = 0; i < sk_OPENSSL_CSTRING_num(engines); i++) {
    396      1.1  christos         const char *id = sk_OPENSSL_CSTRING_value(engines, i);
    397      1.1  christos         if ((e = ENGINE_by_id(id)) != NULL) {
    398      1.1  christos             const char *name = ENGINE_get_name(e);
    399      1.1  christos             /*
    400      1.1  christos              * Do "id" first, then "name". Easier to auto-parse.
    401      1.1  christos              */
    402      1.1  christos             BIO_printf(out, "(%s) %s\n", id, name);
    403      1.1  christos             util_do_cmds(e, pre_cmds, out, indent);
    404      1.1  christos             if (strcmp(ENGINE_get_id(e), id) != 0) {
    405      1.1  christos                 BIO_printf(out, "Loaded: (%s) %s\n",
    406  1.1.1.2  christos                     ENGINE_get_id(e), ENGINE_get_name(e));
    407      1.1  christos             }
    408      1.1  christos             if (list_cap) {
    409      1.1  christos                 int cap_size = 256;
    410      1.1  christos                 char *cap_buf = NULL;
    411      1.1  christos                 int k, n;
    412      1.1  christos                 const int *nids;
    413      1.1  christos                 ENGINE_CIPHERS_PTR fn_c;
    414      1.1  christos                 ENGINE_DIGESTS_PTR fn_d;
    415      1.1  christos                 ENGINE_PKEY_METHS_PTR fn_pk;
    416      1.1  christos 
    417      1.1  christos                 if (ENGINE_get_RSA(e) != NULL
    418      1.1  christos                     && !append_buf(&cap_buf, &cap_size, "RSA"))
    419      1.1  christos                     goto end;
    420      1.1  christos                 if (ENGINE_get_EC(e) != NULL
    421      1.1  christos                     && !append_buf(&cap_buf, &cap_size, "EC"))
    422      1.1  christos                     goto end;
    423      1.1  christos                 if (ENGINE_get_DSA(e) != NULL
    424      1.1  christos                     && !append_buf(&cap_buf, &cap_size, "DSA"))
    425      1.1  christos                     goto end;
    426      1.1  christos                 if (ENGINE_get_DH(e) != NULL
    427      1.1  christos                     && !append_buf(&cap_buf, &cap_size, "DH"))
    428      1.1  christos                     goto end;
    429      1.1  christos                 if (ENGINE_get_RAND(e) != NULL
    430      1.1  christos                     && !append_buf(&cap_buf, &cap_size, "RAND"))
    431      1.1  christos                     goto end;
    432      1.1  christos 
    433      1.1  christos                 fn_c = ENGINE_get_ciphers(e);
    434      1.1  christos                 if (fn_c == NULL)
    435      1.1  christos                     goto skip_ciphers;
    436      1.1  christos                 n = fn_c(e, NULL, &nids, 0);
    437      1.1  christos                 for (k = 0; k < n; ++k)
    438      1.1  christos                     if (!append_buf(&cap_buf, &cap_size, OBJ_nid2sn(nids[k])))
    439      1.1  christos                         goto end;
    440      1.1  christos 
    441  1.1.1.2  christos             skip_ciphers:
    442      1.1  christos                 fn_d = ENGINE_get_digests(e);
    443      1.1  christos                 if (fn_d == NULL)
    444      1.1  christos                     goto skip_digests;
    445      1.1  christos                 n = fn_d(e, NULL, &nids, 0);
    446      1.1  christos                 for (k = 0; k < n; ++k)
    447      1.1  christos                     if (!append_buf(&cap_buf, &cap_size, OBJ_nid2sn(nids[k])))
    448      1.1  christos                         goto end;
    449      1.1  christos 
    450  1.1.1.2  christos             skip_digests:
    451      1.1  christos                 fn_pk = ENGINE_get_pkey_meths(e);
    452      1.1  christos                 if (fn_pk == NULL)
    453      1.1  christos                     goto skip_pmeths;
    454      1.1  christos                 n = fn_pk(e, NULL, &nids, 0);
    455      1.1  christos                 for (k = 0; k < n; ++k)
    456      1.1  christos                     if (!append_buf(&cap_buf, &cap_size, OBJ_nid2sn(nids[k])))
    457      1.1  christos                         goto end;
    458  1.1.1.2  christos             skip_pmeths: {
    459  1.1.1.2  christos                 struct util_store_cap_data store_ctx;
    460      1.1  christos 
    461  1.1.1.2  christos                 store_ctx.engine = e;
    462  1.1.1.2  christos                 store_ctx.cap_buf = &cap_buf;
    463  1.1.1.2  christos                 store_ctx.cap_size = &cap_size;
    464  1.1.1.2  christos                 store_ctx.ok = 1;
    465  1.1.1.2  christos 
    466  1.1.1.2  christos                 OSSL_STORE_do_all_loaders(util_store_cap, &store_ctx);
    467  1.1.1.2  christos                 if (!store_ctx.ok)
    468  1.1.1.2  christos                     goto end;
    469  1.1.1.2  christos             }
    470      1.1  christos                 if (cap_buf != NULL && (*cap_buf != '\0'))
    471      1.1  christos                     BIO_printf(out, " [%s]\n", cap_buf);
    472      1.1  christos 
    473      1.1  christos                 OPENSSL_free(cap_buf);
    474      1.1  christos             }
    475      1.1  christos             if (test_avail) {
    476      1.1  christos                 BIO_printf(out, "%s", indent);
    477      1.1  christos                 if (ENGINE_init(e)) {
    478      1.1  christos                     BIO_printf(out, "[ available ]\n");
    479      1.1  christos                     util_do_cmds(e, post_cmds, out, indent);
    480      1.1  christos                     ENGINE_finish(e);
    481      1.1  christos                 } else {
    482      1.1  christos                     BIO_printf(out, "[ unavailable ]\n");
    483      1.1  christos                     if (test_avail_noise)
    484      1.1  christos                         ERR_print_errors_fp(stdout);
    485      1.1  christos                     ERR_clear_error();
    486      1.1  christos                 }
    487      1.1  christos             }
    488      1.1  christos             if ((verbose > 0) && !util_verbose(e, verbose, out, indent))
    489      1.1  christos                 goto end;
    490      1.1  christos             ENGINE_free(e);
    491      1.1  christos         } else {
    492      1.1  christos             ERR_print_errors(bio_err);
    493      1.1  christos             /* because exit codes above 127 have special meaning on Unix */
    494      1.1  christos             if (++ret > 127)
    495      1.1  christos                 ret = 127;
    496      1.1  christos         }
    497      1.1  christos     }
    498      1.1  christos 
    499  1.1.1.2  christos end:
    500      1.1  christos 
    501      1.1  christos     ERR_print_errors(bio_err);
    502      1.1  christos     sk_OPENSSL_CSTRING_free(engines);
    503      1.1  christos     sk_OPENSSL_STRING_free(pre_cmds);
    504      1.1  christos     sk_OPENSSL_STRING_free(post_cmds);
    505      1.1  christos     BIO_free_all(out);
    506      1.1  christos     return ret;
    507      1.1  christos }
    508