oweals/openssl.git
8 years agoProperly own the duplicated string
Dmitry-Me [Wed, 9 Mar 2016 12:25:07 +0000 (15:25 +0300)]
Properly own the duplicated string

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoImprove comment
Dmitry-Me [Mon, 14 Mar 2016 11:39:32 +0000 (14:39 +0300)]
Improve comment

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoTry 'make install' with one of the Travis configurations
Richard Levitte [Tue, 29 Mar 2016 15:50:53 +0000 (17:50 +0200)]
Try 'make install' with one of the Travis configurations

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoPrevent EBCDIC overread for very long strings
Matt Caswell [Thu, 28 Apr 2016 09:46:55 +0000 (10:46 +0100)]
Prevent EBCDIC overread for very long strings

ASN1 Strings that are over 1024 bytes can cause an overread in
applications using the X509_NAME_oneline() function on EBCDIC systems.
This could result in arbitrary stack data being returned in the buffer.

Issue reported by Guido Vranken.

CVE-2016-2176

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoFix encrypt overflow
Matt Caswell [Thu, 3 Mar 2016 23:36:23 +0000 (23:36 +0000)]
Fix encrypt overflow

An overflow can occur in the EVP_EncryptUpdate function. If an attacker is
able to supply very large amounts of input data after a previous call to
EVP_EncryptUpdate with a partial block then a length check can overflow
resulting in a heap corruption.

Following an analysis of all OpenSSL internal usage of the
EVP_EncryptUpdate function all usage is one of two forms.

The first form is like this:
EVP_EncryptInit()
EVP_EncryptUpdate()

i.e. where the EVP_EncryptUpdate() call is known to be the first called
function after an EVP_EncryptInit(), and therefore that specific call
must be safe.

The second form is where the length passed to EVP_EncryptUpdate() can be
seen from the code to be some small value and therefore there is no
possibility of an overflow.

Since all instances are one of these two forms, I believe that there can
be no overflows in internal code due to this problem.

It should be noted that EVP_DecryptUpdate() can call EVP_EncryptUpdate()
in certain code paths. Also EVP_CipherUpdate() is a synonym for
EVP_EncryptUpdate(). Therefore I have checked all instances of these
calls too, and came to the same conclusion, i.e. there are no instances
in internal usage where an overflow could occur.

This could still represent a security issue for end user code that calls
this function directly.

CVE-2016-2106

Issue reported by Guido Vranken.

Reviewed-by: Tim Hudson <tjh@openssl.org>
8 years agoFix i2d_X509_AUX: pp can be NULL.
Dr. Stephen Henson [Mon, 2 May 2016 16:33:50 +0000 (17:33 +0100)]
Fix i2d_X509_AUX: pp can be NULL.

Reported by David Benjamin

Reviewed-by: Emilia Käsper <emilia@openssl.org>
8 years agoGH875: Document -no_check_time
Rich Salz [Mon, 2 May 2016 21:03:55 +0000 (17:03 -0400)]
GH875: Document -no_check_time
Date:   Tue Mar 15 15:19:44 2016 +0100

This commit updates the documentation of cms, ocsp, s_client,
s_server, and verify to reflect the new "-no_check_time"
option introduced in commit d35ff2c0ade0a12e84aaa2e9841b4983a2f3cf45
on 2015-07-31.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoRemove confusing comment.
TJ Saunders [Fri, 29 Apr 2016 14:41:50 +0000 (07:41 -0700)]
Remove confusing comment.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoIssue #719:
TJ Saunders [Wed, 23 Mar 2016 18:55:53 +0000 (11:55 -0700)]
Issue #719:

If no serverinfo extension is found in some cases, do not abort the handshake,
but simply omit/skip that extension.

Check for already-registered serverinfo callbacks during serverinfo
registration.

Update SSL_CTX_use_serverinfo() documentation to mention the need to reload the
same serverinfo per certificate, for servers with multiple server certificates.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoDocument the addition of OPENSSL_LOCAL_CONFIG_DIR
Richard Levitte [Mon, 2 May 2016 18:00:12 +0000 (20:00 +0200)]
Document the addition of OPENSSL_LOCAL_CONFIG_DIR

Reviewed-by: Stephen Henson <steve@openssl.org>
8 years agoAdd the possibility for local build file templates
Richard Levitte [Mon, 2 May 2016 15:05:48 +0000 (17:05 +0200)]
Add the possibility for local build file templates

Use the environment variable OPENSSL_LOCAL_CONFIG_DIR to find build
file templates as well.

Reviewed-by: Stephen Henson <steve@openssl.org>
8 years agoAdd the possibility to have an extra local OpenSSL configs directory
Richard Levitte [Mon, 2 May 2016 14:50:51 +0000 (16:50 +0200)]
Add the possibility to have an extra local OpenSSL configs directory

The environment variable OPENSSL_LOCAL_CONFIG_DIR is used to indicate
that there's a local directory with extra configuration files.

Reviewed-by: Stephen Henson <steve@openssl.org>
8 years agoRemove personal configs from version control
Richard Levitte [Mon, 2 May 2016 14:02:04 +0000 (16:02 +0200)]
Remove personal configs from version control

As per a team decision back in 2014.

Reviewed-by: Stephen Henson <steve@openssl.org>
8 years agoSecure memory fixes
Todd Short [Mon, 11 Apr 2016 20:03:42 +0000 (16:03 -0400)]
Secure memory fixes

Fix some of the variables to be (s)size_t, so that more than 1GB of
secure memory can be allocated. The arena has to be a power of 2, and
2GB fails because it ends up being a negative 32-bit signed number.

The |too_late| flag is not strictly necessary; it is easy to figure
out if something is secure memory by looking at the arena. As before,
secure memory allocations will not fail, but now they can be freed
correctly. Once initialized, secure memory can still be used, even if
allocations occured before initialization.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agossl/record/rec_layer_s3.c: fix typo from previous commit.
Andy Polyakov [Mon, 2 May 2016 13:20:41 +0000 (15:20 +0200)]
ssl/record/rec_layer_s3.c: fix typo from previous commit.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoHandle multi-line "written by/for" comments.
Rich Salz [Sun, 1 May 2016 13:23:38 +0000 (09:23 -0400)]
Handle multi-line "written by/for" comments.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoAndroid build fixes.
Andy Polyakov [Sun, 1 May 2016 11:35:31 +0000 (13:35 +0200)]
Android build fixes.

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoRemove obsolete defined(__INTEL__) condition.
Andy Polyakov [Sun, 1 May 2016 12:14:34 +0000 (14:14 +0200)]
Remove obsolete defined(__INTEL__) condition.

This macro was defined by no-longer-supported __MWERKS__ compiler.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agochacha/asm/chacha-x86.pl: make it compile on legacy systems.
Andy Polyakov [Sun, 1 May 2016 12:09:15 +0000 (14:09 +0200)]
chacha/asm/chacha-x86.pl: make it compile on legacy systems.

Usage of $ymm variable is a bit misleading here, it doesn't refer
to %ymm register bank, but rather to VEX instruction encoding,
which AMD XOP code path depends on.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFix spelling in pod files
FdaSilvaYY [Sun, 1 May 2016 17:52:58 +0000 (19:52 +0200)]
Fix spelling in pod files

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agomake update
Richard Levitte [Sun, 1 May 2016 13:10:15 +0000 (15:10 +0200)]
make update

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoAdd the adjusted perl scripts to the set of "update" scripts
Richard Levitte [Sun, 1 May 2016 13:09:20 +0000 (15:09 +0200)]
Add the adjusted perl scripts to the set of "update" scripts

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoAdjust a last few generators to new license boilerplate and C code style
Richard Levitte [Sun, 1 May 2016 13:08:34 +0000 (15:08 +0200)]
Adjust a last few generators to new license boilerplate and C code style

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoSkip blank lines if old copyright comment was removed, and only then
Richard Levitte [Sun, 1 May 2016 12:01:50 +0000 (14:01 +0200)]
Skip blank lines if old copyright comment was removed, and only then

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoFix some X509_STORE macros
Matt Caswell [Fri, 29 Apr 2016 16:44:46 +0000 (17:44 +0100)]
Fix some X509_STORE macros

Some X509_STORE macros do not work since the type was made opaque.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
8 years agoAdd checks to X509_NAME_oneline()
Dr. Stephen Henson [Thu, 28 Apr 2016 18:45:44 +0000 (19:45 +0100)]
Add checks to X509_NAME_oneline()

Sanity check field lengths and sums to avoid potential overflows and reject
excessively large X509_NAME structures.

Issue reported by Guido Vranken.

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoSanity check buffer length.
Dr. Stephen Henson [Thu, 28 Apr 2016 12:09:27 +0000 (13:09 +0100)]
Sanity check buffer length.

Reject zero length buffers passed to X509_NAME_onelne().

Issue reported by Guido Vranken.

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoAdd size limit to X509_NAME structure.
Dr. Stephen Henson [Thu, 28 Apr 2016 11:55:29 +0000 (12:55 +0100)]
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>
8 years agoRemove BIO_dummy, it's old cruft
Richard Levitte [Fri, 29 Apr 2016 16:59:20 +0000 (18:59 +0200)]
Remove BIO_dummy, it's old cruft

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoChange 'struct bio_st' in all public header where applicable
Richard Levitte [Fri, 29 Apr 2016 16:57:58 +0000 (18:57 +0200)]
Change 'struct bio_st' in all public header where applicable

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoAdd asn1_mac
Rich Salz [Fri, 29 Apr 2016 16:42:22 +0000 (12:42 -0400)]
Add asn1_mac

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoRemove some dead code from EC_GROUP_check()
Matt Caswell [Fri, 29 Apr 2016 14:22:18 +0000 (15:22 +0100)]
Remove some dead code from EC_GROUP_check()

EC_GROUP_check() was obtaining a temporary BIGNUM from the BN_CTX, but
then not using it.

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoDon't use an uninitialised variable in srp application
Matt Caswell [Fri, 29 Apr 2016 11:17:15 +0000 (12:17 +0100)]
Don't use an uninitialised variable in srp application

The srp application created an uninitialised DB_ATTR object and then
passed it to the load_index function which attempted to read it. A
DB_ATTR object only contains a single field called "unique_subject".
AFAICT this attribute is unused in the SRP case, and therefore it would be
better to pass a NULL DB_ATTR to load_index (which handles that case
gracefully).

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoAvoid a NULL ptr deref if group is not set
Matt Caswell [Fri, 29 Apr 2016 10:44:39 +0000 (11:44 +0100)]
Avoid a NULL ptr deref if group is not set

We should only copy parameters and keys if the group is set. Otherwise
they don't really make any sense. Previously we copied the private key
regardless of whether the group was set...but if it wasn't a NULL ptr
deref could occur. It's unclear whether we could ever get into that
situation, but since we were already checking it for the public key we
should be consistent.

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoCheck for a NULL return value from a call to X509_STORE_CTX_new()
Matt Caswell [Fri, 29 Apr 2016 10:29:50 +0000 (11:29 +0100)]
Check for a NULL return value from a call to X509_STORE_CTX_new()

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoCheck for failed malloc in BIO_ADDR_new
Matt Caswell [Fri, 29 Apr 2016 10:27:09 +0000 (11:27 +0100)]
Check for failed malloc in BIO_ADDR_new

BIO_ADDR_new() calls OPENSSL_zalloc() which can fail - but the return
value is not checked.

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoThe x509_name_canon function doesn't check for an error return
Matt Caswell [Thu, 28 Apr 2016 16:05:21 +0000 (17:05 +0100)]
The x509_name_canon function doesn't check for an error return

i2d_name_canon can return a negative number on error. We should check it
before continuing.

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoMake header signature of CRYPTO_mem_leaks BIO instead of struct bio_st
Paul Kehrer [Fri, 29 Apr 2016 13:52:55 +0000 (08:52 -0500)]
Make header signature of CRYPTO_mem_leaks BIO instead of struct bio_st

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1012)

8 years agoAvoid overflow issues in X509_cmp.
David Benjamin [Thu, 28 Apr 2016 00:02:35 +0000 (20:02 -0400)]
Avoid overflow issues in X509_cmp.

The length is a long, so returning the difference does not quite work.

Thanks to Torbjörn Granlund for noticing.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoMisc tweaks for EBCDIC based on feedback received
Matt Caswell [Fri, 29 Apr 2016 13:46:07 +0000 (14:46 +0100)]
Misc tweaks for EBCDIC based on feedback received

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoFix EBCDIC problem in conf_def.h
Matt Caswell [Fri, 29 Apr 2016 10:03:00 +0000 (11:03 +0100)]
Fix EBCDIC problem in conf_def.h

The non-ascii version of this set of macros ensures that the "a" variable
is inside the expected range. This logic wasn't quite right for the
EBCDIC version.

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoFix the tests to work with EBCDIC
Matt Caswell [Fri, 29 Apr 2016 09:56:20 +0000 (10:56 +0100)]
Fix the tests to work with EBCDIC

Most of the tests already pass with EBCIDC but a few were trying to
write into read only memory.

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoFix a build error with strict-warnings and CHARSET_EBCDIC
Matt Caswell [Fri, 29 Apr 2016 09:30:05 +0000 (10:30 +0100)]
Fix a build error with strict-warnings and CHARSET_EBCDIC

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoAdd the ability to test EBCDIC builds
Matt Caswell [Fri, 29 Apr 2016 09:19:27 +0000 (10:19 +0100)]
Add the ability to test EBCDIC builds

This adds the define CHARSET_EBCDIC_TEST which enables testing of EBCDIC
code on an ASCII system.

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoFix building with -DCHARSET_EBCDIC
Matt Caswell [Thu, 28 Apr 2016 10:34:54 +0000 (11:34 +0100)]
Fix building with -DCHARSET_EBCDIC

Building with -DCHARSET_EBCDIC and using --strict-warnings resulted in
lots of miscellaneous errors. This fixes it.

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoVMS: only explicitely translate names in library C files.
Richard Levitte [Thu, 28 Apr 2016 16:18:04 +0000 (18:18 +0200)]
VMS: only explicitely translate names in library C files.

When compiling all other C files, rely on the compiler to
automatically pick up the name translation information from the header
files __DECC_INCLUDE_{PRO,EPI}LOGUE.H.

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoVMS: It seems DEC C doesn't handle certain header files quite right
Richard Levitte [Mon, 11 Apr 2016 16:42:52 +0000 (18:42 +0200)]
VMS: It seems DEC C doesn't handle certain header files quite right

With DEC C on VMS, you can use __DECC_INCLUDE_PROLOGUE.H and
__DECC_INCLUDE_EPILOGUE.H to include some DEC C specific features or
pragmas without having to touch the other header files.

It seems, however, that the current version of the compiler requires
the file names to be upcased, or it doesn't handle them quite right.

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoAdd aliases for des-ede-ecb and des-ede3-ecb ciphers.
Kirill Marinushkin [Sun, 24 Apr 2016 09:30:08 +0000 (11:30 +0200)]
Add aliases for des-ede-ecb and des-ede3-ecb ciphers.

Currently we can get all block ciphers with
EVP_get_cipherbyname("<alg_name>-<block-mode-name>")
for example, by names "aes-128-ecb" or "des-ede-cbc".
I found a problem with des-ede-ecb and des-ede3-ecb ciphers as
they can be accessed only with names:
EVP_get_cipherbyname("des-ede")
EVP_get_cipherbyname("des-ede3")
It breaks the general concept.

In this patch I add aliases which allow to use names:
EVP_get_cipherbyname("des-ede-ecb")
EVP_get_cipherbyname("des-ede3-ecb")
in addition to the currently used names.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoFixed scripts order for generate_crypto_objects target
Kirill Marinushkin [Sun, 24 Apr 2016 00:01:25 +0000 (02:01 +0200)]
Fixed scripts order for generate_crypto_objects target

Script obj_dat.pl depends on file obj_mac.h generated by script objects.pl

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agocrypto/ppccap.c: fix missing declaration warning.
Andy Polyakov [Wed, 27 Apr 2016 13:46:05 +0000 (15:46 +0200)]
crypto/ppccap.c: fix missing declaration warning.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agocrypto/ppccap.c: permit build with no-chacha and no-poly1305.
Andy Polyakov [Wed, 27 Apr 2016 13:42:36 +0000 (15:42 +0200)]
crypto/ppccap.c: permit build with no-chacha and no-poly1305.

RT#4508

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoRemove some dead code
Matt Caswell [Thu, 28 Apr 2016 15:47:36 +0000 (16:47 +0100)]
Remove some dead code

Commit e1d9f1ab39eea left some dead code behind. This removes it.

Reviewed-by: Stephen Henson <steve@openssl.org>
8 years agoA call to RSA_set0_key had the arguments in the wrong order
Matt Caswell [Thu, 28 Apr 2016 14:20:52 +0000 (15:20 +0100)]
A call to RSA_set0_key had the arguments in the wrong order

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoClient side CKE processing can double free on error
Matt Caswell [Thu, 28 Apr 2016 14:12:37 +0000 (15:12 +0100)]
Client side CKE processing can double free on error

The tls_client_key_exchange_post_work() frees the pms on error. It also
calls ssl_generate_master_secret() which also free the pms. If an error
occurs after ssl_generate_master_secret() has been called then a double
free can occur.

Reviewed-by: Andy Polyakov <appro@openssl.org>
8 years agoDon't free the BIGNUM passed to BN_mpi2bn
Matt Caswell [Thu, 28 Apr 2016 18:53:08 +0000 (19:53 +0100)]
Don't free the BIGNUM passed to BN_mpi2bn

Commit 91fb42dd fixed a leak but introduced a problem where a parameter
is erroneously freed instead.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoFix a leak in i2b_PVK
Matt Caswell [Thu, 28 Apr 2016 18:49:17 +0000 (19:49 +0100)]
Fix a leak in i2b_PVK

Commit 8e588e28 fixed a leak but introduced a new one.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agomake update
Richard Levitte [Fri, 29 Apr 2016 07:09:46 +0000 (09:09 +0200)]
make update

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoapps/progs.pl: don't make digests disablable by default
Richard Levitte [Fri, 29 Apr 2016 07:08:06 +0000 (09:08 +0200)]
apps/progs.pl: don't make digests disablable by default

Some digest algorithms can't be disabled, don't pretend they can.

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoBIO_free should call method->destroy before free'ing member fields
FdaSilvaYY [Thu, 28 Apr 2016 18:13:44 +0000 (20:13 +0200)]
BIO_free should call method->destroy before free'ing member fields

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1007)

8 years agoAdd checks on CRYPTO_new_ex_data return value...
FdaSilvaYY [Tue, 8 Mar 2016 19:11:48 +0000 (20:11 +0100)]
Add checks on CRYPTO_new_ex_data return value...
with some adaptation to new multi-threading API.

Once reference, lock, meth and flag fields are setup,
DSA_free/DH_free can be called directly.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/996)

8 years agoAdd checks on CRYPTO_new_ex_data return value
FdaSilvaYY [Sat, 13 Feb 2016 18:29:34 +0000 (19:29 +0100)]
Add checks on CRYPTO_new_ex_data return value

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/996)

8 years agoFix an error code spelling.
FdaSilvaYY [Mon, 4 Apr 2016 18:42:27 +0000 (20:42 +0200)]
Fix an error code spelling.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/952)

8 years agovarious spelling fixes
FdaSilvaYY [Thu, 10 Mar 2016 20:34:48 +0000 (21:34 +0100)]
various spelling fixes

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/952)

8 years agoAdd getters for X509_STORE and X509_OBJECT members
Christian Heimes [Tue, 19 Apr 2016 19:11:30 +0000 (21:11 +0200)]
Add getters for X509_STORE and X509_OBJECT members

OpenSSL 1.1.0-pre5 has made some additional structs opaque. Python's ssl
module requires access to some of the struct members. Three new getters
are added:

int X509_OBJECT_get_type(X509_OBJECT *a);
STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *v);
X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *ctx);

Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agomake update
Viktor Dukhovni [Wed, 27 Apr 2016 18:37:19 +0000 (14:37 -0400)]
make update

Recycling an unused slot.

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoImplement X509_STORE_CTX_set_current_cert() accessor
Viktor Dukhovni [Wed, 27 Apr 2016 18:36:48 +0000 (14:36 -0400)]
Implement X509_STORE_CTX_set_current_cert() accessor

Reviewed-by: Rich Salz <rsalz@openssl.org>
8 years agoFix BIO_set_nbio_accept()
Richard Levitte [Thu, 28 Apr 2016 15:39:26 +0000 (17:39 +0200)]
Fix BIO_set_nbio_accept()

The code that implements this control would work when enabling nbio,
but the disabling code needed fixing.

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoDon't leak memory on error path in dane_ctx_enable()
Matt Caswell [Wed, 27 Apr 2016 13:22:20 +0000 (14:22 +0100)]
Don't leak memory on error path in dane_ctx_enable()

The function dane_ctx_enable() allocated some memory that it did not
free in an error path.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFree an ASN1_OBJECT in an error path
Matt Caswell [Wed, 27 Apr 2016 13:17:33 +0000 (14:17 +0100)]
Free an ASN1_OBJECT in an error path

The r2i_certpol() function allocates an ASN1_OBJECT but can fail to free
it in an error path.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak an ASN1_OCTET_STRING on error in rsa_cms_encrypt
Matt Caswell [Wed, 27 Apr 2016 13:13:59 +0000 (14:13 +0100)]
Don't leak an ASN1_OCTET_STRING on error in rsa_cms_encrypt

The rsa_cms_encrypt() function allocates an ASN1_OCTET_STRING but can
then fail to free it in an error condition.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFree memory on error in PKCS7_dataFinal()
Matt Caswell [Wed, 27 Apr 2016 13:09:35 +0000 (14:09 +0100)]
Free memory on error in PKCS7_dataFinal()

The PKCS7_dataFinal() function allocates a memory buffer but then fails
to free it on an error condition.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak memory on error in PKCS12_key_gen_uni
Matt Caswell [Wed, 27 Apr 2016 13:06:40 +0000 (14:06 +0100)]
Don't leak memory on error in PKCS12_key_gen_uni

The PKCS12_key_gen_uni() had one error path which did not free memory
correctly.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak memory on error in i2b_PVK
Matt Caswell [Wed, 27 Apr 2016 13:00:37 +0000 (14:00 +0100)]
Don't leak memory on error in i2b_PVK

The i2b_PVK function leaked a number of different memory allocations on
error paths (and even some non-error paths).

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak memory on error in b2i_rsa
Matt Caswell [Wed, 27 Apr 2016 12:52:37 +0000 (13:52 +0100)]
Don't leak memory on error in b2i_rsa

The b2i_rsa() function uses a number of temporary local variables which
get leaked on an error path.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak resource on error in OCSP_url_svcloc_new
Matt Caswell [Wed, 27 Apr 2016 12:40:52 +0000 (13:40 +0100)]
Don't leak resource on error in OCSP_url_svcloc_new

On error we could leak a ACCESS_DESCRIPTION and an ASN1_IA5STRING. Both
should be freed in the error path.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoCheck that we were actually allocated BIGNUMs in dsa_builtin_paramgen2
Matt Caswell [Wed, 27 Apr 2016 12:32:58 +0000 (13:32 +0100)]
Check that we were actually allocated BIGNUMs in dsa_builtin_paramgen2

Calls to BN_CTX_get() can fail so we should check that they were
successful.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak EVP_MD_CTX on error path
Matt Caswell [Wed, 27 Apr 2016 12:22:29 +0000 (13:22 +0100)]
Don't leak EVP_MD_CTX on error path

The cms_SignerInfo_content_sign() function allocated an EVP_MD_CTX but
then failed to free it on an error path.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak memory on error in cms_RecipientInfo_pwri_crypt
Matt Caswell [Wed, 27 Apr 2016 12:18:38 +0000 (13:18 +0100)]
Don't leak memory on error in cms_RecipientInfo_pwri_crypt

The cms_RecipientInfo_pwri_crypt() allocated an EVP_CIPHER_CTX but then
failed to free it in some error paths. By allocating it a bit later that
can be avoided.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak memory on error in BN_generate_prime_ex
Matt Caswell [Wed, 27 Apr 2016 11:59:19 +0000 (12:59 +0100)]
Don't leak memory on error in BN_generate_prime_ex

In BN_generate_prime_ex() we do some sanity checks first and return
with an error if they fail. We should do that *before* allocating any
resources to avoid a memory leak.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFree a BIGNUM on error in BN_mpi2bn
Matt Caswell [Wed, 27 Apr 2016 11:55:44 +0000 (12:55 +0100)]
Free a BIGNUM on error in BN_mpi2bn

In the BN_mpi2bn() function, a failure of a call to BN_bin2bn() could
result in the leak of a previously allocated BIGNUM value.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoDon't leak memory on failure to create a mem BIO
Matt Caswell [Wed, 27 Apr 2016 11:52:29 +0000 (12:52 +0100)]
Don't leak memory on failure to create a mem BIO

During construction of a mem BIO we allocate some resources. If this
allocation fails we can end up leaking everything we have allocated so
far.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoClose the accept socket on error
Matt Caswell [Wed, 27 Apr 2016 11:46:51 +0000 (12:46 +0100)]
Close the accept socket on error

When setting an accepted socket for non-blocking, if the operation fails
make sure we close the accepted socket.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoMake BIO_sock_error return a proper error code when getsockopt fails
Richard Levitte [Thu, 28 Apr 2016 11:19:38 +0000 (13:19 +0200)]
Make BIO_sock_error return a proper error code when getsockopt fails

BIO_sock_error() returned 1 when getsockopt() fails when it should
return the error code for that failure.

Additionally, the optlen parameter to getsockopt() has to point at
the size of the area that the optval parameter points at rather than
zero.  Some systems may forgive it being zero, but others don't.

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoReject inappropriate private key encryption ciphers.
Dr. Stephen Henson [Sat, 23 Apr 2016 12:33:05 +0000 (13:33 +0100)]
Reject inappropriate private key encryption ciphers.

The traditional private key encryption algorithm doesn't function
properly if the IV length of the cipher is zero. These ciphers
(e.g. ECB mode) are not suitable for private key encryption
anyway.

Reviewed-by: Emilia Käsper <emilia@openssl.org>
8 years agoFix set0 reuse test
Viktor Dukhovni [Wed, 27 Apr 2016 19:08:33 +0000 (15:08 -0400)]
Fix set0 reuse test

We must test for new object == current object, not !=.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFuture proof build_chain() in x509_vfy.c
Viktor Dukhovni [Tue, 26 Apr 2016 18:17:57 +0000 (14:17 -0400)]
Future proof build_chain() in x509_vfy.c

Coverity reports a potential NULL deref when "2 0 0" DANE trust-anchors
from DNS are configured via SSL_dane_tlsa_add() and X509_STORE_CTX_init()
is called with a NULL stack of untrusted certificates.

Since ssl_verify_cert_chain() always provideds a non-NULL stack of
untrusted certs, and no other code path enables DANE, the problem
can only happen in applications that use SSL_CTX_set_cert_verify_callback()
to implement their own wrappers around X509_verify_cert() passing
only the leaf certificate to the latter.

Regardless of the "improbability" of the problem, we do need to
ensure that build_chain() handles this case correctly.

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoDocumentation the changed {RSA,DSA,DH}_set0_* functionality change
Richard Levitte [Tue, 26 Apr 2016 11:40:53 +0000 (13:40 +0200)]
Documentation the changed {RSA,DSA,DH}_set0_* functionality change

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoRSA, DSA, DH: Allow some given input to be NULL on already initialised keys
Richard Levitte [Mon, 25 Apr 2016 18:28:54 +0000 (20:28 +0200)]
RSA, DSA, DH: Allow some given input to be NULL on already initialised keys

The diverse {RSA,DSA,DH}_set0_* functions are made to allow some
parameters to be NULL IF the corresponding numbers in the given key
structure have already been previously initialised.  Specifically,
this allows the addition of private components to be added to a key
that already has the public half, approximately like this:

    RSA_get0_key(rsa, NULL, &e, NULL);
    RSA_get0_factors(rsa, &p, &q);
    /* calculate new d */
    RSA_set0_key(rsa, NULL, NULL, d);

Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoGH975 Add ex_data functions for X509_STORE
Kazuki Yamaguchi [Tue, 19 Apr 2016 01:22:15 +0000 (10:22 +0900)]
GH975 Add ex_data functions for X509_STORE

Add X509_STORE_{set,get}_ex_data() function and
X509_STORE_get_ex_new_index() macro.

X509_STORE has ex_data and the documentation also mentions them but they
are not actually implemented.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFix no-gost no-srp no-ec no-dh.
Ben Laurie [Tue, 19 Apr 2016 07:25:58 +0000 (08:25 +0100)]
Fix no-gost no-srp no-ec no-dh.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFix enable-ssl-trace no-nextprotoneg.
Ben Laurie [Mon, 18 Apr 2016 09:45:02 +0000 (10:45 +0100)]
Fix enable-ssl-trace no-nextprotoneg.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFix no-engine no-ui.
Ben Laurie [Mon, 18 Apr 2016 09:44:42 +0000 (10:44 +0100)]
Fix no-engine no-ui.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agosplit_send_fragment should always be less than or equal to max_send_fragment
Matt Caswell [Tue, 26 Apr 2016 17:01:24 +0000 (18:01 +0100)]
split_send_fragment should always be less than or equal to max_send_fragment

A bug meant that SSL_CTRL_SET_MAX_SEND_FRAGMENT was not adjusting
split_send_fragment properly.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoFix BIO_CTRL_DUP for an SSL BIO
Matt Caswell [Tue, 26 Apr 2016 16:52:21 +0000 (17:52 +0100)]
Fix BIO_CTRL_DUP for an SSL BIO

The variables in the BIO weren't being duplicated properly.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
8 years agoFix passwd seg fault
Matt Caswell [Tue, 26 Apr 2016 16:00:33 +0000 (17:00 +0100)]
Fix passwd seg fault

Passing the -stdin arg to the passwd command line app *and* supply a
password on the command line causes a seg fault.

Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoSPARCv9 assembly pack: fine-tune run-time switch.
Andy Polyakov [Mon, 25 Apr 2016 21:17:57 +0000 (23:17 +0200)]
SPARCv9 assembly pack: fine-tune run-time switch.

Reviewed-by: Tim Hudson <tjh@openssl.org>
8 years agocamellia/build.info: fix typo
Andy Polyakov [Mon, 25 Apr 2016 21:24:06 +0000 (23:24 +0200)]
camellia/build.info: fix typo

RT#4520

Reviewed-by: Tim Hudson <tjh@openssl.org>
8 years agoRemove dead-code infinite loop
Benjamin Kaduk [Mon, 18 Apr 2016 17:50:34 +0000 (12:50 -0500)]
Remove dead-code infinite loop

Commit d32f5d8733df9938727710d4194e92813c421ef1 added a 'goto end;' statement
at the end of the code block for the 'end' label.  Fortunately, it was after a
return statement, so no infinite loop occurred, but it is still dead code.

Remove the extra goto statement as cleanup.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
8 years agoAdd ex_data functions for X509_STORE
Kazuki Yamaguchi [Tue, 19 Apr 2016 01:22:15 +0000 (10:22 +0900)]
Add ex_data functions for X509_STORE

Add X509_STORE_{set,get}_ex_data() function and
X509_STORE_get_ex_new_index() macro.

X509_STORE has ex_data and the documentation also mentions them but they
are not actually implemented.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
8 years agoEnsure we check i2d_X509 return val
Matt Caswell [Mon, 25 Apr 2016 15:05:55 +0000 (16:05 +0100)]
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>