1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
--- sendmail/tls.c.orig 2015-06-20 01:37:28 UTC
+++ sendmail/tls.c
@@ -16,6 +16,9 @@ SM_RCSID("@(#)$Id: tls.c,v 8.127 2013-11
# include <openssl/err.h>
# include <openssl/bio.h>
# include <openssl/pem.h>
+# if !NO_DH
+# include <openssl/dh.h>
+# endif /* !NO_DH */
# ifndef HASURANDOMDEV
# include <openssl/rand.h>
# endif /* ! HASURANDOMDEV */
@@ -44,6 +47,22 @@ static bool tls_safe_f __P((char *, long
static int tls_verify_log __P((int, X509_STORE_CTX *, const char *));
# if !NO_DH
+# if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100001L || \
+ defined(LIBRESSL_VERSION_NUMBER)
+static int
+DH_set0_pqg(dh, p, q, g)
+ DH *dh;
+ BIGNUM *p;
+ BIGNUM *q;
+ BIGNUM *g;
+{
+ dh->p=p;
+ dh->q=q;
+ dh->g=g;
+ return 1; /* success */
+}
+# endif /* !defined() || OPENSSL_VERSION_NUMBER < 0x00907000L */
+
static DH *get_dh512 __P((void));
static unsigned char dh512_p[] =
@@ -64,13 +83,21 @@ static DH *
get_dh512()
{
DH *dh = NULL;
+ BIGNUM *dhp_bn, *dhg_bn;
if ((dh = DH_new()) == NULL)
return NULL;
- dh->p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);
- dh->g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);
- if ((dh->p == NULL) || (dh->g == NULL))
- return NULL;
+ dhp_bn=BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);
+ dhg_bn=BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);
+ if ((dhp_bn == NULL) || (dhg_bn == NULL) || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn))
+ {
+ DH_free(dh);
+ BN_free(dhp_bn);
+ BN_free(dhg_bn);
+ return(NULL);
+ }
+ BN_free(dhp_bn);
+ BN_free(dhg_bn);
return dh;
}
@@ -117,16 +144,21 @@ get_dh2048()
};
static unsigned char dh2048_g[]={ 0x02, };
DH *dh;
+ BIGNUM *dhp_bn, *dhg_bn;
if ((dh=DH_new()) == NULL)
return(NULL);
- dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
- dh->g=BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
- if ((dh->p == NULL) || (dh->g == NULL))
+ dhp_bn=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
+ dhg_bn=BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
+ if ((dhp_bn == NULL) || (dhg_bn == NULL) || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn))
{
DH_free(dh);
+ BN_free(dhp_bn);
+ BN_free(dhg_bn);
return(NULL);
}
+ BN_free(dhp_bn);
+ BN_free(dhg_bn);
return(dh);
}
# endif /* !NO_DH */
@@ -708,6 +740,44 @@ load_certkey(ssl, srv, certfile, keyfile
static char server_session_id_context[] = "sendmail8";
+# if !TLS_NO_RSA
+static RSA *
+sm_RSA_generate_key(num, e)
+ int num;
+ unsigned long e;
+{
+ RSA *rsa;
+ BIGNUM *bn_rsa_r4;
+ int rc;
+
+ rsa = RSA_new();
+ if (rsa == NULL)
+ {
+ if (LogLevel > 0)
+ sm_syslog(LOG_ERR, NOQID,
+ "STARTTLS=server, tmp_rsa_key: RSA_new failed!");
+ return NULL;
+ }
+ rc = BN_set_word(bn_rsa_r4, RSA_F4);
+ if (rc == 0)
+ {
+ if (LogLevel > 0)
+ sm_syslog(LOG_ERR, NOQID,
+ "STARTTLS=server, tmp_rsa_key: BN_set_word failed!");
+ RSA_free(rsa);
+ return NULL;
+ }
+ rc = RSA_generate_key_ex(rsa, RSA_KEYLENGTH, bn_rsa_r4, NULL);
+ BN_free(bn_rsa_r4);
+ if (rc != 0)
+ {
+ RSA_free(rsa);
+ return NULL;
+ }
+ return rsa;
+}
+# endif /* !TLS_NO_RSA */
+
/* 0.9.8a and b have a problem with SSL_OP_TLS_BLOCK_PADDING_BUG */
#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL)
# define SM_SSL_OP_TLS_BLOCK_PADDING_BUG 1
@@ -926,7 +996,7 @@ inittls(ctx, req, options, srv, certfile
{
/* get a pointer to the current certificate validation store */
store = SSL_CTX_get_cert_store(*ctx); /* does not fail */
- crl_file = BIO_new(BIO_s_file_internal());
+ crl_file = BIO_new(BIO_s_file());
if (crl_file != NULL)
{
if (BIO_read_filename(crl_file, CRLFile) >= 0)
@@ -1003,8 +1073,7 @@ inittls(ctx, req, options, srv, certfile
if (bitset(TLS_I_RSA_TMP, req)
# if SM_CONF_SHM
&& ShmId != SM_SHM_NO_ID &&
- (rsa_tmp = RSA_generate_key(RSA_KEYLENGTH, RSA_F4, NULL,
- NULL)) == NULL
+ (rsa_tmp = sm_RSA_generate_key(RSA_KEYLENGTH, RSA_F4)) == NULL
# else /* SM_CONF_SHM */
&& 0 /* no shared memory: no need to generate key now */
# endif /* SM_CONF_SHM */
@@ -1209,9 +1278,10 @@ inittls(ctx, req, options, srv, certfile
if (tTd(96, 2))
sm_dprintf("inittls: Generating %d bit DH parameters\n", bits);
+ dsa=DSA_new();
/* this takes a while! */
- dsa = DSA_generate_parameters(bits, NULL, 0, NULL,
- NULL, 0, NULL);
+ (void)DSA_generate_parameters_ex(dsa, bits, NULL, 0,
+ NULL, NULL, NULL);
dh = DSA_dup_DH(dsa);
DSA_free(dsa);
}
@@ -1744,7 +1814,7 @@ tmp_rsa_key(s, export, keylength)
if (rsa_tmp != NULL)
RSA_free(rsa_tmp);
- rsa_tmp = RSA_generate_key(RSA_KEYLENGTH, RSA_F4, NULL, NULL);
+ rsa_tmp = sm_RSA_generate_key(RSA_KEYLENGTH, RSA_F4);
if (rsa_tmp == NULL)
{
if (LogLevel > 0)
@@ -1971,9 +2041,9 @@ x509_verify_cb(ok, ctx)
{
if (LogLevel > 13)
tls_verify_log(ok, ctx, "x509");
- if (ctx->error == X509_V_ERR_UNABLE_TO_GET_CRL)
+ if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_UNABLE_TO_GET_CRL)
{
- ctx->error = 0;
+ X509_STORE_CTX_set_error(ctx, 0);
return 1; /* override it */
}
}
|