You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
12 KiB

  1. From a513cb5fed8c4f63d60b6da12ae9f63a258a9e44 Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <cote2004-github@yahoo.com>
  3. Date: Wed, 6 Jun 2018 08:20:35 -0300
  4. Subject: [PATCH] dhparams: Add pregenerated .c file to the repository.
  5. The version of dhparams.c generated by any given version of OpenSSL or
  6. LibreSSL might work only with that version of the library. This can be
  7. inconvenient for cross-compiling if the "openssl" program on the build
  8. machine has a different version from the library on the host where OVS will
  9. run, since it could generate code that won't compile.
  10. This commit fixes the problem by generating dhparams.c that works on the
  11. currently important versions of OpenSSL and LibreSSL.
  12. Submitted-at: https://github.com/openvswitch/ovs/pull/235
  13. Signed-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
  14. Signed-off-by: Ben Pfaff <blp@ovn.org>
  15. ---
  16. build-aux/automake.mk | 1 +
  17. build-aux/generate-dhparams-c | 31 +++++++
  18. lib/automake.mk | 17 ++--
  19. lib/dhparams.c | 192 ++++++++++++++++++++++++++++++++++++++++++
  20. 5 files changed, 233 insertions(+), 9 deletions(-)
  21. create mode 100755 build-aux/generate-dhparams-c
  22. create mode 100644 lib/dhparams.c
  23. diff --git a/build-aux/automake.mk b/build-aux/automake.mk
  24. index a1f2f856f..3a3b31ce1 100644
  25. --- a/build-aux/automake.mk
  26. +++ b/build-aux/automake.mk
  27. @@ -4,6 +4,7 @@ EXTRA_DIST += \
  28. build-aux/cksum-schema-check \
  29. build-aux/dist-docs \
  30. build-aux/dpdkstrip.py \
  31. + build-aux/generate-dhparams-c \
  32. build-aux/sodepends.py \
  33. build-aux/soexpand.py \
  34. build-aux/text2c \
  35. diff --git a/build-aux/generate-dhparams-c b/build-aux/generate-dhparams-c
  36. new file mode 100755
  37. index 000000000..a75e1d5a7
  38. --- /dev/null
  39. +++ b/build-aux/generate-dhparams-c
  40. @@ -0,0 +1,31 @@
  41. +#! /bin/sh -e
  42. +
  43. +cat <<'EOF'
  44. +/* Generated automatically; do not modify! -*- buffer-read-only: t -*-
  45. + *
  46. + * If you do need to regenerate this file, run "make generate-dhparams-c". */
  47. +
  48. +#include <config.h>
  49. +#include "lib/dhparams.h"
  50. +#include "openvswitch/util.h"
  51. +
  52. +static int
  53. +my_DH_set0_pqg(DH *dh, BIGNUM *p, const BIGNUM **q OVS_UNUSED, BIGNUM *g)
  54. +{
  55. + ovs_assert(q == NULL);
  56. +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
  57. + dh->p = p;
  58. + dh->g = g;
  59. + return 1;
  60. +#else
  61. + return DH_set0_pqg(dh, p, NULL, g);
  62. +#endif
  63. +}
  64. +EOF
  65. +(openssl dhparam -C -in lib/dh1024.pem -noout &&
  66. +openssl dhparam -C -in lib/dh2048.pem -noout &&
  67. +openssl dhparam -C -in lib/dh4096.pem -noout) | sed '
  68. + s/\(get_dh[0-9]*\)()/\1(void)/
  69. + s/\(DH_set0_pqg\)/my_\1/
  70. + s/[ ]*$//
  71. +'
  72. diff --git a/lib/automake.mk b/lib/automake.mk
  73. index fb781e847..3bec3fd56 100644
  74. --- a/lib/automake.mk
  75. +++ b/lib/automake.mk
  76. @@ -450,15 +450,16 @@ lib_libopenvswitch_la_SOURCES += \
  77. lib/route-table-bsd.c
  78. endif
  79. +.PHONY: generate-dhparams-c
  80. if HAVE_OPENSSL
  81. -lib_libopenvswitch_la_SOURCES += lib/stream-ssl.c
  82. -nodist_lib_libopenvswitch_la_SOURCES += lib/dhparams.c
  83. -lib/dhparams.c: lib/dh1024.pem lib/dh2048.pem lib/dh4096.pem
  84. - $(AM_V_GEN)(echo '#include "lib/dhparams.h"' && \
  85. - openssl dhparam -C -in $(srcdir)/lib/dh1024.pem -noout && \
  86. - openssl dhparam -C -in $(srcdir)/lib/dh2048.pem -noout && \
  87. - openssl dhparam -C -in $(srcdir)/lib/dh4096.pem -noout) \
  88. - | sed 's/\(get_dh[0-9]*\)()/\1(void)/' > lib/dhparams.c.tmp && \
  89. +lib_libopenvswitch_la_SOURCES += lib/stream-ssl.c lib/dhparams.c
  90. +
  91. +# Manually regenerates lib/dhparams.c. Not normally necessary since
  92. +# lib/dhparams.c is part of the repository and doesn't normally need
  93. +# updates.
  94. +generate-dhparams-c:
  95. + $(AM_V_GEN)cd $(srcdir) && \
  96. + build-aux/generate-dhparams-c > lib/dhparams.c.tmp && \
  97. mv lib/dhparams.c.tmp lib/dhparams.c
  98. else
  99. lib_libopenvswitch_la_SOURCES += lib/stream-nossl.c
  100. diff --git a/lib/dhparams.c b/lib/dhparams.c
  101. new file mode 100644
  102. index 000000000..c9c338bf1
  103. --- /dev/null
  104. +++ b/lib/dhparams.c
  105. @@ -0,0 +1,192 @@
  106. +/* Generated automatically; do not modify! -*- buffer-read-only: t -*-
  107. + *
  108. + * If you do need to regenerate this file, run "make generate-dhparams-c". */
  109. +
  110. +#include <config.h>
  111. +#include "lib/dhparams.h"
  112. +#include "openvswitch/util.h"
  113. +
  114. +static int
  115. +my_DH_set0_pqg(DH *dh, BIGNUM *p, const BIGNUM **q OVS_UNUSED, BIGNUM *g)
  116. +{
  117. + ovs_assert(q == NULL);
  118. +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER)
  119. + dh->p = p;
  120. + dh->g = g;
  121. + return 1;
  122. +#else
  123. + return DH_set0_pqg(dh, p, NULL, g);
  124. +#endif
  125. +}
  126. +#ifndef HEADER_DH_H
  127. +# include <openssl/dh.h>
  128. +#endif
  129. +
  130. +DH *get_dh1024(void)
  131. +{
  132. + static unsigned char dhp_1024[] = {
  133. + 0xF4, 0x88, 0xFD, 0x58, 0x4E, 0x49, 0xDB, 0xCD, 0x20, 0xB4,
  134. + 0x9D, 0xE4, 0x91, 0x07, 0x36, 0x6B, 0x33, 0x6C, 0x38, 0x0D,
  135. + 0x45, 0x1D, 0x0F, 0x7C, 0x88, 0xB3, 0x1C, 0x7C, 0x5B, 0x2D,
  136. + 0x8E, 0xF6, 0xF3, 0xC9, 0x23, 0xC0, 0x43, 0xF0, 0xA5, 0x5B,
  137. + 0x18, 0x8D, 0x8E, 0xBB, 0x55, 0x8C, 0xB8, 0x5D, 0x38, 0xD3,
  138. + 0x34, 0xFD, 0x7C, 0x17, 0x57, 0x43, 0xA3, 0x1D, 0x18, 0x6C,
  139. + 0xDE, 0x33, 0x21, 0x2C, 0xB5, 0x2A, 0xFF, 0x3C, 0xE1, 0xB1,
  140. + 0x29, 0x40, 0x18, 0x11, 0x8D, 0x7C, 0x84, 0xA7, 0x0A, 0x72,
  141. + 0xD6, 0x86, 0xC4, 0x03, 0x19, 0xC8, 0x07, 0x29, 0x7A, 0xCA,
  142. + 0x95, 0x0C, 0xD9, 0x96, 0x9F, 0xAB, 0xD0, 0x0A, 0x50, 0x9B,
  143. + 0x02, 0x46, 0xD3, 0x08, 0x3D, 0x66, 0xA4, 0x5D, 0x41, 0x9F,
  144. + 0x9C, 0x7C, 0xBD, 0x89, 0x4B, 0x22, 0x19, 0x26, 0xBA, 0xAB,
  145. + 0xA2, 0x5E, 0xC3, 0x55, 0xE9, 0x2F, 0x78, 0xC7
  146. + };
  147. + static unsigned char dhg_1024[] = {
  148. + 0x02
  149. + };
  150. + DH *dh = DH_new();
  151. + BIGNUM *dhp_bn, *dhg_bn;
  152. +
  153. + if (dh == NULL)
  154. + return NULL;
  155. + dhp_bn = BN_bin2bn(dhp_1024, sizeof (dhp_1024), NULL);
  156. + dhg_bn = BN_bin2bn(dhg_1024, sizeof (dhg_1024), NULL);
  157. + if (dhp_bn == NULL || dhg_bn == NULL
  158. + || !my_DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {
  159. + DH_free(dh);
  160. + BN_free(dhp_bn);
  161. + BN_free(dhg_bn);
  162. + return NULL;
  163. + }
  164. + return dh;
  165. +}
  166. +#ifndef HEADER_DH_H
  167. +# include <openssl/dh.h>
  168. +#endif
  169. +
  170. +DH *get_dh2048(void)
  171. +{
  172. + static unsigned char dhp_2048[] = {
  173. + 0xF6, 0x42, 0x57, 0xB7, 0x08, 0x7F, 0x08, 0x17, 0x72, 0xA2,
  174. + 0xBA, 0xD6, 0xA9, 0x42, 0xF3, 0x05, 0xE8, 0xF9, 0x53, 0x11,
  175. + 0x39, 0x4F, 0xB6, 0xF1, 0x6E, 0xB9, 0x4B, 0x38, 0x20, 0xDA,
  176. + 0x01, 0xA7, 0x56, 0xA3, 0x14, 0xE9, 0x8F, 0x40, 0x55, 0xF3,
  177. + 0xD0, 0x07, 0xC6, 0xCB, 0x43, 0xA9, 0x94, 0xAD, 0xF7, 0x4C,
  178. + 0x64, 0x86, 0x49, 0xF8, 0x0C, 0x83, 0xBD, 0x65, 0xE9, 0x17,
  179. + 0xD4, 0xA1, 0xD3, 0x50, 0xF8, 0xF5, 0x59, 0x5F, 0xDC, 0x76,
  180. + 0x52, 0x4F, 0x3D, 0x3D, 0x8D, 0xDB, 0xCE, 0x99, 0xE1, 0x57,
  181. + 0x92, 0x59, 0xCD, 0xFD, 0xB8, 0xAE, 0x74, 0x4F, 0xC5, 0xFC,
  182. + 0x76, 0xBC, 0x83, 0xC5, 0x47, 0x30, 0x61, 0xCE, 0x7C, 0xC9,
  183. + 0x66, 0xFF, 0x15, 0xF9, 0xBB, 0xFD, 0x91, 0x5E, 0xC7, 0x01,
  184. + 0xAA, 0xD3, 0x5B, 0x9E, 0x8D, 0xA0, 0xA5, 0x72, 0x3A, 0xD4,
  185. + 0x1A, 0xF0, 0xBF, 0x46, 0x00, 0x58, 0x2B, 0xE5, 0xF4, 0x88,
  186. + 0xFD, 0x58, 0x4E, 0x49, 0xDB, 0xCD, 0x20, 0xB4, 0x9D, 0xE4,
  187. + 0x91, 0x07, 0x36, 0x6B, 0x33, 0x6C, 0x38, 0x0D, 0x45, 0x1D,
  188. + 0x0F, 0x7C, 0x88, 0xB3, 0x1C, 0x7C, 0x5B, 0x2D, 0x8E, 0xF6,
  189. + 0xF3, 0xC9, 0x23, 0xC0, 0x43, 0xF0, 0xA5, 0x5B, 0x18, 0x8D,
  190. + 0x8E, 0xBB, 0x55, 0x8C, 0xB8, 0x5D, 0x38, 0xD3, 0x34, 0xFD,
  191. + 0x7C, 0x17, 0x57, 0x43, 0xA3, 0x1D, 0x18, 0x6C, 0xDE, 0x33,
  192. + 0x21, 0x2C, 0xB5, 0x2A, 0xFF, 0x3C, 0xE1, 0xB1, 0x29, 0x40,
  193. + 0x18, 0x11, 0x8D, 0x7C, 0x84, 0xA7, 0x0A, 0x72, 0xD6, 0x86,
  194. + 0xC4, 0x03, 0x19, 0xC8, 0x07, 0x29, 0x7A, 0xCA, 0x95, 0x0C,
  195. + 0xD9, 0x96, 0x9F, 0xAB, 0xD0, 0x0A, 0x50, 0x9B, 0x02, 0x46,
  196. + 0xD3, 0x08, 0x3D, 0x66, 0xA4, 0x5D, 0x41, 0x9F, 0x9C, 0x7C,
  197. + 0xBD, 0x89, 0x4B, 0x22, 0x19, 0x26, 0xBA, 0xAB, 0xA2, 0x5E,
  198. + 0xC3, 0x55, 0xE9, 0x32, 0x0B, 0x3B
  199. + };
  200. + static unsigned char dhg_2048[] = {
  201. + 0x02
  202. + };
  203. + DH *dh = DH_new();
  204. + BIGNUM *dhp_bn, *dhg_bn;
  205. +
  206. + if (dh == NULL)
  207. + return NULL;
  208. + dhp_bn = BN_bin2bn(dhp_2048, sizeof (dhp_2048), NULL);
  209. + dhg_bn = BN_bin2bn(dhg_2048, sizeof (dhg_2048), NULL);
  210. + if (dhp_bn == NULL || dhg_bn == NULL
  211. + || !my_DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {
  212. + DH_free(dh);
  213. + BN_free(dhp_bn);
  214. + BN_free(dhg_bn);
  215. + return NULL;
  216. + }
  217. + return dh;
  218. +}
  219. +#ifndef HEADER_DH_H
  220. +# include <openssl/dh.h>
  221. +#endif
  222. +
  223. +DH *get_dh4096(void)
  224. +{
  225. + static unsigned char dhp_4096[] = {
  226. + 0xFA, 0x14, 0x72, 0x52, 0xC1, 0x4D, 0xE1, 0x5A, 0x49, 0xD4,
  227. + 0xEF, 0x09, 0x2D, 0xC0, 0xA8, 0xFD, 0x55, 0xAB, 0xD7, 0xD9,
  228. + 0x37, 0x04, 0x28, 0x09, 0xE2, 0xE9, 0x3E, 0x77, 0xE2, 0xA1,
  229. + 0x7A, 0x18, 0xDD, 0x46, 0xA3, 0x43, 0x37, 0x23, 0x90, 0x97,
  230. + 0xF3, 0x0E, 0xC9, 0x03, 0x50, 0x7D, 0x65, 0xCF, 0x78, 0x62,
  231. + 0xA6, 0x3A, 0x62, 0x22, 0x83, 0xA1, 0x2F, 0xFE, 0x79, 0xBA,
  232. + 0x35, 0xFF, 0x59, 0xD8, 0x1D, 0x61, 0xDD, 0x1E, 0x21, 0x13,
  233. + 0x17, 0xFE, 0xCD, 0x38, 0x87, 0x9E, 0xF5, 0x4F, 0x79, 0x10,
  234. + 0x61, 0x8D, 0xD4, 0x22, 0xF3, 0x5A, 0xED, 0x5D, 0xEA, 0x21,
  235. + 0xE9, 0x33, 0x6B, 0x48, 0x12, 0x0A, 0x20, 0x77, 0xD4, 0x25,
  236. + 0x60, 0x61, 0xDE, 0xF6, 0xB4, 0x4F, 0x1C, 0x63, 0x40, 0x8B,
  237. + 0x3A, 0x21, 0x93, 0x8B, 0x79, 0x53, 0x51, 0x2C, 0xCA, 0xB3,
  238. + 0x7B, 0x29, 0x56, 0xA8, 0xC7, 0xF8, 0xF4, 0x7B, 0x08, 0x5E,
  239. + 0xA6, 0xDC, 0xA2, 0x45, 0x12, 0x56, 0xDD, 0x41, 0x92, 0xF2,
  240. + 0xDD, 0x5B, 0x8F, 0x23, 0xF0, 0xF3, 0xEF, 0xE4, 0x3B, 0x0A,
  241. + 0x44, 0xDD, 0xED, 0x96, 0x84, 0xF1, 0xA8, 0x32, 0x46, 0xA3,
  242. + 0xDB, 0x4A, 0xBE, 0x3D, 0x45, 0xBA, 0x4E, 0xF8, 0x03, 0xE5,
  243. + 0xDD, 0x6B, 0x59, 0x0D, 0x84, 0x1E, 0xCA, 0x16, 0x5A, 0x8C,
  244. + 0xC8, 0xDF, 0x7C, 0x54, 0x44, 0xC4, 0x27, 0xA7, 0x3B, 0x2A,
  245. + 0x97, 0xCE, 0xA3, 0x7D, 0x26, 0x9C, 0xAD, 0xF4, 0xC2, 0xAC,
  246. + 0x37, 0x4B, 0xC3, 0xAD, 0x68, 0x84, 0x7F, 0x99, 0xA6, 0x17,
  247. + 0xEF, 0x6B, 0x46, 0x3A, 0x7A, 0x36, 0x7A, 0x11, 0x43, 0x92,
  248. + 0xAD, 0xE9, 0x9C, 0xFB, 0x44, 0x6C, 0x3D, 0x82, 0x49, 0xCC,
  249. + 0x5C, 0x6A, 0x52, 0x42, 0xF8, 0x42, 0xFB, 0x44, 0xF9, 0x39,
  250. + 0x73, 0xFB, 0x60, 0x79, 0x3B, 0xC2, 0x9E, 0x0B, 0xDC, 0xD4,
  251. + 0xA6, 0x67, 0xF7, 0x66, 0x3F, 0xFC, 0x42, 0x3B, 0x1B, 0xDB,
  252. + 0x4F, 0x66, 0xDC, 0xA5, 0x8F, 0x66, 0xF9, 0xEA, 0xC1, 0xED,
  253. + 0x31, 0xFB, 0x48, 0xA1, 0x82, 0x7D, 0xF8, 0xE0, 0xCC, 0xB1,
  254. + 0xC7, 0x03, 0xE4, 0xF8, 0xB3, 0xFE, 0xB7, 0xA3, 0x13, 0x73,
  255. + 0xA6, 0x7B, 0xC1, 0x0E, 0x39, 0xC7, 0x94, 0x48, 0x26, 0x00,
  256. + 0x85, 0x79, 0xFC, 0x6F, 0x7A, 0xAF, 0xC5, 0x52, 0x35, 0x75,
  257. + 0xD7, 0x75, 0xA4, 0x40, 0xFA, 0x14, 0x74, 0x61, 0x16, 0xF2,
  258. + 0xEB, 0x67, 0x11, 0x6F, 0x04, 0x43, 0x3D, 0x11, 0x14, 0x4C,
  259. + 0xA7, 0x94, 0x2A, 0x39, 0xA1, 0xC9, 0x90, 0xCF, 0x83, 0xC6,
  260. + 0xFF, 0x02, 0x8F, 0xA3, 0x2A, 0xAC, 0x26, 0xDF, 0x0B, 0x8B,
  261. + 0xBE, 0x64, 0x4A, 0xF1, 0xA1, 0xDC, 0xEE, 0xBA, 0xC8, 0x03,
  262. + 0x82, 0xF6, 0x62, 0x2C, 0x5D, 0xB6, 0xBB, 0x13, 0x19, 0x6E,
  263. + 0x86, 0xC5, 0x5B, 0x2B, 0x5E, 0x3A, 0xF3, 0xB3, 0x28, 0x6B,
  264. + 0x70, 0x71, 0x3A, 0x8E, 0xFF, 0x5C, 0x15, 0xE6, 0x02, 0xA4,
  265. + 0xCE, 0xED, 0x59, 0x56, 0xCC, 0x15, 0x51, 0x07, 0x79, 0x1A,
  266. + 0x0F, 0x25, 0x26, 0x27, 0x30, 0xA9, 0x15, 0xB2, 0xC8, 0xD4,
  267. + 0x5C, 0xCC, 0x30, 0xE8, 0x1B, 0xD8, 0xD5, 0x0F, 0x19, 0xA8,
  268. + 0x80, 0xA4, 0xC7, 0x01, 0xAA, 0x8B, 0xBA, 0x53, 0xBB, 0x47,
  269. + 0xC2, 0x1F, 0x6B, 0x54, 0xB0, 0x17, 0x60, 0xED, 0x79, 0x21,
  270. + 0x95, 0xB6, 0x05, 0x84, 0x37, 0xC8, 0x03, 0xA4, 0xDD, 0xD1,
  271. + 0x06, 0x69, 0x8F, 0x4C, 0x39, 0xE0, 0xC8, 0x5D, 0x83, 0x1D,
  272. + 0xBE, 0x6A, 0x9A, 0x99, 0xF3, 0x9F, 0x0B, 0x45, 0x29, 0xD4,
  273. + 0xCB, 0x29, 0x66, 0xEE, 0x1E, 0x7E, 0x3D, 0xD7, 0x13, 0x4E,
  274. + 0xDB, 0x90, 0x90, 0x58, 0xCB, 0x5E, 0x9B, 0xCD, 0x2E, 0x2B,
  275. + 0x0F, 0xA9, 0x4E, 0x78, 0xAC, 0x05, 0x11, 0x7F, 0xE3, 0x9E,
  276. + 0x27, 0xD4, 0x99, 0xE1, 0xB9, 0xBD, 0x78, 0xE1, 0x84, 0x41,
  277. + 0xA0, 0xDF
  278. + };
  279. + static unsigned char dhg_4096[] = {
  280. + 0x02
  281. + };
  282. + DH *dh = DH_new();
  283. + BIGNUM *dhp_bn, *dhg_bn;
  284. +
  285. + if (dh == NULL)
  286. + return NULL;
  287. + dhp_bn = BN_bin2bn(dhp_4096, sizeof (dhp_4096), NULL);
  288. + dhg_bn = BN_bin2bn(dhg_4096, sizeof (dhg_4096), NULL);
  289. + if (dhp_bn == NULL || dhg_bn == NULL
  290. + || !my_DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {
  291. + DH_free(dh);
  292. + BN_free(dhp_bn);
  293. + BN_free(dhg_bn);
  294. + return NULL;
  295. + }
  296. + return dh;
  297. +}
  298. --
  299. 2.16.4