version.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright 1995-2018 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. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "apps.h"
  13. #include "progs.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. typedef enum OPTION_choice {
  33. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
  34. OPT_B, OPT_D, OPT_E, OPT_F, OPT_O, OPT_P, OPT_V, OPT_A, OPT_R
  35. } OPTION_CHOICE;
  36. const OPTIONS version_options[] = {
  37. {"help", OPT_HELP, '-', "Display this summary"},
  38. {"a", OPT_A, '-', "Show all data"},
  39. {"b", OPT_B, '-', "Show build date"},
  40. {"d", OPT_D, '-', "Show configuration directory"},
  41. {"e", OPT_E, '-', "Show engines directory"},
  42. {"f", OPT_F, '-', "Show compiler flags used"},
  43. {"o", OPT_O, '-', "Show some internal datatype options"},
  44. {"p", OPT_P, '-', "Show target build platform"},
  45. {"r", OPT_R, '-', "Show random seeding options"},
  46. {"v", OPT_V, '-', "Show library version"},
  47. {NULL}
  48. };
  49. #if defined(OPENSSL_RAND_SEED_DEVRANDOM) || defined(OPENSSL_RAND_SEED_EGD)
  50. static void printlist(const char *prefix, const char **dev)
  51. {
  52. printf("%s (", prefix);
  53. for ( ; *dev != NULL; dev++)
  54. printf(" \"%s\"", *dev);
  55. printf(" )");
  56. }
  57. #endif
  58. int version_main(int argc, char **argv)
  59. {
  60. int ret = 1, dirty = 0, seed = 0;
  61. int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
  62. int engdir = 0;
  63. char *prog;
  64. OPTION_CHOICE o;
  65. prog = opt_init(argc, argv, version_options);
  66. while ((o = opt_next()) != OPT_EOF) {
  67. switch (o) {
  68. case OPT_EOF:
  69. case OPT_ERR:
  70. opthelp:
  71. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  72. goto end;
  73. case OPT_HELP:
  74. opt_help(version_options);
  75. ret = 0;
  76. goto end;
  77. case OPT_B:
  78. dirty = date = 1;
  79. break;
  80. case OPT_D:
  81. dirty = dir = 1;
  82. break;
  83. case OPT_E:
  84. dirty = engdir = 1;
  85. break;
  86. case OPT_F:
  87. dirty = cflags = 1;
  88. break;
  89. case OPT_O:
  90. dirty = options = 1;
  91. break;
  92. case OPT_P:
  93. dirty = platform = 1;
  94. break;
  95. case OPT_R:
  96. dirty = seed = 1;
  97. break;
  98. case OPT_V:
  99. dirty = version = 1;
  100. break;
  101. case OPT_A:
  102. seed = options = cflags = version = date = platform = dir = engdir
  103. = 1;
  104. break;
  105. }
  106. }
  107. if (opt_num_rest() != 0) {
  108. BIO_printf(bio_err, "Extra parameters given.\n");
  109. goto opthelp;
  110. }
  111. if (!dirty)
  112. version = 1;
  113. if (version) {
  114. if (OpenSSL_version_num() == OPENSSL_VERSION_NUMBER)
  115. printf("%s\n", OpenSSL_version(OPENSSL_VERSION));
  116. else
  117. printf("%s (Library: %s)\n",
  118. OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
  119. }
  120. if (date)
  121. printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON));
  122. if (platform)
  123. printf("%s\n", OpenSSL_version(OPENSSL_PLATFORM));
  124. if (options) {
  125. printf("options: ");
  126. printf("%s ", BN_options());
  127. #ifndef OPENSSL_NO_MD2
  128. printf("%s ", MD2_options());
  129. #endif
  130. #ifndef OPENSSL_NO_RC4
  131. printf("%s ", RC4_options());
  132. #endif
  133. #ifndef OPENSSL_NO_DES
  134. printf("%s ", DES_options());
  135. #endif
  136. #ifndef OPENSSL_NO_IDEA
  137. printf("%s ", IDEA_options());
  138. #endif
  139. #ifndef OPENSSL_NO_BF
  140. printf("%s ", BF_options());
  141. #endif
  142. printf("\n");
  143. }
  144. if (cflags)
  145. printf("%s\n", OpenSSL_version(OPENSSL_CFLAGS));
  146. if (dir)
  147. printf("%s\n", OpenSSL_version(OPENSSL_DIR));
  148. if (engdir)
  149. printf("%s\n", OpenSSL_version(OPENSSL_ENGINES_DIR));
  150. if (seed) {
  151. printf("Seeding source:");
  152. #ifdef OPENSSL_RAND_SEED_RTDSC
  153. printf(" rtdsc");
  154. #endif
  155. #ifdef OPENSSL_RAND_SEED_RDCPU
  156. printf(" rdrand ( rdseed rdrand )");
  157. #endif
  158. #ifdef OPENSSL_RAND_SEED_LIBRANDOM
  159. printf(" C-library-random");
  160. #endif
  161. #ifdef OPENSSL_RAND_SEED_GETRANDOM
  162. printf(" getrandom-syscall");
  163. #endif
  164. #ifdef OPENSSL_RAND_SEED_DEVRANDOM
  165. {
  166. static const char *dev[] = { DEVRANDOM, NULL };
  167. printlist(" random-device", dev);
  168. }
  169. #endif
  170. #ifdef OPENSSL_RAND_SEED_EGD
  171. {
  172. static const char *dev[] = { DEVRANDOM_EGD, NULL };
  173. printlist(" EGD", dev);
  174. }
  175. #endif
  176. #ifdef OPENSSL_RAND_SEED_NONE
  177. printf(" none");
  178. #endif
  179. #ifdef OPENSSL_RAND_SEED_OS
  180. printf(" os-specific");
  181. #endif
  182. printf("\n");
  183. }
  184. ret = 0;
  185. end:
  186. return ret;
  187. }