Commit graph

800 commits

Author SHA1 Message Date
Dr. Stephen Henson
e1be1dce77 Leak fixes.
Fix error path leaks in a2i_ASN1_STRING(), a2i_ASN1_INTEGER() and
a2i_ASN1_ENUMERATED().

Thanks to Shi Lei for reporting these issues.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-05 16:46:09 +01:00
Kurt Roeckx
32baafb2f6 Return error when trying to print invalid ASN1 integer
GH: #1322
(cherry picked from commit 5e3553c2de)

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Stephen Henson <steve@openssl.org>
2016-08-04 22:22:07 +01:00
Dr. Stephen Henson
81f69e5b69 Limit recursion depth in old d2i_ASN1_bytes function
Thanks to Shi Lei for reporting this bug.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-04 17:46:27 +01:00
Dr. Stephen Henson
af601b8319 Check for overflows in i2d_ASN1_SET()
Thanks to Shi Lei for reporting this issue.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-04 17:42:53 +01:00
Dr. Stephen Henson
436dead2e2 Calculate sequence length properly.
Use correct length in old ASN.1 indefinite length sequence decoder
(only used by SSL_SESSION).

This bug was discovered by Hanno Böck using libfuzzer.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-03 00:13:03 +01:00
Dr. Stephen Henson
134ab5139a include <limits.h>
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-02 23:41:45 +01:00
Dr. Stephen Henson
ff8b6b92f4 Check for overflows in ASN1_object_size().
Reviewed-by: Richard Levitte <levitte@openssl.org>
(cherry picked from commit e9f17097e9)
2016-08-02 20:54:32 +01:00
Dr. Stephen Henson
b10c10422a Check for overlows and error return from ASN1_object_size()
Reviewed-by: Richard Levitte <levitte@openssl.org>
(cherry picked from commit 56f9953c84)
2016-08-02 20:54:31 +01:00
Dr. Stephen Henson
59eefa115a Check and print out boolean type properly.
If underlying type is boolean don't check field is NULL.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit ad72d9fdf7)
2016-07-19 02:33:34 +01:00
Dr. Stephen Henson
1a2e1334a2 Fix print of ASN.1 BIGNUM type.
The ASN.1 BIGNUM type needs to be handled in a custom way as it is
not a generic ASN1_STRING type.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 3cea73a7fc)

Conflicts:
	crypto/asn1/x_bignum.c
2016-07-18 19:42:12 +01:00
Dr. Stephen Henson
9bda728801 Don't indicate errors during initial adb decode.
Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit b385889640)
2016-07-06 02:41:55 +01:00
Matt Caswell
ad64a69e02 Change usage of RAND_pseudo_bytes to RAND_bytes
RAND_pseudo_bytes() allows random data to be returned even in low entropy
conditions. Sometimes this is ok. Many times it is not. For the avoidance
of any doubt, replace existing usage of RAND_pseudo_bytes() with
RAND_bytes().

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-06-27 15:00:08 +01:00
Matt Caswell
bd598cc405 Fix ASN1_STRING_to_UTF8 could not convert NumericString
tag2nbyte had -1 at 18th position, but underlying ASN1_mbstring_copy
supports NumericString. tag2nbyte is also used in do_print_ex which will
not be broken by setting 1 at 18th position of tag2nbyte

Reviewed-by: Stephen Henson <steve@openssl.org>
(cherry picked from commit d6079a87db)
2016-06-23 20:51:28 +01:00
Richard Levitte
5e102f96eb Change (!seqtt) to (seqtt == NULL)
Reviewed-by: Stephen Henson <steve@openssl.org>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
(cherry picked from commit fdcb499cc2)
2016-06-15 01:42:40 +02:00
Richard Levitte
a9b2346524 Always check that the value returned by asn1_do_adb() is non-NULL
Reviewed-by: Stephen Henson <steve@openssl.org>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
(cherry picked from commit bace847eae)
2016-06-15 01:42:40 +02:00
Dr. Stephen Henson
c421067331 Fix omitted selector handling.
The selector field could be omitted because it has a DEFAULT value.
In this case *sfld == NULL (sfld can never be NULL). This was not
noticed because this was never used in existing ASN.1 modules.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 7c46746bf2)
2016-06-14 19:16:19 +01:00
Dirk Feytons
782a2be2ed Fix build with no-cmac
Add missing ifdefs. Same change is already present in master, see
b4a3aeebd9

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1155)
2016-06-03 13:03:29 -04:00
FdaSilvaYY
f792c66304 Fix some missing inits
Backport of 8e89e85f55
From PR #1019 / #997

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1019)
2016-05-31 16:58:22 -04:00
Richard Levitte
ca3c0d7c03 Revert "make update"
This reverts commit 7229a91a48.

Reviewed-by: Matt Caswell <matt@openssl.org>
2016-05-20 16:21:50 +02:00
Richard Levitte
d29d4b317b Revert "Make it possible to have RFC2254 escapes with ASN1_STRING_print_ex()"
This reverts commit 87728c6829.

Reviewed-by: Matt Caswell <matt@openssl.org>
2016-05-20 16:21:50 +02:00
Richard Levitte
f5d3117d4e Refresh seldom used C generating scripts to current C standard
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-05-18 19:57:06 +02:00
Richard Levitte
7229a91a48 make update
RT#1466

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 0794b6a6a8)
2016-05-18 18:38:47 +02:00
Richard Levitte
87728c6829 Make it possible to have RFC2254 escapes with ASN1_STRING_print_ex()
Also adds 'esc_2254' to the possible command line name options

RT#1466

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit bc77651098)
2016-05-18 18:33:00 +02:00
isnotnick
688c10544d RT3513: req doesn't display attributes using utf8string
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-05-14 20:06:33 +02:00
Viktor Dukhovni
36c3794490 Fix i2d_X509_AUX and update docs
When *pp is NULL, don't write garbage, return an unexpected pointer
or leak memory on error.

Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
2016-05-11 01:50:03 -04:00
Richard Levitte
a20dd9f951 Add NULL check in i2d_PrivateKey()
Originally submitted by Kurt Cancemi <kurt@x64architecture.com>

Closes RT#4533

Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit 59a56c4cf0)
2016-05-09 22:30:25 +02:00
Dr. Stephen Henson
a1eef756cc Fix name length limit check.
The name length limit check in x509_name_ex_d2i() includes
the containing structure as well as the actual X509_NAME. This will
cause large CRLs to be rejected.

Fix by limiting the length passed to ASN1_item_ex_d2i() which will
then return an error if the passed X509_NAME exceeds the length.

RT#4531

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 4e0d184ac1)
2016-05-04 17:40:53 +01:00
Dr. Stephen Henson
b8c75aab21 Fix double free in d2i_PrivateKey().
RT#4527

Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit 3340e8bb18)
2016-05-04 12:59:11 +01:00
Dr. Stephen Henson
d4b2598002 Fix ASN1_INTEGER handling.
Only treat an ASN1_ANY type as an integer if it has the V_ASN1_INTEGER
tag: V_ASN1_NEG_INTEGER is an internal only value which is never used
for on the wire encoding.

Thanks to David Benjamin <davidben@google.com> for reporting this bug.

This was found using libFuzzer.

RT#4364 (part)CVE-2016-2108.

Reviewed-by: Emilia Käsper <emilia@openssl.org>
2016-05-03 13:05:34 +01:00
Dr. Stephen Henson
c5e603ee18 Fix i2d_X509_AUX: pp can be NULL.
Reported by David Benjamin

Reviewed-by: Emilia Käsper <emilia@openssl.org>
(cherry picked from commit 05aef4bbdb)
2016-05-02 22:49:32 +01:00
Dr. Stephen Henson
64eaf6c928 Don't free ret->data if malloc fails.
Issue reported by Guido Vranken.

Reviewed-by: Matt Caswell <matt@openssl.org>
2016-04-29 21:36:14 +01:00
Dr. Stephen Henson
65cb92f4da Add size limit to X509_NAME structure.
This adds an explicit limit to the size of an X509_NAME structure. Some
part of OpenSSL (e.g. TLS) already effectively limit the size due to
restrictions on certificate size.

Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit 295f3a2491)
2016-04-29 19:45:52 +01:00
Matt Caswell
8f43c80bfa Ensure we check i2d_X509 return val
The i2d_X509() function can return a negative value on error. Therefore
we should make sure we check it.

Issue reported by Yuan Jochen Kang.

Reviewed-by: Emilia Käsper <emilia@openssl.org>
(cherry picked from commit 446ba8de9a)
2016-04-26 14:32:45 +01:00
Matt Caswell
0ca67644dd Fix a signed/unsigned warning
This causes a compilation failure when using --strict-warnings in 1.0.2
and 1.0.1

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
2016-04-25 17:45:11 +01:00
Viktor Dukhovni
2442382e11 Fix buffer overrun in ASN1_parse().
Backport of commits:

        79c7f74d6c
	bdcd660e33

from master.

Reviewed-by: Matt Caswell <matt@openssl.org>
2016-04-23 00:44:50 -04:00
Dr. Stephen Henson
f32774087f Harden ASN.1 BIO handling of large amounts of data.
If the ASN.1 BIO is presented with a large length field read it in
chunks of increasing size checking for EOF on each read. This prevents
small files allocating excessive amounts of data.

CVE-2016-2109

Thanks to Brian Carpenter for reporting this issue.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(cherry picked from commit c62981390d)
2016-04-23 00:27:42 +01:00
Dr. Stephen Henson
01c32b5e44 Don't shift serial number into sign bit
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-03-07 15:14:18 +00:00
Kurt Roeckx
29305f4edc Fix invalid free
Also removes an extra initializer, the master branch has a extra field.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-28 13:59:57 +01:00
FdaSilvaYY
e9cf5f0366 Fix possible memory leak on BUF_MEM_grow_clean failure
backport of 3eb70c5eba
shorter changes

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-27 17:05:32 -05:00
Dr. Stephen Henson
cc598f321f Fix leak with ASN.1 combine.
When parsing a combined structure pass a flag to the decode routine
so on error a pointer to the parent structure is not zeroed as
this will leak any additional components in the parent.

This can leak memory in any application parsing PKCS#7 or CMS structures.

CVE-2015-3195.

Thanks to Adam Langley (Google/BoringSSL) for discovering this bug using
libFuzzer.

PR#4131

Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-12-03 14:32:05 +00:00
Dr. Stephen Henson
943c4ca62b Fix uninitialised p error.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 63eb10a07e)
2015-11-24 16:55:34 +00:00
Dr. Stephen Henson
d88ef40a1e Limit depth of ASN1 parse printing.
Thanks to Guido Vranken <guidovranken@gmail.com> for reporting this issue.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit 158e5207a7)

Conflicts:
	crypto/asn1/asn1_par.c
2015-11-24 15:29:05 +00:00
Kurt Roeckx
6b247c1817 Fix more d2i cases to properly update the input pointer
Thanks to David Benjamin <davidben@google.com> for pointing them out.

Reviewed-by: Steve Henson <steve@openssl.org>
MR #1198

(cherry picked from commit 605236f6a8)
2015-10-03 13:29:15 +02:00
Rich Salz
3be39dc1e3 RT4044: Remove .cvsignore files.
Reviewed-by: Matt Caswell <matt@openssl.org>
2015-09-15 11:58:27 -04:00
Kurt Roeckx
728bcd59d3 d2i: don't update input pointer on failure
Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
MR #1005
(cherry picked from commit a46c9789ce)
2015-09-15 00:07:54 +02:00
mrpre
cae70cfd46 check bn_new return value
Slightly modified from the original PR.
Signed-off-by: Rich Salz <rsalz@akamai.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>

(cherry picked from commit a7e974c7be)
2015-08-31 16:04:39 -04:00
Alessandro Ghedini
c8491de393 GH354: Memory leak fixes
Fix more potential leaks in X509_verify_cert()
Fix memory leak in ClientHello test
Fix memory leak in gost2814789 test
Fix potential memory leak in PKCS7_verify()
Fix potential memory leaks in X509_add1_reject_object()
Refactor to use "goto err" in cleanup.

Signed-off-by: Rich Salz <rsalz@akamai.com>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
(cherry picked from commit 55500ea7c4)
2015-08-28 11:59:23 -04:00
Sergey Agievich
ad0fb7f498 Add funtions to set item_sign and item_verify
PR#3872

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Stephen Henson <steve@openssl.org>
2015-06-03 15:18:14 +01:00
Richard Levitte
bf42354620 Fix the update target and remove duplicate file updates
We had updates of certain header files in both Makefile.org and the
Makefile in the directory the header file lived in.  This is error
prone and also sometimes generates slightly different results (usually
just a comment that differs) depending on which way the update was
done.

This removes the file update targets from the top level Makefile, adds
an update: target in all Makefiles and has it depend on the depend: or
local_depend: targets, whichever is appropriate, so we don't get a
double run through the whole file tree.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 0f539dc1a2)

Conflicts:
	Makefile.org
	apps/Makefile
	test/Makefile
2015-05-23 06:25:12 +02:00
Dr. Stephen Henson
3661bb4e79 Fix encoding bug in i2c_ASN1_INTEGER
Fix bug where i2c_ASN1_INTEGER mishandles zero if it is marked as
negative.

Thanks to Huzaifa Sidhpurwala <huzaifas@redhat.com> and
Hanno Böck <hanno@hboeck.de> for reporting this issue.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit a0eed48d37)
2015-04-18 14:43:33 +01:00