version.c 5.2 KB

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