Commit graph

12315 commits

Author SHA1 Message Date
Rich Salz
a03f81f4ea Fix NULL-return checks in 1.0.2
RT4386: Add sanity checks for BN_new()
RT4384: Missing Sanity Checks for RSA_new_method()
RT4384: Missing Sanity Check plus potential NULL pointer deref
RT4382: Missing Sanity Check(s) for BUF_strdup()
RT4380: Missing Sanity Checks for EVP_PKEY_new()
RT4377: Prevent potential NULL pointer dereference
RT4375: Missing sanity checks for OPENSSL_malloc()
RT4374: Potential for NULL pointer dereferences
RT4371: Missing Sanity Check for malloc()
RT4370: Potential for NULL pointer dereferences

Also expand tabs, make update, typo fix (rsalz)
Minor tweak by Paul Dale.
Some minor internal review feedback.

Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-08-19 10:44:32 -04:00
Richard Levitte
66e7083265 Have dtlstest run on VMS as well
Reviewed-by: Matt Caswell <matt@openssl.org>
2016-08-19 14:19:00 +01:00
Matt Caswell
26aebca74e Update function error code
A function error code needed updating due to merge issues.

Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-08-19 13:50:27 +01:00
Matt Caswell
3884b47b7c Fix DTLS replay protection
The DTLS implementation provides some protection against replay attacks
in accordance with RFC6347 section 4.1.2.6.

A sliding "window" of valid record sequence numbers is maintained with
the "right" hand edge of the window set to the highest sequence number we
have received so far. Records that arrive that are off the "left" hand
edge of the window are rejected. Records within the window are checked
against a list of records received so far. If we already received it then
we also reject the new record.

If we have not already received the record, or the sequence number is off
the right hand edge of the window then we verify the MAC of the record.
If MAC verification fails then we discard the record. Otherwise we mark
the record as received. If the sequence number was off the right hand edge
of the window, then we slide the window along so that the right hand edge
is in line with the newly received sequence number.

Records may arrive for future epochs, i.e. a record from after a CCS being
sent, can arrive before the CCS does if the packets get re-ordered. As we
have not yet received the CCS we are not yet in a position to decrypt or
validate the MAC of those records. OpenSSL places those records on an
unprocessed records queue. It additionally updates the window immediately,
even though we have not yet verified the MAC. This will only occur if
currently in a handshake/renegotiation.

This could be exploited by an attacker by sending a record for the next
epoch (which does not have to decrypt or have a valid MAC), with a very
large sequence number. This means the right hand edge of the window is
moved very far to the right, and all subsequent legitimate packets are
dropped causing a denial of service.

A similar effect can be achieved during the initial handshake. In this
case there is no MAC key negotiated yet. Therefore an attacker can send a
message for the current epoch with a very large sequence number. The code
will process the record as normal. If the hanshake message sequence number
(as opposed to the record sequence number that we have been talking about
so far) is in the future then the injected message is bufferred to be
handled later, but the window is still updated. Therefore all subsequent
legitimate handshake records are dropped. This aspect is not considered a
security issue because there are many ways for an attacker to disrupt the
initial handshake and prevent it from completing successfully (e.g.
injection of a handshake message will cause the Finished MAC to fail and
the handshake to be aborted). This issue comes about as a result of trying
to do replay protection, but having no integrity mechanism in place yet.
Does it even make sense to have replay protection in epoch 0? That
issue isn't addressed here though.

This addressed an OCAP Audit issue.

CVE-2016-2181

Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-08-19 13:50:27 +01:00
Matt Caswell
30ea36e695 Add DTLS replay protection test
Injects a record from epoch 1 during epoch 0 handshake, with a record
sequence number in the future, to test that the record replay protection
feature works as expected. This is described more fully in the next commit.

Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-08-19 13:50:27 +01:00
Matt Caswell
20744f6b40 Fix DTLS unprocessed records bug
During a DTLS handshake we may get records destined for the next epoch
arrive before we have processed the CCS. In that case we can't decrypt or
verify the record yet, so we buffer it for later use. When we do receive
the CCS we work through the queue of unprocessed records and process them.

Unfortunately the act of processing wipes out any existing packet data
that we were still working through. This includes any records from the new
epoch that were in the same packet as the CCS. We should only process the
buffered records if we've not got any data left.

Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-08-19 13:50:27 +01:00
Matt Caswell
bc4d7e1230 Add a DTLS unprocesed records test
Add a test to inject a record from the next epoch during the handshake and
make sure it doesn't get processed immediately.

Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-08-19 13:50:27 +01:00
Matt Caswell
48e8df6e39 Back port ssltestlib code to 1.0.2
Enables the testing of DTLS code in 1.0.2

Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-08-19 13:50:27 +01:00
Richard Levitte
7b415b0ec3 VSI submission: RAND fixups
- make the VMS version of RAND_poll() faster and more secure
- avoid pointer size warnings with setvbuf()

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-19 14:41:07 +02:00
Richard Levitte
23ffde2eac VSI submission: make better use of item lists in o_time.c
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-19 14:41:07 +02:00
Richard Levitte
556c4b51d5 VSI submission: avoid pointer size warnings in mem.c
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-19 14:41:07 +02:00
Richard Levitte
c78a34f475 evp_test.c: avoid warning from having a pointer difference returned as int
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-19 14:41:07 +02:00
Richard Levitte
8a2ce3a313 VMS: synchronise tests with Unix
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-18 17:17:12 +02:00
Richard Levitte
a1be17a72f make update to have PEM_R_HEADER_TOO_LONG defined
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-08-16 14:14:33 +02:00
Dr. Stephen Henson
b552f32dcb Limit reads in do_b2i_bio()
Apply a limit to the maximum blob length which can be read in do_d2i_bio()
to avoid excessive allocation.

Thanks to Shi Lei for reporting this.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 66bcba1457)
2016-08-16 00:28:16 +01:00
Dr. Stephen Henson
e36f27ddb8 Check for errors in BN_bn2dec()
If an oversize BIGNUM is presented to BN_bn2dec() it can cause
BN_div_word() to fail and not reduce the value of 't' resulting
in OOB writes to the bn_data buffer and eventually crashing.

Fix by checking return value of BN_div_word() and checking writes
don't overflow buffer.

Thanks to Shi Lei for reporting this bug.

CVE-2016-2182

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

Conflicts:
	crypto/bn/bn_print.c
2016-08-16 00:21:54 +01:00
Dr. Stephen Henson
d871284aca Check for errors in a2d_ASN1_OBJECT()
Check for error return in BN_div_word().

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit 8b9afbc0fc)
2016-08-16 00:20:34 +01:00
Andy Polyakov
657566ead9 sha/asm/sha1-x86_64.pl: fix crash in SHAEXT code on Windows.
RT#4530

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit 7123aa81e9)
2016-08-11 13:41:01 +02:00
Dr. Stephen Henson
13bacff9aa Sanity check input length in OPENSSL_uni2asc().
Thanks to Hanno Böck for reporting this bug.

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

Conflicts:
	crypto/pkcs12/p12_utl.c
2016-08-05 19:00:34 +01:00
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
f96b3ff25e Limit status message sisze in ts_get_status_check
Thanks to Shi Lei for reporting this issue.

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

Conflicts:
	include/openssl/ts.h
2016-08-04 17:37:59 +01:00
Richard Levitte
1228ae7738 Don't check any revocation info on proxy certificates
Because proxy certificates typically come without any CRL information,
trying to check revocation on them will fail.  Better not to try
checking such information for them at all.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 790555d675)
2016-08-03 16:15:05 +02: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
3dc160e9be Fix CRL time comparison.
Thanks to David Benjamin <davidben@google.com> for reporting this bug.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit e032117db2)
2016-07-29 18:49:12 +01:00
Rich Salz
cdddc96d5d Add missing casts.
Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
2016-07-28 11:48:59 -04:00
Dr. Stephen Henson
68bc6b7a36 Note cipher BIO write errors too.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 976ef6adcc)

Conflicts:
	crypto/evp/bio_enc.c
2016-07-26 22:45:04 +01:00
Dr. Stephen Henson
97a7b2ebd9 Set error if EVP_CipherUpdate fails.
Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit ee6ce5cc36)

Conflicts:
	crypto/evp/bio_enc.c
2016-07-26 17:12:46 +01:00
Dr. Stephen Henson
325da8231c Use newest CRL.
If two CRLs are equivalent then use the one with a later lastUpdate field:
this will result in the newest CRL available being used.

RT#4615

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 626aa24849)
2016-07-22 16:15:02 +01:00
Dr. Stephen Henson
02f873c541 Send alert for bad DH CKE
RT#4511

Reviewed-by: Matt Caswell <matt@openssl.org>
2016-07-22 16:02:07 +01:00
Dr. Stephen Henson
b746aa3fe0 Fix OOB read in TS_OBJ_print_bio().
TS_OBJ_print_bio() misuses OBJ_txt2obj: it should print the result
as a null terminated buffer. The length value returned is the total
length the complete text reprsentation would need not the amount of
data written.

CVE-2016-2180

Thanks to Shi Lei for reporting this bug.

Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit 0ed26acce3)
2016-07-22 15:16:31 +01:00
Dr. Stephen Henson
b880283683 Clarify digest change in HMAC_Init_ex()
RT#4603

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-07-22 14:11:13 +01:00
Todd Short
941d9fb6bd OCSP_request_add0_id() inconsistent error return
There are two failure cases for OCSP_request_add_id():
1. OCSP_ONEREQ_new() failure, where |cid| is not freed
2. sk_OCSP_ONEREQ_push() failure, where |cid| is freed

This changes makes the error behavior consistent, such that |cid| is
not freed when sk_OCSP_ONEREQ_push() fails. OpenSSL only takes
ownership of |cid| when the function succeeds.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1289)
(cherry picked from commit 415e7c488e)
2016-07-20 01:29:16 -04:00
Dr. Stephen Henson
b5c835b399 Sanity check in ssl_get_algorithm2().
RT#4600

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

Conflicts:
	ssl/s3_lib.c
2016-07-20 00:14:36 +01:00
Dr. Stephen Henson
9ae9cbc0c7 Send alert on CKE error.
RT#4610

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-07-19 17:20:58 +01:00
Dr. Stephen Henson
6d3b5eeb51 Support PKCS v2.0 print in pkcs12 utility.
Extended alg_print() in pkcs12 utility to support PBES2 algorithms.

RT#4588

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-07-19 12:32:05 +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
Richard Levitte
25dfe50b51 Remove the silly CVS markers from LPdir_*.c
Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 28e90f69fb)
2016-07-16 09:04:56 +02:00
Richard Levitte
427b22646d Fix ASN.1 private encode of EC_KEY to not change the input key
RT#4611

Reviewed-by: Stephen Henson <steve@openssl.org>
(cherry picked from commit b8a7bd83e6)
2016-07-15 15:17:31 +02:00
Matt Caswell
e88a5cfc2c Disallow multiple protocol flags to s_server and s_client
We shouldn't allow both "-tls1" and "-tls1_2", or "-tls1" and "-no_tls1_2".
The only time multiple flags are allowed is where they are all "-no_<prot>".

This fixes Github Issue #1268

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-07-08 16:24:00 +01:00
Orgad Shaneh
23aec60661 Fix compilation with CMS disabled
Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1293)
2016-07-06 08:44:51 +03: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
Cristian Stoica
6c6bd9bc2f remove double initialization of cryptodev engine
cryptodev engine is initialized together with the other engines in
ENGINE_load_builtin_engines. The initialization done through
OpenSSL_add_all_algorithms is redundant.

Signed-off-by: Cristian Stoica <cristian.stoica@nxp.com>

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2016-07-05 22:56:45 +02:00
Matt Caswell
77857ddcca Avoid an overflow in constructing the ServerKeyExchange message
We calculate the size required for the ServerKeyExchange message and then
call BUF_MEM_grow_clean() on the buffer. However we fail to take account of
2 bytes required for the signature algorithm and 2 bytes for the signature
length, i.e. we could overflow by 4 bytes. In reality this won't happen
because the buffer is pre-allocated to a large size that means it should be
big enough anyway.

Addresses an OCAP Audit issue.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-07-01 19:26:12 +01:00