]>
Commit | Line | Data |
---|---|---|
846e33c7 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
3ac82faa | 3 | * |
846e33c7 RS |
4 | * Licensed under the OpenSSL license (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 | |
3ac82faa BM |
8 | */ |
9 | ||
d02b48c6 RE |
10 | #include <stdio.h> |
11 | #include <string.h> | |
12 | #include <stdlib.h> | |
ec577822 BM |
13 | #include <openssl/bio.h> |
14 | #include <openssl/crypto.h> | |
15 | #include <openssl/lhash.h> | |
16 | #include <openssl/conf.h> | |
17 | #include <openssl/x509.h> | |
18 | #include <openssl/pem.h> | |
19 | #include <openssl/ssl.h> | |
0b13e9f0 | 20 | #ifndef OPENSSL_NO_ENGINE |
0f113f3e | 21 | # include <openssl/engine.h> |
0b13e9f0 | 22 | #endif |
ec577822 | 23 | #include <openssl/err.h> |
856650de | 24 | #ifdef OPENSSL_FIPS |
0f113f3e | 25 | # include <openssl/fips.h> |
856650de | 26 | #endif |
3b061a00 RS |
27 | #define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */ |
28 | #include "s_apps.h" | |
29 | /* Needed to get the other O_xxx flags. */ | |
30 | #ifdef OPENSSL_SYS_VMS | |
31 | # include <unixio.h> | |
32 | #endif | |
1e7e1c8d | 33 | #define INCLUDE_FUNCTION_TABLE |
7e1b7485 RS |
34 | #include "apps.h" |
35 | ||
7e1b7485 RS |
36 | |
37 | #ifdef OPENSSL_NO_CAMELLIA | |
38 | # define FORMAT "%-15s" | |
39 | # define COLUMNS 5 | |
40 | #else | |
41 | # define FORMAT "%-18s" | |
42 | # define COLUMNS 4 | |
43 | #endif | |
44 | ||
45 | /* Special sentinel to exit the program. */ | |
46 | #define EXIT_THE_PROGRAM (-1) | |
d02b48c6 | 47 | |
0f113f3e MC |
48 | /* |
49 | * The LHASH callbacks ("hash" & "cmp") have been replaced by functions with | |
50 | * the base prototypes (we cast each variable inside the function to the | |
51 | * required type of "FUNCTION*"). This removes the necessity for | |
52 | * macro-generated wrapper functions. | |
53 | */ | |
0f113f3e MC |
54 | static LHASH_OF(FUNCTION) *prog_init(void); |
55 | static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]); | |
2f58faad RS |
56 | static void list_pkey(void); |
57 | static void list_type(FUNC_TYPE ft); | |
a760a380 | 58 | static void list_disabled(void); |
0f113f3e | 59 | char *default_config_file = NULL; |
d02b48c6 | 60 | |
df2ee0e2 | 61 | static CONF *config = NULL; |
7e1b7485 RS |
62 | BIO *bio_in = NULL; |
63 | BIO *bio_out = NULL; | |
0f113f3e | 64 | BIO *bio_err = NULL; |
7e1b7485 | 65 | |
a0a82324 | 66 | static int apps_startup() |
7e1b7485 RS |
67 | { |
68 | #ifdef SIGPIPE | |
69 | signal(SIGPIPE, SIG_IGN); | |
70 | #endif | |
a0a82324 | 71 | |
b9f75707 | 72 | /* Set non-default library initialisation settings */ |
0fc32b07 MC |
73 | if (!OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN |
74 | | OPENSSL_INIT_LOAD_CONFIG, NULL)) | |
75 | return 0; | |
a0a82324 | 76 | |
923b1857 | 77 | #ifndef OPENSSL_NO_UI |
7e1b7485 | 78 | setup_ui_method(); |
923b1857 | 79 | #endif |
b9f75707 | 80 | |
a0a82324 | 81 | return 1; |
7e1b7485 RS |
82 | } |
83 | ||
84 | static void apps_shutdown() | |
85 | { | |
923b1857 | 86 | #ifndef OPENSSL_NO_UI |
7e1b7485 | 87 | destroy_ui_method(); |
923b1857 | 88 | #endif |
7e1b7485 RS |
89 | } |
90 | ||
91 | static char *make_config_name() | |
92 | { | |
cc01d217 | 93 | const char *t; |
7e1b7485 RS |
94 | size_t len; |
95 | char *p; | |
96 | ||
b0700d2c | 97 | if ((t = getenv("OPENSSL_CONF")) != NULL) |
7644a9ae | 98 | return OPENSSL_strdup(t); |
cc01d217 RS |
99 | |
100 | t = X509_get_default_cert_area(); | |
101 | len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1; | |
68dc6824 | 102 | p = app_malloc(len, "config filename buffer"); |
cc01d217 | 103 | strcpy(p, t); |
7e1b7485 | 104 | #ifndef OPENSSL_SYS_VMS |
cc01d217 | 105 | strcat(p, "/"); |
d02b48c6 | 106 | #endif |
cc01d217 | 107 | strcat(p, OPENSSL_CONF); |
7e1b7485 RS |
108 | |
109 | return p; | |
110 | } | |
111 | ||
7e1b7485 | 112 | int main(int argc, char *argv[]) |
0f113f3e | 113 | { |
0f113f3e | 114 | FUNCTION f, *fp; |
0f113f3e | 115 | LHASH_OF(FUNCTION) *prog = NULL; |
7e1b7485 | 116 | char **copied_argv = NULL; |
cc01d217 | 117 | char *p, *pname; |
7e1b7485 RS |
118 | char buf[1024]; |
119 | const char *prompt; | |
120 | ARGS arg; | |
121 | int first, n, i, ret = 0; | |
8ecef24a | 122 | |
7e1b7485 RS |
123 | arg.argv = NULL; |
124 | arg.size = 0; | |
125 | ||
7768e116 RS |
126 | /* Set up some of the environment. */ |
127 | default_config_file = make_config_name(); | |
a60994df RL |
128 | bio_in = dup_bio_in(FORMAT_TEXT); |
129 | bio_out = dup_bio_out(FORMAT_TEXT); | |
149bd5d6 | 130 | bio_err = dup_bio_err(FORMAT_TEXT); |
7768e116 | 131 | |
368058d0 RL |
132 | #if defined(OPENSSL_SYS_VMS) && defined(__DECC) |
133 | copied_argv = argv = copy_argv(&argc, argv); | |
7e1b7485 RS |
134 | #endif |
135 | ||
136 | p = getenv("OPENSSL_DEBUG_MEMORY"); | |
bbd86bf5 RS |
137 | if (p != NULL && strcmp(p, "on") == 0) |
138 | CRYPTO_set_mem_debug(1); | |
0f113f3e | 139 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); |
3ac82faa | 140 | |
0f113f3e | 141 | if (getenv("OPENSSL_FIPS")) { |
856650de | 142 | #ifdef OPENSSL_FIPS |
0f113f3e | 143 | if (!FIPS_mode_set(1)) { |
7768e116 RS |
144 | ERR_print_errors(bio_err); |
145 | return 1; | |
0f113f3e | 146 | } |
856650de | 147 | #else |
7768e116 RS |
148 | BIO_printf(bio_err, "FIPS mode not supported.\n"); |
149 | return 1; | |
856650de | 150 | #endif |
0f113f3e MC |
151 | } |
152 | ||
a0a82324 MC |
153 | if (!apps_startup()) |
154 | goto end; | |
155 | ||
7e1b7485 | 156 | prog = prog_init(); |
368058d0 | 157 | pname = opt_progname(argv[0]); |
0f113f3e | 158 | |
0f113f3e | 159 | /* first check the program name */ |
0f113f3e MC |
160 | f.name = pname; |
161 | fp = lh_FUNCTION_retrieve(prog, &f); | |
162 | if (fp != NULL) { | |
368058d0 RL |
163 | argv[0] = pname; |
164 | ret = fp->func(argc, argv); | |
0f113f3e MC |
165 | goto end; |
166 | } | |
167 | ||
7e1b7485 RS |
168 | /* If there is stuff on the command line, run with that. */ |
169 | if (argc != 1) { | |
170 | argc--; | |
368058d0 RL |
171 | argv++; |
172 | ret = do_cmd(prog, argc, argv); | |
0f113f3e MC |
173 | if (ret < 0) |
174 | ret = 0; | |
175 | goto end; | |
176 | } | |
177 | ||
7e1b7485 | 178 | /* ok, lets enter interactive mode */ |
0f113f3e MC |
179 | for (;;) { |
180 | ret = 0; | |
57d5edad RS |
181 | /* Read a line, continue reading if line ends with \ */ |
182 | for (p = buf, n = sizeof buf, i = 0, first = 1; n > 0; first = 0) { | |
1c9c2435 | 183 | prompt = first ? "OpenSSL> " : "> "; |
0f113f3e | 184 | p[0] = '\0'; |
57d5edad | 185 | #ifndef READLINE |
0f113f3e MC |
186 | fputs(prompt, stdout); |
187 | fflush(stdout); | |
188 | if (!fgets(p, n, stdin)) | |
189 | goto end; | |
190 | if (p[0] == '\0') | |
191 | goto end; | |
192 | i = strlen(p); | |
193 | if (i <= 1) | |
194 | break; | |
195 | if (p[i - 2] != '\\') | |
196 | break; | |
197 | i -= 2; | |
198 | p += i; | |
199 | n -= i; | |
57d5edad RS |
200 | #else |
201 | { | |
202 | extern char *readline(const char *); | |
203 | extern void add_history(const char *cp); | |
204 | char *text; | |
205 | ||
72106aaa | 206 | text = readline(prompt); |
57d5edad RS |
207 | if (text == NULL) |
208 | goto end; | |
209 | i = strlen(text); | |
210 | if (i == 0 || i > n) | |
211 | break; | |
212 | if (text[i - 1] != '\\') { | |
213 | p += strlen(strcpy(p, text)); | |
214 | free(text); | |
215 | add_history(buf); | |
216 | break; | |
217 | } | |
218 | ||
219 | text[i - 1] = '\0'; | |
220 | p += strlen(strcpy(p, text)); | |
221 | free(text); | |
222 | n -= i; | |
223 | } | |
224 | #endif | |
0f113f3e | 225 | } |
57d5edad | 226 | |
7e1b7485 RS |
227 | if (!chopup_args(&arg, buf)) { |
228 | BIO_printf(bio_err, "Can't parse (no memory?)\n"); | |
0f113f3e | 229 | break; |
7e1b7485 | 230 | } |
0f113f3e | 231 | |
7e1b7485 RS |
232 | ret = do_cmd(prog, arg.argc, arg.argv); |
233 | if (ret == EXIT_THE_PROGRAM) { | |
0f113f3e MC |
234 | ret = 0; |
235 | goto end; | |
236 | } | |
237 | if (ret != 0) | |
7e1b7485 RS |
238 | BIO_printf(bio_err, "error in %s\n", arg.argv[0]); |
239 | (void)BIO_flush(bio_out); | |
0f113f3e MC |
240 | (void)BIO_flush(bio_err); |
241 | } | |
0f113f3e MC |
242 | ret = 1; |
243 | end: | |
b548a1f1 | 244 | OPENSSL_free(copied_argv); |
cc01d217 | 245 | OPENSSL_free(default_config_file); |
25aaa98a RS |
246 | NCONF_free(config); |
247 | config = NULL; | |
248 | lh_FUNCTION_free(prog); | |
b548a1f1 | 249 | OPENSSL_free(arg.argv); |
0f113f3e | 250 | |
7e1b7485 RS |
251 | BIO_free(bio_in); |
252 | BIO_free_all(bio_out); | |
0f113f3e | 253 | apps_shutdown(); |
c2e27310 | 254 | #ifndef OPENSSL_NO_CRYPTO_MDEBUG |
541e9565 DSH |
255 | if (CRYPTO_mem_leaks(bio_err) <= 0) |
256 | ret = 1; | |
bbd86bf5 | 257 | #endif |
ca3a82c3 | 258 | BIO_free(bio_err); |
aa147792 | 259 | EXIT(ret); |
7e1b7485 RS |
260 | } |
261 | ||
262 | OPTIONS exit_options[] = { | |
263 | {NULL} | |
264 | }; | |
265 | ||
2f58faad RS |
266 | static void list_cipher_fn(const EVP_CIPHER *c, |
267 | const char *from, const char *to, void *arg) | |
268 | { | |
269 | if (c) | |
270 | BIO_printf(arg, "%s\n", EVP_CIPHER_name(c)); | |
271 | else { | |
272 | if (!from) | |
273 | from = "<undefined>"; | |
274 | if (!to) | |
275 | to = "<undefined>"; | |
276 | BIO_printf(arg, "%s => %s\n", from, to); | |
277 | } | |
278 | } | |
279 | ||
280 | static void list_md_fn(const EVP_MD *m, | |
281 | const char *from, const char *to, void *arg) | |
282 | { | |
283 | if (m) | |
284 | BIO_printf(arg, "%s\n", EVP_MD_name(m)); | |
285 | else { | |
286 | if (!from) | |
287 | from = "<undefined>"; | |
288 | if (!to) | |
289 | to = "<undefined>"; | |
290 | BIO_printf((BIO *)arg, "%s => %s\n", from, to); | |
291 | } | |
292 | } | |
293 | ||
7e1b7485 RS |
294 | /* Unified enum for help and list commands. */ |
295 | typedef enum HELPLIST_CHOICE { | |
296 | OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, | |
297 | OPT_COMMANDS, OPT_DIGEST_COMMANDS, | |
298 | OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS, | |
a760a380 | 299 | OPT_PK_ALGORITHMS, OPT_DISABLED |
7e1b7485 RS |
300 | } HELPLIST_CHOICE; |
301 | ||
302 | OPTIONS list_options[] = { | |
303 | {"help", OPT_HELP, '-', "Display this summary"}, | |
304 | {"commands", OPT_COMMANDS, '-', "List of standard commands"}, | |
305 | {"digest-commands", OPT_DIGEST_COMMANDS, '-', | |
306 | "List of message digest commands"}, | |
307 | {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-', | |
308 | "List of message digest algorithms"}, | |
309 | {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"}, | |
310 | {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-', | |
311 | "List of cipher algorithms"}, | |
312 | {"public-key-algorithms", OPT_PK_ALGORITHMS, '-', | |
313 | "List of public key algorithms"}, | |
a760a380 DSH |
314 | {"disabled", OPT_DISABLED, '-', |
315 | "List of disabled features"}, | |
7e1b7485 RS |
316 | {NULL} |
317 | }; | |
318 | ||
319 | int list_main(int argc, char **argv) | |
320 | { | |
321 | char *prog; | |
322 | HELPLIST_CHOICE o; | |
19948cea | 323 | int done = 0; |
7e1b7485 RS |
324 | |
325 | prog = opt_init(argc, argv, list_options); | |
326 | while ((o = opt_next()) != OPT_EOF) { | |
327 | switch (o) { | |
19948cea | 328 | case OPT_EOF: /* Never hit, but suppresses warning */ |
7e1b7485 RS |
329 | case OPT_ERR: |
330 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | |
331 | return 1; | |
332 | case OPT_HELP: | |
333 | opt_help(list_options); | |
334 | break; | |
335 | case OPT_COMMANDS: | |
2f58faad RS |
336 | list_type(FT_general); |
337 | break; | |
7e1b7485 | 338 | case OPT_DIGEST_COMMANDS: |
2f58faad RS |
339 | list_type(FT_md); |
340 | break; | |
7e1b7485 | 341 | case OPT_DIGEST_ALGORITHMS: |
2f58faad RS |
342 | EVP_MD_do_all_sorted(list_md_fn, bio_out); |
343 | break; | |
7e1b7485 | 344 | case OPT_CIPHER_COMMANDS: |
2f58faad RS |
345 | list_type(FT_cipher); |
346 | break; | |
7e1b7485 | 347 | case OPT_CIPHER_ALGORITHMS: |
2f58faad RS |
348 | EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out); |
349 | break; | |
7e1b7485 | 350 | case OPT_PK_ALGORITHMS: |
2f58faad RS |
351 | list_pkey(); |
352 | break; | |
a760a380 DSH |
353 | case OPT_DISABLED: |
354 | list_disabled(); | |
355 | break; | |
7e1b7485 | 356 | } |
19948cea BL |
357 | done = 1; |
358 | } | |
359 | ||
360 | if (!done) { | |
361 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | |
362 | return 1; | |
7e1b7485 RS |
363 | } |
364 | ||
365 | return 0; | |
366 | } | |
367 | ||
368 | OPTIONS help_options[] = { | |
369 | {"help", OPT_HELP, '-', "Display this summary"}, | |
370 | {NULL} | |
371 | }; | |
372 | ||
373 | int help_main(int argc, char **argv) | |
374 | { | |
375 | FUNCTION *fp; | |
376 | int i, nl; | |
377 | FUNC_TYPE tp; | |
378 | char *prog; | |
379 | HELPLIST_CHOICE o; | |
380 | ||
381 | prog = opt_init(argc, argv, help_options); | |
382 | while ((o = opt_next()) != OPT_EOF) { | |
383 | switch (o) { | |
384 | default: | |
385 | BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | |
386 | return 1; | |
387 | case OPT_HELP: | |
388 | opt_help(help_options); | |
389 | return 0; | |
390 | } | |
391 | } | |
7e1b7485 | 392 | |
5d94e5b6 | 393 | if (opt_num_rest() != 0) { |
7e1b7485 RS |
394 | BIO_printf(bio_err, "Usage: %s\n", prog); |
395 | return 1; | |
396 | } | |
397 | ||
398 | BIO_printf(bio_err, "\nStandard commands"); | |
399 | i = 0; | |
400 | tp = FT_none; | |
401 | for (fp = functions; fp->name != NULL; fp++) { | |
402 | nl = 0; | |
403 | if (((i++) % COLUMNS) == 0) { | |
404 | BIO_printf(bio_err, "\n"); | |
405 | nl = 1; | |
406 | } | |
407 | if (fp->type != tp) { | |
408 | tp = fp->type; | |
409 | if (!nl) | |
410 | BIO_printf(bio_err, "\n"); | |
411 | if (tp == FT_md) { | |
412 | i = 1; | |
413 | BIO_printf(bio_err, | |
414 | "\nMessage Digest commands (see the `dgst' command for more details)\n"); | |
415 | } else if (tp == FT_cipher) { | |
416 | i = 1; | |
417 | BIO_printf(bio_err, | |
418 | "\nCipher commands (see the `enc' command for more details)\n"); | |
419 | } | |
420 | } | |
421 | BIO_printf(bio_err, FORMAT, fp->name); | |
422 | } | |
423 | BIO_printf(bio_err, "\n\n"); | |
424 | return 0; | |
425 | } | |
8c00f4cf | 426 | |
7e1b7485 RS |
427 | int exit_main(int argc, char **argv) |
428 | { | |
429 | return EXIT_THE_PROGRAM; | |
0f113f3e | 430 | } |
d02b48c6 | 431 | |
2f58faad | 432 | static void list_type(FUNC_TYPE ft) |
7e1b7485 RS |
433 | { |
434 | FUNCTION *fp; | |
435 | int i = 0; | |
436 | ||
437 | for (fp = functions; fp->name != NULL; fp++) | |
2f58faad | 438 | if (fp->type == ft) { |
7e1b7485 RS |
439 | if ((i++ % COLUMNS) == 0) |
440 | BIO_printf(bio_out, "\n"); | |
441 | BIO_printf(bio_out, FORMAT, fp->name); | |
442 | } | |
443 | BIO_printf(bio_out, "\n"); | |
7e1b7485 | 444 | } |
fc8ee06b | 445 | |
3c1d6bbc | 446 | static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]) |
0f113f3e MC |
447 | { |
448 | FUNCTION f, *fp; | |
0f113f3e | 449 | |
7e1b7485 RS |
450 | if (argc <= 0 || argv[0] == NULL) |
451 | return (0); | |
0f113f3e MC |
452 | f.name = argv[0]; |
453 | fp = lh_FUNCTION_retrieve(prog, &f); | |
454 | if (fp == NULL) { | |
455 | if (EVP_get_digestbyname(argv[0])) { | |
7e1b7485 | 456 | f.type = FT_md; |
0f113f3e MC |
457 | f.func = dgst_main; |
458 | fp = &f; | |
459 | } else if (EVP_get_cipherbyname(argv[0])) { | |
7e1b7485 | 460 | f.type = FT_cipher; |
0f113f3e MC |
461 | f.func = enc_main; |
462 | fp = &f; | |
463 | } | |
464 | } | |
465 | if (fp != NULL) { | |
7e1b7485 RS |
466 | return (fp->func(argc, argv)); |
467 | } | |
468 | if ((strncmp(argv[0], "no-", 3)) == 0) { | |
469 | /* | |
470 | * User is asking if foo is unsupported, by trying to "run" the | |
471 | * no-foo command. Strange. | |
472 | */ | |
0f113f3e | 473 | f.name = argv[0] + 3; |
7e1b7485 RS |
474 | if (lh_FUNCTION_retrieve(prog, &f) == NULL) { |
475 | BIO_printf(bio_out, "%s\n", argv[0]); | |
476 | return (0); | |
0f113f3e | 477 | } |
7e1b7485 RS |
478 | BIO_printf(bio_out, "%s\n", argv[0] + 3); |
479 | return 1; | |
50acf46b | 480 | } |
7e1b7485 RS |
481 | if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 || |
482 | strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0) | |
483 | /* Special value to mean "exit the program. */ | |
484 | return EXIT_THE_PROGRAM; | |
0f113f3e | 485 | |
7e1b7485 RS |
486 | BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n", |
487 | argv[0]); | |
488 | return (1); | |
0f113f3e | 489 | } |
50acf46b | 490 | |
2f58faad | 491 | static void list_pkey(void) |
0f113f3e MC |
492 | { |
493 | int i; | |
7e1b7485 | 494 | |
0f113f3e MC |
495 | for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) { |
496 | const EVP_PKEY_ASN1_METHOD *ameth; | |
497 | int pkey_id, pkey_base_id, pkey_flags; | |
498 | const char *pinfo, *pem_str; | |
499 | ameth = EVP_PKEY_asn1_get0(i); | |
500 | EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags, | |
501 | &pinfo, &pem_str, ameth); | |
502 | if (pkey_flags & ASN1_PKEY_ALIAS) { | |
7e1b7485 RS |
503 | BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id)); |
504 | BIO_printf(bio_out, "\tAlias for: %s\n", | |
0f113f3e MC |
505 | OBJ_nid2ln(pkey_base_id)); |
506 | } else { | |
7e1b7485 RS |
507 | BIO_printf(bio_out, "Name: %s\n", pinfo); |
508 | BIO_printf(bio_out, "\tType: %s Algorithm\n", | |
0f113f3e MC |
509 | pkey_flags & ASN1_PKEY_DYNAMIC ? |
510 | "External" : "Builtin"); | |
7e1b7485 | 511 | BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id)); |
0f113f3e MC |
512 | if (pem_str == NULL) |
513 | pem_str = "(none)"; | |
7e1b7485 | 514 | BIO_printf(bio_out, "\tPEM string: %s\n", pem_str); |
0f113f3e MC |
515 | } |
516 | ||
517 | } | |
0f113f3e | 518 | } |
3c1d6bbc | 519 | |
0f113f3e MC |
520 | static int function_cmp(const FUNCTION * a, const FUNCTION * b) |
521 | { | |
522 | return strncmp(a->name, b->name, 8); | |
523 | } | |
50acf46b | 524 | |
0f113f3e MC |
525 | static unsigned long function_hash(const FUNCTION * a) |
526 | { | |
739a1eb1 | 527 | return OPENSSL_LH_strhash(a->name); |
0f113f3e | 528 | } |
d02b48c6 | 529 | |
7e1b7485 RS |
530 | static int SortFnByName(const void *_f1, const void *_f2) |
531 | { | |
532 | const FUNCTION *f1 = _f1; | |
533 | const FUNCTION *f2 = _f2; | |
534 | ||
535 | if (f1->type != f2->type) | |
536 | return f1->type - f2->type; | |
537 | return strcmp(f1->name, f2->name); | |
538 | } | |
539 | ||
a760a380 DSH |
540 | static void list_disabled(void) |
541 | { | |
d230bd1d | 542 | BIO_puts(bio_out, "Disabled algorithms:\n"); |
27dae1b0 RL |
543 | #ifdef OPENSSL_NO_BF |
544 | BIO_puts(bio_out, "BF\n"); | |
545 | #endif | |
2d0b4412 BC |
546 | #ifndef OPENSSL_NO_BLAKE2 |
547 | BIO_puts(bio_out, "BLAKE2\n"); | |
548 | #endif | |
27dae1b0 RL |
549 | #ifdef OPENSSL_NO_CAMELLIA |
550 | BIO_puts(bio_out, "CAMELLIA\n"); | |
551 | #endif | |
552 | #ifdef OPENSSL_NO_CAST | |
553 | BIO_puts(bio_out, "CAST\n"); | |
554 | #endif | |
56c1ef05 RL |
555 | #ifdef OPENSSL_NO_CMAC |
556 | BIO_puts(bio_out, "CMAC\n"); | |
557 | #endif | |
27dae1b0 RL |
558 | #ifdef OPENSSL_NO_CMS |
559 | BIO_puts(bio_out, "CMS\n"); | |
560 | #endif | |
66b14bab RL |
561 | #ifdef OPENSSL_NO_COMP |
562 | BIO_puts(bio_out, "COMP\n"); | |
563 | #endif | |
27dae1b0 RL |
564 | #ifdef OPENSSL_NO_DES |
565 | BIO_puts(bio_out, "DES\n"); | |
566 | #endif | |
2df84dd3 RL |
567 | #ifdef OPENSSL_NO_DGRAM |
568 | BIO_puts(bio_out, "DGRAM\n"); | |
569 | #endif | |
a760a380 DSH |
570 | #ifdef OPENSSL_NO_DH |
571 | BIO_puts(bio_out, "DH\n"); | |
572 | #endif | |
573 | #ifdef OPENSSL_NO_DSA | |
574 | BIO_puts(bio_out, "DSA\n"); | |
575 | #endif | |
a5ecdc6a KR |
576 | #if defined(OPENSSL_NO_DTLS) |
577 | BIO_puts(bio_out, "DTLS\n"); | |
66b14bab | 578 | #endif |
6b01bed2 VD |
579 | #if defined(OPENSSL_NO_DTLS1) |
580 | BIO_puts(bio_out, "DTLS1\n"); | |
581 | #endif | |
582 | #if defined(OPENSSL_NO_DTLS1_2) | |
583 | BIO_puts(bio_out, "DTLS1_2\n"); | |
584 | #endif | |
a760a380 DSH |
585 | #ifdef OPENSSL_NO_EC |
586 | BIO_puts(bio_out, "EC\n"); | |
587 | #endif | |
588 | #ifdef OPENSSL_NO_EC2M | |
589 | BIO_puts(bio_out, "EC2M\n"); | |
590 | #endif | |
27dae1b0 RL |
591 | #ifdef OPENSSL_NO_ENGINE |
592 | BIO_puts(bio_out, "ENGINE\n"); | |
593 | #endif | |
2df84dd3 RL |
594 | #ifdef OPENSSL_NO_GOST |
595 | BIO_puts(bio_out, "GOST\n"); | |
596 | #endif | |
22e3dcb7 RS |
597 | #ifdef OPENSSL_NO_HEARTBEATS |
598 | BIO_puts(bio_out, "HEARTBEATS\n"); | |
599 | #endif | |
27dae1b0 RL |
600 | #ifdef OPENSSL_NO_IDEA |
601 | BIO_puts(bio_out, "IDEA\n"); | |
602 | #endif | |
603 | #ifdef OPENSSL_NO_MD2 | |
604 | BIO_puts(bio_out, "MD2\n"); | |
605 | #endif | |
606 | #ifdef OPENSSL_NO_MD4 | |
607 | BIO_puts(bio_out, "MD4\n"); | |
608 | #endif | |
609 | #ifdef OPENSSL_NO_MD5 | |
610 | BIO_puts(bio_out, "MD5\n"); | |
611 | #endif | |
612 | #ifdef OPENSSL_NO_MDC2 | |
613 | BIO_puts(bio_out, "MDC2\n"); | |
614 | #endif | |
2df84dd3 RL |
615 | #ifdef OPENSSL_NO_OCB |
616 | BIO_puts(bio_out, "OCB\n"); | |
617 | #endif | |
27dae1b0 RL |
618 | #ifdef OPENSSL_NO_OCSP |
619 | BIO_puts(bio_out, "OCSP\n"); | |
620 | #endif | |
a760a380 DSH |
621 | #ifdef OPENSSL_NO_PSK |
622 | BIO_puts(bio_out, "PSK\n"); | |
623 | #endif | |
27dae1b0 RL |
624 | #ifdef OPENSSL_NO_RC2 |
625 | BIO_puts(bio_out, "RC2\n"); | |
626 | #endif | |
627 | #ifdef OPENSSL_NO_RC4 | |
628 | BIO_puts(bio_out, "RC4\n"); | |
629 | #endif | |
630 | #ifdef OPENSSL_NO_RC5 | |
631 | BIO_puts(bio_out, "RC5\n"); | |
632 | #endif | |
633 | #ifdef OPENSSL_NO_RMD160 | |
634 | BIO_puts(bio_out, "RMD160\n"); | |
635 | #endif | |
d230bd1d RL |
636 | #ifdef OPENSSL_NO_RSA |
637 | BIO_puts(bio_out, "RSA\n"); | |
638 | #endif | |
66b14bab RL |
639 | #ifdef OPENSSL_NO_SCRYPT |
640 | BIO_puts(bio_out, "SCRYPT\n"); | |
641 | #endif | |
2df84dd3 RL |
642 | #ifdef OPENSSL_NO_SCTP |
643 | BIO_puts(bio_out, "SCTP\n"); | |
644 | #endif | |
27dae1b0 RL |
645 | #ifdef OPENSSL_NO_SEED |
646 | BIO_puts(bio_out, "SEED\n"); | |
647 | #endif | |
648 | #ifdef OPENSSL_NO_SOCK | |
649 | BIO_puts(bio_out, "SOCK\n"); | |
650 | #endif | |
a760a380 DSH |
651 | #ifdef OPENSSL_NO_SRP |
652 | BIO_puts(bio_out, "SRP\n"); | |
653 | #endif | |
66b14bab RL |
654 | #ifdef OPENSSL_NO_SRTP |
655 | BIO_puts(bio_out, "SRTP\n"); | |
656 | #endif | |
657 | #ifdef OPENSSL_NO_SSL3 | |
658 | BIO_puts(bio_out, "SSL3\n"); | |
659 | #endif | |
6b01bed2 VD |
660 | #ifdef OPENSSL_NO_TLS1 |
661 | BIO_puts(bio_out, "TLS1\n"); | |
662 | #endif | |
663 | #ifdef OPENSSL_NO_TLS1_1 | |
664 | BIO_puts(bio_out, "TLS1_1\n"); | |
665 | #endif | |
666 | #ifdef OPENSSL_NO_TLS1_2 | |
667 | BIO_puts(bio_out, "TLS1_2\n"); | |
668 | #endif | |
27dae1b0 RL |
669 | #ifdef OPENSSL_NO_WHIRLPOOL |
670 | BIO_puts(bio_out, "WHIRLPOOL\n"); | |
671 | #endif | |
d230bd1d RL |
672 | #ifndef ZLIB |
673 | BIO_puts(bio_out, "ZLIB\n"); | |
674 | #endif | |
a760a380 DSH |
675 | } |
676 | ||
0f113f3e MC |
677 | static LHASH_OF(FUNCTION) *prog_init(void) |
678 | { | |
679 | LHASH_OF(FUNCTION) *ret; | |
680 | FUNCTION *f; | |
681 | size_t i; | |
682 | ||
7e1b7485 | 683 | /* Sort alphabetically within category. For nicer help displays. */ |
0f113f3e | 684 | for (i = 0, f = functions; f->name != NULL; ++f, ++i) ; |
b4faea50 | 685 | qsort(functions, i, sizeof(*functions), SortFnByName); |
0f113f3e | 686 | |
62d0577e | 687 | if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL) |
0f113f3e MC |
688 | return (NULL); |
689 | ||
690 | for (f = functions; f->name != NULL; f++) | |
691 | (void)lh_FUNCTION_insert(ret, f); | |
692 | return (ret); | |
693 | } |