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