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.

255 lines
5.8 KiB

  1. Not needed for 8.16
  2. From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
  3. Date: Sat, 10 Sep 2016 19:27:17 +0000
  4. Subject: [PATCH] sendmail: compile against openssl 1.1.0
  5. Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
  6. ---
  7. --- a/sendmail/tls.c
  8. +++ b/sendmail/tls.c
  9. @@ -60,18 +60,58 @@ static unsigned char dh512_g[] =
  10. 0x02
  11. };
  12. +#if OPENSSL_VERSION_NUMBER < 0x10100000
  13. +
  14. +static inline int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
  15. +{
  16. + /* If the fields p and g in d are NULL, the corresponding input
  17. + * parameters MUST be non-NULL. q may remain NULL.
  18. + */
  19. + if ((dh->p == NULL && p == NULL)
  20. + || (dh->g == NULL && g == NULL))
  21. + return 0;
  22. +
  23. + if (p != NULL) {
  24. + BN_free(dh->p);
  25. + dh->p = p;
  26. + }
  27. + if (q != NULL) {
  28. + BN_free(dh->q);
  29. + dh->q = q;
  30. + }
  31. + if (g != NULL) {
  32. + BN_free(dh->g);
  33. + dh->g = g;
  34. + }
  35. +
  36. + if (q != NULL) {
  37. + dh->length = BN_num_bits(q);
  38. + }
  39. +
  40. + return 1;
  41. +}
  42. +#endif
  43. +
  44. static DH *
  45. get_dh512()
  46. {
  47. DH *dh = NULL;
  48. + BIGNUM *p;
  49. + BIGNUM *g;
  50. - if ((dh = DH_new()) == NULL)
  51. - return NULL;
  52. - dh->p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);
  53. - dh->g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);
  54. - if ((dh->p == NULL) || (dh->g == NULL))
  55. - return NULL;
  56. + dh = DH_new();
  57. + p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);
  58. + g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);
  59. + if (!dh || !p || !g)
  60. + goto err;
  61. + if (!DH_set0_pqg(dh, p, NULL, g))
  62. + goto err;
  63. return dh;
  64. +err:
  65. + DH_free(dh);
  66. + BN_free(p);
  67. + BN_free(g);
  68. + return NULL;
  69. }
  70. # if 0
  71. @@ -117,17 +157,22 @@ get_dh2048()
  72. };
  73. static unsigned char dh2048_g[]={ 0x02, };
  74. DH *dh;
  75. + BIGNUM *p;
  76. + BIGNUM *g;
  77. - if ((dh=DH_new()) == NULL)
  78. - return(NULL);
  79. - dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
  80. - dh->g=BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
  81. - if ((dh->p == NULL) || (dh->g == NULL))
  82. - {
  83. - DH_free(dh);
  84. - return(NULL);
  85. - }
  86. + dh = DH_new();
  87. + p = BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
  88. + g = BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
  89. + if (!dh || !p || !g)
  90. + goto err;
  91. + if (!DH_set0_pqg(dh, p, NULL, g))
  92. + goto err;
  93. return(dh);
  94. +err:
  95. + DH_free(dh);
  96. + BN_free(p);
  97. + BN_free(g);
  98. + return NULL;
  99. }
  100. # endif /* !NO_DH */
  101. @@ -926,7 +971,7 @@ inittls(ctx, req, options, srv, certfile
  102. {
  103. /* get a pointer to the current certificate validation store */
  104. store = SSL_CTX_get_cert_store(*ctx); /* does not fail */
  105. - crl_file = BIO_new(BIO_s_file_internal());
  106. + crl_file = BIO_new(BIO_s_file());
  107. if (crl_file != NULL)
  108. {
  109. if (BIO_read_filename(crl_file, CRLFile) >= 0)
  110. @@ -1000,26 +1045,43 @@ inittls(ctx, req, options, srv, certfile
  111. ** maybe we should do it only on demand...
  112. */
  113. - if (bitset(TLS_I_RSA_TMP, req)
  114. # if SM_CONF_SHM
  115. - && ShmId != SM_SHM_NO_ID &&
  116. - (rsa_tmp = RSA_generate_key(RSA_KEYLENGTH, RSA_F4, NULL,
  117. - NULL)) == NULL
  118. -# else /* SM_CONF_SHM */
  119. - && 0 /* no shared memory: no need to generate key now */
  120. -# endif /* SM_CONF_SHM */
  121. - )
  122. + if (bitset(TLS_I_RSA_TMP, req)
  123. + && ShmId != SM_SHM_NO_ID)
  124. {
  125. - if (LogLevel > 7)
  126. + BIGNUM *bn;
  127. +
  128. + bn = BN_new();
  129. + rsa_tmp = RSA_new();
  130. + if (!bn || !rsa_tmp || !BN_set_word(bn, RSA_F4)) {
  131. + RSA_free(rsa_tmp);
  132. + rsa_tmp = NULL;
  133. + }
  134. + if (rsa_tmp)
  135. {
  136. - sm_syslog(LOG_WARNING, NOQID,
  137. - "STARTTLS=%s, error: RSA_generate_key failed",
  138. - who);
  139. - if (LogLevel > 9)
  140. - tlslogerr(LOG_WARNING, who);
  141. + if (!RSA_generate_key_ex(rsa_tmp, RSA_KEYLENGTH, bn, NULL))
  142. + {
  143. + RSA_free(rsa_tmp);
  144. + rsa_tmp = NULL;
  145. + }
  146. + }
  147. + BN_free(bn);
  148. + if (!rsa_tmp)
  149. + {
  150. + if (LogLevel > 7)
  151. + {
  152. + sm_syslog(LOG_WARNING, NOQID,
  153. + "STARTTLS=%s, error: RSA_generate_key failed",
  154. + who);
  155. + if (LogLevel > 9)
  156. + tlslogerr(LOG_WARNING, who);
  157. + }
  158. + return false;
  159. }
  160. - return false;
  161. }
  162. +# else /* SM_CONF_SHM */
  163. + /* no shared memory: no need to generate key now */
  164. +# endif /* SM_CONF_SHM */
  165. # endif /* !TLS_NO_RSA */
  166. /*
  167. @@ -1210,9 +1272,15 @@ inittls(ctx, req, options, srv, certfile
  168. sm_dprintf("inittls: Generating %d bit DH parameters\n", bits);
  169. /* this takes a while! */
  170. - dsa = DSA_generate_parameters(bits, NULL, 0, NULL,
  171. - NULL, 0, NULL);
  172. - dh = DSA_dup_DH(dsa);
  173. + dsa = DSA_new();
  174. + if (dsa) {
  175. + int r;
  176. +
  177. + r = DSA_generate_parameters_ex(dsa, bits, NULL, 0,
  178. + NULL, NULL, NULL);
  179. + if (r != 0)
  180. + dh = DSA_dup_DH(dsa);
  181. + }
  182. DSA_free(dsa);
  183. }
  184. else if (dh == NULL && bitset(TLS_I_DHFIXED, req))
  185. @@ -1733,6 +1801,9 @@ tmp_rsa_key(s, export, keylength)
  186. int export;
  187. int keylength;
  188. {
  189. + BIGNUM *bn;
  190. + int ret;
  191. +
  192. # if SM_CONF_SHM
  193. extern int ShmId;
  194. extern int *PRSATmpCnt;
  195. @@ -1742,10 +1813,22 @@ tmp_rsa_key(s, export, keylength)
  196. return rsa_tmp;
  197. # endif /* SM_CONF_SHM */
  198. - if (rsa_tmp != NULL)
  199. - RSA_free(rsa_tmp);
  200. - rsa_tmp = RSA_generate_key(RSA_KEYLENGTH, RSA_F4, NULL, NULL);
  201. - if (rsa_tmp == NULL)
  202. + if (rsa_tmp == NULL) {
  203. + rsa_tmp = RSA_new();
  204. + if (!rsa_tmp)
  205. + return NULL;
  206. + }
  207. +
  208. + bn = BN_new();
  209. + if (!bn)
  210. + return NULL;
  211. + if (!BN_set_word(bn, RSA_F4)) {
  212. + BN_free(bn);
  213. + return NULL;
  214. + }
  215. + ret = RSA_generate_key_ex(rsa_tmp, RSA_KEYLENGTH, bn, NULL);
  216. + BN_free(bn);
  217. + if (!ret)
  218. {
  219. if (LogLevel > 0)
  220. sm_syslog(LOG_ERR, NOQID,
  221. @@ -1971,9 +2054,9 @@ x509_verify_cb(ok, ctx)
  222. {
  223. if (LogLevel > 13)
  224. tls_verify_log(ok, ctx, "x509");
  225. - if (ctx->error == X509_V_ERR_UNABLE_TO_GET_CRL)
  226. + if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_UNABLE_TO_GET_CRL)
  227. {
  228. - ctx->error = 0;
  229. + X509_STORE_CTX_set_error(ctx, 0);
  230. return 1; /* override it */
  231. }
  232. }
  233. --- a/doc/op/op.me
  234. +++ b/doc/op/op.me
  235. @@ -10898,7 +10898,7 @@ C=FileName_of_CA_Certificate
  236. ln -s $C `openssl x509 -noout -hash < $C`.0
  237. .)b
  238. A better way to do this is to use the
  239. -.b c_rehash
  240. +.b "openssl rehash"
  241. command that is part of the OpenSSL distribution
  242. because it handles subject hash collisions
  243. by incrementing the number in the suffix of the filename of the symbolic link,