oweals/openssl.git
4 years agoInitialize files that declare internal symbols
Richard Levitte [Mon, 6 Apr 2020 11:58:41 +0000 (13:58 +0200)]
Initialize files that declare internal symbols

util/other-internal.syms is like util/other.syms, but for internal symbols.
Likewise, util/missingcrypto-internal.txt and util/missingssl-internal.txt
are like util/missingcrypto.txt and util/missingssl.txt

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

4 years agoRework util/find-doc-nits to distinguish internal documentation
Richard Levitte [Mon, 6 Apr 2020 11:51:36 +0000 (13:51 +0200)]
Rework util/find-doc-nits to distinguish internal documentation

We didn't really distinguish internal and public documentation, or
matched that with the state of the documented symbols.  we therefore
needed to rework the logic to account for the state of each symbol.

To simplify things, and make them consistent, we load all of
util/*.num, util/*.syms and util/missing*.txt unconditionally.

Also, we rework the reading of the manuals to happen only once (or
well, not quite, Pod::Checker reads from file too, but at the very
least, our script isn't reading the same file multiple times).

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

4 years agoAdd manpage entry for X509_check_purpose()
Jake Maynard [Wed, 30 Oct 2019 15:27:04 +0000 (11:27 -0400)]
Add manpage entry for X509_check_purpose()

Fixes #10263

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

4 years agoFix EVP_DigestSign interface when used with DES CMAC
Patrick Steuer [Thu, 9 Apr 2020 17:58:02 +0000 (19:58 +0200)]
Fix EVP_DigestSign interface when used with DES CMAC

DES implementations were missing the dup/copy ctx routines
required by CMAC implementation. A regression test is added.

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11498)

4 years agoEVP: legacy_ctrl_to_param() to handle provider side keys
Richard Levitte [Thu, 9 Apr 2020 04:07:54 +0000 (06:07 +0200)]
EVP: legacy_ctrl_to_param() to handle provider side keys

There was one spot where this function would look at ctx->pmeth
directly to determine if it's for RSASSA-PSS, which fails when
presented with an EVP_PKEY_CTX holding a provider side key.
Switching to use EVP_PKEY_is_a() should make things better.

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

4 years agoCMS KARI: Temporarly downgrade newly generated EVP_PKEYs to legacy
Richard Levitte [Wed, 8 Apr 2020 13:41:05 +0000 (15:41 +0200)]
CMS KARI: Temporarly downgrade newly generated EVP_PKEYs to legacy

The EVP_PKEY_ASN1_METHOD code used by CMS_RecipientInfo_kari_decrypt()
and cms_RecipientInfo_kari_encrypt() is quite complex and needs more
careful thought to work with provider side keys.  Unfortunately, we
need to get key generation in place, among others for ECC keys, so we
add a temporary hack, similar to what's already done in TLS code, that
downgrades a provider side EVP_PKEY to become EVP_PKEY_ASN1_METHOD /
EVP_PKEY_METHOD based.

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

4 years agoDon't compile commands if disabled
Rich Salz [Wed, 4 Mar 2020 21:52:22 +0000 (16:52 -0500)]
Don't compile commands if disabled

Rather than wrapping whole files in "ifndef OPENSSL_NO_xxx" we handle
the changes in build.info

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

4 years agoFix krb5 external test
Benjamin Kaduk [Wed, 8 Apr 2020 17:05:27 +0000 (10:05 -0700)]
Fix krb5 external test

Since commit c3845ceba84aab9ddeb43f043549238fd10de63b ("Build file
templates: don't set OPENSSL_{ENGINES,MODULES}") the krb5 external test
has been failing.  This is because it relied on OPENSSL_MODULES already
being set -- even though it did assign to OPENSSL_MODULES itself (and
thus got skipped by the cleanup pass in that commit), it was doing so
only to canonicalize the existing value to an absolute path, not as a de
novo assignment.

Catch up to the rest of the tree and just set it directly as the
"providers" path from the build top (but still canonicalized to an
absolute path).

[extended tests]

Fixes: 11492

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

4 years agoAdd common internal crypto/ modules in liblegacy.a
Richard Levitte [Thu, 9 Apr 2020 10:49:23 +0000 (12:49 +0200)]
Add common internal crypto/ modules in liblegacy.a

Just as for the FIPS module, there's code in the legacy module that need
this.

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

4 years agoEnable Ed25519 signing/verifying to use the libctx
Matt Caswell [Tue, 7 Apr 2020 10:10:02 +0000 (11:10 +0100)]
Enable Ed25519 signing/verifying to use the libctx

Ed25519 needs to fetch a digest and so needs to use the correct libctx.

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

4 years agoAdd the auto generated der files to .gitignore
Matt Caswell [Wed, 8 Apr 2020 11:14:41 +0000 (12:14 +0100)]
Add the auto generated der files to .gitignore

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

4 years agoDocument the new library context aware CT functions
Matt Caswell [Tue, 7 Apr 2020 16:37:39 +0000 (17:37 +0100)]
Document the new library context aware CT functions

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

4 years agoEnsure libssl uses the new library context aware CT code
Matt Caswell [Fri, 3 Apr 2020 15:26:28 +0000 (16:26 +0100)]
Ensure libssl uses the new library context aware CT code

Ensure that when we create a CTLOG_STORE we use the new library context
aware function.

Also ensure that when we create a CT_POLICY_EVAL_CTX we associate it with
the library context.

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

4 years agoMake the CT code library context aware
Matt Caswell [Fri, 3 Apr 2020 15:25:18 +0000 (16:25 +0100)]
Make the CT code library context aware

Add the new functions CTLOG_STORE_new_with_libctx(),
CTLOG_new_with_libctx() and CTLOG_new_from_base64_with_libctx() to pass
in the library context/property query string to use a library context
is to be used.

We also add the function CT_POLICY_EVAL_CTX_new_with_libctx() to enable
the creation of a CT_POLICY_EVAL_CTX to be associated with a libctx and
property query string.

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

4 years agoEnable export_to functions to have access to the libctx
Matt Caswell [Mon, 6 Apr 2020 15:05:24 +0000 (16:05 +0100)]
Enable export_to functions to have access to the libctx

The EC export_to function calls EC_POINT_point2buf that can later
generate a random number in some circumstances. Therefore we pass in a
BN_CTX associated with the library context. This means we have to change
the export_to function signature to accept the library context.

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

4 years agoOpenSSL::OID: Don't use List::Util
Richard Levitte [Thu, 9 Apr 2020 10:10:24 +0000 (12:10 +0200)]
OpenSSL::OID: Don't use List::Util

It turns out that the pairwise functions of List::Util came into perl
far later than 5.10.0.  We can't use that under those conditions, so
must revert to a quick internal implementation of the functions we're
after.

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

4 years agoUpdate RAND_METHOD definition in man page
Jim Newsome [Tue, 7 Apr 2020 21:29:53 +0000 (16:29 -0500)]
Update RAND_METHOD definition in man page

The `add` and `seed` callbacks were changed to return `int` instead of
`void` in b6dcdbfc94c482f6c15ba725754fc9e827e41851 (first included in
tag OpenSSL_1_1_0-pre1).

The `add` callback was changed to take a `double` instead of an `int`
in 853f757ecea74a271a7c5cdee3f3b5fe0d3ae863.

CLA: trivial
Fixes: #10199

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/11486)

4 years agoTravis build matrix adjustments
Tomas Mraz [Fri, 3 Apr 2020 15:26:57 +0000 (17:26 +0200)]
Travis build matrix adjustments

- do not exclude all clang builds on Linux
- exclude the constantly timeouting -fsanitize=address build on OS/X
- drop some mostly duplicate builds
- change the base linux distro to Bionic
- drop sudo as that is no longer needed - always on
- drop -D__NO_STRING_INLINES where not needed
- memleak test is not working with old clang

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

4 years agoAdd a null provider which implements no algorithms.
Pauli [Wed, 8 Apr 2020 02:02:34 +0000 (12:02 +1000)]
Add a null provider which implements no algorithms.

By loading the null provider into the default context, it is possible
to verify that it is not accidentally being used.

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

4 years agoMove legacy ciphers into the legacy provider
Shane Lontis [Thu, 9 Apr 2020 02:47:46 +0000 (12:47 +1000)]
Move legacy ciphers into the legacy provider

DES, idea, seed, rc2, rc4, rc5, cast and blowfish have been moved out of the default provider.
Code shared between desx and tdes has been moved into a seperate file (cipher_tdes_common.c).
3 test recipes failed due to using app/openssl calls that used legacy ciphers.
These calls have been updated to supply both the default and legacy providers.
Fixed openssl app '-provider' memory leak

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

4 years agoDocument the new X509_STORE_CTX_new_with_libctx() function
Matt Caswell [Wed, 1 Apr 2020 15:15:39 +0000 (16:15 +0100)]
Document the new X509_STORE_CTX_new_with_libctx() function

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

4 years agoExplicitly cache the X509v3_extensions in one more place in libssl
Matt Caswell [Wed, 1 Apr 2020 15:10:08 +0000 (16:10 +0100)]
Explicitly cache the X509v3_extensions in one more place in libssl

Make sure we cache the extensions for a cert using the right libctx.

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

4 years agoUse the libctx and propq from the X509_STORE_CTX
Matt Caswell [Wed, 1 Apr 2020 15:09:05 +0000 (16:09 +0100)]
Use the libctx and propq from the X509_STORE_CTX

Now that X509_STORE_CTX contain a libctx we should use it in a couple of
places where we cache the X509v3 extensions.

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

4 years agoUse X509_STORE_CTX_new_with_libctx() in libssl
Matt Caswell [Wed, 1 Apr 2020 15:05:07 +0000 (16:05 +0100)]
Use X509_STORE_CTX_new_with_libctx() in libssl

Libssl is OPENSSL_CTX aware so we should use it when creating an
X509_STORE_CTX.

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

4 years agoAdd X509_STORE_CTX_new_with_libctx()
Matt Caswell [Wed, 1 Apr 2020 15:03:44 +0000 (16:03 +0100)]
Add X509_STORE_CTX_new_with_libctx()

Make it possible to create an X509_STORE_CTX with an associated libctx
and propq.

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

4 years agoTLS: Temporarly downgrade newly generated EVP_PKEYs to legacy
Richard Levitte [Mon, 23 Mar 2020 12:21:21 +0000 (13:21 +0100)]
TLS: Temporarly downgrade newly generated EVP_PKEYs to legacy

The transfer of TLS encodedpoint to backends isn't yet fully supported
in provider implementations.  This is a temporary measure so as not to
get stuck in other development.

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

4 years agoFix export of provided EC keys
Richard Levitte [Mon, 23 Mar 2020 12:19:40 +0000 (13:19 +0100)]
Fix export of provided EC keys

The exporter freed a buffer too soon, and there were attempts to use
its data later, which was overwritten by something else at that
point.

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

4 years agoEVP & TLS: Add necessary EC_KEY data extraction functions, and use them
Richard Levitte [Wed, 18 Mar 2020 14:54:47 +0000 (15:54 +0100)]
EVP & TLS: Add necessary EC_KEY data extraction functions, and use them

libssl code uses EVP_PKEY_get0_EC_KEY() to extract certain basic data
from the EC_KEY.  We replace that with internal EVP_PKEY functions.

This may or may not be refactored later on.

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

4 years agoEVP: add EVP_PKEY_is_a() and EVP_PKEY_can_sign()
Richard Levitte [Mon, 16 Mar 2020 17:55:32 +0000 (18:55 +0100)]
EVP: add EVP_PKEY_is_a() and EVP_PKEY_can_sign()

EVP_PKEY_is_a() is the provider side key checking function corresponding
to checking EVP_PKEY_id() or an EVP_PKEY against macros like EVP_PKEY_EC.
It also works with legacy internal keys.

We also add a warning indoc/man3/EVP_PKEY_set1_RSA.pod regarding the
reliability of certain functions that only understand legacy keys.

Finally, we take the opportunity to clean up doc/man3/EVP_PKEY_set1_RSA.pod
to better conform with man-page layout norms, see man-pages(7) on Linux.

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

4 years agoparams: add a warning about the PTR types.
Pauli [Tue, 7 Apr 2020 05:50:02 +0000 (15:50 +1000)]
params: add a warning about the PTR types.

The warning is deter the unsure -- if in doubt the PTR type is almost certainly
NOT what you should be using.

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

4 years agoAES CTR-DRGB: do not leak timing information
Patrick Steuer [Sat, 22 Feb 2020 00:20:09 +0000 (01:20 +0100)]
AES CTR-DRGB: do not leak timing information

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11147)

4 years agoInteger overflow in ASN1_STRING_set.
Pauli [Sun, 5 Apr 2020 23:23:00 +0000 (09:23 +1000)]
Integer overflow in ASN1_STRING_set.

Addressing a potential integer overflow condition.

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

4 years agoparams: avoid a core dump with a null pointer and a get string call
Pauli [Mon, 6 Apr 2020 01:53:10 +0000 (11:53 +1000)]
params: avoid a core dump with a null pointer and a get string call

Previous a get string (UTF8 or octet) params call would memcpy(2) from a NULL
pointer if the OSSL_PARAM didn't have its data field set.  This change makes
the operation fail rather than core dump and it returns to param size (if set).

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

4 years ago[crypto/ec] blind coordinates in ec_wNAF_mul for robustness
Billy Brumley [Wed, 1 Apr 2020 18:15:58 +0000 (21:15 +0300)]
[crypto/ec] blind coordinates in ec_wNAF_mul for robustness

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Nicola Tuveri <nicola.tuveri@ibm.com>
(Merged from https://github.com/openssl/openssl/pull/11439)

4 years agoFix the error handling in EC_POINTs_mul
Bernd Edlinger [Mon, 6 Apr 2020 08:41:36 +0000 (10:41 +0200)]
Fix the error handling in EC_POINTs_mul

This was pointed out by a false-positive
-fsanitizer warning ;-)

However from the cryptographical POV the
code is wrong:
A point R^0 on the wrong curve
is infinity on the wrong curve.

[extended tests]

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/11475)

4 years agoFix misleading error msg for PBM check w/o secret in OSSL_CMP_validate_msg()
Dr. David von Oheimb [Tue, 31 Mar 2020 14:04:55 +0000 (16:04 +0200)]
Fix misleading error msg for PBM check w/o secret in OSSL_CMP_validate_msg()

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/11448)

4 years agoFix error reporting glitch in X509_STORE_CTX_print_verify_cb() in t_x509.c
Dr. David von Oheimb [Tue, 31 Mar 2020 11:26:32 +0000 (13:26 +0200)]
Fix error reporting glitch in X509_STORE_CTX_print_verify_cb() in t_x509.c

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/11448)

4 years agoFix bugs in 3GPP exception checking and improve diagnostics in crypt/cmp/cmp_vfy.c
Dr. David von Oheimb [Mon, 30 Mar 2020 14:40:14 +0000 (16:40 +0200)]
Fix bugs in 3GPP exception checking and improve diagnostics in crypt/cmp/cmp_vfy.c

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/11448)

4 years agoPROV: Add DERlib support for ECDSA and EC keys
Richard Levitte [Tue, 31 Mar 2020 15:20:24 +0000 (17:20 +0200)]
PROV: Add DERlib support for ECDSA and EC keys

This replaces crypto/ec/ecdsa_aid.c with new code and generated OIDs

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

4 years agoPROV: Add DERlib support for DSA
Richard Levitte [Tue, 31 Mar 2020 15:16:59 +0000 (17:16 +0200)]
PROV: Add DERlib support for DSA

This replaces crypto/dsa/dsa_aid.c with new code and generated OIDs

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

4 years agoPROV: Add DERlib support for RSA
Richard Levitte [Tue, 31 Mar 2020 15:15:17 +0000 (17:15 +0200)]
PROV: Add DERlib support for RSA

This replaces crypto/rsa/rsa_aid.c with new code and generated OIDs

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

4 years agoPROV: Add the beginning of a DER writing library
Richard Levitte [Tue, 31 Mar 2020 14:54:43 +0000 (16:54 +0200)]
PROV: Add the beginning of a DER writing library

This library is meant to be small and quick.  It's based on WPACKET,
which was extended to support DER writing.  The way it's used is a
bit unusual, as it's used to write the structures backward into a
given buffer.  A typical quick call looks like this:

    /*
     * Fill in this structure:
     *
     * something ::= SEQUENCE {
     *     id OBJECT IDENTIFIER,
     *     x [0] INTEGER OPTIONAL,
     *     y [1] BOOLEAN OPTIONAL,
     *     n INTEGER
     * }
     */
    unsigned char buf[nnnn], *p = NULL;
    size_t encoded_len = 0;
    WPACKET pkt;
    int ok;

    ok =   WPACKET_init_der(&pkt, buf, sizeof(buf)
        && DER_w_start_sequence(&pkt, -1)
        && DER_w_bn(&pkt, -1, bn)
        && DER_w_boolean(&pkt, 1, bool)
        && DER_w_precompiled(&pkt, -1, OID, sizeof(OID))
        && DER_w_end_sequence(&pkt, -1)
        && WPACKET_finish(&pkt)
        && WPACKET_get_total_written(&pkt, &encoded_len)
        && (p = WPACKET_get_curr(&pkt)) != NULL;

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

4 years agoAdd perl support to parse and DER encode ASN.1 OID specs
Richard Levitte [Tue, 31 Mar 2020 14:42:04 +0000 (16:42 +0200)]
Add perl support to parse and DER encode ASN.1 OID specs

We have an old OID database that's not as readable as would be
desired, and we have spots with hand coded DER for well known OIDs.

The perl modules added here give enough support that we can parse
OBJECT IDENTIFIER definitions and encode them as DER.

OpenSSL::OID is a general OID parsing and encoding of ASN.1
definitions, and supports enough of the X.680 syntax to understand
what we find in RFCs and similar documents and produce the DER
encoding for them.

oids_to_c is a specialized module to convert the DER encoding from
OpenSSL::OID to C code.  This is primarily useful in file templates
that are processed with util/dofile.pl.

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

4 years agoAdd test cases for the non CA certificate with pathlen:0
Tomas Mraz [Fri, 3 Apr 2020 08:24:40 +0000 (10:24 +0200)]
Add test cases for the non CA certificate with pathlen:0

Accept verification without -x509_strict and reject it with it.

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

4 years agoSet X509_V_ERR_INVALID_EXTENSION error for invalid basic constraints
Tomas Mraz [Thu, 2 Apr 2020 15:31:21 +0000 (17:31 +0200)]
Set X509_V_ERR_INVALID_EXTENSION error for invalid basic constraints

If we encounter certificate with basic constraints CA:false,
pathlen present and X509_V_FLAG_X509_STRICT is set we set
X509_V_ERR_INVALID_EXTENSION error.

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

4 years agoAllow certificates with Basic Constraints CA:false, pathlen:0
Tomas Mraz [Thu, 2 Apr 2020 13:56:12 +0000 (15:56 +0200)]
Allow certificates with Basic Constraints CA:false, pathlen:0

Do not mark such certificates with EXFLAG_INVALID although they
violate the RFC 5280, they are syntactically correct and
openssl itself can produce such certificates without any errors
with command such as:

openssl x509 -req -signkey private.pem -in csr.pem -out cert.pem \
  -extfile <(echo "basicConstraints=CA:FALSE,pathlen:0")

With the commit ba4356ae4002a04e28642da60c551877eea804f7 the
EXFLAG_INVALID causes openssl to not consider such certificate
even as leaf self-signed certificate which is breaking existing
installations.

Fixes: #11456

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

4 years agoAdd a WPACKET test for the new DER capability
Matt Caswell [Thu, 2 Apr 2020 11:26:47 +0000 (12:26 +0100)]
Add a WPACKET test for the new DER capability

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

4 years agoAdd "endfirst" writing to WPACKET
Matt Caswell [Thu, 2 Apr 2020 10:21:24 +0000 (11:21 +0100)]
Add "endfirst" writing to WPACKET

Support the concept of writing to the end of the packet first.

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

4 years agoFix a gcc warning about possible null pointer
Bernd Edlinger [Sun, 3 Nov 2019 18:36:11 +0000 (19:36 +0100)]
Fix a gcc warning about possible null pointer

In function 'ccm_tls_cipher',
    inlined from 'ccm_cipher_internal' at providers/common/ciphers/cipher_ccm.c:359:16,
    inlined from 'ccm_stream_final' at providers/common/ciphers/cipher_ccm.c:265:9:
providers/common/ciphers/cipher_ccm.c:317:5: error: argument 2 null where non-null expected [-Werror=nonnull]
  317 |     memcpy(ctx->iv + EVP_CCM_TLS_FIXED_IV_LEN, in, EVP_CCM_TLS_EXPLICIT_IV_LEN);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/internal/cryptlib.h:14,
                 from providers/common/include/prov/ciphercommon.h:14,
                 from providers/common/ciphers/cipher_ccm.c:12:
providers/common/ciphers/cipher_ccm.c: In function 'ccm_stream_final':
/home/ed/gnu/arm-linux-gnueabihf-linux64/arm-linux-gnueabihf/sys-include/string.h:44:14: note: in a call to function 'memcpy' declared here
   44 | extern void *memcpy (void *__restrict __dest,
      |              ^~~~~~

[extended tests]

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

4 years agoExpand the XTS documentation
Matt Caswell [Thu, 2 Apr 2020 08:58:59 +0000 (09:58 +0100)]
Expand the XTS documentation

Explain that XTS does not support streaming, and that the IV value is the
tweak.

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

4 years agoRemove an unnecessary call to BN_CTX_free.
Aaron Thompson [Tue, 31 Mar 2020 07:19:16 +0000 (07:19 +0000)]
Remove an unnecessary call to BN_CTX_free.

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

4 years agoFix bugs in EC code introduced with FIPS changes.
Aaron Thompson [Tue, 31 Mar 2020 06:47:58 +0000 (06:47 +0000)]
Fix bugs in EC code introduced with FIPS changes.

a9612d6c034f47c4788c67d85651d0cd58c3faf7 introduced possible memory leaks in EC_GROUP_cmp and EC_POINTs_mul, and a possible BN_CTX_end without BN_CTX_start in ec_field_inverse_mod_ord.

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

4 years agoAdd data driven SELF TEST code for signatures and key agreement
Shane Lontis [Fri, 3 Apr 2020 06:50:36 +0000 (16:50 +1000)]
Add data driven SELF TEST code for signatures and key agreement

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

4 years agoHTTP client: make server/proxy and port params more consistent; minor other improvements
Dr. David von Oheimb [Wed, 25 Mar 2020 12:46:02 +0000 (13:46 +0100)]
HTTP client: make server/proxy and port params more consistent; minor other improvements

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/11404)

4 years ago Chunk 10 of CMP contribution to OpenSSL: CMP http client and related tests
Dr. David von Oheimb [Wed, 19 Feb 2020 17:00:26 +0000 (18:00 +0100)]
Chunk 10 of CMP contribution to OpenSSL: CMP http client and related tests

    Also improve the generic HTTP client w.r.t. proxy and no_proxy options.

    Certificate Management Protocol (CMP, RFC 4210) extension to OpenSSL
    Also includes CRMF (RFC 4211) and HTTP transfer (RFC 6712).
    Adds the CMP and CRMF API to libcrypto and the "cmp" app to the CLI.
    Adds extensive documentation and tests.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/11404)

4 years agoTLS Cipher Suite 0xC102 Support
Nikolay Morozov [Wed, 25 Mar 2020 13:00:43 +0000 (16:00 +0300)]
TLS Cipher Suite 0xC102 Support

For GOST2012-GOST8912-GOST8912 was used 0xFF85 identifier,
but new identifier 0xc102 was assigned.
Because of old software we will support both numbers.

https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-2
https://datatracker.ietf.org/doc/draft-smyshlyaev-tls12-gost-suites/

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

4 years agoFix a printf format error in cmp_client.c
Bernd Edlinger [Wed, 1 Apr 2020 04:00:27 +0000 (06:00 +0200)]
Fix a printf format error in cmp_client.c

The value is of type uint64 but the format
%ld is not suitable for that, need to use %jd.

[extended tests]

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

4 years agoFixups in CHANGES.md
Richard Levitte [Tue, 31 Mar 2020 12:10:27 +0000 (14:10 +0200)]
Fixups in CHANGES.md

Fixed one ambiguous line and removed a few unnecessary backticks.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
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/11447)

4 years agoExtend the sslprovider_test to be able to additionally test FIPS
Matt Caswell [Mon, 16 Mar 2020 17:03:08 +0000 (17:03 +0000)]
Extend the sslprovider_test to be able to additionally test FIPS

Previously we could test an empty default ctx, with the default provider
loaded into another ctx. Now we do the same with the FIPS provider.

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

4 years agoMake sure we always use the correct libctx in sslprovidertest.c
Matt Caswell [Thu, 12 Mar 2020 14:51:34 +0000 (14:51 +0000)]
Make sure we always use the correct libctx in sslprovidertest.c

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

4 years agoMake sure we use the libctx when creating an EVP_PKEY_CTX in libssl
Matt Caswell [Thu, 12 Mar 2020 14:49:19 +0000 (14:49 +0000)]
Make sure we use the libctx when creating an EVP_PKEY_CTX in libssl

We should use EVP_PKEY_CTX_new_from_pkey() to ensure we use the correct
libctx.

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

4 years agoUse EVP_DigestSignInit_ex and EVP_DigestVerifyInit_ex in libssl
Matt Caswell [Thu, 12 Mar 2020 14:46:30 +0000 (14:46 +0000)]
Use EVP_DigestSignInit_ex and EVP_DigestVerifyInit_ex in libssl

We need to make sure we use the correct libctx for all operations in
libssl.

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

4 years agoDon't double free a DH object
Matt Caswell [Mon, 30 Mar 2020 13:15:06 +0000 (14:15 +0100)]
Don't double free a DH object

Having created a DH object and assigned it to an EVP_PKEY - we should
not free both the EVP_PKEY and the original DH. This will lead to a
double free occurring.

This issue was discovered and reported by GitHub Security Lab team member
Agustin Gianni.

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

4 years ago[crypto/ec] Ladder tweaks
Billy Brumley [Sat, 28 Mar 2020 18:35:43 +0000 (20:35 +0200)]
[crypto/ec] Ladder tweaks

- Convert to affine coords on ladder entry. This lets us use more efficient
  ladder step formulae.

- Convert to affine coords on ladder exit. This prevents the current code
  awkwardness where conversion happens twice during serialization: first to
  fetch the buffer size, then again to fetch the coords.

- Instead of projectively blinding the input point, blind both accumulators
  independently.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/11435)

4 years ago[test] Make sm2_internal_test less fragile to changes in the ec module
Billy Brumley [Sun, 29 Mar 2020 07:38:37 +0000 (10:38 +0300)]
[test] Make sm2_internal_test less fragile to changes in the ec module

Since these are KATs, the trailing randomness consumed by the ec module
does not really matter. So make the fake random buffer circular.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/11435)

4 years agoapps: support sendfile in s_server when ktls enabled
Tianjia Zhang [Fri, 13 Mar 2020 03:24:05 +0000 (11:24 +0800)]
apps: support sendfile in s_server when ktls enabled

When the -WWW or -HTTP option is specified, s_server can choose
to use SSL_sendfile to transmit the file requested by client
with KTLS is enabled, taking full advantage of the performance
advantages of Kernel TLS, and adding the '-sendfile' command
line parameter to control this behavior.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11318)

4 years agoAdd EVP_PKEY_gettable_params support for accessing EVP_PKEY key data fields
Shane Lontis [Wed, 1 Apr 2020 05:51:18 +0000 (15:51 +1000)]
Add EVP_PKEY_gettable_params support for accessing EVP_PKEY key data fields

Currently only RSA, EC and ECX are supported (DH and DSA need to be added to the keygen
PR's seperately because the fields supported have changed significantly).

The API's require the keys to be provider based.

Made the keymanagement export and get_params functions share the same code by supplying
support functions that work for both a OSSL_PARAM_BLD as well as a OSSL_PARAM[].
This approach means that complex code is not required to build an
empty OSSL_PARAM[] with the correct sized fields before then doing a second
pass to populate the array.

The RSA factor arrays have been changed to use unique key names to simplify the interface
needed by the user.

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

4 years agoWindows makefile generator: Don't delete long lists of files in one go
Richard Levitte [Tue, 25 Feb 2020 10:14:28 +0000 (11:14 +0100)]
Windows makefile generator: Don't delete long lists of files in one go

The Windows command line has its limits, and we're hitting it hard.
We therefore generate one 'del' command for each explicit file for the
'clean' target.

Fixes #11163

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

4 years agoGive a better error if we can't find a sig alg
Matt Caswell [Fri, 27 Mar 2020 17:16:59 +0000 (17:16 +0000)]
Give a better error if we can't find a sig alg

Some scenarios where we could not find a suitable sig alg just
gave "internal error" as the reason - which isn't very helpful. A
more suitable reason code already exists - so we use that.

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

4 years agoFix off-by-1 bug on provider_activate with custom error strings
Nicola Tuveri [Fri, 27 Mar 2020 14:39:34 +0000 (15:39 +0100)]
Fix off-by-1 bug on provider_activate with custom error strings

Starting `cnt` from 1 would work if we weren't using cnt itself to
access elements of the array returned calling the provider callback.

As it is before this commit, we have 2 problems:
- first, in the unlikely case that the incoming array was "empty" (only
  contains the terminator item) we would skip past it and potentially
  end up with oob reads;
- otherwise, at the end of the while loop, `cnt` will be equal to the
  number of items in the input array, not 1 more. We then add 1 more to
  the zalloc call to account for the library name item, and we fill all
  of it (relying on zalloc to have zeroed the terminator item).
  The first read access that will read the list up to the terminator
  will result in a OOB read as we did not allocate enough space to also
  contain the terminator.

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

4 years agoAdd test for providers exposing OSSL_FUNC_PROVIDER_GET_REASON_STRINGS
Nicola Tuveri [Fri, 27 Mar 2020 11:02:48 +0000 (12:02 +0100)]
Add test for providers exposing OSSL_FUNC_PROVIDER_GET_REASON_STRINGS

This test currently fails, next commit has the description of the bug
and the fix.

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

4 years agoDocument the new X509v3_cache_extensions() function
Matt Caswell [Wed, 25 Mar 2020 16:00:42 +0000 (16:00 +0000)]
Document the new X509v3_cache_extensions() function

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

4 years agoExplicitly cache X509v3 extensions in libssl
Matt Caswell [Fri, 20 Mar 2020 11:55:19 +0000 (11:55 +0000)]
Explicitly cache X509v3 extensions in libssl

Caching the X509v3 extensions requires an explicit libctx. We do that
where required in libssl.

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

4 years agoAdd the X509v3_cache_extensions() function
Matt Caswell [Fri, 20 Mar 2020 11:52:07 +0000 (11:52 +0000)]
Add the X509v3_cache_extensions() function

Various functions cause the results of processing extensions to be
cached. The processing itself requires a libctx, and so this implicit
caching means that the default ctx is used which can lead to failures.
By explicitly caching the extensions we can specify the libctx to be used.

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

4 years agoDon't attempt to up-ref an EVP_CIPHER if it is NULL
Matt Caswell [Fri, 27 Mar 2020 16:05:36 +0000 (16:05 +0000)]
Don't attempt to up-ref an EVP_CIPHER if it is NULL

EVP_CIPHERs in the ssl_cipher_methods table can be NULL if
they are not available. We shouldn't attempt to up-ref a
cipher if it is NULL.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11426)

4 years agoDescribe the "want" parameter in int create_bare_ssl_connection()
Matt Caswell [Thu, 26 Mar 2020 11:29:42 +0000 (11:29 +0000)]
Describe the "want" parameter in int create_bare_ssl_connection()

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

4 years agoDisplay errors if a test TLS connection fails
Matt Caswell [Fri, 20 Mar 2020 11:58:34 +0000 (11:58 +0000)]
Display errors if a test TLS connection fails

If a connection fails it is useful during debugging to have any errors
that are on the OpenSSL error stack at the time of the failure.

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

4 years agoParam builder: Remove the static size limit.
Pauli [Fri, 27 Mar 2020 00:33:46 +0000 (10:33 +1000)]
Param builder: Remove the static size limit.

Prior to this, the param builder had a statically sized array internally.
This changes it so that it uses a stack instead.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/11390)

4 years agoParam build: make structures opaque.
Pauli [Wed, 25 Mar 2020 23:28:01 +0000 (09:28 +1000)]
Param build: make structures opaque.

Since this is public, it is best to make the underlying structure opaque.
This means converting from stack allocation to dynamic allocation for all
usages.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/11390)

4 years agoNEWS: note OSSL_PARAM_BLD API as public.
Pauli [Tue, 24 Mar 2020 05:08:00 +0000 (15:08 +1000)]
NEWS: note OSSL_PARAM_BLD API as public.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/11390)

4 years agoParam builder: make the OSSL_PARAM_BLD APIs public.
Pauli [Tue, 24 Mar 2020 04:58:57 +0000 (14:58 +1000)]
Param builder: make the OSSL_PARAM_BLD APIs public.

The catalyst for this is the difficult of passing BNs through the other
OSSL_PARAM APIs.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/11390)

4 years agos_server: Properly indicate ALPN protocol mismatch
Tomas Mraz [Thu, 26 Mar 2020 14:59:00 +0000 (15:59 +0100)]
s_server: Properly indicate ALPN protocol mismatch

Return SSL_TLSEXT_ERR_ALERT_FATAL from alpn_select_cb so that
an alert is sent to the client on ALPN protocol mismatch.

Fixes: #2708

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

4 years agoPROV: Fix EC_KEY exporters to allow domain parameter keys
Richard Levitte [Tue, 24 Mar 2020 15:31:43 +0000 (16:31 +0100)]
PROV: Fix EC_KEY exporters to allow domain parameter keys

The provider key export functions for EC_KEY assumed that a public key
is always present, and would fail if not.  This blocks any attempt to
export a key structure with only domain parameters.

This is similar to earlier work done in EVP_PKEY_ASN1_METHODs.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11394)

4 years agoDocument various SRP related APIs
Matt Caswell [Wed, 25 Mar 2020 17:43:50 +0000 (17:43 +0000)]
Document various SRP related APIs

This includes the newly added *_ex() variants that take a libctx/property
query string.

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

4 years agoUse the new library context aware SRP functions in sslapitest
Matt Caswell [Fri, 20 Mar 2020 17:24:51 +0000 (17:24 +0000)]
Use the new library context aware SRP functions in sslapitest

For the moment this still just uses the default library context, but a
future version of sslapitest will specify a non-default library context.

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

4 years agoUpdate libssl to use the new library context aware SRP functions
Matt Caswell [Fri, 20 Mar 2020 17:24:24 +0000 (17:24 +0000)]
Update libssl to use the new library context aware SRP functions

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

4 years agoMake SRP library context aware
Matt Caswell [Fri, 20 Mar 2020 17:23:25 +0000 (17:23 +0000)]
Make SRP library context aware

In order for the TLS SRP tests to pass when using a non-default library
context the underlying SRP calls need to be library context aware.

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

4 years agoUse the new OCSP functions in sslapitest.c
Matt Caswell [Wed, 25 Mar 2020 15:01:36 +0000 (15:01 +0000)]
Use the new OCSP functions in sslapitest.c

At the moment we just use the default libctx - but a future PR will add
support for running sslapitest with a non-default libctx.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11407)

4 years agoAdd OCSP_RESPID_set_by_key_ex() and OCSP_RESPID_match_ex()
Matt Caswell [Fri, 20 Mar 2020 14:54:55 +0000 (14:54 +0000)]
Add OCSP_RESPID_set_by_key_ex() and OCSP_RESPID_match_ex()

OCSP_RESPID_set_by_key() calculates a SHA1 hash of the supplied
certificate. We need to be able to specify which libctx and property
query string is used to fetch that algorithm so we introduce
OCSP_RESPID_set_by_key_ex() which does the same thing but enables you to
speicfy the library context and propery query string explicitly.

OCSP_RESPID_match() matches with certificates based on the SHA1 hash.
Therefore for the same reason we introduce OCSP_RESPID_match_ex().

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11407)

4 years agoIgnore some fetch failures
Matt Caswell [Fri, 20 Mar 2020 12:00:12 +0000 (12:00 +0000)]
Ignore some fetch failures

Some fetch failurs are ok and should be ignored.

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

4 years agoPut an error on the stack in the event of a fetch failure
Matt Caswell [Wed, 25 Mar 2020 12:12:59 +0000 (12:12 +0000)]
Put an error on the stack in the event of a fetch failure

Fetch failures are a common problem and it is useful to have detailed
information about what was requested in the event of a failure.

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

4 years agoUse a fetched cipher for the TLSv1.3 early secret
Matt Caswell [Fri, 20 Mar 2020 12:37:20 +0000 (12:37 +0000)]
Use a fetched cipher for the TLSv1.3 early secret

We should use an explicitly fetched cipher to ensure that we are using
the correct libctx and property query.

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

4 years agoUse a fetched cipher when decrypting a ticket in libssl
Matt Caswell [Thu, 19 Mar 2020 18:23:58 +0000 (18:23 +0000)]
Use a fetched cipher when decrypting a ticket in libssl

We need to make sure we are using the correct libctx and property query.

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

4 years agoEVP: Limit the diverse key parameter functions to domain params only
Richard Levitte [Mon, 23 Mar 2020 05:03:16 +0000 (06:03 +0100)]
EVP: Limit the diverse key parameter functions to domain params only

Provider KEYMGMT functions can handle domain parameters as well as
"other" parameters (the cofactor mode flag in ECC keys is one of
those).  The public EVP functions EVP_PKEY_copy_parameters(),
EVP_PKEY_missing_parameters(), EVP_PKEY_cmp_parameters() and
EVP_PKEY_cmp() tried to handle all parameters, but looking back at
EVP_PKEY_ASN1_METHOD code (especially crypto/ec/ec_ameth.c), it turns
out that they only need to concern themselves with domain parameters.

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

4 years agoEVP: Implement support for key downgrading in backends
Richard Levitte [Mon, 23 Mar 2020 04:40:47 +0000 (05:40 +0100)]
EVP: Implement support for key downgrading in backends

Downgrading EVP_PKEYs from containing provider side internal keys to
containing legacy keys demands support in the EVP_PKEY_ASN1_METHOD.

This became a bit elaborate because the code would be almost exactly
the same as the import functions int EVP_KEYMGMT.  Therefore, we end
up moving most of the code to common backend support files that can be
used both by legacy backend code and by our providers.

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

4 years agotest/evp_pkey_provided_test.c: Add test of EVP_PKEY_copy_parameters()
Richard Levitte [Sat, 21 Mar 2020 05:26:41 +0000 (06:26 +0100)]
test/evp_pkey_provided_test.c: Add test of EVP_PKEY_copy_parameters()

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

4 years agoEVP: Downgrade keys rather than upgrade
Richard Levitte [Sat, 21 Mar 2020 05:21:26 +0000 (06:21 +0100)]
EVP: Downgrade keys rather than upgrade

Upgrading EVP_PKEYs from containing legacy keys to containing provider
side keys proved to be risky, with a number of unpleasant corner
cases, and with functions like EVP_PKEY_get0_DSA() failing
unexpectedly.

We therefore change course, and instead of upgrading legacy internal
keys to provider side internal keys, we downgrade provider side
internal keys to legacy ones.  To be able to do this, we add
|import_from| and make it a callback function designed for
evp_keymgmt_export().

This means that evp_pkey_upgrade_to_provider() is replaced with
evp_pkey_downgrade().

EVP_PKEY_copy_parameters() is the most deeply affected function of
this change.

Fixes #11366

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

4 years agoEVP: Add EVP_PKEY_set_type_by_keymgmt() and use it
Richard Levitte [Sat, 21 Mar 2020 05:14:25 +0000 (06:14 +0100)]
EVP: Add EVP_PKEY_set_type_by_keymgmt() and use it

This function intialises an EVP_PKEY to contain a provider side internal
key.

We take the opportunity to also document the older EVP_PKEY_set_type()
and EVP_PKEY_set_type_str().

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

4 years agoEVP: Clarify the states of an EVP_PKEY
Richard Levitte [Sat, 21 Mar 2020 05:03:39 +0000 (06:03 +0100)]
EVP: Clarify the states of an EVP_PKEY

EVP_PKEY is rather complex, even before provider side keys entered the
stage.
You could have untyped / unassigned keys (pk->type == EVP_PKEY_NONE),
keys that had been assigned a type but no data (pk->pkey.ptr == NULL),
and fully assigned keys (pk->type != EVP_PKEY_NONE && pk->pkey.ptr != NULL).

For provider side keys, the corresponding states weren't well defined,
and the code didn't quite account for all the possibilities.

We also guard most of the legacy fields in EVP_PKEY with FIPS_MODE, so
they don't exist at all in the FIPS module.

Most of all, code needs to adapt to the case where an EVP_PKEY's
|keymgmt| is non-NULL, but its |keydata| is NULL.

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

4 years agoEC: Refactor ec_curve_name2nid() to accept NIST curve names
Richard Levitte [Tue, 24 Mar 2020 10:18:50 +0000 (11:18 +0100)]
EC: Refactor ec_curve_name2nid() to accept NIST curve names

We can find no reason why everyone should have to call both
EC_curve_nist2nid() and ec_curve_name2nid() to find the NID for a
name, and it's too easy to forget EC_curve_nist2nid(), so we make life
simpler.

One could argue that FIPS only allows a limited set of names, but that
now gets handled internally, and those who really want to be really
sure to only get the NIST names can still do so with EC_curve_nist2nid()

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11391)