openssl.git
7 years agoVMS: use BLDDIR rather than BUILDDIR in descrip.mms.tmpl
Richard Levitte [Tue, 14 Jun 2016 20:03:08 +0000 (22:03 +0200)]
VMS: use BLDDIR rather than BUILDDIR in descrip.mms.tmpl

Just like in the other build file templates

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoAdd a developer target 'build_generated' to rebuild mandatory headers
Richard Levitte [Tue, 14 Jun 2016 19:39:13 +0000 (21:39 +0200)]
Add a developer target 'build_generated' to rebuild mandatory headers

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoBuild file templates: make sure to depend on generated header files
Richard Levitte [Mon, 13 Jun 2016 20:02:11 +0000 (22:02 +0200)]
Build file templates: make sure to depend on generated header files

As well as properly generating those that are made from .in files.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoMove the Configure generated header files to the top build.info
Richard Levitte [Mon, 13 Jun 2016 20:01:08 +0000 (22:01 +0200)]
Move the Configure generated header files to the top build.info

This turns these headers into build file generated ones.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoConfigure: Make it possible to generate mandatory header files
Richard Levitte [Mon, 13 Jun 2016 19:57:51 +0000 (21:57 +0200)]
Configure: Make it possible to generate mandatory header files

'DEPEND[]=file.h' becomes a special way to say that 'file.h' must be
generated before anything else is built.  It's likely that a number
of source files depend on these header files, this provides a simple
way to make sure they are always generated even it the dependency data
hasn't been added to the build file yet.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoFix omitted selector handling.
Dr. Stephen Henson [Tue, 14 Jun 2016 16:44:22 +0000 (17:44 +0100)]
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>
7 years agoUpdate fuzz corpora
Kurt Roeckx [Sun, 12 Jun 2016 11:27:56 +0000 (13:27 +0200)]
Update fuzz corpora

Reviewed-by: Rich Salz <rsalz@openssl.org>
MR: #2949

7 years agoInitialize the session_id
Kurt Roeckx [Sun, 5 Jun 2016 21:34:57 +0000 (23:34 +0200)]
Initialize the session_id

ssl_session_hash() always looks at the first 4 bytes, regardless of the length.
A client can send a session id that's shorter, and the callback could also
generate one that's shorter.  So we make sure that the rest of the buffer is
initliazed to 0 so that we always calculate the same hash.

Found by tis-interpreter, also previously reported as RT #2871

Reviewed-by: Rich Salz <rsalz@openssl.org>
MR: #2911

7 years agoRemove an unused variable assignment
Matt Caswell [Tue, 14 Jun 2016 15:54:08 +0000 (16:54 +0100)]
Remove an unused variable assignment

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoRT4562: Fix misleading doc on OPENSSL_config
Rich Salz [Mon, 13 Jun 2016 01:49:40 +0000 (21:49 -0400)]
RT4562: Fix misleading doc on OPENSSL_config

Also changed the code to use "appname" not "filename"

Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoFree memory on an error path
Matt Caswell [Tue, 14 Jun 2016 10:45:34 +0000 (11:45 +0100)]
Free memory on an error path

The function a2i_ASN1_STRING can encounter an error after already
allocating a buffer. It wasn't always freeing that buffer on error.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoAvoid a double-free in crl2pl7
Matt Caswell [Tue, 14 Jun 2016 10:27:10 +0000 (11:27 +0100)]
Avoid a double-free in crl2pl7

The variable |crtflst| could get double freed in an error path.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoAdd missing break statement
Matt Caswell [Tue, 14 Jun 2016 10:21:44 +0000 (11:21 +0100)]
Add missing break statement

The -psk option processing was falling through to the -srp option
processing in the ciphers app.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoFix comment
Matt Caswell [Tue, 14 Jun 2016 09:41:00 +0000 (10:41 +0100)]
Fix comment

Fix a comment following commit c2c49969e23605.

RT2388

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agomake update
Matt Caswell [Mon, 13 Jun 2016 22:30:27 +0000 (23:30 +0100)]
make update

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoShorten some symbol names
Richard Levitte [Mon, 13 Jun 2016 22:44:29 +0000 (00:44 +0200)]
Shorten some symbol names

VMS C doesn't allow symbols longer than 31 characters.  We do the
automatic shortening with the library files, but not otherwise (to
make sure to work the VMS C magic).

For consistency, I shortened other similar symbols in the same manner.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoGH1141: Different fix, preferred by Richard.
Rich Salz [Mon, 13 Jun 2016 13:51:12 +0000 (09:51 -0400)]
GH1141: Different fix, preferred by Richard.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoRT3454: Re-enable nistp-64_gcc_128 on windows
Peter Mosmans [Mon, 13 Jun 2016 19:04:33 +0000 (15:04 -0400)]
RT3454: Re-enable nistp-64_gcc_128 on windows

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoMissed some copyright merge
Rich Salz [Mon, 13 Jun 2016 18:59:57 +0000 (14:59 -0400)]
Missed some copyright merge

Reviewed-by: Tim Hudson <tjh@openssl.org>
7 years agoEnsure that NULL r and s parameters cannot be set on DSA_SIG/ECDSA_SIGs.
TJ Saunders [Fri, 10 Jun 2016 07:36:45 +0000 (00:36 -0700)]
Ensure that NULL r and s parameters cannot be set on DSA_SIG/ECDSA_SIGs.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1193)

7 years agoForgot to update the setter argument ordering in the public headers.
TJ Saunders [Thu, 9 Jun 2016 21:53:23 +0000 (14:53 -0700)]
Forgot to update the setter argument ordering in the public headers.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1193)

7 years agoReorder the setter arguments to more consistently match that of other APIs,
TJ Saunders [Thu, 9 Jun 2016 21:52:04 +0000 (14:52 -0700)]
Reorder the setter arguments to more consistently match that of other APIs,
per review comments.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1193)

7 years agoImplement DSA_SIG_set0() and ECDSA_SIG_set0(), for setting signature values.
TJ Saunders [Wed, 8 Jun 2016 20:54:22 +0000 (13:54 -0700)]
Implement DSA_SIG_set0() and ECDSA_SIG_set0(), for setting signature values.

SSH2 implementations which use DSA_do_verify() and ECDSA_do_verify() are given
the R and S values, and the data to be signed, by the client.  Thus in order
to validate these signatures, SSH2 implementations will digest and sign
the data -- and then pass in properly provisioned DSA_SIG and ECDSA_SIG objects.

Unfortunately, the existing OpenSSL-1.1.0 APIs do not allow for directly setting
those R and S values in these objects, which makes using OpenSSL for such
SSH2 implementations much more difficult.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Emilia Käsper <emilia@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1193)

7 years agoAdd some missing return value checks
Matt Caswell [Fri, 10 Jun 2016 15:51:39 +0000 (16:51 +0100)]
Add some missing return value checks

Some misc return value checks

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoUpdate sslapitest to use the test framework
Matt Caswell [Mon, 13 Jun 2016 10:55:29 +0000 (11:55 +0100)]
Update sslapitest to use the test framework

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoUpdate the SSL_set_session() documentation
Matt Caswell [Thu, 9 Jun 2016 12:46:34 +0000 (13:46 +0100)]
Update the SSL_set_session() documentation

Update the SSL_set_session() documentation to reflect the fact that old
bad sessions are removed from the cache if necessary.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoAdd some session API tests
Matt Caswell [Thu, 9 Jun 2016 12:33:27 +0000 (13:33 +0100)]
Add some session API tests

This commit adds some session API tests, and in particular tests the
modified behaviour of SSL_set_session() introduced in the last commit. To
do this I have factored out some common code from the asynciotest into a
new ssltestlib.c file. I've also renamed getsettest to sslapitest as this
more closely matches what it now is!

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoEnsure SSL_set_session clears the old session from cache if it is bad
Matt Caswell [Thu, 9 Jun 2016 12:24:54 +0000 (13:24 +0100)]
Ensure SSL_set_session clears the old session from cache if it is bad

SSL_clear() and SSL_free() will remove a session from the cache if it is
considered "bad". However SSL_set_session() does not do this for the session
it is replacing.

SSL_clear() clears an SSL object ready for reuse. It does not clear the
session though. This means that:

  SSL_clear(s)
  SSL_set_session(s, sess);

and
  SSL_set_session(s, sess);
  SSL_clear(s);

do not do the same thing, although logically you would expect that they
would.

The failure of SSL_set_session() to remove bad sessions from the cache
should be considered a bug, so this commit fixes it.

RT#597

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoSSL test: only write out server2 when testing SNI
Emilia Kasper [Mon, 13 Jun 2016 15:46:12 +0000 (17:46 +0200)]
SSL test: only write out server2 when testing SNI

The SNI tests introduced a redundant "server2" section into every test
configuration. Copy this automatically from "server" unless testing SNI,
to reduce noise in the generated confs.

Also remove duplicate SSL_TEST_CTX_create (merge conflict error).

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoHandle inability to create AFALG socket
Matt Caswell [Wed, 1 Jun 2016 22:15:12 +0000 (23:15 +0100)]
Handle inability to create AFALG socket

Some Linux platforms have a suitably recent kernel to support AFALG, but
apparently you still can't actually create an afalg socket. This extends
the afalg_chk_platform() function to additionally check whether we can
create an AFALG socket. We also amend the afalgtest to not report a
failure to load the engine as a test failure. A failure to load is almost
certainly due to platform environmental issues, and not an OpenSSL problem.

RT 4434

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoPort DTLS version negotiation tests
Emilia Kasper [Fri, 3 Jun 2016 15:49:04 +0000 (17:49 +0200)]
Port DTLS version negotiation tests

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoClean up following new SNI tests
Emilia Kasper [Thu, 9 Jun 2016 22:39:22 +0000 (00:39 +0200)]
Clean up following new SNI tests

- Only send SNI in SNI tests. This allows us to test handshakes without
  the SNI extension as well.
- Move all handshake-specific machinery to handshake_helper.c
- Use enum types to represent the enum everywhere
  (Resorting to plain ints can end in sign mismatch when the enum is
  represented by an unsigned type.)

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoRT3809: basicConstraints is critical
Rich Salz [Mon, 13 Jun 2016 02:21:54 +0000 (22:21 -0400)]
RT3809: basicConstraints is critical

This is really a security bugfix, not enhancement any more.
Everyone knows critical extensions.

Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
7 years agobn/bn_add.c: favour counted loops over ifs and breaks.
Andy Polyakov [Sun, 12 Jun 2016 10:34:46 +0000 (12:34 +0200)]
bn/bn_add.c: favour counted loops over ifs and breaks.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agodoc/crypto/OPENSSL_ia32cap.pod update.
Andy Polyakov [Sun, 12 Jun 2016 10:31:40 +0000 (12:31 +0200)]
doc/crypto/OPENSSL_ia32cap.pod update.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoDon't skip leading zeroes in PSK keys.
Dr. Stephen Henson [Wed, 8 Jun 2016 18:01:42 +0000 (19:01 +0100)]
Don't skip leading zeroes in PSK keys.

Don't use BN_hex2bn() for PSK key conversion as the conversion to
BN and back removes leading zeroes, use OPENSSL_hexstr2buf() instead.

RT#4554

Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoRT2759: Don't read TTY when already at EOF.
John Denker [Fri, 10 Jun 2016 18:46:07 +0000 (14:46 -0400)]
RT2759: Don't read TTY when already at EOF.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoAvoid memory leaks if options repeated.
Rich Salz [Fri, 10 Jun 2016 15:40:32 +0000 (11:40 -0400)]
Avoid memory leaks if options repeated.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoRT3053: Check for NULL before dereferencing
Phillip Hellewell [Sun, 12 Jun 2016 00:04:21 +0000 (20:04 -0400)]
RT3053: Check for NULL before dereferencing

Reviewed-by: Tim Hudson <tjh@openssl.org>
7 years agoEnsure that the EVP_MD_meth_new docs properly match the declared functions;
TJ Saunders [Fri, 10 Jun 2016 20:10:51 +0000 (13:10 -0700)]
Ensure that the EVP_MD_meth_new docs properly match the declared functions;
it looks like these names have shifted a little over time.

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1203)

7 years agoAvoid creating illegal pointers
Kurt Roeckx [Mon, 6 Jun 2016 20:50:25 +0000 (22:50 +0200)]
Avoid creating illegal pointers

Found by tis-interpreter

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1179

7 years agoinclude stdlib for malloc() and free()
Kurt Roeckx [Sun, 5 Jun 2016 18:51:04 +0000 (20:51 +0200)]
include stdlib for malloc() and free()

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1174

7 years agoDon't compare a just free()d pointer
Kurt Roeckx [Sun, 5 Jun 2016 18:48:08 +0000 (20:48 +0200)]
Don't compare a just free()d pointer

Found by tis-interpreter

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1173

7 years agoSpecify array sizes
Kurt Roeckx [Sun, 5 Jun 2016 12:13:33 +0000 (14:13 +0200)]
Specify array sizes

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1172

7 years agoAvoid creating an illegal pointer.
Kurt Roeckx [Sat, 4 Jun 2016 17:52:28 +0000 (19:52 +0200)]
Avoid creating an illegal pointer.

Found by tis-interpreter

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1166

7 years agoAvoid creating an illegal pointer
Kurt Roeckx [Sat, 4 Jun 2016 14:25:39 +0000 (16:25 +0200)]
Avoid creating an illegal pointer

Found by tis-interpreter

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1164

7 years agoFix an error path leak in int X509_ATTRIBUTE_set1_data()
Matt Caswell [Fri, 10 Jun 2016 14:30:41 +0000 (15:30 +0100)]
Fix an error path leak in int X509_ATTRIBUTE_set1_data()

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoFix an error path leak in do_ext_nconf()
Matt Caswell [Fri, 10 Jun 2016 14:30:09 +0000 (15:30 +0100)]
Fix an error path leak in do_ext_nconf()

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoFix seg fault in TS_RESP_verify_response()
Matt Caswell [Fri, 10 Jun 2016 13:25:15 +0000 (14:25 +0100)]
Fix seg fault in TS_RESP_verify_response()

The TS_RESP_verify_response() function is used for verifying the response
from a TSA. You can set the provided TS_VERIFY_CTX with different flags
depending on what aspects of the response you wish to verify.

A seg fault will occur if you supply the TS_VFY_SIGNER or TS_VFY_TSA_NAME
flags without also specifying TS_VFY_SIGNATURE.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoFix no-dtls* builds
Matt Caswell [Fri, 10 Jun 2016 09:49:48 +0000 (10:49 +0100)]
Fix no-dtls* builds

Most of the no-dtls* builds were failing due to one test which had an
incorrect "skip" condition.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoExpand SSL_CTX_set_default_verify_paths() documentation
Matt Caswell [Thu, 9 Jun 2016 13:48:40 +0000 (14:48 +0100)]
Expand SSL_CTX_set_default_verify_paths() documentation

Add some information about the location of the default directory and the
default file.

RT#1051

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoGH1183: Fix -unix and -connect, etc., override
Rich Salz [Wed, 8 Jun 2016 16:22:14 +0000 (12:22 -0400)]
GH1183: Fix -unix and -connect, etc., override

If a user specifies -unix, -6, etc., then the program tries to
use the last one specified.  This is confusing code and leads to
scripting errors.  Instead, allow only one type.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoOmit corpora from tarball.
Ben Laurie [Fri, 10 Jun 2016 11:07:32 +0000 (12:07 +0100)]
Omit corpora from tarball.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoMake corpora binary.
Ben Laurie [Thu, 12 May 2016 09:29:13 +0000 (10:29 +0100)]
Make corpora binary.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoAdd fuzz corpora.
Ben Laurie [Sat, 7 May 2016 17:51:08 +0000 (18:51 +0100)]
Add fuzz corpora.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoRT3720 Increment session miss counter properly
Laszlo Kovacs [Fri, 20 Feb 2015 19:35:57 +0000 (14:35 -0500)]
RT3720 Increment session miss counter properly

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoRT 4242: reject invalid EC point coordinates
Emilia Kasper [Fri, 3 Jun 2016 12:42:04 +0000 (14:42 +0200)]
RT 4242: reject invalid EC point coordinates

We already test in EC_POINT_oct2point that points are on the curve. To
be on the safe side, move this check to
EC_POINT_set_affine_coordinates_* so as to also check point coordinates
received through some other method.

We do not check projective coordinates, though, as
- it's unlikely that applications would be receiving this primarily
  internal representation from untrusted sources, and
- it's possible that the projective setters are used in a setting where
  performance matters.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoMake a2i_ipadd an internal function
Rich Salz [Sun, 5 Jun 2016 19:51:35 +0000 (15:51 -0400)]
Make a2i_ipadd an internal function

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoMore API docs; small changes.
Rich Salz [Thu, 9 Jun 2016 21:02:59 +0000 (17:02 -0400)]
More API docs; small changes.

Also fix typo noted on GitHub.
Suppport typedef and #define to find-doc-nits

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoClean up "generic" intro pod files.
Rich Salz [Thu, 9 Jun 2016 20:39:19 +0000 (16:39 -0400)]
Clean up "generic" intro pod files.

Files like dh.pod, etc., mostly duplicated the API-specific pod files.
Removed the duplicated content; that often mean the whole file could
be removed.  Some of the content about internals got moved into README
files in the source tree.  Some content (e.g., err.pod) got moved
into other pod pages.

Annotate generic pages, remove dup NAME

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoWrite X509_dup, PEM_read, etc.
Rich Salz [Thu, 9 Jun 2016 12:34:17 +0000 (08:34 -0400)]
Write X509_dup, PEM_read, etc.

Partially document the ASN1 template stuff, and its use for i2d/d2i
and PEM I/O.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoDocs: install generic manpages to man section 7
Richard Levitte [Thu, 9 Jun 2016 15:22:26 +0000 (17:22 +0200)]
Docs: install generic manpages to man section 7

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agohmac/hmac.c: fix sizeof typo in hmac_ctx_cleanup.
Andy Polyakov [Wed, 8 Jun 2016 18:38:12 +0000 (20:38 +0200)]
hmac/hmac.c: fix sizeof typo in hmac_ctx_cleanup.

Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoFix session ticket and SNI
Todd Short [Thu, 12 May 2016 22:16:52 +0000 (18:16 -0400)]
Fix session ticket and SNI

When session tickets are used, it's possible that SNI might swtich the
SSL_CTX on an SSL. Normally, this is not a problem, because the
initial_ctx/session_ctx are used for all session ticket/id processes.

However, when the SNI callback occurs, it's possible that the callback
may update the options in the SSL from the SSL_CTX, and this could
cause SSL_OP_NO_TICKET to be set. If this occurs, then two bad things
can happen:

1. The session ticket TLSEXT may not be written when the ticket expected
flag is set. The state machine transistions to writing the ticket, and
the client responds with an error as its not expecting a ticket.
2. When creating the session ticket, if the ticket key cb returns 0
the crypto/hmac contexts are not initialized, and the code crashes when
trying to encrypt the session ticket.

To fix 1, if the ticket TLSEXT is not written out, clear the expected
ticket flag.
To fix 2, consider a return of 0 from the ticket key cb a recoverable
error, and write a 0 length ticket and continue. The client-side code
can explicitly handle this case.

Fix these two cases, and add unit test code to validate ticket behavior.

Reviewed-by: Emilia Käsper <emilia@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1098)

7 years agoFixes to get -ansi working
Jeffrey Walton [Wed, 8 Jun 2016 19:10:50 +0000 (20:10 +0100)]
Fixes to get -ansi working

Various fixes to get the following to compile:

./config no-asm -ansi -D_DEFAULT_SOURCE

RT4479
RT4480

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoAdd some accessor API's
Rich Salz [Wed, 8 Jun 2016 15:37:06 +0000 (11:37 -0400)]
Add some accessor API's

GH1098: Add X509_get_pathlen() (and a test)
GH1097:  Add SSL_is_dtls() function.

Documented.

Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agocrypto/x509/x509_vpm.c: Simplify int_x509_param_set1()
Kurt Cancemi [Thu, 26 May 2016 20:38:31 +0000 (16:38 -0400)]
crypto/x509/x509_vpm.c: Simplify int_x509_param_set1()

This change also avoids calling strlen twice when srclen is 0

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoAlways use session_ctx when removing a session
Todd Short [Thu, 26 May 2016 17:49:36 +0000 (13:49 -0400)]
Always use session_ctx when removing a session

Sessions are stored on the session_ctx, which doesn't change after
SSL_set_SSL_CTX().

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoFix some typos in pod files
FdaSilvaYY [Tue, 7 Jun 2016 21:03:15 +0000 (23:03 +0200)]
Fix some typos in pod files

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

7 years agoIgnore tsget.pl and c_rehash.pl, as well as other compiler generated files
Richard Levitte [Wed, 8 Jun 2016 12:08:53 +0000 (14:08 +0200)]
Ignore tsget.pl and c_rehash.pl, as well as other compiler generated files

Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoAdd empty record tests
Matt Caswell [Wed, 1 Jun 2016 16:44:19 +0000 (17:44 +0100)]
Add empty record tests

The previous commit changed how we handle out-of-context empty records.
This commit adds some tests for the various scenarios. There are three
tests:
1: Check that if we inject an out-of-context empty record then we fail
2: Check that if we inject an in-context empty record then we succeed
3: Check that if we inject too many in-context empty records then we fail.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoReject out of context empty records
Matt Caswell [Wed, 1 Jun 2016 15:31:11 +0000 (16:31 +0100)]
Reject out of context empty records

Previously if we received an empty record we just threw it away and
ignored it. Really though if we get an empty record of a different content
type to what we are expecting then that should be an error, i.e. we should
reject out of context empty records. This commit makes the necessary changes
to achieve that.

RT#4395

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoFix pipelining bug
Matt Caswell [Wed, 1 Jun 2016 15:25:31 +0000 (16:25 +0100)]
Fix pipelining bug

The number of read pipelines should be reset in the event of reuse of an
SSL object.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoAdd a BN_mod_word test()
Matt Caswell [Tue, 31 May 2016 10:38:52 +0000 (11:38 +0100)]
Add a BN_mod_word test()

The previous commit fixed a bug with BN_mod_word() which would have been
caught if we had a test for it. This commit adds one.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoFix BN_mod_word bug
Matt Caswell [Tue, 31 May 2016 10:28:14 +0000 (11:28 +0100)]
Fix BN_mod_word bug

On systems where we do not have BN_ULLONG (e.g. typically 64 bit systems)
then BN_mod_word() can return incorrect results if the supplied modulus is
too big.

RT#4501

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoUnify d2i/i2d documentation.
Rich Salz [Tue, 7 Jun 2016 19:49:08 +0000 (15:49 -0400)]
Unify d2i/i2d documentation.

Make d2i_X509 a generic d2i/i2d manpage.
Pull common stuff out of other d2i/i2d docs.
Update find-doc-nits to know about "generic" manpages.
Cleanup some overlap.
Fix up a bunch of other references.

Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoNit about pod filenames
Rich Salz [Tue, 7 Jun 2016 17:08:20 +0000 (13:08 -0400)]
Nit about pod filenames

The asdf.pod filename must have asdf in its NAME section.
also check for names existing as a different filename (via Levitte)

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
7 years agoFix potential access of null pointer (pp)
Rob Percival [Tue, 7 Jun 2016 16:01:44 +0000 (17:01 +0100)]
Fix potential access of null pointer (pp)

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

7 years agoAdd an SSL get/set test
Matt Caswell [Tue, 7 Jun 2016 15:35:38 +0000 (16:35 +0100)]
Add an SSL get/set test

We just do the getters/setter for tlsext_status_type. This could be extended
for others in the future.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoAdd documentation for the newly added SSL_get_tlsext_status_type()
Matt Caswell [Tue, 7 Jun 2016 13:33:07 +0000 (14:33 +0100)]
Add documentation for the newly added SSL_get_tlsext_status_type()

And also for SSL_CTX_get_tlsext_status_type()

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoAdd SSL_CTX_get_tlsext_status_type()
Matt Caswell [Tue, 7 Jun 2016 14:14:14 +0000 (15:14 +0100)]
Add SSL_CTX_get_tlsext_status_type()

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoReturn the value of tlsext_status_type in the return not arg
Matt Caswell [Tue, 7 Jun 2016 14:13:40 +0000 (15:13 +0100)]
Return the value of tlsext_status_type in the return not arg

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoAdd SSL_get_tlsext_status_type() method
Alessandro Ghedini [Tue, 10 May 2016 23:48:49 +0000 (00:48 +0100)]
Add SSL_get_tlsext_status_type() method

The tlsext_status_type field in SSL is used by e.g. OpenResty to determine
if the client requested the certificate status, but SSL is now opaque.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoFix some GitHub issues.
Rich Salz [Tue, 7 Jun 2016 14:54:42 +0000 (10:54 -0400)]
Fix some GitHub issues.

GH1180: Local variable sometimes unused
GH1181: Missing close paren.

Thanks to <wipedout@yandex.ru> for reporting these.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoSet flag BN_FLG_CONSTTIME earlier
Cesar Pereida [Tue, 7 Jun 2016 13:02:01 +0000 (16:02 +0300)]
Set flag BN_FLG_CONSTTIME earlier

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoRemove kq and set BN_FLG_CONSTTIME in k for BN_mod_inverse
Cesar Pereida [Tue, 7 Jun 2016 08:32:23 +0000 (11:32 +0300)]
Remove kq and set BN_FLG_CONSTTIME in k for BN_mod_inverse

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoAdd script to find undocumented API
Rich Salz [Wed, 1 Jun 2016 17:10:24 +0000 (13:10 -0400)]
Add script to find undocumented API

Also tweaks to find-doc-nits, including name/synopsis checking.
Ironically, it also reports on duplicated doc names :)

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoDocument the issue with threads and dlopen()
Matt Caswell [Tue, 7 Jun 2016 12:24:01 +0000 (13:24 +0100)]
Document the issue with threads and dlopen()

If using threads and OpenSSL is loaded via dlopen(), and subsequently
closed again via dlclose() *before* the threads are destroyed, then
OpenSSL will not free up the per thread resources. We need to document
this restriction, and provide some guidance on what to do about it.

I did some testing and discovered/verified a few of things (at least
this is the behaviour on Linux):

- Using OpenSSL via dlopen in a mutli-threaded app does leak memory if
threads are destroyed after dlcose() is called.
- In a single threaded environment, or if threads are destroyed prior to
dlclose() being called, then no memory is leaked
- Using the RTLD_NODELETE flag to dlopen solves the above problem
- Interestingly the OpenSSL atexit() handler gets called when dlclose()
is called rather than at application exit (I was worred that it might crash
if there was an atexit() handler for a function that has been unloaded)
- RTLD_NODELETE is a non-standard flag - but it does seem to be fairly
widely supported. As far as I could determine (via google), at least Linux,
Solaris, OpenBSD, FreeBSD, HP-UX all seem to support it.

I also tested on Windows (using LoadLibrary instead of dlopen and
FreeLibrary instead of dlclose) and experienced similar behaviour, except
that (AFAIK) there is no equivalent of RTLD_NODELETE on Windows.

GitHub Issue #653

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoMore doc nits
Rich Salz [Mon, 6 Jun 2016 04:43:05 +0000 (00:43 -0400)]
More doc nits

Update script to look for period or POD markup in NAME section, and
fix them.

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoNOTES.WIN: use secure urls
Viktor Szakats [Sun, 5 Jun 2016 21:43:16 +0000 (23:43 +0200)]
NOTES.WIN: use secure urls
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1175)

7 years agotests: fix the shutting up of the shell
Richard Levitte [Mon, 6 Jun 2016 13:01:50 +0000 (15:01 +0200)]
tests: fix the shutting up of the shell

If we're going to redirect STDERR and STDOUT, it's better to do it by
the book.  This fix is a straight copy of examples in the perlfunc
manual.

Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agoFix the directory target generation
Richard Levitte [Sun, 5 Jun 2016 20:12:04 +0000 (22:12 +0200)]
Fix the directory target generation

The directories for the final products were never registered, it was
plain luck that intermediary files were in the same place and
registered the directory anyway.

Also, scripts are generated directly from source (binaries go through
intermadiary object files), so we need to explicitely make sure to
avoid registering the source directory unless it's an in source
build.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoDeprecate the flags that switch off constant time
Matt Caswell [Thu, 26 May 2016 09:55:11 +0000 (10:55 +0100)]
Deprecate the flags that switch off constant time

The flags RSA_FLAG_NO_CONSTTIME, DSA_FLAG_NO_EXP_CONSTTIME and
DH_FLAG_NO_EXP_CONSTTIME which previously provided the ability to switch
off the constant time implementation for RSA, DSA and DH have been made
no-ops and deprecated.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoSimplify dsa_ossl.c
Matt Caswell [Thu, 26 May 2016 09:06:27 +0000 (10:06 +0100)]
Simplify dsa_ossl.c

The dsa_ossl.c file defined a couple of multi-line macros, but then only
used each one once. The macros just serve to complicate the code and make
it more difficult to understand what is really going on. Hence they are
removed.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoFix DSA, preserve BN_FLG_CONSTTIME
Cesar Pereida [Mon, 23 May 2016 09:45:25 +0000 (12:45 +0300)]
Fix DSA, preserve BN_FLG_CONSTTIME

Operations in the DSA signing algorithm should run in constant time in
order to avoid side channel attacks. A flaw in the OpenSSL DSA
implementation means that a non-constant time codepath is followed for
certain operations. This has been demonstrated through a cache-timing
attack to be sufficient for an attacker to recover the private DSA key.

CVE-2016-2178

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
7 years agos390x assembly pack: improve portability.
Andy Polyakov [Mon, 30 May 2016 20:16:31 +0000 (22:16 +0200)]
s390x assembly pack: improve portability.

Some of the instructions used in latest additions are extension
ones. There is no real reason to limit ourselves to specific
processors, so [re-]adhere to base instruction set.

RT#4548

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agotests: Shut the shell up unless verbose
Richard Levitte [Sun, 5 Jun 2016 21:01:24 +0000 (23:01 +0200)]
tests: Shut the shell up unless verbose

In rare cases, the shell we run test programs in may have complaints.
Shut those up unless testing verbosely.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
7 years agoRemove extra include's in synopsis.
Rich Salz [Fri, 3 Jun 2016 20:19:49 +0000 (16:19 -0400)]
Remove extra include's in synopsis.

Reviewed-by: Richard Levitte <levitte@openssl.org>
7 years agoConfigure: complete the changed fuzz option checks
Richard Levitte [Sun, 5 Jun 2016 08:59:31 +0000 (10:59 +0200)]
Configure: complete the changed fuzz option checks

Reviewed-by: Andy Polyakov <appro@openssl.org>
7 years agoSilence misleading test_abort stderr output
Viktor Dukhovni [Sun, 5 Jun 2016 15:13:34 +0000 (11:13 -0400)]
Silence misleading test_abort stderr output

Reviewed-by: Rich Salz <rsalz@openssl.org>