Fix 'key' option in s_server can be in ENGINE keyform
[openssl.git] / apps / version.c
1 /*
2  * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "apps.h"
14 #include <openssl/evp.h>
15 #include <openssl/crypto.h>
16 #include <openssl/bn.h>
17 #ifndef OPENSSL_NO_MD2
18 # include <openssl/md2.h>
19 #endif
20 #ifndef OPENSSL_NO_RC4
21 # include <openssl/rc4.h>
22 #endif
23 #ifndef OPENSSL_NO_DES
24 # include <openssl/des.h>
25 #endif
26 #ifndef OPENSSL_NO_IDEA
27 # include <openssl/idea.h>
28 #endif
29 #ifndef OPENSSL_NO_BF
30 # include <openssl/blowfish.h>
31 #endif
32
33 typedef enum OPTION_choice {
34     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
35     OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
36 } OPTION_CHOICE;
37
38 const OPTIONS version_options[] = {
39     {"help", OPT_HELP, '-', "Display this summary"},
40     {"a", OPT_A, '-', "Show all data"},
41     {"b", OPT_B, '-', "Show build date"},
42     {"d", OPT_D, '-', "Show configuration directory"},
43     {"e", OPT_E, '-', "Show engines directory"},
44     {"f", OPT_F, '-', "Show compiler flags used"},
45     {"o", OPT_O, '-', "Show some internal datatype options"},
46     {"p", OPT_P, '-', "Show target build platform"},
47     {"r", OPT_R, '-', "Show random seeding options"},
48     {"v", OPT_V, '-', "Show library version"},
49     {NULL}
50 };
51
52 #if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
53 static void printlist(const char *prefix, const char **dev)
54 {
55     printf("%s (", prefix);
56     for ( ; *dev != NULL; dev++)
57         printf(" \"%s\"", *dev);
58     printf(" )");
59 }
60 #endif
61
62 int version_main(int argc, char **argv)
63 {
64     int ret = 1, dirty = 0, seed = 0;
65     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
66     int engdir = 0;
67     char *prog;
68     OPTION_CHOICE o;
69
70     prog = opt_init(argc, argv, version_options);
71     while ((o = opt_next()) != OPT_EOF) {
72         switch (o) {
73         case OPT_EOF:
74         case OPT_ERR:
75 opthelp:
76             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
77             goto end;
78         case OPT_HELP:
79             opt_help(version_options);
80             ret = 0;
81             goto end;
82         case OPT_B:
83             dirty = date = 1;
84             break;
85         case OPT_D:
86             dirty = dir = 1;
87             break;
88         case OPT_E:
89             dirty = engdir = 1;
90             break;
91         case OPT_F:
92             dirty = cflags = 1;
93             break;
94         case OPT_O:
95             dirty = options = 1;
96             break;
97         case OPT_P:
98             dirty = platform = 1;
99             break;
100         case OPT_R:
101             dirty = seed = 1;
102             break;
103         case OPT_V:
104             dirty = version = 1;
105             break;
106         case OPT_A:
107             seed = cflags = version = date = platform = dir = engdir = 1;
108             break;
109         }
110     }
111     if (opt_num_rest() != 0) {
112         BIO_printf(bio_err, "Extra parameters given.\n");
113         goto opthelp;
114     }
115     if (!dirty)
116         version = 1;
117
118     if (version) {
119         if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
120             printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
121         else
122             printf("%s (Library: %s)\n",
123                    OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
124     }
125     if (date)
126         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
127     if (platform)
128         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
129     if (options) {
130         printf("options:  ");
131         printf("%s ", BN_options());
132 #ifndef OPENSSL_NO_MD2
133         printf("%s ", MD2_options());
134 #endif
135 #ifndef OPENSSL_NO_RC4
136         printf("%s ", RC4_options());
137 #endif
138 #ifndef OPENSSL_NO_DES
139         printf("%s ", DES_options());
140 #endif
141 #ifndef OPENSSL_NO_IDEA
142         printf("%s ", IDEA_options());
143 #endif
144 #ifndef OPENSSL_NO_BF
145         printf("%s ", BF_options());
146 #endif
147         printf("\n");
148     }
149     if (cflags)
150         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
151     if (dir)
152         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
153     if (engdir)
154         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
155     if (seed) {
156         printf("Seeding source:");
157 #ifdef OPENSSL_RAND_SEED_RTDSC
158         printf(" rtdsc");
159 #endif
160 #ifdef OPENSSL_RAND_SEED_RDCPU
161         printf(" rdrand ( rdseed rdrand )");
162 #endif
163 #ifdef OPENSSL_RAND_SEED_LIBRANDOM
164         printf(" C-library-random");
165 #endif
166 #ifdef OPENSSL_RAND_SEED_GETRANDOM
167         printf(" getrandom-syscall");
168 #endif
169 #ifdef OPENSSL_RAND_SEED_DEVRANDOM
170         {
171             static const char *dev[] = { DEVRANDOM, NULL };
172             printlist(" random-device", dev);
173         }
174 #endif
175 #ifdef OPENSSL_RAND_SEED_EGD
176         {
177             static const char *dev[] = { DEVRANDOM_EGD, NULL };
178             printlist(" EGD", dev);
179         }
180 #endif
181 #ifdef OPENSSL_RAND_SEED_NONE
182         printf(" none");
183 #endif
184 #ifdef OPENSSL_RAND_SEED_OS
185         printf(" os-specific");
186 #endif
187         printf("\n");
188     }
189     ret = 0;
190  end:
191     return (ret);
192 }