Home | History | Annotate | Line # | Download | only in apps
      1  1.1.1.2  christos /*
      2  1.1.1.2  christos  * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
      3      1.1  christos  *
      4  1.1.1.2  christos  * Licensed under the OpenSSL license (the "License").  You may not use
      5  1.1.1.2  christos  * this file except in compliance with the License.  You can obtain a copy
      6  1.1.1.2  christos  * in the file LICENSE in the source distribution or at
      7  1.1.1.2  christos  * https://www.openssl.org/source/license.html
      8      1.1  christos  */
      9      1.1  christos 
     10      1.1  christos #include <stdio.h>
     11      1.1  christos #include <stdlib.h>
     12      1.1  christos #include <string.h>
     13      1.1  christos #include "apps.h"
     14  1.1.1.2  christos #include "progs.h"
     15      1.1  christos #include <openssl/evp.h>
     16      1.1  christos #include <openssl/crypto.h>
     17      1.1  christos #include <openssl/bn.h>
     18      1.1  christos #ifndef OPENSSL_NO_MD2
     19      1.1  christos # include <openssl/md2.h>
     20      1.1  christos #endif
     21      1.1  christos #ifndef OPENSSL_NO_RC4
     22      1.1  christos # include <openssl/rc4.h>
     23      1.1  christos #endif
     24      1.1  christos #ifndef OPENSSL_NO_DES
     25      1.1  christos # include <openssl/des.h>
     26      1.1  christos #endif
     27      1.1  christos #ifndef OPENSSL_NO_IDEA
     28      1.1  christos # include <openssl/idea.h>
     29      1.1  christos #endif
     30      1.1  christos #ifndef OPENSSL_NO_BF
     31      1.1  christos # include <openssl/blowfish.h>
     32      1.1  christos #endif
     33      1.1  christos 
     34  1.1.1.2  christos typedef enum OPTION_choice {
     35  1.1.1.2  christos     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
     36  1.1.1.2  christos     OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
     37  1.1.1.2  christos } OPTION_CHOICE;
     38  1.1.1.2  christos 
     39  1.1.1.2  christos const OPTIONS version_options[] = {
     40  1.1.1.2  christos     {"help", OPT_HELP, '-', "Display this summary"},
     41  1.1.1.2  christos     {"a", OPT_A, '-', "Show all data"},
     42  1.1.1.2  christos     {"b", OPT_B, '-', "Show build date"},
     43  1.1.1.2  christos     {"d", OPT_D, '-', "Show configuration directory"},
     44  1.1.1.2  christos     {"e", OPT_E, '-', "Show engines directory"},
     45  1.1.1.2  christos     {"f", OPT_F, '-', "Show compiler flags used"},
     46  1.1.1.2  christos     {"o", OPT_O, '-', "Show some internal datatype options"},
     47  1.1.1.2  christos     {"p", OPT_P, '-', "Show target build platform"},
     48  1.1.1.2  christos     {"r", OPT_R, '-', "Show random seeding options"},
     49  1.1.1.2  christos     {"v", OPT_V, '-', "Show library version"},
     50  1.1.1.2  christos     {NULL}
     51  1.1.1.2  christos };
     52      1.1  christos 
     53  1.1.1.2  christos #if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
     54  1.1.1.2  christos static void printlist(const char *prefix, const char **dev)
     55  1.1.1.2  christos {
     56  1.1.1.2  christos     printf("%s (", prefix);
     57  1.1.1.2  christos     for ( ; *dev != NULL; dev++)
     58  1.1.1.2  christos         printf(" \"%s\"", *dev);
     59  1.1.1.2  christos     printf(" )");
     60  1.1.1.2  christos }
     61  1.1.1.2  christos #endif
     62      1.1  christos 
     63  1.1.1.2  christos int version_main(int argc, char **argv)
     64      1.1  christos {
     65  1.1.1.2  christos     int ret = 1, dirty = 0, seed = 0;
     66      1.1  christos     int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
     67  1.1.1.2  christos     int engdir = 0;
     68  1.1.1.2  christos     char *prog;
     69  1.1.1.2  christos     OPTION_CHOICE o;
     70  1.1.1.2  christos 
     71  1.1.1.2  christos     prog = opt_init(argc, argv, version_options);
     72  1.1.1.2  christos     while ((o = opt_next()) != OPT_EOF) {
     73  1.1.1.2  christos         switch (o) {
     74  1.1.1.2  christos         case OPT_EOF:
     75  1.1.1.2  christos         case OPT_ERR:
     76  1.1.1.2  christos opthelp:
     77  1.1.1.2  christos             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
     78      1.1  christos             goto end;
     79  1.1.1.2  christos         case OPT_HELP:
     80  1.1.1.2  christos             opt_help(version_options);
     81  1.1.1.2  christos             ret = 0;
     82  1.1.1.2  christos             goto end;
     83  1.1.1.2  christos         case OPT_B:
     84  1.1.1.2  christos             dirty = date = 1;
     85  1.1.1.2  christos             break;
     86  1.1.1.2  christos         case OPT_D:
     87  1.1.1.2  christos             dirty = dir = 1;
     88  1.1.1.2  christos             break;
     89  1.1.1.2  christos         case OPT_E:
     90  1.1.1.2  christos             dirty = engdir = 1;
     91  1.1.1.2  christos             break;
     92  1.1.1.2  christos         case OPT_F:
     93  1.1.1.2  christos             dirty = cflags = 1;
     94  1.1.1.2  christos             break;
     95  1.1.1.2  christos         case OPT_O:
     96  1.1.1.2  christos             dirty = options = 1;
     97  1.1.1.2  christos             break;
     98  1.1.1.2  christos         case OPT_P:
     99  1.1.1.2  christos             dirty = platform = 1;
    100  1.1.1.2  christos             break;
    101  1.1.1.2  christos         case OPT_R:
    102  1.1.1.2  christos             dirty = seed = 1;
    103  1.1.1.2  christos             break;
    104  1.1.1.2  christos         case OPT_V:
    105  1.1.1.2  christos             dirty = version = 1;
    106  1.1.1.2  christos             break;
    107  1.1.1.2  christos         case OPT_A:
    108  1.1.1.2  christos             seed = options = cflags = version = date = platform = dir = engdir
    109  1.1.1.2  christos                 = 1;
    110  1.1.1.2  christos             break;
    111      1.1  christos         }
    112      1.1  christos     }
    113  1.1.1.2  christos     if (opt_num_rest() != 0) {
    114  1.1.1.2  christos         BIO_printf(bio_err, "Extra parameters given.\n");
    115  1.1.1.2  christos         goto opthelp;
    116  1.1.1.2  christos     }
    117  1.1.1.2  christos     if (!dirty)
    118  1.1.1.2  christos         version = 1;
    119      1.1  christos 
    120      1.1  christos     if (version) {
    121  1.1.1.2  christos         if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
    122  1.1.1.2  christos             printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
    123  1.1.1.2  christos         else
    124      1.1  christos             printf("%s (Library: %s)\n",
    125  1.1.1.2  christos                    OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
    126      1.1  christos     }
    127      1.1  christos     if (date)
    128  1.1.1.2  christos         printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
    129      1.1  christos     if (platform)
    130  1.1.1.2  christos         printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
    131      1.1  christos     if (options) {
    132      1.1  christos         printf("options:  ");
    133      1.1  christos         printf("%s ", BN_options());
    134      1.1  christos #ifndef OPENSSL_NO_MD2
    135      1.1  christos         printf("%s ", MD2_options());
    136      1.1  christos #endif
    137      1.1  christos #ifndef OPENSSL_NO_RC4
    138      1.1  christos         printf("%s ", RC4_options());
    139      1.1  christos #endif
    140      1.1  christos #ifndef OPENSSL_NO_DES
    141      1.1  christos         printf("%s ", DES_options());
    142      1.1  christos #endif
    143      1.1  christos #ifndef OPENSSL_NO_IDEA
    144  1.1.1.2  christos         printf("%s ", IDEA_options());
    145      1.1  christos #endif
    146      1.1  christos #ifndef OPENSSL_NO_BF
    147      1.1  christos         printf("%s ", BF_options());
    148      1.1  christos #endif
    149      1.1  christos         printf("\n");
    150      1.1  christos     }
    151      1.1  christos     if (cflags)
    152  1.1.1.2  christos         printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
    153      1.1  christos     if (dir)
    154  1.1.1.2  christos         printf("%s\n", OpenSSL_version(OPENSSL_DIR));
    155  1.1.1.2  christos     if (engdir)
    156  1.1.1.2  christos         printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
    157  1.1.1.2  christos     if (seed) {
    158  1.1.1.2  christos         printf("Seeding source:");
    159  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_RTDSC
    160  1.1.1.2  christos         printf(" rtdsc");
    161  1.1.1.2  christos #endif
    162  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_RDCPU
    163  1.1.1.2  christos         printf(" rdrand ( rdseed rdrand )");
    164  1.1.1.2  christos #endif
    165  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_LIBRANDOM
    166  1.1.1.2  christos         printf(" C-library-random");
    167  1.1.1.2  christos #endif
    168  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_GETRANDOM
    169  1.1.1.2  christos         printf(" getrandom-syscall");
    170  1.1.1.2  christos #endif
    171  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_DEVRANDOM
    172  1.1.1.2  christos         {
    173  1.1.1.2  christos             static const char *dev[] = { DEVRANDOM, NULL };
    174  1.1.1.2  christos             printlist(" random-device", dev);
    175  1.1.1.2  christos         }
    176  1.1.1.2  christos #endif
    177  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_EGD
    178  1.1.1.2  christos         {
    179  1.1.1.2  christos             static const char *dev[] = { DEVRANDOM_EGD, NULL };
    180  1.1.1.2  christos             printlist(" EGD", dev);
    181  1.1.1.2  christos         }
    182  1.1.1.2  christos #endif
    183  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_NONE
    184  1.1.1.2  christos         printf(" none");
    185  1.1.1.2  christos #endif
    186  1.1.1.2  christos #ifdef OPENSSL_RAND_SEED_OS
    187  1.1.1.2  christos         printf(" os-specific");
    188  1.1.1.2  christos #endif
    189  1.1.1.2  christos         printf("\n");
    190  1.1.1.2  christos     }
    191  1.1.1.2  christos     ret = 0;
    192      1.1  christos  end:
    193  1.1.1.2  christos     return ret;
    194      1.1  christos }
    195