Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/openssl/apps/list.c
104186 views
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
sk_OPENSSL_CSTRING_free(names);
753
}
754
sk_EVP_SKEYMGMT_pop_free(km_stack, EVP_SKEYMGMT_free);
755
}
756
757
DEFINE_STACK_OF(EVP_SIGNATURE)
758
static int signature_cmp(const EVP_SIGNATURE *const *a,
759
const EVP_SIGNATURE *const *b)
760
{
761
return strcmp(OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*a)),
762
OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*b)));
763
}
764
765
static void collect_signatures(EVP_SIGNATURE *sig, void *stack)
766
{
767
STACK_OF(EVP_SIGNATURE) *sig_stack = stack;
768
769
if (is_signature_fetchable(sig)
770
&& EVP_SIGNATURE_up_ref(sig)
771
&& sk_EVP_SIGNATURE_push(sig_stack, sig) <= 0)
772
EVP_SIGNATURE_free(sig); /* up-ref successful but push to stack failed */
773
}
774
775
static void list_signatures(void)
776
{
777
int i, count = 0;
778
STACK_OF(EVP_SIGNATURE) *sig_stack = sk_EVP_SIGNATURE_new(signature_cmp);
779
780
EVP_SIGNATURE_do_all_provided(app_get0_libctx(), collect_signatures,
781
sig_stack);
782
sk_EVP_SIGNATURE_sort(sig_stack);
783
784
for (i = 0; i < sk_EVP_SIGNATURE_num(sig_stack); i++) {
785
EVP_SIGNATURE *k = sk_EVP_SIGNATURE_value(sig_stack, i);
786
STACK_OF(OPENSSL_CSTRING) *names = NULL;
787
788
if (select_name != NULL && !EVP_SIGNATURE_is_a(k, select_name))
789
continue;
790
791
names = sk_OPENSSL_CSTRING_new(name_cmp);
792
if (names != NULL && EVP_SIGNATURE_names_do_all(k, collect_names, names)) {
793
count++;
794
BIO_printf(bio_out, " ");
795
print_names(bio_out, names);
796
797
BIO_printf(bio_out, " @ %s\n",
798
OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(k)));
799
800
if (verbose) {
801
const char *desc = EVP_SIGNATURE_get0_description(k);
802
803
if (desc != NULL)
804
BIO_printf(bio_out, " description: %s\n", desc);
805
print_param_types("settable operation parameters",
806
EVP_SIGNATURE_settable_ctx_params(k), 4);
807
print_param_types("retrievable operation parameters",
808
EVP_SIGNATURE_gettable_ctx_params(k), 4);
809
}
810
}
811
sk_OPENSSL_CSTRING_free(names);
812
}
813
sk_EVP_SIGNATURE_pop_free(sig_stack, EVP_SIGNATURE_free);
814
if (count == 0)
815
BIO_printf(bio_out, " -\n");
816
}
817
818
static int list_provider_tls_sigalgs(const OSSL_PARAM params[], void *data)
819
{
820
const OSSL_PARAM *p;
821
822
/* Get registered IANA name */
823
p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_SIGALG_IANA_NAME);
824
if (p != NULL && p->data_type == OSSL_PARAM_UTF8_STRING) {
825
if (*((int *)data) > 0)
826
BIO_printf(bio_out, ":");
827
BIO_printf(bio_out, "%s", (char *)(p->data));
828
/* mark presence of a provider-based sigalg */
829
*((int *)data) = 2;
830
}
831
/* As built-in providers don't have this capability, never error */
832
return 1;
833
}
834
835
static int list_tls_sigalg_caps(OSSL_PROVIDER *provider, void *cbdata)
836
{
837
OSSL_PROVIDER_get_capabilities(provider, "TLS-SIGALG",
838
list_provider_tls_sigalgs,
839
cbdata);
840
/* As built-in providers don't have this capability, never error */
841
return 1;
842
}
843
844
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
845
static void list_tls_groups(int version, int all)
846
{
847
SSL_CTX *ctx = NULL;
848
STACK_OF(OPENSSL_CSTRING) *groups;
849
size_t i, num;
850
851
if ((groups = sk_OPENSSL_CSTRING_new_null()) == NULL) {
852
BIO_printf(bio_err, "ERROR: Memory allocation\n");
853
return;
854
}
855
if ((ctx = SSL_CTX_new(TLS_method())) == NULL) {
856
BIO_printf(bio_err, "ERROR: Memory allocation\n");
857
goto err;
858
}
859
if (!SSL_CTX_set_min_proto_version(ctx, version)
860
|| !SSL_CTX_set_max_proto_version(ctx, version)) {
861
BIO_printf(bio_err, "ERROR: setting TLS protocol version\n");
862
goto err;
863
}
864
if (!SSL_CTX_get0_implemented_groups(ctx, all, groups)) {
865
BIO_printf(bio_err, "ERROR: getting implemented TLS group list\n");
866
goto err;
867
}
868
num = sk_OPENSSL_CSTRING_num(groups);
869
for (i = 0; i < num; ++i) {
870
BIO_printf(bio_out, "%s%c", sk_OPENSSL_CSTRING_value(groups, i),
871
(i < num - 1) ? ':' : '\n');
872
}
873
err:
874
SSL_CTX_free(ctx);
875
sk_OPENSSL_CSTRING_free(groups);
876
return;
877
}
878
#endif
879
880
static void list_tls_signatures(void)
881
{
882
int tls_sigalg_listed = 0;
883
char *builtin_sigalgs = SSL_get1_builtin_sigalgs(app_get0_libctx());
884
885
if (builtin_sigalgs != NULL) {
886
if (builtin_sigalgs[0] != 0) {
887
BIO_printf(bio_out, "%s", builtin_sigalgs);
888
tls_sigalg_listed = 1;
889
}
890
OPENSSL_free(builtin_sigalgs);
891
}
892
893
if (!OSSL_PROVIDER_do_all(NULL, list_tls_sigalg_caps, &tls_sigalg_listed))
894
BIO_printf(bio_err,
895
"ERROR: could not list all provider signature algorithms\n");
896
if (tls_sigalg_listed < 2)
897
BIO_printf(bio_out,
898
"\nNo TLS sig algs registered by currently active providers");
899
BIO_printf(bio_out, "\n");
900
}
901
902
DEFINE_STACK_OF(EVP_KEM)
903
static int kem_cmp(const EVP_KEM *const *a,
904
const EVP_KEM *const *b)
905
{
906
return strcmp(OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*a)),
907
OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*b)));
908
}
909
910
static void collect_kem(EVP_KEM *kem, void *stack)
911
{
912
STACK_OF(EVP_KEM) *kem_stack = stack;
913
914
if (is_kem_fetchable(kem)
915
&& EVP_KEM_up_ref(kem)
916
&& sk_EVP_KEM_push(kem_stack, kem) <= 0)
917
EVP_KEM_free(kem); /* up-ref successful but push to stack failed */
918
}
919
920
static void list_kems(void)
921
{
922
int i, count = 0;
923
STACK_OF(EVP_KEM) *kem_stack = sk_EVP_KEM_new(kem_cmp);
924
925
EVP_KEM_do_all_provided(app_get0_libctx(), collect_kem, kem_stack);
926
sk_EVP_KEM_sort(kem_stack);
927
928
for (i = 0; i < sk_EVP_KEM_num(kem_stack); i++) {
929
EVP_KEM *k = sk_EVP_KEM_value(kem_stack, i);
930
STACK_OF(OPENSSL_CSTRING) *names = NULL;
931
932
if (select_name != NULL && !EVP_KEM_is_a(k, select_name))
933
continue;
934
935
names = sk_OPENSSL_CSTRING_new(name_cmp);
936
if (names != NULL && EVP_KEM_names_do_all(k, collect_names, names)) {
937
count++;
938
BIO_printf(bio_out, " ");
939
print_names(bio_out, names);
940
941
BIO_printf(bio_out, " @ %s\n",
942
OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(k)));
943
944
if (verbose) {
945
const char *desc = EVP_KEM_get0_description(k);
946
947
if (desc != NULL)
948
BIO_printf(bio_out, " description: %s\n", desc);
949
print_param_types("settable operation parameters",
950
EVP_KEM_settable_ctx_params(k), 4);
951
print_param_types("retrievable operation parameters",
952
EVP_KEM_gettable_ctx_params(k), 4);
953
}
954
}
955
sk_OPENSSL_CSTRING_free(names);
956
}
957
sk_EVP_KEM_pop_free(kem_stack, EVP_KEM_free);
958
if (count == 0)
959
BIO_printf(bio_out, " -\n");
960
}
961
962
DEFINE_STACK_OF(EVP_ASYM_CIPHER)
963
static int asymcipher_cmp(const EVP_ASYM_CIPHER *const *a,
964
const EVP_ASYM_CIPHER *const *b)
965
{
966
return strcmp(OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*a)),
967
OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*b)));
968
}
969
970
static void collect_asymciph(EVP_ASYM_CIPHER *asym_cipher, void *stack)
971
{
972
STACK_OF(EVP_ASYM_CIPHER) *asym_cipher_stack = stack;
973
974
if (is_asym_cipher_fetchable(asym_cipher)
975
&& EVP_ASYM_CIPHER_up_ref(asym_cipher)
976
&& sk_EVP_ASYM_CIPHER_push(asym_cipher_stack, asym_cipher) <= 0)
977
EVP_ASYM_CIPHER_free(asym_cipher); /* up-ref successful but push to stack failed */
978
}
979
980
static void list_asymciphers(void)
981
{
982
int i, count = 0;
983
STACK_OF(EVP_ASYM_CIPHER) *asymciph_stack = sk_EVP_ASYM_CIPHER_new(asymcipher_cmp);
984
985
EVP_ASYM_CIPHER_do_all_provided(app_get0_libctx(), collect_asymciph,
986
asymciph_stack);
987
sk_EVP_ASYM_CIPHER_sort(asymciph_stack);
988
989
for (i = 0; i < sk_EVP_ASYM_CIPHER_num(asymciph_stack); i++) {
990
EVP_ASYM_CIPHER *k = sk_EVP_ASYM_CIPHER_value(asymciph_stack, i);
991
STACK_OF(OPENSSL_CSTRING) *names = NULL;
992
993
if (select_name != NULL && !EVP_ASYM_CIPHER_is_a(k, select_name))
994
continue;
995
996
names = sk_OPENSSL_CSTRING_new(name_cmp);
997
if (names != NULL
998
&& EVP_ASYM_CIPHER_names_do_all(k, collect_names, names)) {
999
count++;
1000
BIO_printf(bio_out, " ");
1001
print_names(bio_out, names);
1002
1003
BIO_printf(bio_out, " @ %s\n",
1004
OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(k)));
1005
1006
if (verbose) {
1007
const char *desc = EVP_ASYM_CIPHER_get0_description(k);
1008
1009
if (desc != NULL)
1010
BIO_printf(bio_out, " description: %s\n", desc);
1011
print_param_types("settable operation parameters",
1012
EVP_ASYM_CIPHER_settable_ctx_params(k), 4);
1013
print_param_types("retrievable operation parameters",
1014
EVP_ASYM_CIPHER_gettable_ctx_params(k), 4);
1015
}
1016
}
1017
sk_OPENSSL_CSTRING_free(names);
1018
}
1019
sk_EVP_ASYM_CIPHER_pop_free(asymciph_stack, EVP_ASYM_CIPHER_free);
1020
if (count == 0)
1021
BIO_printf(bio_out, " -\n");
1022
}
1023
1024
DEFINE_STACK_OF(EVP_KEYEXCH)
1025
static int kex_cmp(const EVP_KEYEXCH *const *a,
1026
const EVP_KEYEXCH *const *b)
1027
{
1028
return strcmp(OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*a)),
1029
OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*b)));
1030
}
1031
1032
static void collect_kex(EVP_KEYEXCH *kex, void *stack)
1033
{
1034
STACK_OF(EVP_KEYEXCH) *kex_stack = stack;
1035
1036
if (is_keyexch_fetchable(kex)
1037
&& EVP_KEYEXCH_up_ref(kex)
1038
&& sk_EVP_KEYEXCH_push(kex_stack, kex) <= 0)
1039
EVP_KEYEXCH_free(kex); /* up-ref successful but push to stack failed */
1040
}
1041
1042
static void list_keyexchanges(void)
1043
{
1044
int i, count = 0;
1045
STACK_OF(EVP_KEYEXCH) *kex_stack = sk_EVP_KEYEXCH_new(kex_cmp);
1046
1047
EVP_KEYEXCH_do_all_provided(app_get0_libctx(), collect_kex, kex_stack);
1048
sk_EVP_KEYEXCH_sort(kex_stack);
1049
1050
for (i = 0; i < sk_EVP_KEYEXCH_num(kex_stack); i++) {
1051
EVP_KEYEXCH *k = sk_EVP_KEYEXCH_value(kex_stack, i);
1052
STACK_OF(OPENSSL_CSTRING) *names = NULL;
1053
1054
if (select_name != NULL && !EVP_KEYEXCH_is_a(k, select_name))
1055
continue;
1056
1057
names = sk_OPENSSL_CSTRING_new(name_cmp);
1058
if (names != NULL && EVP_KEYEXCH_names_do_all(k, collect_names, names)) {
1059
count++;
1060
BIO_printf(bio_out, " ");
1061
print_names(bio_out, names);
1062
1063
BIO_printf(bio_out, " @ %s\n",
1064
OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(k)));
1065
1066
if (verbose) {
1067
const char *desc = EVP_KEYEXCH_get0_description(k);
1068
1069
if (desc != NULL)
1070
BIO_printf(bio_out, " description: %s\n", desc);
1071
print_param_types("settable operation parameters",
1072
EVP_KEYEXCH_settable_ctx_params(k), 4);
1073
print_param_types("retrievable operation parameters",
1074
EVP_KEYEXCH_gettable_ctx_params(k), 4);
1075
}
1076
}
1077
sk_OPENSSL_CSTRING_free(names);
1078
}
1079
sk_EVP_KEYEXCH_pop_free(kex_stack, EVP_KEYEXCH_free);
1080
if (count == 0)
1081
BIO_printf(bio_out, " -\n");
1082
}
1083
1084
static void list_objects(void)
1085
{
1086
int max_nid = OBJ_new_nid(0);
1087
int i;
1088
char *oid_buf = NULL;
1089
int oid_size = 0;
1090
1091
/* Skip 0, since that's NID_undef */
1092
for (i = 1; i < max_nid; i++) {
1093
const ASN1_OBJECT *obj = OBJ_nid2obj(i);
1094
const char *sn = OBJ_nid2sn(i);
1095
const char *ln = OBJ_nid2ln(i);
1096
int n = 0;
1097
1098
/*
1099
* If one of the retrieved objects somehow generated an error,
1100
* we ignore it. The check for NID_undef below will detect the
1101
* error and simply skip to the next NID.
1102
*/
1103
ERR_clear_error();
1104
1105
if (OBJ_obj2nid(obj) == NID_undef)
1106
continue;
1107
1108
if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
1109
BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
1110
continue;
1111
}
1112
if (n < 0)
1113
break; /* Error */
1114
1115
if (n > oid_size) {
1116
oid_buf = OPENSSL_realloc(oid_buf, n + 1);
1117
if (oid_buf == NULL) {
1118
BIO_printf(bio_err, "ERROR: Memory allocation\n");
1119
break; /* Error */
1120
}
1121
oid_size = n + 1;
1122
}
1123
if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
1124
break; /* Error */
1125
if (ln == NULL || strcmp(sn, ln) == 0)
1126
BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
1127
else
1128
BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
1129
}
1130
1131
OPENSSL_free(oid_buf);
1132
}
1133
1134
static void list_options_for_command(const char *command)
1135
{
1136
const FUNCTION *fp;
1137
const OPTIONS *o;
1138
1139
for (fp = functions; fp->name != NULL; fp++)
1140
if (strcmp(fp->name, command) == 0)
1141
break;
1142
if (fp->name == NULL) {
1143
BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
1144
command);
1145
return;
1146
}
1147
1148
if ((o = fp->help) == NULL)
1149
return;
1150
1151
for (; o->name != NULL; o++) {
1152
char c = o->valtype;
1153
1154
if (o->name == OPT_PARAM_STR)
1155
break;
1156
1157
if (o->name == OPT_HELP_STR
1158
|| o->name == OPT_MORE_STR
1159
|| o->name == OPT_SECTION_STR
1160
|| o->name[0] == '\0')
1161
continue;
1162
BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
1163
}
1164
/* Always output the -- marker since it is sometimes documented. */
1165
BIO_printf(bio_out, "- -\n");
1166
}
1167
1168
static int is_md_available(const char *name)
1169
{
1170
EVP_MD *md;
1171
const char *propq = app_get0_propq();
1172
1173
/* Look through providers' digests */
1174
ERR_set_mark();
1175
md = EVP_MD_fetch(app_get0_libctx(), name, propq);
1176
ERR_pop_to_mark();
1177
if (md != NULL) {
1178
EVP_MD_free(md);
1179
return 1;
1180
}
1181
1182
return propq != NULL || get_digest_from_engine(name) == NULL ? 0 : 1;
1183
}
1184
1185
static int is_cipher_available(const char *name)
1186
{
1187
EVP_CIPHER *cipher;
1188
const char *propq = app_get0_propq();
1189
1190
/* Look through providers' ciphers */
1191
ERR_set_mark();
1192
cipher = EVP_CIPHER_fetch(app_get0_libctx(), name, propq);
1193
ERR_pop_to_mark();
1194
if (cipher != NULL) {
1195
EVP_CIPHER_free(cipher);
1196
return 1;
1197
}
1198
1199
return propq != NULL || get_cipher_from_engine(name) == NULL ? 0 : 1;
1200
}
1201
1202
static void list_type(FUNC_TYPE ft, int one)
1203
{
1204
FUNCTION *fp;
1205
int i = 0;
1206
DISPLAY_COLUMNS dc;
1207
1208
memset(&dc, 0, sizeof(dc));
1209
if (!one)
1210
calculate_columns(functions, &dc);
1211
1212
for (fp = functions; fp->name != NULL; fp++) {
1213
if (fp->type != ft)
1214
continue;
1215
switch (ft) {
1216
case FT_cipher:
1217
if (!is_cipher_available(fp->name))
1218
continue;
1219
break;
1220
case FT_md:
1221
if (!is_md_available(fp->name))
1222
continue;
1223
break;
1224
default:
1225
break;
1226
}
1227
if (one) {
1228
BIO_printf(bio_out, "%s\n", fp->name);
1229
} else {
1230
if (i % dc.columns == 0 && i > 0)
1231
BIO_printf(bio_out, "\n");
1232
BIO_printf(bio_out, "%-*s", dc.width, fp->name);
1233
i++;
1234
}
1235
}
1236
if (!one)
1237
BIO_printf(bio_out, "\n\n");
1238
}
1239
1240
static void list_pkey(void)
1241
{
1242
#ifndef OPENSSL_NO_DEPRECATED_3_0
1243
int i;
1244
1245
if (select_name == NULL && include_legacy()) {
1246
BIO_printf(bio_out, "Legacy:\n");
1247
for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
1248
const EVP_PKEY_ASN1_METHOD *ameth;
1249
int pkey_id, pkey_base_id, pkey_flags;
1250
const char *pinfo, *pem_str;
1251
ameth = EVP_PKEY_asn1_get0(i);
1252
EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
1253
&pinfo, &pem_str, ameth);
1254
if (pkey_flags & ASN1_PKEY_ALIAS) {
1255
BIO_printf(bio_out, " Name: %s\n", OBJ_nid2ln(pkey_id));
1256
BIO_printf(bio_out, "\tAlias for: %s\n",
1257
OBJ_nid2ln(pkey_base_id));
1258
} else {
1259
BIO_printf(bio_out, " Name: %s\n", pinfo);
1260
BIO_printf(bio_out, "\tType: %s Algorithm\n",
1261
pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
1262
BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
1263
if (pem_str == NULL)
1264
pem_str = "(none)";
1265
BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
1266
}
1267
}
1268
}
1269
#endif
1270
BIO_printf(bio_out, "Provided:\n");
1271
BIO_printf(bio_out, " Key Managers:\n");
1272
list_keymanagers();
1273
}
1274
1275
static void list_pkey_meth(void)
1276
{
1277
#ifndef OPENSSL_NO_DEPRECATED_3_0
1278
size_t i;
1279
size_t meth_count = EVP_PKEY_meth_get_count();
1280
1281
if (select_name == NULL && include_legacy()) {
1282
BIO_printf(bio_out, "Legacy:\n");
1283
for (i = 0; i < meth_count; i++) {
1284
const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
1285
int pkey_id, pkey_flags;
1286
1287
EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
1288
BIO_printf(bio_out, " %s\n", OBJ_nid2ln(pkey_id));
1289
BIO_printf(bio_out, "\tType: %s Algorithm\n",
1290
pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
1291
}
1292
}
1293
#endif
1294
BIO_printf(bio_out, "Provided:\n");
1295
BIO_printf(bio_out, " Encryption:\n");
1296
list_asymciphers();
1297
BIO_printf(bio_out, " Key Exchange:\n");
1298
list_keyexchanges();
1299
BIO_printf(bio_out, " Signatures:\n");
1300
list_signatures();
1301
BIO_printf(bio_out, " Key encapsulation:\n");
1302
list_kems();
1303
}
1304
1305
DEFINE_STACK_OF(OSSL_STORE_LOADER)
1306
static int store_cmp(const OSSL_STORE_LOADER *const *a,
1307
const OSSL_STORE_LOADER *const *b)
1308
{
1309
return strcmp(OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*a)),
1310
OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*b)));
1311
}
1312
1313
static void collect_store_loaders(OSSL_STORE_LOADER *store, void *stack)
1314
{
1315
STACK_OF(OSSL_STORE_LOADER) *store_stack = stack;
1316
1317
if (OSSL_STORE_LOADER_up_ref(store)
1318
&& sk_OSSL_STORE_LOADER_push(store_stack, store) <= 0)
1319
OSSL_STORE_LOADER_free(store); /* up-ref successful but push to stack failed */
1320
}
1321
1322
static void list_store_loaders(void)
1323
{
1324
STACK_OF(OSSL_STORE_LOADER) *stores = sk_OSSL_STORE_LOADER_new(store_cmp);
1325
int i;
1326
1327
if (stores == NULL) {
1328
BIO_printf(bio_err, "ERROR: Memory allocation\n");
1329
return;
1330
}
1331
BIO_printf(bio_out, "Provided STORE LOADERs:\n");
1332
OSSL_STORE_LOADER_do_all_provided(app_get0_libctx(), collect_store_loaders,
1333
stores);
1334
sk_OSSL_STORE_LOADER_sort(stores);
1335
for (i = 0; i < sk_OSSL_STORE_LOADER_num(stores); i++) {
1336
const OSSL_STORE_LOADER *m = sk_OSSL_STORE_LOADER_value(stores, i);
1337
STACK_OF(OPENSSL_CSTRING) *names = NULL;
1338
1339
if (select_name != NULL && !OSSL_STORE_LOADER_is_a(m, select_name))
1340
continue;
1341
1342
names = sk_OPENSSL_CSTRING_new(name_cmp);
1343
if (names != NULL && OSSL_STORE_LOADER_names_do_all(m, collect_names, names)) {
1344
BIO_printf(bio_out, " ");
1345
print_names(bio_out, names);
1346
1347
BIO_printf(bio_out, " @ %s\n",
1348
OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(m)));
1349
}
1350
sk_OPENSSL_CSTRING_free(names);
1351
}
1352
sk_OSSL_STORE_LOADER_pop_free(stores, OSSL_STORE_LOADER_free);
1353
}
1354
1355
DEFINE_STACK_OF(OSSL_PROVIDER)
1356
static int provider_cmp(const OSSL_PROVIDER *const *a,
1357
const OSSL_PROVIDER *const *b)
1358
{
1359
return strcmp(OSSL_PROVIDER_get0_name(*a), OSSL_PROVIDER_get0_name(*b));
1360
}
1361
1362
static int collect_providers(OSSL_PROVIDER *provider, void *stack)
1363
{
1364
STACK_OF(OSSL_PROVIDER) *provider_stack = stack;
1365
1366
/*
1367
* If OK - result is the index of inserted data
1368
* Error - result is -1 or 0
1369
*/
1370
return sk_OSSL_PROVIDER_push(provider_stack, provider) > 0 ? 1 : 0;
1371
}
1372
1373
static void list_provider_info(void)
1374
{
1375
STACK_OF(OSSL_PROVIDER) *providers = sk_OSSL_PROVIDER_new(provider_cmp);
1376
OSSL_PARAM params[5];
1377
char *name, *version, *buildinfo;
1378
int status;
1379
int i;
1380
1381
if (providers == NULL) {
1382
BIO_printf(bio_err, "ERROR: Memory allocation\n");
1383
return;
1384
}
1385
1386
if (OSSL_PROVIDER_do_all(NULL, &collect_providers, providers) != 1) {
1387
sk_OSSL_PROVIDER_free(providers);
1388
BIO_printf(bio_err, "ERROR: Memory allocation\n");
1389
return;
1390
}
1391
1392
BIO_printf(bio_out, "Providers:\n");
1393
sk_OSSL_PROVIDER_sort(providers);
1394
for (i = 0; i < sk_OSSL_PROVIDER_num(providers); i++) {
1395
const OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(providers, i);
1396
const char *provname = OSSL_PROVIDER_get0_name(prov);
1397
1398
BIO_printf(bio_out, " %s\n", provname);
1399
1400
/* Query the "known" information parameters, the order matches below */
1401
params[0] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_NAME,
1402
&name, 0);
1403
params[1] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION,
1404
&version, 0);
1405
params[2] = OSSL_PARAM_construct_int(OSSL_PROV_PARAM_STATUS, &status);
1406
params[3] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_BUILDINFO,
1407
&buildinfo, 0);
1408
params[4] = OSSL_PARAM_construct_end();
1409
OSSL_PARAM_set_all_unmodified(params);
1410
if (!OSSL_PROVIDER_get_params(prov, params)) {
1411
BIO_printf(bio_err,
1412
"WARNING: Unable to query provider parameters for %s\n",
1413
provname);
1414
} else {
1415
/* Print out the provider information, the params order matches above */
1416
if (OSSL_PARAM_modified(params))
1417
BIO_printf(bio_out, " name: %s\n", name);
1418
if (OSSL_PARAM_modified(params + 1))
1419
BIO_printf(bio_out, " version: %s\n", version);
1420
if (OSSL_PARAM_modified(params + 2))
1421
BIO_printf(bio_out, " status: %sactive\n", status ? "" : "in");
1422
if (verbose) {
1423
if (OSSL_PARAM_modified(params + 3))
1424
BIO_printf(bio_out, " build info: %s\n", buildinfo);
1425
print_param_types("gettable provider parameters",
1426
OSSL_PROVIDER_gettable_params(prov), 4);
1427
}
1428
}
1429
}
1430
sk_OSSL_PROVIDER_free(providers);
1431
}
1432
1433
#ifndef OPENSSL_NO_DEPRECATED_3_0
1434
static void list_engines(void)
1435
{
1436
#ifndef OPENSSL_NO_ENGINE
1437
ENGINE *e;
1438
1439
BIO_puts(bio_out, "Engines:\n");
1440
e = ENGINE_get_first();
1441
while (e) {
1442
BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
1443
e = ENGINE_get_next(e);
1444
}
1445
#else
1446
BIO_puts(bio_out, "Engine support is disabled.\n");
1447
#endif
1448
}
1449
#endif
1450
1451
static void list_disabled(void)
1452
{
1453
BIO_puts(bio_out, "Disabled algorithms:\n");
1454
#ifdef OPENSSL_NO_ARGON2
1455
BIO_puts(bio_out, "ARGON2\n");
1456
#endif
1457
#ifdef OPENSSL_NO_ARIA
1458
BIO_puts(bio_out, "ARIA\n");
1459
#endif
1460
#ifdef OPENSSL_NO_BF
1461
BIO_puts(bio_out, "BF\n");
1462
#endif
1463
#ifdef OPENSSL_NO_BLAKE2
1464
BIO_puts(bio_out, "BLAKE2\n");
1465
#endif
1466
#ifdef OPENSSL_NO_CAMELLIA
1467
BIO_puts(bio_out, "CAMELLIA\n");
1468
#endif
1469
#ifdef OPENSSL_NO_CAST
1470
BIO_puts(bio_out, "CAST\n");
1471
#endif
1472
#ifdef OPENSSL_NO_CMAC
1473
BIO_puts(bio_out, "CMAC\n");
1474
#endif
1475
#ifdef OPENSSL_NO_CMS
1476
BIO_puts(bio_out, "CMS\n");
1477
#endif
1478
#ifdef OPENSSL_NO_COMP
1479
BIO_puts(bio_out, "COMP\n");
1480
#endif
1481
#ifdef OPENSSL_NO_DES
1482
BIO_puts(bio_out, "DES\n");
1483
#endif
1484
#ifdef OPENSSL_NO_DGRAM
1485
BIO_puts(bio_out, "DGRAM\n");
1486
#endif
1487
#ifdef OPENSSL_NO_DH
1488
BIO_puts(bio_out, "DH\n");
1489
#endif
1490
#ifdef OPENSSL_NO_DSA
1491
BIO_puts(bio_out, "DSA\n");
1492
#endif
1493
#if defined(OPENSSL_NO_DTLS)
1494
BIO_puts(bio_out, "DTLS\n");
1495
#endif
1496
#if defined(OPENSSL_NO_DTLS1)
1497
BIO_puts(bio_out, "DTLS1\n");
1498
#endif
1499
#if defined(OPENSSL_NO_DTLS1_2)
1500
BIO_puts(bio_out, "DTLS1_2\n");
1501
#endif
1502
#ifdef OPENSSL_NO_EC
1503
BIO_puts(bio_out, "EC\n");
1504
#endif
1505
#ifdef OPENSSL_NO_ECX
1506
BIO_puts(bio_out, "ECX\n");
1507
#endif
1508
#ifdef OPENSSL_NO_EC2M
1509
BIO_puts(bio_out, "EC2M\n");
1510
#endif
1511
#if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1512
BIO_puts(bio_out, "ENGINE\n");
1513
#endif
1514
#ifdef OPENSSL_NO_GOST
1515
BIO_puts(bio_out, "GOST\n");
1516
#endif
1517
#ifdef OPENSSL_NO_IDEA
1518
BIO_puts(bio_out, "IDEA\n");
1519
#endif
1520
#ifdef OPENSSL_NO_MD2
1521
BIO_puts(bio_out, "MD2\n");
1522
#endif
1523
#ifdef OPENSSL_NO_MD4
1524
BIO_puts(bio_out, "MD4\n");
1525
#endif
1526
#ifdef OPENSSL_NO_MD5
1527
BIO_puts(bio_out, "MD5\n");
1528
#endif
1529
#ifdef OPENSSL_NO_MDC2
1530
BIO_puts(bio_out, "MDC2\n");
1531
#endif
1532
#ifdef OPENSSL_NO_OCB
1533
BIO_puts(bio_out, "OCB\n");
1534
#endif
1535
#ifdef OPENSSL_NO_OCSP
1536
BIO_puts(bio_out, "OCSP\n");
1537
#endif
1538
#ifdef OPENSSL_NO_PSK
1539
BIO_puts(bio_out, "PSK\n");
1540
#endif
1541
#ifdef OPENSSL_NO_RC2
1542
BIO_puts(bio_out, "RC2\n");
1543
#endif
1544
#ifdef OPENSSL_NO_RC4
1545
BIO_puts(bio_out, "RC4\n");
1546
#endif
1547
#ifdef OPENSSL_NO_RC5
1548
BIO_puts(bio_out, "RC5\n");
1549
#endif
1550
#ifdef OPENSSL_NO_RMD160
1551
BIO_puts(bio_out, "RMD160\n");
1552
#endif
1553
#ifdef OPENSSL_NO_SCRYPT
1554
BIO_puts(bio_out, "SCRYPT\n");
1555
#endif
1556
#ifdef OPENSSL_NO_SCTP
1557
BIO_puts(bio_out, "SCTP\n");
1558
#endif
1559
#ifdef OPENSSL_NO_SEED
1560
BIO_puts(bio_out, "SEED\n");
1561
#endif
1562
#ifdef OPENSSL_NO_SM2
1563
BIO_puts(bio_out, "SM2\n");
1564
#endif
1565
#ifdef OPENSSL_NO_SM3
1566
BIO_puts(bio_out, "SM3\n");
1567
#endif
1568
#ifdef OPENSSL_NO_SM4
1569
BIO_puts(bio_out, "SM4\n");
1570
#endif
1571
#ifdef OPENSSL_NO_SOCK
1572
BIO_puts(bio_out, "SOCK\n");
1573
#endif
1574
#ifdef OPENSSL_NO_SRP
1575
BIO_puts(bio_out, "SRP\n");
1576
#endif
1577
#ifdef OPENSSL_NO_SRTP
1578
BIO_puts(bio_out, "SRTP\n");
1579
#endif
1580
#ifdef OPENSSL_NO_SSL3
1581
BIO_puts(bio_out, "SSL3\n");
1582
#endif
1583
#ifdef OPENSSL_NO_TLS1
1584
BIO_puts(bio_out, "TLS1\n");
1585
#endif
1586
#ifdef OPENSSL_NO_TLS1_1
1587
BIO_puts(bio_out, "TLS1_1\n");
1588
#endif
1589
#ifdef OPENSSL_NO_TLS1_2
1590
BIO_puts(bio_out, "TLS1_2\n");
1591
#endif
1592
#ifdef OPENSSL_NO_WHIRLPOOL
1593
BIO_puts(bio_out, "WHIRLPOOL\n");
1594
#endif
1595
#ifdef OPENSSL_NO_ZLIB
1596
BIO_puts(bio_out, "ZLIB\n");
1597
#endif
1598
#ifdef OPENSSL_NO_BROTLI
1599
BIO_puts(bio_out, "BROTLI\n");
1600
#endif
1601
#ifdef OPENSSL_NO_ZSTD
1602
BIO_puts(bio_out, "ZSTD\n");
1603
#endif
1604
}
1605
1606
/* Unified enum for help and list commands. */
1607
typedef enum HELPLIST_CHOICE {
1608
OPT_COMMON,
1609
OPT_ONE,
1610
OPT_VERBOSE,
1611
OPT_ALL_ARGORITHMS,
1612
OPT_COMMANDS,
1613
OPT_DIGEST_COMMANDS,
1614
OPT_MAC_ALGORITHMS,
1615
OPT_OPTIONS,
1616
OPT_DIGEST_ALGORITHMS,
1617
OPT_CIPHER_COMMANDS,
1618
OPT_CIPHER_ALGORITHMS,
1619
OPT_PK_ALGORITHMS,
1620
OPT_PK_METHOD,
1621
OPT_DISABLED,
1622
OPT_KDF_ALGORITHMS,
1623
OPT_RANDOM_INSTANCES,
1624
OPT_RANDOM_GENERATORS,
1625
OPT_ENCODERS,
1626
OPT_DECODERS,
1627
OPT_KEYMANAGERS,
1628
OPT_KEYEXCHANGE_ALGORITHMS,
1629
OPT_SKEYMANAGERS,
1630
OPT_KEM_ALGORITHMS,
1631
OPT_SIGNATURE_ALGORITHMS,
1632
OPT_TLS_SIGNATURE_ALGORITHMS,
1633
OPT_ASYM_CIPHER_ALGORITHMS,
1634
OPT_STORE_LOADERS,
1635
OPT_PROVIDER_INFO,
1636
OPT_OBJECTS,
1637
OPT_SELECT_NAME,
1638
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1639
OPT_ALL_TLS_GROUPS,
1640
OPT_TLS_GROUPS,
1641
#if !defined(OPENSSL_NO_TLS1_2)
1642
OPT_TLS1_2,
1643
#endif
1644
#if !defined(OPENSSL_NO_TLS1_3)
1645
OPT_TLS1_3,
1646
#endif
1647
#endif
1648
#ifndef OPENSSL_NO_DEPRECATED_3_0
1649
OPT_ENGINES,
1650
#endif
1651
OPT_PROV_ENUM
1652
} HELPLIST_CHOICE;
1653
1654
const OPTIONS list_options[] = {
1655
1656
OPT_SECTION("General"),
1657
{ "help", OPT_HELP, '-', "Display this summary" },
1658
1659
OPT_SECTION("Output"),
1660
{ "1", OPT_ONE, '-', "List in one column" },
1661
{ "verbose", OPT_VERBOSE, '-', "Verbose listing" },
1662
{ "select", OPT_SELECT_NAME, 's', "Select a single algorithm" },
1663
{ "commands", OPT_COMMANDS, '-', "List of standard commands" },
1664
{ "standard-commands", OPT_COMMANDS, '-', "List of standard commands" },
1665
{ "all-algorithms", OPT_ALL_ARGORITHMS, '-', "List of all algorithms" },
1666
#ifndef OPENSSL_NO_DEPRECATED_3_0
1667
{ "digest-commands", OPT_DIGEST_COMMANDS, '-',
1668
"List of message digest commands (deprecated)" },
1669
#endif
1670
{ "digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
1671
"List of message digest algorithms" },
1672
{ "kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
1673
"List of key derivation and pseudo random function algorithms" },
1674
{ "random-instances", OPT_RANDOM_INSTANCES, '-',
1675
"List the primary, public and private random number generator details" },
1676
{ "random-generators", OPT_RANDOM_GENERATORS, '-',
1677
"List of random number generators" },
1678
{ "mac-algorithms", OPT_MAC_ALGORITHMS, '-',
1679
"List of message authentication code algorithms" },
1680
#ifndef OPENSSL_NO_DEPRECATED_3_0
1681
{ "cipher-commands", OPT_CIPHER_COMMANDS, '-',
1682
"List of cipher commands (deprecated)" },
1683
#endif
1684
{ "cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
1685
"List of symmetric cipher algorithms" },
1686
{ "encoders", OPT_ENCODERS, '-', "List of encoding methods" },
1687
{ "decoders", OPT_DECODERS, '-', "List of decoding methods" },
1688
{ "key-managers", OPT_KEYMANAGERS, '-', "List of key managers" },
1689
{ "skey-managers", OPT_SKEYMANAGERS, '-', "List of symmetric key managers" },
1690
{ "key-exchange-algorithms", OPT_KEYEXCHANGE_ALGORITHMS, '-',
1691
"List of key exchange algorithms" },
1692
{ "kem-algorithms", OPT_KEM_ALGORITHMS, '-',
1693
"List of key encapsulation mechanism algorithms" },
1694
{ "signature-algorithms", OPT_SIGNATURE_ALGORITHMS, '-',
1695
"List of signature algorithms" },
1696
{ "tls-signature-algorithms", OPT_TLS_SIGNATURE_ALGORITHMS, '-',
1697
"List of TLS signature algorithms" },
1698
{ "asymcipher-algorithms", OPT_ASYM_CIPHER_ALGORITHMS, '-',
1699
"List of asymmetric cipher algorithms" },
1700
{ "public-key-algorithms", OPT_PK_ALGORITHMS, '-',
1701
"List of public key algorithms" },
1702
{ "public-key-methods", OPT_PK_METHOD, '-',
1703
"List of public key methods" },
1704
{ "store-loaders", OPT_STORE_LOADERS, '-',
1705
"List of store loaders" },
1706
#if !defined(OPENSSL_NO_TLS1_2) || !defined(OPENSSL_NO_TLS1_3)
1707
{ "tls-groups", OPT_TLS_GROUPS, '-',
1708
"List implemented TLS key exchange 'groups'" },
1709
{ "all-tls-groups", OPT_ALL_TLS_GROUPS, '-',
1710
"List implemented TLS key exchange 'groups' and all aliases" },
1711
#ifndef OPENSSL_NO_TLS1_2
1712
{ "tls1_2", OPT_TLS1_2, '-',
1713
"When listing 'groups', list those compatible with TLS1.2" },
1714
#endif
1715
#ifndef OPENSSL_NO_TLS1_3
1716
{ "tls1_3", OPT_TLS1_3, '-',
1717
"When listing 'groups', list those compatible with TLS1.3" },
1718
#endif
1719
#endif
1720
{ "providers", OPT_PROVIDER_INFO, '-',
1721
"List of provider information" },
1722
#ifndef OPENSSL_NO_DEPRECATED_3_0
1723
{ "engines", OPT_ENGINES, '-',
1724
"List of loaded engines" },
1725
#endif
1726
{ "disabled", OPT_DISABLED, '-', "List of disabled features" },
1727
{ "options", OPT_OPTIONS, 's',
1728
"List options for specified command" },
1729
{ "objects", OPT_OBJECTS, '-',
1730
"List built in objects (OID<->name mappings)" },
1731
1732
OPT_PROV_OPTIONS,
1733
{ NULL }
1734
};
1735
1736
int list_main(int argc, char **argv)
1737
{
1738
char *prog;
1739
HELPLIST_CHOICE o;
1740
int one = 0, done = 0;
1741
int print_newline = 0;
1742
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1743
int all_tls_groups = 0;
1744
#if !defined(OPENSSL_NO_TLS1_3)
1745
unsigned int tls_version = TLS1_3_VERSION;
1746
#else
1747
unsigned int tls_version = TLS1_2_VERSION;
1748
#endif
1749
#endif
1750
struct {
1751
unsigned int commands : 1;
1752
unsigned int all_algorithms : 1;
1753
unsigned int random_instances : 1;
1754
unsigned int random_generators : 1;
1755
unsigned int digest_commands : 1;
1756
unsigned int digest_algorithms : 1;
1757
unsigned int kdf_algorithms : 1;
1758
unsigned int mac_algorithms : 1;
1759
unsigned int cipher_commands : 1;
1760
unsigned int cipher_algorithms : 1;
1761
unsigned int encoder_algorithms : 1;
1762
unsigned int decoder_algorithms : 1;
1763
unsigned int keymanager_algorithms : 1;
1764
unsigned int skeymanager_algorithms : 1;
1765
unsigned int signature_algorithms : 1;
1766
unsigned int tls_signature_algorithms : 1;
1767
unsigned int keyexchange_algorithms : 1;
1768
unsigned int kem_algorithms : 1;
1769
unsigned int tls_groups : 1;
1770
unsigned int asym_cipher_algorithms : 1;
1771
unsigned int pk_algorithms : 1;
1772
unsigned int pk_method : 1;
1773
unsigned int store_loaders : 1;
1774
unsigned int provider_info : 1;
1775
#ifndef OPENSSL_NO_DEPRECATED_3_0
1776
unsigned int engines : 1;
1777
#endif
1778
unsigned int disabled : 1;
1779
unsigned int objects : 1;
1780
unsigned int options : 1;
1781
} todo = {
1782
0,
1783
};
1784
1785
verbose = 0; /* Clear a possible previous call */
1786
1787
prog = opt_init(argc, argv, list_options);
1788
while ((o = opt_next()) != OPT_EOF) {
1789
switch (o) {
1790
case OPT_EOF: /* Never hit, but suppresses warning */
1791
case OPT_ERR:
1792
opthelp:
1793
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1794
return 1;
1795
case OPT_HELP:
1796
opt_help(list_options);
1797
return 0;
1798
case OPT_ONE:
1799
one = 1;
1800
break;
1801
case OPT_ALL_ARGORITHMS:
1802
todo.all_algorithms = 1;
1803
break;
1804
case OPT_COMMANDS:
1805
todo.commands = 1;
1806
break;
1807
case OPT_DIGEST_COMMANDS:
1808
todo.digest_commands = 1;
1809
break;
1810
case OPT_DIGEST_ALGORITHMS:
1811
todo.digest_algorithms = 1;
1812
break;
1813
case OPT_KDF_ALGORITHMS:
1814
todo.kdf_algorithms = 1;
1815
break;
1816
case OPT_RANDOM_INSTANCES:
1817
todo.random_instances = 1;
1818
break;
1819
case OPT_RANDOM_GENERATORS:
1820
todo.random_generators = 1;
1821
break;
1822
case OPT_MAC_ALGORITHMS:
1823
todo.mac_algorithms = 1;
1824
break;
1825
case OPT_CIPHER_COMMANDS:
1826
todo.cipher_commands = 1;
1827
break;
1828
case OPT_CIPHER_ALGORITHMS:
1829
todo.cipher_algorithms = 1;
1830
break;
1831
case OPT_ENCODERS:
1832
todo.encoder_algorithms = 1;
1833
break;
1834
case OPT_DECODERS:
1835
todo.decoder_algorithms = 1;
1836
break;
1837
case OPT_KEYMANAGERS:
1838
todo.keymanager_algorithms = 1;
1839
break;
1840
case OPT_SKEYMANAGERS:
1841
todo.skeymanager_algorithms = 1;
1842
break;
1843
case OPT_SIGNATURE_ALGORITHMS:
1844
todo.signature_algorithms = 1;
1845
break;
1846
case OPT_TLS_SIGNATURE_ALGORITHMS:
1847
todo.tls_signature_algorithms = 1;
1848
break;
1849
case OPT_KEYEXCHANGE_ALGORITHMS:
1850
todo.keyexchange_algorithms = 1;
1851
break;
1852
case OPT_KEM_ALGORITHMS:
1853
todo.kem_algorithms = 1;
1854
break;
1855
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1856
case OPT_TLS_GROUPS:
1857
todo.tls_groups = 1;
1858
break;
1859
case OPT_ALL_TLS_GROUPS:
1860
all_tls_groups = 1;
1861
todo.tls_groups = 1;
1862
break;
1863
#if !defined(OPENSSL_NO_TLS1_2)
1864
case OPT_TLS1_2:
1865
tls_version = TLS1_2_VERSION;
1866
break;
1867
#endif
1868
#if !defined(OPENSSL_NO_TLS1_3)
1869
case OPT_TLS1_3:
1870
tls_version = TLS1_3_VERSION;
1871
break;
1872
#endif
1873
#endif
1874
case OPT_ASYM_CIPHER_ALGORITHMS:
1875
todo.asym_cipher_algorithms = 1;
1876
break;
1877
case OPT_PK_ALGORITHMS:
1878
todo.pk_algorithms = 1;
1879
break;
1880
case OPT_PK_METHOD:
1881
todo.pk_method = 1;
1882
break;
1883
case OPT_STORE_LOADERS:
1884
todo.store_loaders = 1;
1885
break;
1886
case OPT_PROVIDER_INFO:
1887
todo.provider_info = 1;
1888
break;
1889
#ifndef OPENSSL_NO_DEPRECATED_3_0
1890
case OPT_ENGINES:
1891
todo.engines = 1;
1892
break;
1893
#endif
1894
case OPT_DISABLED:
1895
todo.disabled = 1;
1896
break;
1897
case OPT_OBJECTS:
1898
todo.objects = 1;
1899
break;
1900
case OPT_OPTIONS:
1901
list_options_for_command(opt_arg());
1902
break;
1903
case OPT_VERBOSE:
1904
verbose = 1;
1905
break;
1906
case OPT_SELECT_NAME:
1907
select_name = opt_arg();
1908
break;
1909
case OPT_PROV_CASES:
1910
if (!opt_provider(o))
1911
return 1;
1912
break;
1913
}
1914
done = 1;
1915
}
1916
1917
/* No extra arguments. */
1918
if (!opt_check_rest_arg(NULL))
1919
goto opthelp;
1920
1921
#define MAYBE_ADD_NL(cmd) \
1922
do { \
1923
if (print_newline++) { \
1924
BIO_printf(bio_out, "\n"); \
1925
} \
1926
cmd; \
1927
} while (0)
1928
1929
if (todo.commands)
1930
MAYBE_ADD_NL(list_type(FT_general, one));
1931
if (todo.all_algorithms) {
1932
MAYBE_ADD_NL({});
1933
1934
BIO_printf(bio_out, "Digests:\n");
1935
list_digests(" ");
1936
BIO_printf(bio_out, "\nSymmetric Ciphers:\n");
1937
list_ciphers(" ");
1938
BIO_printf(bio_out, "\n");
1939
list_kdfs();
1940
BIO_printf(bio_out, "\n");
1941
list_macs();
1942
1943
BIO_printf(bio_out, "\nProvided Asymmetric Encryption:\n");
1944
list_asymciphers();
1945
BIO_printf(bio_out, "\nProvided Key Exchange:\n");
1946
list_keyexchanges();
1947
BIO_printf(bio_out, "\nProvided Signatures:\n");
1948
list_signatures();
1949
BIO_printf(bio_out, "\nProvided Key encapsulation:\n");
1950
list_kems();
1951
BIO_printf(bio_out, "\nProvided Key managers:\n");
1952
list_keymanagers();
1953
1954
BIO_printf(bio_out, "\n");
1955
list_encoders();
1956
BIO_printf(bio_out, "\n");
1957
list_decoders();
1958
BIO_printf(bio_out, "\n");
1959
list_store_loaders();
1960
}
1961
if (todo.random_instances)
1962
MAYBE_ADD_NL(list_random_instances());
1963
if (todo.random_generators)
1964
MAYBE_ADD_NL(list_random_generators());
1965
if (todo.digest_commands)
1966
MAYBE_ADD_NL(list_type(FT_md, one));
1967
if (todo.digest_algorithms)
1968
MAYBE_ADD_NL(list_digests(""));
1969
if (todo.kdf_algorithms)
1970
MAYBE_ADD_NL(list_kdfs());
1971
if (todo.mac_algorithms)
1972
MAYBE_ADD_NL(list_macs());
1973
if (todo.cipher_commands)
1974
MAYBE_ADD_NL(list_type(FT_cipher, one));
1975
if (todo.cipher_algorithms)
1976
MAYBE_ADD_NL(list_ciphers(""));
1977
if (todo.encoder_algorithms)
1978
MAYBE_ADD_NL(list_encoders());
1979
if (todo.decoder_algorithms)
1980
MAYBE_ADD_NL(list_decoders());
1981
if (todo.keymanager_algorithms)
1982
MAYBE_ADD_NL(list_keymanagers());
1983
if (todo.skeymanager_algorithms)
1984
MAYBE_ADD_NL(list_skeymanagers());
1985
if (todo.signature_algorithms)
1986
MAYBE_ADD_NL(list_signatures());
1987
if (todo.tls_signature_algorithms)
1988
MAYBE_ADD_NL(list_tls_signatures());
1989
if (todo.asym_cipher_algorithms)
1990
MAYBE_ADD_NL(list_asymciphers());
1991
if (todo.keyexchange_algorithms)
1992
MAYBE_ADD_NL(list_keyexchanges());
1993
if (todo.kem_algorithms)
1994
MAYBE_ADD_NL(list_kems());
1995
#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
1996
if (todo.tls_groups)
1997
MAYBE_ADD_NL(list_tls_groups(tls_version, all_tls_groups));
1998
#endif
1999
if (todo.pk_algorithms)
2000
MAYBE_ADD_NL(list_pkey());
2001
if (todo.pk_method)
2002
MAYBE_ADD_NL(list_pkey_meth());
2003
if (todo.store_loaders)
2004
MAYBE_ADD_NL(list_store_loaders());
2005
if (todo.provider_info)
2006
MAYBE_ADD_NL(list_provider_info());
2007
#ifndef OPENSSL_NO_DEPRECATED_3_0
2008
if (todo.engines)
2009
MAYBE_ADD_NL(list_engines());
2010
#endif
2011
if (todo.disabled)
2012
MAYBE_ADD_NL(list_disabled());
2013
if (todo.objects)
2014
MAYBE_ADD_NL(list_objects());
2015
2016
#undef MAYBE_ADD_NL
2017
2018
if (!done)
2019
goto opthelp;
2020
2021
return 0;
2022
}
2023
2024