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.

333 lines
9.4 KiB

  1. From 8a12d9183271b2b16f399c3fe867f149dbf753d7 Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Thu, 20 Feb 2020 18:58:52 -0800
  4. Subject: [PATCH] Fix compilation without DSA and deprecated APIs
  5. Signed-off-by: Rosen Penev <rosenp@gmail.com>
  6. ---
  7. dnssec.c | 2 ++
  8. examples/ldns-dane.c | 2 ++
  9. examples/ldns-keygen.c | 2 ++
  10. examples/ldns-signzone.c | 16 ++++++++++++++++
  11. examples/ldns-verify-zone.c | 2 ++
  12. host2str.c | 8 ++++++++
  13. keys.c | 10 +++++++---
  14. ldns/keys.h | 8 ++++++++
  15. rr_functions.c | 4 ++++
  16. 9 files changed, 51 insertions(+), 3 deletions(-)
  17. diff --git a/dnssec.c b/dnssec.c
  18. index 482cefd6..71508600 100644
  19. --- a/dnssec.c
  20. +++ b/dnssec.c
  21. @@ -332,6 +332,7 @@ uint16_t ldns_calc_keytag_raw(const uint8_t* key, size_t keysize)
  22. }
  23. #ifdef HAVE_SSL
  24. +#ifdef USE_DSA
  25. DSA *
  26. ldns_key_buf2dsa(const ldns_buffer *key)
  27. {
  28. @@ -407,6 +408,7 @@ ldns_key_buf2dsa_raw(const unsigned char* key, size_t len)
  29. #endif /* OPENSSL_VERSION_NUMBER */
  30. return dsa;
  31. }
  32. +#endif /* USE_DSA */
  33. RSA *
  34. ldns_key_buf2rsa(const ldns_buffer *key)
  35. diff --git a/examples/ldns-dane.c b/examples/ldns-dane.c
  36. index 4c31fd8f..7b33ad18 100644
  37. --- a/examples/ldns-dane.c
  38. +++ b/examples/ldns-dane.c
  39. @@ -1680,9 +1680,11 @@ main(int argc, char* const* argv)
  40. assert(0);
  41. }
  42. +#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
  43. /* ssl inititalize */
  44. SSL_load_error_strings();
  45. SSL_library_init();
  46. +#endif
  47. /* ssl load validation store */
  48. if (! assume_pkix_validity || CAfile || CApath) {
  49. diff --git a/examples/ldns-keygen.c b/examples/ldns-keygen.c
  50. index 62b8d228..237016e5 100644
  51. --- a/examples/ldns-keygen.c
  52. +++ b/examples/ldns-keygen.c
  53. @@ -148,6 +148,7 @@ main(int argc, char *argv[])
  54. exit(1);
  55. }
  56. break;
  57. +#ifdef USE_DSA
  58. case LDNS_SIGN_DSA:
  59. case LDNS_SIGN_DSA_NSEC3:
  60. if (bits < 512 || bits > 1024) {
  61. @@ -156,6 +157,7 @@ main(int argc, char *argv[])
  62. exit(1);
  63. }
  64. break;
  65. +#endif /* USE_DSA */
  66. #ifdef USE_GOST
  67. case LDNS_SIGN_ECC_GOST:
  68. if(!ldns_key_EVP_load_gost_id()) {
  69. diff --git a/examples/ldns-signzone.c b/examples/ldns-signzone.c
  70. index 7d24ad90..abae352a 100644
  71. --- a/examples/ldns-signzone.c
  72. +++ b/examples/ldns-signzone.c
  73. @@ -72,10 +72,14 @@ usage(FILE *fp, const char *prog) {
  74. fprintf ( fp, "\n " );
  75. __LIST ( RSAMD5 );
  76. +#ifdef USE_DSA
  77. __LIST ( DSA );
  78. +#endif
  79. __LIST ( RSASHA1 );
  80. fprintf ( fp, "\n " );
  81. +#ifdef USE_DSA
  82. __LIST ( DSA_NSEC3 );
  83. +#endif
  84. __LIST ( RSASHA1_NSEC3 );
  85. __LIST ( RSASHA256 );
  86. fprintf ( fp, "\n " );
  87. @@ -350,11 +354,15 @@ parse_algspec ( const char * const p )
  88. __MATCH ( RSAMD5 );
  89. __MATCH ( RSASHA1 );
  90. +#ifdef USE_DSA
  91. __MATCH ( DSA );
  92. +#endif
  93. __MATCH ( RSASHA1_NSEC3 );
  94. __MATCH ( RSASHA256 );
  95. __MATCH ( RSASHA512 );
  96. +#ifdef USE_DSA
  97. __MATCH ( DSA_NSEC3 );
  98. +#endif
  99. __MATCH ( ECC_GOST );
  100. __MATCH ( ECDSAP256SHA256 );
  101. __MATCH ( ECDSAP384SHA384 );
  102. @@ -419,8 +427,10 @@ load_key ( const char * const p, ENGINE * const e )
  103. case LDNS_SIGN_RSASHA1_NSEC3:
  104. case LDNS_SIGN_RSASHA256:
  105. case LDNS_SIGN_RSASHA512:
  106. +#ifdef USE_DSA
  107. case LDNS_SIGN_DSA:
  108. case LDNS_SIGN_DSA_NSEC3:
  109. +#endif
  110. case LDNS_SIGN_ECC_GOST:
  111. #ifdef USE_ECDSA
  112. case LDNS_SIGN_ECDSAP256SHA256:
  113. @@ -995,9 +1005,13 @@ main(int argc, char *argv[])
  114. #ifdef HAVE_SSL
  115. if (ERR_peek_error()) {
  116. +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(HAVE_LIBRESSL)
  117. ERR_load_crypto_strings();
  118. +#endif
  119. ERR_print_errors_fp(stderr);
  120. +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(HAVE_LIBRESSL)
  121. ERR_free_strings();
  122. +#endif
  123. }
  124. #endif
  125. exit(EXIT_FAILURE);
  126. @@ -1018,7 +1032,9 @@ main(int argc, char *argv[])
  127. #ifndef OPENSSL_NO_ENGINE
  128. shutdown_openssl ( engine );
  129. #else
  130. +#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
  131. CRYPTO_cleanup_all_ex_data();
  132. +#endif
  133. #endif
  134. free(prog);
  135. diff --git a/examples/ldns-verify-zone.c b/examples/ldns-verify-zone.c
  136. index c17bd21c..a5a1d003 100644
  137. --- a/examples/ldns-verify-zone.c
  138. +++ b/examples/ldns-verify-zone.c
  139. @@ -113,7 +113,9 @@ print_rr_status_error(FILE* stream, ldns_rr* rr, ldns_status status)
  140. if (status != LDNS_STATUS_OK) {
  141. print_rr_error(stream, rr, ldns_get_errorstr_by_id(status));
  142. if (verbosity > 0 && status == LDNS_STATUS_SSL_ERR) {
  143. +#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
  144. ERR_load_crypto_strings();
  145. +#endif
  146. ERR_print_errors_fp(stream);
  147. }
  148. }
  149. diff --git a/host2str.c b/host2str.c
  150. index 3ca23c20..29a5f5c9 100644
  151. --- a/host2str.c
  152. +++ b/host2str.c
  153. @@ -49,10 +49,14 @@
  154. ldns_lookup_table ldns_algorithms[] = {
  155. { LDNS_RSAMD5, "RSAMD5" },
  156. { LDNS_DH, "DH" },
  157. +#ifdef USE_DSA
  158. { LDNS_DSA, "DSA" },
  159. +#endif /* USE_DSA */
  160. { LDNS_ECC, "ECC" },
  161. { LDNS_RSASHA1, "RSASHA1" },
  162. +#ifdef USE_DSA
  163. { LDNS_DSA_NSEC3, "DSA-NSEC3-SHA1" },
  164. +#endif /* USE_DSA */
  165. { LDNS_RSASHA1_NSEC3, "RSASHA1-NSEC3-SHA1" },
  166. #ifdef USE_SHA2
  167. { LDNS_RSASHA256, "RSASHA256"},
  168. @@ -2133,7 +2137,9 @@ ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k)
  169. unsigned char *bignum;
  170. #ifdef HAVE_SSL
  171. RSA *rsa;
  172. +#ifdef USE_DSA
  173. DSA *dsa;
  174. +#endif /* USE_DSA */
  175. #endif /* HAVE_SSL */
  176. if (!k) {
  177. @@ -2243,6 +2249,7 @@ ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k)
  178. RSA_free(rsa);
  179. break;
  180. +#ifdef USE_DSA
  181. case LDNS_SIGN_DSA:
  182. case LDNS_SIGN_DSA_NSEC3:
  183. dsa = ldns_key_dsa_key(k);
  184. @@ -2283,6 +2290,7 @@ ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k)
  185. goto error;
  186. }
  187. break;
  188. +#endif /* USE_DSA */
  189. case LDNS_SIGN_ECC_GOST:
  190. /* no format defined, use blob */
  191. #if defined(HAVE_SSL) && defined(USE_GOST)
  192. diff --git a/keys.c b/keys.c
  193. index 06afb739..ddff6f35 100644
  194. --- a/keys.c
  195. +++ b/keys.c
  196. @@ -905,6 +905,7 @@ ldns_key_new_frm_fp_rsa_l(FILE *f, int *line_nr)
  197. return NULL;
  198. }
  199. +#ifdef USE_DSA
  200. DSA *
  201. ldns_key_new_frm_fp_dsa(FILE *f)
  202. {
  203. @@ -1015,6 +1016,7 @@ ldns_key_new_frm_fp_dsa_l(FILE *f, ATTR_UNUSED(int *line_nr))
  204. BN_free(pub_key);
  205. return NULL;
  206. }
  207. +#endif /* USE_DSA */
  208. unsigned char *
  209. ldns_key_new_frm_fp_hmac(FILE *f, size_t *hmac_size)
  210. @@ -1149,9 +1151,9 @@ ldns_key_new_frm_algorithm(ldns_signing_algorithm alg, uint16_t size)
  211. #endif /* HAVE_EVP_PKEY_KEYGEN */
  212. #endif /* HAVE_SSL */
  213. break;
  214. +#ifdef USE_DSA
  215. case LDNS_SIGN_DSA:
  216. case LDNS_SIGN_DSA_NSEC3:
  217. -#ifdef USE_DSA
  218. #ifdef HAVE_SSL
  219. # if OPENSSL_VERSION_NUMBER < 0x00908000L
  220. d = DSA_generate_parameters((int)size, NULL, 0, NULL, NULL, NULL, NULL);
  221. @@ -1878,10 +1880,10 @@ ldns_key2rr(const ldns_key *k)
  222. #endif
  223. size++;
  224. break;
  225. +#ifdef USE_DSA
  226. case LDNS_SIGN_DSA:
  227. ldns_rr_push_rdf(pubkey,
  228. ldns_native2rdf_int8(LDNS_RDF_TYPE_ALG, LDNS_DSA));
  229. -#ifdef USE_DSA
  230. #ifdef HAVE_SSL
  231. dsa = ldns_key_dsa_key(k);
  232. if (dsa) {
  233. @@ -1901,10 +1903,10 @@ ldns_key2rr(const ldns_key *k)
  234. #endif /* HAVE_SSL */
  235. #endif /* USE_DSA */
  236. break;
  237. +#ifdef USE_DSA
  238. case LDNS_SIGN_DSA_NSEC3:
  239. ldns_rr_push_rdf(pubkey,
  240. ldns_native2rdf_int8(LDNS_RDF_TYPE_ALG, LDNS_DSA_NSEC3));
  241. -#ifdef USE_DSA
  242. #ifdef HAVE_SSL
  243. dsa = ldns_key_dsa_key(k);
  244. if (dsa) {
  245. @@ -2165,7 +2167,9 @@ ldns_signing_algorithm ldns_get_signing_algorithm_by_name(const char* name)
  246. ldns_lookup_table aliases[] = {
  247. /* from bind dnssec-keygen */
  248. {LDNS_SIGN_HMACMD5, "HMAC-MD5"},
  249. +#ifdef USE_DSA
  250. {LDNS_SIGN_DSA_NSEC3, "NSEC3DSA"},
  251. +#endif /* USE_DSA */
  252. {LDNS_SIGN_RSASHA1_NSEC3, "NSEC3RSASHA1"},
  253. /* old ldns usage, now RFC names */
  254. #ifdef USE_DSA
  255. diff --git a/ldns/keys.h b/ldns/keys.h
  256. index df4bb22b..826f876f 100644
  257. --- a/ldns/keys.h
  258. +++ b/ldns/keys.h
  259. @@ -45,10 +45,14 @@ enum ldns_enum_algorithm
  260. {
  261. LDNS_RSAMD5 = 1, /* RFC 4034,4035 */
  262. LDNS_DH = 2,
  263. +#ifdef USE_DSA
  264. LDNS_DSA = 3,
  265. +#endif /* USE_DSA */
  266. LDNS_ECC = 4,
  267. LDNS_RSASHA1 = 5,
  268. +#ifdef USE_DSA
  269. LDNS_DSA_NSEC3 = 6,
  270. +#endif /* USE_DSA */
  271. LDNS_RSASHA1_NSEC3 = 7,
  272. LDNS_RSASHA256 = 8, /* RFC 5702 */
  273. LDNS_RSASHA512 = 10, /* RFC 5702 */
  274. @@ -90,11 +94,15 @@ enum ldns_enum_signing_algorithm
  275. {
  276. LDNS_SIGN_RSAMD5 = LDNS_RSAMD5,
  277. LDNS_SIGN_RSASHA1 = LDNS_RSASHA1,
  278. +#ifdef USE_DSA
  279. LDNS_SIGN_DSA = LDNS_DSA,
  280. +#endif /* USE_DSA */
  281. LDNS_SIGN_RSASHA1_NSEC3 = LDNS_RSASHA1_NSEC3,
  282. LDNS_SIGN_RSASHA256 = LDNS_RSASHA256,
  283. LDNS_SIGN_RSASHA512 = LDNS_RSASHA512,
  284. +#ifdef USE_DSA
  285. LDNS_SIGN_DSA_NSEC3 = LDNS_DSA_NSEC3,
  286. +#endif /* USE_DSA */
  287. LDNS_SIGN_ECC_GOST = LDNS_ECC_GOST,
  288. LDNS_SIGN_ECDSAP256SHA256 = LDNS_ECDSAP256SHA256,
  289. LDNS_SIGN_ECDSAP384SHA384 = LDNS_ECDSAP384SHA384,
  290. diff --git a/rr_functions.c b/rr_functions.c
  291. index 20a0bfaa..8d72696b 100644
  292. --- a/rr_functions.c
  293. +++ b/rr_functions.c
  294. @@ -269,14 +269,17 @@ ldns_rr_dnskey_key_size_raw(const unsigned char* keydata,
  295. const size_t len,
  296. const ldns_algorithm alg)
  297. {
  298. +#ifdef USE_DSA
  299. /* for DSA keys */
  300. uint8_t t;
  301. +#endif /* USE_DSA */
  302. /* for RSA keys */
  303. uint16_t exp;
  304. uint16_t int16;
  305. switch ((ldns_signing_algorithm)alg) {
  306. +#ifdef USE_DSA
  307. case LDNS_SIGN_DSA:
  308. case LDNS_SIGN_DSA_NSEC3:
  309. if (len > 0) {
  310. @@ -286,6 +289,7 @@ ldns_rr_dnskey_key_size_raw(const unsigned char* keydata,
  311. return 0;
  312. }
  313. break;
  314. +#endif /* USE_DSA */
  315. case LDNS_SIGN_RSAMD5:
  316. case LDNS_SIGN_RSASHA1:
  317. case LDNS_SIGN_RSASHA1_NSEC3: