Fix a crash in tls_construct_client_certificate.
[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
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     {"v", OPT_V, '-', "Show library version"},
48     {NULL}
49 };
50
51 int version_main(int argc, char **argv)
52 {
53     int ret = 1, dirty = 0;
54     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
55     int engdir = 0;
56     char *prog;
57     OPTION_CHOICE o;
58
59     prog = opt_init(argc, argv, version_options);
60     while ((o = opt_next()) != OPT_EOF) {
61         switch (o) {
62         case OPT_EOF:
63         case OPT_ERR:
64             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
65             goto end;
66         case OPT_HELP:
67             opt_help(version_options);
68             ret = 0;
69             goto end;
70         case OPT_B:
71             dirty = date = 1;
72             break;
73         case OPT_D:
74             dirty = dir = 1;
75             break;
76         case OPT_E:
77             dirty = engdir = 1;
78             break;
79         case OPT_F:
80             dirty = cflags = 1;
81             break;
82         case OPT_O:
83             dirty = options = 1;
84             break;
85         case OPT_P:
86             dirty = platform = 1;
87             break;
88         case OPT_V:
89             dirty = version = 1;
90             break;
91         case OPT_A:
92             cflags = version = date = platform = dir = engdir = 1;
93             break;
94         }
95     }
96     if (!dirty)
97         version = 1;
98
99     if (version) {
100         if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
101             printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
102         else
103             printf("%s (Library: %s)\n",
104                    OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
105     }
106     if (date)
107         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
108     if (platform)
109         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
110     if (options) {
111         printf("options:  ");
112         printf("%s ", BN_options());
113 #ifndef OPENSSL_NO_MD2
114         printf("%s ", MD2_options());
115 #endif
116 #ifndef OPENSSL_NO_RC4
117         printf("%s ", RC4_options());
118 #endif
119 #ifndef OPENSSL_NO_DES
120         printf("%s ", DES_options());
121 #endif
122 #ifndef OPENSSL_NO_IDEA
123         printf("%s ", IDEA_options());
124 #endif
125 #ifndef OPENSSL_NO_BF
126         printf("%s ", BF_options());
127 #endif
128         printf("\n");
129     }
130     if (cflags)
131         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
132     if (dir)
133         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
134     if (engdir)
135         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
136     ret = 0;
137  end:
138     return (ret);
139 }