diff options
author | tedu <> | 2015-03-19 14:02:30 +0000 |
---|---|---|
committer | tedu <> | 2015-03-19 14:02:30 +0000 |
commit | e37b71b3b36a3d8dc2434dbdf0089ec516ad0bd9 (patch) | |
tree | 2c65397650d4960ce2013813a11bf290ce1fecbe | |
parent | 226d6a5d87975332d4fcc59a84b281713a349e0c (diff) | |
download | openbsd-e37b71b3b36a3d8dc2434dbdf0089ec516ad0bd9.tar.gz openbsd-e37b71b3b36a3d8dc2434dbdf0089ec516ad0bd9.tar.bz2 openbsd-e37b71b3b36a3d8dc2434dbdf0089ec516ad0bd9.zip |
Fix several crash causing defects from OpenSSL.
These include:
CVE-2015-0209 - Use After Free following d2i_ECPrivatekey error
CVE-2015-0286 - Segmentation fault in ASN1_TYPE_cmp
CVE-2015-0287 - ASN.1 structure reuse memory corruption
CVE-2015-0288 - X509_to_X509_REQ NULL pointer deref
CVE-2015-0289 - PKCS7 NULL pointer dereferences
Several other issues did not apply or were already fixed.
Refer to https://www.openssl.org/news/secadv_20150319.txt
joint work with beck, doug, guenther, jsing, miod
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_int.c | 6 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_set.c | 4 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/a_type.c | 6 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/d2i_pr.c | 4 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/d2i_pu.c | 4 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/n_pkey.c | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/tasn_dec.c | 27 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/x_x509.c | 16 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/ec/ec_asn1.c | 41 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/pkcs7/pk7_doit.c | 98 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/pkcs7/pk7_lib.c | 4 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509_req.c | 6 | ||||
-rw-r--r-- | src/lib/libssl/src/ssl/d1_lib.c | 5 |
13 files changed, 166 insertions, 65 deletions
diff --git a/src/lib/libssl/src/crypto/asn1/a_int.c b/src/lib/libssl/src/crypto/asn1/a_int.c index ba2895db6b..7e2ab3d25d 100644 --- a/src/lib/libssl/src/crypto/asn1/a_int.c +++ b/src/lib/libssl/src/crypto/asn1/a_int.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_int.c,v 1.24 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: a_int.c,v 1.24.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -268,7 +268,7 @@ c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len) | |||
268 | 268 | ||
269 | err: | 269 | err: |
270 | ASN1err(ASN1_F_C2I_ASN1_INTEGER, i); | 270 | ASN1err(ASN1_F_C2I_ASN1_INTEGER, i); |
271 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 271 | if (a == NULL || *a != ret) |
272 | M_ASN1_INTEGER_free(ret); | 272 | M_ASN1_INTEGER_free(ret); |
273 | return (NULL); | 273 | return (NULL); |
274 | } | 274 | } |
@@ -335,7 +335,7 @@ d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length) | |||
335 | 335 | ||
336 | err: | 336 | err: |
337 | ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i); | 337 | ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i); |
338 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 338 | if (a == NULL || *a != ret) |
339 | M_ASN1_INTEGER_free(ret); | 339 | M_ASN1_INTEGER_free(ret); |
340 | return (NULL); | 340 | return (NULL); |
341 | } | 341 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/a_set.c b/src/lib/libssl/src/crypto/asn1/a_set.c index ba4f28be34..7513eaa570 100644 --- a/src/lib/libssl/src/crypto/asn1/a_set.c +++ b/src/lib/libssl/src/crypto/asn1/a_set.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_set.c,v 1.16 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: a_set.c,v 1.16.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -225,7 +225,7 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length, | |||
225 | return ret; | 225 | return ret; |
226 | 226 | ||
227 | err: | 227 | err: |
228 | if (ret != NULL && (a == NULL || *a != ret)) { | 228 | if (a == NULL || *a != ret) { |
229 | if (free_func != NULL) | 229 | if (free_func != NULL) |
230 | sk_OPENSSL_BLOCK_pop_free(ret, free_func); | 230 | sk_OPENSSL_BLOCK_pop_free(ret, free_func); |
231 | else | 231 | else |
diff --git a/src/lib/libssl/src/crypto/asn1/a_type.c b/src/lib/libssl/src/crypto/asn1/a_type.c index add5ff1253..73c7a98e65 100644 --- a/src/lib/libssl/src/crypto/asn1/a_type.c +++ b/src/lib/libssl/src/crypto/asn1/a_type.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_type.c,v 1.14 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: a_type.c,v 1.14.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -122,7 +122,9 @@ ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) | |||
122 | case V_ASN1_OBJECT: | 122 | case V_ASN1_OBJECT: |
123 | result = OBJ_cmp(a->value.object, b->value.object); | 123 | result = OBJ_cmp(a->value.object, b->value.object); |
124 | break; | 124 | break; |
125 | 125 | case V_ASN1_BOOLEAN: | |
126 | result = a->value.boolean - b->value.boolean; | ||
127 | break; | ||
126 | case V_ASN1_NULL: | 128 | case V_ASN1_NULL: |
127 | result = 0; /* They do not have content. */ | 129 | result = 0; /* They do not have content. */ |
128 | break; | 130 | break; |
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pr.c b/src/lib/libssl/src/crypto/asn1/d2i_pr.c index 2deec613ed..3556346ed6 100644 --- a/src/lib/libssl/src/crypto/asn1/d2i_pr.c +++ b/src/lib/libssl/src/crypto/asn1/d2i_pr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d2i_pr.c,v 1.12 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: d2i_pr.c,v 1.12.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -117,7 +117,7 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length) | |||
117 | return (ret); | 117 | return (ret); |
118 | 118 | ||
119 | err: | 119 | err: |
120 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 120 | if (a == NULL || *a != ret) |
121 | EVP_PKEY_free(ret); | 121 | EVP_PKEY_free(ret); |
122 | return (NULL); | 122 | return (NULL); |
123 | } | 123 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/d2i_pu.c b/src/lib/libssl/src/crypto/asn1/d2i_pu.c index df6fea4af5..2736189393 100644 --- a/src/lib/libssl/src/crypto/asn1/d2i_pu.c +++ b/src/lib/libssl/src/crypto/asn1/d2i_pu.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d2i_pu.c,v 1.12 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: d2i_pu.c,v 1.12.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -130,7 +130,7 @@ d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length) | |||
130 | return (ret); | 130 | return (ret); |
131 | 131 | ||
132 | err: | 132 | err: |
133 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 133 | if (a == NULL || *a != ret) |
134 | EVP_PKEY_free(ret); | 134 | EVP_PKEY_free(ret); |
135 | return (NULL); | 135 | return (NULL); |
136 | } | 136 | } |
diff --git a/src/lib/libssl/src/crypto/asn1/n_pkey.c b/src/lib/libssl/src/crypto/asn1/n_pkey.c index 42431b6e24..e8968b5c16 100644 --- a/src/lib/libssl/src/crypto/asn1/n_pkey.c +++ b/src/lib/libssl/src/crypto/asn1/n_pkey.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: n_pkey.c,v 1.22 2014/07/12 22:26:01 miod Exp $ */ | 1 | /* $OpenBSD: n_pkey.c,v 1.22.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -250,11 +250,11 @@ d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | |||
250 | return NULL; | 250 | return NULL; |
251 | } | 251 | } |
252 | 252 | ||
253 | if ((enckey->os->length != 11) || (strncmp("private-key", | 253 | /* XXX 11 == strlen("private-key") */ |
254 | (char *)enckey->os->data, 11) != 0)) { | 254 | if (enckey->os->length != 11 || |
255 | memcmp("private-key", enckey->os->data, 11) != 0) { | ||
255 | ASN1err(ASN1_F_D2I_RSA_NET, ASN1_R_PRIVATE_KEY_HEADER_MISSING); | 256 | ASN1err(ASN1_F_D2I_RSA_NET, ASN1_R_PRIVATE_KEY_HEADER_MISSING); |
256 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 257 | goto err; |
257 | return NULL; | ||
258 | } | 258 | } |
259 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) { | 259 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) { |
260 | ASN1err(ASN1_F_D2I_RSA_NET, | 260 | ASN1err(ASN1_F_D2I_RSA_NET, |
diff --git a/src/lib/libssl/src/crypto/asn1/tasn_dec.c b/src/lib/libssl/src/crypto/asn1/tasn_dec.c index f633d03e9c..16b36359a2 100644 --- a/src/lib/libssl/src/crypto/asn1/tasn_dec.c +++ b/src/lib/libssl/src/crypto/asn1/tasn_dec.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tasn_dec.c,v 1.24 2014/06/12 15:49:27 deraadt Exp $ */ | 1 | /* $OpenBSD: tasn_dec.c,v 1.24.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -304,8 +304,16 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
304 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) | 304 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) |
305 | goto auxerr; | 305 | goto auxerr; |
306 | 306 | ||
307 | /* Allocate structure */ | 307 | if (*pval) { |
308 | if (!*pval && !ASN1_item_ex_new(pval, it)) { | 308 | /* Free up and zero CHOICE value if initialised */ |
309 | i = asn1_get_choice_selector(pval, it); | ||
310 | if ((i >= 0) && (i < it->tcount)) { | ||
311 | tt = it->templates + i; | ||
312 | pchptr = asn1_get_field_ptr(pval, tt); | ||
313 | ASN1_template_free(pchptr, tt); | ||
314 | asn1_set_choice_selector(pval, -1, it); | ||
315 | } | ||
316 | } else if (!ASN1_item_ex_new(pval, it)) { | ||
309 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, | 317 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
310 | ERR_R_NESTED_ASN1_ERROR); | 318 | ERR_R_NESTED_ASN1_ERROR); |
311 | goto err; | 319 | goto err; |
@@ -391,6 +399,19 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, | |||
391 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) | 399 | if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) |
392 | goto auxerr; | 400 | goto auxerr; |
393 | 401 | ||
402 | /* Free up and zero any ADB found */ | ||
403 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) { | ||
404 | if (tt->flags & ASN1_TFLG_ADB_MASK) { | ||
405 | const ASN1_TEMPLATE *seqtt; | ||
406 | ASN1_VALUE **pseqval; | ||
407 | seqtt = asn1_do_adb(pval, tt, 1); | ||
408 | if (!seqtt) | ||
409 | goto err; | ||
410 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
411 | ASN1_template_free(pseqval, seqtt); | ||
412 | } | ||
413 | } | ||
414 | |||
394 | /* Get each field entry */ | 415 | /* Get each field entry */ |
395 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) { | 416 | for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) { |
396 | const ASN1_TEMPLATE *seqtt; | 417 | const ASN1_TEMPLATE *seqtt; |
diff --git a/src/lib/libssl/src/crypto/asn1/x_x509.c b/src/lib/libssl/src/crypto/asn1/x_x509.c index 0236a0faa2..83d1b317fe 100644 --- a/src/lib/libssl/src/crypto/asn1/x_x509.c +++ b/src/lib/libssl/src/crypto/asn1/x_x509.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x_x509.c,v 1.17 2014/07/11 08:44:47 jsing Exp $ */ | 1 | /* $OpenBSD: x_x509.c,v 1.17.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -177,16 +177,20 @@ d2i_X509_AUX(X509 **a, const unsigned char **pp, long length) | |||
177 | 177 | ||
178 | /* Save start position */ | 178 | /* Save start position */ |
179 | q = *pp; | 179 | q = *pp; |
180 | ret = d2i_X509(a, pp, length); | 180 | ret = d2i_X509(NULL, pp, length); |
181 | /* If certificate unreadable then forget it */ | 181 | /* If certificate unreadable then forget it */ |
182 | if (!ret) | 182 | if (!ret) |
183 | return NULL; | 183 | return NULL; |
184 | /* update length */ | 184 | /* update length */ |
185 | length -= *pp - q; | 185 | length -= *pp - q; |
186 | if (!length) | 186 | if (length > 0) { |
187 | return ret; | 187 | if (!d2i_X509_CERT_AUX(&ret->aux, pp, length)) |
188 | if (!d2i_X509_CERT_AUX(&ret->aux, pp, length)) | 188 | goto err; |
189 | goto err; | 189 | } |
190 | if (a != NULL) { | ||
191 | X509_free(*a); | ||
192 | *a = ret; | ||
193 | } | ||
190 | return ret; | 194 | return ret; |
191 | 195 | ||
192 | err: | 196 | err: |
diff --git a/src/lib/libssl/src/crypto/ec/ec_asn1.c b/src/lib/libssl/src/crypto/ec/ec_asn1.c index c54f6593d5..d0047436fe 100644 --- a/src/lib/libssl/src/crypto/ec/ec_asn1.c +++ b/src/lib/libssl/src/crypto/ec/ec_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_asn1.c,v 1.10 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.10.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -918,19 +918,19 @@ d2i_ECPKParameters(EC_GROUP ** a, const unsigned char **in, long len) | |||
918 | 918 | ||
919 | if ((params = d2i_ECPKPARAMETERS(NULL, in, len)) == NULL) { | 919 | if ((params = d2i_ECPKPARAMETERS(NULL, in, len)) == NULL) { |
920 | ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_D2I_ECPKPARAMETERS_FAILURE); | 920 | ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_D2I_ECPKPARAMETERS_FAILURE); |
921 | ECPKPARAMETERS_free(params); | 921 | goto err; |
922 | return NULL; | ||
923 | } | 922 | } |
924 | if ((group = ec_asn1_pkparameters2group(params)) == NULL) { | 923 | if ((group = ec_asn1_pkparameters2group(params)) == NULL) { |
925 | ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_PKPARAMETERS2GROUP_FAILURE); | 924 | ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_PKPARAMETERS2GROUP_FAILURE); |
926 | ECPKPARAMETERS_free(params); | 925 | goto err; |
927 | return NULL; | ||
928 | } | 926 | } |
929 | if (a && *a) | 927 | |
928 | if (a != NULL) { | ||
930 | EC_GROUP_clear_free(*a); | 929 | EC_GROUP_clear_free(*a); |
931 | if (a) | ||
932 | *a = group; | 930 | *a = group; |
931 | } | ||
933 | 932 | ||
933 | err: | ||
934 | ECPKPARAMETERS_free(params); | 934 | ECPKPARAMETERS_free(params); |
935 | return (group); | 935 | return (group); |
936 | } | 936 | } |
@@ -958,7 +958,6 @@ i2d_ECPKParameters(const EC_GROUP * a, unsigned char **out) | |||
958 | EC_KEY * | 958 | EC_KEY * |
959 | d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len) | 959 | d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len) |
960 | { | 960 | { |
961 | int ok = 0; | ||
962 | EC_KEY *ret = NULL; | 961 | EC_KEY *ret = NULL; |
963 | EC_PRIVATEKEY *priv_key = NULL; | 962 | EC_PRIVATEKEY *priv_key = NULL; |
964 | 963 | ||
@@ -973,12 +972,9 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len) | |||
973 | } | 972 | } |
974 | if (a == NULL || *a == NULL) { | 973 | if (a == NULL || *a == NULL) { |
975 | if ((ret = EC_KEY_new()) == NULL) { | 974 | if ((ret = EC_KEY_new()) == NULL) { |
976 | ECerr(EC_F_D2I_ECPRIVATEKEY, | 975 | ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); |
977 | ERR_R_MALLOC_FAILURE); | ||
978 | goto err; | 976 | goto err; |
979 | } | 977 | } |
980 | if (a) | ||
981 | *a = ret; | ||
982 | } else | 978 | } else |
983 | ret = *a; | 979 | ret = *a; |
984 | 980 | ||
@@ -1028,17 +1024,19 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len) | |||
1028 | goto err; | 1024 | goto err; |
1029 | } | 1025 | } |
1030 | } | 1026 | } |
1031 | ok = 1; | 1027 | |
1028 | EC_PRIVATEKEY_free(priv_key); | ||
1029 | if (a != NULL) | ||
1030 | *a = ret; | ||
1031 | return (ret); | ||
1032 | |||
1032 | err: | 1033 | err: |
1033 | if (!ok) { | 1034 | if (a == NULL || *a != ret) |
1034 | if (ret) | 1035 | EC_KEY_free(ret); |
1035 | EC_KEY_free(ret); | ||
1036 | ret = NULL; | ||
1037 | } | ||
1038 | if (priv_key) | 1036 | if (priv_key) |
1039 | EC_PRIVATEKEY_free(priv_key); | 1037 | EC_PRIVATEKEY_free(priv_key); |
1040 | 1038 | ||
1041 | return (ret); | 1039 | return (NULL); |
1042 | } | 1040 | } |
1043 | 1041 | ||
1044 | int | 1042 | int |
@@ -1151,8 +1149,6 @@ d2i_ECParameters(EC_KEY ** a, const unsigned char **in, long len) | |||
1151 | ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_MALLOC_FAILURE); | 1149 | ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_MALLOC_FAILURE); |
1152 | return NULL; | 1150 | return NULL; |
1153 | } | 1151 | } |
1154 | if (a) | ||
1155 | *a = ret; | ||
1156 | } else | 1152 | } else |
1157 | ret = *a; | 1153 | ret = *a; |
1158 | 1154 | ||
@@ -1160,6 +1156,9 @@ d2i_ECParameters(EC_KEY ** a, const unsigned char **in, long len) | |||
1160 | ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_EC_LIB); | 1156 | ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_EC_LIB); |
1161 | return NULL; | 1157 | return NULL; |
1162 | } | 1158 | } |
1159 | |||
1160 | if (a != NULL) | ||
1161 | *a = ret; | ||
1163 | return ret; | 1162 | return ret; |
1164 | } | 1163 | } |
1165 | 1164 | ||
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c index 8f1e393635..442d0ec203 100644 --- a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c +++ b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pk7_doit.c,v 1.29 2014/07/25 06:05:32 doug Exp $ */ | 1 | /* $OpenBSD: pk7_doit.c,v 1.29.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -261,6 +261,28 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio) | |||
261 | PKCS7_RECIP_INFO *ri = NULL; | 261 | PKCS7_RECIP_INFO *ri = NULL; |
262 | ASN1_OCTET_STRING *os = NULL; | 262 | ASN1_OCTET_STRING *os = NULL; |
263 | 263 | ||
264 | if (p7 == NULL) { | ||
265 | PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_INVALID_NULL_POINTER); | ||
266 | return NULL; | ||
267 | } | ||
268 | |||
269 | /* | ||
270 | * The content field in the PKCS7 ContentInfo is optional, | ||
271 | * but that really only applies to inner content (precisely, | ||
272 | * detached signatures). | ||
273 | * | ||
274 | * When reading content, missing outer content is therefore | ||
275 | * treated as an error. | ||
276 | * | ||
277 | * When creating content, PKCS7_content_new() must be called | ||
278 | * before calling this method, so a NULL p7->d is always | ||
279 | * an error. | ||
280 | */ | ||
281 | if (p7->d.ptr == NULL) { | ||
282 | PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_NO_CONTENT); | ||
283 | return NULL; | ||
284 | } | ||
285 | |||
264 | i = OBJ_obj2nid(p7->type); | 286 | i = OBJ_obj2nid(p7->type); |
265 | p7->state = PKCS7_S_HEADER; | 287 | p7->state = PKCS7_S_HEADER; |
266 | 288 | ||
@@ -418,6 +440,17 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) | |||
418 | unsigned char *ek = NULL, *tkey = NULL; | 440 | unsigned char *ek = NULL, *tkey = NULL; |
419 | int eklen = 0, tkeylen = 0; | 441 | int eklen = 0, tkeylen = 0; |
420 | 442 | ||
443 | if (p7 == NULL) { | ||
444 | PKCS7err(PKCS7_F_PKCS7_DATADECODE, | ||
445 | PKCS7_R_INVALID_NULL_POINTER); | ||
446 | return NULL; | ||
447 | } | ||
448 | |||
449 | if (p7->d.ptr == NULL) { | ||
450 | PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_NO_CONTENT); | ||
451 | return NULL; | ||
452 | } | ||
453 | |||
421 | i = OBJ_obj2nid(p7->type); | 454 | i = OBJ_obj2nid(p7->type); |
422 | p7->state = PKCS7_S_HEADER; | 455 | p7->state = PKCS7_S_HEADER; |
423 | 456 | ||
@@ -713,6 +746,17 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) | |||
713 | STACK_OF(PKCS7_SIGNER_INFO) *si_sk = NULL; | 746 | STACK_OF(PKCS7_SIGNER_INFO) *si_sk = NULL; |
714 | ASN1_OCTET_STRING *os = NULL; | 747 | ASN1_OCTET_STRING *os = NULL; |
715 | 748 | ||
749 | if (p7 == NULL) { | ||
750 | PKCS7err(PKCS7_F_PKCS7_DATAFINAL, | ||
751 | PKCS7_R_INVALID_NULL_POINTER); | ||
752 | return 0; | ||
753 | } | ||
754 | |||
755 | if (p7->d.ptr == NULL) { | ||
756 | PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_NO_CONTENT); | ||
757 | return 0; | ||
758 | } | ||
759 | |||
716 | EVP_MD_CTX_init(&ctx_tmp); | 760 | EVP_MD_CTX_init(&ctx_tmp); |
717 | i = OBJ_obj2nid(p7->type); | 761 | i = OBJ_obj2nid(p7->type); |
718 | p7->state = PKCS7_S_HEADER; | 762 | p7->state = PKCS7_S_HEADER; |
@@ -758,6 +802,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) | |||
758 | /* If detached data then the content is excluded */ | 802 | /* If detached data then the content is excluded */ |
759 | if (PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) { | 803 | if (PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) { |
760 | M_ASN1_OCTET_STRING_free(os); | 804 | M_ASN1_OCTET_STRING_free(os); |
805 | os = NULL; | ||
761 | p7->d.sign->contents->d.data = NULL; | 806 | p7->d.sign->contents->d.data = NULL; |
762 | } | 807 | } |
763 | break; | 808 | break; |
@@ -772,6 +817,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) | |||
772 | if (PKCS7_type_is_data(p7->d.digest->contents) && | 817 | if (PKCS7_type_is_data(p7->d.digest->contents) && |
773 | p7->detached) { | 818 | p7->detached) { |
774 | M_ASN1_OCTET_STRING_free(os); | 819 | M_ASN1_OCTET_STRING_free(os); |
820 | os = NULL; | ||
775 | p7->d.digest->contents->d.data = NULL; | 821 | p7->d.digest->contents->d.data = NULL; |
776 | } | 822 | } |
777 | break; | 823 | break; |
@@ -837,22 +883,32 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) | |||
837 | M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len); | 883 | M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len); |
838 | } | 884 | } |
839 | 885 | ||
840 | if (!PKCS7_is_detached(p7) && !(os->flags & ASN1_STRING_FLAG_NDEF)) { | 886 | if (!PKCS7_is_detached(p7)) { |
841 | char *cont; | 887 | /* |
842 | long contlen; | 888 | * NOTE: only reach os == NULL here because detached |
843 | btmp = BIO_find_type(bio, BIO_TYPE_MEM); | 889 | * digested data support is broken? |
844 | if (btmp == NULL) { | 890 | */ |
845 | PKCS7err(PKCS7_F_PKCS7_DATAFINAL, | 891 | if (os == NULL) |
846 | PKCS7_R_UNABLE_TO_FIND_MEM_BIO); | ||
847 | goto err; | 892 | goto err; |
893 | if (!(os->flags & ASN1_STRING_FLAG_NDEF)) { | ||
894 | char *cont; | ||
895 | long contlen; | ||
896 | |||
897 | btmp = BIO_find_type(bio, BIO_TYPE_MEM); | ||
898 | if (btmp == NULL) { | ||
899 | PKCS7err(PKCS7_F_PKCS7_DATAFINAL, | ||
900 | PKCS7_R_UNABLE_TO_FIND_MEM_BIO); | ||
901 | goto err; | ||
902 | } | ||
903 | contlen = BIO_get_mem_data(btmp, &cont); | ||
904 | /* | ||
905 | * Mark the BIO read only then we can use its copy | ||
906 | * of the data instead of making an extra copy. | ||
907 | */ | ||
908 | BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY); | ||
909 | BIO_set_mem_eof_return(btmp, 0); | ||
910 | ASN1_STRING_set0(os, (unsigned char *)cont, contlen); | ||
848 | } | 911 | } |
849 | contlen = BIO_get_mem_data(btmp, &cont); | ||
850 | /* Mark the BIO read only then we can use its copy of the data | ||
851 | * instead of making an extra copy. | ||
852 | */ | ||
853 | BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY); | ||
854 | BIO_set_mem_eof_return(btmp, 0); | ||
855 | ASN1_STRING_set0(os, (unsigned char *)cont, contlen); | ||
856 | } | 912 | } |
857 | ret = 1; | 913 | ret = 1; |
858 | err: | 914 | err: |
@@ -927,6 +983,17 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio, | |||
927 | STACK_OF(X509) *cert; | 983 | STACK_OF(X509) *cert; |
928 | X509 *x509; | 984 | X509 *x509; |
929 | 985 | ||
986 | if (p7 == NULL) { | ||
987 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, | ||
988 | PKCS7_R_INVALID_NULL_POINTER); | ||
989 | return 0; | ||
990 | } | ||
991 | |||
992 | if (p7->d.ptr == NULL) { | ||
993 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_NO_CONTENT); | ||
994 | return 0; | ||
995 | } | ||
996 | |||
930 | if (PKCS7_type_is_signed(p7)) { | 997 | if (PKCS7_type_is_signed(p7)) { |
931 | cert = p7->d.sign->cert; | 998 | cert = p7->d.sign->cert; |
932 | } else if (PKCS7_type_is_signedAndEnveloped(p7)) { | 999 | } else if (PKCS7_type_is_signedAndEnveloped(p7)) { |
@@ -963,6 +1030,7 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio, | |||
963 | 1030 | ||
964 | return PKCS7_signatureVerify(bio, p7, si, x509); | 1031 | return PKCS7_signatureVerify(bio, p7, si, x509); |
965 | err: | 1032 | err: |
1033 | |||
966 | return ret; | 1034 | return ret; |
967 | } | 1035 | } |
968 | 1036 | ||
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_lib.c b/src/lib/libssl/src/crypto/pkcs7/pk7_lib.c index 27370800c9..c9de0eaf5f 100644 --- a/src/lib/libssl/src/crypto/pkcs7/pk7_lib.c +++ b/src/lib/libssl/src/crypto/pkcs7/pk7_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pk7_lib.c,v 1.14 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: pk7_lib.c,v 1.14.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -460,6 +460,8 @@ PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md) | |||
460 | STACK_OF(PKCS7_SIGNER_INFO) * | 460 | STACK_OF(PKCS7_SIGNER_INFO) * |
461 | PKCS7_get_signer_info(PKCS7 *p7) | 461 | PKCS7_get_signer_info(PKCS7 *p7) |
462 | { | 462 | { |
463 | if (p7 == NULL || p7->d.ptr == NULL) | ||
464 | return (NULL); | ||
463 | if (PKCS7_type_is_signed(p7)) { | 465 | if (PKCS7_type_is_signed(p7)) { |
464 | return (p7->d.sign->signer_info); | 466 | return (p7->d.sign->signer_info); |
465 | } else if (PKCS7_type_is_signedAndEnveloped(p7)) { | 467 | } else if (PKCS7_type_is_signedAndEnveloped(p7)) { |
diff --git a/src/lib/libssl/src/crypto/x509/x509_req.c b/src/lib/libssl/src/crypto/x509/x509_req.c index 22d2124614..433ad1d0b5 100644 --- a/src/lib/libssl/src/crypto/x509/x509_req.c +++ b/src/lib/libssl/src/crypto/x509/x509_req.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_req.c,v 1.15 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: x509_req.c,v 1.15.4.1 2015/03/19 14:02:22 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -95,7 +95,9 @@ X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) | |||
95 | if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x))) | 95 | if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x))) |
96 | goto err; | 96 | goto err; |
97 | 97 | ||
98 | pktmp = X509_get_pubkey(x); | 98 | if ((pktmp = X509_get_pubkey(x)) == NULL) |
99 | goto err; | ||
100 | |||
99 | i = X509_REQ_set_pubkey(ret, pktmp); | 101 | i = X509_REQ_set_pubkey(ret, pktmp); |
100 | EVP_PKEY_free(pktmp); | 102 | EVP_PKEY_free(pktmp); |
101 | if (!i) | 103 | if (!i) |
diff --git a/src/lib/libssl/src/ssl/d1_lib.c b/src/lib/libssl/src/ssl/d1_lib.c index ff78d0cf3a..7b66a838e0 100644 --- a/src/lib/libssl/src/ssl/d1_lib.c +++ b/src/lib/libssl/src/ssl/d1_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d1_lib.c,v 1.24 2014/07/17 23:48:24 deraadt Exp $ */ | 1 | /* $OpenBSD: d1_lib.c,v 1.24.4.1 2015/03/19 14:02:23 tedu Exp $ */ |
2 | /* | 2 | /* |
3 | * DTLS implementation written by Nagendra Modadugu | 3 | * DTLS implementation written by Nagendra Modadugu |
4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. |
@@ -449,6 +449,9 @@ dtls1_listen(SSL *s, struct sockaddr *client) | |||
449 | { | 449 | { |
450 | int ret; | 450 | int ret; |
451 | 451 | ||
452 | /* Ensure there is no state left over from a previous invocation */ | ||
453 | SSL_clear(s); | ||
454 | |||
452 | SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE); | 455 | SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE); |
453 | s->d1->listen = 1; | 456 | s->d1->listen = 1; |
454 | 457 | ||