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