Add answers for EVP_PKEY_get_default_digest_name() in RSA and DSA keymgmt
[openssl.git] / apps / version.c
1 /*
2  * Copyright 1995-2018 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 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "apps.h"
14 #include "progs.h"
15 #include <openssl/evp.h>
16 #include <openssl/crypto.h>
17 #include <openssl/bn.h>
18 #ifndef OPENSSL_NO_DES
19 # include <openssl/des.h>
20 #endif
21
22 typedef enum OPTION_choice {
23     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
24     OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
25 } OPTION_CHOICE;
26
27 const OPTIONS version_options[] = {
28     OPT_SECTION("General"),
29     {"help", OPT_HELP, '-', "Display this summary"},
30
31     OPT_SECTION("Output"),
32     {"a", OPT_A, '-', "Show all data"},
33     {"b", OPT_B, '-', "Show build date"},
34     {"d", OPT_D, '-', "Show configuration directory"},
35     {"e", OPT_E, '-', "Show engines directory"},
36     {"m", OPT_M, '-', "Show modules directory"},
37     {"f", OPT_F, '-', "Show compiler flags used"},
38     {"o", OPT_O, '-', "Show some internal datatype options"},
39     {"p", OPT_P, '-', "Show target build platform"},
40     {"r", OPT_R, '-', "Show random seeding options"},
41     {"v", OPT_V, '-', "Show library version"},
42     {"c", OPT_C, '-', "Show CPU settings info"},
43     {NULL}
44 };
45
46 int version_main(int argc, char **argv)
47 {
48     int ret = 1, dirty = 0, seed = 0;
49     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
50     int engdir = 0, moddir = 0, cpuinfo = 0;
51     char *prog;
52     OPTION_CHOICE o;
53
54     prog = opt_init(argc, argv, version_options);
55     while ((o = opt_next()) != OPT_EOF) {
56         switch (o) {
57         case OPT_EOF:
58         case OPT_ERR:
59 opthelp:
60             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
61             goto end;
62         case OPT_HELP:
63             opt_help(version_options);
64             ret = 0;
65             goto end;
66         case OPT_B:
67             dirty = date = 1;
68             break;
69         case OPT_D:
70             dirty = dir = 1;
71             break;
72         case OPT_E:
73             dirty = engdir = 1;
74             break;
75         case OPT_M:
76             dirty = moddir = 1;
77             break;
78         case OPT_F:
79             dirty = cflags = 1;
80             break;
81         case OPT_O:
82             dirty = options = 1;
83             break;
84         case OPT_P:
85             dirty = platform = 1;
86             break;
87         case OPT_R:
88             dirty = seed = 1;
89             break;
90         case OPT_V:
91             dirty = version = 1;
92             break;
93         case OPT_C:
94             dirty = cpuinfo = 1;
95             break;
96         case OPT_A:
97             seed = options = cflags = version = date = platform
98                 = dir = engdir = moddir = cpuinfo
99                 = 1;
100             break;
101         }
102     }
103     if (opt_num_rest() != 0) {
104         BIO_printf(bio_err, "Extra parameters given.\n");
105         goto opthelp;
106     }
107     if (!dirty)
108         version = 1;
109
110     if (version)
111         printf("%s (Library: %s)\n",
112                OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
113     if (date)
114         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
115     if (platform)
116         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
117     if (options) {
118         printf("options: ");
119         printf(" %s", BN_options());
120 #ifndef OPENSSL_NO_DES
121         printf(" %s", DES_options());
122 #endif
123         printf("\n");
124     }
125     if (cflags)
126         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
127     if (dir)
128         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
129     if (engdir)
130         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
131     if (moddir)
132         printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
133     if (seed) {
134         const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
135         printf("Seeding source: %s\n", src ? src : "N/A");
136     }
137     if (cpuinfo)
138         printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
139     ret = 0;
140  end:
141     return ret;
142 }