lkundrak / rpms / sendmail

Forked from rpms/sendmail 4 years ago
Clone
dc1bfda
--- sendmail-8.15.2.orig/sendmail/tls.c	2016-12-01 15:20:59.953546417 +0100
dc1bfda
+++ sendmail-8.15.2.orig/sendmail/tls.c	2016-12-01 17:26:43.868521378 +0100
dc1bfda
@@ -63,14 +63,28 @@ static unsigned char dh512_g[] =
dc1bfda
 static DH *
dc1bfda
 get_dh512()
dc1bfda
 {
dc1bfda
-	DH *dh = NULL;
dc1bfda
+	DH *dh;
dc1bfda
+	BIGNUM *p, *g;
dc1bfda
 
dc1bfda
 	if ((dh = DH_new()) == NULL)
dc1bfda
 		return NULL;
dc1bfda
-	dh->p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);
dc1bfda
-	dh->g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);
dc1bfda
-	if ((dh->p == NULL) || (dh->g == NULL))
dc1bfda
+	p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);
dc1bfda
+	g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);
dc1bfda
+	if (p == NULL || g == NULL)
dc1bfda
+	{
dc1bfda
+		BN_free(p);
dc1bfda
+		BN_free(g);
dc1bfda
+		DH_free(dh);
dc1bfda
 		return NULL;
dc1bfda
+	}
dc1bfda
+
dc1bfda
+#if OPENSSL_VERSION_NUMBER >= 0x10100005L
dc1bfda
+	DH_set0_pqg(dh, p, NULL, g);
dc1bfda
+#else
dc1bfda
+	dh->p = p;
dc1bfda
+	dh->g = g;
dc1bfda
+#endif
dc1bfda
+
dc1bfda
 	return dh;
dc1bfda
 }
dc1bfda
 
dc1bfda
@@ -117,16 +131,27 @@ get_dh2048()
dc1bfda
 		};
dc1bfda
 	static unsigned char dh2048_g[]={ 0x02, };
dc1bfda
 	DH *dh;
dc1bfda
+	BIGNUM *p, *g;
dc1bfda
 
dc1bfda
 	if ((dh=DH_new()) == NULL)
dc1bfda
 		return(NULL);
dc1bfda
-	dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
dc1bfda
-	dh->g=BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
dc1bfda
-	if ((dh->p == NULL) || (dh->g == NULL))
dc1bfda
+	p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);
dc1bfda
+	g = BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL);
dc1bfda
+	if (p == NULL || g == NULL)
dc1bfda
 	{
dc1bfda
+		BN_free(p);
dc1bfda
+		BN_free(g);
dc1bfda
 		DH_free(dh);
dc1bfda
-		return(NULL);
dc1bfda
+		return NULL;
dc1bfda
 	}
dc1bfda
+
dc1bfda
+#if OPENSSL_VERSION_NUMBER >= 0x10100005L
dc1bfda
+	DH_set0_pqg(dh, p, NULL, g);
dc1bfda
+#else
dc1bfda
+	dh->p = p;
dc1bfda
+	dh->g = g;
dc1bfda
+#endif
dc1bfda
+
dc1bfda
 	return(dh);
dc1bfda
 }
dc1bfda
 # endif /* !NO_DH */
dc1bfda
@@ -715,6 +740,54 @@ static char server_session_id_context[]
dc1bfda
 # define SM_SSL_OP_TLS_BLOCK_PADDING_BUG	0
dc1bfda
 #endif
dc1bfda
 
dc1bfda
+static RSA *
dc1bfda
+generate_rsa_key(bits, e)
dc1bfda
+	int bits;
dc1bfda
+	unsigned long e;
dc1bfda
+{
dc1bfda
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
dc1bfda
+	return RSA_generate_key(bits, e, NULL, NULL);
dc1bfda
+#else
dc1bfda
+	BIGNUM *bne;
dc1bfda
+	RSA *rsa = NULL;
dc1bfda
+
dc1bfda
+	bne = BN_new();
dc1bfda
+	if (bne && BN_set_word(bne, e) != 1)
dc1bfda
+		rsa = RSA_new();
dc1bfda
+	if (rsa && RSA_generate_key_ex(rsa, bits, bne, NULL) != 1)
dc1bfda
+	{
dc1bfda
+		RSA_free(rsa);
dc1bfda
+		rsa = NULL;
dc1bfda
+	}
dc1bfda
+	BN_free(bne);
dc1bfda
+	return rsa;
dc1bfda
+#endif
dc1bfda
+}
dc1bfda
+
dc1bfda
+static DSA *
dc1bfda
+generate_dsa_parameters(bits, seed, seed_len, counter_ret, h_ret)
dc1bfda
+	int bits;
dc1bfda
+	unsigned char *seed;
dc1bfda
+	int seed_len;
dc1bfda
+	int *counter_ret;
dc1bfda
+	unsigned long *h_ret;
dc1bfda
+{
dc1bfda
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
dc1bfda
+	return DSA_generate_parameters(bits, seed, seed_len, counter_ret,
dc1bfda
+			               h_ret, NULL, NULL);
dc1bfda
+#else
dc1bfda
+	DSA *dsa = DSA_new();
dc1bfda
+
dc1bfda
+	if (dsa && DSA_generate_parameters_ex(dsa, bits, seed, seed_len,
dc1bfda
+				              counter_ret, h_ret, NULL) != 1)
dc1bfda
+	{
dc1bfda
+		DSA_free(dsa);
dc1bfda
+		dsa = NULL;
dc1bfda
+	}
dc1bfda
+	return dsa;
dc1bfda
+#endif
dc1bfda
+}
dc1bfda
+
dc1bfda
 bool
dc1bfda
 inittls(ctx, req, options, srv, certfile, keyfile, cacertpath, cacertfile, dhparam)
dc1bfda
 	SSL_CTX **ctx;
dc1bfda
@@ -926,7 +999,7 @@ inittls(ctx, req, options, srv, certfile
dc1bfda
 	{
dc1bfda
 		/* get a pointer to the current certificate validation store */
dc1bfda
 		store = SSL_CTX_get_cert_store(*ctx);	/* does not fail */
dc1bfda
-		crl_file = BIO_new(BIO_s_file_internal());
dc1bfda
+		crl_file = BIO_new(BIO_s_file());
dc1bfda
 		if (crl_file != NULL)
dc1bfda
 		{
dc1bfda
 			if (BIO_read_filename(crl_file, CRLFile) >= 0)
dc1bfda
@@ -1003,8 +1076,7 @@ inittls(ctx, req, options, srv, certfile
dc1bfda
 	if (bitset(TLS_I_RSA_TMP, req)
dc1bfda
 #  if SM_CONF_SHM
dc1bfda
 	    && ShmId != SM_SHM_NO_ID &&
dc1bfda
-	    (rsa_tmp = RSA_generate_key(RSA_KEYLENGTH, RSA_F4, NULL,
dc1bfda
-					NULL)) == NULL
dc1bfda
+	    (rsa_tmp = generate_rsa_key(RSA_KEYLENGTH, RSA_F4)) == NULL
dc1bfda
 #  else /* SM_CONF_SHM */
dc1bfda
 	    && 0	/* no shared memory: no need to generate key now */
dc1bfda
 #  endif /* SM_CONF_SHM */
dc1bfda
@@ -1210,8 +1282,8 @@ inittls(ctx, req, options, srv, certfile
dc1bfda
 				sm_dprintf("inittls: Generating %d bit DH parameters\n", bits);
dc1bfda
 
dc1bfda
 			/* this takes a while! */
dc1bfda
-			dsa = DSA_generate_parameters(bits, NULL, 0, NULL,
dc1bfda
-						      NULL, 0, NULL);
dc1bfda
+			dsa = generate_dsa_parameters(bits, NULL, 0, NULL,
dc1bfda
+						      NULL);
dc1bfda
 			dh = DSA_dup_DH(dsa);
dc1bfda
 			DSA_free(dsa);
dc1bfda
 		}
dc1bfda
@@ -1747,7 +1819,7 @@ tmp_rsa_key(s, export, keylength)
dc1bfda
 
dc1bfda
 	if (rsa_tmp != NULL)
dc1bfda
 		RSA_free(rsa_tmp);
dc1bfda
-	rsa_tmp = RSA_generate_key(RSA_KEYLENGTH, RSA_F4, NULL, NULL);
dc1bfda
+	rsa_tmp = generate_rsa_key(RSA_KEYLENGTH, RSA_F4);
dc1bfda
 	if (rsa_tmp == NULL)
dc1bfda
 	{
dc1bfda
 		if (LogLevel > 0)
dc1bfda
@@ -1974,11 +2046,20 @@ x509_verify_cb(ok, ctx)
dc1bfda
 	{
dc1bfda
 		if (LogLevel > 13)
dc1bfda
 			tls_verify_log(ok, ctx, "x509");
dc1bfda
+#if OPENSSL_VERSION_NUMBER >= 0x10100005L
dc1bfda
+		if (X509_STORE_CTX_get_error(ctx) ==
dc1bfda
+		    X509_V_ERR_UNABLE_TO_GET_CRL)
dc1bfda
+		{
dc1bfda
+			X509_STORE_CTX_set_error(ctx, 0);
dc1bfda
+			return 1;	/* override it */
dc1bfda
+		}
dc1bfda
+#else
dc1bfda
 		if (ctx->error == X509_V_ERR_UNABLE_TO_GET_CRL)
dc1bfda
 		{
dc1bfda
 			ctx->error = 0;
dc1bfda
 			return 1;	/* override it */
dc1bfda
 		}
dc1bfda
+#endif
dc1bfda
 	}
dc1bfda
 	return ok;
dc1bfda
 }