1 /* 2 * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 /* We need to use some deprecated APIs */ 11 #define OPENSSL_SUPPRESS_DEPRECATED 12 13 #include "internal/e_os.h" 14 15 #include <string.h> 16 #include <openssl/evp.h> 17 #include <openssl/err.h> 18 #include <openssl/provider.h> 19 #include <openssl/safestack.h> 20 #include <openssl/kdf.h> 21 #include <openssl/encoder.h> 22 #include <openssl/decoder.h> 23 #include <openssl/store.h> 24 #include <openssl/core_names.h> 25 #include <openssl/rand.h> 26 #include <openssl/safestack.h> 27 #include <openssl/ssl.h> 28 #include <openssl/tls1.h> 29 #include "apps.h" 30 #include "app_params.h" 31 #include "progs.h" 32 #include "opt.h" 33 #include "names.h" 34 35 static int verbose = 0; 36 static const char *select_name = NULL; 37 38 /* Checks to see if algorithms are fetchable */ 39 #define IS_FETCHABLE(type, TYPE) \ 40 static int is_ ## type ## _fetchable(const TYPE *alg) \ 41 { \ 42 TYPE *impl; \ 43 const char *propq = app_get0_propq(); \ 44 OSSL_LIB_CTX *libctx = app_get0_libctx(); \ 45 const char *name = TYPE ## _get0_name(alg); \ 46 \ 47 ERR_set_mark(); \ 48 impl = TYPE ## _fetch(libctx, name, propq); \ 49 ERR_pop_to_mark(); \ 50 if (impl == NULL) \ 51 return 0; \ 52 TYPE ## _free(impl); \ 53 return 1; \ 54 } 55 IS_FETCHABLE(cipher, EVP_CIPHER) 56 IS_FETCHABLE(digest, EVP_MD) 57 IS_FETCHABLE(mac, EVP_MAC) 58 IS_FETCHABLE(kdf, EVP_KDF) 59 IS_FETCHABLE(rand, EVP_RAND) 60 IS_FETCHABLE(keymgmt, EVP_KEYMGMT) 61 IS_FETCHABLE(skeymgmt, EVP_SKEYMGMT) 62 IS_FETCHABLE(signature, EVP_SIGNATURE) 63 IS_FETCHABLE(kem, EVP_KEM) 64 IS_FETCHABLE(asym_cipher, EVP_ASYM_CIPHER) 65 IS_FETCHABLE(keyexch, EVP_KEYEXCH) 66 IS_FETCHABLE(decoder, OSSL_DECODER) 67 IS_FETCHABLE(encoder, OSSL_ENCODER) 68 69 #ifndef OPENSSL_NO_DEPRECATED_3_0 70 static int include_legacy(void) 71 { 72 return app_get0_propq() == NULL; 73 } 74 75 static void legacy_cipher_fn(const EVP_CIPHER *c, 76 const char *from, const char *to, void *arg) 77 { 78 if (select_name != NULL 79 && (c == NULL 80 || OPENSSL_strcasecmp(select_name, EVP_CIPHER_get0_name(c)) != 0)) 81 return; 82 if (c != NULL) { 83 BIO_printf(arg, " %s\n", EVP_CIPHER_get0_name(c)); 84 } else { 85 if (from == NULL) 86 from = "<undefined>"; 87 if (to == NULL) 88 to = "<undefined>"; 89 BIO_printf(arg, " %s => %s\n", from, to); 90 } 91 } 92 #endif 93 94 DEFINE_STACK_OF(EVP_CIPHER) 95 static int cipher_cmp(const EVP_CIPHER * const *a, 96 const EVP_CIPHER * const *b) 97 { 98 return strcmp(OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(*a)), 99 OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(*b))); 100 } 101 102 static void collect_ciphers(EVP_CIPHER *cipher, void *stack) 103 { 104 STACK_OF(EVP_CIPHER) *cipher_stack = stack; 105 106 if (is_cipher_fetchable(cipher) 107 && EVP_CIPHER_up_ref(cipher) 108 && sk_EVP_CIPHER_push(cipher_stack, cipher) <= 0) 109 EVP_CIPHER_free(cipher); /* up-ref successful but push to stack failed */ 110 } 111 112 static void list_ciphers(const char *prefix) 113 { 114 STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp); 115 int i; 116 117 if (ciphers == NULL) { 118 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 119 return; 120 } 121 #ifndef OPENSSL_NO_DEPRECATED_3_0 122 if (include_legacy()) { 123 BIO_printf(bio_out, "%sLegacy:\n", prefix); 124 EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out); 125 } 126 #endif 127 128 BIO_printf(bio_out, "%sProvided:\n", prefix); 129 EVP_CIPHER_do_all_provided(app_get0_libctx(), collect_ciphers, ciphers); 130 sk_EVP_CIPHER_sort(ciphers); 131 for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) { 132 const EVP_CIPHER *c = sk_EVP_CIPHER_value(ciphers, i); 133 STACK_OF(OPENSSL_CSTRING) *names = NULL; 134 135 if (select_name != NULL && !EVP_CIPHER_is_a(c, select_name)) 136 continue; 137 138 names = sk_OPENSSL_CSTRING_new(name_cmp); 139 if (names != NULL && EVP_CIPHER_names_do_all(c, collect_names, names)) { 140 BIO_printf(bio_out, " "); 141 print_names(bio_out, names); 142 143 BIO_printf(bio_out, " @ %s\n", 144 OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(c))); 145 146 if (verbose) { 147 const char *desc = EVP_CIPHER_get0_description(c); 148 149 if (desc != NULL) 150 BIO_printf(bio_out, " description: %s\n", desc); 151 print_param_types("retrievable algorithm parameters", 152 EVP_CIPHER_gettable_params(c), 4); 153 print_param_types("retrievable operation parameters", 154 EVP_CIPHER_gettable_ctx_params(c), 4); 155 print_param_types("settable operation parameters", 156 EVP_CIPHER_settable_ctx_params(c), 4); 157 } 158 } 159 sk_OPENSSL_CSTRING_free(names); 160 } 161 sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free); 162 } 163 164 #ifndef OPENSSL_NO_DEPRECATED_3_0 165 static void legacy_md_fn(const EVP_MD *m, 166 const char *from, const char *to, void *arg) 167 { 168 if (m != NULL) { 169 BIO_printf(arg, " %s\n", EVP_MD_get0_name(m)); 170 } else { 171 if (from == NULL) 172 from = "<undefined>"; 173 if (to == NULL) 174 to = "<undefined>"; 175 BIO_printf((BIO *)arg, " %s => %s\n", from, to); 176 } 177 } 178 #endif 179 180 DEFINE_STACK_OF(EVP_MD) 181 static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b) 182 { 183 return strcmp(OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(*a)), 184 OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(*b))); 185 } 186 187 static void collect_digests(EVP_MD *digest, void *stack) 188 { 189 STACK_OF(EVP_MD) *digest_stack = stack; 190 191 if (is_digest_fetchable(digest) 192 && EVP_MD_up_ref(digest) 193 && sk_EVP_MD_push(digest_stack, digest) <= 0) 194 EVP_MD_free(digest); /* up-ref successful but push to stack failed */ 195 } 196 197 static void list_digests(const char *prefix) 198 { 199 STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp); 200 int i; 201 202 if (digests == NULL) { 203 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 204 return; 205 } 206 #ifndef OPENSSL_NO_DEPRECATED_3_0 207 if (include_legacy()) { 208 BIO_printf(bio_out, "%sLegacy:\n", prefix); 209 EVP_MD_do_all_sorted(legacy_md_fn, bio_out); 210 } 211 #endif 212 213 BIO_printf(bio_out, "%sProvided:\n", prefix); 214 EVP_MD_do_all_provided(app_get0_libctx(), collect_digests, digests); 215 sk_EVP_MD_sort(digests); 216 for (i = 0; i < sk_EVP_MD_num(digests); i++) { 217 const EVP_MD *m = sk_EVP_MD_value(digests, i); 218 STACK_OF(OPENSSL_CSTRING) *names = NULL; 219 220 if (select_name != NULL && !EVP_MD_is_a(m, select_name)) 221 continue; 222 223 names = sk_OPENSSL_CSTRING_new(name_cmp); 224 if (names != NULL && EVP_MD_names_do_all(m, collect_names, names)) { 225 BIO_printf(bio_out, " "); 226 print_names(bio_out, names); 227 228 BIO_printf(bio_out, " @ %s\n", 229 OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(m))); 230 231 if (verbose) { 232 const char *desc = EVP_MD_get0_description(m); 233 234 if (desc != NULL) 235 BIO_printf(bio_out, " description: %s\n", desc); 236 print_param_types("retrievable algorithm parameters", 237 EVP_MD_gettable_params(m), 4); 238 print_param_types("retrievable operation parameters", 239 EVP_MD_gettable_ctx_params(m), 4); 240 print_param_types("settable operation parameters", 241 EVP_MD_settable_ctx_params(m), 4); 242 } 243 } 244 sk_OPENSSL_CSTRING_free(names); 245 } 246 sk_EVP_MD_pop_free(digests, EVP_MD_free); 247 } 248 249 DEFINE_STACK_OF(EVP_MAC) 250 static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b) 251 { 252 return strcmp(OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(*a)), 253 OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(*b))); 254 } 255 256 static void collect_macs(EVP_MAC *mac, void *stack) 257 { 258 STACK_OF(EVP_MAC) *mac_stack = stack; 259 260 if (is_mac_fetchable(mac) 261 && sk_EVP_MAC_push(mac_stack, mac) > 0) 262 EVP_MAC_up_ref(mac); 263 } 264 265 static void list_macs(void) 266 { 267 STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp); 268 int i; 269 270 if (macs == NULL) { 271 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 272 return; 273 } 274 BIO_printf(bio_out, "Provided MACs:\n"); 275 EVP_MAC_do_all_provided(app_get0_libctx(), collect_macs, macs); 276 sk_EVP_MAC_sort(macs); 277 for (i = 0; i < sk_EVP_MAC_num(macs); i++) { 278 const EVP_MAC *m = sk_EVP_MAC_value(macs, i); 279 STACK_OF(OPENSSL_CSTRING) *names = NULL; 280 281 if (select_name != NULL && !EVP_MAC_is_a(m, select_name)) 282 continue; 283 284 names = sk_OPENSSL_CSTRING_new(name_cmp); 285 if (names != NULL && EVP_MAC_names_do_all(m, collect_names, names)) { 286 BIO_printf(bio_out, " "); 287 print_names(bio_out, names); 288 289 BIO_printf(bio_out, " @ %s\n", 290 OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(m))); 291 292 if (verbose) { 293 const char *desc = EVP_MAC_get0_description(m); 294 295 if (desc != NULL) 296 BIO_printf(bio_out, " description: %s\n", desc); 297 print_param_types("retrievable algorithm parameters", 298 EVP_MAC_gettable_params(m), 4); 299 print_param_types("retrievable operation parameters", 300 EVP_MAC_gettable_ctx_params(m), 4); 301 print_param_types("settable operation parameters", 302 EVP_MAC_settable_ctx_params(m), 4); 303 } 304 } 305 sk_OPENSSL_CSTRING_free(names); 306 } 307 sk_EVP_MAC_pop_free(macs, EVP_MAC_free); 308 } 309 310 /* 311 * KDFs and PRFs 312 */ 313 DEFINE_STACK_OF(EVP_KDF) 314 static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b) 315 { 316 return strcmp(OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(*a)), 317 OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(*b))); 318 } 319 320 static void collect_kdfs(EVP_KDF *kdf, void *stack) 321 { 322 STACK_OF(EVP_KDF) *kdf_stack = stack; 323 324 if (is_kdf_fetchable(kdf) 325 && EVP_KDF_up_ref(kdf) 326 && sk_EVP_KDF_push(kdf_stack, kdf) <= 0) 327 EVP_KDF_free(kdf); /* up-ref successful but push to stack failed */ 328 } 329 330 static void list_kdfs(void) 331 { 332 STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp); 333 int i; 334 335 if (kdfs == NULL) { 336 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 337 return; 338 } 339 BIO_printf(bio_out, "Provided KDFs and PDFs:\n"); 340 EVP_KDF_do_all_provided(app_get0_libctx(), collect_kdfs, kdfs); 341 sk_EVP_KDF_sort(kdfs); 342 for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) { 343 const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i); 344 STACK_OF(OPENSSL_CSTRING) *names = NULL; 345 346 if (select_name != NULL && !EVP_KDF_is_a(k, select_name)) 347 continue; 348 349 names = sk_OPENSSL_CSTRING_new(name_cmp); 350 if (names != NULL && EVP_KDF_names_do_all(k, collect_names, names)) { 351 BIO_printf(bio_out, " "); 352 print_names(bio_out, names); 353 354 BIO_printf(bio_out, " @ %s\n", 355 OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(k))); 356 357 if (verbose) { 358 const char *desc = EVP_KDF_get0_description(k); 359 360 if (desc != NULL) 361 BIO_printf(bio_out, " description: %s\n", desc); 362 print_param_types("retrievable algorithm parameters", 363 EVP_KDF_gettable_params(k), 4); 364 print_param_types("retrievable operation parameters", 365 EVP_KDF_gettable_ctx_params(k), 4); 366 print_param_types("settable operation parameters", 367 EVP_KDF_settable_ctx_params(k), 4); 368 } 369 } 370 sk_OPENSSL_CSTRING_free(names); 371 } 372 sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free); 373 } 374 375 /* 376 * RANDs 377 */ 378 DEFINE_STACK_OF(EVP_RAND) 379 380 static int rand_cmp(const EVP_RAND * const *a, const EVP_RAND * const *b) 381 { 382 int ret = OPENSSL_strcasecmp(EVP_RAND_get0_name(*a), EVP_RAND_get0_name(*b)); 383 384 if (ret == 0) 385 ret = strcmp(OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(*a)), 386 OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(*b))); 387 388 return ret; 389 } 390 391 static void collect_rands(EVP_RAND *rand, void *stack) 392 { 393 STACK_OF(EVP_RAND) *rand_stack = stack; 394 395 if (is_rand_fetchable(rand) 396 && EVP_RAND_up_ref(rand) 397 && sk_EVP_RAND_push(rand_stack, rand) <= 0) 398 EVP_RAND_free(rand); /* up-ref successful but push to stack failed */ 399 } 400 401 static void list_random_generators(void) 402 { 403 STACK_OF(EVP_RAND) *rands = sk_EVP_RAND_new(rand_cmp); 404 int i; 405 406 if (rands == NULL) { 407 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 408 return; 409 } 410 BIO_printf(bio_out, "Provided RNGs and seed sources:\n"); 411 EVP_RAND_do_all_provided(app_get0_libctx(), collect_rands, rands); 412 sk_EVP_RAND_sort(rands); 413 for (i = 0; i < sk_EVP_RAND_num(rands); i++) { 414 const EVP_RAND *m = sk_EVP_RAND_value(rands, i); 415 416 if (select_name != NULL 417 && OPENSSL_strcasecmp(EVP_RAND_get0_name(m), select_name) != 0) 418 continue; 419 BIO_printf(bio_out, " %s", EVP_RAND_get0_name(m)); 420 BIO_printf(bio_out, " @ %s\n", 421 OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(m))); 422 423 if (verbose) { 424 const char *desc = EVP_RAND_get0_description(m); 425 426 if (desc != NULL) 427 BIO_printf(bio_out, " description: %s\n", desc); 428 print_param_types("retrievable algorithm parameters", 429 EVP_RAND_gettable_params(m), 4); 430 print_param_types("retrievable operation parameters", 431 EVP_RAND_gettable_ctx_params(m), 4); 432 print_param_types("settable operation parameters", 433 EVP_RAND_settable_ctx_params(m), 4); 434 } 435 } 436 sk_EVP_RAND_pop_free(rands, EVP_RAND_free); 437 } 438 439 static void display_random(const char *name, EVP_RAND_CTX *drbg) 440 { 441 EVP_RAND *rand; 442 uint64_t u; 443 const char *p; 444 const OSSL_PARAM *gettables; 445 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END }; 446 unsigned char buf[1000]; 447 448 BIO_printf(bio_out, "%s:\n", name); 449 if (drbg != NULL) { 450 rand = EVP_RAND_CTX_get0_rand(drbg); 451 452 BIO_printf(bio_out, " %s", EVP_RAND_get0_name(rand)); 453 BIO_printf(bio_out, " @ %s\n", 454 OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(rand))); 455 456 switch (EVP_RAND_get_state(drbg)) { 457 case EVP_RAND_STATE_UNINITIALISED: 458 p = "uninitialised"; 459 break; 460 case EVP_RAND_STATE_READY: 461 p = "ready"; 462 break; 463 case EVP_RAND_STATE_ERROR: 464 p = "error"; 465 break; 466 default: 467 p = "unknown"; 468 break; 469 } 470 BIO_printf(bio_out, " state = %s\n", p); 471 472 gettables = EVP_RAND_gettable_ctx_params(rand); 473 if (gettables != NULL) 474 for (; gettables->key != NULL; gettables++) { 475 /* State has been dealt with already, so ignore */ 476 if (OPENSSL_strcasecmp(gettables->key, OSSL_RAND_PARAM_STATE) == 0) 477 continue; 478 /* Outside of verbose mode, we skip non-string values */ 479 if (gettables->data_type != OSSL_PARAM_UTF8_STRING 480 && gettables->data_type != OSSL_PARAM_UTF8_PTR 481 && !verbose) 482 continue; 483 params->key = gettables->key; 484 params->data_type = gettables->data_type; 485 if (gettables->data_type == OSSL_PARAM_UNSIGNED_INTEGER 486 || gettables->data_type == OSSL_PARAM_INTEGER) { 487 params->data = &u; 488 params->data_size = sizeof(u); 489 } else { 490 params->data = buf; 491 params->data_size = sizeof(buf); 492 } 493 params->return_size = 0; 494 if (EVP_RAND_CTX_get_params(drbg, params)) 495 print_param_value(params, 2); 496 } 497 } 498 } 499 500 static void list_random_instances(void) 501 { 502 display_random("primary", RAND_get0_primary(NULL)); 503 display_random("public", RAND_get0_public(NULL)); 504 display_random("private", RAND_get0_private(NULL)); 505 } 506 507 /* 508 * Encoders 509 */ 510 DEFINE_STACK_OF(OSSL_ENCODER) 511 static int encoder_cmp(const OSSL_ENCODER * const *a, 512 const OSSL_ENCODER * const *b) 513 { 514 return strcmp(OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(*a)), 515 OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(*b))); 516 } 517 518 static void collect_encoders(OSSL_ENCODER *encoder, void *stack) 519 { 520 STACK_OF(OSSL_ENCODER) *encoder_stack = stack; 521 522 if (is_encoder_fetchable(encoder) 523 && OSSL_ENCODER_up_ref(encoder) 524 && sk_OSSL_ENCODER_push(encoder_stack, encoder) <= 0) 525 OSSL_ENCODER_free(encoder); /* up-ref successful but push to stack failed */ 526 } 527 528 static void list_encoders(void) 529 { 530 STACK_OF(OSSL_ENCODER) *encoders; 531 int i; 532 533 encoders = sk_OSSL_ENCODER_new(encoder_cmp); 534 if (encoders == NULL) { 535 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 536 return; 537 } 538 BIO_printf(bio_out, "Provided ENCODERs:\n"); 539 OSSL_ENCODER_do_all_provided(app_get0_libctx(), collect_encoders, 540 encoders); 541 sk_OSSL_ENCODER_sort(encoders); 542 543 for (i = 0; i < sk_OSSL_ENCODER_num(encoders); i++) { 544 OSSL_ENCODER *k = sk_OSSL_ENCODER_value(encoders, i); 545 STACK_OF(OPENSSL_CSTRING) *names = NULL; 546 547 if (select_name != NULL && !OSSL_ENCODER_is_a(k, select_name)) 548 continue; 549 550 names = sk_OPENSSL_CSTRING_new(name_cmp); 551 if (names != NULL && OSSL_ENCODER_names_do_all(k, collect_names, names)) { 552 BIO_printf(bio_out, " "); 553 print_names(bio_out, names); 554 555 BIO_printf(bio_out, " @ %s (%s)\n", 556 OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(k)), 557 OSSL_ENCODER_get0_properties(k)); 558 559 if (verbose) { 560 const char *desc = OSSL_ENCODER_get0_description(k); 561 562 if (desc != NULL) 563 BIO_printf(bio_out, " description: %s\n", desc); 564 print_param_types("settable operation parameters", 565 OSSL_ENCODER_settable_ctx_params(k), 4); 566 } 567 } 568 sk_OPENSSL_CSTRING_free(names); 569 } 570 sk_OSSL_ENCODER_pop_free(encoders, OSSL_ENCODER_free); 571 } 572 573 /* 574 * Decoders 575 */ 576 DEFINE_STACK_OF(OSSL_DECODER) 577 static int decoder_cmp(const OSSL_DECODER * const *a, 578 const OSSL_DECODER * const *b) 579 { 580 return strcmp(OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(*a)), 581 OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(*b))); 582 } 583 584 static void collect_decoders(OSSL_DECODER *decoder, void *stack) 585 { 586 STACK_OF(OSSL_DECODER) *decoder_stack = stack; 587 588 if (is_decoder_fetchable(decoder) 589 && OSSL_DECODER_up_ref(decoder) 590 && sk_OSSL_DECODER_push(decoder_stack, decoder) <= 0) 591 OSSL_DECODER_free(decoder); /* up-ref successful but push to stack failed */ 592 } 593 594 static void list_decoders(void) 595 { 596 STACK_OF(OSSL_DECODER) *decoders; 597 int i; 598 599 decoders = sk_OSSL_DECODER_new(decoder_cmp); 600 if (decoders == NULL) { 601 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 602 return; 603 } 604 BIO_printf(bio_out, "Provided DECODERs:\n"); 605 OSSL_DECODER_do_all_provided(app_get0_libctx(), collect_decoders, 606 decoders); 607 sk_OSSL_DECODER_sort(decoders); 608 609 for (i = 0; i < sk_OSSL_DECODER_num(decoders); i++) { 610 OSSL_DECODER *k = sk_OSSL_DECODER_value(decoders, i); 611 STACK_OF(OPENSSL_CSTRING) *names = NULL; 612 613 if (select_name != NULL && !OSSL_DECODER_is_a(k, select_name)) 614 continue; 615 616 names = sk_OPENSSL_CSTRING_new(name_cmp); 617 if (names != NULL && OSSL_DECODER_names_do_all(k, collect_names, names)) { 618 BIO_printf(bio_out, " "); 619 print_names(bio_out, names); 620 621 BIO_printf(bio_out, " @ %s (%s)\n", 622 OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(k)), 623 OSSL_DECODER_get0_properties(k)); 624 625 if (verbose) { 626 const char *desc = OSSL_DECODER_get0_description(k); 627 628 if (desc != NULL) 629 BIO_printf(bio_out, " description: %s\n", desc); 630 print_param_types("settable operation parameters", 631 OSSL_DECODER_settable_ctx_params(k), 4); 632 } 633 } 634 sk_OPENSSL_CSTRING_free(names); 635 } 636 sk_OSSL_DECODER_pop_free(decoders, OSSL_DECODER_free); 637 } 638 639 DEFINE_STACK_OF(EVP_KEYMGMT) 640 static int keymanager_cmp(const EVP_KEYMGMT * const *a, 641 const EVP_KEYMGMT * const *b) 642 { 643 return strcmp(OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(*a)), 644 OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(*b))); 645 } 646 647 static void collect_keymanagers(EVP_KEYMGMT *km, void *stack) 648 { 649 STACK_OF(EVP_KEYMGMT) *km_stack = stack; 650 651 if (is_keymgmt_fetchable(km) 652 && EVP_KEYMGMT_up_ref(km) 653 && sk_EVP_KEYMGMT_push(km_stack, km) <= 0) 654 EVP_KEYMGMT_free(km); /* up-ref successful but push to stack failed */ 655 } 656 657 static void list_keymanagers(void) 658 { 659 int i; 660 STACK_OF(EVP_KEYMGMT) *km_stack = sk_EVP_KEYMGMT_new(keymanager_cmp); 661 662 EVP_KEYMGMT_do_all_provided(app_get0_libctx(), collect_keymanagers, 663 km_stack); 664 sk_EVP_KEYMGMT_sort(km_stack); 665 666 for (i = 0; i < sk_EVP_KEYMGMT_num(km_stack); i++) { 667 EVP_KEYMGMT *k = sk_EVP_KEYMGMT_value(km_stack, i); 668 STACK_OF(OPENSSL_CSTRING) *names = NULL; 669 670 if (select_name != NULL && !EVP_KEYMGMT_is_a(k, select_name)) 671 continue; 672 673 names = sk_OPENSSL_CSTRING_new(name_cmp); 674 if (names != NULL && EVP_KEYMGMT_names_do_all(k, collect_names, names)) { 675 const char *desc = EVP_KEYMGMT_get0_description(k); 676 677 BIO_printf(bio_out, " Name: "); 678 if (desc != NULL) 679 BIO_printf(bio_out, "%s", desc); 680 else 681 BIO_printf(bio_out, "%s", sk_OPENSSL_CSTRING_value(names, 0)); 682 BIO_printf(bio_out, "\n"); 683 BIO_printf(bio_out, " Type: Provider Algorithm\n"); 684 BIO_printf(bio_out, " IDs: "); 685 print_names(bio_out, names); 686 BIO_printf(bio_out, " @ %s\n", 687 OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(k))); 688 689 if (verbose) { 690 print_param_types("settable key generation parameters", 691 EVP_KEYMGMT_gen_settable_params(k), 4); 692 print_param_types("settable operation parameters", 693 EVP_KEYMGMT_settable_params(k), 4); 694 print_param_types("retrievable operation parameters", 695 EVP_KEYMGMT_gettable_params(k), 4); 696 } 697 } 698 sk_OPENSSL_CSTRING_free(names); 699 } 700 sk_EVP_KEYMGMT_pop_free(km_stack, EVP_KEYMGMT_free); 701 } 702 703 DEFINE_STACK_OF(EVP_SKEYMGMT) 704 static int skeymanager_cmp(const EVP_SKEYMGMT * const *a, 705 const EVP_SKEYMGMT * const *b) 706 { 707 return strcmp(OSSL_PROVIDER_get0_name(EVP_SKEYMGMT_get0_provider(*a)), 708 OSSL_PROVIDER_get0_name(EVP_SKEYMGMT_get0_provider(*b))); 709 } 710 711 static void collect_skeymanagers(EVP_SKEYMGMT *km, void *stack) 712 { 713 STACK_OF(EVP_SKEYMGMT) *km_stack = stack; 714 715 if (is_skeymgmt_fetchable(km) 716 && sk_EVP_SKEYMGMT_push(km_stack, km) > 0) 717 EVP_SKEYMGMT_up_ref(km); 718 } 719 720 static void list_skeymanagers(void) 721 { 722 int i; 723 STACK_OF(EVP_SKEYMGMT) *km_stack = sk_EVP_SKEYMGMT_new(skeymanager_cmp); 724 725 EVP_SKEYMGMT_do_all_provided(app_get0_libctx(), collect_skeymanagers, 726 km_stack); 727 sk_EVP_SKEYMGMT_sort(km_stack); 728 729 for (i = 0; i < sk_EVP_SKEYMGMT_num(km_stack); i++) { 730 EVP_SKEYMGMT *k = sk_EVP_SKEYMGMT_value(km_stack, i); 731 STACK_OF(OPENSSL_CSTRING) *names = NULL; 732 733 if (select_name != NULL && !EVP_SKEYMGMT_is_a(k, select_name)) 734 continue; 735 736 names = sk_OPENSSL_CSTRING_new(name_cmp); 737 if (names != NULL && EVP_SKEYMGMT_names_do_all(k, collect_names, names)) { 738 const char *desc = EVP_SKEYMGMT_get0_description(k); 739 740 BIO_printf(bio_out, " Name: "); 741 if (desc != NULL) 742 BIO_printf(bio_out, "%s", desc); 743 else 744 BIO_printf(bio_out, "%s", sk_OPENSSL_CSTRING_value(names, 0)); 745 BIO_printf(bio_out, "\n"); 746 BIO_printf(bio_out, " Type: Provider Algorithm\n"); 747 BIO_printf(bio_out, " IDs: "); 748 print_names(bio_out, names); 749 BIO_printf(bio_out, " @ %s\n", 750 OSSL_PROVIDER_get0_name(EVP_SKEYMGMT_get0_provider(k))); 751 752 } 753 sk_OPENSSL_CSTRING_free(names); 754 } 755 sk_EVP_SKEYMGMT_pop_free(km_stack, EVP_SKEYMGMT_free); 756 } 757 758 DEFINE_STACK_OF(EVP_SIGNATURE) 759 static int signature_cmp(const EVP_SIGNATURE * const *a, 760 const EVP_SIGNATURE * const *b) 761 { 762 return strcmp(OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*a)), 763 OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*b))); 764 } 765 766 static void collect_signatures(EVP_SIGNATURE *sig, void *stack) 767 { 768 STACK_OF(EVP_SIGNATURE) *sig_stack = stack; 769 770 if (is_signature_fetchable(sig) 771 && EVP_SIGNATURE_up_ref(sig) 772 && sk_EVP_SIGNATURE_push(sig_stack, sig) <= 0) 773 EVP_SIGNATURE_free(sig); /* up-ref successful but push to stack failed */ 774 } 775 776 static void list_signatures(void) 777 { 778 int i, count = 0; 779 STACK_OF(EVP_SIGNATURE) *sig_stack = sk_EVP_SIGNATURE_new(signature_cmp); 780 781 EVP_SIGNATURE_do_all_provided(app_get0_libctx(), collect_signatures, 782 sig_stack); 783 sk_EVP_SIGNATURE_sort(sig_stack); 784 785 for (i = 0; i < sk_EVP_SIGNATURE_num(sig_stack); i++) { 786 EVP_SIGNATURE *k = sk_EVP_SIGNATURE_value(sig_stack, i); 787 STACK_OF(OPENSSL_CSTRING) *names = NULL; 788 789 if (select_name != NULL && !EVP_SIGNATURE_is_a(k, select_name)) 790 continue; 791 792 names = sk_OPENSSL_CSTRING_new(name_cmp); 793 if (names != NULL && EVP_SIGNATURE_names_do_all(k, collect_names, names)) { 794 count++; 795 BIO_printf(bio_out, " "); 796 print_names(bio_out, names); 797 798 BIO_printf(bio_out, " @ %s\n", 799 OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(k))); 800 801 if (verbose) { 802 const char *desc = EVP_SIGNATURE_get0_description(k); 803 804 if (desc != NULL) 805 BIO_printf(bio_out, " description: %s\n", desc); 806 print_param_types("settable operation parameters", 807 EVP_SIGNATURE_settable_ctx_params(k), 4); 808 print_param_types("retrievable operation parameters", 809 EVP_SIGNATURE_gettable_ctx_params(k), 4); 810 } 811 } 812 sk_OPENSSL_CSTRING_free(names); 813 } 814 sk_EVP_SIGNATURE_pop_free(sig_stack, EVP_SIGNATURE_free); 815 if (count == 0) 816 BIO_printf(bio_out, " -\n"); 817 } 818 819 static int list_provider_tls_sigalgs(const OSSL_PARAM params[], void *data) 820 { 821 const OSSL_PARAM *p; 822 823 /* Get registered IANA name */ 824 p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_SIGALG_IANA_NAME); 825 if (p != NULL && p->data_type == OSSL_PARAM_UTF8_STRING) { 826 if (*((int *)data) > 0) 827 BIO_printf(bio_out, ":"); 828 BIO_printf(bio_out, "%s", (char *)(p->data)); 829 /* mark presence of a provider-based sigalg */ 830 *((int *)data) = 2; 831 } 832 /* As built-in providers don't have this capability, never error */ 833 return 1; 834 } 835 836 static int list_tls_sigalg_caps(OSSL_PROVIDER *provider, void *cbdata) 837 { 838 OSSL_PROVIDER_get_capabilities(provider, "TLS-SIGALG", 839 list_provider_tls_sigalgs, 840 cbdata); 841 /* As built-in providers don't have this capability, never error */ 842 return 1; 843 } 844 845 #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2) 846 static void list_tls_groups(int version, int all) 847 { 848 SSL_CTX *ctx = NULL; 849 STACK_OF(OPENSSL_CSTRING) *groups; 850 size_t i, num; 851 852 if ((groups = sk_OPENSSL_CSTRING_new_null()) == NULL) { 853 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 854 return; 855 } 856 if ((ctx = SSL_CTX_new(TLS_method())) == NULL) { 857 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 858 goto err; 859 } 860 if (!SSL_CTX_set_min_proto_version(ctx, version) 861 || !SSL_CTX_set_max_proto_version(ctx, version)) { 862 BIO_printf(bio_err, "ERROR: setting TLS protocol version\n"); 863 goto err; 864 } 865 if (!SSL_CTX_get0_implemented_groups(ctx, all, groups)) { 866 BIO_printf(bio_err, "ERROR: getting implemented TLS group list\n"); 867 goto err; 868 } 869 num = sk_OPENSSL_CSTRING_num(groups); 870 for (i = 0; i < num; ++i) { 871 BIO_printf(bio_out, "%s%c", sk_OPENSSL_CSTRING_value(groups, i), 872 (i < num - 1) ? ':' : '\n'); 873 } 874 err: 875 SSL_CTX_free(ctx); 876 sk_OPENSSL_CSTRING_free(groups); 877 return; 878 } 879 #endif 880 881 static void list_tls_signatures(void) 882 { 883 int tls_sigalg_listed = 0; 884 char *builtin_sigalgs = SSL_get1_builtin_sigalgs(app_get0_libctx()); 885 886 if (builtin_sigalgs != NULL) { 887 if (builtin_sigalgs[0] != 0) { 888 BIO_printf(bio_out, "%s", builtin_sigalgs); 889 tls_sigalg_listed = 1; 890 } 891 OPENSSL_free(builtin_sigalgs); 892 } 893 894 if (!OSSL_PROVIDER_do_all(NULL, list_tls_sigalg_caps, &tls_sigalg_listed)) 895 BIO_printf(bio_err, 896 "ERROR: could not list all provider signature algorithms\n"); 897 if (tls_sigalg_listed < 2) 898 BIO_printf(bio_out, 899 "\nNo TLS sig algs registered by currently active providers"); 900 BIO_printf(bio_out, "\n"); 901 } 902 903 DEFINE_STACK_OF(EVP_KEM) 904 static int kem_cmp(const EVP_KEM * const *a, 905 const EVP_KEM * const *b) 906 { 907 return strcmp(OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*a)), 908 OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*b))); 909 } 910 911 static void collect_kem(EVP_KEM *kem, void *stack) 912 { 913 STACK_OF(EVP_KEM) *kem_stack = stack; 914 915 if (is_kem_fetchable(kem) 916 && EVP_KEM_up_ref(kem) 917 && sk_EVP_KEM_push(kem_stack, kem) <= 0) 918 EVP_KEM_free(kem); /* up-ref successful but push to stack failed */ 919 } 920 921 static void list_kems(void) 922 { 923 int i, count = 0; 924 STACK_OF(EVP_KEM) *kem_stack = sk_EVP_KEM_new(kem_cmp); 925 926 EVP_KEM_do_all_provided(app_get0_libctx(), collect_kem, kem_stack); 927 sk_EVP_KEM_sort(kem_stack); 928 929 for (i = 0; i < sk_EVP_KEM_num(kem_stack); i++) { 930 EVP_KEM *k = sk_EVP_KEM_value(kem_stack, i); 931 STACK_OF(OPENSSL_CSTRING) *names = NULL; 932 933 if (select_name != NULL && !EVP_KEM_is_a(k, select_name)) 934 continue; 935 936 names = sk_OPENSSL_CSTRING_new(name_cmp); 937 if (names != NULL && EVP_KEM_names_do_all(k, collect_names, names)) { 938 count++; 939 BIO_printf(bio_out, " "); 940 print_names(bio_out, names); 941 942 BIO_printf(bio_out, " @ %s\n", 943 OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(k))); 944 945 if (verbose) { 946 const char *desc = EVP_KEM_get0_description(k); 947 948 if (desc != NULL) 949 BIO_printf(bio_out, " description: %s\n", desc); 950 print_param_types("settable operation parameters", 951 EVP_KEM_settable_ctx_params(k), 4); 952 print_param_types("retrievable operation parameters", 953 EVP_KEM_gettable_ctx_params(k), 4); 954 } 955 } 956 sk_OPENSSL_CSTRING_free(names); 957 } 958 sk_EVP_KEM_pop_free(kem_stack, EVP_KEM_free); 959 if (count == 0) 960 BIO_printf(bio_out, " -\n"); 961 } 962 963 DEFINE_STACK_OF(EVP_ASYM_CIPHER) 964 static int asymcipher_cmp(const EVP_ASYM_CIPHER * const *a, 965 const EVP_ASYM_CIPHER * const *b) 966 { 967 return strcmp(OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*a)), 968 OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*b))); 969 } 970 971 static void collect_asymciph(EVP_ASYM_CIPHER *asym_cipher, void *stack) 972 { 973 STACK_OF(EVP_ASYM_CIPHER) *asym_cipher_stack = stack; 974 975 if (is_asym_cipher_fetchable(asym_cipher) 976 && EVP_ASYM_CIPHER_up_ref(asym_cipher) 977 && sk_EVP_ASYM_CIPHER_push(asym_cipher_stack, asym_cipher) <= 0) 978 EVP_ASYM_CIPHER_free(asym_cipher); /* up-ref successful but push to stack failed */ 979 } 980 981 static void list_asymciphers(void) 982 { 983 int i, count = 0; 984 STACK_OF(EVP_ASYM_CIPHER) *asymciph_stack = 985 sk_EVP_ASYM_CIPHER_new(asymcipher_cmp); 986 987 EVP_ASYM_CIPHER_do_all_provided(app_get0_libctx(), collect_asymciph, 988 asymciph_stack); 989 sk_EVP_ASYM_CIPHER_sort(asymciph_stack); 990 991 for (i = 0; i < sk_EVP_ASYM_CIPHER_num(asymciph_stack); i++) { 992 EVP_ASYM_CIPHER *k = sk_EVP_ASYM_CIPHER_value(asymciph_stack, i); 993 STACK_OF(OPENSSL_CSTRING) *names = NULL; 994 995 if (select_name != NULL && !EVP_ASYM_CIPHER_is_a(k, select_name)) 996 continue; 997 998 names = sk_OPENSSL_CSTRING_new(name_cmp); 999 if (names != NULL 1000 && EVP_ASYM_CIPHER_names_do_all(k, collect_names, names)) { 1001 count++; 1002 BIO_printf(bio_out, " "); 1003 print_names(bio_out, names); 1004 1005 BIO_printf(bio_out, " @ %s\n", 1006 OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(k))); 1007 1008 if (verbose) { 1009 const char *desc = EVP_ASYM_CIPHER_get0_description(k); 1010 1011 if (desc != NULL) 1012 BIO_printf(bio_out, " description: %s\n", desc); 1013 print_param_types("settable operation parameters", 1014 EVP_ASYM_CIPHER_settable_ctx_params(k), 4); 1015 print_param_types("retrievable operation parameters", 1016 EVP_ASYM_CIPHER_gettable_ctx_params(k), 4); 1017 } 1018 } 1019 sk_OPENSSL_CSTRING_free(names); 1020 } 1021 sk_EVP_ASYM_CIPHER_pop_free(asymciph_stack, EVP_ASYM_CIPHER_free); 1022 if (count == 0) 1023 BIO_printf(bio_out, " -\n"); 1024 } 1025 1026 DEFINE_STACK_OF(EVP_KEYEXCH) 1027 static int kex_cmp(const EVP_KEYEXCH * const *a, 1028 const EVP_KEYEXCH * const *b) 1029 { 1030 return strcmp(OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*a)), 1031 OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*b))); 1032 } 1033 1034 static void collect_kex(EVP_KEYEXCH *kex, void *stack) 1035 { 1036 STACK_OF(EVP_KEYEXCH) *kex_stack = stack; 1037 1038 if (is_keyexch_fetchable(kex) 1039 && EVP_KEYEXCH_up_ref(kex) 1040 && sk_EVP_KEYEXCH_push(kex_stack, kex) <= 0) 1041 EVP_KEYEXCH_free(kex); /* up-ref successful but push to stack failed */ 1042 } 1043 1044 static void list_keyexchanges(void) 1045 { 1046 int i, count = 0; 1047 STACK_OF(EVP_KEYEXCH) *kex_stack = sk_EVP_KEYEXCH_new(kex_cmp); 1048 1049 EVP_KEYEXCH_do_all_provided(app_get0_libctx(), collect_kex, kex_stack); 1050 sk_EVP_KEYEXCH_sort(kex_stack); 1051 1052 for (i = 0; i < sk_EVP_KEYEXCH_num(kex_stack); i++) { 1053 EVP_KEYEXCH *k = sk_EVP_KEYEXCH_value(kex_stack, i); 1054 STACK_OF(OPENSSL_CSTRING) *names = NULL; 1055 1056 if (select_name != NULL && !EVP_KEYEXCH_is_a(k, select_name)) 1057 continue; 1058 1059 names = sk_OPENSSL_CSTRING_new(name_cmp); 1060 if (names != NULL && EVP_KEYEXCH_names_do_all(k, collect_names, names)) { 1061 count++; 1062 BIO_printf(bio_out, " "); 1063 print_names(bio_out, names); 1064 1065 BIO_printf(bio_out, " @ %s\n", 1066 OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(k))); 1067 1068 if (verbose) { 1069 const char *desc = EVP_KEYEXCH_get0_description(k); 1070 1071 if (desc != NULL) 1072 BIO_printf(bio_out, " description: %s\n", desc); 1073 print_param_types("settable operation parameters", 1074 EVP_KEYEXCH_settable_ctx_params(k), 4); 1075 print_param_types("retrievable operation parameters", 1076 EVP_KEYEXCH_gettable_ctx_params(k), 4); 1077 } 1078 } 1079 sk_OPENSSL_CSTRING_free(names); 1080 } 1081 sk_EVP_KEYEXCH_pop_free(kex_stack, EVP_KEYEXCH_free); 1082 if (count == 0) 1083 BIO_printf(bio_out, " -\n"); 1084 } 1085 1086 static void list_objects(void) 1087 { 1088 int max_nid = OBJ_new_nid(0); 1089 int i; 1090 char *oid_buf = NULL; 1091 int oid_size = 0; 1092 1093 /* Skip 0, since that's NID_undef */ 1094 for (i = 1; i < max_nid; i++) { 1095 const ASN1_OBJECT *obj = OBJ_nid2obj(i); 1096 const char *sn = OBJ_nid2sn(i); 1097 const char *ln = OBJ_nid2ln(i); 1098 int n = 0; 1099 1100 /* 1101 * If one of the retrieved objects somehow generated an error, 1102 * we ignore it. The check for NID_undef below will detect the 1103 * error and simply skip to the next NID. 1104 */ 1105 ERR_clear_error(); 1106 1107 if (OBJ_obj2nid(obj) == NID_undef) 1108 continue; 1109 1110 if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) { 1111 BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln); 1112 continue; 1113 } 1114 if (n < 0) 1115 break; /* Error */ 1116 1117 if (n > oid_size) { 1118 oid_buf = OPENSSL_realloc(oid_buf, n + 1); 1119 if (oid_buf == NULL) { 1120 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 1121 break; /* Error */ 1122 } 1123 oid_size = n + 1; 1124 } 1125 if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0) 1126 break; /* Error */ 1127 if (ln == NULL || strcmp(sn, ln) == 0) 1128 BIO_printf(bio_out, "%s = %s\n", sn, oid_buf); 1129 else 1130 BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf); 1131 } 1132 1133 OPENSSL_free(oid_buf); 1134 } 1135 1136 static void list_options_for_command(const char *command) 1137 { 1138 const FUNCTION *fp; 1139 const OPTIONS *o; 1140 1141 for (fp = functions; fp->name != NULL; fp++) 1142 if (strcmp(fp->name, command) == 0) 1143 break; 1144 if (fp->name == NULL) { 1145 BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n", 1146 command); 1147 return; 1148 } 1149 1150 if ((o = fp->help) == NULL) 1151 return; 1152 1153 for ( ; o->name != NULL; o++) { 1154 char c = o->valtype; 1155 1156 if (o->name == OPT_PARAM_STR) 1157 break; 1158 1159 if (o->name == OPT_HELP_STR 1160 || o->name == OPT_MORE_STR 1161 || o->name == OPT_SECTION_STR 1162 || o->name[0] == '\0') 1163 continue; 1164 BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c); 1165 } 1166 /* Always output the -- marker since it is sometimes documented. */ 1167 BIO_printf(bio_out, "- -\n"); 1168 } 1169 1170 static int is_md_available(const char *name) 1171 { 1172 EVP_MD *md; 1173 const char *propq = app_get0_propq(); 1174 1175 /* Look through providers' digests */ 1176 ERR_set_mark(); 1177 md = EVP_MD_fetch(app_get0_libctx(), name, propq); 1178 ERR_pop_to_mark(); 1179 if (md != NULL) { 1180 EVP_MD_free(md); 1181 return 1; 1182 } 1183 1184 return propq != NULL || get_digest_from_engine(name) == NULL ? 0 : 1; 1185 } 1186 1187 static int is_cipher_available(const char *name) 1188 { 1189 EVP_CIPHER *cipher; 1190 const char *propq = app_get0_propq(); 1191 1192 /* Look through providers' ciphers */ 1193 ERR_set_mark(); 1194 cipher = EVP_CIPHER_fetch(app_get0_libctx(), name, propq); 1195 ERR_pop_to_mark(); 1196 if (cipher != NULL) { 1197 EVP_CIPHER_free(cipher); 1198 return 1; 1199 } 1200 1201 return propq != NULL || get_cipher_from_engine(name) == NULL ? 0 : 1; 1202 } 1203 1204 static void list_type(FUNC_TYPE ft, int one) 1205 { 1206 FUNCTION *fp; 1207 int i = 0; 1208 DISPLAY_COLUMNS dc; 1209 1210 memset(&dc, 0, sizeof(dc)); 1211 if (!one) 1212 calculate_columns(functions, &dc); 1213 1214 for (fp = functions; fp->name != NULL; fp++) { 1215 if (fp->type != ft) 1216 continue; 1217 switch (ft) { 1218 case FT_cipher: 1219 if (!is_cipher_available(fp->name)) 1220 continue; 1221 break; 1222 case FT_md: 1223 if (!is_md_available(fp->name)) 1224 continue; 1225 break; 1226 default: 1227 break; 1228 } 1229 if (one) { 1230 BIO_printf(bio_out, "%s\n", fp->name); 1231 } else { 1232 if (i % dc.columns == 0 && i > 0) 1233 BIO_printf(bio_out, "\n"); 1234 BIO_printf(bio_out, "%-*s", dc.width, fp->name); 1235 i++; 1236 } 1237 } 1238 if (!one) 1239 BIO_printf(bio_out, "\n\n"); 1240 } 1241 1242 static void list_pkey(void) 1243 { 1244 #ifndef OPENSSL_NO_DEPRECATED_3_0 1245 int i; 1246 1247 if (select_name == NULL && include_legacy()) { 1248 BIO_printf(bio_out, "Legacy:\n"); 1249 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) { 1250 const EVP_PKEY_ASN1_METHOD *ameth; 1251 int pkey_id, pkey_base_id, pkey_flags; 1252 const char *pinfo, *pem_str; 1253 ameth = EVP_PKEY_asn1_get0(i); 1254 EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags, 1255 &pinfo, &pem_str, ameth); 1256 if (pkey_flags & ASN1_PKEY_ALIAS) { 1257 BIO_printf(bio_out, " Name: %s\n", OBJ_nid2ln(pkey_id)); 1258 BIO_printf(bio_out, "\tAlias for: %s\n", 1259 OBJ_nid2ln(pkey_base_id)); 1260 } else { 1261 BIO_printf(bio_out, " Name: %s\n", pinfo); 1262 BIO_printf(bio_out, "\tType: %s Algorithm\n", 1263 pkey_flags & ASN1_PKEY_DYNAMIC ? 1264 "External" : "Builtin"); 1265 BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id)); 1266 if (pem_str == NULL) 1267 pem_str = "(none)"; 1268 BIO_printf(bio_out, "\tPEM string: %s\n", pem_str); 1269 } 1270 } 1271 } 1272 #endif 1273 BIO_printf(bio_out, "Provided:\n"); 1274 BIO_printf(bio_out, " Key Managers:\n"); 1275 list_keymanagers(); 1276 } 1277 1278 static void list_pkey_meth(void) 1279 { 1280 #ifndef OPENSSL_NO_DEPRECATED_3_0 1281 size_t i; 1282 size_t meth_count = EVP_PKEY_meth_get_count(); 1283 1284 if (select_name == NULL && include_legacy()) { 1285 BIO_printf(bio_out, "Legacy:\n"); 1286 for (i = 0; i < meth_count; i++) { 1287 const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i); 1288 int pkey_id, pkey_flags; 1289 1290 EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth); 1291 BIO_printf(bio_out, " %s\n", OBJ_nid2ln(pkey_id)); 1292 BIO_printf(bio_out, "\tType: %s Algorithm\n", 1293 pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin"); 1294 } 1295 } 1296 #endif 1297 BIO_printf(bio_out, "Provided:\n"); 1298 BIO_printf(bio_out, " Encryption:\n"); 1299 list_asymciphers(); 1300 BIO_printf(bio_out, " Key Exchange:\n"); 1301 list_keyexchanges(); 1302 BIO_printf(bio_out, " Signatures:\n"); 1303 list_signatures(); 1304 BIO_printf(bio_out, " Key encapsulation:\n"); 1305 list_kems(); 1306 } 1307 1308 DEFINE_STACK_OF(OSSL_STORE_LOADER) 1309 static int store_cmp(const OSSL_STORE_LOADER * const *a, 1310 const OSSL_STORE_LOADER * const *b) 1311 { 1312 return strcmp(OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*a)), 1313 OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*b))); 1314 } 1315 1316 static void collect_store_loaders(OSSL_STORE_LOADER *store, void *stack) 1317 { 1318 STACK_OF(OSSL_STORE_LOADER) *store_stack = stack; 1319 1320 if (OSSL_STORE_LOADER_up_ref(store) 1321 && sk_OSSL_STORE_LOADER_push(store_stack, store) <= 0) 1322 OSSL_STORE_LOADER_free(store); /* up-ref successful but push to stack failed */ 1323 } 1324 1325 static void list_store_loaders(void) 1326 { 1327 STACK_OF(OSSL_STORE_LOADER) *stores = sk_OSSL_STORE_LOADER_new(store_cmp); 1328 int i; 1329 1330 if (stores == NULL) { 1331 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 1332 return; 1333 } 1334 BIO_printf(bio_out, "Provided STORE LOADERs:\n"); 1335 OSSL_STORE_LOADER_do_all_provided(app_get0_libctx(), collect_store_loaders, 1336 stores); 1337 sk_OSSL_STORE_LOADER_sort(stores); 1338 for (i = 0; i < sk_OSSL_STORE_LOADER_num(stores); i++) { 1339 const OSSL_STORE_LOADER *m = sk_OSSL_STORE_LOADER_value(stores, i); 1340 STACK_OF(OPENSSL_CSTRING) *names = NULL; 1341 1342 if (select_name != NULL && !OSSL_STORE_LOADER_is_a(m, select_name)) 1343 continue; 1344 1345 names = sk_OPENSSL_CSTRING_new(name_cmp); 1346 if (names != NULL && OSSL_STORE_LOADER_names_do_all(m, collect_names, 1347 names)) { 1348 BIO_printf(bio_out, " "); 1349 print_names(bio_out, names); 1350 1351 BIO_printf(bio_out, " @ %s\n", 1352 OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(m))); 1353 } 1354 sk_OPENSSL_CSTRING_free(names); 1355 } 1356 sk_OSSL_STORE_LOADER_pop_free(stores, OSSL_STORE_LOADER_free); 1357 } 1358 1359 DEFINE_STACK_OF(OSSL_PROVIDER) 1360 static int provider_cmp(const OSSL_PROVIDER * const *a, 1361 const OSSL_PROVIDER * const *b) 1362 { 1363 return strcmp(OSSL_PROVIDER_get0_name(*a), OSSL_PROVIDER_get0_name(*b)); 1364 } 1365 1366 static int collect_providers(OSSL_PROVIDER *provider, void *stack) 1367 { 1368 STACK_OF(OSSL_PROVIDER) *provider_stack = stack; 1369 1370 /* 1371 * If OK - result is the index of inserted data 1372 * Error - result is -1 or 0 1373 */ 1374 return sk_OSSL_PROVIDER_push(provider_stack, provider) > 0 ? 1 : 0; 1375 } 1376 1377 static void list_provider_info(void) 1378 { 1379 STACK_OF(OSSL_PROVIDER) *providers = sk_OSSL_PROVIDER_new(provider_cmp); 1380 OSSL_PARAM params[5]; 1381 char *name, *version, *buildinfo; 1382 int status; 1383 int i; 1384 1385 if (providers == NULL) { 1386 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 1387 return; 1388 } 1389 1390 if (OSSL_PROVIDER_do_all(NULL, &collect_providers, providers) != 1) { 1391 sk_OSSL_PROVIDER_free(providers); 1392 BIO_printf(bio_err, "ERROR: Memory allocation\n"); 1393 return; 1394 } 1395 1396 BIO_printf(bio_out, "Providers:\n"); 1397 sk_OSSL_PROVIDER_sort(providers); 1398 for (i = 0; i < sk_OSSL_PROVIDER_num(providers); i++) { 1399 const OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(providers, i); 1400 const char *provname = OSSL_PROVIDER_get0_name(prov); 1401 1402 BIO_printf(bio_out, " %s\n", provname); 1403 1404 /* Query the "known" information parameters, the order matches below */ 1405 params[0] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_NAME, 1406 &name, 0); 1407 params[1] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION, 1408 &version, 0); 1409 params[2] = OSSL_PARAM_construct_int(OSSL_PROV_PARAM_STATUS, &status); 1410 params[3] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_BUILDINFO, 1411 &buildinfo, 0); 1412 params[4] = OSSL_PARAM_construct_end(); 1413 OSSL_PARAM_set_all_unmodified(params); 1414 if (!OSSL_PROVIDER_get_params(prov, params)) { 1415 BIO_printf(bio_err, 1416 "WARNING: Unable to query provider parameters for %s\n", 1417 provname); 1418 } else { 1419 /* Print out the provider information, the params order matches above */ 1420 if (OSSL_PARAM_modified(params)) 1421 BIO_printf(bio_out, " name: %s\n", name); 1422 if (OSSL_PARAM_modified(params + 1)) 1423 BIO_printf(bio_out, " version: %s\n", version); 1424 if (OSSL_PARAM_modified(params + 2)) 1425 BIO_printf(bio_out, " status: %sactive\n", status ? "" : "in"); 1426 if (verbose) { 1427 if (OSSL_PARAM_modified(params + 3)) 1428 BIO_printf(bio_out, " build info: %s\n", buildinfo); 1429 print_param_types("gettable provider parameters", 1430 OSSL_PROVIDER_gettable_params(prov), 4); 1431 } 1432 } 1433 } 1434 sk_OSSL_PROVIDER_free(providers); 1435 } 1436 1437 #ifndef OPENSSL_NO_DEPRECATED_3_0 1438 static void list_engines(void) 1439 { 1440 # ifndef OPENSSL_NO_ENGINE 1441 ENGINE *e; 1442 1443 BIO_puts(bio_out, "Engines:\n"); 1444 e = ENGINE_get_first(); 1445 while (e) { 1446 BIO_printf(bio_out, "%s\n", ENGINE_get_id(e)); 1447 e = ENGINE_get_next(e); 1448 } 1449 # else 1450 BIO_puts(bio_out, "Engine support is disabled.\n"); 1451 # endif 1452 } 1453 #endif 1454 1455 static void list_disabled(void) 1456 { 1457 BIO_puts(bio_out, "Disabled algorithms:\n"); 1458 #ifdef OPENSSL_NO_ARGON2 1459 BIO_puts(bio_out, "ARGON2\n"); 1460 #endif 1461 #ifdef OPENSSL_NO_ARIA 1462 BIO_puts(bio_out, "ARIA\n"); 1463 #endif 1464 #ifdef OPENSSL_NO_BF 1465 BIO_puts(bio_out, "BF\n"); 1466 #endif 1467 #ifdef OPENSSL_NO_BLAKE2 1468 BIO_puts(bio_out, "BLAKE2\n"); 1469 #endif 1470 #ifdef OPENSSL_NO_CAMELLIA 1471 BIO_puts(bio_out, "CAMELLIA\n"); 1472 #endif 1473 #ifdef OPENSSL_NO_CAST 1474 BIO_puts(bio_out, "CAST\n"); 1475 #endif 1476 #ifdef OPENSSL_NO_CMAC 1477 BIO_puts(bio_out, "CMAC\n"); 1478 #endif 1479 #ifdef OPENSSL_NO_CMS 1480 BIO_puts(bio_out, "CMS\n"); 1481 #endif 1482 #ifdef OPENSSL_NO_COMP 1483 BIO_puts(bio_out, "COMP\n"); 1484 #endif 1485 #ifdef OPENSSL_NO_DES 1486 BIO_puts(bio_out, "DES\n"); 1487 #endif 1488 #ifdef OPENSSL_NO_DGRAM 1489 BIO_puts(bio_out, "DGRAM\n"); 1490 #endif 1491 #ifdef OPENSSL_NO_DH 1492 BIO_puts(bio_out, "DH\n"); 1493 #endif 1494 #ifdef OPENSSL_NO_DSA 1495 BIO_puts(bio_out, "DSA\n"); 1496 #endif 1497 #if defined(OPENSSL_NO_DTLS) 1498 BIO_puts(bio_out, "DTLS\n"); 1499 #endif 1500 #if defined(OPENSSL_NO_DTLS1) 1501 BIO_puts(bio_out, "DTLS1\n"); 1502 #endif 1503 #if defined(OPENSSL_NO_DTLS1_2) 1504 BIO_puts(bio_out, "DTLS1_2\n"); 1505 #endif 1506 #ifdef OPENSSL_NO_EC 1507 BIO_puts(bio_out, "EC\n"); 1508 #endif 1509 #ifdef OPENSSL_NO_ECX 1510 BIO_puts(bio_out, "ECX\n"); 1511 #endif 1512 #ifdef OPENSSL_NO_EC2M 1513 BIO_puts(bio_out, "EC2M\n"); 1514 #endif 1515 #if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0) 1516 BIO_puts(bio_out, "ENGINE\n"); 1517 #endif 1518 #ifdef OPENSSL_NO_GOST 1519 BIO_puts(bio_out, "GOST\n"); 1520 #endif 1521 #ifdef OPENSSL_NO_IDEA 1522 BIO_puts(bio_out, "IDEA\n"); 1523 #endif 1524 #ifdef OPENSSL_NO_MD2 1525 BIO_puts(bio_out, "MD2\n"); 1526 #endif 1527 #ifdef OPENSSL_NO_MD4 1528 BIO_puts(bio_out, "MD4\n"); 1529 #endif 1530 #ifdef OPENSSL_NO_MD5 1531 BIO_puts(bio_out, "MD5\n"); 1532 #endif 1533 #ifdef OPENSSL_NO_MDC2 1534 BIO_puts(bio_out, "MDC2\n"); 1535 #endif 1536 #ifdef OPENSSL_NO_OCB 1537 BIO_puts(bio_out, "OCB\n"); 1538 #endif 1539 #ifdef OPENSSL_NO_OCSP 1540 BIO_puts(bio_out, "OCSP\n"); 1541 #endif 1542 #ifdef OPENSSL_NO_PSK 1543 BIO_puts(bio_out, "PSK\n"); 1544 #endif 1545 #ifdef OPENSSL_NO_RC2 1546 BIO_puts(bio_out, "RC2\n"); 1547 #endif 1548 #ifdef OPENSSL_NO_RC4 1549 BIO_puts(bio_out, "RC4\n"); 1550 #endif 1551 #ifdef OPENSSL_NO_RC5 1552 BIO_puts(bio_out, "RC5\n"); 1553 #endif 1554 #ifdef OPENSSL_NO_RMD160 1555 BIO_puts(bio_out, "RMD160\n"); 1556 #endif 1557 #ifdef OPENSSL_NO_SCRYPT 1558 BIO_puts(bio_out, "SCRYPT\n"); 1559 #endif 1560 #ifdef OPENSSL_NO_SCTP 1561 BIO_puts(bio_out, "SCTP\n"); 1562 #endif 1563 #ifdef OPENSSL_NO_SEED 1564 BIO_puts(bio_out, "SEED\n"); 1565 #endif 1566 #ifdef OPENSSL_NO_SM2 1567 BIO_puts(bio_out, "SM2\n"); 1568 #endif 1569 #ifdef OPENSSL_NO_SM3 1570 BIO_puts(bio_out, "SM3\n"); 1571 #endif 1572 #ifdef OPENSSL_NO_SM4 1573 BIO_puts(bio_out, "SM4\n"); 1574 #endif 1575 #ifdef OPENSSL_NO_SOCK 1576 BIO_puts(bio_out, "SOCK\n"); 1577 #endif 1578 #ifdef OPENSSL_NO_SRP 1579 BIO_puts(bio_out, "SRP\n"); 1580 #endif 1581 #ifdef OPENSSL_NO_SRTP 1582 BIO_puts(bio_out, "SRTP\n"); 1583 #endif 1584 #ifdef OPENSSL_NO_SSL3 1585 BIO_puts(bio_out, "SSL3\n"); 1586 #endif 1587 #ifdef OPENSSL_NO_TLS1 1588 BIO_puts(bio_out, "TLS1\n"); 1589 #endif 1590 #ifdef OPENSSL_NO_TLS1_1 1591 BIO_puts(bio_out, "TLS1_1\n"); 1592 #endif 1593 #ifdef OPENSSL_NO_TLS1_2 1594 BIO_puts(bio_out, "TLS1_2\n"); 1595 #endif 1596 #ifdef OPENSSL_NO_WHIRLPOOL 1597 BIO_puts(bio_out, "WHIRLPOOL\n"); 1598 #endif 1599 #ifdef OPENSSL_NO_ZLIB 1600 BIO_puts(bio_out, "ZLIB\n"); 1601 #endif 1602 #ifdef OPENSSL_NO_BROTLI 1603 BIO_puts(bio_out, "BROTLI\n"); 1604 #endif 1605 #ifdef OPENSSL_NO_ZSTD 1606 BIO_puts(bio_out, "ZSTD\n"); 1607 #endif 1608 } 1609 1610 /* Unified enum for help and list commands. */ 1611 typedef enum HELPLIST_CHOICE { 1612 OPT_COMMON, 1613 OPT_ONE, OPT_VERBOSE, 1614 OPT_ALL_ARGORITHMS, 1615 OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS, 1616 OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS, 1617 OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED, 1618 OPT_KDF_ALGORITHMS, OPT_RANDOM_INSTANCES, OPT_RANDOM_GENERATORS, 1619 OPT_ENCODERS, OPT_DECODERS, OPT_KEYMANAGERS, OPT_KEYEXCHANGE_ALGORITHMS, 1620 OPT_SKEYMANAGERS, 1621 OPT_KEM_ALGORITHMS, OPT_SIGNATURE_ALGORITHMS, 1622 OPT_TLS_SIGNATURE_ALGORITHMS, OPT_ASYM_CIPHER_ALGORITHMS, 1623 OPT_STORE_LOADERS, OPT_PROVIDER_INFO, OPT_OBJECTS, 1624 OPT_SELECT_NAME, 1625 #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2) 1626 OPT_ALL_TLS_GROUPS, OPT_TLS_GROUPS, 1627 # if !defined(OPENSSL_NO_TLS1_2) 1628 OPT_TLS1_2, 1629 # endif 1630 # if !defined(OPENSSL_NO_TLS1_3) 1631 OPT_TLS1_3, 1632 # endif 1633 #endif 1634 #ifndef OPENSSL_NO_DEPRECATED_3_0 1635 OPT_ENGINES, 1636 #endif 1637 OPT_PROV_ENUM 1638 } HELPLIST_CHOICE; 1639 1640 const OPTIONS list_options[] = { 1641 1642 OPT_SECTION("General"), 1643 {"help", OPT_HELP, '-', "Display this summary"}, 1644 1645 OPT_SECTION("Output"), 1646 {"1", OPT_ONE, '-', "List in one column"}, 1647 {"verbose", OPT_VERBOSE, '-', "Verbose listing"}, 1648 {"select", OPT_SELECT_NAME, 's', "Select a single algorithm"}, 1649 {"commands", OPT_COMMANDS, '-', "List of standard commands"}, 1650 {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"}, 1651 {"all-algorithms", OPT_ALL_ARGORITHMS, '-', "List of all algorithms"}, 1652 #ifndef OPENSSL_NO_DEPRECATED_3_0 1653 {"digest-commands", OPT_DIGEST_COMMANDS, '-', 1654 "List of message digest commands (deprecated)"}, 1655 #endif 1656 {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-', 1657 "List of message digest algorithms"}, 1658 {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-', 1659 "List of key derivation and pseudo random function algorithms"}, 1660 {"random-instances", OPT_RANDOM_INSTANCES, '-', 1661 "List the primary, public and private random number generator details"}, 1662 {"random-generators", OPT_RANDOM_GENERATORS, '-', 1663 "List of random number generators"}, 1664 {"mac-algorithms", OPT_MAC_ALGORITHMS, '-', 1665 "List of message authentication code algorithms"}, 1666 #ifndef OPENSSL_NO_DEPRECATED_3_0 1667 {"cipher-commands", OPT_CIPHER_COMMANDS, '-', 1668 "List of cipher commands (deprecated)"}, 1669 #endif 1670 {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-', 1671 "List of symmetric cipher algorithms"}, 1672 {"encoders", OPT_ENCODERS, '-', "List of encoding methods" }, 1673 {"decoders", OPT_DECODERS, '-', "List of decoding methods" }, 1674 {"key-managers", OPT_KEYMANAGERS, '-', "List of key managers" }, 1675 {"skey-managers", OPT_SKEYMANAGERS, '-', "List of symmetric key managers" }, 1676 {"key-exchange-algorithms", OPT_KEYEXCHANGE_ALGORITHMS, '-', 1677 "List of key exchange algorithms" }, 1678 {"kem-algorithms", OPT_KEM_ALGORITHMS, '-', 1679 "List of key encapsulation mechanism algorithms" }, 1680 {"signature-algorithms", OPT_SIGNATURE_ALGORITHMS, '-', 1681 "List of signature algorithms" }, 1682 {"tls-signature-algorithms", OPT_TLS_SIGNATURE_ALGORITHMS, '-', 1683 "List of TLS signature algorithms" }, 1684 {"asymcipher-algorithms", OPT_ASYM_CIPHER_ALGORITHMS, '-', 1685 "List of asymmetric cipher algorithms" }, 1686 {"public-key-algorithms", OPT_PK_ALGORITHMS, '-', 1687 "List of public key algorithms"}, 1688 {"public-key-methods", OPT_PK_METHOD, '-', 1689 "List of public key methods"}, 1690 {"store-loaders", OPT_STORE_LOADERS, '-', 1691 "List of store loaders"}, 1692 #if !defined(OPENSSL_NO_TLS1_2) || !defined(OPENSSL_NO_TLS1_3) 1693 {"tls-groups", OPT_TLS_GROUPS, '-', 1694 "List implemented TLS key exchange 'groups'" }, 1695 {"all-tls-groups", OPT_ALL_TLS_GROUPS, '-', 1696 "List implemented TLS key exchange 'groups' and all aliases" }, 1697 # ifndef OPENSSL_NO_TLS1_2 1698 {"tls1_2", OPT_TLS1_2, '-', 1699 "When listing 'groups', list those compatible with TLS1.2"}, 1700 # endif 1701 # ifndef OPENSSL_NO_TLS1_3 1702 {"tls1_3", OPT_TLS1_3, '-', 1703 "When listing 'groups', list those compatible with TLS1.3"}, 1704 # endif 1705 #endif 1706 {"providers", OPT_PROVIDER_INFO, '-', 1707 "List of provider information"}, 1708 #ifndef OPENSSL_NO_DEPRECATED_3_0 1709 {"engines", OPT_ENGINES, '-', 1710 "List of loaded engines"}, 1711 #endif 1712 {"disabled", OPT_DISABLED, '-', "List of disabled features"}, 1713 {"options", OPT_OPTIONS, 's', 1714 "List options for specified command"}, 1715 {"objects", OPT_OBJECTS, '-', 1716 "List built in objects (OID<->name mappings)"}, 1717 1718 OPT_PROV_OPTIONS, 1719 {NULL} 1720 }; 1721 1722 int list_main(int argc, char **argv) 1723 { 1724 char *prog; 1725 HELPLIST_CHOICE o; 1726 int one = 0, done = 0; 1727 int print_newline = 0; 1728 #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2) 1729 int all_tls_groups = 0; 1730 # if !defined(OPENSSL_NO_TLS1_3) 1731 unsigned int tls_version = TLS1_3_VERSION; 1732 # else 1733 unsigned int tls_version = TLS1_2_VERSION; 1734 # endif 1735 #endif 1736 struct { 1737 unsigned int commands:1; 1738 unsigned int all_algorithms:1; 1739 unsigned int random_instances:1; 1740 unsigned int random_generators:1; 1741 unsigned int digest_commands:1; 1742 unsigned int digest_algorithms:1; 1743 unsigned int kdf_algorithms:1; 1744 unsigned int mac_algorithms:1; 1745 unsigned int cipher_commands:1; 1746 unsigned int cipher_algorithms:1; 1747 unsigned int encoder_algorithms:1; 1748 unsigned int decoder_algorithms:1; 1749 unsigned int keymanager_algorithms:1; 1750 unsigned int skeymanager_algorithms:1; 1751 unsigned int signature_algorithms:1; 1752 unsigned int tls_signature_algorithms:1; 1753 unsigned int keyexchange_algorithms:1; 1754 unsigned int kem_algorithms:1; 1755 unsigned int tls_groups:1; 1756 unsigned int asym_cipher_algorithms:1; 1757 unsigned int pk_algorithms:1; 1758 unsigned int pk_method:1; 1759 unsigned int store_loaders:1; 1760 unsigned int provider_info:1; 1761 #ifndef OPENSSL_NO_DEPRECATED_3_0 1762 unsigned int engines:1; 1763 #endif 1764 unsigned int disabled:1; 1765 unsigned int objects:1; 1766 unsigned int options:1; 1767 } todo = { 0, }; 1768 1769 verbose = 0; /* Clear a possible previous call */ 1770 1771 prog = opt_init(argc, argv, list_options); 1772 while ((o = opt_next()) != OPT_EOF) { 1773 switch (o) { 1774 case OPT_EOF: /* Never hit, but suppresses warning */ 1775 case OPT_ERR: 1776 opthelp: 1777 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); 1778 return 1; 1779 case OPT_HELP: 1780 opt_help(list_options); 1781 return 0; 1782 case OPT_ONE: 1783 one = 1; 1784 break; 1785 case OPT_ALL_ARGORITHMS: 1786 todo.all_algorithms = 1; 1787 break; 1788 case OPT_COMMANDS: 1789 todo.commands = 1; 1790 break; 1791 case OPT_DIGEST_COMMANDS: 1792 todo.digest_commands = 1; 1793 break; 1794 case OPT_DIGEST_ALGORITHMS: 1795 todo.digest_algorithms = 1; 1796 break; 1797 case OPT_KDF_ALGORITHMS: 1798 todo.kdf_algorithms = 1; 1799 break; 1800 case OPT_RANDOM_INSTANCES: 1801 todo.random_instances = 1; 1802 break; 1803 case OPT_RANDOM_GENERATORS: 1804 todo.random_generators = 1; 1805 break; 1806 case OPT_MAC_ALGORITHMS: 1807 todo.mac_algorithms = 1; 1808 break; 1809 case OPT_CIPHER_COMMANDS: 1810 todo.cipher_commands = 1; 1811 break; 1812 case OPT_CIPHER_ALGORITHMS: 1813 todo.cipher_algorithms = 1; 1814 break; 1815 case OPT_ENCODERS: 1816 todo.encoder_algorithms = 1; 1817 break; 1818 case OPT_DECODERS: 1819 todo.decoder_algorithms = 1; 1820 break; 1821 case OPT_KEYMANAGERS: 1822 todo.keymanager_algorithms = 1; 1823 break; 1824 case OPT_SKEYMANAGERS: 1825 todo.skeymanager_algorithms = 1; 1826 break; 1827 case OPT_SIGNATURE_ALGORITHMS: 1828 todo.signature_algorithms = 1; 1829 break; 1830 case OPT_TLS_SIGNATURE_ALGORITHMS: 1831 todo.tls_signature_algorithms = 1; 1832 break; 1833 case OPT_KEYEXCHANGE_ALGORITHMS: 1834 todo.keyexchange_algorithms = 1; 1835 break; 1836 case OPT_KEM_ALGORITHMS: 1837 todo.kem_algorithms = 1; 1838 break; 1839 #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2) 1840 case OPT_TLS_GROUPS: 1841 todo.tls_groups = 1; 1842 break; 1843 case OPT_ALL_TLS_GROUPS: 1844 all_tls_groups = 1; 1845 todo.tls_groups = 1; 1846 break; 1847 # if !defined(OPENSSL_NO_TLS1_2) 1848 case OPT_TLS1_2: 1849 tls_version = TLS1_2_VERSION; 1850 break; 1851 # endif 1852 # if !defined(OPENSSL_NO_TLS1_3) 1853 case OPT_TLS1_3: 1854 tls_version = TLS1_3_VERSION; 1855 break; 1856 # endif 1857 #endif 1858 case OPT_ASYM_CIPHER_ALGORITHMS: 1859 todo.asym_cipher_algorithms = 1; 1860 break; 1861 case OPT_PK_ALGORITHMS: 1862 todo.pk_algorithms = 1; 1863 break; 1864 case OPT_PK_METHOD: 1865 todo.pk_method = 1; 1866 break; 1867 case OPT_STORE_LOADERS: 1868 todo.store_loaders = 1; 1869 break; 1870 case OPT_PROVIDER_INFO: 1871 todo.provider_info = 1; 1872 break; 1873 #ifndef OPENSSL_NO_DEPRECATED_3_0 1874 case OPT_ENGINES: 1875 todo.engines = 1; 1876 break; 1877 #endif 1878 case OPT_DISABLED: 1879 todo.disabled = 1; 1880 break; 1881 case OPT_OBJECTS: 1882 todo.objects = 1; 1883 break; 1884 case OPT_OPTIONS: 1885 list_options_for_command(opt_arg()); 1886 break; 1887 case OPT_VERBOSE: 1888 verbose = 1; 1889 break; 1890 case OPT_SELECT_NAME: 1891 select_name = opt_arg(); 1892 break; 1893 case OPT_PROV_CASES: 1894 if (!opt_provider(o)) 1895 return 1; 1896 break; 1897 } 1898 done = 1; 1899 } 1900 1901 /* No extra arguments. */ 1902 if (!opt_check_rest_arg(NULL)) 1903 goto opthelp; 1904 1905 #define MAYBE_ADD_NL(cmd) \ 1906 do { \ 1907 if (print_newline++) { \ 1908 BIO_printf(bio_out, "\n"); \ 1909 } \ 1910 cmd; \ 1911 } while (0) 1912 1913 if (todo.commands) 1914 MAYBE_ADD_NL(list_type(FT_general, one)); 1915 if (todo.all_algorithms) { 1916 MAYBE_ADD_NL({}); 1917 1918 BIO_printf(bio_out, "Digests:\n"); 1919 list_digests(" "); 1920 BIO_printf(bio_out, "\nSymmetric Ciphers:\n"); 1921 list_ciphers(" "); 1922 BIO_printf(bio_out, "\n"); 1923 list_kdfs(); 1924 BIO_printf(bio_out, "\n"); 1925 list_macs(); 1926 1927 BIO_printf(bio_out, "\nProvided Asymmetric Encryption:\n"); 1928 list_asymciphers(); 1929 BIO_printf(bio_out, "\nProvided Key Exchange:\n"); 1930 list_keyexchanges(); 1931 BIO_printf(bio_out, "\nProvided Signatures:\n"); 1932 list_signatures(); 1933 BIO_printf(bio_out, "\nProvided Key encapsulation:\n"); 1934 list_kems(); 1935 BIO_printf(bio_out, "\nProvided Key managers:\n"); 1936 list_keymanagers(); 1937 1938 BIO_printf(bio_out, "\n"); 1939 list_encoders(); 1940 BIO_printf(bio_out, "\n"); 1941 list_decoders(); 1942 BIO_printf(bio_out, "\n"); 1943 list_store_loaders(); 1944 } 1945 if (todo.random_instances) 1946 MAYBE_ADD_NL(list_random_instances()); 1947 if (todo.random_generators) 1948 MAYBE_ADD_NL(list_random_generators()); 1949 if (todo.digest_commands) 1950 MAYBE_ADD_NL(list_type(FT_md, one)); 1951 if (todo.digest_algorithms) 1952 MAYBE_ADD_NL(list_digests("")); 1953 if (todo.kdf_algorithms) 1954 MAYBE_ADD_NL(list_kdfs()); 1955 if (todo.mac_algorithms) 1956 MAYBE_ADD_NL(list_macs()); 1957 if (todo.cipher_commands) 1958 MAYBE_ADD_NL(list_type(FT_cipher, one)); 1959 if (todo.cipher_algorithms) 1960 MAYBE_ADD_NL(list_ciphers("")); 1961 if (todo.encoder_algorithms) 1962 MAYBE_ADD_NL(list_encoders()); 1963 if (todo.decoder_algorithms) 1964 MAYBE_ADD_NL(list_decoders()); 1965 if (todo.keymanager_algorithms) 1966 MAYBE_ADD_NL(list_keymanagers()); 1967 if (todo.skeymanager_algorithms) 1968 MAYBE_ADD_NL(list_skeymanagers()); 1969 if (todo.signature_algorithms) 1970 MAYBE_ADD_NL(list_signatures()); 1971 if (todo.tls_signature_algorithms) 1972 MAYBE_ADD_NL(list_tls_signatures()); 1973 if (todo.asym_cipher_algorithms) 1974 MAYBE_ADD_NL(list_asymciphers()); 1975 if (todo.keyexchange_algorithms) 1976 MAYBE_ADD_NL(list_keyexchanges()); 1977 if (todo.kem_algorithms) 1978 MAYBE_ADD_NL(list_kems()); 1979 #if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2) 1980 if (todo.tls_groups) 1981 MAYBE_ADD_NL(list_tls_groups(tls_version, all_tls_groups)); 1982 #endif 1983 if (todo.pk_algorithms) 1984 MAYBE_ADD_NL(list_pkey()); 1985 if (todo.pk_method) 1986 MAYBE_ADD_NL(list_pkey_meth()); 1987 if (todo.store_loaders) 1988 MAYBE_ADD_NL(list_store_loaders()); 1989 if (todo.provider_info) 1990 MAYBE_ADD_NL(list_provider_info()); 1991 #ifndef OPENSSL_NO_DEPRECATED_3_0 1992 if (todo.engines) 1993 MAYBE_ADD_NL(list_engines()); 1994 #endif 1995 if (todo.disabled) 1996 MAYBE_ADD_NL(list_disabled()); 1997 if (todo.objects) 1998 MAYBE_ADD_NL(list_objects()); 1999 2000 #undef MAYBE_ADD_NL 2001 2002 if (!done) 2003 goto opthelp; 2004 2005 return 0; 2006 } 2007