oweals/openssl.git
6 years agoFree a variable on an error path
Matt Caswell [Tue, 29 May 2018 14:59:25 +0000 (15:59 +0100)]
Free a variable on an error path

Issue found by Coverity.

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

6 years agoOnly set TCP_NODELAY if the protocol is TCP
Matt Caswell [Tue, 29 May 2018 14:58:47 +0000 (15:58 +0100)]
Only set TCP_NODELAY if the protocol is TCP

This doesn't apply if we're doing DTLS, or using UNIX domain sockets.

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

6 years agoEVP_MD_size() can return an error
Matt Caswell [Tue, 29 May 2018 15:27:25 +0000 (16:27 +0100)]
EVP_MD_size() can return an error

Fix some instances where we weren't checking the error return.

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

6 years agoRemove some logically dead code
Matt Caswell [Tue, 29 May 2018 13:55:45 +0000 (14:55 +0100)]
Remove some logically dead code

Found by coverity. This is an artifact left over from the original
decaf import which generated the source code for different curves. For
curve 448 this is dead.

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

6 years agoRemove some logically dead code
Matt Caswell [Tue, 29 May 2018 13:33:12 +0000 (14:33 +0100)]
Remove some logically dead code

Issues found by Coverity

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

6 years agoapps: when the 'compat' nameopt has been set, leave it be
Richard Levitte [Thu, 31 May 2018 04:51:25 +0000 (06:51 +0200)]
apps: when the 'compat' nameopt has been set, leave it be

XN_FLAG_COMPAT has a unique property, its zero for value.  This means
it needs special treatment; if it has been set (which can only be
determined indirectly) and set alone (*), no other flags should be
set.

(*) if any other nameopt flag has been set by the user, compatibility
mode is blown away.

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

6 years agoReduce minimal out length in CRYPTO_128_unwrap_pad
Yihong Wang [Wed, 16 May 2018 06:34:28 +0000 (23:34 -0700)]
Reduce minimal out length in CRYPTO_128_unwrap_pad

In `aes_wrap_cipher()`, the minimal out buff length is `(inlen - 8)`.
Since it calls `CRYPTO_128_unwrap_pad()` underneath, it makes sense to
reduce the minimal out length in `CRYPTO_128_unwrap_pad()` to align to
its caller.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6266)

6 years agobn/bn_exp.c: mitigation of the One-and-Done side-channel attack.
User [Wed, 16 May 2018 17:59:36 +0000 (13:59 -0400)]
bn/bn_exp.c: mitigation of the One-and-Done side-channel attack.

The One&Done attack, which is described in a paper to appear in the
USENIX Security'18 conference, uses EM emanations to recover the values
of the bits that are obtained using BN_is_bit_set while constructing
the value of the window in BN_mod_exp_consttime. The EM signal changes
slightly depending on the value of the bit, and since the lookup of a
bit is surrounded by highly regular execution (constant-time Montgomery
multiplications) the attack is able to isolate the (very brief) part of
the signal that changes depending on the bit. Although the change is
slight, the attack recovers it successfully >90% of the time on several
phones and IoT devices (all with ARM processors with clock rates around
1GHz), so after only one RSA decryption more than 90% of the bits in
d_p and d_q are recovered correctly, which enables rapid recovery of
the full RSA key using an algorithm (also described in the paper) that
modifies the branch-and-prune approach for a situation in which the
exponents' bits are recovered with errors, i.e. where we do not know
a priori which bits are correctly recovered.

The mitigation for the attack is relatively simple - all the bits of
the window are obtained at once, along with other bits so that an
entire integer's worth of bits are obtained together using masking and
shifts, without unnecessarily considering each bit in isolation. This
improves performance somewhat (one call to bn_get_bits is faster than
several calls to BN_is_bit_set), so the attacker now gets one signal
snippet per window (rather than one per bit) in which the signal is
affected by all bits in the integer (rather than just the one bit).

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6276)

6 years agochacha/asm/chacha-ppc.pl: optimize AltiVec/VMX code path.
Andy Polyakov [Sun, 27 May 2018 12:04:48 +0000 (14:04 +0200)]
chacha/asm/chacha-ppc.pl: optimize AltiVec/VMX code path.

32-bit vector rotate instruction was defined from beginning, it
not being used from the start must be a brain-slip...

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6363)

6 years agoperlasm/ppc-xlate.pl: add new instructions and clean up.
Andy Polyakov [Sun, 27 May 2018 12:03:00 +0000 (14:03 +0200)]
perlasm/ppc-xlate.pl: add new instructions and clean up.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6363)

6 years agoapps/speed.c: address asan failure with small -bytes and large -misalign.
Andy Polyakov [Mon, 21 May 2018 12:26:54 +0000 (14:26 +0200)]
apps/speed.c: address asan failure with small -bytes and large -misalign.

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

6 years agoapps/speed.c: add -aead flag.
Andy Polyakov [Sat, 19 May 2018 13:43:11 +0000 (15:43 +0200)]
apps/speed.c: add -aead flag.

Goal is to exercise AEAD ciphers in TLS-like sequence, i.e. 13-byte
AAD followed by payload. Update doc/man1/speed.pod accordingly.

[While we are at it, address even some styling and readability issues.]

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

6 years agoapps/speed.c: clean up SIGARM handling.
Andy Polyakov [Sat, 19 May 2018 13:53:29 +0000 (15:53 +0200)]
apps/speed.c: clean up SIGARM handling.

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

6 years agoOSSL_STORE: don't test file: URIs on Mingw
Richard Levitte [Wed, 30 May 2018 12:25:46 +0000 (14:25 +0200)]
OSSL_STORE: don't test file: URIs on Mingw

Under a mingw shell, the command line path conversion either mangles
file: URIs to something useless (file;C:\...) or not at all (which
can't be opened by the Windows C RTL unless we're really lucky), so we
simply skip testing them in that environment.

Fixes #6369

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

6 years agoAdd APIs for custom X509_LOOKUP_METHOD creation
Mingtao Yang [Fri, 9 Feb 2018 18:23:18 +0000 (10:23 -0800)]
Add APIs for custom X509_LOOKUP_METHOD creation

OpenSSL 1.1.0 made the X509_LOOKUP_METHOD structure opaque, so
applications that were previously able to define a custom lookup method
are not able to be ported.

This commit adds getters and setters for each of the current fields of
X509_LOOKUP_METHOD, along with getters and setters on several associated
opaque types (such as X509_LOOKUP and X509_OBJECT).

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6152)

6 years agoText description of GOST signature algorithms
Dmitry Belyavskiy [Thu, 3 May 2018 15:31:47 +0000 (18:31 +0300)]
Text description of GOST signature algorithms

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6168)

6 years agoSend GOST SignatureAlgorithms when TLS 1.2 in use
Dmitry Belyavskiy [Thu, 3 May 2018 15:31:01 +0000 (18:31 +0300)]
Send GOST SignatureAlgorithms when TLS 1.2 in use

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6168)

6 years agoBugfix: GOST2012 certificates for GOST ciphersuites were broken.
Dmitry Belyavskiy [Thu, 3 May 2018 14:25:48 +0000 (17:25 +0300)]
Bugfix: GOST2012 certificates for GOST ciphersuites were broken.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6168)

6 years agoReplace strdup() with OPENSSL_strdup()
Todd Short [Tue, 22 May 2018 14:48:04 +0000 (10:48 -0400)]
Replace strdup() with OPENSSL_strdup()

It's freed with OPENSSL_free()

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6331)

6 years agoFix no-sm2 with clang
Todd Short [Fri, 18 May 2018 18:54:01 +0000 (14:54 -0400)]
Fix no-sm2 with clang

Return immediately upon discovery of bad message digest.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6298)

6 years agoTest that a ^ 0 mod -1 is always 0
Matt Caswell [Thu, 24 May 2018 15:13:43 +0000 (16:13 +0100)]
Test that a ^ 0 mod -1 is always 0

Check all functions that do this.

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

6 years agoThe result of a ^ 0 mod -1 is 0 not 1
Matt Caswell [Thu, 24 May 2018 15:12:52 +0000 (16:12 +0100)]
The result of a ^ 0 mod -1 is 0 not 1

Thanks to Guido Vranken and OSSFuzz for finding this issue.

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

6 years agoUpdate the "Connected Commands" section of s_client/s_server docs
Matt Caswell [Tue, 22 May 2018 14:18:01 +0000 (15:18 +0100)]
Update the "Connected Commands" section of s_client/s_server docs

Fixes #6307

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/6330)

6 years agoPrepare for 1.1.1-pre8-dev
Matt Caswell [Tue, 29 May 2018 12:22:05 +0000 (13:22 +0100)]
Prepare for 1.1.1-pre8-dev

Reviewed-by: Richard Levitte <levitte@openssl.org>
6 years agoPrepare for 1.1.1-pre7 release OpenSSL_1_1_1-pre7
Matt Caswell [Tue, 29 May 2018 12:20:01 +0000 (13:20 +0100)]
Prepare for 1.1.1-pre7 release

Reviewed-by: Richard Levitte <levitte@openssl.org>
6 years agoUpdate copyright year
Matt Caswell [Tue, 29 May 2018 12:07:08 +0000 (13:07 +0100)]
Update copyright year

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

6 years agoECDSA_SIG: restore doc comments which were deleted accidentally
Dr. Matthias St. Pierre [Mon, 28 May 2018 20:46:21 +0000 (22:46 +0200)]
ECDSA_SIG: restore doc comments which were deleted accidentally

amends 0396401d1c3f

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

6 years agoECDSA_SIG: add simple getters for commonly used struct members
Dr. Matthias St. Pierre [Sun, 27 May 2018 07:08:08 +0000 (09:08 +0200)]
ECDSA_SIG: add simple getters for commonly used struct members

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

6 years agoRSA: add simple getters for commonly used struct members
Dr. Matthias St. Pierre [Sun, 27 May 2018 07:01:28 +0000 (09:01 +0200)]
RSA: add simple getters for commonly used struct members

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

6 years agoDSA: add simple getters for commonly used struct members
Dr. Matthias St. Pierre [Sun, 27 May 2018 06:57:55 +0000 (08:57 +0200)]
DSA: add simple getters for commonly used struct members

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

6 years agoDH: fix: add simple getters for commonly used struct members
Dr. Matthias St. Pierre [Sun, 27 May 2018 07:07:07 +0000 (09:07 +0200)]
DH: fix: add simple getters for commonly used struct members

amends 6db7fadf0975

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

6 years agoutil/libcrypto.num: fix symbol collision between 1.1.0 and master
Dr. Matthias St. Pierre [Wed, 16 May 2018 20:53:41 +0000 (22:53 +0200)]
util/libcrypto.num: fix symbol collision between 1.1.0 and master

In commit 6decf9436f7, fourteen public symbols were removed from
util/libcrypto.num on the master branch and the following symbols
renumbered. Unfortunately, the symbols `OCSP_resp_get0_signer` and
`X509_get0_authority_key_id` were not adjusted accordingly on the
OpenSSL_1_1_0-stable branch. This commit fixes the collision by
doing a 'double swap'.

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

6 years agoTry to work around ubuntu gcc-5 ubsan build failure
Bernd Edlinger [Sat, 26 May 2018 15:08:03 +0000 (17:08 +0200)]
Try to work around ubuntu gcc-5 ubsan build failure

[extended tests]

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

6 years agoImprove the example getpass() implementation to show an error return
Nick Mathewson [Thu, 24 May 2018 19:23:15 +0000 (15:23 -0400)]
Improve the example getpass() implementation to show an error return

Also, modernize the code, so that it isn't trying to store a size_t
into an int, and then check the int's sign. :/

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

6 years agoUpdate documentation for PEM callback: error is now -1.
Nick Mathewson [Wed, 16 May 2018 15:07:48 +0000 (11:07 -0400)]
Update documentation for PEM callback: error is now -1.

In previous versions of OpenSSL, the documentation for PEM_read_*
said:

   The callback B<must> return the number of characters in the
   passphrase or 0 if an error occurred.

But since c82c3462267afdbbaa5, 0 is now treated as a non-error
return value.  Applications that want to indicate an error need to
return -1 instead.

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

6 years agoFix array bounds violation in ssl_session_dup
Bernd Edlinger [Fri, 25 May 2018 06:06:55 +0000 (08:06 +0200)]
Fix array bounds violation in ssl_session_dup

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

6 years agoAdd a sanity check on the length of pkeyutl inputs
Matt Caswell [Thu, 17 May 2018 11:53:07 +0000 (12:53 +0100)]
Add a sanity check on the length of pkeyutl inputs

When signing or verifying a file using pkeyutl the input is supposed to
be a hash. Some algorithms sanity check the length of the input, while
others don't and silently truncate. To avoid accidents we check that the
length of the input looks sane.

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

6 years agoRevert "Support EVP_PKEY_sign() and EVP_PKEY_verify() for EdDSA"
Matt Caswell [Thu, 17 May 2018 10:18:01 +0000 (11:18 +0100)]
Revert "Support EVP_PKEY_sign() and EVP_PKEY_verify() for EdDSA"

This reverts commit a6f5b1163452a36da1c8378eab3f29ae234e5c7f.

The EVP_PKEY_sign() function is intended for pre-hashed input which is
not supported by our EdDSA implementation.

See the discussion in PR 5880

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

6 years agoImprove compatibility of point and curve checks
Matt Caswell [Mon, 21 May 2018 14:24:56 +0000 (15:24 +0100)]
Improve compatibility of point and curve checks

We check that the curve name associated with the point is the same as that
for the curve.

Fixes #6302

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

6 years agoSave and restore the Windows error around TlsGetValue.
David Benjamin [Sun, 20 May 2018 21:24:30 +0000 (17:24 -0400)]
Save and restore the Windows error around TlsGetValue.

TlsGetValue clears the last error even on success, so that callers may
distinguish it successfully returning NULL or failing. This error-mangling
behavior interferes with the caller's use of GetLastError. In particular
SSL_get_error queries the error queue to determine whether the caller should
look at the OS's errors. To avoid destroying state, save and restore the
Windows error.

Fixes #6299.

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

6 years agoUse OPENSSL_EC_EXPLICIT_CURVE constant.
David Benjamin [Sun, 20 May 2018 18:37:06 +0000 (14:37 -0400)]
Use OPENSSL_EC_EXPLICIT_CURVE constant.

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

6 years agoFix explicit EC curve encoding.
David Benjamin [Sun, 20 May 2018 18:33:49 +0000 (14:33 -0400)]
Fix explicit EC curve encoding.

Per SEC 1, the curve coefficients must be padded up to size. See C.2's
definition of Curve, C.1's definition of FieldElement, and 2.3.5's definition
of how to encode the field elements in http://www.secg.org/sec1-v2.pdf.

This comes up for P-521, where b needs a leading zero.

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

6 years agoSkip CN DNS name constraint checks when not needed
Viktor Dukhovni [Tue, 22 May 2018 05:09:25 +0000 (01:09 -0400)]
Skip CN DNS name constraint checks when not needed

Only check the CN against DNS name contraints if the
`X509_CHECK_FLAG_NEVER_CHECK_SUBJECT` flag is not set, and either the
certificate has no DNS subject alternative names or the
`X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT` flag is set.

Add pertinent documentation, and touch up some stale text about
name checks and DANE.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
6 years agoLimit scope of CN name constraints
Viktor Dukhovni [Wed, 16 May 2018 03:41:20 +0000 (23:41 -0400)]
Limit scope of CN name constraints

Don't apply DNS name constraints to the subject CN when there's a
least one DNS-ID subjectAlternativeName.

Don't apply DNS name constraints to subject CN's that are sufficiently
unlike DNS names.  Checked name must have at least two labels, with
all labels non-empty, no trailing '.' and all hyphens must be
internal in each label.  In addition to the usual LDH characters,
we also allow "_", since some sites use these for hostnames despite
all the standards.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
6 years agoUse the client app traffic secret for PHA Finished message
Matt Caswell [Fri, 18 May 2018 16:33:19 +0000 (17:33 +0100)]
Use the client app traffic secret for PHA Finished message

The TLSv1.3 spec requires us to use the client application traffic secret
during generation of the Finished message following a post handshake
authentication.

Fixes #6263

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/6297)

6 years agoINSTALL: Provide better documentation for enable-ec_nistp_64_gcc_128
Richard Levitte [Tue, 22 May 2018 21:09:01 +0000 (23:09 +0200)]
INSTALL: Provide better documentation for enable-ec_nistp_64_gcc_128

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6328)

6 years agoBetter error code when lacking __SIZEOF_INT128__
Richard Levitte [Tue, 22 May 2018 11:57:29 +0000 (13:57 +0200)]
Better error code when lacking __SIZEOF_INT128__

Fixes #6327

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6328)

6 years agoFix no-ec, no-tls1_3 and no-tls
Matt Caswell [Mon, 21 May 2018 09:46:58 +0000 (10:46 +0100)]
Fix no-ec, no-tls1_3 and no-tls

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

6 years agoEnable SSL_MODE_AUTO_RETRY by default
Kurt Roeckx [Tue, 15 May 2018 17:01:41 +0000 (19:01 +0200)]
Enable SSL_MODE_AUTO_RETRY by default

Because TLS 1.3 sends more non-application data records some clients run
into problems because they don't expect SSL_read() to return and set
SSL_ERROR_WANT_READ after processing it.

This can cause problems for clients that use blocking I/O and use
select() to see if data is available. It can be cleared using
SSL_CTX_clear_mode().

Reviewed-by: Matt Caswell <matt@openssl.org>
GH: #6260

6 years agoFix no-ec in combination with no-dh
Matt Caswell [Mon, 21 May 2018 11:20:18 +0000 (12:20 +0100)]
Fix no-ec in combination with no-dh

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

6 years agossl/ssl_txt: fix NULL-check
Tilman Keskinöz [Thu, 17 May 2018 11:04:31 +0000 (13:04 +0200)]
ssl/ssl_txt: fix NULL-check

NULL-check for cipher is redundant, instead check if cipher->name is NULL

While here fix formatting of BIO_printf calls as suggested by Andy Polyakov.

CLA: trivial

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6282)

6 years agoapps/s_socket.c: address rare TLSProxy failures on Windows.
Andy Polyakov [Sun, 20 May 2018 21:03:47 +0000 (23:03 +0200)]
apps/s_socket.c: address rare TLSProxy failures on Windows.

Reviewed-by: Rich Salz <rsalz@openssl.org>
6 years agoCheck malloc failure via app_malloc
Rich Salz [Mon, 21 May 2018 14:28:16 +0000 (10:28 -0400)]
Check malloc failure via app_malloc

Thanks to GitHUb user murugesandins for reporting this.

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

6 years agoDon't cache stateless tickets in TLSv1.3
Matt Caswell [Fri, 18 May 2018 10:31:31 +0000 (11:31 +0100)]
Don't cache stateless tickets in TLSv1.3

In TLSv1.2 and below we always cache new sessions by default on the server
side in the internal cache (even when we're using session tickets). This is
in order to support resumption from a session id.

In TLSv1.3 there is no session id. It is only possible to resume using the
ticket. Therefore, in the default case,  there is no point in caching the
session in the internal store.

There is still a reason to call the external cache new session callback
because applications may be using the callbacks just to know about when
sessions are created (and not necessarily implementing a full cache). If
the application also implements the remove session callback then we are
forced to also store it in the internal cache so that we can create
timeout events. Otherwise the external cache could just fill up
indefinitely.

This mostly addresses the issue described in #5628. That issue also proposes
having an option to not create full stateless tickets when using the
internal cache. That aspect hasn't been addressed yet.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/6293)

6 years agoFix undefined behaviour in X509_NAME_cmp()
Matt Caswell [Wed, 16 May 2018 10:59:47 +0000 (11:59 +0100)]
Fix undefined behaviour in X509_NAME_cmp()

If the lengths of both names is 0 then don't attempt to do a memcmp.

Issue reported by Simon Friedberger, Robert Merget and Juraj Somorovsky.

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/6291)

6 years agoWindows: don't install __DECC_*.H
Richard Levitte [Sat, 19 May 2018 05:09:19 +0000 (07:09 +0200)]
Windows: don't install __DECC_*.H

This adds the possibility to exclude files by regexp in util/copy.pl

Partial fix for #3254

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6303)

6 years agoQuiet pod2html warnings
Richard Levitte [Sat, 19 May 2018 05:22:10 +0000 (07:22 +0200)]
Quiet pod2html warnings

--quiet stops warnings of this sort:

    Cannot find "BIO_read_ex" in podpath: cannot find suitable replacement path, cannot resolve link

We know what causes these warnings, it's perfectly innocuous, and we
don't want to hear it any more.

Partial fix for #3254

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

6 years agoFix no-srtp build warnings
Todd Short [Mon, 14 May 2018 14:41:06 +0000 (10:41 -0400)]
Fix no-srtp build warnings

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6255)

6 years agoRestore check of |*xn| against |name| in X509_NAME_set
Richard Levitte [Thu, 17 May 2018 07:53:14 +0000 (09:53 +0200)]
Restore check of |*xn| against |name| in X509_NAME_set

A previous change of this function introduced a fragility when the
destination happens to be the same as the source.  Such alias isn't
recommended, but could still happen, for example in this kind of code:

    X509_NAME *subject = X509_get_issuer_name(x);

    /* ... some code passes ... */

    X509_set_issuer_name(x, subject);

Fixes #4710

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6280)

6 years agoAllow the ca application to use EdDSA
Matt Caswell [Thu, 17 May 2018 15:24:29 +0000 (16:24 +0100)]
Allow the ca application to use EdDSA

Using the ca application to sign certificates with EdDSA failed because it
is not possible to set the digest to "null". This adds the capability and
updates the documentation accordingly.

Fixes #6201

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

6 years agoDH: add some basic tests (and comments)
Dr. Matthias St. Pierre [Thu, 17 May 2018 22:51:15 +0000 (00:51 +0200)]
DH: add some basic tests (and comments)

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

6 years agoDH: add simple getters for commonly used DH struct members
Dr. Matthias St. Pierre [Wed, 16 May 2018 14:18:13 +0000 (16:18 +0200)]
DH: add simple getters for commonly used DH struct members

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

6 years agoMake BN_GF2m_mod_arr more constant time
Matt Caswell [Wed, 16 May 2018 08:58:27 +0000 (09:58 +0100)]
Make BN_GF2m_mod_arr more constant time

Experiments have shown that the lookup table used by BN_GF2m_mod_arr
introduces sufficient timing signal to recover the private key for an
attacker with access to cache timing information on the victim's host.
This only affects binary curves (which are less frequently used).

No CVE is considered necessary for this issue.

The fix is to replace the lookup table with an on-the-fly calculation of
the value from the table instead, which can be performed in constant time.

Thanks to Youngjoo Shin for reporting this issue.

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

6 years agoImprove testing of tickets with post-handshake auth
Matt Caswell [Fri, 11 May 2018 16:47:27 +0000 (17:47 +0100)]
Improve testing of tickets with post-handshake auth

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5227)

6 years agoAdd documentation for the ability to control the number of tickets
Matt Caswell [Fri, 16 Mar 2018 18:03:52 +0000 (18:03 +0000)]
Add documentation for the ability to control the number of tickets

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5227)

6 years agoChange the default number of NewSessionTickets we send to 2
Matt Caswell [Wed, 14 Mar 2018 19:22:48 +0000 (19:22 +0000)]
Change the default number of NewSessionTickets we send to 2

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5227)

6 years agoAllow configuation of the number of TLSv1.3 session tickets via SSL_CONF
Matt Caswell [Wed, 31 Jan 2018 16:40:03 +0000 (16:40 +0000)]
Allow configuation of the number of TLSv1.3 session tickets via SSL_CONF

Also allows the apps to set it.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5227)

6 years agoEnable the ability to set the number of TLSv1.3 session tickets sent
Matt Caswell [Wed, 31 Jan 2018 17:26:46 +0000 (17:26 +0000)]
Enable the ability to set the number of TLSv1.3 session tickets sent

We send a session ticket automatically in TLSv1.3 at the end of the
handshake. This commit provides the ability to set how many tickets should
be sent. By default this is one.

Fixes #4978

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5227)

6 years agoAdd a note on CHANGES and NEWS in CONTRIBUTING
Richard Levitte [Mon, 14 May 2018 03:38:59 +0000 (05:38 +0200)]
Add a note on CHANGES and NEWS in CONTRIBUTING

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/6249)

6 years agoWhen producing man-pages, ensure NAME section is one line only
Richard Levitte [Wed, 16 May 2018 09:12:21 +0000 (11:12 +0200)]
When producing man-pages, ensure NAME section is one line only

There are *roff parsers that are strict about the NAME section being
one line only.  The man(7) on Debian GNU/Linux suggests that this is
appropriate, so we compensate our multi-line NAME sections by fixing
the *roff output.

Noted by Eric S. Raymond

Related to #6264

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

6 years agoNOTES.ANDROID: fix typo in build notes
Gregor Jasny [Sun, 13 May 2018 17:51:52 +0000 (19:51 +0200)]
NOTES.ANDROID: fix typo in build notes

CLA: trivial

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6244)

6 years agowindows-makefile.tmpl: delete export library prior link.
Andy Polyakov [Mon, 14 May 2018 15:06:04 +0000 (17:06 +0200)]
windows-makefile.tmpl: delete export library prior link.

LINK can outsmart itself and choose to not update export .lib upon
corresponding .dll re-link. Since dependency is between .lib and all
.obj-s, re-compilation of any .obj makes NMAKE relink .dll and all
.exe-s over and over...

Reviewed-by: Rich Salz <rsalz@openssl.org>
6 years agoSuport TLSv1.3 draft 28
Matt Caswell [Mon, 14 May 2018 17:35:30 +0000 (18:35 +0100)]
Suport TLSv1.3 draft 28

Also retains support for drafts 27 and 26

Fixes #6257

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

6 years agoFix no-tls1_2
Matt Caswell [Mon, 14 May 2018 13:37:16 +0000 (14:37 +0100)]
Fix no-tls1_2

Also fixes no-tls1_2-method, no-tls1_3, no-tls, no-ec

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

6 years agoFix no-psk
Matt Caswell [Mon, 14 May 2018 13:28:06 +0000 (14:28 +0100)]
Fix no-psk

Fixes #6239

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

6 years agoCI config: no need to make both install and install_docs
Richard Levitte [Mon, 14 May 2018 07:28:52 +0000 (09:28 +0200)]
CI config: no need to make both install and install_docs

'install' depends on 'install_docs', so making the latter explicit is
a waste.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6250)

6 years agoLink in passphrase-encoding(7) in relevant documentation
Richard Levitte [Sun, 13 May 2018 09:35:14 +0000 (11:35 +0200)]
Link in passphrase-encoding(7) in relevant documentation

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6179)

6 years agoDocs: add general document on how pass phrases are handled
Richard Levitte [Fri, 4 May 2018 22:06:07 +0000 (00:06 +0200)]
Docs: add general document on how pass phrases are handled

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6179)

6 years agoUI console: Restore tty settings, do not force ECHO after prompt
Richard Levitte [Wed, 2 May 2018 12:18:55 +0000 (14:18 +0200)]
UI console: Restore tty settings, do not force ECHO after prompt

The Console UI method always set echo on after prompting without
echo.  However, echo might not have been on originally, so just
restore the original TTY settings.

Fixes #2373

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6156)

6 years agoapps/speed: Add brainpool curves support
FdaSilvaYY [Tue, 8 May 2018 08:34:59 +0000 (10:34 +0200)]
apps/speed: Add brainpool curves support

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6133)

6 years agoapps/speed: fix possible OOB access in some EC arrays
FdaSilvaYY [Sun, 29 Apr 2018 23:13:58 +0000 (01:13 +0200)]
apps/speed: fix possible OOB access in some EC arrays

because there are actually 18 curves defined, but only 16 are plugged for
ecdsa test.
Deduce array size using OSSL_NELEM and so remove various magic numbers,
which required some declarations moving.
Implement OPT_PAIR list search without a null-ending element.
Fix some comparison between signed and unsigned integer expressions.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6133)

6 years agoSet sess to NULL after freeing it.
Kurt Roeckx [Sat, 12 May 2018 10:08:14 +0000 (12:08 +0200)]
Set sess to NULL after freeing it.

Found by OSS-fuzz

Bug introduced in commit 61fb59238dad6452a37ec14513fae617a4faef29

Reviewed-by: Matt Caswell <matt@openssl.org>
GH: #6235

6 years agoDon't memcpy the contents of an empty fragment
Matt Caswell [Fri, 11 May 2018 09:28:47 +0000 (10:28 +0100)]
Don't memcpy the contents of an empty fragment

In DTLS if we have buffered a fragment for a zero length message (e.g.
ServerHelloDone) then, when we unbuffered the fragment, we were attempting
to memcpy the contents of the fragment which is zero length and a NULL
pointer. This is undefined behaviour. We should check first whether we
have a zero length fragment.

Fixes a travis issue.

[extended tests]

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

6 years agoIn cases where we ask PEM_def_callback for minimum 0 length, accept 0 length
Richard Levitte [Fri, 4 May 2018 12:19:44 +0000 (14:19 +0200)]
In cases where we ask PEM_def_callback for minimum 0 length, accept 0 length

Fixes #4716

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

6 years agoFix typo: 'is an error occurred' in documentation
Dr. Matthias St. Pierre [Fri, 11 May 2018 14:54:43 +0000 (16:54 +0200)]
Fix typo: 'is an error occurred' in documentation

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

6 years agoRework the decrypt ticket callback
Matt Caswell [Wed, 9 May 2018 17:22:36 +0000 (18:22 +0100)]
Rework the decrypt ticket callback

Don't call the decrypt ticket callback if we've already encountered a
fatal error. Do call it if we have an empty ticket present.

Change the return code to have 5 distinct returns codes and separate it
from the input status value.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6198)

6 years agoFix mem leak in sslapi test
Matt Caswell [Wed, 9 May 2018 09:45:46 +0000 (10:45 +0100)]
Fix mem leak in sslapi test

The recent change in behaviour where you do not get a NewSessionTicket
message sent if you established the connection using a PSK caused a mem
leak to be triggered in sslapitest. It was actually a latent bug and we
were just lucky we never hit it before. The problem is due to complexity
with the way PSK sessions were set up in the early_data tests. PSK session
reference counting was handled differently to normal session reference
counting. This meant there were lots of special cases in the code where
we don't free a session if it is a PSK. It makes things easier if we just
handle PSK reference counts in the same way as other session reference
counts, and then we can remove all of the special case code.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6198)

6 years agoAdd a test for the ticket callbacks
Matt Caswell [Tue, 8 May 2018 15:29:02 +0000 (16:29 +0100)]
Add a test for the ticket callbacks

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6198)

6 years agoDocument when a new session ticket gets created on resumption
Matt Caswell [Tue, 8 May 2018 15:28:44 +0000 (16:28 +0100)]
Document when a new session ticket gets created on resumption

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6198)

6 years agoFix ticket callbacks in TLSv1.3
Matt Caswell [Tue, 8 May 2018 13:50:17 +0000 (14:50 +0100)]
Fix ticket callbacks in TLSv1.3

The return value from the ticket_key callback was not properly handled in
TLSv1.3, so that a ticket was *always* renewed even if the callback
requested that it should not be.

Also the ticket decrypt callback was not being called at all in TLSv1.3.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6198)

6 years agoFlush server side unauthenticated writes
Matt Caswell [Tue, 8 May 2018 13:34:27 +0000 (14:34 +0100)]
Flush server side unauthenticated writes

When a server call SSL_write_early_data() to write to an unauthenticated
client the buffering BIO is still in place, so we should ensure we flush
the write.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6198)

6 years agoAdd some more SSL_pending() and SSL_has_pending() tests
Matt Caswell [Wed, 2 May 2018 15:08:07 +0000 (16:08 +0100)]
Add some more SSL_pending() and SSL_has_pending() tests

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

6 years agoDon't set TCP_NODELAY on a UDP socket
Matt Caswell [Wed, 2 May 2018 15:08:27 +0000 (16:08 +0100)]
Don't set TCP_NODELAY on a UDP socket

This was preventing DTLS connections from being made from the command line.

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

6 years agoMark DTLS records as read when we have finished with them
Matt Caswell [Wed, 2 May 2018 15:07:13 +0000 (16:07 +0100)]
Mark DTLS records as read when we have finished with them

The TLS code marks records as read when its finished using a record. The DTLS code did
not do that. However SSL_has_pending() relies on it. So we should make DTLS consistent.

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

6 years agoTest an old style PSK callback with no cert will prefer SHA-256
Matt Caswell [Thu, 10 May 2018 11:33:51 +0000 (12:33 +0100)]
Test an old style PSK callback with no cert will prefer SHA-256

If using an old style PSK callback and no certificate is configured for
the server, we should prefer ciphersuites based on SHA-256, because that
is the default hash for those callbacks as specified in the TLSv1.3 spec.

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

6 years agoProvide documentation for the -psk_session option
Matt Caswell [Thu, 10 May 2018 11:01:06 +0000 (12:01 +0100)]
Provide documentation for the -psk_session option

The s_client/s_server docs were missing documentation for this option.

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

6 years agoPrefer SHA-256 ciphersuites if using old style PSKs
Matt Caswell [Thu, 10 May 2018 10:51:45 +0000 (11:51 +0100)]
Prefer SHA-256 ciphersuites if using old style PSKs

If we have no certificate and we are using "old style" PSKs then we will
always default to using SHA-256 for that PSK. However we may have selected
a ciphersuite that is not based on SHA-256. Therefore if we see that there
are no certificates and we have been configured for "old style" PSKs then
we should prefer SHA-256 based ciphersuites during the selection process.

Fixes #6197

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

6 years agoUse void in all function definitions that do not take any arguments
Kurt Roeckx [Wed, 9 May 2018 15:09:50 +0000 (17:09 +0200)]
Use void in all function definitions that do not take any arguments

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

6 years agorsaz_avx2_eligible doesn't take parameters
Kurt Roeckx [Wed, 9 May 2018 16:32:02 +0000 (18:32 +0200)]
rsaz_avx2_eligible doesn't take parameters

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

6 years agoSet the ossl_shim to auto retry if not running asynchronously
Matt Caswell [Thu, 10 May 2018 14:31:00 +0000 (15:31 +0100)]
Set the ossl_shim to auto retry if not running asynchronously

In certain circumstances in the DTLS code we have to drop a record (e.g. if
it is a stale retransmit). We then have to move on to try and read the next
record. Some applications using blocking sockets (e.g. s_server/s_client
will hang if there isn't actually any data to be read from the socket yet).
Others can tolerate this. Therefore SSL_read()/SSL_write() can sometimes
return SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE even when using blocking
sockets. Applications can use the mode SSL_MODE_AUTO_RETRY, to switch this
behaviour off so that we never return unless we have read the data we
wanted to.

Commit ad96225285 fixed a DTLS problem where we always retried even if
SSL_MODE_AUTO_RETRY was not set. However that fix caused the Boring
ossl_shim to fail in some tests because it was relying on the previous
(buggy) behaviour. The ossl_shim should be set into SSL_MODE_AUTO_RETRY if
it is not operating asynchronously to avoid this problem.

[extended tests]

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