version.c 4.5 KB
Newer Older
R
Rich Salz 已提交
1
/*
2
 * Copyright 1995-2017 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 15
#include <openssl/evp.h>
#include <openssl/crypto.h>
16
#include <openssl/bn.h>
17 18 19 20 21 22 23
#ifndef OPENSSL_NO_MD2
# include <openssl/md2.h>
#endif
#ifndef OPENSSL_NO_RC4
# include <openssl/rc4.h>
#endif
#ifndef OPENSSL_NO_DES
24
# include <openssl/des.h>
25 26 27 28 29 30 31
#endif
#ifndef OPENSSL_NO_IDEA
# include <openssl/idea.h>
#endif
#ifndef OPENSSL_NO_BF
# include <openssl/blowfish.h>
#endif
32

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

F
FdaSilvaYY 已提交
38
const OPTIONS version_options[] = {
39 40 41 42
    {"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 已提交
43
    {"e", OPT_E, '-', "Show engines directory"},
44 45 46
    {"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 已提交
47
    {"r", OPT_R, '-', "Show random seeding options"},
48 49 50
    {"v", OPT_V, '-', "Show library version"},
    {NULL}
};
51

52
int version_main(int argc, char **argv)
53
{
R
Rich Salz 已提交
54
    int ret = 1, dirty = 0, seed = 0;
55
    int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
56
    int engdir = 0;
57 58
    char *prog;
    OPTION_CHOICE o;
59

60 61 62 63 64 65
    prog = opt_init(argc, argv, version_options);
    while ((o = opt_next()) != OPT_EOF) {
        switch (o) {
        case OPT_EOF:
        case OPT_ERR:
            BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
66
            goto end;
67 68 69 70 71 72 73 74 75 76
        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;
77 78 79
        case OPT_E:
            dirty = engdir = 1;
            break;
80 81 82 83 84 85 86 87 88
        case OPT_F:
            dirty = cflags = 1;
            break;
        case OPT_O:
            dirty = options = 1;
            break;
        case OPT_P:
            dirty = platform = 1;
            break;
R
Rich Salz 已提交
89 90 91
        case OPT_R:
            dirty = seed = 1;
            break;
92 93 94 95
        case OPT_V:
            dirty = version = 1;
            break;
        case OPT_A:
R
Rich Salz 已提交
96
            seed = cflags = version = date = platform = dir = engdir = 1;
97
            break;
98 99
        }
    }
100 101
    if (!dirty)
        version = 1;
102

103
    if (version) {
104
        if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
R
Rich Salz 已提交
105
            printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
106
        else
107
            printf("%s (Library: %s)\n",
R
Rich Salz 已提交
108
                   OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
109 110
    }
    if (date)
R
Rich Salz 已提交
111
        printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
112
    if (platform)
R
Rich Salz 已提交
113
        printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
114 115 116
    if (options) {
        printf("options:  ");
        printf("%s ", BN_options());
117
#ifndef OPENSSL_NO_MD2
118
        printf("%s ", MD2_options());
119
#endif
120
#ifndef OPENSSL_NO_RC4
121
        printf("%s ", RC4_options());
122
#endif
123
#ifndef OPENSSL_NO_DES
124
        printf("%s ", DES_options());
125
#endif
126
#ifndef OPENSSL_NO_IDEA
R
Rich Salz 已提交
127
        printf("%s ", IDEA_options());
128
#endif
129
#ifndef OPENSSL_NO_BF
130
        printf("%s ", BF_options());
131
#endif
132 133 134
        printf("\n");
    }
    if (cflags)
R
Rich Salz 已提交
135
        printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
136
    if (dir)
R
Rich Salz 已提交
137
        printf("%s\n", OpenSSL_version(OPENSSL_DIR));
138 139
    if (engdir)
        printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
R
Rich Salz 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    if (seed) {
        printf("Seeding source:");
#ifdef OPENSSL_RAND_SEED_RTDSC
        printf(" rtdsc");
#endif
#ifdef OPENSSL_RAND_SEED_RDCPU
        printf(" rdrand-hardware");
#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
        printf(" random-device");
#endif
#ifdef OPENSSL_RAND_SEED_EGD
        printf(" EGD");
#endif
#ifdef OPENSSL_RAND_SEED_NONE
        printf(" none");
#endif
#ifdef OPENSSL_RAND_SEED_OS
        printf(" os-specific");
#endif
        printf("\n");
    }
168
    ret = 0;
169
 end:
170
    return (ret);
171
}