1*1dcdf01fSchristos /*
2*1dcdf01fSchristos * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
360662d10Schristos *
4*1dcdf01fSchristos * Licensed under the OpenSSL license (the "License"). You may not use
5*1dcdf01fSchristos * this file except in compliance with the License. You can obtain a copy
6*1dcdf01fSchristos * in the file LICENSE in the source distribution or at
7*1dcdf01fSchristos * https://www.openssl.org/source/license.html
860662d10Schristos */
960662d10Schristos
1060662d10Schristos #include <stdio.h>
1160662d10Schristos #include <stdlib.h>
1260662d10Schristos #include <string.h>
1360662d10Schristos #include "apps.h"
14*1dcdf01fSchristos #include "progs.h"
1560662d10Schristos #include <openssl/evp.h>
1660662d10Schristos #include <openssl/crypto.h>
1760662d10Schristos #include <openssl/bn.h>
1860662d10Schristos #ifndef OPENSSL_NO_MD2
1960662d10Schristos # include <openssl/md2.h>
2060662d10Schristos #endif
2160662d10Schristos #ifndef OPENSSL_NO_RC4
2260662d10Schristos # include <openssl/rc4.h>
2360662d10Schristos #endif
2460662d10Schristos #ifndef OPENSSL_NO_DES
2560662d10Schristos # include <openssl/des.h>
2660662d10Schristos #endif
2760662d10Schristos #ifndef OPENSSL_NO_IDEA
2860662d10Schristos # include <openssl/idea.h>
2960662d10Schristos #endif
3060662d10Schristos #ifndef OPENSSL_NO_BF
3160662d10Schristos # include <openssl/blowfish.h>
3260662d10Schristos #endif
3360662d10Schristos
34*1dcdf01fSchristos typedef enum OPTION_choice {
35*1dcdf01fSchristos OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
36*1dcdf01fSchristos OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
37*1dcdf01fSchristos } OPTION_CHOICE;
3860662d10Schristos
39*1dcdf01fSchristos const OPTIONS version_options[] = {
40*1dcdf01fSchristos {"help", OPT_HELP, '-', "Display this summary"},
41*1dcdf01fSchristos {"a", OPT_A, '-', "Show all data"},
42*1dcdf01fSchristos {"b", OPT_B, '-', "Show build date"},
43*1dcdf01fSchristos {"d", OPT_D, '-', "Show configuration directory"},
44*1dcdf01fSchristos {"e", OPT_E, '-', "Show engines directory"},
45*1dcdf01fSchristos {"f", OPT_F, '-', "Show compiler flags used"},
46*1dcdf01fSchristos {"o", OPT_O, '-', "Show some internal datatype options"},
47*1dcdf01fSchristos {"p", OPT_P, '-', "Show target build platform"},
48*1dcdf01fSchristos {"r", OPT_R, '-', "Show random seeding options"},
49*1dcdf01fSchristos {"v", OPT_V, '-', "Show library version"},
50*1dcdf01fSchristos {NULL}
51*1dcdf01fSchristos };
5260662d10Schristos
53*1dcdf01fSchristos #if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
printlist(const char * prefix,const char ** dev)54*1dcdf01fSchristos static void printlist(const char *prefix, const char **dev)
5560662d10Schristos {
56*1dcdf01fSchristos printf("%s (", prefix);
57*1dcdf01fSchristos for ( ; *dev != NULL; dev++)
58*1dcdf01fSchristos printf(" \"%s\"", *dev);
59*1dcdf01fSchristos printf(" )");
60*1dcdf01fSchristos }
61*1dcdf01fSchristos #endif
62*1dcdf01fSchristos
version_main(int argc,char ** argv)63*1dcdf01fSchristos int version_main(int argc, char **argv)
64*1dcdf01fSchristos {
65*1dcdf01fSchristos int ret = 1, dirty = 0, seed = 0;
6660662d10Schristos int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
67*1dcdf01fSchristos int engdir = 0;
68*1dcdf01fSchristos char *prog;
69*1dcdf01fSchristos OPTION_CHOICE o;
7060662d10Schristos
71*1dcdf01fSchristos prog = opt_init(argc, argv, version_options);
72*1dcdf01fSchristos while ((o = opt_next()) != OPT_EOF) {
73*1dcdf01fSchristos switch (o) {
74*1dcdf01fSchristos case OPT_EOF:
75*1dcdf01fSchristos case OPT_ERR:
76*1dcdf01fSchristos opthelp:
77*1dcdf01fSchristos BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
7860662d10Schristos goto end;
79*1dcdf01fSchristos case OPT_HELP:
80*1dcdf01fSchristos opt_help(version_options);
81*1dcdf01fSchristos ret = 0;
82*1dcdf01fSchristos goto end;
83*1dcdf01fSchristos case OPT_B:
84*1dcdf01fSchristos dirty = date = 1;
85*1dcdf01fSchristos break;
86*1dcdf01fSchristos case OPT_D:
87*1dcdf01fSchristos dirty = dir = 1;
88*1dcdf01fSchristos break;
89*1dcdf01fSchristos case OPT_E:
90*1dcdf01fSchristos dirty = engdir = 1;
91*1dcdf01fSchristos break;
92*1dcdf01fSchristos case OPT_F:
93*1dcdf01fSchristos dirty = cflags = 1;
94*1dcdf01fSchristos break;
95*1dcdf01fSchristos case OPT_O:
96*1dcdf01fSchristos dirty = options = 1;
97*1dcdf01fSchristos break;
98*1dcdf01fSchristos case OPT_P:
99*1dcdf01fSchristos dirty = platform = 1;
100*1dcdf01fSchristos break;
101*1dcdf01fSchristos case OPT_R:
102*1dcdf01fSchristos dirty = seed = 1;
103*1dcdf01fSchristos break;
104*1dcdf01fSchristos case OPT_V:
105*1dcdf01fSchristos dirty = version = 1;
106*1dcdf01fSchristos break;
107*1dcdf01fSchristos case OPT_A:
108*1dcdf01fSchristos seed = options = cflags = version = date = platform = dir = engdir
109*1dcdf01fSchristos = 1;
110*1dcdf01fSchristos break;
11160662d10Schristos }
11260662d10Schristos }
113*1dcdf01fSchristos if (opt_num_rest() != 0) {
114*1dcdf01fSchristos BIO_printf(bio_err, "Extra parameters given.\n");
115*1dcdf01fSchristos goto opthelp;
116*1dcdf01fSchristos }
117*1dcdf01fSchristos if (!dirty)
118*1dcdf01fSchristos version = 1;
11960662d10Schristos
12060662d10Schristos if (version) {
121*1dcdf01fSchristos if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
122*1dcdf01fSchristos printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
123*1dcdf01fSchristos else
12460662d10Schristos printf("%s (Library: %s)\n",
125*1dcdf01fSchristos OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
12660662d10Schristos }
12760662d10Schristos if (date)
128*1dcdf01fSchristos printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
12960662d10Schristos if (platform)
130*1dcdf01fSchristos printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
13160662d10Schristos if (options) {
13260662d10Schristos printf("options: ");
13360662d10Schristos printf("%s ", BN_options());
13460662d10Schristos #ifndef OPENSSL_NO_MD2
13560662d10Schristos printf("%s ", MD2_options());
13660662d10Schristos #endif
13760662d10Schristos #ifndef OPENSSL_NO_RC4
13860662d10Schristos printf("%s ", RC4_options());
13960662d10Schristos #endif
14060662d10Schristos #ifndef OPENSSL_NO_DES
14160662d10Schristos printf("%s ", DES_options());
14260662d10Schristos #endif
14360662d10Schristos #ifndef OPENSSL_NO_IDEA
144*1dcdf01fSchristos printf("%s ", IDEA_options());
14560662d10Schristos #endif
14660662d10Schristos #ifndef OPENSSL_NO_BF
14760662d10Schristos printf("%s ", BF_options());
14860662d10Schristos #endif
14960662d10Schristos printf("\n");
15060662d10Schristos }
15160662d10Schristos if (cflags)
152*1dcdf01fSchristos printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
15360662d10Schristos if (dir)
154*1dcdf01fSchristos printf("%s\n", OpenSSL_version(OPENSSL_DIR));
155*1dcdf01fSchristos if (engdir)
156*1dcdf01fSchristos printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
157*1dcdf01fSchristos if (seed) {
158*1dcdf01fSchristos printf("Seeding source:");
159*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_RTDSC
160*1dcdf01fSchristos printf(" rtdsc");
161*1dcdf01fSchristos #endif
162*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_RDCPU
163*1dcdf01fSchristos printf(" rdrand ( rdseed rdrand )");
164*1dcdf01fSchristos #endif
165*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_LIBRANDOM
166*1dcdf01fSchristos printf(" C-library-random");
167*1dcdf01fSchristos #endif
168*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_GETRANDOM
169*1dcdf01fSchristos printf(" getrandom-syscall");
170*1dcdf01fSchristos #endif
171*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_DEVRANDOM
172*1dcdf01fSchristos {
173*1dcdf01fSchristos static const char *dev[] = { DEVRANDOM, NULL };
174*1dcdf01fSchristos printlist(" random-device", dev);
175*1dcdf01fSchristos }
176*1dcdf01fSchristos #endif
177*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_EGD
178*1dcdf01fSchristos {
179*1dcdf01fSchristos static const char *dev[] = { DEVRANDOM_EGD, NULL };
180*1dcdf01fSchristos printlist(" EGD", dev);
181*1dcdf01fSchristos }
182*1dcdf01fSchristos #endif
183*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_NONE
184*1dcdf01fSchristos printf(" none");
185*1dcdf01fSchristos #endif
186*1dcdf01fSchristos #ifdef OPENSSL_RAND_SEED_OS
187*1dcdf01fSchristos printf(" os-specific");
188*1dcdf01fSchristos #endif
189*1dcdf01fSchristos printf("\n");
190*1dcdf01fSchristos }
191*1dcdf01fSchristos ret = 0;
19260662d10Schristos end:
193*1dcdf01fSchristos return ret;
19460662d10Schristos }
195