]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/version.c
Security hardening: Expose Build flags for Position Independed Execution (PIE)
[thirdparty/openssl.git] / apps / version.c
CommitLineData
846e33c7 1/*
aff636a4 2 * Copyright 1995-2021 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>
d02b48c6 18
7e1b7485 19typedef enum OPTION_choice {
b0f96018 20 OPT_COMMON,
363e941e 21 OPT_B, OPT_D, OPT_E, OPT_M, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R, OPT_C
7e1b7485 22} OPTION_CHOICE;
d02b48c6 23
44c83ebd 24const OPTIONS version_options[] = {
5388f986 25 OPT_SECTION("General"),
7e1b7485 26 {"help", OPT_HELP, '-', "Display this summary"},
5388f986
RS
27
28 OPT_SECTION("Output"),
7e1b7485
RS
29 {"a", OPT_A, '-', "Show all data"},
30 {"b", OPT_B, '-', "Show build date"},
31 {"d", OPT_D, '-', "Show configuration directory"},
01a2ade0 32 {"e", OPT_E, '-', "Show engines directory"},
47ca8338 33 {"m", OPT_M, '-', "Show modules directory"},
7e1b7485
RS
34 {"f", OPT_F, '-', "Show compiler flags used"},
35 {"o", OPT_O, '-', "Show some internal datatype options"},
36 {"p", OPT_P, '-', "Show target build platform"},
8389ec4b 37 {"r", OPT_R, '-', "Show random seeding options"},
7e1b7485 38 {"v", OPT_V, '-', "Show library version"},
363e941e 39 {"c", OPT_C, '-', "Show CPU settings info"},
7e1b7485
RS
40 {NULL}
41};
667ac4ec 42
7e1b7485 43int version_main(int argc, char **argv)
0f113f3e 44{
8389ec4b 45 int ret = 1, dirty = 0, seed = 0;
0f113f3e 46 int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
363e941e 47 int engdir = 0, moddir = 0, cpuinfo = 0;
7e1b7485
RS
48 char *prog;
49 OPTION_CHOICE o;
d02b48c6 50
7e1b7485
RS
51 prog = opt_init(argc, argv, version_options);
52 while ((o = opt_next()) != OPT_EOF) {
53 switch (o) {
54 case OPT_EOF:
55 case OPT_ERR:
c27363f5 56opthelp:
7e1b7485 57 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
0f113f3e 58 goto end;
7e1b7485
RS
59 case OPT_HELP:
60 opt_help(version_options);
61 ret = 0;
62 goto end;
63 case OPT_B:
64 dirty = date = 1;
65 break;
66 case OPT_D:
67 dirty = dir = 1;
68 break;
e09621ff
RL
69 case OPT_E:
70 dirty = engdir = 1;
71 break;
47ca8338
RL
72 case OPT_M:
73 dirty = moddir = 1;
74 break;
7e1b7485
RS
75 case OPT_F:
76 dirty = cflags = 1;
77 break;
78 case OPT_O:
79 dirty = options = 1;
80 break;
81 case OPT_P:
82 dirty = platform = 1;
83 break;
8389ec4b
RS
84 case OPT_R:
85 dirty = seed = 1;
86 break;
7e1b7485
RS
87 case OPT_V:
88 dirty = version = 1;
89 break;
363e941e
BE
90 case OPT_C:
91 dirty = cpuinfo = 1;
92 break;
7e1b7485 93 case OPT_A:
47ca8338 94 seed = options = cflags = version = date = platform
363e941e 95 = dir = engdir = moddir = cpuinfo
b971b05e 96 = 1;
7e1b7485 97 break;
0f113f3e
MC
98 }
99 }
021410ea
RS
100
101 /* No extra arguments. */
d9f07357 102 if (!opt_check_rest_arg(NULL))
c27363f5 103 goto opthelp;
021410ea 104
7e1b7485
RS
105 if (!dirty)
106 version = 1;
d02b48c6 107
1dea43c3
P
108 if (version)
109 printf("%s (Library: %s)\n",
110 OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
0f113f3e 111 if (date)
b0700d2c 112 printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
0f113f3e 113 if (platform)
b0700d2c 114 printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
0f113f3e 115 if (options) {
bddf965d
P
116 printf("options: ");
117 printf(" %s", BN_options());
0f113f3e
MC
118 printf("\n");
119 }
120 if (cflags)
b0700d2c 121 printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
0f113f3e 122 if (dir)
b0700d2c 123 printf("%s\n", OpenSSL_version(OPENSSL_DIR));
e09621ff
RL
124 if (engdir)
125 printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
47ca8338
RL
126 if (moddir)
127 printf("%s\n", OpenSSL_version(OPENSSL_MODULES_DIR));
363e941e
BE
128 if (seed) {
129 const char *src = OPENSSL_info(OPENSSL_INFO_SEED_SOURCE);
130 printf("Seeding source: %s\n", src ? src : "N/A");
131 }
132 if (cpuinfo)
133 printf("%s\n", OpenSSL_version(OPENSSL_CPU_INFO));
7e1b7485 134 ret = 0;
0f113f3e 135 end:
26a7d938 136 return ret;
0f113f3e 137}
08073700
RB
138
139
140#if defined(__TANDEM) && defined(OPENSSL_VPROC)
141/*
142 * Define a VPROC function for the openssl program.
143 * This is used by platform version identification tools.
144 * Do not inline this procedure or make it static.
145 */
146# define OPENSSL_VPROC_STRING_(x) x##_OPENSSL
147# define OPENSSL_VPROC_STRING(x) OPENSSL_VPROC_STRING_(x)
148# define OPENSSL_VPROC_FUNC OPENSSL_VPROC_STRING(OPENSSL_VPROC)
149void OPENSSL_VPROC_FUNC(void) {}
150#endif