aboutsummaryrefslogtreecommitdiff
path: root/website/static/security/patches/SA-06:23/openssl.patch
blob: 984d2bbea798b2aaa0f3a31f901e7389eda58e80 (plain) (blame)
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
Index: crypto/openssl/crypto/asn1/tasn_dec.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/asn1/tasn_dec.c,v
retrieving revision 1.1.1.2
diff -u -I__FBSDID -r1.1.1.2 tasn_dec.c
--- crypto/openssl/crypto/asn1/tasn_dec.c	1 Oct 2003 12:32:37 -0000	1.1.1.2
+++ crypto/openssl/crypto/asn1/tasn_dec.c	27 Sep 2006 07:03:22 -0000
@@ -628,6 +628,9 @@
 		ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
 		return 0;
 	} else if(ret == -1) return -1;
+
+	ret = 0;
+
 	/* SEQUENCE, SET and "OTHER" are left in encoded form */
 	if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
 		/* Clear context cache for type OTHER because the auto clear when
Index: crypto/openssl/crypto/dh/dh.h
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/dh/dh.h,v
retrieving revision 1.1.1.6
diff -u -I__FBSDID -r1.1.1.6 dh.h
--- crypto/openssl/crypto/dh/dh.h	28 Jan 2003 21:21:24 -0000	1.1.1.6
+++ crypto/openssl/crypto/dh/dh.h	27 Sep 2006 07:03:22 -0000
@@ -70,6 +70,10 @@
 #include <openssl/crypto.h>
 #include <openssl/ossl_typ.h>
 	
+#ifndef OPENSSL_DH_MAX_MODULUS_BITS
+# define OPENSSL_DH_MAX_MODULUS_BITS	10000
+#endif
+
 #define DH_FLAG_CACHE_MONT_P	0x01
 
 #ifdef  __cplusplus
@@ -200,6 +204,7 @@
 /* Reason codes. */
 #define DH_R_BAD_GENERATOR				 101
 #define DH_R_NO_PRIVATE_VALUE				 100
+#define DH_R_MODULUS_TOO_LARGE				 103
 
 #ifdef  __cplusplus
 }
Index: crypto/openssl/crypto/dh/dh_err.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/dh/dh_err.c,v
retrieving revision 1.1.1.5
diff -u -I__FBSDID -r1.1.1.5 dh_err.c
--- crypto/openssl/crypto/dh/dh_err.c	25 Feb 2005 05:34:36 -0000	1.1.1.5
+++ crypto/openssl/crypto/dh/dh_err.c	27 Sep 2006 07:03:22 -0000
@@ -78,6 +78,7 @@
 static ERR_STRING_DATA DH_str_reasons[]=
 	{
 {DH_R_BAD_GENERATOR                      ,"bad generator"},
+{DH_R_MODULUS_TOO_LARGE                  ,"modulus too large"},
 {DH_R_NO_PRIVATE_VALUE                   ,"no private value"},
 {0,NULL}
 	};
Index: crypto/openssl/crypto/dh/dh_key.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/dh/dh_key.c,v
retrieving revision 1.1.1.9
diff -u -I__FBSDID -r1.1.1.9 dh_key.c
--- crypto/openssl/crypto/dh/dh_key.c	25 Feb 2005 05:34:37 -0000	1.1.1.9
+++ crypto/openssl/crypto/dh/dh_key.c	27 Sep 2006 07:03:22 -0000
@@ -164,6 +164,12 @@
 	BIGNUM *tmp;
 	int ret= -1;
 
+	if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
+		{
+		DHerr(DH_F_DH_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE);
+		return -1;
+		}
+
 	ctx = BN_CTX_new();
 	if (ctx == NULL) goto err;
 	BN_CTX_start(ctx);
Index: crypto/openssl/crypto/dsa/dsa.h
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/dsa/dsa.h,v
retrieving revision 1.1.1.7
diff -u -I__FBSDID -r1.1.1.7 dsa.h
--- crypto/openssl/crypto/dsa/dsa.h	25 Feb 2005 05:34:39 -0000	1.1.1.7
+++ crypto/openssl/crypto/dsa/dsa.h	27 Sep 2006 07:03:23 -0000
@@ -79,6 +79,10 @@
 # include <openssl/dh.h>
 #endif
 
+#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
+# define OPENSSL_DSA_MAX_MODULUS_BITS	10000
+#endif
+
 #define DSA_FLAG_CACHE_MONT_P	0x01
 
 #if defined(OPENSSL_FIPS)
@@ -245,8 +249,10 @@
 #define DSA_F_SIG_CB					 114
 
 /* Reason codes. */
+#define DSA_R_BAD_Q_VALUE				 102
 #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE		 100
 #define DSA_R_MISSING_PARAMETERS			 101
+#define DSA_R_MODULUS_TOO_LARGE				 103
 
 #ifdef  __cplusplus
 }
Index: crypto/openssl/crypto/dsa/dsa_err.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/dsa/dsa_err.c,v
retrieving revision 1.1.1.4
diff -u -I__FBSDID -r1.1.1.4 dsa_err.c
--- crypto/openssl/crypto/dsa/dsa_err.c	28 Jan 2003 21:21:31 -0000	1.1.1.4
+++ crypto/openssl/crypto/dsa/dsa_err.c	27 Sep 2006 07:03:23 -0000
@@ -85,8 +85,10 @@
 
 static ERR_STRING_DATA DSA_str_reasons[]=
 	{
+{DSA_R_BAD_Q_VALUE                       ,"bad q value"},
 {DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE       ,"data too large for key size"},
 {DSA_R_MISSING_PARAMETERS                ,"missing parameters"},
+{DSA_R_MODULUS_TOO_LARGE                 ,"modulus too large"},
 {0,NULL}
 	};
 
Index: crypto/openssl/crypto/dsa/dsa_ossl.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/dsa/dsa_ossl.c,v
retrieving revision 1.1.1.8
diff -u -I__FBSDID -r1.1.1.8 dsa_ossl.c
--- crypto/openssl/crypto/dsa/dsa_ossl.c	25 Feb 2005 05:34:40 -0000	1.1.1.8
+++ crypto/openssl/crypto/dsa/dsa_ossl.c	27 Sep 2006 07:03:23 -0000
@@ -245,6 +245,18 @@
 		return -1;
 		}
 
+	if (BN_num_bits(dsa->q) != 160)
+		{
+		DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
+		return -1;
+		}
+
+	if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS)
+		{
+		DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
+		return -1;
+		}
+
 	BN_init(&u1);
 	BN_init(&u2);
 	BN_init(&t1);
Index: crypto/openssl/crypto/rsa/rsa.h
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/rsa/rsa.h,v
retrieving revision 1.11
diff -u -I__FBSDID -r1.11 rsa.h
--- crypto/openssl/crypto/rsa/rsa.h	25 Feb 2005 05:49:43 -0000	1.11
+++ crypto/openssl/crypto/rsa/rsa.h	27 Sep 2006 07:03:23 -0000
@@ -155,6 +155,17 @@
 	BN_BLINDING *blinding;
 	};
 
+#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
+# define OPENSSL_RSA_MAX_MODULUS_BITS	16400
+#endif
+
+#ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
+# define OPENSSL_RSA_SMALL_MODULUS_BITS	4112
+#endif
+#ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
+# define OPENSSL_RSA_MAX_PUBEXP_BITS	72 /* exponent limit enforced for "large" modulus only */
+#endif
+
 #define RSA_3	0x3L
 #define RSA_F4	0x10001L
 
@@ -348,6 +359,7 @@
 #define RSA_R_INVALID_MESSAGE_LENGTH			 131
 #define RSA_R_IQMP_NOT_INVERSE_OF_Q			 126
 #define RSA_R_KEY_SIZE_TOO_SMALL			 120
+#define RSA_R_MODULUS_TOO_LARGE				 105
 #define RSA_R_NULL_BEFORE_BLOCK_MISSING			 113
 #define RSA_R_N_DOES_NOT_EQUAL_P_Q			 127
 #define RSA_R_OAEP_DECODING_ERROR			 121
Index: crypto/openssl/crypto/rsa/rsa_eay.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/rsa/rsa_eay.c,v
retrieving revision 1.13
diff -u -I__FBSDID -r1.13 rsa_eay.c
--- crypto/openssl/crypto/rsa/rsa_eay.c	25 Feb 2005 05:49:43 -0000	1.13
+++ crypto/openssl/crypto/rsa/rsa_eay.c	27 Sep 2006 07:03:24 -0000
@@ -105,6 +105,28 @@
 	unsigned char *buf=NULL;
 	BN_CTX *ctx=NULL;
 
+	if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
+		{
+		RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
+		return -1;
+		}
+
+	if (BN_ucmp(rsa->n, rsa->e) <= 0)
+		{
+		RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
+		return -1;
+		}
+
+	/* for large moduli, enforce exponent limit */
+	if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
+		{
+		if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
+			{
+			RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
+			return -1;
+			}
+		}
+	
 	BN_init(&f);
 	BN_init(&ret);
 	if ((ctx=BN_CTX_new()) == NULL) goto err;
@@ -505,6 +527,28 @@
 	unsigned char *buf=NULL;
 	BN_CTX *ctx=NULL;
 
+	if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
+		{
+		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE);
+		return -1;
+		}
+
+	if (BN_ucmp(rsa->n, rsa->e) <= 0)
+		{
+		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
+		return -1;
+		}
+
+	/* for large moduli, enforce exponent limit */
+	if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
+		{
+		if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
+			{
+			RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
+			return -1;
+			}
+		}
+	
 	BN_init(&f);
 	BN_init(&ret);
 	ctx=BN_CTX_new();
Index: crypto/openssl/crypto/rsa/rsa_err.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/crypto/rsa/rsa_err.c,v
retrieving revision 1.1.1.4
diff -u -I__FBSDID -r1.1.1.4 rsa_err.c
--- crypto/openssl/crypto/rsa/rsa_err.c	28 Jan 2003 21:28:58 -0000	1.1.1.4
+++ crypto/openssl/crypto/rsa/rsa_err.c	27 Sep 2006 07:03:24 -0000
@@ -116,6 +116,7 @@
 {RSA_R_INVALID_MESSAGE_LENGTH            ,"invalid message length"},
 {RSA_R_IQMP_NOT_INVERSE_OF_Q             ,"iqmp not inverse of q"},
 {RSA_R_KEY_SIZE_TOO_SMALL                ,"key size too small"},
+{RSA_R_MODULUS_TOO_LARGE                 ,"modulus too large"},
 {RSA_R_NULL_BEFORE_BLOCK_MISSING         ,"null before block missing"},
 {RSA_R_N_DOES_NOT_EQUAL_P_Q              ,"n does not equal p q"},
 {RSA_R_OAEP_DECODING_ERROR               ,"oaep decoding error"},
Index: crypto/openssl/ssl/s2_clnt.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/ssl/s2_clnt.c,v
retrieving revision 1.13
diff -u -I__FBSDID -r1.13 s2_clnt.c
--- crypto/openssl/ssl/s2_clnt.c	25 Feb 2005 05:49:43 -0000	1.13
+++ crypto/openssl/ssl/s2_clnt.c	27 Sep 2006 07:03:24 -0000
@@ -538,7 +538,8 @@
 		CRYPTO_add(&s->session->peer->references, 1, CRYPTO_LOCK_X509);
 		}
 
-	if (s->session->peer != s->session->sess_cert->peer_key->x509)
+	if (s->session->sess_cert == NULL 
+      || s->session->peer != s->session->sess_cert->peer_key->x509)
 		/* can't happen */
 		{
 		ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
Index: crypto/openssl/ssl/s3_srvr.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/ssl/s3_srvr.c,v
retrieving revision 1.1.1.14
diff -u -I__FBSDID -r1.1.1.14 s3_srvr.c
--- crypto/openssl/ssl/s3_srvr.c	25 Feb 2005 05:38:27 -0000	1.1.1.14
+++ crypto/openssl/ssl/s3_srvr.c	27 Sep 2006 07:03:25 -0000
@@ -1733,7 +1733,7 @@
 
                 if (kssl_ctx->client_princ)
                         {
-                        int len = strlen(kssl_ctx->client_princ);
+                        size_t len = strlen(kssl_ctx->client_princ);
                         if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) 
                                 {
                                 s->session->krb5_client_princ_len = len;
Index: crypto/openssl/ssl/ssl_lib.c
===================================================================
RCS file: /home/ncvs/src/crypto/openssl/ssl/ssl_lib.c,v
retrieving revision 1.1.1.12
diff -u -I__FBSDID -r1.1.1.12 ssl_lib.c
--- crypto/openssl/ssl/ssl_lib.c	25 Feb 2005 05:38:37 -0000	1.1.1.12
+++ crypto/openssl/ssl/ssl_lib.c	27 Sep 2006 07:03:26 -0000
@@ -1167,7 +1167,7 @@
 		c=sk_SSL_CIPHER_value(sk,i);
 		for (cp=c->name; *cp; )
 			{
-			if (len-- == 0)
+			if (len-- <= 0)
 				{
 				*p='\0';
 				return(buf);