oweals/openssl.git
5 years agoUpdate dgst.c to show a list of message digests
agnosticdev [Mon, 16 Sep 2019 12:09:01 +0000 (07:09 -0500)]
Update dgst.c to show a list of message digests

Fixes #9893

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10219)

5 years agofixed the RETURN VALUES section in the EC_GROUP documentation
jayaram [Thu, 22 Aug 2019 05:21:25 +0000 (10:51 +0530)]
fixed the RETURN VALUES section in the EC_GROUP documentation
for the following functions.

EC_GROUP_get_order
EC_GROUP_get_cofactor
EC_GROUP_get_curve_name
EC_GROUP_get_asn1_flag
EC_GROUP_get_point_conversion_form
EC_GROUP_get_degree

(cherry picked from commit df3d1e84b3802acffeec11d6224e8a0e33d0aa83)

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9664)

5 years agoMove random-related defines from e_os.h to rand_unix.c
Dr. Matthias St. Pierre [Sun, 29 Sep 2019 23:00:59 +0000 (01:00 +0200)]
Move random-related defines from e_os.h to rand_unix.c

Fixes #10049

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

(cherry picked from commit 01036e2afbe116d608be048ed15930fc885ab2a8)

5 years agorand_unix.c: correct include guard comments
Dr. Matthias St. Pierre [Mon, 30 Sep 2019 07:05:44 +0000 (09:05 +0200)]
rand_unix.c: correct include guard comments

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

(cherry picked from commit 2a7e6ed86be20bd472696a3eafe5d20ec9579dab)

5 years agoAdd GCD testing infrastructure.
Cesar Pereida Garcia [Fri, 20 Sep 2019 11:11:19 +0000 (14:11 +0300)]
Add GCD testing infrastructure.

This commit adds testing and Known Answer Tests (KATs) to OpenSSL for
the `BN_gcd` function.

(cherry picked from commit b75d6310857bc44ef2851bde68a1979c18bb4807)

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10122)

5 years agoConstant-time GCD function.
Cesar Pereida Garcia [Fri, 13 Sep 2019 14:54:54 +0000 (17:54 +0300)]
Constant-time GCD function.

This commit replaces the current `BN_gcd` function with a constant-time
GCD implementation.

(cherry picked from commit f3c4adfc7eb13e9eff514039b4c60b457bdba433)

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10122)

5 years agoUnify BN_rshift design
Cesar Pereida Garcia [Wed, 16 Oct 2019 09:10:18 +0000 (12:10 +0300)]
Unify BN_rshift design

This commit aims at refactoring the `BN_rshift` by making it a wrapper
around `bn_rshift_fixed_top`, in order to match the current design of
`BN_lshift`, as suggested in the discussion at
https://github.com/openssl/openssl/pull/10122#discussion_r332474277 .

As described in the code, by refactoring this function, `BN_rshift`
provides a constant-time behavior for sufficiently[!] zero-padded inputs
under the following assumptions: `|n < BN_BITS2|` or `|n / BN_BITS2|`
being non-secret.

Notice that `BN_rshift` returns a canonical representation of the
BIGNUM, if a `fixed_top` representation is required, the caller should
call `bn_rshift_fixed_top` instead.

(cherry picked from commit 8eba6de59e2b06f23c214344423a5a618d1c9ffd)

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10196)

5 years ago[crypto/asn1/x_bignum.c] Explicit test against NULL
Cesar Pereida Garcia [Thu, 12 Sep 2019 13:58:50 +0000 (16:58 +0300)]
[crypto/asn1/x_bignum.c] Explicit test against NULL

As a fixup to https://github.com/openssl/openssl/pull/9779 to better
conform to the project code style guidelines, this commit amends the
original changeset to explicitly test against NULL, i.e. writing

```
if (p != NULL)
```

rather than

```
if (!p)
```

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9881)

5 years agoFix an incorrect macro
Matt Caswell [Thu, 6 Jun 2019 11:14:59 +0000 (12:14 +0100)]
Fix an incorrect macro

A macro was missing a space which was confusing find-doc-nits

Reviewed-by: Richard Levitte <levitte@openssl.org>
(cherry picked from commit 8caab503ba004abb555d636c1ca9f7bcde79657f)

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10094)

5 years agoi2d_PublicKey was listed in 2 different man pages
Matt Caswell [Thu, 6 Jun 2019 11:14:28 +0000 (12:14 +0100)]
i2d_PublicKey was listed in 2 different man pages

find-doc-nits complains if a symbol is documented in more than one
location.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(cherry picked from commit 4ff4e53f816855b07fc02dc931dd57b2ae324aa1)

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10094)

5 years agoissue-8493: Fix for filenames with newlines using openssl dgst
Pauli [Sat, 30 Mar 2019 01:22:51 +0000 (11:22 +1000)]
issue-8493: Fix for filenames with newlines using openssl dgst

The output format now matches coreutils *dgst tools.

[ edited to remove trailing white space ]

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(cherry picked from commit f3448f5481a8d1f6fbf5fd05caaca229af0b87f7)

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10094)

5 years agoAdd documentation for the -sigopt option.
Pauli [Tue, 19 Mar 2019 01:22:32 +0000 (11:22 +1000)]
Add documentation for the -sigopt option.

Reviewed-by: Paul Yang <yang.yang@baishancloud.com>
(cherry picked from commit d7b2124a428f9e00ed7647554b5be7153aac71f6)

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10094)

5 years agoDocument and add macros for additional DSA options
David Benjamin [Fri, 25 Jan 2019 19:56:45 +0000 (13:56 -0600)]
Document and add macros for additional DSA options

EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS and EVP_PKEY_CTRL_DSA_PARAMGEN_MD are only
exposed from EVP_PKEY_CTX_ctrl, which means callers must write more error-prone
code (see also issue #1319). Add the missing wrapper macros and document them.

Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit a97faad76a1be22eadd6c1a39972ad5e095d9e80)

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10094)

5 years agoAdd missing EVP_MD documentation
Antoine Salon [Fri, 14 Dec 2018 20:47:07 +0000 (12:47 -0800)]
Add missing EVP_MD documentation

Signed-off-by: Antoine Salon <asalon@vmware.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit 37842dfaebcf28b4ca452c6abd93ebde1b4aa6dc)

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10094)

5 years agoIgnore duplicated undocumented things
Rich Salz [Wed, 17 Oct 2018 14:25:00 +0000 (10:25 -0400)]
Ignore duplicated undocumented things

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Yang <yang.yang@baishancloud.com>
(cherry picked from commit ee4afacd96f5bfbe7662c8f0ec4464c6eee4c450)

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/10094)

5 years ago[ec_asn1.c] Avoid injecting seed when built-in matches
Nicola Tuveri [Thu, 10 Oct 2019 17:30:58 +0000 (20:30 +0300)]
[ec_asn1.c] Avoid injecting seed when built-in matches

An unintended consequence of https://github.com/openssl/openssl/pull/9808
is that when an explicit parameters curve is matched against one of the
well-known builtin curves we automatically inherit also the associated
seed parameter, even if the input parameters excluded such
parameter.

This later affects the serialization of such parsed keys, causing their
input DER encoding and output DER encoding to differ due to the
additional optional field.

This does not cause problems internally but could affect external
applications, as reported in
https://github.com/openssl/openssl/pull/9811#issuecomment-536153288

This commit fixes the issue by conditionally clearing the seed field if
the original input parameters did not include it.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/10140)

(cherry picked from commit f97a8af2f3f3573f0759693117c9d33d2a63c27e)

5 years agoConfigure: accept Windows style compiler options
Dr. Matthias St. Pierre [Fri, 20 Sep 2019 22:14:16 +0000 (00:14 +0200)]
Configure: accept Windows style compiler options

Currently the Configure command only supports passing UNIX style
options (`-opt`) to the compiler. Passing Windows style options
(`/opt`) yields an error. Fortunately, the compiler accepts both
types of options, nevertheless this commit fixes that discrimination
of Windows users.

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

(cherry picked from commit f246f54f18d380791cc60be4aea0fbc7253a9a20)

5 years agoIgnore empty ALPN elements in CLI args
Viktor Dukhovni [Fri, 11 Oct 2019 21:52:19 +0000 (17:52 -0400)]
Ignore empty ALPN elements in CLI args

Reviewed-by: Matt Caswell <matt@openssl.org>
5 years agoFix unused goto label gcc warning
Viktor Szakats [Tue, 10 Sep 2019 22:47:57 +0000 (22:47 +0000)]
Fix unused goto label gcc warning

On systems with undefined AI_ADDRCONFIG and AI_NUMERICHOST:

x86_64-w64-mingw32-gcc  -I. -Icrypto/include -Iinclude -m64 -Wall -O3 -fno-ident ...
crypto/bio/b_addr.c: In function 'BIO_lookup_ex':
crypto/bio/b_addr.c:699:7: warning: label 'retry' defined but not used [-Wunused-label]
       retry:
       ^~~~~

Regression from: 3f91ede9aea70774d9b5d509bc76d484ebaff6aa

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/9856)

(cherry picked from commit be66a15cc1a4c3cc68fa854ceea321ca57f96304)

5 years agossl/statem/statem_lib.c: make servercontext/clientcontext arrays of chars instead...
Artiom Vaskov [Thu, 12 Sep 2019 10:40:32 +0000 (13:40 +0300)]
ssl/statem/statem_lib.c: make servercontext/clientcontext arrays of chars instead of char pointers to fix EBCDIC builds.

Fixes #9869

CLA:trivial

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

5 years agoFix reference to PEM docs
Rich Salz [Sat, 5 Oct 2019 17:48:50 +0000 (13:48 -0400)]
Fix reference to PEM docs

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/10101)

(cherry picked from commit 120cc034271e9ab52f92840a16784228e50564f9)

5 years agoAdd documentation for PEM_{read,write}_bio_Parameters()
Richard Levitte [Mon, 7 Oct 2019 05:23:32 +0000 (07:23 +0200)]
Add documentation for PEM_{read,write}_bio_Parameters()

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

(cherry picked from commit 9a6abb95be42b88c7c5ebc8c97f14afdc5919aa1)

5 years agoSend bad_record_mac instead of decryption_failed
Matt Caswell [Fri, 4 Oct 2019 13:01:21 +0000 (14:01 +0100)]
Send bad_record_mac instead of decryption_failed

The decryption failed alert was deprecated a long time ago. It can
provide an attacker too much information to be able to distinguish between
MAC failures and decryption failures and can lead to oracle attacks.
Instead we should always use the bad_record_mac alert for these issues.
This fixes one instance that still exists. It does not represent a
security issue in this case because it is only ever sent if the record is
publicly invalid, i.e. we have detected it is invalid without using any
secret material.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/10093)

(cherry picked from commit 37133290832ac2d1389926eba7325125fdacbe8d)

5 years agoFix typo in comment
Pauli [Sun, 6 Oct 2019 03:39:01 +0000 (13:39 +1000)]
Fix typo in comment

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

(cherry picked from commit 89e5aaa1d72058404d3ea06bfaeff5334aba202d)

5 years ago'init_buf' memory can be freed when DTLS is used over SCTP (not over UDP).
NaveenShivanna86 [Wed, 21 Aug 2019 06:28:29 +0000 (11:58 +0530)]
'init_buf' memory can be freed when DTLS is used over SCTP (not over UDP).

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/9653)

(cherry picked from commit e7c27a6c3716843f8412fd96311b70ac84b785f9)

5 years agoDefine AESNI_ASM if AESNI assembler is included, and use it
Richard Levitte [Thu, 3 Oct 2019 06:28:31 +0000 (08:28 +0200)]
Define AESNI_ASM if AESNI assembler is included, and use it

Because we have cases where basic assembler support isn't present, but
AESNI asssembler support is, we need a separate macro that indicates
that, and use it.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10080)

5 years agorsa: replace magic number '11' by RSA_PKCS1_PADDING_SIZE
Dr. Matthias St. Pierre [Thu, 3 Oct 2019 12:20:52 +0000 (14:20 +0200)]
rsa: replace magic number '11' by RSA_PKCS1_PADDING_SIZE

Suggested by Matt Hart

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

(cherry picked from commit f1d1903dd3dd1d68a5eae190b8c2a88bfe0a68ac)

5 years agoFix iOS simulator build
Bernd Edlinger [Tue, 24 Sep 2019 17:38:18 +0000 (19:38 +0200)]
Fix iOS simulator build

Fixes #9999

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10002)

5 years agoAdd arm64 in test matrix on TravisCI.
Fangming.Fang [Sun, 29 Sep 2019 05:58:19 +0000 (05:58 +0000)]
Add arm64 in test matrix on TravisCI.

Change-Id: I5d2b729699cfd8e80c3df17db4a9d2edcbf64454

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10046)

(cherry picked from commit 0399aba7e05ea9bb1a58bd2e1b164f353f6ef1c9)

5 years agodoc: EVP_DigestInit clears all flags
Christian Heimes [Fri, 27 Sep 2019 09:08:43 +0000 (11:08 +0200)]
doc: EVP_DigestInit clears all flags

Mention that EVP_DigestInit() also clears all flags.

Fixes: 10031
Signed-off-by: Christian Heimes <christian@python.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10032)

(cherry picked from commit 091aab66a6dbc3a3ecee7684aa30811b342f04e7)

5 years agoDo not print extensions in Certificate message for TLS1.2 and lower
Daniil Zotkin [Tue, 24 Sep 2019 08:08:23 +0000 (11:08 +0300)]
Do not print extensions in Certificate message for TLS1.2 and lower

According to RFC8446 CertificateEntry in Certificate message contains
extensions that were not present in the Certificate message in RFC5246.

CLA: trivial

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9994)

(cherry picked from commit 65c76cd2c9e8da9468dd490b334e56c51dbef582)

5 years agoFix long name of some Microsoft objects
Michael Osipov [Fri, 27 Sep 2019 07:04:53 +0000 (09:04 +0200)]
Fix long name of some Microsoft objects

CLA: trivial

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10029)

(cherry picked from commit 648b53b88ea55b4c2f2c8c57d041075731db5f95)

5 years agoAdd defines for __NR_getrandom for all Linux architectures
Kurt Roeckx [Sat, 28 Sep 2019 12:59:32 +0000 (14:59 +0200)]
Add defines for __NR_getrandom for all Linux architectures

Fixes: #10015

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
GH: #10044
(cherry picked from commit 4dcb150ea30f9bbfa7946e6b39c30a86aca5ed02)

5 years agoCorrect the function names in SSL_CTX_set_stateless_cookie_generate_cb.pod
Matt Caswell [Fri, 27 Sep 2019 10:24:26 +0000 (11:24 +0100)]
Correct the function names in SSL_CTX_set_stateless_cookie_generate_cb.pod

Although the synopsis used the correct function names, the description did
not. Also the description of the equivalent DTLSv1_listen() callbacks was
missing, so these have been added.

Fixes #10030

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/10033)

(cherry picked from commit 84f471ecab76a16281a16c53d259bbcae358816f)

5 years agoFix a bundle of mischecks of return values
Paul Yang [Mon, 30 Sep 2019 06:05:31 +0000 (14:05 +0800)]
Fix a bundle of mischecks of return values

Several EVP_PKEY_xxxx functions return 0 and a negative value for
indicating errors. Some places call these functions with a zero return
value check only, which misses the check for the negative scenarios.

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

(cherry picked from commit 7e3ae24832e0705583b1471febf3dc0eb1cc021f)

5 years agoFix a return value bug in apps/speed.c
Paul Yang [Mon, 30 Sep 2019 03:33:24 +0000 (11:33 +0800)]
Fix a return value bug in apps/speed.c

Those functions returns less than and equal to 0 to indicate an error
occured.

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

(cherry picked from commit 94bd168a9e31d1ab4986e94056dfae71ec5f051f)

5 years agoAdd util/fix-includes script
Dr. Matthias St. Pierre [Fri, 27 Sep 2019 21:58:12 +0000 (23:58 +0200)]
Add util/fix-includes script

This script contains all adjustments to header files which were made
during the reorganization of the header files. It is meant as an aid
for other contributors which encounter preprocessor #include errors
after rebasing over this pull request. Simply running

  util/fix-includes

from the root of the source directory should hopefully fix the problem.

Note: such #include errors are expected only for pull requests which
add a lot of new code, in particular new compilation modules.

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

5 years agoFix header file include guard names
Dr. Matthias St. Pierre [Fri, 27 Sep 2019 21:58:12 +0000 (23:58 +0200)]
Fix header file include guard names

Make the include guards consistent by renaming them systematically according
to the naming conventions below

The public header files (in the 'include/openssl' directory) are not changed
in 1.1.1, because it is a stable release.

For the private header files files, the guard names try to match the path
specified in the include directives, with all letters converted to upper case
and '/' and '.' replaced by '_'. An extra 'OSSL_' is added as prefix.

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

5 years agoReorganize local header files
Dr. Matthias St. Pierre [Fri, 27 Sep 2019 21:58:06 +0000 (23:58 +0200)]
Reorganize local header files

Apart from public and internal header files, there is a third type called
local header files, which are located next to source files in the source
directory. Currently, they have different suffixes like

  '*_lcl.h', '*_local.h', or '*_int.h'

This commit changes the different suffixes to '*_local.h' uniformly.

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

5 years agoReorganize private crypto header files
Dr. Matthias St. Pierre [Fri, 27 Sep 2019 21:57:58 +0000 (23:57 +0200)]
Reorganize private crypto header files

Currently, there are two different directories which contain internal
header files of libcrypto which are meant to be shared internally:

While header files in 'include/internal' are intended to be shared
between libcrypto and libssl, the files in 'crypto/include/internal'
are intended to be shared inside libcrypto only.

To make things complicated, the include search path is set up in such
a way that the directive #include "internal/file.h" could refer to
a file in either of these two directoroes. This makes it necessary
in some cases to add a '_int.h' suffix to some files to resolve this
ambiguity:

  #include "internal/file.h"      # located in 'include/internal'
  #include "internal/file_int.h"  # located in 'crypto/include/internal'

This commit moves the private crypto headers from

  'crypto/include/internal'  to  'include/crypto'

As a result, the include directives become unambiguous

  #include "internal/file.h"       # located in 'include/internal'
  #include "crypto/file.h"         # located in 'include/crypto'

hence the superfluous '_int.h' suffixes can be stripped.

The files 'store_int.h' and 'store.h' need to be treated specially;
they are joined into a single file.

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

5 years agoDOC: fix documentation of som EVP_MD_CTX functions
Richard Levitte [Tue, 24 Sep 2019 11:22:13 +0000 (13:22 +0200)]
DOC: fix documentation of som EVP_MD_CTX functions

They were documented to take an EVP_MD pointer, when they really take
an EVP_MD_CTX pointer.

Fixes #9993

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9997)

5 years agoUse the correct maximum indent
Kurt Roeckx [Fri, 20 Sep 2019 18:26:42 +0000 (20:26 +0200)]
Use the correct maximum indent

Found by OSS-Fuzz

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
GH: #9959
(cherry picked from commit a6105ef40d65b35818f2b8ae8ca9e57ca6956d1d)

5 years agoapps/pkcs12: print multiple PKCS#12 safeBag attribute values if present
Jon Spillett [Mon, 2 Sep 2019 00:06:29 +0000 (10:06 +1000)]
apps/pkcs12: print multiple PKCS#12 safeBag attribute values if present

Currently the pkcs12 app will only ever print the first value of a multi-value
attribute. This is OK for some attributes (e.g. friendlyName, localKeyId) but
may miss values for other attributes.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/9751)

(cherry picked from commit dbcc7b45670483cc89428afe1d3c363ef83d76df)

5 years agoFix building statically without any dso support
Bernd Edlinger [Fri, 13 Sep 2019 08:45:29 +0000 (10:45 +0200)]
Fix building statically without any dso support

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

5 years agoclearing the ecx private key memory
ManishPatidar1 [Mon, 9 Sep 2019 13:32:56 +0000 (19:02 +0530)]
clearing the ecx private key memory

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9830)

(cherry picked from commit 6ef03ea98fac501e6d6e33bac6ad3c92ea074712)

5 years agoFix small typo in doc for X509_STORE_CTX_new
Jan-Frederik Rieckers [Fri, 13 Sep 2019 17:34:14 +0000 (19:34 +0200)]
Fix small typo in doc for X509_STORE_CTX_new

CLA: trivial

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9894)

(cherry picked from commit 64c1e74572f16a3e7c225f66fe85a3451ad39e68)

5 years agoDo no mention private headers in public headers
Richard Levitte [Mon, 9 Sep 2019 00:41:26 +0000 (02:41 +0200)]
Do no mention private headers in public headers

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

(cherry picked from commit bd9faf117db1e53b2ad2ee9cbfe8def8c98ecb7b)

5 years agoAdd a minimal linux build target for Travis
Bernd Edlinger [Fri, 13 Sep 2019 07:24:53 +0000 (09:24 +0200)]
Add a minimal linux build target for Travis

[extended tests]

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

5 years agoAdd a minimal windows build config for AppVeyor
Bernd Edlinger [Fri, 13 Sep 2019 07:05:08 +0000 (09:05 +0200)]
Add a minimal windows build config for AppVeyor

[extended tests]

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

5 years agoFix potential memory leaks with BN_to_ASN1_INTEGER
Bernd Edlinger [Mon, 9 Sep 2019 17:12:25 +0000 (19:12 +0200)]
Fix potential memory leaks with BN_to_ASN1_INTEGER

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9833)

(cherry picked from commit f28bc7d386b25fb75625d0c62c6b2e6d21de0d09)

5 years agoBIO_f_zlib: Properly handle BIO_CTRL_PENDING and BIO_CTRL_WPENDING calls.
Tomas Mraz [Thu, 12 Sep 2019 10:27:36 +0000 (12:27 +0200)]
BIO_f_zlib: Properly handle BIO_CTRL_PENDING and BIO_CTRL_WPENDING calls.

There can be data to write in output buffer and data to read that were
not yet read in the input stream.

Fixes #9866

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

(cherry picked from commit 6beb8b39ba8e4cb005c1fcd2586ba19e17f04b95)

5 years agocrypto/threads_win.c: fix preprocessor indentation
Dr. Matthias St. Pierre [Wed, 11 Sep 2019 08:40:18 +0000 (10:40 +0200)]
crypto/threads_win.c: fix preprocessor indentation

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

5 years agocrypto/threads_none.c: fix syntax error in openssl_get_fork_id()
Dr. Matthias St. Pierre [Wed, 11 Sep 2019 08:25:43 +0000 (10:25 +0200)]
crypto/threads_none.c: fix syntax error in openssl_get_fork_id()

Fixes #9858

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

5 years agoPrepare for 1.1.1e-dev
Matt Caswell [Tue, 10 Sep 2019 13:14:31 +0000 (14:14 +0100)]
Prepare for 1.1.1e-dev

Reviewed-by: Richard Levitte <levitte@openssl.org>
5 years agoPrepare for 1.1.1d release OpenSSL_1_1_1d
Matt Caswell [Tue, 10 Sep 2019 13:13:07 +0000 (14:13 +0100)]
Prepare for 1.1.1d release

Reviewed-by: Richard Levitte <levitte@openssl.org>
5 years agoUpdate copyright year
Matt Caswell [Tue, 10 Sep 2019 12:56:40 +0000 (13:56 +0100)]
Update copyright year

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

5 years agoRemove duplicate CHANGES entry
Matt Caswell [Tue, 10 Sep 2019 10:51:59 +0000 (11:51 +0100)]
Remove duplicate CHANGES entry

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

5 years agoFix a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey
Bernd Edlinger [Sat, 31 Aug 2019 22:16:28 +0000 (00:16 +0200)]
Fix a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey

An attack is simple, if the first CMS_recipientInfo is valid but the
second CMS_recipientInfo is chosen ciphertext. If the second
recipientInfo decodes to PKCS #1 v1.5 form plaintext, the correct
encryption key will be replaced by garbage, and the message cannot be
decoded, but if the RSA decryption fails, the correct encryption key is
used and the recipient will not notice the attack.

As a work around for this potential attack the length of the decrypted
key must be equal to the cipher default key length, in case the
certifiate is not given and all recipientInfo are tried out.

The old behaviour can be re-enabled in the CMS code by setting the
CMS_DEBUG_DECRYPT flag.

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

(cherry picked from commit 5840ed0cd1e6487d247efbc1a04136a41d7b3a37)

5 years agoUpdate CHANGES and NEWS for the new release
Matt Caswell [Tue, 10 Sep 2019 09:26:07 +0000 (10:26 +0100)]
Update CHANGES and NEWS for the new release

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9841)

5 years agoFix a potential crash in rand_unix.c
Bernd Edlinger [Fri, 6 Sep 2019 19:54:13 +0000 (21:54 +0200)]
Fix a potential crash in rand_unix.c

Due to the dynamic allocation that was added to rand_pool_add_begin
this function could now return a null pointer where it was previously
guaranteed to succeed. But the return value of this function does
not need to be checked by design.

Move rand_pool_grow from rand_pool_add_begin to rand_pool_bytes_needed.
Make an allocation error persistent to avoid falling back to less secure
or blocking entropy sources.

Fixes: a6a66e4511ee ("Make rand_pool buffers more dynamic in their sizing.")

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9687)

(cherry picked from commit fa3eb248e29ca8031e6a14e8a2c6f3cd58b5450e)

5 years agoFix a strict warnings error in rand_pool_acquire_entropy
Bernd Edlinger [Sat, 24 Aug 2019 09:38:32 +0000 (11:38 +0200)]
Fix a strict warnings error in rand_pool_acquire_entropy

There was a warning about unused variables in this config:
./config --strict-warnings --with-rand-seed=rdcpu

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9687)

(cherry picked from commit e301c147a763f67dcc5ba63eb7e2ae40d83a68aa)

5 years agodrbg: fix issue where DRBG_CTR fails if NO_DF is used (2nd attempt)
Dr. Matthias St. Pierre [Thu, 30 May 2019 16:37:29 +0000 (18:37 +0200)]
drbg: fix issue where DRBG_CTR fails if NO_DF is used (2nd attempt)

Since commit 7c226dfc434d a chained DRBG does not add additional
data anymore when reseeding from its parent. The reason is that
the size of the additional data exceeded the allowed size when
no derivation function was used.

This commit provides an alternative fix: instead of adding the
entire DRBG's complete state, we just add the DRBG's address
in memory, thereby providing some distinction between the different
DRBG instances.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9802)

5 years agodrbg: add fork id to additional data on UNIX systems
Dr. Matthias St. Pierre [Thu, 30 May 2019 16:52:39 +0000 (18:52 +0200)]
drbg: add fork id to additional data on UNIX systems

Provides a little extra fork-safety on UNIX systems, adding to the
fact that all DRBGs reseed automatically when the fork_id changes.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9802)

5 years agodrbg: ensure fork-safety without using a pthread_atfork handler
Dr. Matthias St. Pierre [Mon, 27 May 2019 19:03:09 +0000 (21:03 +0200)]
drbg: ensure fork-safety without using a pthread_atfork handler

When the new OpenSSL CSPRNG was introduced in version 1.1.1,
it was announced in the release notes that it would be fork-safe,
which the old CSPRNG hadn't been.

The fork-safety was implemented using a fork count, which was
incremented by a pthread_atfork handler. Initially, this handler
was enabled by default. Unfortunately, the default behaviour
had to be changed for other reasons in commit b5319bdbd095, so
the new OpenSSL CSPRNG failed to keep its promise.

This commit restores the fork-safety using a different approach.
It replaces the fork count by a fork id, which coincides with
the process id on UNIX-like operating systems and is zero on other
operating systems. It is used to detect when an automatic reseed
after a fork is necessary.

To prevent a future regression, it also adds a test to verify that
the child reseeds after fork.

CVE-2019-1549

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9802)

5 years ago[test] ECC: check the bounds for auto computing cofactor
Billy Brumley [Mon, 9 Sep 2019 08:29:09 +0000 (11:29 +0300)]
[test] ECC: check the bounds for auto computing cofactor

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/9821)

(cherry picked from commit 1d3cd983f56e0a580ee4216692ee3c9c7bf14de9)

5 years agoFix build with VS2008
Bernd Edlinger [Mon, 9 Sep 2019 09:42:56 +0000 (11:42 +0200)]
Fix build with VS2008

crypto/rand/rand_win.c(70) : error C2065: 'BCRYPT_USE_SYSTEM_PREFERRED_RNG' : undeclared identifier

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

(cherry picked from commit d3a1128bc25ec8bf835c81821e1be68fba39ab4b)

5 years agoUse BN_clear_free in DH_set0_key
Bernd Edlinger [Fri, 6 Sep 2019 22:53:24 +0000 (00:53 +0200)]
Use BN_clear_free in DH_set0_key

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9796)

(cherry picked from commit fa01370f7dc8f0a379483bbe74de11225857e5fe)

5 years agoDH_check_pub_key_ex was accidentally calling DH_check,
Bernd Edlinger [Fri, 6 Sep 2019 22:58:31 +0000 (00:58 +0200)]
DH_check_pub_key_ex was accidentally calling DH_check,
so results were undefined.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9796)

(cherry picked from commit 2b95e8efcf8b99892106070d9ac745a0a369f503)

5 years agoChange DH_generate_parameters back to order 2q subgroup
Bernd Edlinger [Mon, 9 Sep 2019 07:59:54 +0000 (09:59 +0200)]
Change DH_generate_parameters back to order 2q subgroup

For for G=2 and 5 DH_generate_parameters will continue to generate
the order 2q subgroup for compatibility with previous versions.

For G=3 DH_generate_parameters generates an order q subgroup, but it
will not pass the check in DH_check with previous OpenSSL versions.

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

5 years agoFix spacing nit in test/ectest.c
Nicola Tuveri [Mon, 9 Sep 2019 00:52:00 +0000 (03:52 +0300)]
Fix spacing nit in test/ectest.c

(cherry picked from commit 65936a56461fe09e8c81bca45122af5adcfabb00)

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

5 years ago[ec] Match built-in curves on EC_GROUP_new_from_ecparameters
Nicola Tuveri [Sat, 7 Sep 2019 15:05:31 +0000 (18:05 +0300)]
[ec] Match built-in curves on EC_GROUP_new_from_ecparameters

Description
-----------

Upon `EC_GROUP_new_from_ecparameters()` check if the parameters match any
of the built-in curves. If that is the case, return a new
`EC_GROUP_new_by_curve_name()` object instead of the explicit parameters
`EC_GROUP`.

This affects all users of `EC_GROUP_new_from_ecparameters()`:
- direct calls to `EC_GROUP_new_from_ecparameters()`
- direct calls to `EC_GROUP_new_from_ecpkparameters()` with an explicit
  parameters argument
- ASN.1 parsing of explicit parameters keys (as it eventually
  ends up calling `EC_GROUP_new_from_ecpkparameters()`)

A parsed explicit parameter key will still be marked with the
`OPENSSL_EC_EXPLICIT_CURVE` ASN.1 flag on load, so, unless
programmatically forced otherwise, if the key is eventually serialized
the output will still be encoded with explicit parameters, even if
internally it is treated as a named curve `EC_GROUP`.

Before this change, creating any `EC_GROUP` object using
`EC_GROUP_new_from_ecparameters()`, yielded an object associated with
the default generic `EC_METHOD`, but this was never guaranteed in the
documentation.
After this commit, users of the library that intentionally want to
create an `EC_GROUP` object using a specific `EC_METHOD` can still
explicitly call `EC_GROUP_new(foo_method)` and then manually set the
curve parameters using `EC_GROUP_set_*()`.

Motivation
----------

This has obvious performance benefits for the built-in curves with
specialized `EC_METHOD`s and subtle but important security benefits:
- the specialized methods have better security hardening than the
  generic implementations
- optional fields in the parameter encoding, like the `cofactor`, cannot
  be leveraged by an attacker to force execution of the less secure
  code-paths for single point scalar multiplication
- in general, this leads to reducing the attack surface

Check the manuscript at https://arxiv.org/abs/1909.01785 for an in depth
analysis of the issues related to this commit.

It should be noted that `libssl` does not allow to negotiate explicit
parameters (as per RFC 8422), so it is not directly affected by the
consequences of using explicit parameters that this commit fixes.
On the other hand, we detected external applications and users in the
wild that use explicit parameters by default (and sometimes using 0 as
the cofactor value, which is technically not a valid value per the
specification, but is tolerated by parsers for wider compatibility given
that the field is optional).
These external users of `libcrypto` are exposed to these vulnerabilities
and their security will benefit from this commit.

Related commits
---------------

While this commit is beneficial for users using built-in curves and
explicit parameters encoding for serialized keys, commit
b783beeadf6b80bc431e6f3230b5d5585c87ef87 (and its equivalents for the
1.0.2, 1.1.0 and 1.1.1 stable branches) fixes the consequences of the
invalid cofactor values more in general also for other curves
(CVE-2019-1547).

The following list covers commits in `master` that are related to the
vulnerabilities presented in the manuscript motivating this commit:

d2baf88c43 [crypto/rsa] Set the constant-time flag in multi-prime RSA too
311e903d84 [crypto/asn1] Fix multiple SCA vulnerabilities during RSA key validation.
b783beeadf [crypto/ec] for ECC parameters with NULL or zero cofactor, compute it
724339ff44 Fix SCA vulnerability when using PVK and MSBLOB key formats

Note that the PRs that contributed the listed commits also include other
commits providing related testing and documentation, in addition to
links to PRs and commits backporting the fixes to the 1.0.2, 1.1.0 and
1.1.1 branches.

This commit includes a partial backport of
https://github.com/openssl/openssl/pull/8555
(commit 8402cd5f75f8c2f60d8bd39775b24b03dd8b3b38)
for which the main author is Shane Lontis.

Responsible Disclosure
----------------------

This and the other issues presented in https://arxiv.org/abs/1909.01785
were reported by Cesar Pereida GarcĂ­a, Sohaib ul Hassan, Nicola Tuveri,
Iaroslav Gridin, Alejandro Cabrera Aldaya and Billy Bob Brumley from the
NISEC group at Tampere University, FINLAND.

The OpenSSL Security Team evaluated the security risk for this
vulnerability as low, and encouraged to propose fixes using public Pull
Requests.

_______________________________________________________________________________

Co-authored-by: Shane Lontis <shane.lontis@oracle.com>
(Backport from https://github.com/openssl/openssl/pull/9808)

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

5 years agoConfigure: clang: move -Wno-unknown-warning-option to the front
Dr. Matthias St. Pierre [Tue, 23 Jul 2019 18:54:03 +0000 (20:54 +0200)]
Configure: clang: move -Wno-unknown-warning-option to the front

While gcc ignores unknown options of the type '-Wno-xxx', clang by default issues
a warning [-Wunknown-warning-option] (see [3]), which together with '-Werror'
causes the build to fail. This turned out to be a problem on the 1.0.2 stable branch
in the case of the '-Wextended-offsetof' option, which was removed in version 6.0.0,
but needs to be kept here in order to support older clang versions, too (see #9446).

Incidentally, master and 1.1.1 branch already contained the -Wno-unknown-warning-option
option. Due to its special role and its importance, this commit adds an explaining
commit message and moves the option to the front.

[extended tests]

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9447)

(cherry picked from commit 03e5668343078b963cc6544ad7270743de13e514)

5 years agoAppend CVE-2019-1547 to related CHANGES entry
Nicola Tuveri [Sat, 7 Sep 2019 09:10:24 +0000 (12:10 +0300)]
Append CVE-2019-1547 to related CHANGES entry

This amends the entry added in a6186f39802f94937a46f7a41ef0c86b6334b592
with the relevant CVE.

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

5 years agoRemove x86/x86_64 BSAES and AES_ASM support
Bernd Edlinger [Fri, 23 Aug 2019 08:17:31 +0000 (10:17 +0200)]
Remove x86/x86_64 BSAES and AES_ASM support

This leaves VPAES and AESNI support.
The VPAES performance is comparable but BSAES is not
completely constant time. There are table lookups
using secret key data in AES_set_encrypt/decrypt_key
and in ctr mode short data uses the non-constant
time AES_encrypt function instead of bit-slicing.
Furthermore the AES_ASM is by far outperformed
by recent GCC versions.
Since BSAES calls back to AES_ASM for short
data blocks the performance on those is also
worse than the pure software implementaion.

Fixes: #9640

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

5 years agoCHANGES entry: for ECC parameters with NULL or zero cofactor, compute it
Billy Brumley [Fri, 6 Sep 2019 14:26:40 +0000 (17:26 +0300)]
CHANGES entry: for ECC parameters with NULL or zero cofactor, compute it

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/9781)

5 years ago[test] computing ECC cofactors: regression test
Billy Brumley [Thu, 5 Sep 2019 18:25:52 +0000 (21:25 +0300)]
[test] computing ECC cofactors: regression test

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/9781)

5 years ago[crypto/ec] for ECC parameters with NULL or zero cofactor, compute it
Billy Brumley [Thu, 5 Sep 2019 18:25:37 +0000 (21:25 +0300)]
[crypto/ec] for ECC parameters with NULL or zero cofactor, compute it

The cofactor argument to EC_GROUP_set_generator is optional, and SCA
mitigations for ECC currently use it. So the library currently falls
back to very old SCA-vulnerable code if the cofactor is not present.

This PR allows EC_GROUP_set_generator to compute the cofactor for all
curves of cryptographic interest. Steering scalar multiplication to more
SCA-robust code.

This issue affects persisted private keys in explicit parameter form,
where the (optional) cofactor field is zero or absent.

It also affects curves not built-in to the library, but constructed
programatically with explicit parameters, then calling
EC_GROUP_set_generator with a nonsensical value (NULL, zero).

The very old scalar multiplication code is known to be vulnerable to
local uarch attacks, outside of the OpenSSL threat model. New results
suggest the code path is also vulnerable to traditional wall clock
timing attacks.

CVE-2019-1547

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/9781)

5 years ago[ec/ecp_nistp*.c] restyle: use {} around `else` too
Nicola Tuveri [Fri, 6 Sep 2019 11:05:26 +0000 (14:05 +0300)]
[ec/ecp_nistp*.c] restyle: use {} around `else` too

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

(cherry picked from commit 4fe2ee3a449a8ca2886584e221f34ff0ef5de119)

5 years ago[ec/ecp_nistp*.c] remove flip_endian()
Nicola Tuveri [Thu, 5 Sep 2019 22:31:45 +0000 (01:31 +0300)]
[ec/ecp_nistp*.c] remove flip_endian()

Replace flip_endian() by using the little endian specific
BN_bn2lebinpad() and BN_lebin2bn().

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

(cherry picked from commit e0b660c27d8d97b4ad9e2098cc957de26872c0ef)

5 years agoUniform BN_bn2binpad() and BN_bn2lebinpad() implementations
Nicola Tuveri [Thu, 5 Sep 2019 21:18:36 +0000 (00:18 +0300)]
Uniform BN_bn2binpad() and BN_bn2lebinpad() implementations

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

(cherry picked from commit 1b338abe3abb8c73f004c34d4b8a9272b89dfd5d)

5 years agoMake BN_num_bits() consttime upon BN_FLG_CONSTTIME
Nicola Tuveri [Thu, 1 Aug 2019 23:08:34 +0000 (02:08 +0300)]
Make BN_num_bits() consttime upon BN_FLG_CONSTTIME

This issue was partially addressed by commit
972c87dfc7e765bd28a4964519c362f0d3a58ca4, which hardened its callee
BN_num_bits_word() to avoid leaking the most-significant word of its
argument via branching and memory access pattern.
The commit message also reported:
> There are a few places where BN_num_bits is called on an input where
> the bit length is also secret. This does *not* fully resolve those
> cases as we still only look at the top word.

BN_num_bits() is called directly or indirectly (e.g., through
BN_num_bytes() or BN_bn2binpad() ) in various parts of the `crypto/ec`
code, notably in all the currently supported implementations of scalar
multiplication (in the generic path through ec_scalar_mul_ladder() as
well as in dedicated methods like ecp_nistp{224,256,521}.c and
ecp_nistz256.c).

Under the right conditions, a motivated SCA attacker could retrieve the
secret bitlength of a secret nonce through this vulnerability,
potentially leading, ultimately, to recover a long-term secret key.

With this commit, exclusively for BIGNUMs that are flagged with
BN_FLG_CONSTTIME, instead of accessing only bn->top, all the limbs of
the BIGNUM are accessed up to bn->dmax and bitwise masking is used to
avoid branching.

Memory access pattern still leaks bn->dmax, the size of the lazily
allocated buffer for representing the BIGNUM, which is inevitable with
the current BIGNUM architecture: reading past bn->dmax would be an
out-of-bound read.
As such, it's the caller responsibility to ensure that bn->dmax does not
leak secret information, by explicitly expanding the internal BIGNUM
buffer to a public value sufficient to avoid any lazy reallocation
while manipulating it: this should be already done at the top level
alongside setting the BN_FLG_CONSTTIME.

Thanks to David Schrammel and Samuel Weiser for reporting this issue
through responsible disclosure.

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

(cherry picked from commit 8b44198b916015f77bef1befa26edb48ad8a0238)

5 years agoFix a SCA leak using BN_bn2bin()
Nicola Tuveri [Thu, 1 Aug 2019 22:33:05 +0000 (01:33 +0300)]
Fix a SCA leak using BN_bn2bin()

BN_bn2bin() is not constant-time and leaks the number of bits in the
processed BIGNUM.

The specialized methods in ecp_nistp224.c, ecp_nistp256.c and
ecp_nistp521.c internally used BN_bn2bin() to convert scalars into the
internal fixed length representation.

This can leak during ECDSA/ECDH key generation or handling the nonce
while generating an ECDSA signature, when using these implementations.
The amount and risk of leaked information useful for a SCA attack
varies for each of the three curves, as it depends mainly on the
ratio between the bitlength of the curve subgroup order (governing the
size of the secret nonce/key) and the limb size for the internal BIGNUM
representation (which depends on the compilation target architecture).

To fix this, we replace BN_bn2bin() with BN_bn2binpad(), bounding the
output length to the width of the internal representation buffer: this
length is public.

Internally the final implementation of both BN_bn2binpad() and
BN_bn2bin() already has masking in place to avoid leaking bn->top
through memory access patterns.
Memory access pattern still leaks bn->dmax, the size of the lazily
allocated buffer for representing the BIGNUM, which is inevitable with
the current BIGNUM architecture: reading past bn->dmax would be an
out-of-bound read.
As such, it's the caller responsibility to ensure that bn->dmax does not
leak secret information, by explicitly expanding the internal BIGNUM
buffer to a public value sufficient to avoid any lazy reallocation
while manipulating it: this is already done at the top level alongside
setting the BN_FLG_CONSTTIME.

Finally, the internal implementation of BN_bn2binpad() indirectly calls
BN_num_bits() via BN_num_bytes(): the current implementation of
BN_num_bits() can leak information to a SCA attacker, and is addressed
in the next commit.

Thanks to David Schrammel and Samuel Weiser for reporting this issue
through responsible disclosure.

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

(cherry picked from commit 805315d3a20f7274195eed75b06c391dacf3b197)

5 years agoFix a SCA leak in BN_generate_dsa_nonce
Bernd Edlinger [Fri, 6 Sep 2019 06:46:46 +0000 (08:46 +0200)]
Fix a SCA leak in BN_generate_dsa_nonce

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/9782)

(cherry picked from commit 31ca19403d56ad71d823cf62990518dfc6905bb4)

5 years ago[crypto/rsa] Set the constant-time flag in multi-prime RSA too
Cesar Pereida Garcia [Fri, 6 Sep 2019 07:48:00 +0000 (10:48 +0300)]
[crypto/rsa] Set the constant-time flag in multi-prime RSA too

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

5 years ago[crypto/asn1] Fix multiple SCA vulnerabilities during RSA key validation.
Cesar Pereida Garcia [Thu, 5 Sep 2019 09:13:11 +0000 (12:13 +0300)]
[crypto/asn1] Fix multiple SCA vulnerabilities during RSA key validation.

This commit addresses multiple side-channel vulnerabilities present
during RSA key validation.
Private key parameters are re-computed using variable-time functions.

This issue was discovered and reported by the NISEC group at TAU Finland.

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

5 years agoTeach TLSProxy how to parse CertificateRequest messages
Matt Caswell [Thu, 5 Sep 2019 15:21:56 +0000 (16:21 +0100)]
Teach TLSProxy how to parse CertificateRequest messages

We also use this in test_tls13messages to check that the extensions we
expect to see in a CertificateRequest are there.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9780)

(cherry picked from commit dc5bcb88d819de55eb37460c122e02fec91c6d86)

5 years agoDon't send a status_request extension in a CertificateRequest message
Matt Caswell [Thu, 5 Sep 2019 15:43:57 +0000 (16:43 +0100)]
Don't send a status_request extension in a CertificateRequest message

If a TLSv1.3 server configured to respond to the status_request extension
also attempted to send a CertificateRequest then it was incorrectly
inserting a non zero length status_request extension into that message.

The TLSv1.3 RFC does allow that extension in that message but it must
always be zero length.

In fact we should not be sending the extension at all in that message
because we don't support it.

Fixes #9767

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9780)

(cherry picked from commit debb64a0ca43969eb3f043aa8895a4faa7f12b6e)

5 years agoFix error handling in x509_lu.c
Bernd Edlinger [Mon, 19 Aug 2019 15:12:22 +0000 (17:12 +0200)]
Fix error handling in x509_lu.c

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9639)

(cherry picked from commit c70e2ec33943d3bd46d3d9950f774307feda832b)

5 years agoCleanup includes in rand_unix.c
Bernd Edlinger [Wed, 4 Sep 2019 09:39:54 +0000 (11:39 +0200)]
Cleanup includes in rand_unix.c

Fixes #9757

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

(cherry picked from commit 41ffd2ab09d24692c71850ccd7d5ff154196fe01)

5 years agoRemove ifndef FIPS_MODE from rand_unix.c
Bernd Edlinger [Wed, 4 Sep 2019 09:50:54 +0000 (11:50 +0200)]
Remove ifndef FIPS_MODE from rand_unix.c

This will never be the case for 1.1.1 so removed.

Fixes: comment 1 of #9757

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9762)

5 years agoSuppress 'No server certificate CA names sent' message
Billy Brawner [Wed, 28 Aug 2019 00:07:17 +0000 (17:07 -0700)]
Suppress 'No server certificate CA names sent' message

Fixes #9080

Signed-off-by: Billy Brawner <billy@wbrawner.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9710)

(cherry picked from commit 1e8e75d18be8856e753a57771754b9926c3f4264)

5 years agoTest SSL_set_ciphersuites
raja-ashok [Fri, 31 May 2019 03:20:54 +0000 (08:50 +0530)]
Test SSL_set_ciphersuites

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9621)

5 years agoFix SSL_set_ciphersuites to set even if no call to SSL_set_cipher_list
raja-ashok [Thu, 30 May 2019 18:21:18 +0000 (23:51 +0530)]
Fix SSL_set_ciphersuites to set even if no call to SSL_set_cipher_list

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9621)

5 years agoFix bogus check for EVP_PKEY mandatory digest in check_cert_usable()
David Woodhouse [Thu, 22 Aug 2019 17:42:05 +0000 (18:42 +0100)]
Fix bogus check for EVP_PKEY mandatory digest in check_cert_usable()

In commit 6aca8d1a5 ("Honour mandatory digest on private key in
has_usable_cert()") I added two checks for the capabilities of the
EVP_PKEY being used. One of them was wrong, as it should only be
checking the signature of the X.509 cert (by its issuer) against the
sigalgs given in a TLS v1.3 signature_algorithms_cert extension.

Remove it.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9705)

5 years agoRemove duplicate CHANGES text.
Pauli [Fri, 30 Aug 2019 09:16:43 +0000 (19:16 +1000)]
Remove duplicate CHANGES text.

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

5 years agoDon't include the DEVRANDOM being seeded logic on Android.
Pauli [Thu, 29 Aug 2019 21:38:58 +0000 (07:38 +1000)]
Don't include the DEVRANDOM being seeded logic on Android.

It lacks exposure of the `shm*` functions and should prefer the GETRANDOM
source.

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/9735)

(cherry picked from commit 280cc0180862ae6664b88d5ea12cb5f599000d36)

5 years agoFix NITs in comments and CHANGES for DEVRANDOM seeded check.
Pauli [Thu, 29 Aug 2019 21:29:35 +0000 (07:29 +1000)]
Fix NITs in comments and CHANGES for DEVRANDOM seeded check.

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

(cherry picked from commit 46a9cc9451213039fd53f62733b2ccd04e853bb2)

5 years agoFix SCA vulnerability when using PVK and MSBLOB key formats
Cesar Pereida Garcia [Wed, 14 Aug 2019 07:17:06 +0000 (10:17 +0300)]
Fix SCA vulnerability when using PVK and MSBLOB key formats

This commit addresses a side-channel vulnerability present when
PVK and MSBLOB key formats are loaded into OpenSSL.
The public key was not computed using a constant-time exponentiation
function.

This issue was discovered and reported by the NISEC group at TAU Finland.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9587)

(cherry picked from commit 724339ff44235149c4e8ddae614e1dda6863e23e)

5 years agoAvoid overflowing FDSET when using select(2).
Pauli [Sat, 24 Aug 2019 06:13:24 +0000 (16:13 +1000)]
Avoid overflowing FDSET when using select(2).

There is a problem in the rand_unix.c code when the random seed fd is greater
than or equal to FD_SETSIZE and the FDSET overruns its limit and walks the
stack.

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

(cherry picked from commit e1f8584d47a499301fba781086af6885fcf21fec)

5 years agotest/evp_test.c: distinguish parsing errors from processing errors
Richard Levitte [Fri, 23 Aug 2019 15:41:23 +0000 (17:41 +0200)]
test/evp_test.c: distinguish parsing errors from processing errors

Parsing functions are at liberty to return:

1:  when parsing on processing of the parsed value succeeded
0:  when the parsed keyword is unknown
-1: when the parsed value processing failed

Some parsing functions didn't do this quite right, they returned 0
when they should have returned -1, causing a message like this:

    Line 123: unknown keyword PeerKey

When this message (which is displayed when the parsing function
returns -1) would have been more appropriate:

    Line 123: error processing keyword PeerKey = ffdhe2048-2-pub

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/9682)

(cherry picked from commit f42c225d7f9a0bce0bf46103343402d3f0ad742f)