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