]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/openssl.c
Remove OPENSSL_NO_AES guards
[thirdparty/openssl.git] / apps / openssl.c
CommitLineData
58964a49 1/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
d02b48c6
RE
2 * All rights reserved.
3 *
4 * This package is an SSL implementation written
5 * by Eric Young (eay@cryptsoft.com).
6 * The implementation was written so as to conform with Netscapes SSL.
0f113f3e 7 *
d02b48c6
RE
8 * This library is free for commercial and non-commercial use as long as
9 * the following conditions are aheared to. The following conditions
10 * apply to all code found in this distribution, be it the RC4, RSA,
11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12 * included with this distribution is covered by the same copyright terms
13 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
0f113f3e 14 *
d02b48c6
RE
15 * Copyright remains Eric Young's, and as such any Copyright notices in
16 * the code are not to be removed.
17 * If this package is used in a product, Eric Young should be given attribution
18 * as the author of the parts of the library used.
19 * This can be in the form of a textual message at program startup or
20 * in documentation (online or textual) provided with the package.
0f113f3e 21 *
d02b48c6
RE
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * "This product includes cryptographic software written by
33 * Eric Young (eay@cryptsoft.com)"
34 * The word 'cryptographic' can be left out if the rouines from the library
35 * being used are not cryptographic related :-).
0f113f3e 36 * 4. If you include any Windows specific code (or a derivative thereof) from
d02b48c6
RE
37 * the apps directory (application code) you must include an acknowledgement:
38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
0f113f3e 39 *
d02b48c6
RE
40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
0f113f3e 51 *
d02b48c6
RE
52 * The licence and distribution terms for any publically available version or
53 * derivative of this code cannot be changed. i.e. this code cannot simply be
54 * copied and put under another distribution licence
55 * [including the GNU Public Licence.]
56 */
3ac82faa 57/* ====================================================================
f3dea9a5 58 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
3ac82faa
BM
59 *
60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions
62 * are met:
63 *
64 * 1. Redistributions of source code must retain the above copyright
0f113f3e 65 * notice, this list of conditions and the following disclaimer.
3ac82faa
BM
66 *
67 * 2. Redistributions in binary form must reproduce the above copyright
68 * notice, this list of conditions and the following disclaimer in
69 * the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3. All advertising materials mentioning features or use of this
73 * software must display the following acknowledgment:
74 * "This product includes software developed by the OpenSSL Project
75 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
76 *
77 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
78 * endorse or promote products derived from this software without
79 * prior written permission. For written permission, please contact
80 * openssl-core@openssl.org.
81 *
82 * 5. Products derived from this software may not be called "OpenSSL"
83 * nor may "OpenSSL" appear in their names without prior written
84 * permission of the OpenSSL Project.
85 *
86 * 6. Redistributions of any form whatsoever must retain the following
87 * acknowledgment:
88 * "This product includes software developed by the OpenSSL Project
89 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
92 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
94 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
95 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
96 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
97 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
98 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
100 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
101 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
102 * OF THE POSSIBILITY OF SUCH DAMAGE.
103 * ====================================================================
104 *
105 * This product includes cryptographic software written by Eric Young
106 * (eay@cryptsoft.com). This product includes software written by Tim
107 * Hudson (tjh@cryptsoft.com).
108 *
109 */
110
d02b48c6
RE
111#include <stdio.h>
112#include <string.h>
113#include <stdlib.h>
ec577822
BM
114#include <openssl/bio.h>
115#include <openssl/crypto.h>
3d1160d5 116#include <openssl/rand.h>
ec577822
BM
117#include <openssl/lhash.h>
118#include <openssl/conf.h>
119#include <openssl/x509.h>
120#include <openssl/pem.h>
121#include <openssl/ssl.h>
0b13e9f0 122#ifndef OPENSSL_NO_ENGINE
0f113f3e 123# include <openssl/engine.h>
0b13e9f0 124#endif
ec577822 125#include <openssl/err.h>
856650de 126#ifdef OPENSSL_FIPS
0f113f3e 127# include <openssl/fips.h>
856650de 128#endif
3b061a00
RS
129#define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
130#include "s_apps.h"
131/* Needed to get the other O_xxx flags. */
132#ifdef OPENSSL_SYS_VMS
133# include <unixio.h>
134#endif
1e7e1c8d 135#define INCLUDE_FUNCTION_TABLE
7e1b7485
RS
136#include "apps.h"
137
7e1b7485
RS
138
139#ifdef OPENSSL_NO_CAMELLIA
140# define FORMAT "%-15s"
141# define COLUMNS 5
142#else
143# define FORMAT "%-18s"
144# define COLUMNS 4
145#endif
146
147/* Special sentinel to exit the program. */
148#define EXIT_THE_PROGRAM (-1)
d02b48c6 149
0f113f3e
MC
150/*
151 * The LHASH callbacks ("hash" & "cmp") have been replaced by functions with
152 * the base prototypes (we cast each variable inside the function to the
153 * required type of "FUNCTION*"). This removes the necessity for
154 * macro-generated wrapper functions.
155 */
0f113f3e
MC
156static LHASH_OF(FUNCTION) *prog_init(void);
157static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
2f58faad
RS
158static void list_pkey(void);
159static void list_type(FUNC_TYPE ft);
a760a380 160static void list_disabled(void);
0f113f3e 161char *default_config_file = NULL;
d02b48c6 162
df2ee0e2 163static CONF *config = NULL;
7e1b7485
RS
164BIO *bio_in = NULL;
165BIO *bio_out = NULL;
0f113f3e 166BIO *bio_err = NULL;
7e1b7485 167
a0a82324 168static int apps_startup()
7e1b7485
RS
169{
170#ifdef SIGPIPE
171 signal(SIGPIPE, SIG_IGN);
172#endif
a0a82324 173
b9f75707 174 /* Set non-default library initialisation settings */
0fc32b07
MC
175 if (!OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN
176 | OPENSSL_INIT_LOAD_CONFIG, NULL))
177 return 0;
a0a82324 178
923b1857 179#ifndef OPENSSL_NO_UI
7e1b7485 180 setup_ui_method();
923b1857 181#endif
b9f75707 182
a0a82324 183 return 1;
7e1b7485
RS
184}
185
186static void apps_shutdown()
187{
923b1857 188#ifndef OPENSSL_NO_UI
7e1b7485 189 destroy_ui_method();
923b1857 190#endif
7e1b7485
RS
191}
192
193static char *make_config_name()
194{
cc01d217 195 const char *t;
7e1b7485
RS
196 size_t len;
197 char *p;
198
b0700d2c 199 if ((t = getenv("OPENSSL_CONF")) != NULL)
7644a9ae 200 return OPENSSL_strdup(t);
cc01d217
RS
201
202 t = X509_get_default_cert_area();
203 len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1;
68dc6824 204 p = app_malloc(len, "config filename buffer");
cc01d217 205 strcpy(p, t);
7e1b7485 206#ifndef OPENSSL_SYS_VMS
cc01d217 207 strcat(p, "/");
d02b48c6 208#endif
cc01d217 209 strcat(p, OPENSSL_CONF);
7e1b7485
RS
210
211 return p;
212}
213
7e1b7485 214int main(int argc, char *argv[])
0f113f3e 215{
0f113f3e 216 FUNCTION f, *fp;
0f113f3e 217 LHASH_OF(FUNCTION) *prog = NULL;
7e1b7485 218 char **copied_argv = NULL;
cc01d217 219 char *p, *pname;
7e1b7485
RS
220 char buf[1024];
221 const char *prompt;
222 ARGS arg;
223 int first, n, i, ret = 0;
8ecef24a 224
7e1b7485
RS
225 arg.argv = NULL;
226 arg.size = 0;
227
7768e116
RS
228 /* Set up some of the environment. */
229 default_config_file = make_config_name();
a60994df
RL
230 bio_in = dup_bio_in(FORMAT_TEXT);
231 bio_out = dup_bio_out(FORMAT_TEXT);
149bd5d6 232 bio_err = dup_bio_err(FORMAT_TEXT);
7768e116 233
368058d0
RL
234#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
235 copied_argv = argv = copy_argv(&argc, argv);
7e1b7485
RS
236#endif
237
238 p = getenv("OPENSSL_DEBUG_MEMORY");
bbd86bf5
RS
239 if (p != NULL && strcmp(p, "on") == 0)
240 CRYPTO_set_mem_debug(1);
0f113f3e 241 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
3ac82faa 242
0f113f3e 243 if (getenv("OPENSSL_FIPS")) {
856650de 244#ifdef OPENSSL_FIPS
0f113f3e 245 if (!FIPS_mode_set(1)) {
7768e116
RS
246 ERR_print_errors(bio_err);
247 return 1;
0f113f3e 248 }
856650de 249#else
7768e116
RS
250 BIO_printf(bio_err, "FIPS mode not supported.\n");
251 return 1;
856650de 252#endif
0f113f3e
MC
253 }
254
a0a82324
MC
255 if (!apps_startup())
256 goto end;
257
7e1b7485 258 prog = prog_init();
368058d0 259 pname = opt_progname(argv[0]);
0f113f3e 260
0f113f3e 261 /* first check the program name */
0f113f3e
MC
262 f.name = pname;
263 fp = lh_FUNCTION_retrieve(prog, &f);
264 if (fp != NULL) {
368058d0
RL
265 argv[0] = pname;
266 ret = fp->func(argc, argv);
0f113f3e
MC
267 goto end;
268 }
269
7e1b7485
RS
270 /* If there is stuff on the command line, run with that. */
271 if (argc != 1) {
272 argc--;
368058d0
RL
273 argv++;
274 ret = do_cmd(prog, argc, argv);
0f113f3e
MC
275 if (ret < 0)
276 ret = 0;
277 goto end;
278 }
279
7e1b7485 280 /* ok, lets enter interactive mode */
0f113f3e
MC
281 for (;;) {
282 ret = 0;
57d5edad
RS
283 /* Read a line, continue reading if line ends with \ */
284 for (p = buf, n = sizeof buf, i = 0, first = 1; n > 0; first = 0) {
1c9c2435 285 prompt = first ? "OpenSSL> " : "> ";
0f113f3e 286 p[0] = '\0';
57d5edad 287#ifndef READLINE
0f113f3e
MC
288 fputs(prompt, stdout);
289 fflush(stdout);
290 if (!fgets(p, n, stdin))
291 goto end;
292 if (p[0] == '\0')
293 goto end;
294 i = strlen(p);
295 if (i <= 1)
296 break;
297 if (p[i - 2] != '\\')
298 break;
299 i -= 2;
300 p += i;
301 n -= i;
57d5edad
RS
302#else
303 {
304 extern char *readline(const char *);
305 extern void add_history(const char *cp);
306 char *text;
307
308 char *text = readline(prompt);
309 if (text == NULL)
310 goto end;
311 i = strlen(text);
312 if (i == 0 || i > n)
313 break;
314 if (text[i - 1] != '\\') {
315 p += strlen(strcpy(p, text));
316 free(text);
317 add_history(buf);
318 break;
319 }
320
321 text[i - 1] = '\0';
322 p += strlen(strcpy(p, text));
323 free(text);
324 n -= i;
325 }
326#endif
0f113f3e 327 }
57d5edad 328
7e1b7485
RS
329 if (!chopup_args(&arg, buf)) {
330 BIO_printf(bio_err, "Can't parse (no memory?)\n");
0f113f3e 331 break;
7e1b7485 332 }
0f113f3e 333
7e1b7485
RS
334 ret = do_cmd(prog, arg.argc, arg.argv);
335 if (ret == EXIT_THE_PROGRAM) {
0f113f3e
MC
336 ret = 0;
337 goto end;
338 }
339 if (ret != 0)
7e1b7485
RS
340 BIO_printf(bio_err, "error in %s\n", arg.argv[0]);
341 (void)BIO_flush(bio_out);
0f113f3e
MC
342 (void)BIO_flush(bio_err);
343 }
0f113f3e
MC
344 ret = 1;
345 end:
b548a1f1 346 OPENSSL_free(copied_argv);
cc01d217 347 OPENSSL_free(default_config_file);
25aaa98a
RS
348 NCONF_free(config);
349 config = NULL;
350 lh_FUNCTION_free(prog);
b548a1f1 351 OPENSSL_free(arg.argv);
0f113f3e 352
7e1b7485
RS
353 BIO_free(bio_in);
354 BIO_free_all(bio_out);
0f113f3e 355 apps_shutdown();
c2e27310 356#ifndef OPENSSL_NO_CRYPTO_MDEBUG
541e9565
DSH
357 if (CRYPTO_mem_leaks(bio_err) <= 0)
358 ret = 1;
bbd86bf5 359#endif
ca3a82c3 360 BIO_free(bio_err);
aa147792 361 EXIT(ret);
7e1b7485
RS
362}
363
364OPTIONS exit_options[] = {
365 {NULL}
366};
367
2f58faad
RS
368static void list_cipher_fn(const EVP_CIPHER *c,
369 const char *from, const char *to, void *arg)
370{
371 if (c)
372 BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
373 else {
374 if (!from)
375 from = "<undefined>";
376 if (!to)
377 to = "<undefined>";
378 BIO_printf(arg, "%s => %s\n", from, to);
379 }
380}
381
382static void list_md_fn(const EVP_MD *m,
383 const char *from, const char *to, void *arg)
384{
385 if (m)
386 BIO_printf(arg, "%s\n", EVP_MD_name(m));
387 else {
388 if (!from)
389 from = "<undefined>";
390 if (!to)
391 to = "<undefined>";
392 BIO_printf((BIO *)arg, "%s => %s\n", from, to);
393 }
394}
395
7e1b7485
RS
396/* Unified enum for help and list commands. */
397typedef enum HELPLIST_CHOICE {
398 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
399 OPT_COMMANDS, OPT_DIGEST_COMMANDS,
400 OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
a760a380 401 OPT_PK_ALGORITHMS, OPT_DISABLED
7e1b7485
RS
402} HELPLIST_CHOICE;
403
404OPTIONS list_options[] = {
405 {"help", OPT_HELP, '-', "Display this summary"},
406 {"commands", OPT_COMMANDS, '-', "List of standard commands"},
407 {"digest-commands", OPT_DIGEST_COMMANDS, '-',
408 "List of message digest commands"},
409 {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
410 "List of message digest algorithms"},
411 {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
412 {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
413 "List of cipher algorithms"},
414 {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
415 "List of public key algorithms"},
a760a380
DSH
416 {"disabled", OPT_DISABLED, '-',
417 "List of disabled features"},
7e1b7485
RS
418 {NULL}
419};
420
421int list_main(int argc, char **argv)
422{
423 char *prog;
424 HELPLIST_CHOICE o;
19948cea 425 int done = 0;
7e1b7485
RS
426
427 prog = opt_init(argc, argv, list_options);
428 while ((o = opt_next()) != OPT_EOF) {
429 switch (o) {
19948cea 430 case OPT_EOF: /* Never hit, but suppresses warning */
7e1b7485
RS
431 case OPT_ERR:
432 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
433 return 1;
434 case OPT_HELP:
435 opt_help(list_options);
436 break;
437 case OPT_COMMANDS:
2f58faad
RS
438 list_type(FT_general);
439 break;
7e1b7485 440 case OPT_DIGEST_COMMANDS:
2f58faad
RS
441 list_type(FT_md);
442 break;
7e1b7485 443 case OPT_DIGEST_ALGORITHMS:
2f58faad
RS
444 EVP_MD_do_all_sorted(list_md_fn, bio_out);
445 break;
7e1b7485 446 case OPT_CIPHER_COMMANDS:
2f58faad
RS
447 list_type(FT_cipher);
448 break;
7e1b7485 449 case OPT_CIPHER_ALGORITHMS:
2f58faad
RS
450 EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
451 break;
7e1b7485 452 case OPT_PK_ALGORITHMS:
2f58faad
RS
453 list_pkey();
454 break;
a760a380
DSH
455 case OPT_DISABLED:
456 list_disabled();
457 break;
7e1b7485 458 }
19948cea
BL
459 done = 1;
460 }
461
462 if (!done) {
463 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
464 return 1;
7e1b7485
RS
465 }
466
467 return 0;
468}
469
470OPTIONS help_options[] = {
471 {"help", OPT_HELP, '-', "Display this summary"},
472 {NULL}
473};
474
475int help_main(int argc, char **argv)
476{
477 FUNCTION *fp;
478 int i, nl;
479 FUNC_TYPE tp;
480 char *prog;
481 HELPLIST_CHOICE o;
482
483 prog = opt_init(argc, argv, help_options);
484 while ((o = opt_next()) != OPT_EOF) {
485 switch (o) {
486 default:
487 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
488 return 1;
489 case OPT_HELP:
490 opt_help(help_options);
491 return 0;
492 }
493 }
494 argc = opt_num_rest();
495 argv = opt_rest();
496
497 if (argc != 0) {
498 BIO_printf(bio_err, "Usage: %s\n", prog);
499 return 1;
500 }
501
502 BIO_printf(bio_err, "\nStandard commands");
503 i = 0;
504 tp = FT_none;
505 for (fp = functions; fp->name != NULL; fp++) {
506 nl = 0;
507 if (((i++) % COLUMNS) == 0) {
508 BIO_printf(bio_err, "\n");
509 nl = 1;
510 }
511 if (fp->type != tp) {
512 tp = fp->type;
513 if (!nl)
514 BIO_printf(bio_err, "\n");
515 if (tp == FT_md) {
516 i = 1;
517 BIO_printf(bio_err,
518 "\nMessage Digest commands (see the `dgst' command for more details)\n");
519 } else if (tp == FT_cipher) {
520 i = 1;
521 BIO_printf(bio_err,
522 "\nCipher commands (see the `enc' command for more details)\n");
523 }
524 }
525 BIO_printf(bio_err, FORMAT, fp->name);
526 }
527 BIO_printf(bio_err, "\n\n");
528 return 0;
529}
8c00f4cf 530
7e1b7485
RS
531int exit_main(int argc, char **argv)
532{
533 return EXIT_THE_PROGRAM;
0f113f3e 534}
d02b48c6 535
2f58faad 536static void list_type(FUNC_TYPE ft)
7e1b7485
RS
537{
538 FUNCTION *fp;
539 int i = 0;
540
541 for (fp = functions; fp->name != NULL; fp++)
2f58faad 542 if (fp->type == ft) {
7e1b7485
RS
543 if ((i++ % COLUMNS) == 0)
544 BIO_printf(bio_out, "\n");
545 BIO_printf(bio_out, FORMAT, fp->name);
546 }
547 BIO_printf(bio_out, "\n");
7e1b7485 548}
fc8ee06b 549
3c1d6bbc 550static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
0f113f3e
MC
551{
552 FUNCTION f, *fp;
0f113f3e 553
7e1b7485
RS
554 if (argc <= 0 || argv[0] == NULL)
555 return (0);
0f113f3e
MC
556 f.name = argv[0];
557 fp = lh_FUNCTION_retrieve(prog, &f);
558 if (fp == NULL) {
559 if (EVP_get_digestbyname(argv[0])) {
7e1b7485 560 f.type = FT_md;
0f113f3e
MC
561 f.func = dgst_main;
562 fp = &f;
563 } else if (EVP_get_cipherbyname(argv[0])) {
7e1b7485 564 f.type = FT_cipher;
0f113f3e
MC
565 f.func = enc_main;
566 fp = &f;
567 }
568 }
569 if (fp != NULL) {
7e1b7485
RS
570 return (fp->func(argc, argv));
571 }
572 if ((strncmp(argv[0], "no-", 3)) == 0) {
573 /*
574 * User is asking if foo is unsupported, by trying to "run" the
575 * no-foo command. Strange.
576 */
0f113f3e 577 f.name = argv[0] + 3;
7e1b7485
RS
578 if (lh_FUNCTION_retrieve(prog, &f) == NULL) {
579 BIO_printf(bio_out, "%s\n", argv[0]);
580 return (0);
0f113f3e 581 }
7e1b7485
RS
582 BIO_printf(bio_out, "%s\n", argv[0] + 3);
583 return 1;
50acf46b 584 }
7e1b7485
RS
585 if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 ||
586 strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
587 /* Special value to mean "exit the program. */
588 return EXIT_THE_PROGRAM;
0f113f3e 589
7e1b7485
RS
590 BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
591 argv[0]);
592 return (1);
0f113f3e 593}
50acf46b 594
2f58faad 595static void list_pkey(void)
0f113f3e
MC
596{
597 int i;
7e1b7485 598
0f113f3e
MC
599 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
600 const EVP_PKEY_ASN1_METHOD *ameth;
601 int pkey_id, pkey_base_id, pkey_flags;
602 const char *pinfo, *pem_str;
603 ameth = EVP_PKEY_asn1_get0(i);
604 EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
605 &pinfo, &pem_str, ameth);
606 if (pkey_flags & ASN1_PKEY_ALIAS) {
7e1b7485
RS
607 BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
608 BIO_printf(bio_out, "\tAlias for: %s\n",
0f113f3e
MC
609 OBJ_nid2ln(pkey_base_id));
610 } else {
7e1b7485
RS
611 BIO_printf(bio_out, "Name: %s\n", pinfo);
612 BIO_printf(bio_out, "\tType: %s Algorithm\n",
0f113f3e
MC
613 pkey_flags & ASN1_PKEY_DYNAMIC ?
614 "External" : "Builtin");
7e1b7485 615 BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
0f113f3e
MC
616 if (pem_str == NULL)
617 pem_str = "(none)";
7e1b7485 618 BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
0f113f3e
MC
619 }
620
621 }
0f113f3e 622}
3c1d6bbc 623
0f113f3e
MC
624static int function_cmp(const FUNCTION * a, const FUNCTION * b)
625{
626 return strncmp(a->name, b->name, 8);
627}
50acf46b 628
0f113f3e
MC
629static unsigned long function_hash(const FUNCTION * a)
630{
631 return lh_strhash(a->name);
632}
d02b48c6 633
7e1b7485
RS
634static int SortFnByName(const void *_f1, const void *_f2)
635{
636 const FUNCTION *f1 = _f1;
637 const FUNCTION *f2 = _f2;
638
639 if (f1->type != f2->type)
640 return f1->type - f2->type;
641 return strcmp(f1->name, f2->name);
642}
643
a760a380
DSH
644static void list_disabled(void)
645{
d230bd1d 646 BIO_puts(bio_out, "Disabled algorithms:\n");
27dae1b0
RL
647#ifdef OPENSSL_NO_BF
648 BIO_puts(bio_out, "BF\n");
649#endif
2d0b4412
BC
650#ifndef OPENSSL_NO_BLAKE2
651 BIO_puts(bio_out, "BLAKE2\n");
652#endif
27dae1b0
RL
653#ifdef OPENSSL_NO_CAMELLIA
654 BIO_puts(bio_out, "CAMELLIA\n");
655#endif
656#ifdef OPENSSL_NO_CAST
657 BIO_puts(bio_out, "CAST\n");
658#endif
56c1ef05
RL
659#ifdef OPENSSL_NO_CMAC
660 BIO_puts(bio_out, "CMAC\n");
661#endif
27dae1b0
RL
662#ifdef OPENSSL_NO_CMS
663 BIO_puts(bio_out, "CMS\n");
664#endif
66b14bab
RL
665#ifdef OPENSSL_NO_COMP
666 BIO_puts(bio_out, "COMP\n");
667#endif
27dae1b0
RL
668#ifdef OPENSSL_NO_DES
669 BIO_puts(bio_out, "DES\n");
670#endif
2df84dd3
RL
671#ifdef OPENSSL_NO_DGRAM
672 BIO_puts(bio_out, "DGRAM\n");
673#endif
a760a380
DSH
674#ifdef OPENSSL_NO_DH
675 BIO_puts(bio_out, "DH\n");
676#endif
677#ifdef OPENSSL_NO_DSA
678 BIO_puts(bio_out, "DSA\n");
679#endif
a5ecdc6a
KR
680#if defined(OPENSSL_NO_DTLS)
681 BIO_puts(bio_out, "DTLS\n");
66b14bab 682#endif
6b01bed2
VD
683#if defined(OPENSSL_NO_DTLS1)
684 BIO_puts(bio_out, "DTLS1\n");
685#endif
686#if defined(OPENSSL_NO_DTLS1_2)
687 BIO_puts(bio_out, "DTLS1_2\n");
688#endif
a760a380
DSH
689#ifdef OPENSSL_NO_EC
690 BIO_puts(bio_out, "EC\n");
691#endif
692#ifdef OPENSSL_NO_EC2M
693 BIO_puts(bio_out, "EC2M\n");
694#endif
27dae1b0
RL
695#ifdef OPENSSL_NO_ENGINE
696 BIO_puts(bio_out, "ENGINE\n");
697#endif
2df84dd3
RL
698#ifdef OPENSSL_NO_GOST
699 BIO_puts(bio_out, "GOST\n");
700#endif
22e3dcb7
RS
701#ifdef OPENSSL_NO_HEARTBEATS
702 BIO_puts(bio_out, "HEARTBEATS\n");
703#endif
56c1ef05
RL
704#ifdef OPENSSL_NO_HMAC
705 BIO_puts(bio_out, "HMAC\n");
706#endif
27dae1b0
RL
707#ifdef OPENSSL_NO_IDEA
708 BIO_puts(bio_out, "IDEA\n");
709#endif
710#ifdef OPENSSL_NO_MD2
711 BIO_puts(bio_out, "MD2\n");
712#endif
713#ifdef OPENSSL_NO_MD4
714 BIO_puts(bio_out, "MD4\n");
715#endif
716#ifdef OPENSSL_NO_MD5
717 BIO_puts(bio_out, "MD5\n");
718#endif
719#ifdef OPENSSL_NO_MDC2
720 BIO_puts(bio_out, "MDC2\n");
721#endif
2df84dd3
RL
722#ifdef OPENSSL_NO_OCB
723 BIO_puts(bio_out, "OCB\n");
724#endif
27dae1b0
RL
725#ifdef OPENSSL_NO_OCSP
726 BIO_puts(bio_out, "OCSP\n");
727#endif
a760a380
DSH
728#ifdef OPENSSL_NO_PSK
729 BIO_puts(bio_out, "PSK\n");
730#endif
27dae1b0
RL
731#ifdef OPENSSL_NO_RC2
732 BIO_puts(bio_out, "RC2\n");
733#endif
734#ifdef OPENSSL_NO_RC4
735 BIO_puts(bio_out, "RC4\n");
736#endif
737#ifdef OPENSSL_NO_RC5
738 BIO_puts(bio_out, "RC5\n");
739#endif
740#ifdef OPENSSL_NO_RMD160
741 BIO_puts(bio_out, "RMD160\n");
742#endif
d230bd1d
RL
743#ifdef OPENSSL_NO_RSA
744 BIO_puts(bio_out, "RSA\n");
745#endif
66b14bab
RL
746#ifdef OPENSSL_NO_SCRYPT
747 BIO_puts(bio_out, "SCRYPT\n");
748#endif
2df84dd3
RL
749#ifdef OPENSSL_NO_SCT
750 BIO_puts(bio_out, "SCT\n");
751#endif
752#ifdef OPENSSL_NO_SCTP
753 BIO_puts(bio_out, "SCTP\n");
754#endif
27dae1b0
RL
755#ifdef OPENSSL_NO_SEED
756 BIO_puts(bio_out, "SEED\n");
757#endif
2df84dd3
RL
758#ifdef OPENSSL_NO_SHA
759 BIO_puts(bio_out, "SHA\n");
760#endif
27dae1b0
RL
761#ifdef OPENSSL_NO_SOCK
762 BIO_puts(bio_out, "SOCK\n");
763#endif
a760a380
DSH
764#ifdef OPENSSL_NO_SRP
765 BIO_puts(bio_out, "SRP\n");
766#endif
66b14bab
RL
767#ifdef OPENSSL_NO_SRTP
768 BIO_puts(bio_out, "SRTP\n");
769#endif
6b01bed2
VD
770#ifdef OPENSSL_NO_SSL
771 BIO_puts(bio_out, "SSL\n");
772#endif
66b14bab
RL
773#ifdef OPENSSL_NO_SSL3
774 BIO_puts(bio_out, "SSL3\n");
775#endif
6b01bed2
VD
776#if defined(OPENSSL_NO_TLS)
777 BIO_puts(bio_out, "TLS\n");
778#endif
779#ifdef OPENSSL_NO_TLS1
780 BIO_puts(bio_out, "TLS1\n");
781#endif
782#ifdef OPENSSL_NO_TLS1_1
783 BIO_puts(bio_out, "TLS1_1\n");
784#endif
785#ifdef OPENSSL_NO_TLS1_2
786 BIO_puts(bio_out, "TLS1_2\n");
787#endif
27dae1b0
RL
788#ifdef OPENSSL_NO_WHIRLPOOL
789 BIO_puts(bio_out, "WHIRLPOOL\n");
790#endif
d230bd1d
RL
791#ifndef ZLIB
792 BIO_puts(bio_out, "ZLIB\n");
793#endif
a760a380
DSH
794}
795
0f113f3e
MC
796static LHASH_OF(FUNCTION) *prog_init(void)
797{
798 LHASH_OF(FUNCTION) *ret;
799 FUNCTION *f;
800 size_t i;
801
7e1b7485 802 /* Sort alphabetically within category. For nicer help displays. */
0f113f3e 803 for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
b4faea50 804 qsort(functions, i, sizeof(*functions), SortFnByName);
0f113f3e 805
62d0577e 806 if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
0f113f3e
MC
807 return (NULL);
808
809 for (f = functions; f->name != NULL; f++)
810 (void)lh_FUNCTION_insert(ret, f);
811 return (ret);
812}