version.c 5.0 KB
Newer Older
R
Rich Salz 已提交
1
/*
M
Matt Caswell 已提交
2
 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3
 *
R
Rich Salz 已提交
4 5 6 7
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
8
 */
9 10 11 12 13

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "apps.h"
14
#include "progs.h"
15 16
#include <openssl/evp.h>
#include <openssl/crypto.h>
17
#include <openssl/bn.h>
18 19 20 21 22 23 24
#ifndef OPENSSL_NO_MD2
# include <openssl/md2.h>
#endif
#ifndef OPENSSL_NO_RC4
# include <openssl/rc4.h>
#endif
#ifndef OPENSSL_NO_DES
25
# include <openssl/des.h>
26 27 28 29 30 31 32
#endif
#ifndef OPENSSL_NO_IDEA
# include <openssl/idea.h>
#endif
#ifndef OPENSSL_NO_BF
# include <openssl/blowfish.h>
#endif
33

34 35
typedef enum OPTION_choice {
    OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
R
Rich Salz 已提交
36
    OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
37
} OPTION_CHOICE;
38

F
FdaSilvaYY 已提交
39
const OPTIONS version_options[] = {
40 41 42 43
    {"help", OPT_HELP, '-', "Display this summary"},
    {"a", OPT_A, '-', "Show all data"},
    {"b", OPT_B, '-', "Show build date"},
    {"d", OPT_D, '-', "Show configuration directory"},
D
typo  
Dr. Stephen Henson 已提交
44
    {"e", OPT_E, '-', "Show engines directory"},
45 46 47
    {"f", OPT_F, '-', "Show compiler flags used"},
    {"o", OPT_O, '-', "Show some internal datatype options"},
    {"p", OPT_P, '-', "Show target build platform"},
R
Rich Salz 已提交
48
    {"r", OPT_R, '-', "Show random seeding options"},
49 50 51
    {"v", OPT_V, '-', "Show library version"},
    {NULL}
};
52

R
Rich Salz 已提交
53 54 55 56 57 58 59 60 61 62
#if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
static void printlist(const char *prefix, const char **dev)
{
    printf("%s (", prefix);
    for ( ; *dev != NULL; dev++)
        printf(" \"%s\"", *dev);
    printf(" )");
}
#endif

63
int version_main(int argc, char **argv)
64
{
R
Rich Salz 已提交
65
    int ret = 1, dirty = 0, seed = 0;
66
    int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
67
    int engdir = 0;
68 69
    char *prog;
    OPTION_CHOICE o;
70

71 72 73 74 75
    prog = opt_init(argc, argv, version_options);
    while ((o = opt_next()) != OPT_EOF) {
        switch (o) {
        case OPT_EOF:
        case OPT_ERR:
76
opthelp:
77
            BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
78
            goto end;
79 80 81 82 83 84 85 86 87 88
        case OPT_HELP:
            opt_help(version_options);
            ret = 0;
            goto end;
        case OPT_B:
            dirty = date = 1;
            break;
        case OPT_D:
            dirty = dir = 1;
            break;
89 90 91
        case OPT_E:
            dirty = engdir = 1;
            break;
92 93 94 95 96 97 98 99 100
        case OPT_F:
            dirty = cflags = 1;
            break;
        case OPT_O:
            dirty = options = 1;
            break;
        case OPT_P:
            dirty = platform = 1;
            break;
R
Rich Salz 已提交
101 102 103
        case OPT_R:
            dirty = seed = 1;
            break;
104 105 106 107
        case OPT_V:
            dirty = version = 1;
            break;
        case OPT_A:
R
Rich Salz 已提交
108
            seed = cflags = version = date = platform = dir = engdir = 1;
109
            break;
110 111
        }
    }
112 113 114 115
    if (opt_num_rest() != 0) {
        BIO_printf(bio_err, "Extra parameters given.\n");
        goto opthelp;
    }
116 117
    if (!dirty)
        version = 1;
118

119
    if (version) {
120
        if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
R
Rich Salz 已提交
121
            printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
122
        else
123
            printf("%s (Library: %s)\n",
R
Rich Salz 已提交
124
                   OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
125 126
    }
    if (date)
R
Rich Salz 已提交
127
        printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
128
    if (platform)
R
Rich Salz 已提交
129
        printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
130 131 132
    if (options) {
        printf("options:  ");
        printf("%s ", BN_options());
133
#ifndef OPENSSL_NO_MD2
134
        printf("%s ", MD2_options());
135
#endif
136
#ifndef OPENSSL_NO_RC4
137
        printf("%s ", RC4_options());
138
#endif
139
#ifndef OPENSSL_NO_DES
140
        printf("%s ", DES_options());
141
#endif
142
#ifndef OPENSSL_NO_IDEA
R
Rich Salz 已提交
143
        printf("%s ", IDEA_options());
144
#endif
145
#ifndef OPENSSL_NO_BF
146
        printf("%s ", BF_options());
147
#endif
148 149 150
        printf("\n");
    }
    if (cflags)
R
Rich Salz 已提交
151
        printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
152
    if (dir)
R
Rich Salz 已提交
153
        printf("%s\n", OpenSSL_version(OPENSSL_DIR));
154 155
    if (engdir)
        printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
R
Rich Salz 已提交
156 157 158 159 160 161
    if (seed) {
        printf("Seeding source:");
#ifdef OPENSSL_RAND_SEED_RTDSC
        printf(" rtdsc");
#endif
#ifdef OPENSSL_RAND_SEED_RDCPU
R
Rich Salz 已提交
162
        printf(" rdrand ( rdseed rdrand )");
R
Rich Salz 已提交
163 164 165 166 167 168 169 170
#endif
#ifdef OPENSSL_RAND_SEED_LIBRANDOM
        printf(" C-library-random");
#endif
#ifdef OPENSSL_RAND_SEED_GETRANDOM
        printf(" getrandom-syscall");
#endif
#ifdef OPENSSL_RAND_SEED_DEVRANDOM
R
Rich Salz 已提交
171 172 173 174
        {
            static const char *dev[] = { DEVRANDOM, NULL };
            printlist(" random-device", dev);
        }
R
Rich Salz 已提交
175 176
#endif
#ifdef OPENSSL_RAND_SEED_EGD
R
Rich Salz 已提交
177 178 179 180
        {
            static const char *dev[] = { DEVRANDOM_EGD, NULL };
            printlist(" EGD", dev);
        }
R
Rich Salz 已提交
181 182 183 184 185 186 187 188 189
#endif
#ifdef OPENSSL_RAND_SEED_NONE
        printf(" none");
#endif
#ifdef OPENSSL_RAND_SEED_OS
        printf(" os-specific");
#endif
        printf("\n");
    }
190
    ret = 0;
191
 end:
K
KaoruToda 已提交
192
    return ret;
193
}