openssl.git
3 years agotest: add import and export key management hooks for the TLS provider.
Pauli [Tue, 9 Feb 2021 06:58:38 +0000 (16:58 +1000)]
test: add import and export key management hooks for the TLS provider.

Without these hooks, if the TLS provider isn't matched in the fetch cache, a test
failure will occur in the TLS API tests.  Without allowing import and export, an
existing key can not move to a new key manager even if it is really the same.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agotest: filter provider honours the no_cache setting.
Pauli [Tue, 9 Feb 2021 01:55:59 +0000 (11:55 +1000)]
test: filter provider honours the no_cache setting.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agochanges: add a CHANGES.md entry for the OSSL_FORCE_NO_CACHE_FETCH option.
Pauli [Mon, 8 Feb 2021 03:09:49 +0000 (13:09 +1000)]
changes: add a CHANGES.md entry for the OSSL_FORCE_NO_CACHE_FETCH option.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agotest: fix no-cache problem with the quality comparison for KDFs.
Pauli [Mon, 8 Feb 2021 02:01:20 +0000 (12:01 +1000)]
test: fix no-cache problem with the quality comparison for KDFs.

In a caching world, it's fine to compare the pointers directly.  In a
non-caching world, the names and providers need to be compared.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agoEVP: fix reference counting for EVP_CIPHER.
Pauli [Mon, 8 Feb 2021 01:38:21 +0000 (11:38 +1000)]
EVP: fix reference counting for EVP_CIPHER.

Under some circumstances, the reference count for a cipher wasn't updated
properly.  This shows up best when fetches are not being queried but would be
possible if the cache flushed at a bad time.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agoProv: add an option to force provider fetches to not be cached.
Pauli [Mon, 8 Feb 2021 01:03:01 +0000 (11:03 +1000)]
Prov: add an option to force provider fetches to not be cached.

If the macro OSSL_FORCE_NO_CACHE_FETCH is defined, no provider will have its
fetches cached.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agoCI: add a non-caching CI loop
Pauli [Mon, 8 Feb 2021 01:02:52 +0000 (11:02 +1000)]
CI: add a non-caching CI loop

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agoEVP: fix reference counting for digest operations.
Pauli [Mon, 8 Feb 2021 00:54:52 +0000 (10:54 +1000)]
EVP: fix reference counting for digest operations.

The reference count wasn't being incremented but the EVP_MD pointer was being
held.  In a no cache build, this resulted in a failure on update in some
circumstances.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14126)

3 years agoAllow -rand to be repeated
Rich Salz [Wed, 10 Feb 2021 18:33:41 +0000 (13:33 -0500)]
Allow -rand to be repeated

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14135)

3 years agoFetch cipher after loading providers
Rich Salz [Mon, 8 Feb 2021 19:20:01 +0000 (14:20 -0500)]
Fetch cipher after loading providers

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14135)

3 years agoProcess digest option after loading providers
Rich Salz [Mon, 8 Feb 2021 19:03:35 +0000 (14:03 -0500)]
Process digest option after loading providers

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14135)

3 years agoLoad rand state after loading providers
Rich Salz [Mon, 8 Feb 2021 18:45:23 +0000 (13:45 -0500)]
Load rand state after loading providers

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14135)

3 years agoFetch alg, etc., after loading providers
Rich Salz [Sun, 7 Feb 2021 15:42:23 +0000 (10:42 -0500)]
Fetch alg, etc., after loading providers

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14135)

3 years agoFetch algorithm after loading providers
Rich Salz [Fri, 5 Feb 2021 20:38:07 +0000 (15:38 -0500)]
Fetch algorithm after loading providers

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14135)

3 years agotest: add an option to output timing information from tests.
Pauli [Wed, 10 Feb 2021 22:28:41 +0000 (08:28 +1000)]
test: add an option to output timing information from tests.

Fixes #14141

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

3 years agoX509_STORE_CTX_cleanup(): Use internally so no need to call explicitly
Dr. David von Oheimb [Fri, 5 Feb 2021 20:52:01 +0000 (21:52 +0100)]
X509_STORE_CTX_cleanup(): Use internally so no need to call explicitly

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

3 years agoX509_STORE_CTX_get1_issuer(): Make preference on expired certs consistent with find_i...
Dr. David von Oheimb [Mon, 8 Feb 2021 14:27:49 +0000 (15:27 +0100)]
X509_STORE_CTX_get1_issuer(): Make preference on expired certs consistent with find_issuer()

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

3 years agox509_vfy.c: Make chain_build() error diagnostics to the point
Dr. David von Oheimb [Sat, 6 Feb 2021 20:51:55 +0000 (21:51 +0100)]
x509_vfy.c: Make chain_build() error diagnostics to the point

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14094)

3 years agoRename internal providercommonerr.h to less mouthful proverr.h
Tomas Mraz [Tue, 9 Feb 2021 12:25:16 +0000 (13:25 +0100)]
Rename internal providercommonerr.h to less mouthful proverr.h

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

3 years agoVarious cleanup of PROV_R_ reason codes
Tomas Mraz [Fri, 5 Feb 2021 17:51:37 +0000 (18:51 +0100)]
Various cleanup of PROV_R_ reason codes

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

3 years agoMove the PROV_R reason codes to a public header
Tomas Mraz [Fri, 5 Feb 2021 16:40:42 +0000 (17:40 +0100)]
Move the PROV_R reason codes to a public header

The PROV_R codes can be returned to applications so it is useful
to have some common set of provider reason codes for the applications
or third party providers.

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

3 years agoMatch description with actual output of dgst
KOBAYASHI Ittoku [Sat, 6 Feb 2021 02:59:12 +0000 (11:59 +0900)]
Match description with actual output of dgst

CLA: trivial

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14089)

3 years agoinclude/internal: add a few missing #pragma once directives
FdaSilvaYY [Sat, 6 Feb 2021 21:14:03 +0000 (22:14 +0100)]
include/internal: add a few missing #pragma once directives

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/14096)

3 years agoinclude/openssl: add a few missing #pragma once directives
FdaSilvaYY [Sat, 6 Feb 2021 21:13:21 +0000 (22:13 +0100)]
include/openssl: add a few missing #pragma once directives

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/14096)

3 years agoinclude/crypto: add a few missing #pragma once directives
FdaSilvaYY [Sat, 6 Feb 2021 21:36:46 +0000 (22:36 +0100)]
include/crypto: add a few missing #pragma once directives

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/14096)

3 years agotest: turn off parallel tests in verbose mode.
Pauli [Tue, 9 Feb 2021 08:32:32 +0000 (18:32 +1000)]
test: turn off parallel tests in verbose mode.

The existing code prints a warning saying that verbose mode is ignored with
parallel jobs.  This seems backward, more useful is disabling parallel jobs
when verbose is enabled.

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

3 years agoHandle partial data re-sending on ktls/sendfile on FreeBSD
Oleksandr Tymoshenko [Sun, 20 Dec 2020 19:01:53 +0000 (11:01 -0800)]
Handle partial data re-sending on ktls/sendfile on FreeBSD

Add a handler for EBUSY sendfile error in addition to
EAGAIN. With EBUSY returned the data still can be partially
sent and user code has to be notified about it, otherwise it
may try to send data multiple times.

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

3 years agoRemove unused 'peer_type' from SSL_SESSION
Benjamin Kaduk [Wed, 27 Jan 2021 20:19:08 +0000 (12:19 -0800)]
Remove unused 'peer_type' from SSL_SESSION

This field has not been used since #3858 was merged in 2017 when we
moved to a table-based lookup for certificate type properties instead of
an index-based one.

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

3 years agoReplace provider digest flags with separate param fields
Shane Lontis [Thu, 17 Dec 2020 06:42:05 +0000 (16:42 +1000)]
Replace provider digest flags with separate param fields

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13830)

3 years agoReplace provider cipher flags with separate param fields
Shane Lontis [Thu, 17 Dec 2020 06:39:57 +0000 (16:39 +1000)]
Replace provider cipher flags with separate param fields

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13830)

3 years agoReplace MAC flags OSSL_MAC_PARAM_FLAGS with separate param fields.
Shane Lontis [Mon, 14 Dec 2020 04:36:48 +0000 (14:36 +1000)]
Replace MAC flags OSSL_MAC_PARAM_FLAGS with separate param fields.

Fixes #12992

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13830)

3 years agoChange the ASN1 variant of x942kdf so that it can test acvp data.
Shane Lontis [Fri, 5 Feb 2021 07:45:39 +0000 (17:45 +1000)]
Change the ASN1 variant of x942kdf so that it can test acvp data.

This 'special' way of specifying the data should only be used for testing
purposes. It should not be used in production environments.
ACVP passes a blob of DER encoded data for some of the fields rather
than passing them as separate fields that need to be DER encoded.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14077)

3 years agox509_vfy.c: Sort out return values 0 vs. -1 (failure/internal error)
Dr. David von Oheimb [Sat, 6 Feb 2021 21:41:40 +0000 (22:41 +0100)]
x509_vfy.c: Sort out return values 0 vs. -1 (failure/internal error)

Also simplify first part of verify_chain()

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14095)

3 years agoX509_get_pubkey_parameters(): Correct failure behavior and its use
Dr. David von Oheimb [Mon, 8 Feb 2021 06:31:11 +0000 (07:31 +0100)]
X509_get_pubkey_parameters(): Correct failure behavior and its use

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14095)

3 years agox509_vfy: Clarify relevance of ctx->error also on successful verification
Dr. David von Oheimb [Mon, 8 Feb 2021 07:17:23 +0000 (08:17 +0100)]
x509_vfy: Clarify relevance of ctx->error also on successful verification

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14127)

3 years agox509_vfy.c: Fix various coding style and documentation style nits
Dr. David von Oheimb [Mon, 8 Feb 2021 07:12:15 +0000 (08:12 +0100)]
x509_vfy.c: Fix various coding style and documentation style nits

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14127)

3 years agoCHANGES.md: Mention RSA key generation slowdown related changes
Tomas Mraz [Thu, 4 Feb 2021 17:40:33 +0000 (18:40 +0100)]
CHANGES.md: Mention RSA key generation slowdown related changes

Fixes #14068

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14073)

3 years agoDeprecate BN_pseudo_rand() and BN_pseudo_rand_range()
Tomas Mraz [Thu, 4 Feb 2021 18:25:44 +0000 (19:25 +0100)]
Deprecate BN_pseudo_rand() and BN_pseudo_rand_range()

The functions are obsolete aliases for BN_rand() and BN_rand_range()
since 1.1.0.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14080)

3 years agoEnhanced integer parsing in OSSL_PARAM_allocate_from_text
Petr Gotthard [Sat, 6 Feb 2021 20:47:20 +0000 (21:47 +0100)]
Enhanced integer parsing in OSSL_PARAM_allocate_from_text

Fixes #14041 and additional bugs discovered by the newly created
tests.

This patch:
 - Introduces support for 0x prefixed integers
 - Fixes parsing of negative integers (negative numbers were
   shifted by -2)
 - Fixes ability to parse maximal unsigned numbers ("too small
   buffer" error used to be reported incorrectly)
 - Fixes a memory leak when OSSL_PARAM_allocate_from_text fails
   leaving a temporary BN allocated

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

3 years agoConfiguration: ensure that 'no-tests' works correctly
Richard Levitte [Fri, 5 Feb 2021 14:39:32 +0000 (15:39 +0100)]
Configuration: ensure that 'no-tests' works correctly

'no-tests' wasn't entirely respected when specifying subdirs in the
top build.info.

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

3 years agoEnable fipsload test on NonStop x86.
Randall S. Becker [Thu, 28 Jan 2021 18:05:02 +0000 (11:05 -0700)]
Enable fipsload test on NonStop x86.

CLA: Trivial

Fixes: #14005
Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14006)

3 years agomknum.pl: Exclude duplicate entries and include source file name in diagnostics
Dr. David von Oheimb [Thu, 4 Feb 2021 14:58:51 +0000 (15:58 +0100)]
mknum.pl: Exclude duplicate entries and include source file name in diagnostics

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

3 years agoSimplify the EVP_PKEY_XXX_fromdata_XX methods.
Shane Lontis [Fri, 5 Feb 2021 03:55:50 +0000 (13:55 +1000)]
Simplify the EVP_PKEY_XXX_fromdata_XX methods.

The existing names such as EVP_PKEY_param_fromdata_settable were a bit
confusing since the 'param' referred to key params not OSSL_PARAM. To simplify
the interface a 'selection' parameter will be passed instead. The
changes are:

(1) EVP_PKEY_fromdata_init() replaces both EVP_PKEY_key_fromdata_init() and EVP_PKEY_param_fromdata_init().
(2) EVP_PKEY_fromdata() has an additional selection parameter.
(3) EVP_PKEY_fromdata_settable() replaces EVP_PKEY_key_fromdata_settable() and EVP_PKEY_param_fromdata_settable().
    EVP_PKEY_fromdata_settable() also uses a selection parameter.

Fixes #12989

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

3 years agoFix race condition & allow operation cache to grow.
Pauli [Thu, 4 Feb 2021 04:40:19 +0000 (14:40 +1000)]
Fix race condition & allow operation cache to grow.

This fixes a race condition where the index to the cache location was found
under a read lock and a later write lock set the cache entry.  The issue being
that two threads could get the same location index and then fight each other
over writing the cache entry.  The most likely outcome is a memory leak,
however it would be possible to set up an invalid cache entry.

The operation cache was a fixed sized array, once full an assertion failed.
The other fix here is to convert this to a stack.  The code is simplified and
it avoids a cache overflow condition.

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

3 years agoAdd X509_STORE_CTX_verify(), which takes the first untrusted cert as default target
Dr. David von Oheimb [Wed, 27 Jan 2021 23:28:25 +0000 (00:28 +0100)]
Add X509_STORE_CTX_verify(), which takes the first untrusted cert as default target

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

3 years agoPROV: Fix encoding of MDWithRSAEncryption signature AlgorithmID
Richard Levitte [Sun, 31 Jan 2021 22:15:08 +0000 (23:15 +0100)]
PROV: Fix encoding of MDWithRSAEncryption signature AlgorithmID

All {MD}WithRSAEncryption signature AlgorithmID have the parameters
being NULL, according to PKCS#1.  We didn't.  Now corrected.

This bug was the topic of this thread on openssl-users@openssl.org:
https://mta.openssl.org/pipermail/openssl-users/2021-January/013416.html

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

3 years agoFix the cipher_overhead_test
Matt Caswell [Mon, 1 Feb 2021 15:15:10 +0000 (15:15 +0000)]
Fix the cipher_overhead_test

Now that libssl no longer has any OPENSSL_NO_ALG guards the internal
cipher_overhead_test wasn't quite handling disabled ciphers correctly.

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

3 years agoRemove all OPENSSL_NO_XXX from libssl where XXX is a crypto alg
Matt Caswell [Wed, 20 Jan 2021 15:29:59 +0000 (15:29 +0000)]
Remove all OPENSSL_NO_XXX from libssl where XXX is a crypto alg

We should no longer be relying on compile time checks in libssl for
the availability of crypto algorithms. The availability of crypto
algorithms should be determined at runtime based on what providers have
been loaded.

Fixes #13616

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

3 years agoRemove OPENSSL_NO_EC guards from libssl
Matt Caswell [Fri, 15 Jan 2021 16:54:28 +0000 (16:54 +0000)]
Remove OPENSSL_NO_EC guards from libssl

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

3 years agoMake sure we don't use sigalgs that are not available
Matt Caswell [Wed, 20 Jan 2021 15:09:24 +0000 (15:09 +0000)]
Make sure we don't use sigalgs that are not available

We may have compiled in sigalg values that we can't support at runtime.
Make sure we only use sigalgs that are actually enabled.

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

3 years agoAdd the nist group names as aliases for the normal TLS group names
Matt Caswell [Wed, 20 Jan 2021 12:38:43 +0000 (12:38 +0000)]
Add the nist group names as aliases for the normal TLS group names

By recognising the nist group names directly we can avoid having to call
EC_curve_nist2nid in libssl, which is not available in a no-ec build.

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

3 years agoRemove compile time guard checking from ssl3_get_req_cert_type
Matt Caswell [Fri, 15 Jan 2021 16:10:52 +0000 (16:10 +0000)]
Remove compile time guard checking from ssl3_get_req_cert_type

With 3.0 we need to know whether algs are available at run time not
at compile time. Actually the code as written is sufficient to do this,
so we can simply remove the guards.

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

3 years agoCheck for availability of ciphersuites at run time
Matt Caswell [Fri, 15 Jan 2021 15:43:28 +0000 (15:43 +0000)]
Check for availability of ciphersuites at run time

In 1.1.1 and below we would check for the availability of certain
algorithms based on compile time guards. However with 3.0 this is no
longer sufficient. Some algorithms that are unavailable at compile time
may become available later if 3rd party providers are loaded. Similarly,
algorithms that exist in our built-in providers at compile time may not
be available at run time if those providers are not loaded.

Fixes #13184

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

3 years agoStop disabling TLSv1.3 if ec and dh are disabled
Matt Caswell [Thu, 14 Jan 2021 15:50:20 +0000 (15:50 +0000)]
Stop disabling TLSv1.3 if ec and dh are disabled

Even if EC and DH are disabled then we may still be able to use TLSv1.3
if we have groups that have been plugged in by an external provider.

Fixes #13767

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

3 years agoMake supported_groups code independent of EC and DH
Matt Caswell [Wed, 13 Jan 2021 17:27:10 +0000 (17:27 +0000)]
Make supported_groups code independent of EC and DH

The supported groups code was checking the OPENSSL_NO_EC and
OPENSSL_NO_DH guards in order to work, and the list of default groups was
based on those guards. However we now need it to work even in a no-ec
and no-dh build, because new groups might be added from providers.

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

3 years agoEnsure default supported groups works even with no-ec and no-dh
Matt Caswell [Wed, 13 Jan 2021 15:50:36 +0000 (15:50 +0000)]
Ensure default supported groups works even with no-ec and no-dh

The default supported groups code was disabled in the event of a build
with no-ec and no-dh. However now that providers can add there own
groups (which might not fit into either of these categories), this is
no longer appropriate.

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

3 years agoRemove OPENSSL_NO_DH guards from libssl
Matt Caswell [Wed, 13 Jan 2021 12:39:40 +0000 (12:39 +0000)]
Remove OPENSSL_NO_DH guards from libssl

This removes man unnecessary OPENSSL_NO_DH guards from libssl. Now that
libssl is entirely using the EVP APIs and implementations can be plugged
in via providers it is no longer needed to disable DH at compile time in
libssl. Instead it should detect at runtime whether DH is available from
the loaded providers.

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

3 years agoMakefile template: Allow separate generation of .pod.in -> .pod
Richard Levitte [Thu, 4 Feb 2021 14:32:37 +0000 (15:32 +0100)]
Makefile template: Allow separate generation of .pod.in -> .pod

We do this by adding the attribute 'pod' to all .pod.in -> .pod
generations, like this:

    DEPEND[NAME.pod]{pod}=NAME.pod.in,

...  and selecting out the target files for those dependencies into a
dedicated target 'build_generated_pods', which the 'doc-nits' and
'cmd-nits' make targets are made to depend on.

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

3 years agoDOCS: Remove the "global" dependency on writing .pod files from .pod.in
Richard Levitte [Thu, 4 Feb 2021 11:58:35 +0000 (12:58 +0100)]
DOCS: Remove the "global" dependency on writing .pod files from .pod.in

The dependency was made in such a way that .pod.in -> .pod generation
would always be done, no matter what.  This changes the procedure so
that the generation is made "on demand", i.e. when the resulting .pod
files are needed.

This turned out to be duplicated dependencies, as the .pod -> .pod.in
dependencies were already in place.  Just removing the duplicate fixes
the situation.

'make build_all_generated' still works, for those who do want to have
all file generations performed.  (as a reminder, this is suitable to
generate the files a fast system and then copy the result to a slower
system, or system where there's no perl)

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

3 years agoTEST: Add an algorithm ID tester for libcrypto vs provider
Richard Levitte [Tue, 2 Feb 2021 14:13:08 +0000 (15:13 +0100)]
TEST: Add an algorithm ID tester for libcrypto vs provider

Providers produce algorithm IDs of their own, and we need to compare
them against the same thing produced by libcrypto's ASN.1 code and
with legacy keys.

This tester can compare algorithm IDs for signatures and for keys,
given certificates that hold such data.

To verify key algorithm IDs, only one certificate is necessary, and
its public key is used.

To verify certificate algorithm IDs, we need to launch the signature
operation that would verify a certificate against the public key of
its signing CA, so that test needs two files.

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

3 years agoEVP: use evp_pkey_copy_downgraded() in EVP_PKEY_copy_parameters()
Richard Levitte [Sat, 7 Nov 2020 10:31:35 +0000 (11:31 +0100)]
EVP: use evp_pkey_copy_downgraded() in EVP_PKEY_copy_parameters()

We used evp_pkey_downgrade() on 'from', which permanently converts 'from'
to have a legacy internal key.  Now that we have evp_pkey_copy_downgraded(),
it's better to use that (and thereby restore the constness contract).

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

3 years agodev/release.sh: Fix typo
Richard Levitte [Mon, 9 Nov 2020 07:39:39 +0000 (08:39 +0100)]
dev/release.sh: Fix typo

tagley -> tagkey

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/14061)

3 years agoRemove the old DEPRECATEDIN macros
Richard Levitte [Fri, 20 Nov 2020 10:07:35 +0000 (11:07 +0100)]
Remove the old DEPRECATEDIN macros

They serve no purpose any more

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

3 years agoERR: Rebuild all generated error headers and source files
Richard Levitte [Thu, 12 Nov 2020 10:36:38 +0000 (11:36 +0100)]
ERR: Rebuild all generated error headers and source files

This is the result of 'make errors ERROR_REBUILD=-rebuild'

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

3 years agoERR: clean away everything related to _F_ macros from util/mkerr.pl
Richard Levitte [Thu, 12 Nov 2020 08:21:05 +0000 (09:21 +0100)]
ERR: clean away everything related to _F_ macros from util/mkerr.pl

Instead, we preserve all the pre-3.0 _F_ macros in the backward
compatibility headers include/openssl/cryptoerr_legacy.h and
include/openssl/sslerr_legacy.h

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

3 years agoRSA: properly generate algorithm identifier for RSA-PSS signatures
Tomas Mraz [Fri, 29 Jan 2021 16:02:32 +0000 (17:02 +0100)]
RSA: properly generate algorithm identifier for RSA-PSS signatures

Fixes #13969

- properly handle the mandatory RSA-PSS key parameters
- improve parameter checking when setting the parameters
- compute the algorithm id at the time it is requested so it
  reflects the actual parameters set
- when generating keys do not override previously set parameters
  with defaults
- tests added to the test_req recipe that should cover the PSS signature
  handling

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

3 years agoprovider-signature.pod: Fix formatting.
Tomas Mraz [Wed, 27 Jan 2021 09:22:41 +0000 (10:22 +0100)]
provider-signature.pod: Fix formatting.

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

3 years agoDon't make pthreads mutexes recursive.
Rich Salz [Thu, 21 Jan 2021 17:32:27 +0000 (12:32 -0500)]
Don't make pthreads mutexes recursive.

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

3 years agoSwitch to BIO_snprintf to avoid missing symbol problems on Windows
Jon Spillett [Thu, 4 Feb 2021 05:13:18 +0000 (15:13 +1000)]
Switch to BIO_snprintf to avoid missing symbol problems on Windows

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14063)

3 years agoEVP: Adapt EVP_PKEY_{set1,get1}_encoded_public_key()
Richard Levitte [Wed, 3 Feb 2021 15:48:21 +0000 (16:48 +0100)]
EVP: Adapt EVP_PKEY_{set1,get1}_encoded_public_key()

These functions are modified to use EVP_PKEY_set_octet_string_param()
and EVP_PKEY_get_octet_string_param() instead of evp_keymgmt_set_params()
and evp_keymgmt_get_params().
To accomplish this fully, EVP_PKEY_get_octet_string_param() is changed
slightly to populate |*out_sz| with the return size, even if getting
the params resulted in an error.

We also modify EVP_PKEY_get_utf8_string_param() to match
EVP_PKEY_get_octet_string_param()

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14056)

3 years agoEVP: Modify the checks in EVP_PKEY_{set,get}_xxx_param() functions
Richard Levitte [Wed, 3 Feb 2021 13:10:08 +0000 (14:10 +0100)]
EVP: Modify the checks in EVP_PKEY_{set,get}_xxx_param() functions

The checks of the type of EVP_PKEY were from before we had the macro
evp_pkey_is_provided().

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14056)

3 years agoEVP: Adapt the other EVP_PKEY_set_xxx_param() functions
Richard Levitte [Wed, 3 Feb 2021 12:55:30 +0000 (13:55 +0100)]
EVP: Adapt the other EVP_PKEY_set_xxx_param() functions

They were calling evp_keymgmt_set_params() directly.  Those calls are
changed to go through EVP_PKEY_set_params().

We take the opportunity to constify these functions.  They have to
unconstify internally for the compiler to stop complaining when
placing those pointers in an OSSL_PARAM element, but that's still
better than forcing the callers to do that cast.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14056)

3 years agoEVP: Make EVP_PKEY_set_params() increment the dirty count
Richard Levitte [Wed, 3 Feb 2021 12:50:23 +0000 (13:50 +0100)]
EVP: Make EVP_PKEY_set_params() increment the dirty count

When the internal key is changed, we must count it as muted, so that
next time the affected key is considered for an operation, it gets
re-exported to the signing provider.  In other words, this will clear
the EVP_PKEY export cache when the next export attempt occurs.

This also updates evp_keymgmt_util_export_to_provider() to actually
look at the dirty count for provider native origin keys, and act
appropriately.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14056)

3 years agoapps/openssl: add -propquery command line option
Petr Gotthard [Sat, 26 Dec 2020 20:32:14 +0000 (21:32 +0100)]
apps/openssl: add -propquery command line option

Fixes #13656. Right now all openssl commands use a NULL propq. This
patch adds a possibility to specify a custom propq.

The implementation follows the example of set_nameopt/get_nameopt.

Various tools had to be modified to call app_get0_propq after it has
been populated. Otherwise the -propquery has no effect.

The tests then verify the -propquery affects the tool behaviour by
requesting a non-existing property.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13707)

3 years agox509_vfy.c: Improve coding style and comments all over the file
Dr. David von Oheimb [Sun, 4 Oct 2020 19:55:49 +0000 (21:55 +0200)]
x509_vfy.c: Improve coding style and comments all over the file

No changes in semantics.

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

3 years agoRemove a DSA related TODO
Matt Caswell [Mon, 1 Feb 2021 17:31:05 +0000 (17:31 +0000)]
Remove a DSA related TODO

There are no instances of the macros that this comment is referring to
being used anywhere within current master. All of the macros were
deprecated by commit f41ac0e. Therefore this TODO should just be removed.

Fixes #13020

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14038)

3 years agoRemove some TODO(OpenSSL1.2) references
Matt Caswell [Mon, 1 Feb 2021 15:45:44 +0000 (15:45 +0000)]
Remove some TODO(OpenSSL1.2) references

We had a couple of stray references to OpenSSL1.2 in libssl. We just
reword the comments to remove those references without changing any
behaviour.

The first one in t1_lib.c is a technical non-compliance in the TLSv1.3
spec where, under some circumstances, we offer DSA sigalgs even in a
ClientHello that eventually negotiates TLSv1.3. We explicitly chose to
accept this behaviour in 1.1.1 and we're not planning to change it for
3.0.

The second one in s3_lib.c is regarnding the behaviour of
SSL_set_tlsext_host_name(). Technically you shouldn't be able to call
this from a server - but we allow it and just ignore it rather than
raising an error. The TODO suggest we consider raising an error instead.
However, with 3.0 we are trying to minimise breaking changes so I suggest
not making this change now.

Fixes #13161

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

3 years agoDH/DHX parameter check using pkeyparam
Dmitry Belyavskiy [Fri, 22 Jan 2021 13:54:09 +0000 (14:54 +0100)]
DH/DHX parameter check using pkeyparam

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13930)

3 years agoAllow NULL arg to OPENSSL_sk_{dup,deep_copy} returning empty stack
Dr. David von Oheimb [Wed, 23 Dec 2020 18:33:03 +0000 (19:33 +0100)]
Allow NULL arg to OPENSSL_sk_{dup,deep_copy} returning empty stack

This simplifies many usages

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

3 years agorun_tests.pl: Improve diagnostics on the use of HARNESS_JOBS
Dr. David von Oheimb [Wed, 2 Dec 2020 08:05:22 +0000 (09:05 +0100)]
run_tests.pl: Improve diagnostics on the use of HARNESS_JOBS

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

3 years agotest/recipes: split 81_test_cmp_cli.t, add test using -engine loader_attic
Dr. David von Oheimb [Fri, 27 Nov 2020 09:08:31 +0000 (10:08 +0100)]
test/recipes: split 81_test_cmp_cli.t, add test using -engine loader_attic

The HTTP-based tests are now in 80_test_cmp_http.t, to start a little earlier.
This should decrease total test run time due to better parallelization.

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

3 years agoapps/cmp.c: check and exit on engine load error
Dr. David von Oheimb [Fri, 27 Nov 2020 19:45:21 +0000 (20:45 +0100)]
apps/cmp.c: check and exit on engine load error

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

3 years agoopenssl.pod: Add documentation for using the loader_attic engine
Dr. David von Oheimb [Fri, 27 Nov 2020 13:09:22 +0000 (14:09 +0100)]
openssl.pod: Add documentation for using the loader_attic engine

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

3 years agoFix a use after free issue when a provider context is being used and isn't cached
Pauli [Wed, 3 Feb 2021 07:47:38 +0000 (17:47 +1000)]
Fix a use after free issue when a provider context is being used and isn't cached

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

3 years agoEC: Reverse the default asn1_flag in a new EC_GROUP
Richard Levitte [Wed, 27 Jan 2021 13:55:28 +0000 (14:55 +0100)]
EC: Reverse the default asn1_flag in a new EC_GROUP

The default was OPENSSL_EC_NAMED_CURVE, but that's not true until a
curve name has been set, so we change the initial value to
OPENSSL_EC_EXPLICIT_CURVE and let EC_GROUP_set_curve_name() change it
to OPENSSL_EC_NAMED_CURVE.

Submitted by Matt Caswell

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13973)

3 years agoEVP: Fix evp_pkey_ctx_store_cached_data() to handle provider backed EVP_PKEY_CTX
Richard Levitte [Wed, 27 Jan 2021 10:07:38 +0000 (11:07 +0100)]
EVP: Fix evp_pkey_ctx_store_cached_data() to handle provider backed EVP_PKEY_CTX

It assumed there would always be a non-NULL ctx->pmeth, leading to a
crash when that isn't the case.  Since it needs to check 'keytype'
when that one isn't -1, we also add a corresponding check for the
provider backed EVP_PKEY_CTX case.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13973)

3 years agoEVP: Don't find standard EVP_PKEY_METHODs automatically
Richard Levitte [Tue, 26 Jan 2021 16:01:15 +0000 (17:01 +0100)]
EVP: Don't find standard EVP_PKEY_METHODs automatically

EVP_PKEY_meth_find() got called automatically any time a new
EVP_PKEY_CTX allocator was called with some sort of key type data.
Since we have now moved all our standard algorithms to our providers,
this is no longer necessary.

We do retain looking up EVP_PKEY_METHODs that are added by the calling
application.

Fixes #11424

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13973)

3 years agoCORE & PROV: clean away OSSL_FUNC_mac_size()
Richard Levitte [Tue, 2 Feb 2021 12:42:55 +0000 (13:42 +0100)]
CORE & PROV: clean away OSSL_FUNC_mac_size()

There was a remaining function signature declaration, but no
OSSL_DISPATCH number for it nor any way it's ever used.  It did exist
once, but was replaced with an OSSL_PARAM item to retrieve.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14048)

3 years agoapps/ecparam: Avoid crash when parameters fail to load
Tomas Mraz [Mon, 1 Feb 2021 14:15:43 +0000 (15:15 +0100)]
apps/ecparam: Avoid crash when parameters fail to load

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14043)

3 years agoapps/ca: Properly handle certificate expiration times in do_updatedb
Armin Fuerst [Fri, 29 Jan 2021 18:16:14 +0000 (19:16 +0100)]
apps/ca: Properly handle certificate expiration times in do_updatedb

Fixes #13944

   + changed ASN1_UTCTIME to ASN1_TIME
   + removed all Y2K code from do_updatedb
   + changed compare to ASN1_TIME_compare

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14026)

(cherry picked from commit dabea5447dc487983a50a40856f731db0db17a8e)

3 years agoDeprecate EVP_MD_CTX_{set_}update_fn()
Rich Salz [Thu, 28 Jan 2021 20:47:53 +0000 (15:47 -0500)]
Deprecate EVP_MD_CTX_{set_}update_fn()

They are still used internally in legacy code.

Also fixed up some minor things in EVP_DigestInit.pod

Fixes: #14003
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14008)

3 years agoAdd diacritics to my name in CHANGES.md
Tomas Mraz [Mon, 1 Feb 2021 21:07:17 +0000 (22:07 +0100)]
Add diacritics to my name in CHANGES.md

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

3 years agodh_cms_set_peerkey: Pad the public key to p size
Tomas Mraz [Mon, 25 Jan 2021 18:12:43 +0000 (19:12 +0100)]
dh_cms_set_peerkey: Pad the public key to p size

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

3 years agoAdd some missing committers to the AUTHORS list
Dr. Matthias St. Pierre [Sun, 31 Jan 2021 21:08:33 +0000 (22:08 +0100)]
Add some missing committers to the AUTHORS list

Fixes #13815

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

3 years agoAdd a CI job to run the threads test with threads sanitizer on
Matt Caswell [Wed, 27 Jan 2021 17:23:13 +0000 (17:23 +0000)]
Add a CI job to run the threads test with threads sanitizer on

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13987)

3 years agoEnsure the EVP_PKEY operation_cache is appropriately locked
Matt Caswell [Wed, 27 Jan 2021 17:18:27 +0000 (17:18 +0000)]
Ensure the EVP_PKEY operation_cache is appropriately locked

The EVP_PKEY operation_cache caches references to provider side key
objects that have previously been exported for this EVP_PKEY, and their
associated key managers. The cache may be updated from time to time as the
EVP_PKEY is exported to more providers. Since an EVP_PKEY may be shared by
multiple threads simultaneously we must be careful to ensure the cache
updates are locked.

Fixes #13818

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13987)

3 years agoEnsure access to FIPS_state and rate_limit is appropriately locked
Matt Caswell [Wed, 27 Jan 2021 15:51:48 +0000 (15:51 +0000)]
Ensure access to FIPS_state and rate_limit is appropriately locked

These variables can be accessed concurrently from multiple threads so
we ensure that we properly lock them before read or write.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13987)

3 years agoAlways ensure we hold ctx->lock when calling CRYPTO_get_ex_data()
Matt Caswell [Tue, 26 Jan 2021 17:00:25 +0000 (17:00 +0000)]
Always ensure we hold ctx->lock when calling CRYPTO_get_ex_data()

Otherwise we can get data races.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13987)

3 years agoAvoid races by caching exported ciphers in the init function
Matt Caswell [Tue, 26 Jan 2021 15:23:19 +0000 (15:23 +0000)]
Avoid races by caching exported ciphers in the init function

TSAN was reporting a race of the exported ciphers cache that we create in
the default and fips providers. This was because we cached it in the query
function rather than the init function, so this would cause a race if multiple
threads queried at the same time. In practice it probably wouldn't make much
difference since different threads should come up with the same answer.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13987)

3 years agoRefactor RAND_get0_primary() locking
Matt Caswell [Tue, 26 Jan 2021 15:14:02 +0000 (15:14 +0000)]
Refactor RAND_get0_primary() locking

Make sure we never read or write to dgbl->primary outside of a lock.

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13987)