diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md index baf7743c..dae83457 100644 --- a/ACKNOWLEDGEMENTS.md +++ b/ACKNOWLEDGEMENTS.md @@ -3,6 +3,5 @@ Acknowlegements Please see our [Thanks!][] page for the current acknowledgements. - [Thanks!]: https://www.openssl.org/community/thanks.html diff --git a/AUTHORS.md b/AUTHORS.md index e9ff5441..af72f43b 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -7,40 +7,38 @@ since in some cases, their employer may be the copyright holder. To see the full list of contributors, see the revision history in source control. - Groups ------ - * OpenSSL Software Services, Inc. - * OpenSSL Software Foundation, Inc. - + * OpenSSL Software Services, Inc. + * OpenSSL Software Foundation, Inc. Individuals ----------- - * Andy Polyakov - * Ben Laurie - * Ben Kaduk - * Bernd Edlinger - * Bodo Möller - * David Benjamin - * Emilia Käsper - * Eric Young - * Geoff Thorpe - * Holger Reif - * Kurt Roeckx - * Lutz Jänicke - * Mark J. Cox - * Matt Caswell - * Matthias St. Pierre - * Nils Larsch - * Paul Dale - * Paul C. Sutton - * Ralf S. Engelschall - * Rich Salz - * Richard Levitte - * Stephen Henson - * Steve Marquess - * Tim Hudson - * Ulf Möller - * Viktor Dukhovni + * Andy Polyakov + * Ben Laurie + * Ben Kaduk + * Bernd Edlinger + * Bodo Möller + * David Benjamin + * Emilia Käsper + * Eric Young + * Geoff Thorpe + * Holger Reif + * Kurt Roeckx + * Lutz Jänicke + * Mark J. Cox + * Matt Caswell + * Matthias St. Pierre + * Nils Larsch + * Paul Dale + * Paul C. Sutton + * Ralf S. Engelschall + * Rich Salz + * Richard Levitte + * Stephen Henson + * Steve Marquess + * Tim Hudson + * Ulf Möller + * Viktor Dukhovni diff --git a/CHANGES.md b/CHANGES.md index 78e8f88c..bc4f5241 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,7 +7,6 @@ pick the appropriate release branch. [log]: https://github.com/openssl/openssl/commits/ - OpenSSL Releases ---------------- @@ -22,7 +21,19 @@ OpenSSL Releases OpenSSL 3.0 ----------- -### Changes between 1.1.1 and 3.0 [xx XXX xxxx] ### +### Changes between 1.1.1 and 3.0 [xx XXX xxxx] + + * Deprecated EC_POINTs_mul(). This function is not widely used and applications + should instead use the L function. + + *Billy Bob Brumley* + + * Removed FIPS_mode() and FIPS_mode_set(). These functions are legacy API's + that are not applicable to the new provider model. Applications should + instead use EVP_default_properties_is_fips_enabled() and + EVP_default_properties_enable_fips(). + + *Shane Lontis* * Deprecated EC_POINT_set_Jprojective_coordinates_GFp() and EC_POINT_get_Jprojective_coordinates_GFp(). These functions are not widely @@ -80,7 +91,6 @@ OpenSSL 3.0 *Matthias St. Pierre* - * The test suite is changed to preserve results of each test recipe. A new directory test-runs/ with subdirectories named like the test recipes are created in the build tree for this purpose. @@ -88,10 +98,10 @@ OpenSSL 3.0 *Richard Levitte* * Added an implementation of CMP and CRMF (RFC 4210, RFC 4211 RFC 6712). - This adds crypto/cmp/, crpyto/crmf/, and test/cmp_*. - See L as starting point. + This adds crypto/cmp/, crpyto/crmf/, apps/cmp.c, and test/cmp_*. + See L and L as starting points. - *David von Oheimb* + *David von Oheimb, Martin Peylo* * Generalized the HTTP client code from crypto/ocsp/ into crpyto/http/. The legacy OCSP-focused and only partly documented API is retained. @@ -101,24 +111,22 @@ OpenSSL 3.0 * All of the low level RSA functions have been deprecated including: - RSA_new_method, RSA_bits, RSA_size, RSA_security_bits, - RSA_get0_pss_params, RSA_get_version, RSA_get0_engine, - RSA_generate_key_ex, RSA_generate_multi_prime_key, - RSA_X931_derive_ex, RSA_X931_generate_key_ex, RSA_check_key, - RSA_check_key_ex, RSA_public_encrypt, RSA_private_encrypt, + RSA_new_method, RSA_size, RSA_security_bits, RSA_get0_pss_params, + RSA_get_version, RSA_get0_engine, RSA_generate_key_ex, + RSA_generate_multi_prime_key, RSA_X931_derive_ex, RSA_X931_generate_key_ex, + RSA_check_key, RSA_check_key_ex, RSA_public_encrypt, RSA_private_encrypt, RSA_public_decrypt, RSA_private_decrypt, RSA_set_default_method, RSA_get_default_method, RSA_null_method, RSA_get_method, RSA_set_method, RSA_PKCS1_OpenSSL, RSA_print_fp, RSA_print, RSA_sign, RSA_verify, - RSA_sign_ASN1_OCTET_STRING, RSA_verify_ASN1_OCTET_STRING, - RSA_blinding_on, RSA_blinding_off, RSA_setup_blinding, - RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1, - RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2, - PKCS1_MGF1, RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP, - RSA_padding_add_PKCS1_OAEP_mgf1, RSA_padding_check_PKCS1_OAEP_mgf1, - RSA_padding_add_SSLv23, RSA_padding_check_SSLv23, - RSA_padding_add_none, RSA_padding_check_none, RSA_padding_add_X931, - RSA_padding_check_X931, RSA_X931_hash_id, RSA_verify_PKCS1_PSS, - RSA_padding_add_PKCS1_PSS, RSA_verify_PKCS1_PSS_mgf1, + RSA_sign_ASN1_OCTET_STRING, RSA_verify_ASN1_OCTET_STRING, RSA_blinding_on, + RSA_blinding_off, RSA_setup_blinding, RSA_padding_add_PKCS1_type_1, + RSA_padding_check_PKCS1_type_1, RSA_padding_add_PKCS1_type_2, + RSA_padding_check_PKCS1_type_2, PKCS1_MGF1, RSA_padding_add_PKCS1_OAEP, + RSA_padding_check_PKCS1_OAEP, RSA_padding_add_PKCS1_OAEP_mgf1, + RSA_padding_check_PKCS1_OAEP_mgf1, RSA_padding_add_SSLv23, + RSA_padding_check_SSLv23, RSA_padding_add_none, RSA_padding_check_none, + RSA_padding_add_X931, RSA_padding_check_X931, RSA_X931_hash_id, + RSA_verify_PKCS1_PSS, RSA_padding_add_PKCS1_PSS, RSA_verify_PKCS1_PSS_mgf1, RSA_padding_add_PKCS1_PSS_mgf1, RSA_set_ex_data, RSA_get_ex_data, RSA_meth_new, RSA_meth_free, RSA_meth_dup, RSA_meth_get0_name, RSA_meth_set1_name, RSA_meth_get_flags, RSA_meth_set_flags, @@ -171,20 +179,19 @@ OpenSSL 3.0 * All of the low level DH functions have been deprecated including: - DH_OpenSSL, DH_set_default_method, DH_get_default_method, - DH_set_method, DH_new_method, DH_bits, DH_size, DH_security_bits, - DH_get_ex_new_index, DH_set_ex_data, DH_get_ex_data, - DH_generate_parameters_ex, DH_check_params_ex, DH_check_ex, - DH_check_pub_key_ex, DH_check, DH_check_pub_key, DH_generate_key, - DH_compute_key, DH_compute_key_padded, DHparams_print_fp, - DHparams_print, DH_get_nid, DH_KDF_X9_42, DH_get0_engine, DH_meth_new, - DH_meth_free, DH_meth_dup, DH_meth_get0_name, DH_meth_set1_name, - DH_meth_get_flags, DH_meth_set_flags, DH_meth_get0_app_data, - DH_meth_set0_app_data, DH_meth_get_generate_key, DH_meth_set_generate_key, - DH_meth_get_compute_key, DH_meth_set_compute_key, DH_meth_get_bn_mod_exp, - DH_meth_set_bn_mod_exp, DH_meth_get_init, DH_meth_set_init, - DH_meth_get_finish, DH_meth_set_finish, DH_meth_get_generate_params - and DH_meth_set_generate_params. + DH_OpenSSL, DH_set_default_method, DH_get_default_method, DH_set_method, + DH_new_method, DH_size, DH_security_bits, DH_get_ex_new_index, + DH_set_ex_data, DH_get_ex_data, DH_generate_parameters_ex, + DH_check_params_ex, DH_check_ex, DH_check_pub_key_ex, + DH_check, DH_check_pub_key, DH_generate_key, DH_compute_key, + DH_compute_key_padded, DHparams_print_fp, DHparams_print, DH_get_nid, + DH_KDF_X9_42, DH_get0_engine, DH_meth_new, DH_meth_free, DH_meth_dup, + DH_meth_get0_name, DH_meth_set1_name, DH_meth_get_flags, DH_meth_set_flags, + DH_meth_get0_app_data, DH_meth_set0_app_data, DH_meth_get_generate_key, + DH_meth_set_generate_key, DH_meth_get_compute_key, DH_meth_set_compute_key, + DH_meth_get_bn_mod_exp, DH_meth_set_bn_mod_exp, DH_meth_get_init, + DH_meth_set_init, DH_meth_get_finish, DH_meth_set_finish, + DH_meth_get_generate_params and DH_meth_set_generate_params. Use of these low level functions has been informally discouraged for a long time. Instead applications should use L @@ -195,18 +202,19 @@ OpenSSL 3.0 * All of the low level DSA functions have been deprecated including: DSA_do_sign, DSA_do_verify, DSA_OpenSSL, DSA_set_default_method, - DSA_get_default_method, DSA_set_method, DSA_get_method, DSA_new_method, - DSA_sign_setup, DSA_sign, DSA_verify, DSA_get_ex_new_index, - DSA_set_ex_data, DSA_get_ex_data, DSA_generate_parameters_ex, - DSA_generate_key, DSA_meth_new, DSA_get0_engine, DSA_meth_free, - DSA_meth_dup, DSA_meth_get0_name, DSA_meth_set1_name, DSA_meth_get_flags, - DSA_meth_set_flags, DSA_meth_get0_app_data, DSA_meth_set0_app_data, - DSA_meth_get_sign, DSA_meth_set_sign, DSA_meth_get_sign_setup, - DSA_meth_set_sign_setup, DSA_meth_get_verify, DSA_meth_set_verify, - DSA_meth_get_mod_exp, DSA_meth_set_mod_exp, DSA_meth_get_bn_mod_exp, - DSA_meth_set_bn_mod_exp, DSA_meth_get_init, DSA_meth_set_init, - DSA_meth_get_finish, DSA_meth_set_finish, DSA_meth_get_paramgen, - DSA_meth_set_paramgen, DSA_meth_get_keygen and DSA_meth_set_keygen. + DSA_get_default_method, DSA_set_method, DSA_get_method, + DSA_new_method, DSA_size, DSA_security_bits, DSA_sign_setup, DSA_sign, + DSA_verify, DSA_get_ex_new_index, DSA_set_ex_data, DSA_get_ex_data, + DSA_generate_parameters_ex, DSA_generate_key, DSA_meth_new, DSA_get0_engine, + DSA_meth_free, DSA_meth_dup, DSA_meth_get0_name, DSA_meth_set1_name, + DSA_meth_get_flags, DSA_meth_set_flags, DSA_meth_get0_app_data, + DSA_meth_set0_app_data, DSA_meth_get_sign, DSA_meth_set_sign, + DSA_meth_get_sign_setup, DSA_meth_set_sign_setup, DSA_meth_get_verify, + DSA_meth_set_verify, DSA_meth_get_mod_exp, DSA_meth_set_mod_exp, + DSA_meth_get_bn_mod_exp, DSA_meth_set_bn_mod_exp, DSA_meth_get_init, + DSA_meth_set_init, DSA_meth_get_finish, DSA_meth_set_finish, + DSA_meth_get_paramgen, DSA_meth_set_paramgen, DSA_meth_get_keygen and + DSA_meth_set_keygen. Use of these low level functions has been informally discouraged for a long time. Instead applications should use L, @@ -330,7 +338,7 @@ OpenSSL 3.0 *Paul Dale* - * Corrected the documentation of the return values from the EVP_DigestSign* + * Corrected the documentation of the return values from the `EVP_DigestSign*` set of functions. The documentation mentioned negative values for some errors, but this was never the case, so the mention of negative values was removed. @@ -418,6 +426,11 @@ OpenSSL 3.0 *Rich Salz* + * Added documentation for the STACK API. OpenSSL only defines the STACK + functions where they are used. + + *Rich Salz* + * Introduced a new method type and API, OSSL_SERIALIZER, to represent generic serializers. An implementation is expected to be able to serialize an object associated with a given name (such @@ -579,7 +592,6 @@ OpenSSL 3.0 $ mms /macro=(VF=1) test ! OpenVMS $ nmake VF=1 test # Windows - *Richard Levitte* * For built-in EC curves, ensure an EC_GROUP built from the curve name is @@ -631,7 +643,7 @@ OpenSSL 3.0 when primes for RSA keys are computed. Since we previously always generated primes == 2 (mod 3) for RSA keys, the 2-prime and 3-prime RSA modules were easy to distinguish, since - N = p*q = 1 (mod 3), but N = p*q*r = 2 (mod 3). Therefore fingerprinting + `N = p*q = 1 (mod 3)`, but `N = p*q*r = 2 (mod 3)`. Therefore fingerprinting 2-prime vs. 3-prime RSA keys was possible by computing N mod 3. This avoids possible fingerprinting of newly generated RSA modules. @@ -682,7 +694,7 @@ OpenSSL 3.0 *Paul Dale* - * {CRYPTO,OPENSSL}_mem_debug_{push,pop} are now no-ops and have been + * `{CRYPTO,OPENSSL}_mem_debug_{push,pop}` are now no-ops and have been deprecated. *Rich Salz* @@ -797,7 +809,7 @@ OpenSSL 3.0 *Paul Dale* * Added newline escaping functionality to a filename when using openssl dgst. - This output format is to replicate the output format found in the '*sum' + This output format is to replicate the output format found in the `*sum` checksum programs. This aims to preserve backward compatibility. *Matt Eaton, Richard Levitte, and Paul Dale* @@ -957,7 +969,7 @@ OpenSSL 3.0 the attacked described in "Efficient Instantiations of Tweakable Blockciphers and Refinements to Modes OCB and PMAC" by Phillip Rogaway. Details of this attack can be obtained from: - http://web.cs.ucdavis.edu/%7Erogaway/papers/offsets.pdf + *Paul Dale* @@ -978,14 +990,12 @@ OpenSSL 3.0 *Boris Pismenny* - OpenSSL 1.1.1 ------------- -### Changes between 1.1.1e and 1.1.1f [xx XXX xxxx] ### +### Changes between 1.1.1e and 1.1.1f [xx XXX xxxx] - -### Changes between 1.1.1d and 1.1.1e [17 Mar 2020] ### +### Changes between 1.1.1d and 1.1.1e [17 Mar 2020] * Properly detect EOF while reading in libssl. Previously if we hit an EOF while reading in libssl then we would report an error back to the @@ -1029,7 +1039,7 @@ OpenSSL 1.1.1 *Richard Levitte* * Added newline escaping functionality to a filename when using openssl dgst. - This output format is to replicate the output format found in the '*sum' + This output format is to replicate the output format found in the `*sum` checksum programs. This aims to preserve backward compatibility. *Matt Eaton, Richard Levitte, and Paul Dale* @@ -1039,7 +1049,7 @@ OpenSSL 1.1.1 *Jon Spillett* -### Changes between 1.1.1c and 1.1.1d [10 Sep 2019] ### +### Changes between 1.1.1c and 1.1.1d [10 Sep 2019] * Fixed a fork protection issue. OpenSSL 1.1.1 introduced a rewritten random number generator (RNG). This was intended to include protection in the @@ -1144,7 +1154,7 @@ OpenSSL 1.1.1 *Matthias St. Pierre* -### Changes between 1.1.1b and 1.1.1c [28 May 2019] ### +### Changes between 1.1.1b and 1.1.1c [28 May 2019] * Add build tests for C++. These are generated files that only do one thing, to include one public OpenSSL head file each. This tests that @@ -1235,7 +1245,7 @@ OpenSSL 1.1.1 *Paul Yang* -### Changes between 1.1.1a and 1.1.1b [26 Feb 2019] ### +### Changes between 1.1.1a and 1.1.1b [26 Feb 2019] * Change the info callback signals for the start and end of a post-handshake message exchange in TLSv1.3. In 1.1.1/1.1.1a we used SSL_CB_HANDSHAKE_START @@ -1249,7 +1259,7 @@ OpenSSL 1.1.1 *Matt Caswell* -### Changes between 1.1.1 and 1.1.1a [20 Nov 2018] ### +### Changes between 1.1.1 and 1.1.1a [20 Nov 2018] * Timing vulnerability in DSA signature generation @@ -1282,7 +1292,7 @@ OpenSSL 1.1.1 automatically and is fully functional even without additional randomness provided by the application. -### Changes between 1.1.0i and 1.1.1 [11 Sep 2018] ### +### Changes between 1.1.0i and 1.1.1 [11 Sep 2018] * Add a new ClientHello callback. Provides a callback interface that gives the application the ability to adjust the nascent SSL object at the @@ -1552,7 +1562,7 @@ OpenSSL 1.1.1 * Support for TLSv1.3 added. Note that users upgrading from an earlier version of OpenSSL should review their configuration settings to ensure that they are still appropriate for TLSv1.3. For further information see: - https://wiki.openssl.org/index.php/TLS1.3 + *Matt Caswell* @@ -1805,7 +1815,7 @@ OpenSSL 1.1.1 * 'openssl passwd' can now produce SHA256 and SHA512 based output, using the algorithm defined in - https://www.akkadia.org/drepper/SHA-crypt.txt + *Richard Levitte* @@ -1825,8 +1835,7 @@ OpenSSL 1.1.1 OpenSSL 1.1.0 ------------- - -### Changes between 1.1.0k and 1.1.0l [10 Sep 2019] ### +### Changes between 1.1.0k and 1.1.0l [10 Sep 2019] * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters, when loading a serialized key @@ -1872,7 +1881,7 @@ OpenSSL 1.1.0 *Richard Levitte* -### Changes between 1.1.0j and 1.1.0k [28 May 2019] ### +### Changes between 1.1.0j and 1.1.0k [28 May 2019] * Change the default RSA, DSA and DH size to 2048 bit instead of 1024. This changes the size when using the genpkey app when no size is given. It @@ -1935,7 +1944,7 @@ OpenSSL 1.1.0 *Richard Levitte* -### Changes between 1.1.0i and 1.1.0j [20 Nov 2018] ### +### Changes between 1.1.0i and 1.1.0j [20 Nov 2018] * Timing vulnerability in DSA signature generation @@ -1965,7 +1974,7 @@ OpenSSL 1.1.0 *Sohaib ul Hassan, Nicola Tuveri, Billy Bob Brumley* -### Changes between 1.1.0h and 1.1.0i [14 Aug 2018] ### +### Changes between 1.1.0h and 1.1.0i [14 Aug 2018] * Client DoS due to large DH parameter @@ -2050,7 +2059,7 @@ OpenSSL 1.1.0 *Matt Caswell* -### Changes between 1.1.0g and 1.1.0h [27 Mar 2018] ### +### Changes between 1.1.0g and 1.1.0h [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack @@ -2129,7 +2138,7 @@ OpenSSL 1.1.0 *Andy Polyakov* -### Changes between 1.1.0f and 1.1.0g [2 Nov 2017] ### +### Changes between 1.1.0f and 1.1.0g [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 @@ -2164,7 +2173,7 @@ OpenSSL 1.1.0 *Rich Salz* -### Changes between 1.1.0e and 1.1.0f [25 May 2017] ### +### Changes between 1.1.0e and 1.1.0f [25 May 2017] * Have 'config' recognise 64-bit mingw and choose 'mingw64' as the target platform rather than 'mingw'. @@ -2177,7 +2186,7 @@ OpenSSL 1.1.0 *Richard Levitte* -### Changes between 1.1.0d and 1.1.0e [16 Feb 2017] ### +### Changes between 1.1.0d and 1.1.0e [16 Feb 2017] * Encrypt-Then-Mac renegotiation crash @@ -2191,7 +2200,7 @@ OpenSSL 1.1.0 *Matt Caswell* -### Changes between 1.1.0c and 1.1.0d [26 Jan 2017] ### +### Changes between 1.1.0c and 1.1.0d [26 Jan 2017] * Truncated packet could crash via OOB read @@ -2237,11 +2246,11 @@ OpenSSL 1.1.0 *Andy Polyakov* -### Changes between 1.1.0b and 1.1.0c [10 Nov 2016] ### +### Changes between 1.1.0b and 1.1.0c [10 Nov 2016] * ChaCha20/Poly1305 heap-buffer-overflow - TLS connections using *-CHACHA20-POLY1305 ciphersuites are susceptible to + TLS connections using `*-CHACHA20-POLY1305` ciphersuites are susceptible to a DoS attack by corrupting larger payloads. This can result in an OpenSSL crash. This issue is not considered to be exploitable beyond a DoS. @@ -2293,7 +2302,7 @@ OpenSSL 1.1.0 *Richard Levitte* -### Changes between 1.1.0a and 1.1.0b [26 Sep 2016] ### +### Changes between 1.1.0a and 1.1.0b [26 Sep 2016] * Fix Use After Free for large message sizes @@ -2311,7 +2320,7 @@ OpenSSL 1.1.0 *Matt Caswell* -### Changes between 1.1.0 and 1.1.0a [22 Sep 2016] ### +### Changes between 1.1.0 and 1.1.0a [22 Sep 2016] * OCSP Status Request extension unbounded memory growth @@ -2390,7 +2399,7 @@ OpenSSL 1.1.0 *Andy Polyakov* -### Changes between 1.0.2h and 1.1.0 [25 Aug 2016] ### +### Changes between 1.0.2h and 1.1.0 [25 Aug 2016] * Windows command-line tool supports UTF-8 opt-in option for arguments and console input. Setting OPENSSL_WIN32_UTF8 environment variable @@ -2433,8 +2442,8 @@ OpenSSL 1.1.0 *Joseph Wylie Yandle, Rich Salz* - * The stack and lhash API's were renamed to start with OPENSSL_SK_ - and OPENSSL_LH_, respectively. The old names are available + * The stack and lhash API's were renamed to start with `OPENSSL_SK_` + and `OPENSSL_LH_`, respectively. The old names are available with API compatibility. They new names are now completely documented. *Rich Salz* @@ -2612,12 +2621,12 @@ OpenSSL 1.1.0 *Todd Short* * Changes to the DEFAULT cipherlist: - - Prefer (EC)DHE handshakes over plain RSA. - - Prefer AEAD ciphers over legacy ciphers. - - Prefer ECDSA over RSA when both certificates are available. - - Prefer TLSv1.2 ciphers/PRF. - - Remove DSS, SEED, IDEA, CAMELLIA, and AES-CCM from the - default cipherlist. + - Prefer (EC)DHE handshakes over plain RSA. + - Prefer AEAD ciphers over legacy ciphers. + - Prefer ECDSA over RSA when both certificates are available. + - Prefer TLSv1.2 ciphers/PRF. + - Remove DSS, SEED, IDEA, CAMELLIA, and AES-CCM from the + default cipherlist. *Emilia Käsper* @@ -2779,8 +2788,8 @@ OpenSSL 1.1.0 * The signature of the session callback configured with SSL_CTX_sess_set_get_cb was changed. The read-only input buffer - was explicitly marked as 'const unsigned char*' instead of - 'unsigned char*'. + was explicitly marked as `const unsigned char*` instead of + `unsigned char*`. *Emilia Käsper* @@ -2812,7 +2821,7 @@ OpenSSL 1.1.0 Makefile. Instead, Configure produces a perl module in configdata.pm which holds most of the config data (in the hash table %config), the target data that comes from the target - configuration in one of the Configurations/*.conf files (in + configuration in one of the `Configurations/*.conf~ files (in %target). *Richard Levitte* @@ -2841,7 +2850,7 @@ OpenSSL 1.1.0 * The GOST engine was out of date and therefore it has been removed. An up to date GOST engine is now being maintained in an external repository. - See: https://wiki.openssl.org/index.php/Binaries. Libssl still retains + See: . Libssl still retains support for GOST ciphersuites (these are only activated if a GOST engine is present). @@ -3195,7 +3204,7 @@ OpenSSL 1.1.0 * Added support for OCB mode. OpenSSL has been granted a patent license compatible with the OpenSSL license for use of OCB. Details are available - at https://www.openssl.org/source/OCB-patent-grant-OpenSSL.pdf. Support + at . Support for OCB can be removed by calling config with no-ocb. *Matt Caswell* @@ -3234,16 +3243,16 @@ OpenSSL 1.1.0 *Rich Salz* * Clean up OPENSSL_NO_xxx #define's - - Use setbuf() and remove OPENSSL_NO_SETVBUF_IONBF - - Rename OPENSSL_SYSNAME_xxx to OPENSSL_SYS_xxx - - OPENSSL_NO_EC{DH,DSA} merged into OPENSSL_NO_EC - - OPENSSL_NO_RIPEMD160, OPENSSL_NO_RIPEMD merged into OPENSSL_NO_RMD160 - - OPENSSL_NO_FP_API merged into OPENSSL_NO_STDIO - - Remove OPENSSL_NO_BIO OPENSSL_NO_BUFFER OPENSSL_NO_CHAIN_VERIFY - OPENSSL_NO_EVP OPENSSL_NO_FIPS_ERR OPENSSL_NO_HASH_COMP - OPENSSL_NO_LHASH OPENSSL_NO_OBJECT OPENSSL_NO_SPEED OPENSSL_NO_STACK - OPENSSL_NO_X509 OPENSSL_NO_X509_VERIFY - - Remove MS_STATIC; it's a relic from platforms <32 bits. + - Use setbuf() and remove OPENSSL_NO_SETVBUF_IONBF + - Rename OPENSSL_SYSNAME_xxx to OPENSSL_SYS_xxx + - OPENSSL_NO_EC{DH,DSA} merged into OPENSSL_NO_EC + - OPENSSL_NO_RIPEMD160, OPENSSL_NO_RIPEMD merged into OPENSSL_NO_RMD160 + - OPENSSL_NO_FP_API merged into OPENSSL_NO_STDIO + - Remove OPENSSL_NO_BIO OPENSSL_NO_BUFFER OPENSSL_NO_CHAIN_VERIFY + OPENSSL_NO_EVP OPENSSL_NO_FIPS_ERR OPENSSL_NO_HASH_COMP + OPENSSL_NO_LHASH OPENSSL_NO_OBJECT OPENSSL_NO_SPEED OPENSSL_NO_STACK + OPENSSL_NO_X509 OPENSSL_NO_X509_VERIFY + - Remove MS_STATIC; it's a relic from platforms <32 bits. *Rich Salz* @@ -3301,7 +3310,7 @@ OpenSSL 1.1.0 * Fix for the attack described in the paper "Recovering OpenSSL ECDSA Nonces Using the FLUSH+RELOAD Cache Side-channel Attack" by Yuval Yarom and Naomi Benger. Details can be obtained from: - http://eprint.iacr.org/2014/140 + Thanks to Yuval Yarom and Naomi Benger for discovering this flaw and to Yuval Yarom for supplying a fix [CVE-2014-0076][] @@ -3326,7 +3335,6 @@ OpenSSL 1.1.0 WARNING: EXPERIMENTAL, SUBJECT TO CHANGE. - *Steve Henson* * Add EVP support for key wrapping algorithms, to avoid problems with @@ -3532,7 +3540,7 @@ OpenSSL 1.1.0 *Steve Henson* * Initial, experimental EVP support for AES-GCM. AAD can be input by - setting output buffer to NULL. The *Final function must be + setting output buffer to NULL. The `*Final` function must be called although it will not retrieve any additional data. The tag can be set or retrieved with a ctrl. The IV length is by default 12 bytes (96 bits) but can be set to an alternative value. If the IV @@ -3624,7 +3632,7 @@ OpenSSL 1.1.0 OpenSSL 1.0.2 ------------- -### Changes between 1.0.2s and 1.0.2t [10 Sep 2019] ### +### Changes between 1.0.2s and 1.0.2t [10 Sep 2019] * For built-in EC curves, ensure an EC_GROUP built from the curve name is used even when parsing explicit parameters, when loading a serialized key @@ -3670,7 +3678,7 @@ OpenSSL 1.0.2 *Richard Levitte* -### Changes between 1.0.2r and 1.0.2s [28 May 2019] ### +### Changes between 1.0.2r and 1.0.2s [28 May 2019] * Change the default RSA, DSA and DH size to 2048 bit instead of 1024. This changes the size when using the genpkey app when no size is given. It @@ -3689,7 +3697,7 @@ OpenSSL 1.0.2 *Matthias St. Pierre* -### Changes between 1.0.2q and 1.0.2r [26 Feb 2019] ### +### Changes between 1.0.2q and 1.0.2r [26 Feb 2019] * 0-byte record padding oracle @@ -3718,7 +3726,7 @@ OpenSSL 1.0.2 *Richard Levitte* -### Changes between 1.0.2p and 1.0.2q [20 Nov 2018] ### +### Changes between 1.0.2p and 1.0.2q [20 Nov 2018] * Microarchitecture timing vulnerability in ECC scalar multiplication @@ -3751,7 +3759,7 @@ OpenSSL 1.0.2 *Nicola Tuveri* -### Changes between 1.0.2o and 1.0.2p [14 Aug 2018] ### +### Changes between 1.0.2o and 1.0.2p [14 Aug 2018] * Client DoS due to large DH parameter @@ -3818,7 +3826,7 @@ OpenSSL 1.0.2 *Emilia Käsper* -### Changes between 1.0.2n and 1.0.2o [27 Mar 2018] ### +### Changes between 1.0.2n and 1.0.2o [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack @@ -3834,7 +3842,7 @@ OpenSSL 1.0.2 *Matt Caswell* -### Changes between 1.0.2m and 1.0.2n [7 Dec 2017] ### +### Changes between 1.0.2m and 1.0.2n [7 Dec 2017] * Read/write after SSL object in error state @@ -3881,7 +3889,7 @@ OpenSSL 1.0.2 *Andy Polyakov* -### Changes between 1.0.2l and 1.0.2m [2 Nov 2017] ### +### Changes between 1.0.2l and 1.0.2m [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 @@ -3916,14 +3924,14 @@ OpenSSL 1.0.2 *Rich Salz* -### Changes between 1.0.2k and 1.0.2l [25 May 2017] ### +### Changes between 1.0.2k and 1.0.2l [25 May 2017] * Have 'config' recognise 64-bit mingw and choose 'mingw64' as the target platform rather than 'mingw'. *Richard Levitte* -### Changes between 1.0.2j and 1.0.2k [26 Jan 2017] ### +### Changes between 1.0.2j and 1.0.2k [26 Jan 2017] * Truncated packet could crash via OOB read @@ -3988,7 +3996,7 @@ OpenSSL 1.0.2 *Matt Caswell* -### Changes between 1.0.2i and 1.0.2j [26 Sep 2016] ### +### Changes between 1.0.2i and 1.0.2j [26 Sep 2016] * Missing CRL sanity check @@ -4001,7 +4009,7 @@ OpenSSL 1.0.2 *Matt Caswell* -### Changes between 1.0.2h and 1.0.2i [22 Sep 2016] ### +### Changes between 1.0.2h and 1.0.2i [22 Sep 2016] * OCSP Status Request extension unbounded memory growth @@ -4172,7 +4180,7 @@ OpenSSL 1.0.2 *Stephen Henson* -### Changes between 1.0.2g and 1.0.2h [3 May 2016] ### +### Changes between 1.0.2g and 1.0.2h [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check @@ -4200,7 +4208,7 @@ OpenSSL 1.0.2 corruption. Internally to OpenSSL the EVP_EncodeUpdate() function is primarily used by - the PEM_write_bio* family of functions. These are mainly used within the + the `PEM_write_bio*` family of functions. These are mainly used within the OpenSSL command line applications, so any application which processes data from an untrusted source and outputs it as a PEM file should be considered vulnerable to this issue. User applications that call these APIs directly @@ -4277,7 +4285,7 @@ OpenSSL 1.0.2 *Kurt Roeckx* -### Changes between 1.0.2f and 1.0.2g [1 Mar 2016] ### +### Changes between 1.0.2f and 1.0.2g [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. Builds that are not configured with "enable-weak-ssl-ciphers" will not @@ -4362,10 +4370,10 @@ OpenSSL 1.0.2 *Matt Caswell* - * Fix memory issues in BIO_*printf functions + * Fix memory issues in `BIO_*printf` functions The internal |fmtstr| function used in processing a "%s" format string in - the BIO_*printf functions could overflow while calculating the length of a + the `BIO_*printf` functions could overflow while calculating the length of a string and cause an OOB read when printing very long strings. Additionally the internal |doapr_outch| function can attempt to write to an @@ -4377,7 +4385,7 @@ OpenSSL 1.0.2 The first issue may mask the second issue dependent on compiler behaviour. These problems could enable attacks where large amounts of untrusted data - is passed to the BIO_*printf functions. If applications use these functions + is passed to the `BIO_*printf` functions. If applications use these functions in this way then they could be vulnerable. OpenSSL itself uses these functions when printing out human-readable dumps of ASN.1 data. Therefore applications that print this data could be vulnerable if the data is from @@ -4405,7 +4413,7 @@ OpenSSL 1.0.2 This issue was reported to OpenSSL by Yuval Yarom, The University of Adelaide and NICTA, Daniel Genkin, Technion and Tel Aviv University, and Nadia Heninger, University of Pennsylvania with more information at - http://cachebleed.info. + . [CVE-2016-0702][] *Andy Polyakov* @@ -4417,7 +4425,8 @@ OpenSSL 1.0.2 *Emilia Käsper* -### Changes between 1.0.2e and 1.0.2f [28 Jan 2016] ### +### Changes between 1.0.2e and 1.0.2f [28 Jan 2016] + * DH small subgroups Historically OpenSSL only ever generated DH parameters based on "safe" @@ -4463,7 +4472,7 @@ OpenSSL 1.0.2 *Viktor Dukhovni* -### Changes between 1.0.2d and 1.0.2e [3 Dec 2015] ### +### Changes between 1.0.2d and 1.0.2e [3 Dec 2015] * BN_mod_exp may produce incorrect results on x86_64 @@ -4526,7 +4535,7 @@ OpenSSL 1.0.2 *Rich Salz and Ismo Puustinen * -### Changes between 1.0.2c and 1.0.2d [9 Jul 2015] ### +### Changes between 1.0.2c and 1.0.2d [9 Jul 2015] * Alternate chains certificate forgery @@ -4542,7 +4551,7 @@ OpenSSL 1.0.2 *Matt Caswell* -### Changes between 1.0.2b and 1.0.2c [12 Jun 2015] ### +### Changes between 1.0.2b and 1.0.2c [12 Jun 2015] * Fix HMAC ABI incompatibility. The previous version introduced an ABI incompatibility in the handling of HMAC. The previous ABI has now been @@ -4550,7 +4559,7 @@ OpenSSL 1.0.2 *Matt Caswell* -### Changes between 1.0.2a and 1.0.2b [11 Jun 2015] ### +### Changes between 1.0.2a and 1.0.2b [11 Jun 2015] * Malformed ECParameters causes infinite loop @@ -4629,7 +4638,7 @@ OpenSSL 1.0.2 *Emilia Kasper* -### Changes between 1.0.2 and 1.0.2a [19 Mar 2015] ### +### Changes between 1.0.2 and 1.0.2a [19 Mar 2015] * ClientHello sigalgs DoS fix @@ -4805,7 +4814,7 @@ OpenSSL 1.0.2 *Kurt Roeckx* -### Changes between 1.0.1l and 1.0.2 [22 Jan 2015] ### +### Changes between 1.0.1l and 1.0.2 [22 Jan 2015] * Facilitate "universal" ARM builds targeting range of ARM ISAs, e.g. ARMv5 through ARMv8, as opposite to "locking" it to single one. @@ -4956,7 +4965,7 @@ OpenSSL 1.0.2 *Steve Henson* - * SSL_CONF* functions. These provide a common framework for application + * `SSL_CONF*` functions. These provide a common framework for application configuration using configuration files or command lines. *Steve Henson* @@ -5024,7 +5033,6 @@ OpenSSL 1.0.2 Note: if the CERT based stores are not set then the parent SSL_CTX store is used to retain compatibility with existing behaviour. - *Steve Henson* * New function ssl_set_client_disabled to set a ciphersuite disabled @@ -5200,11 +5208,10 @@ OpenSSL 1.0.2 X509_CINF_set_modified, X509_CINF_get_issuer, X509_CINF_get_extensions and X509_CINF_get_signature were reverted post internal team review. - OpenSSL 1.0.1 ------------- -### Changes between 1.0.1t and 1.0.1u [22 Sep 2016] ### +### Changes between 1.0.1t and 1.0.1u [22 Sep 2016] * OCSP Status Request extension unbounded memory growth @@ -5375,7 +5382,7 @@ OpenSSL 1.0.1 *Stephen Henson* -### Changes between 1.0.1s and 1.0.1t [3 May 2016] ### +### Changes between 1.0.1s and 1.0.1t [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check @@ -5403,7 +5410,7 @@ OpenSSL 1.0.1 corruption. Internally to OpenSSL the EVP_EncodeUpdate() function is primarly used by - the PEM_write_bio* family of functions. These are mainly used within the + the `PEM_write_bio*` family of functions. These are mainly used within the OpenSSL command line applications, so any application which processes data from an untrusted source and outputs it as a PEM file should be considered vulnerable to this issue. User applications that call these APIs directly @@ -5480,7 +5487,7 @@ OpenSSL 1.0.1 *Kurt Roeckx* -### Changes between 1.0.1r and 1.0.1s [1 Mar 2016] ### +### Changes between 1.0.1r and 1.0.1s [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. Builds that are not configured with "enable-weak-ssl-ciphers" will not @@ -5565,10 +5572,10 @@ OpenSSL 1.0.1 *Matt Caswell* - * Fix memory issues in BIO_*printf functions + * Fix memory issues in `BIO_*printf` functions The internal |fmtstr| function used in processing a "%s" format string in - the BIO_*printf functions could overflow while calculating the length of a + the `BIO_*printf` functions could overflow while calculating the length of a string and cause an OOB read when printing very long strings. Additionally the internal |doapr_outch| function can attempt to write to an @@ -5580,7 +5587,7 @@ OpenSSL 1.0.1 The first issue may mask the second issue dependent on compiler behaviour. These problems could enable attacks where large amounts of untrusted data - is passed to the BIO_*printf functions. If applications use these functions + is passed to the `BIO_*printf` functions. If applications use these functions in this way then they could be vulnerable. OpenSSL itself uses these functions when printing out human-readable dumps of ASN.1 data. Therefore applications that print this data could be vulnerable if the data is from @@ -5608,7 +5615,7 @@ OpenSSL 1.0.1 This issue was reported to OpenSSL by Yuval Yarom, The University of Adelaide and NICTA, Daniel Genkin, Technion and Tel Aviv University, and Nadia Heninger, University of Pennsylvania with more information at - http://cachebleed.info. + . [CVE-2016-0702][] *Andy Polyakov* @@ -5620,7 +5627,7 @@ OpenSSL 1.0.1 *Emilia Käsper* -### Changes between 1.0.1q and 1.0.1r [28 Jan 2016] ### +### Changes between 1.0.1q and 1.0.1r [28 Jan 2016] * Protection for DH small subgroup attacks @@ -5647,7 +5654,7 @@ OpenSSL 1.0.1 *Kurt Roeckx* -### Changes between 1.0.1p and 1.0.1q [3 Dec 2015] ### +### Changes between 1.0.1p and 1.0.1q [3 Dec 2015] * Certificate verify crash with missing PSS parameter @@ -5690,7 +5697,7 @@ OpenSSL 1.0.1 *Rich Salz and Ismo Puustinen * -### Changes between 1.0.1o and 1.0.1p [9 Jul 2015] ### +### Changes between 1.0.1o and 1.0.1p [9 Jul 2015] * Alternate chains certificate forgery @@ -5717,12 +5724,13 @@ OpenSSL 1.0.1 *Stephen Henson* -### Changes between 1.0.1n and 1.0.1o [12 Jun 2015] ### +### Changes between 1.0.1n and 1.0.1o [12 Jun 2015] + * Fix HMAC ABI incompatibility. The previous version introduced an ABI incompatibility in the handling of HMAC. The previous ABI has now been restored. -### Changes between 1.0.1m and 1.0.1n [11 Jun 2015] ### +### Changes between 1.0.1m and 1.0.1n [11 Jun 2015] * Malformed ECParameters causes infinite loop @@ -5803,7 +5811,7 @@ OpenSSL 1.0.1 *Kurt Roeckx and Emilia Kasper* -### Changes between 1.0.1l and 1.0.1m [19 Mar 2015] ### +### Changes between 1.0.1l and 1.0.1m [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix @@ -5887,13 +5895,13 @@ OpenSSL 1.0.1 *Kurt Roeckx* -### Changes between 1.0.1k and 1.0.1l [15 Jan 2015] ### +### Changes between 1.0.1k and 1.0.1l [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms *Matt Caswell and Richard Levitte* -### Changes between 1.0.1j and 1.0.1k [8 Jan 2015] ### +### Changes between 1.0.1j and 1.0.1k [8 Jan 2015] * Fix DTLS segmentation fault in dtls1_get_record. A carefully crafted DTLS message can cause a segmentation fault in OpenSSL due to a NULL pointer @@ -5998,44 +6006,44 @@ OpenSSL 1.0.1 *Steve Henson* - *) Correct Bignum squaring. Bignum squaring (BN_sqr) may produce incorrect - results on some platforms, including x86_64. This bug occurs at random - with a very low probability, and is not known to be exploitable in any - way, though its exact impact is difficult to determine. Thanks to Pieter - Wuille (Blockstream) who reported this issue and also suggested an initial - fix. Further analysis was conducted by the OpenSSL development team and - Adam Langley of Google. The final fix was developed by Andy Polyakov of - the OpenSSL core team. - [CVE-2014-3570][] + * Correct Bignum squaring. Bignum squaring (BN_sqr) may produce incorrect + results on some platforms, including x86_64. This bug occurs at random + with a very low probability, and is not known to be exploitable in any + way, though its exact impact is difficult to determine. Thanks to Pieter + Wuille (Blockstream) who reported this issue and also suggested an initial + fix. Further analysis was conducted by the OpenSSL development team and + Adam Langley of Google. The final fix was developed by Andy Polyakov of + the OpenSSL core team. + [CVE-2014-3570][] *Andy Polyakov* - *) Do not resume sessions on the server if the negotiated protocol - version does not match the session's version. Resuming with a different - version, while not strictly forbidden by the RFC, is of questionable - sanity and breaks all known clients. + * Do not resume sessions on the server if the negotiated protocol + version does not match the session's version. Resuming with a different + version, while not strictly forbidden by the RFC, is of questionable + sanity and breaks all known clients. *David Benjamin, Emilia Käsper* - *) Tighten handling of the ChangeCipherSpec (CCS) message: reject - early CCS messages during renegotiation. (Note that because - renegotiation is encrypted, this early CCS was not exploitable.) + * Tighten handling of the ChangeCipherSpec (CCS) message: reject + early CCS messages during renegotiation. (Note that because + renegotiation is encrypted, this early CCS was not exploitable.) *Emilia Käsper* - *) Tighten client-side session ticket handling during renegotiation: - ensure that the client only accepts a session ticket if the server sends - the extension anew in the ServerHello. Previously, a TLS client would - reuse the old extension state and thus accept a session ticket if one was - announced in the initial ServerHello. + * Tighten client-side session ticket handling during renegotiation: + ensure that the client only accepts a session ticket if the server sends + the extension anew in the ServerHello. Previously, a TLS client would + reuse the old extension state and thus accept a session ticket if one was + announced in the initial ServerHello. - Similarly, ensure that the client requires a session ticket if one - was advertised in the ServerHello. Previously, a TLS client would - ignore a missing NewSessionTicket message. + Similarly, ensure that the client requires a session ticket if one + was advertised in the ServerHello. Previously, a TLS client would + ignore a missing NewSessionTicket message. *Emilia Käsper* -### Changes between 1.0.1i and 1.0.1j [15 Oct 2014] ### +### Changes between 1.0.1i and 1.0.1j [15 Oct 2014] * SRTP Memory Leak. @@ -6088,10 +6096,9 @@ OpenSSL 1.0.1 Note: this is a precautionary measure and no attacks are currently known. - *Steve Henson* -### Changes between 1.0.1h and 1.0.1i [6 Aug 2014] ### +### Changes between 1.0.1h and 1.0.1i [6 Aug 2014] * Fix SRP buffer overrun vulnerability. Invalid parameters passed to the SRP code can be overrun an internal buffer. Add sanity check that @@ -6187,7 +6194,7 @@ OpenSSL 1.0.1 *Bodo Moeller* -### Changes between 1.0.1g and 1.0.1h [5 Jun 2014] ### +### Changes between 1.0.1g and 1.0.1h [5 Jun 2014] * Fix for SSL/TLS MITM flaw. An attacker using a carefully crafted handshake can force the use of weak keying material in OpenSSL @@ -6238,7 +6245,7 @@ OpenSSL 1.0.1 *mancha * -### Changes between 1.0.1f and 1.0.1g [7 Apr 2014] ### +### Changes between 1.0.1f and 1.0.1g [7 Apr 2014] * A missing bounds check in the handling of the TLS heartbeat extension can be used to reveal up to 64k of memory to a connected client or @@ -6253,7 +6260,7 @@ OpenSSL 1.0.1 * Fix for the attack described in the paper "Recovering OpenSSL ECDSA Nonces Using the FLUSH+RELOAD Cache Side-channel Attack" by Yuval Yarom and Naomi Benger. Details can be obtained from: - http://eprint.iacr.org/2014/140 + Thanks to Yuval Yarom and Naomi Benger for discovering this flaw and to Yuval Yarom for supplying a fix [CVE-2014-0076][] @@ -6267,10 +6274,9 @@ OpenSSL 1.0.1 less that 512 pad with a dummy extension containing zeroes so it is at least 512 bytes long. - *Adam Langley, Steve Henson* -### Changes between 1.0.1e and 1.0.1f [6 Jan 2014] ### +### Changes between 1.0.1e and 1.0.1f [6 Jan 2014] * Fix for TLS record tampering bug. A carefully crafted invalid handshake could crash OpenSSL with a NULL pointer exception. @@ -6292,20 +6298,20 @@ OpenSSL 1.0.1 *Rob Stradling, Adam Langley* -### Changes between 1.0.1d and 1.0.1e [11 Feb 2013] ### +### Changes between 1.0.1d and 1.0.1e [11 Feb 2013] * Correct fix for CVE-2013-0169. The original didn't work on AES-NI supporting platforms or when small records were transferred. *Andy Polyakov, Steve Henson* -### Changes between 1.0.1c and 1.0.1d [5 Feb 2013] ### +### Changes between 1.0.1c and 1.0.1d [5 Feb 2013] * Make the decoding of SSLv3, TLS and DTLS CBC records constant time. This addresses the flaw in CBC record processing discovered by Nadhem Alfardan and Kenny Paterson. Details of this attack can be found - at: http://www.isg.rhul.ac.uk/tls/ + at: Thanks go to Nadhem Alfardan and Kenny Paterson of the Information Security Group at Royal Holloway, University of London @@ -6336,7 +6342,7 @@ OpenSSL 1.0.1 * Call OCSP Stapling callback after ciphersuite has been chosen, so the right response is stapled. Also change SSL_get_certificate() so it returns the certificate actually sent. - See http://rt.openssl.org/Ticket/Display.html?id=2836. + See . *Rob Stradling * @@ -6349,7 +6355,7 @@ OpenSSL 1.0.1 *Steve Henson* -### Changes between 1.0.1b and 1.0.1c [10 May 2012] ### +### Changes between 1.0.1b and 1.0.1c [10 May 2012] * Sanity check record length before skipping explicit IV in TLS 1.2, 1.1 and DTLS to fix DoS attack. @@ -6370,7 +6376,7 @@ OpenSSL 1.0.1 *Steve Henson* -### Changes between 1.0.1a and 1.0.1b [26 Apr 2012] ### +### Changes between 1.0.1a and 1.0.1b [26 Apr 2012] * OpenSSL 1.0.0 sets SSL_OP_ALL to 0x80000FFFL and OpenSSL 1.0.1 and 1.0.1a set SSL_OP_NO_TLSv1_1 to 0x00000400L which would unfortunately @@ -6395,7 +6401,7 @@ OpenSSL 1.0.1 *Andy Polyakov* -### Changes between 1.0.1 and 1.0.1a [19 Apr 2012] ### +### Changes between 1.0.1 and 1.0.1a [19 Apr 2012] * Check for potentially exploitable overflows in asn1_d2i_read_bio BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer @@ -6430,7 +6436,7 @@ OpenSSL 1.0.1 *Andy Polyakov* -### Changes between 1.0.0h and 1.0.1 [14 Mar 2012] ### +### Changes between 1.0.0h and 1.0.1 [14 Mar 2012] * Add compatibility with old MDC2 signatures which use an ASN1 OCTET STRING form instead of a DigestInfo. @@ -6467,12 +6473,12 @@ OpenSSL 1.0.1 * Extensive assembler packs updates, most notably: - - x86[_64]: AES-NI, PCLMULQDQ, RDRAND support; - - x86[_64]: SSSE3 support (SHA1, vector-permutation AES); - - x86_64: bit-sliced AES implementation; - - ARM: NEON support, contemporary platforms optimizations; - - s390x: z196 support; - - *: GHASH and GF(2^m) multiplication implementations; + - x86[_64]: AES-NI, PCLMULQDQ, RDRAND support; + - x86[_64]: SSSE3 support (SHA1, vector-permutation AES); + - x86_64: bit-sliced AES implementation; + - ARM: NEON support, contemporary platforms optimizations; + - s390x: z196 support; + - `*`: GHASH and GF(2^m) multiplication implementations; *Andy Polyakov* @@ -6490,7 +6496,7 @@ OpenSSL 1.0.1 *Eric Rescorla* * Add Next Protocol Negotiation, - http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-00. Can be + . Can be disabled with a no-npn flag to config or Configure. Code donated by Google. @@ -6598,7 +6604,7 @@ OpenSSL 1.0.1 * Add GCM support to TLS library. Some custom code is needed to split the IV between the fixed (from PRF) and explicit (from TLS record) portions. This adds all GCM ciphersuites supported by RFC5288 and - RFC5289. Generalise some AES* cipherstrings to include GCM and + RFC5289. Generalise some `AES*` cipherstrings to include GCM and add a special AESGCM string for GCM only. *Steve Henson* @@ -6660,7 +6666,7 @@ OpenSSL 1.0.1 * Low level digest APIs are not approved in FIPS mode: any attempt to use these will cause a fatal error. Applications that *really* want - to use them can use the private_* version instead. + to use them can use the `private_*` version instead. *Steve Henson* @@ -6772,7 +6778,7 @@ OpenSSL 1.0.1 OpenSSL 1.0.0 ------------- -### Changes between 1.0.0s and 1.0.0t [3 Dec 2015] ### +### Changes between 1.0.0s and 1.0.0t [3 Dec 2015] * X509_ATTRIBUTE memory leak @@ -6797,7 +6803,7 @@ OpenSSL 1.0.0 *Stephen Henson* -### Changes between 1.0.0r and 1.0.0s [11 Jun 2015] ### +### Changes between 1.0.0r and 1.0.0s [11 Jun 2015] * Malformed ECParameters causes infinite loop @@ -6870,7 +6876,7 @@ OpenSSL 1.0.0 *Matt Caswell* -### Changes between 1.0.0q and 1.0.0r [19 Mar 2015] ### +### Changes between 1.0.0q and 1.0.0r [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix @@ -6954,13 +6960,13 @@ OpenSSL 1.0.0 *Kurt Roeckx* -### Changes between 1.0.0p and 1.0.0q [15 Jan 2015] ### +### Changes between 1.0.0p and 1.0.0q [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms *Matt Caswell and Richard Levitte* -### Changes between 1.0.0o and 1.0.0p [8 Jan 2015] ### +### Changes between 1.0.0o and 1.0.0p [8 Jan 2015] * Fix DTLS segmentation fault in dtls1_get_record. A carefully crafted DTLS message can cause a segmentation fault in OpenSSL due to a NULL pointer @@ -7019,17 +7025,17 @@ OpenSSL 1.0.0 *Steve Henson* - *) Correct Bignum squaring. Bignum squaring (BN_sqr) may produce incorrect - results on some platforms, including x86_64. This bug occurs at random - with a very low probability, and is not known to be exploitable in any - way, though its exact impact is difficult to determine. Thanks to Pieter - Wuille (Blockstream) who reported this issue and also suggested an initial - fix. Further analysis was conducted by the OpenSSL development team and - Adam Langley of Google. The final fix was developed by Andy Polyakov of - the OpenSSL core team. - [CVE-2014-3570][] + * Correct Bignum squaring. Bignum squaring (BN_sqr) may produce incorrect + results on some platforms, including x86_64. This bug occurs at random + with a very low probability, and is not known to be exploitable in any + way, though its exact impact is difficult to determine. Thanks to Pieter + Wuille (Blockstream) who reported this issue and also suggested an initial + fix. Further analysis was conducted by the OpenSSL development team and + Adam Langley of Google. The final fix was developed by Andy Polyakov of + the OpenSSL core team. + [CVE-2014-3570][] - *Andy Polyakov* + *Andy Polyakov* * Fix various certificate fingerprint issues. @@ -7069,7 +7075,7 @@ OpenSSL 1.0.0 *Steve Henson* -### Changes between 1.0.0n and 1.0.0o [15 Oct 2014] ### +### Changes between 1.0.0n and 1.0.0o [15 Oct 2014] * Session Ticket Memory Leak. @@ -7107,10 +7113,9 @@ OpenSSL 1.0.0 Note: this is a precautionary measure and no attacks are currently known. - *Steve Henson* -### Changes between 1.0.0m and 1.0.0n [6 Aug 2014] ### +### Changes between 1.0.0m and 1.0.0n [6 Aug 2014] * OpenSSL DTLS clients enabling anonymous (EC)DH ciphersuites are subject to a denial of service attack. A malicious server can crash the client @@ -7173,7 +7178,7 @@ OpenSSL 1.0.0 *Bodo Moeller* -### Changes between 1.0.0l and 1.0.0m [5 Jun 2014] ### +### Changes between 1.0.0l and 1.0.0m [5 Jun 2014] * Fix for SSL/TLS MITM flaw. An attacker using a carefully crafted handshake can force the use of weak keying material in OpenSSL @@ -7227,14 +7232,14 @@ OpenSSL 1.0.0 * Fix for the attack described in the paper "Recovering OpenSSL ECDSA Nonces Using the FLUSH+RELOAD Cache Side-channel Attack" by Yuval Yarom and Naomi Benger. Details can be obtained from: - http://eprint.iacr.org/2014/140 + Thanks to Yuval Yarom and Naomi Benger for discovering this flaw and to Yuval Yarom for supplying a fix [CVE-2014-0076][] *Yuval Yarom and Naomi Benger* -### Changes between 1.0.0k and 1.0.0l [6 Jan 2014] ### +### Changes between 1.0.0k and 1.0.0l [6 Jan 2014] * Keep original DTLS digest and encryption contexts in retransmission structures so we can use the previous session parameters if they need @@ -7251,13 +7256,13 @@ OpenSSL 1.0.0 *Rob Stradling, Adam Langley* -### Changes between 1.0.0j and 1.0.0k [5 Feb 2013] ### +### Changes between 1.0.0j and 1.0.0k [5 Feb 2013] * Make the decoding of SSLv3, TLS and DTLS CBC records constant time. This addresses the flaw in CBC record processing discovered by Nadhem Alfardan and Kenny Paterson. Details of this attack can be found - at: http://www.isg.rhul.ac.uk/tls/ + at: Thanks go to Nadhem Alfardan and Kenny Paterson of the Information Security Group at Royal Holloway, University of London @@ -7275,7 +7280,7 @@ OpenSSL 1.0.0 * Call OCSP Stapling callback after ciphersuite has been chosen, so the right response is stapled. Also change SSL_get_certificate() so it returns the certificate actually sent. - See http://rt.openssl.org/Ticket/Display.html?id=2836. + See . (This is a backport) *Rob Stradling * @@ -7284,7 +7289,7 @@ OpenSSL 1.0.0 *Steve Henson* -### Changes between 1.0.0i and 1.0.0j [10 May 2012] ### +### Changes between 1.0.0i and 1.0.0j [10 May 2012] [NB: OpenSSL 1.0.0i and later 1.0.0 patch levels were released after OpenSSL 1.0.1.] @@ -7303,7 +7308,7 @@ OpenSSL 1.0.1.] *Steve Henson* -### Changes between 1.0.0h and 1.0.0i [19 Apr 2012] ### +### Changes between 1.0.0h and 1.0.0i [19 Apr 2012] * Check for potentially exploitable overflows in asn1_d2i_read_bio BUF_mem_grow and BUF_mem_grow_clean. Refuse attempts to shrink buffer @@ -7315,7 +7320,7 @@ OpenSSL 1.0.1.] *Adam Langley (Google), Tavis Ormandy, Google Security Team* -### Changes between 1.0.0g and 1.0.0h [12 Mar 2012] ### +### Changes between 1.0.0g and 1.0.0h [12 Mar 2012] * Fix MMA (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) weakness in CMS and PKCS7 code. When RSA decryption fails use a random key for @@ -7335,7 +7340,7 @@ OpenSSL 1.0.1.] *Steve Henson* -### Changes between 1.0.0f and 1.0.0g [18 Jan 2012] ### +### Changes between 1.0.0f and 1.0.0g [18 Jan 2012] * Fix for DTLS DoS issue introduced by fix for CVE-2011-4109. Thanks to Antonio Martin, Enterprise Secure Access Research and @@ -7344,7 +7349,7 @@ OpenSSL 1.0.1.] *Antonio Martin* -### Changes between 1.0.0e and 1.0.0f [4 Jan 2012] ### +### Changes between 1.0.0e and 1.0.0f [4 Jan 2012] * Nadhem Alfardan and Kenny Paterson have discovered an extension of the Vaudenay padding oracle attack on CBC mode encryption @@ -7352,7 +7357,7 @@ OpenSSL 1.0.1.] the OpenSSL implementation of DTLS. Their attack exploits timing differences arising during decryption processing. A research paper describing this attack can be found at: - http://www.isg.rhul.ac.uk/~kp/dtls.pdf + Thanks go to Nadhem Alfardan and Kenny Paterson of the Information Security Group at Royal Holloway, University of London (www.isg.rhul.ac.uk) for discovering this flaw and to Robin Seggelmann @@ -7395,7 +7400,7 @@ OpenSSL 1.0.1.] *Emilia Käsper (Google)* * Fix the BIO_f_buffer() implementation (which was mixing different - interpretations of the '..._len' fields). + interpretations of the `..._len` fields). *Adam Langley (Google)* @@ -7414,7 +7419,7 @@ OpenSSL 1.0.1.] *Bob Buckholz (Google)* -### Changes between 1.0.0d and 1.0.0e [6 Sep 2011] ### +### Changes between 1.0.0d and 1.0.0e [6 Sep 2011] * Fix bug where CRLs with nextUpdate in the past are sometimes accepted by initialising X509_STORE_CTX properly. [CVE-2011-3207][] @@ -7438,13 +7443,11 @@ OpenSSL 1.0.1.] * Add protection against ECDSA timing attacks as mentioned in the paper by Billy Bob Brumley and Nicola Tuveri, see: - - http://eprint.iacr.org/2011/232.pdf - + *Billy Bob Brumley and Nicola Tuveri* -### Changes between 1.0.0c and 1.0.0d [8 Feb 2011] ### +### Changes between 1.0.0c and 1.0.0d [8 Feb 2011] * Fix parsing of OCSP stapling ClientHello extension. CVE-2011-0014 @@ -7456,7 +7459,7 @@ OpenSSL 1.0.1.] *Steve Henson* -### Changes between 1.0.0b and 1.0.0c [2 Dec 2010] ### +### Changes between 1.0.0b and 1.0.0c [2 Dec 2010] * Disable code workaround for ancient and obsolete Netscape browsers and servers: an attacker can use it in a ciphersuite downgrade attack. @@ -7470,7 +7473,7 @@ OpenSSL 1.0.1.] *Ben Laurie* -### Changes between 1.0.0a and 1.0.0b [16 Nov 2010] ### +### Changes between 1.0.0a and 1.0.0b [16 Nov 2010] * Fix extension code to avoid race conditions which can result in a buffer overrun vulnerability: resumed sessions must not be modified as they can @@ -7483,14 +7486,14 @@ OpenSSL 1.0.1.] *Steve Henson* -### Changes between 1.0.0 and 1.0.0a [01 Jun 2010] ### +### Changes between 1.0.0 and 1.0.0a [01 Jun 2010] * Check return value of int_rsa_verify in pkey_rsa_verifyrecover [CVE-2010-1633][] *Steve Henson, Peter-Michael Hager * -### Changes between 0.9.8n and 1.0.0 [29 Mar 2010] ### +### Changes between 0.9.8n and 1.0.0 [29 Mar 2010] * Add "missing" function EVP_CIPHER_CTX_copy(). This copies a cipher context. The operation can be customised via the ctrl mechanism in @@ -7566,7 +7569,7 @@ OpenSSL 1.0.1.] * Add "missing" function EVP_MD_flags() (without this the only way to retrieve a digest flags is by accessing the structure directly. Update - EVP_MD_do_all*() and EVP_CIPHER_do_all*() to include the name a digest + `EVP_MD_do_all*()` and `EVP_CIPHER_do_all*()` to include the name a digest or cipher is registered as in the "from" argument. Print out all registered digests in the dgst usage message instead of manually attempting to work them out. @@ -7600,7 +7603,6 @@ OpenSSL 1.0.1.] and this works for ENGINE based algorithms too. - *Steve Henson* * Update Gost ENGINE to support parameter files. @@ -7653,7 +7655,7 @@ OpenSSL 1.0.1.] * New function OPENSSL_gmtime_adj() to add a specific number of days and seconds to a tm structure directly, instead of going through OS specific date routines. This avoids any issues with OS routines such - as the year 2038 bug. New *_adj() functions for ASN1 time structures + as the year 2038 bug. New `*_adj()` functions for ASN1 time structures and X509_time_adj_ex() to cover the extended range. The existing X509_time_adj() is still usable and will no longer have any date issues. @@ -7871,13 +7873,11 @@ OpenSSL 1.0.1.] SSL_set_options(ssl, SSL_OP_NO_SSLv2) is especially recommended for applications that need to enforce opaque PRF input. - *Bodo Moeller* * Update ssl code to support digests other than SHA1+MD5 for handshake MAC. - *Victor B. Wagner * * Add RFC4507 support to OpenSSL. This includes the corrections in @@ -7921,7 +7921,7 @@ OpenSSL 1.0.1.] *Steve Henson* * Experimental support for use of HMAC via EVP_PKEY interface. This - allows HMAC to be handled via the EVP_DigestSign*() interface. The + allows HMAC to be handled via the `EVP_DigestSign*()` interface. The EVP_PKEY "key" in this case is the HMAC key, potentially allowing ENGINE support for HMAC keys which are unextractable. New -mac and -macopt options to dgst utility. @@ -7929,7 +7929,7 @@ OpenSSL 1.0.1.] *Steve Henson* * New option -sigopt to dgst utility. Update dgst to use - EVP_Digest{Sign,Verify}*. These two changes make it possible to use + `EVP_Digest{Sign,Verify}*`. These two changes make it possible to use alternative signing parameters such as X9.31 or PSS in the dgst utility. @@ -8138,7 +8138,6 @@ OpenSSL 1.0.1.] AECDH - anonymous ECDH EECDH - non-anonymous ephemeral ECDH (equivalent to "kEECDH:-AECDH") - *Bodo Moeller* * Add additional S/MIME capabilities for AES and GOST ciphers if supported. @@ -8157,8 +8156,8 @@ OpenSSL 1.0.1.] *Steve Henson* - * New functions EVP_Digest{Sign,Verify)*. These are enhanced versions of - EVP_{Sign,Verify}* which allow an application to customise the signature + * New functions `EVP_Digest{Sign,Verify)*`. These are enhanced versions of + `EVP_{Sign,Verify}*` which allow an application to customise the signature process. *Steve Henson* @@ -8266,8 +8265,8 @@ OpenSSL 1.0.1.] *Steve Henson* * Add functions for main EVP_PKEY_method operations. The undocumented - functions EVP_PKEY_{encrypt,decrypt} have been renamed to - EVP_PKEY_{encrypt,decrypt}_old. + functions `EVP_PKEY_{encrypt,decrypt}` have been renamed to + `EVP_PKEY_{encrypt,decrypt}_old`. *Steve Henson* @@ -8333,7 +8332,6 @@ OpenSSL 1.0.1.] SSL_get_psk_identity SSL_use_psk_identity_hint - *Mika Kousa and Pasi Eronen of Nokia Corporation* * Add RFC 3161 compliant time stamp request creation, response generation @@ -8344,7 +8342,7 @@ OpenSSL 1.0.1.] * Add initial support for TLS extensions, specifically for the server_name extension so far. The SSL_SESSION, SSL_CTX, and SSL data structures now have new members for a host name. The SSL data structure has an - additional member SSL_CTX *initial_ctx so that new sessions can be + additional member `SSL_CTX *initial_ctx` so that new sessions can be stored in that context to allow for session resumption, even after the SSL has been switched to a new SSL_CTX in reaction to a client's server_name extension. @@ -8373,7 +8371,6 @@ OpenSSL 1.0.1.] default is a warning; it becomes fatal with the '-servername_fatal' option. - *Peter Sylvester, Remy Allais, Christophe Renou* * Whirlpool hash implementation is added. @@ -8458,7 +8455,7 @@ OpenSSL 1.0.1.] OpenSSL 0.9.x ------------- -### Changes between 0.9.8m and 0.9.8n [24 Mar 2010] ### +### Changes between 0.9.8m and 0.9.8n [24 Mar 2010] * When rejecting SSL/TLS records due to an incorrect version number, never update s->server with a new major version number. As of @@ -8475,7 +8472,7 @@ OpenSSL 0.9.x *Tomas Hoger * -### Changes between 0.9.8l and 0.9.8m [25 Feb 2010] ### +### Changes between 0.9.8l and 0.9.8m [25 Feb 2010] * Always check bn_wexpand() return values for failure. [CVE-2009-3245][] @@ -8659,11 +8656,11 @@ OpenSSL 0.9.x *Darryl Miles * - * Add 2.5.4.* OIDs + * Add `2.5.4.*` OIDs *Ilya O. * -### Changes between 0.9.8k and 0.9.8l [5 Nov 2009] ### +### Changes between 0.9.8k and 0.9.8l [5 Nov 2009] * Disable renegotiation completely - this fixes a severe security problem [CVE-2009-3555][] at the cost of breaking all @@ -8674,10 +8671,10 @@ OpenSSL 0.9.x *Ben Laurie* -### Changes between 0.9.8j and 0.9.8k [25 Mar 2009] ### +### Changes between 0.9.8j and 0.9.8k [25 Mar 2009] * Don't set val to NULL when freeing up structures, it is freed up by - underlying code. If sizeof(void *) > sizeof(long) this can result in + underlying code. If `sizeof(void *) > sizeof(long)` this can result in zeroing past the valid field. [CVE-2009-0789][] *Paolo Ganci * @@ -8728,7 +8725,7 @@ OpenSSL 0.9.x *Ben Laurie* -### Changes between 0.9.8i and 0.9.8j [07 Jan 2009] ### +### Changes between 0.9.8i and 0.9.8j [07 Jan 2009] * Properly check EVP_VerifyFinal() and similar return values [CVE-2008-5077][]. @@ -8775,7 +8772,7 @@ OpenSSL 0.9.x *Bodo Moeller* -### Changes between 0.9.8h and 0.9.8i [15 Sep 2008] ### +### Changes between 0.9.8h and 0.9.8i [15 Sep 2008] * Fix NULL pointer dereference if a DTLS server received ChangeCipherSpec as first record [CVE-2009-1386][]. @@ -8783,7 +8780,7 @@ OpenSSL 0.9.x *PR #1679* * Fix a state transition in s3_srvr.c and d1_srvr.c - (was using SSL3_ST_CW_CLNT_HELLO_B, should be ..._ST_SW_SRVR_...). + (was using SSL3_ST_CW_CLNT_HELLO_B, should be `..._ST_SW_SRVR_...`). *Nagendra Modadugu* @@ -8795,7 +8792,6 @@ OpenSSL 0.9.x So now fix this for real by retiring the MONT_HELPER macro in crypto/rsa/rsa_eay.c. - *Bodo Moeller; problem pointed out by Marius Schilder* * Various precautionary measures: @@ -8812,7 +8808,6 @@ OpenSSL 0.9.x - Enforce the 'num' check in BN_div() (bn_div.c) for non-BN_DEBUG builds. - *Neel Mehta, Bodo Moeller* * Allow engines to be "soft loaded" - i.e. optionally don't die if @@ -8849,7 +8844,7 @@ OpenSSL 0.9.x *Steve Henson* -### Changes between 0.9.8g and 0.9.8h [28 May 2008] ### +### Changes between 0.9.8g and 0.9.8h [28 May 2008] * Fix flaw if 'Server Key exchange message' is omitted from a TLS handshake which could lead to a client crash as found using the @@ -8904,7 +8899,6 @@ OpenSSL 0.9.x namely BN_from_montgomery_word. (To enable this otherwise, e.g. x86_64, try `-DMONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD`.) - *Andy Polyakov (backport partially by Bodo Moeller)* * Add TLS session ticket callback. This allows an application to set @@ -9001,7 +8995,7 @@ OpenSSL 0.9.x *Steve Henson* -### Changes between 0.9.8f and 0.9.8g [19 Oct 2007] ### +### Changes between 0.9.8f and 0.9.8g [19 Oct 2007] * Fix various bugs: + Binary incompatibility of ssl_ctx_st structure @@ -9011,7 +9005,7 @@ OpenSSL 0.9.x *Andy Polyakov, Steve Henson* -### Changes between 0.9.8e and 0.9.8f [11 Oct 2007] ### +### Changes between 0.9.8e and 0.9.8f [11 Oct 2007] * DTLS Handshake overhaul. There were longstanding issues with OpenSSL DTLS implementation, which were making it impossible for @@ -9055,7 +9049,7 @@ OpenSSL 0.9.x * Add initial support for TLS extensions, specifically for the server_name extension so far. The SSL_SESSION, SSL_CTX, and SSL data structures now have new members for a host name. The SSL data structure has an - additional member SSL_CTX *initial_ctx so that new sessions can be + additional member `SSL_CTX *initial_ctx` so that new sessions can be stored in that context to allow for session resumption, even after the SSL has been switched to a new SSL_CTX in reaction to a client's server_name extension. @@ -9084,7 +9078,6 @@ OpenSSL 0.9.x default is a warning; it becomes fatal with the '-servername_fatal' option. - *Peter Sylvester, Remy Allais, Christophe Renou, Steve Henson* * Add AES and SSE2 assembly language support to VC++ build. @@ -9109,7 +9102,7 @@ OpenSSL 0.9.x *Dean Gaudet (Google)* * Add the Korean symmetric 128-bit cipher SEED (see - http://www.kisa.or.kr/kisa/seed/jsp/seed_eng.jsp) and + ) and add SEED ciphersuites from RFC 4162: TLS_RSA_WITH_SEED_CBC_SHA = "SEED-SHA" @@ -9126,7 +9119,7 @@ OpenSSL 0.9.x * Mitigate branch prediction attacks, which can be practical if a single processor is shared, allowing a spy process to extract information. For detailed background information, see - http://eprint.iacr.org/2007/039 (O. Aciicmez, S. Gueron, + (O. Aciicmez, S. Gueron, J.-P. Seifert, "New Branch Prediction Vulnerabilities in OpenSSL and Necessary Software Countermeasures"). The core of the change are new versions BN_div_no_branch() and @@ -9151,14 +9144,13 @@ OpenSSL 0.9.x BN_BLINDING_new() will now use BN_dup() for the modulus so that the BN_BLINDING structure gets an independent copy of the - modulus. This means that the previous "BIGNUM *m" argument to + modulus. This means that the previous `BIGNUM *m` argument to BN_BLINDING_new() and to BN_BLINDING_create_param() now - essentially becomes "const BIGNUM *m", although we can't actually + essentially becomes `const BIGNUM *m`, although we can't actually change this in the header file before 0.9.9. It allows RSA_setup_blinding() to use BN_with_flags() on the modulus to enable BN_FLG_CONSTTIME. - *Matthew D Wood (Intel Corp)* * In the SSL/TLS server implementation, be strict about session ID @@ -9183,7 +9175,7 @@ OpenSSL 0.9.x not complete and could lead to a possible single byte overflow [CVE-2007-5135][] [Ben Laurie] -### Changes between 0.9.8d and 0.9.8e [23 Feb 2007] ### +### Changes between 0.9.8d and 0.9.8e [23 Feb 2007] * Since AES128 and AES256 (and similarly Camellia128 and Camellia256) share a single mask bit in the logic of @@ -9225,7 +9217,7 @@ OpenSSL 0.9.x *Goetz Babin-Ebell* -### Changes between 0.9.8c and 0.9.8d [28 Sep 2006] ### +### Changes between 0.9.8c and 0.9.8d [28 Sep 2006] * Introduce limits to prevent malicious keys being able to cause a denial of service. [CVE-2006-2940][] @@ -9268,10 +9260,9 @@ OpenSSL 0.9.x definition to split the single 'unsigned long mask' bitmap into multiple values to extend the available space. - *Bodo Moeller* -### Changes between 0.9.8b and 0.9.8c [05 Sep 2006] ### +### Changes between 0.9.8b and 0.9.8c [05 Sep 2006] * Avoid PKCS #1 v1.5 signature attack discovered by Daniel Bleichenbacher [CVE-2006-4339][] [Ben Laurie and Google Security Team] @@ -9298,9 +9289,9 @@ OpenSSL 0.9.x * Disable rogue ciphersuites: - - SSLv2 0x08 0x00 0x80 ("RC4-64-MD5") - - SSLv3/TLSv1 0x00 0x61 ("EXP1024-RC2-CBC-MD5") - - SSLv3/TLSv1 0x00 0x60 ("EXP1024-RC4-MD5") + - SSLv2 0x08 0x00 0x80 ("RC4-64-MD5") + - SSLv3/TLSv1 0x00 0x61 ("EXP1024-RC2-CBC-MD5") + - SSLv3/TLSv1 0x00 0x60 ("EXP1024-RC4-MD5") The latter two were purportedly from draft-ietf-tls-56-bit-ciphersuites-0[01].txt, but do not really @@ -9319,7 +9310,7 @@ OpenSSL 0.9.x * Add the symmetric cipher Camellia (128-bit, 192-bit, 256-bit key versions), which is now available for royalty-free use - (see http://info.isl.ntt.co.jp/crypt/eng/info/chiteki.html). + (see ). Also, add Camellia TLS ciphersuites from RFC 4132. To minimize changes between patchlevels in the OpenSSL 0.9.8 @@ -9337,7 +9328,7 @@ OpenSSL 0.9.x *Steve Henson* -### Changes between 0.9.8a and 0.9.8b [04 May 2006] ### +### Changes between 0.9.8a and 0.9.8b [04 May 2006] * When applying a cipher rule check to see if string match is an explicit cipher suite and only match that one cipher suite if it is. @@ -9363,7 +9354,7 @@ OpenSSL 0.9.x * Fixes and enhancements to zlib compression code. We now only use "zlib1.dll" and use the default `__cdecl` calling convention on Win32 to conform with the standards mentioned here: - http://www.zlib.net/DLL_FAQ.txt + Static zlib linking now works on Windows and the new --with-zlib-include --with-zlib-lib options to Configure can be used to supply the location of the headers and library. Gracefully handle case where zlib library @@ -9388,7 +9379,7 @@ OpenSSL 0.9.x *Richard Levitte* -### Changes between 0.9.8 and 0.9.8a [11 Oct 2005] ### +### Changes between 0.9.8 and 0.9.8a [11 Oct 2005] * Remove the functionality of SSL_OP_MSIE_SSLV2_RSA_PADDING (part of SSL_OP_ALL). This option used to disable the @@ -9398,7 +9389,7 @@ OpenSSL 0.9.x *Bodo Moeller; problem pointed out by Yutaka Oiwa (Research Center for Information Security, National Institute of Advanced Industrial - Science and Technology [AIST*, Japan)] + Science and Technology [AIST], Japan)* * Add two function to clear and return the verify parameter flags. @@ -9432,7 +9423,7 @@ OpenSSL 0.9.x *Steve Henson* -### Changes between 0.9.7h and 0.9.8 [05 Jul 2005] ### +### Changes between 0.9.7h and 0.9.8 [05 Jul 2005] [NB: OpenSSL 0.9.7i and later 0.9.7 patch levels were released after OpenSSL 0.9.8.] @@ -9522,7 +9513,6 @@ OpenSSL 0.9.8.] fee for non-commercial use. As before, "no-idea" can be used to avoid this algorithm.) - *Bodo Moeller* * Add processing of proxy certificates (see RFC 3820). This work was @@ -9545,7 +9535,6 @@ OpenSSL 0.9.8.] The blank line is mandatory. - *Steve Henson* * New arguments -certform, -keyform and -pass for s_client and s_server @@ -9569,7 +9558,7 @@ OpenSSL 0.9.8.] *Michal Ludvig , with help from Andy Polyakov* - * Deprecate BN_[get|set]_params() functions (they were ignored internally). + * Deprecate `BN_[get|set]_params()` functions (they were ignored internally). *Geoff Thorpe* @@ -9718,7 +9707,7 @@ OpenSSL 0.9.8.] to clean up those corresponding objects before destroying the hash table (and losing the object pointers). So some over-zealous constifications in LHASH have been relaxed so that lh_insert() does not take (nor store) the - objects as "const" and the lh_doall[_arg] callback wrappers are not + objects as "const" and the `lh_doall[_arg]` callback wrappers are not prototyped to have "const" restrictions on the object pointers they are given (and so aren't required to cast them away any more). @@ -9727,8 +9716,9 @@ OpenSSL 0.9.8.] * The tmdiff.h API was so ugly and minimal that our own timing utility (speed) prefers to use its own implementation. The two implementations haven't been consolidated as yet (volunteers?) but the tmdiff API has had - its object type properly exposed (MS_TM) instead of casting to/from "char - *". This may still change yet if someone realises MS_TM and "ms_time_***" + its object type properly exposed (MS_TM) instead of casting to/from + `char *`. This may still change yet if someone realises MS_TM and + `ms_time_***` aren't necessarily the greatest nomenclatures - but this is what was used internally to the implementation so I've used that for now. @@ -9961,7 +9951,7 @@ OpenSSL 0.9.8.] * Change the "progress" mechanism used in key-generation and primality testing to functions that take a new BN_GENCB pointer in - place of callback/argument pairs. The new API functions have "_ex" + place of callback/argument pairs. The new API functions have `_ex` postfixes and the older functions are reimplemented as wrappers for the new ones. The OPENSSL_NO_DEPRECATED symbol can be used to hide declarations of the old functions to help (graceful) attempts to @@ -10122,8 +10112,7 @@ OpenSSL 0.9.8.] * Add named elliptic curves over binary fields from X9.62, SECG, and WAP/WTLS; add OIDs that were still missing. - *Sheueling Chang Shantz and Douglas Stebila - (Sun Microsystems Laboratories)* + *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Extend the EC library for elliptic curves over binary fields (new files ec2_smpl.c, ec2_smpt.c, ec2_mult.c in crypto/ec/). @@ -10147,16 +10136,15 @@ OpenSSL 0.9.8.] As binary polynomials are represented as BIGNUMs, various members of the EC_GROUP and EC_POINT data structures can be shared between the implementations for prime fields and binary fields; - the above ..._GF2m functions (except for EX_GROUP_new_curve_GF2m) - are essentially identical to their ..._GFp counterparts. - (For simplicity, the '..._GFp' prefix has been dropped from + the above `..._GF2m functions` (except for EX_GROUP_new_curve_GF2m) + are essentially identical to their `..._GFp` counterparts. + (For simplicity, the `..._GFp` prefix has been dropped from various internal method names.) An internal 'field_div' method (similar to 'field_mul' and 'field_sqr') has been added; this is used only for binary fields. - *Sheueling Chang Shantz and Douglas Stebila - (Sun Microsystems Laboratories)* + *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Optionally dispatch EC_POINT_mul(), EC_POINT_precompute_mult() through methods ('mul', 'precompute_mult'). @@ -10165,21 +10153,18 @@ OpenSSL 0.9.8.] and 'ec_wNAF_precomputed_mult') remain the default if these methods are undefined. - *Sheueling Chang Shantz and Douglas Stebila - (Sun Microsystems Laboratories)* + *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * New function EC_GROUP_get_degree, which is defined through EC_METHOD. For curves over prime fields, this returns the bit length of the modulus. - *Sheueling Chang Shantz and Douglas Stebila - (Sun Microsystems Laboratories)* + *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * New functions EC_GROUP_dup, EC_POINT_dup. (These simply call ..._new and ..._copy). - *Sheueling Chang Shantz and Douglas Stebila - (Sun Microsystems Laboratories)* + *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Add binary polynomial arithmetic software in crypto/bn/bn_gf2m.c. Polynomials are represented as BIGNUMs (where the sign bit is not @@ -10232,8 +10217,7 @@ OpenSSL 0.9.8.] if OPENSSL_SUN_GF2M_DIV is defined (patent pending; read the copyright notice in crypto/bn/bn_gf2m.c before enabling it). - *Sheueling Chang Shantz and Douglas Stebila - (Sun Microsystems Laboratories)* + *Sheueling Chang Shantz and Douglas Stebila (Sun Microsystems Laboratories)* * Add new error code 'ERR_R_DISABLED' that can be used when some functionality is disabled at compile-time. @@ -10356,7 +10340,7 @@ OpenSSL 0.9.8.] *Richard Levitte* -### Changes between 0.9.7l and 0.9.7m [23 Feb 2007] ### +### Changes between 0.9.7l and 0.9.7m [23 Feb 2007] * Cleanse PEM buffers before freeing them since they may contain sensitive data. @@ -10406,7 +10390,7 @@ OpenSSL 0.9.8.] *Steve Henson* -### Changes between 0.9.7k and 0.9.7l [28 Sep 2006] ### +### Changes between 0.9.7k and 0.9.7l [28 Sep 2006] * Introduce limits to prevent malicious keys being able to cause a denial of service. [CVE-2006-2940][] @@ -10434,7 +10418,7 @@ OpenSSL 0.9.8.] *Bodo Moeller* -### Changes between 0.9.7j and 0.9.7k [05 Sep 2006] ### +### Changes between 0.9.7j and 0.9.7k [05 Sep 2006] * Avoid PKCS #1 v1.5 signature attack discovered by Daniel Bleichenbacher [CVE-2006-4339][] [Ben Laurie and Google Security Team] @@ -10447,9 +10431,9 @@ OpenSSL 0.9.8.] * Disable rogue ciphersuites: - - SSLv2 0x08 0x00 0x80 ("RC4-64-MD5") - - SSLv3/TLSv1 0x00 0x61 ("EXP1024-RC2-CBC-MD5") - - SSLv3/TLSv1 0x00 0x60 ("EXP1024-RC4-MD5") + - SSLv2 0x08 0x00 0x80 ("RC4-64-MD5") + - SSLv3/TLSv1 0x00 0x61 ("EXP1024-RC2-CBC-MD5") + - SSLv3/TLSv1 0x00 0x60 ("EXP1024-RC4-MD5") The latter two were purportedly from draft-ietf-tls-56-bit-ciphersuites-0[01].txt, but do not really @@ -10466,7 +10450,7 @@ OpenSSL 0.9.8.] *Bodo Moeller* -### Changes between 0.9.7i and 0.9.7j [04 May 2006] ### +### Changes between 0.9.7i and 0.9.7j [04 May 2006] * Adapt fipsld and the build system to link against the validated FIPS module in FIPS mode. @@ -10484,7 +10468,7 @@ OpenSSL 0.9.8.] *Steve Henson* -### Changes between 0.9.7h and 0.9.7i [14 Oct 2005] ### +### Changes between 0.9.7h and 0.9.7i [14 Oct 2005] * Wrapped the definition of EVP_MAX_MD_SIZE in a #ifdef OPENSSL_FIPS. The value now differs depending on if you build for FIPS or not. @@ -10494,7 +10478,7 @@ OpenSSL 0.9.8.] *Andy Polyakov* -### Changes between 0.9.7g and 0.9.7h [11 Oct 2005] ### +### Changes between 0.9.7g and 0.9.7h [11 Oct 2005] * Remove the functionality of SSL_OP_MSIE_SSLV2_RSA_PADDING (part of SSL_OP_ALL). This option used to disable the @@ -10504,7 +10488,7 @@ OpenSSL 0.9.8.] *Bodo Moeller; problem pointed out by Yutaka Oiwa (Research Center for Information Security, National Institute of Advanced Industrial - Science and Technology [AIST*, Japan)] + Science and Technology [AIST, Japan)]* * Minimal support for X9.31 signatures and PSS padding modes. This is mainly for FIPS compliance and not fully integrated at this stage. @@ -10532,7 +10516,6 @@ OpenSSL 0.9.8.] RSA_FLAG_NO_EXP_CONSTTIME, DSA_FLAG_NO_EXP_CONSTTIME, or DH_FLAG_NO_EXP_CONSTTIME, respectively, is set. - *Matthew D Wood (Intel Corp), with some changes by Bodo Moeller* * Change the client implementation for SSLv23_method() and @@ -10560,7 +10543,7 @@ OpenSSL 0.9.8.] *Steve Henson* -### Changes between 0.9.7f and 0.9.7g [11 Apr 2005] ### +### Changes between 0.9.7f and 0.9.7g [11 Apr 2005] [NB: OpenSSL 0.9.7h and later 0.9.7 patch levels were released after OpenSSL 0.9.8.] @@ -10585,7 +10568,7 @@ OpenSSL 0.9.8.] *Richard Levitte* -### Changes between 0.9.7e and 0.9.7f [22 Mar 2005] ### +### Changes between 0.9.7e and 0.9.7f [22 Mar 2005] * Use (SSL_RANDOM_VALUE - 4) bytes of pseudo random data when generating server and client random values. Previously @@ -10648,15 +10631,15 @@ OpenSSL 0.9.8.] side effect always do the following basic checks on extensions, not just when there's an associated purpose to the check: - - if there is an unhandled critical extension (unless the user - has chosen to ignore this fault) - - if the path length has been exceeded (if one is set at all) - - that certain extensions fit the associated purpose (if one has - been given) + - if there is an unhandled critical extension (unless the user + has chosen to ignore this fault) + - if the path length has been exceeded (if one is set at all) + - that certain extensions fit the associated purpose (if one has + been given) *Richard Levitte* -### Changes between 0.9.7d and 0.9.7e [25 Oct 2004] ### +### Changes between 0.9.7d and 0.9.7e [25 Oct 2004] * Avoid a race condition when CRLs are checked in a multi threaded environment. This would happen due to the reordering of the revoked @@ -10684,7 +10667,7 @@ OpenSSL 0.9.8.] *Steve Henson* -### Changes between 0.9.7c and 0.9.7d [17 Mar 2004] ### +### Changes between 0.9.7c and 0.9.7d [17 Mar 2004] * Fix null-pointer assignment in do_change_cipher_spec() revealed by using the Codenomicon TLS Test Tool [CVE-2004-0079][] @@ -10737,7 +10720,7 @@ OpenSSL 0.9.8.] *Steve Henson* -### Changes between 0.9.7b and 0.9.7c [30 Sep 2003] ### +### Changes between 0.9.7b and 0.9.7c [30 Sep 2003] * Fix various bugs revealed by running the NISCC test suite: @@ -10749,7 +10732,6 @@ OpenSSL 0.9.8.] If verify callback ignores invalid public key errors don't try to check certificate signature with the NULL public key. - *Steve Henson* * New -ignore_err option in ocsp application to stop the server @@ -10796,7 +10778,7 @@ OpenSSL 0.9.8.] *Steve Henson* -### Changes between 0.9.7a and 0.9.7b [10 Apr 2003] ### +### Changes between 0.9.7a and 0.9.7b [10 Apr 2003] * Countermeasure against the Klima-Pokorny-Rosa extension of Bleichbacher's attack on PKCS #1 v1.5 padding: treat @@ -10836,7 +10818,7 @@ OpenSSL 0.9.8.] *Ulf Moeller* -### Changes between 0.9.7 and 0.9.7a [19 Feb 2003] ### +### Changes between 0.9.7 and 0.9.7a [19 Feb 2003] * In ssl3_get_record (ssl/s3_pkt.c), minimize information leaked via timing by performing a MAC computation even if incorrect @@ -10927,7 +10909,7 @@ OpenSSL 0.9.8.] *Richard Levitte & Kris Kennaway * -### Changes between 0.9.6h and 0.9.7 [31 Dec 2002] ### +### Changes between 0.9.6h and 0.9.7 [31 Dec 2002] [NB: OpenSSL 0.9.6i and later 0.9.6 patch levels were released after OpenSSL 0.9.7.] @@ -11171,7 +11153,7 @@ OpenSSL 0.9.7.] * Remove most calls to EVP_CIPHER_CTX_cleanup() in evp_enc.c, this allows existing EVP_CIPHER_CTX structures to be reused after - calling EVP_*Final(). This behaviour is used by encryption + calling `EVP_*Final()`. This behaviour is used by encryption BIOs and some applications. This has the side effect that applications must explicitly clean up cipher contexts with EVP_CIPHER_CTX_cleanup() or they will leak memory. @@ -11426,12 +11408,12 @@ OpenSSL 0.9.7.] *Massimiliano Pala madwolf@openca.org* - * Change all functions with names starting with des_ to be starting - with DES_ instead. Add wrappers that are compatible with libdes, - but are named _ossl_old_des_*. Finally, add macros that map the - des_* symbols to the corresponding _ossl_old_des_* if libdes + * Change all functions with names starting with `des_` to be starting + with `DES_` instead. Add wrappers that are compatible with libdes, + but are named `_ossl_old_des_*`. Finally, add macros that map the + `des_*` symbols to the corresponding `_ossl_old_des_*` if libdes compatibility is desired. If OpenSSL 0.9.6c compatibility is - desired, the des_* symbols will be mapped to DES_*, with one + desired, the `des_*` symbols will be mapped to `DES_*`, with one exception. Since we provide two compatibility mappings, the user needs to @@ -11449,7 +11431,7 @@ OpenSSL 0.9.7.] won't work. NOTE: This is a major break of an old API into a new one. Software - authors are encouraged to switch to the DES_ style functions. Some + authors are encouraged to switch to the `DES_` style functions. Some time in the future, des_old.h and the libdes compatibility functions will be disable (i.e. OPENSSL_DISABLE_OLD_DES_SUPPORT will be the default), and then completely removed. @@ -11509,7 +11491,7 @@ OpenSSL 0.9.7.] deal more passive and at run-time, operations deal directly with RSA_METHODs, DSA_METHODs (etc) as they did before, rather than dereferencing through an ENGINE pointer any more. Also, the ENGINE - functions dealing with BN_MOD_EXP[_CRT] handlers have been removed - + functions dealing with `BN_MOD_EXP[_CRT]` handlers have been removed - they were not being used by the framework as there is no concept of a BIGNUM_METHOD and they could not be generalised to the new 'ENGINE_TABLE' mechanism that underlies the new code. Similarly, @@ -11523,7 +11505,7 @@ OpenSSL 0.9.7.] *Steve Henson* * Change mkdef.pl to sort symbols that get the same entry number, - and make sure the automatically generated functions ERR_load_* + and make sure the automatically generated functions `ERR_load_*` become part of libeay.num as well. *Richard Levitte* @@ -11555,7 +11537,7 @@ OpenSSL 0.9.7.] *Steve Henson* * Make maximum certificate chain size accepted from the peer application - settable (SSL*_get/set_max_cert_list()), as proposed by + settable (`SSL*_get/set_max_cert_list()`), as proposed by "Douglas E. Engert" . *Lutz Jaenicke* @@ -11649,7 +11631,7 @@ OpenSSL 0.9.7.] *Geoff Thorpe* - * Give DH, DSA, and RSA types their own "**_up_ref()" function to increment + * Give DH, DSA, and RSA types their own `*_up_ref()` function to increment reference counts. This performs normal REF_PRINT/REF_CHECK macros on the operation, and provides a more encapsulated way for external code (crypto/evp/ and ssl/) to do this. Also changed the evp and ssl code @@ -11697,7 +11679,6 @@ OpenSSL 0.9.7.] EVP_DigestFinal(&md, out, NULL); EVP_MD_CTX_cleanup(&md); /* new function call */ - *Ben Laurie* * Make DES key schedule conform to the usual scheme, as well as @@ -11728,8 +11709,8 @@ OpenSSL 0.9.7.] *Ben Laurie* - * Change historical references to {NID,SN,LN}_des_ede and ede3 to add the - correct _ecb suffix. + * Change historical references to `{NID,SN,LN}_des_ede` and ede3 to add the + correct `_ecb suffix`. *Ben Laurie* @@ -11746,17 +11727,16 @@ OpenSSL 0.9.7.] *Richard Levitte* * Changes to Kerberos SSL for RFC 2712 compliance: - 1. Implemented real KerberosWrapper, instead of just using - KRB5 AP_REQ message. [Thanks to Simon Wilkinson ] - 2. Implemented optional authenticator field of KerberosWrapper. + 1. Implemented real KerberosWrapper, instead of just using + KRB5 AP_REQ message. [Thanks to Simon Wilkinson ] + 2. Implemented optional authenticator field of KerberosWrapper. Added openssl-style ASN.1 macros for Kerberos ticket, ap_req, and authenticator structs; see crypto/krb5/. Generalized Kerberos calls to support multiple Kerberos libraries. - *Vern Staats , - Jeffrey Altman - via Richard Levitte* + *Vern Staats , Jeffrey Altman + via Richard Levitte* * Cause 'openssl speed' to use fully hard-coded DSA keys as it already does with RSA. testdsa.h now has 'priv_key/pub_key' @@ -12098,7 +12078,7 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k *Bodo Moeller* - * Modify EVP_Digest*() routines so they now return values. Although the + * Modify `EVP_Digest*()` routines so they now return values. Although the internal software routines can never fail additional hardware versions might. @@ -12244,14 +12224,14 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k * Make all configuration macros available for application by making sure they are available in opensslconf.h, by giving them names starting - with "OPENSSL_" to avoid conflicts with other packages and by making + with `OPENSSL_` to avoid conflicts with other packages and by making sure e_os2.h will cover all platform-specific cases together with opensslconf.h. Additionally, it is now possible to define configuration/platform- specific names (called "system identities"). In the C code, these - are prefixed with "OPENSSL_SYSNAME_". e_os2.h will create another - macro with the name beginning with "OPENSSL_SYS_", which is determined - from "OPENSSL_SYSNAME_*" or compiler-specific macros depending on + are prefixed with `OPENSSL_SYSNAME_`. e_os2.h will create another + macro with the name beginning with `OPENSSL_SYS_`, which is determined + from `OPENSSL_SYSNAME_*` or compiler-specific macros depending on what is available. *Richard Levitte* @@ -12300,7 +12280,7 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k * Disable stdin buffering in load_cert (apps/apps.c) so that no certs are skipped when using openssl x509 multiple times on a single input file, - e.g. "(openssl x509 -out cert1; openssl x509 -out cert2) ' prints the status of the cert with + `openssl ca -status ` prints the status of the cert with the given serial number (according to the index file). - 'openssl ca -updatedb' updates the expiry status of certificates + `openssl ca -updatedb` updates the expiry status of certificates in the index file. *Massimiliano Pala * @@ -12494,7 +12474,7 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k * Allowing defining memory allocation callbacks that will be given file name and line number information in additional arguments - (a const char* and an int). The basic functionality remains, as + (a `const char*` and an int). The basic functionality remains, as well as the original possibility to just replace malloc(), realloc() and free() by functions that do not know about these additional arguments. To register and find out the current @@ -12507,9 +12487,9 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k CRYPTO_get_locked_mem_ex_functions These work the same way as CRYPTO_set_mem_functions and friends. - CRYPTO_get_[locked_]mem_functions now writes 0 where such an + `CRYPTO_get_[locked_]mem_functions` now writes 0 where such an extended allocation function is enabled. - Similarly, CRYPTO_get_[locked_]mem_ex_functions writes 0 where + Similarly, `CRYPTO_get_[locked_]mem_ex_functions` writes 0 where a conventional allocation function is enabled. *Richard Levitte, Bodo Moeller* @@ -12617,7 +12597,7 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k * New functions or ASN1_item_d2i_fp() and ASN1_item_d2i_bio(). These replace the old function pointer based I/O routines. Change most of - the *_d2i_bio() and *_d2i_fp() functions to use these. + the `*_d2i_bio()` and `*_d2i_fp()` functions to use these. *Steve Henson* @@ -12744,7 +12724,7 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k * Added Kerberos Cipher Suites to be used with TLS, as written in RFC 2712. *Veers Staats , - Jeffrey Altman , via Richard Levitte* + Jeffrey Altman , via Richard Levitte* * Reformat the FAQ so the different questions and answers can be divided in sections depending on the subject. @@ -12810,7 +12790,7 @@ s-cbc 3624.96k 5258.21k 5530.91k 5624.30k 5628.26k *Bodo Moeller* - * Move BN_mod_... functions into new file crypto/bn/bn_mod.c + * Move `BN_mod_...` functions into new file crypto/bn/bn_mod.c (except for exponentiation, which stays in crypto/bn/bn_exp.c, and BN_mod_mul_reciprocal, which stays in crypto/bn/bn_recp.c) and add new functions: @@ -12974,7 +12954,7 @@ ndif * NCONF changes. NCONF_get_number() has no error checking at all. As a replacement, - NCONF_get_number_e() is defined (_e for "error checking") and is + NCONF_get_number_e() is defined (`_e` for "error checking") and is promoted strongly. The old NCONF_get_number is kept around for binary backward compatibility. Make it possible for methods to load from something other than a BIO, @@ -13008,14 +12988,14 @@ ndif *Richard Levitte* -### Changes between 0.9.6l and 0.9.6m [17 Mar 2004] ### +### Changes between 0.9.6l and 0.9.6m [17 Mar 2004] * Fix null-pointer assignment in do_change_cipher_spec() revealed by using the Codenomicon TLS Test Tool [CVE-2004-0079][] *Joe Orton, Steve Henson* -### Changes between 0.9.6k and 0.9.6l [04 Nov 2003] ### +### Changes between 0.9.6k and 0.9.6l [04 Nov 2003] * Fix additional bug revealed by the NISCC test suite: @@ -13024,7 +13004,7 @@ ndif *Steve Henson* -### Changes between 0.9.6j and 0.9.6k [30 Sep 2003] ### +### Changes between 0.9.6j and 0.9.6k [30 Sep 2003] * Fix various bugs revealed by running the NISCC test suite: @@ -13034,7 +13014,6 @@ ndif If verify callback ignores invalid public key errors don't try to check certificate signature with the NULL public key. - *Steve Henson* * In ssl3_accept() (ssl/s3_srvr.c) only accept a client certificate @@ -13054,7 +13033,7 @@ ndif *Richard Levitte* -### Changes between 0.9.6i and 0.9.6j [10 Apr 2003] ### +### Changes between 0.9.6i and 0.9.6j [10 Apr 2003] * Countermeasure against the Klima-Pokorny-Rosa extension of Bleichbacher's attack on PKCS #1 v1.5 padding: treat @@ -13082,7 +13061,7 @@ ndif *Bodo Moeller* -### Changes between 0.9.6h and 0.9.6i [19 Feb 2003] ### +### Changes between 0.9.6h and 0.9.6i [19 Feb 2003] * In ssl3_get_record (ssl/s3_pkt.c), minimize information leaked via timing by performing a MAC computation even if incorrect @@ -13094,7 +13073,7 @@ ndif Alain Hiltgen (UBS), Serge Vaudenay (EPFL), and Martin Vuagnoux (EPFL, Ilion)* -### Changes between 0.9.6g and 0.9.6h [5 Dec 2002] ### +### Changes between 0.9.6g and 0.9.6h [5 Dec 2002] * New function OPENSSL_cleanse(), which is used to cleanse a section of memory from its contents. This is done with a counter that will @@ -13174,20 +13153,19 @@ ndif *Steve Henson* -### Changes between 0.9.6f and 0.9.6g [9 Aug 2002] ### +### Changes between 0.9.6f and 0.9.6g [9 Aug 2002] * [In 0.9.6g-engine release:] - Fix crypto/engine/vendor_defns/cswift.h for WIN32 (use '_stdcall'). + Fix crypto/engine/vendor_defns/cswift.h for WIN32 (use `_stdcall`). *Lynn Gazis * -### Changes between 0.9.6e and 0.9.6f [8 Aug 2002] ### +### Changes between 0.9.6e and 0.9.6f [8 Aug 2002] * Fix ASN1 checks. Check for overflow by comparing with LONG_MAX and get fix the header length calculation. *Florian Weimer , - Alon Kantor (and others), - Steve Henson* + Alon Kantor (and others), Steve Henson* * Use proper error handling instead of 'assertions' in buffer overflow checks added in 0.9.6e. This prevents DoS (the @@ -13195,7 +13173,7 @@ ndif *Arne Ansper , Bodo Moeller* -### Changes between 0.9.6d and 0.9.6e [30 Jul 2002] ### +### Changes between 0.9.6d and 0.9.6e [30 Jul 2002] * Add various sanity checks to asn1_get_length() to reject the ASN1 length bytes if they exceed sizeof(long), will appear @@ -13249,7 +13227,7 @@ ndif * Various temporary buffers to hold ASCII versions of integers were too small for 64 bit platforms. [CVE-2002-0655][] - *Matthew Byng-Maddick and Ben Laurie (CHATS)> + *Matthew Byng-Maddick and Ben Laurie (CHATS)>* * Remote buffer overflow in SSL3 protocol - an attacker could supply an oversized session ID to a client. [CVE-2002-0656][] @@ -13261,14 +13239,14 @@ ndif *Ben Laurie (CHATS)* -### Changes between 0.9.6c and 0.9.6d [9 May 2002] ### +### Changes between 0.9.6c and 0.9.6d [9 May 2002] * Fix crypto/asn1/a_sign.c so that 'parameters' is omitted (not encoded as NULL) with id-dsa-with-sha1. *Nils Larsch ; problem pointed out by Bodo Moeller* - * Check various X509_...() return values in apps/req.c. + * Check various `X509_...()` return values in apps/req.c. *Nils Larsch * @@ -13404,12 +13382,12 @@ ndif *D P Chang * -### Changes between 0.9.6b and 0.9.6c [21 dec 2001] ### +### Changes between 0.9.6b and 0.9.6c [21 dec 2001] * Fix BN_rand_range bug pointed out by Dominikus Scherkl . (The previous implementation - worked incorrectly for those cases where range = 10..._2 and - 3*range is two bits longer than range.) + worked incorrectly for those cases where range = `10..._2` and + `3*range` is two bits longer than range.) *Bodo Moeller* @@ -13480,7 +13458,7 @@ ndif instead. BIO_gethostbyname() does not know what timeouts are appropriate, so entries would stay in cache even when they have become invalid. - *Bodo Moeller; problem pointed out by Rich Salz + *Bodo Moeller; problem pointed out by Rich Salz * * Change ssl23_get_client_hello (ssl/s23_srvr.c) behaviour when faced with a pathologically small ClientHello fragment that does @@ -13577,7 +13555,7 @@ ndif *Lutz Jaenicke* - * Add alert descriptions for TLSv1 to SSL_alert_desc_string[_long](). + * Add alert descriptions for TLSv1 to `SSL_alert_desc_string[_long]()`. *Lutz Jaenicke* @@ -13683,7 +13661,7 @@ ndif *Richard Levitte* -### Changes between 0.9.6a and 0.9.6b [9 Jul 2001] ### +### Changes between 0.9.6a and 0.9.6b [9 Jul 2001] * Change ssleay_rand_bytes (crypto/rand/md_rand.c) to avoid a SSLeay/OpenSSL PRNG weakness pointed out by @@ -13729,7 +13707,7 @@ ndif *Bodo Moeller* - * Don't change *pointer in CRYPTO_add_lock() is add_lock_callback is + * Don't change `*pointer` in CRYPTO_add_lock() is add_lock_callback is used: it isn't thread safe and the add_lock_callback should handle that itself. @@ -13811,7 +13789,7 @@ ndif *Bodo Moeller* -### Changes between 0.9.6 and 0.9.6a [5 Apr 2001] ### +### Changes between 0.9.6 and 0.9.6a [5 Apr 2001] * Fix a couple of memory leaks in PKCS7_dataDecode() @@ -13849,7 +13827,7 @@ ndif * Check the result of RSA-CRT (see D. Boneh, R. DeMillo, R. Lipton: On the Importance of Eliminating Errors in Cryptographic Computations, J. Cryptology 14 (2001) 2, 101-119, - http://theory.stanford.edu/~dabo/papers/faults.ps.gz). + ). *Ulf Moeller* @@ -13890,7 +13868,7 @@ ndif *Bodo Moeller* - * Replace rdtsc with _emit statements for VC++ version 5. + * Replace rdtsc with `_emit` statements for VC++ version 5. *Jeremy Cooper * @@ -13934,7 +13912,7 @@ ndif * Fix CPU detection on Irix 6.x. *Kurt Hockenbury and - "Bruce W. Forsberg" * + "Bruce W. Forsberg" * * Fix X509_NAME bug which produced incorrect encoding if X509_NAME was empty. @@ -13957,7 +13935,7 @@ ndif *Ulf Moeller, Bodo Moeller* - * In the NCONF_...-based implementations for CONF_... queries + * In the `NCONF_...`-based implementations for `CONF_...` queries (crypto/conf/conf_lib.c), if the input LHASH is NULL, avoid using a temporary CONF structure with the data component set to NULL (which gives segmentation faults in lh_retrieve). @@ -14040,8 +14018,8 @@ ndif *Bodo Moeller; problem reported by Eric Day * - * In RSA_eay_public_{en,ed}crypt and RSA_eay_mod_exp (rsa_eay.c), - obtain lock CRYPTO_LOCK_RSA before setting rsa->_method_mod_{n,p,q}. + * In `RSA_eay_public_{en,ed}crypt` and RSA_eay_mod_exp (rsa_eay.c), + obtain lock CRYPTO_LOCK_RSA before setting `rsa->_method_mod_{n,p,q}`. (RSA objects have a reference count access to which is protected by CRYPTO_LOCK_RSA [see rsa_lib.c, s3_srvr.c, ssl_cert.c, ssl_rsa.c], @@ -14153,7 +14131,7 @@ ndif *Lutz Jaenicke* -### Changes between 0.9.5a and 0.9.6 [24 Sep 2000] ### +### Changes between 0.9.5a and 0.9.6 [24 Sep 2000] * In ssl23_get_client_hello, generate an error message when faced with an initial SSL 3.0/TLS record that is too small to contain the @@ -14273,7 +14251,7 @@ ndif *Ben Laurie* - * Add a few more EBCDIC conditionals that make `req' and `x509' + * Add a few more EBCDIC conditionals that make `req` and `x509` work better on such systems. *Martin Kraemer * @@ -14397,7 +14375,7 @@ ndif *Andreas Schneider * * A demo state-machine implementation was sponsored by - Nuron (http://www.nuron.com/) and is now available in + Nuron () and is now available in demos/state_machine. *Ben Laurie* @@ -14453,13 +14431,12 @@ ndif and as before, if none of those prefixes are present at the beginning of the string, LOG_ERR is chosen. - On Win32, the LOG_* levels are mapped according to this: + On Win32, the `LOG_*` levels are mapped according to this: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR => EVENTLOG_ERROR_TYPE LOG_WARNING => EVENTLOG_WARNING_TYPE LOG_NOTICE, LOG_INFO, LOG_DEBUG => EVENTLOG_INFORMATION_TYPE - *Richard Levitte* * Made it possible to reconfigure with just the configuration @@ -14541,8 +14518,8 @@ ndif *Steve Henson* - * crypto/err.c locking bugfix: Use write locks (CRYPTO_w_[un]lock), - not read locks (CRYPTO_r_[un]lock). + * crypto/err.c locking bugfix: Use write locks (`CRYPTO_w_[un]lock`), + not read locks (`CRYPTO_r_[un]lock`). *Bodo Moeller* @@ -14578,7 +14555,7 @@ ndif *Steve Henson* - * New ASN1 functions, i2c_* and c2i_* for INTEGER and BIT + * New ASN1 functions, `i2c_*` and `c2i_*` for INTEGER and BIT STRING types. These convert content octets to and from the underlying type. The actual tag and length octets are already assumed to have been read in and checked. These @@ -14636,7 +14613,7 @@ ndif * Reorganisation of the stack code. The macros are now all collected in safestack.h . Each macro is defined in terms of - a "stack macro" of the form SKM_(type, a, b). The + a "stack macro" of the form `SKM_(type, a, b)`. The DEBUG_SAFESTACK is now handled in terms of function casts, this has the advantage of retaining type safety without the use of additional functions. If DEBUG_SAFESTACK is not defined @@ -14679,7 +14656,7 @@ ndif *Bodo Moeller* - * Increase maximum window size in BN_mod_exp_... to 6 bits instead of 5 + * Increase maximum window size in `BN_mod_exp_...` to 6 bits instead of 5 (meaning that now 2^5 values will be precomputed, which is only 4 KB plus overhead for 1024 bit moduli). This makes exponentiations about 0.5 % faster for 1024 bit @@ -14719,7 +14696,7 @@ ndif also involved a cleanup of sorts in safestack.h to more correctly map type-safe stack functions onto their plain stack counterparts. This work has also resulted in a variety of "const"ifications of - lots of the code, especially "_cmp" operations which should normally + lots of the code, especially `_cmp` operations which should normally be prototyped with "const" parameters anyway. *Geoff Thorpe* @@ -14782,7 +14759,7 @@ ndif *Bodo Moeller* - * Call dh_tmp_cb (set by ..._TMP_DH_CB) with correct 'is_export' flag; + * Call dh_tmp_cb (set by `..._TMP_DH_CB`) with correct 'is_export' flag; i.e. non-zero for export ciphersuites, zero otherwise. Previous versions had this flag inverted, inconsistent with rsa_tmp_cb (..._TMP_RSA_CB). @@ -14872,13 +14849,13 @@ ndif * CONF library reworked to become more general. A new CONF configuration file reader "class" is implemented as well as a - new functions (NCONF_*, for "New CONF") to handle it. The now - old CONF_* functions are still there, but are reimplemented to + new functions (`NCONF_*`, for "New CONF") to handle it. The now + old `CONF_*` functions are still there, but are reimplemented to work in terms of the new functions. Also, a set of functions to handle the internal storage of the configuration data is provided to make it easier to write new configuration file reader "classes" (I can definitely see something reading a - configuration file in XML format, for example), called _CONF_*, + configuration file in XML format, for example), called `_CONF_*`, or "the configuration storage API"... The new configuration file reading functions are: @@ -14893,12 +14870,12 @@ ndif NCONF_default and NCONF_WIN32 are method (or "class") choosers, NCONF_new creates a new CONF object. This works in the same way as other interfaces in OpenSSL, like the BIO interface. - NCONF_dump_* dump the internal storage of the configuration file, + `NCONF_dump_*` dump the internal storage of the configuration file, which is useful for debugging. All other functions take the same - arguments as the old CONF_* functions with the exception of the - first that must be a `CONF *' instead of a `LHASH *'. + arguments as the old `CONF_*` functions with the exception of the + first that must be a `CONF *` instead of a `LHASH *`. - To make it easier to use the new classes with the old CONF_* functions, + To make it easier to use the new classes with the old `CONF_*` functions, the function CONF_set_default_method is provided. *Richard Levitte* @@ -14916,7 +14893,7 @@ ndif *Geoff Thorpe, with contributions from Richard Levitte* -### Changes between 0.9.5 and 0.9.5a [1 Apr 2000] ### +### Changes between 0.9.5 and 0.9.5a [1 Apr 2000] * Make sure _lrotl and _lrotr are only used with MSVC. @@ -14943,7 +14920,7 @@ ndif * des_quad_cksum() byte order bug fix. *Ulf Möller, using the problem description in krb4-0.9.7, where - the solution is attributed to Derrick J Brashear * + the solution is attributed to Derrick J Brashear * * Fix so V_ASN1_APP_CHOOSE works again: however its use is strongly discouraged. @@ -15071,7 +15048,7 @@ ndif *Lutz Behnke * -### Changes between 0.9.4 and 0.9.5 [28 Feb 2000] ### +### Changes between 0.9.4 and 0.9.5 [28 Feb 2000] * PKCS7_encrypt() was adding text MIME headers twice because they were added manually and by SMIME_crlf_copy(). @@ -15104,7 +15081,7 @@ ndif * Change names of new functions to the new get1/get0 naming convention: After 'get1', the caller owns a reference count - and has to call ..._free; 'get0' returns a pointer to some + and has to call `..._free`; 'get0' returns a pointer to some data structure without incrementing reference counters. (Some of the existing 'get' functions increment a reference counter, some don't.) @@ -15120,7 +15097,7 @@ ndif * Fix potential buffer overrun problem in BIO_printf(). *Ulf Möller, using public domain code by Patrick Powell; problem - pointed out by David Sacerdote * + pointed out by David Sacerdote * * Support EGD . New functions RAND_egd() and RAND_status(). In the command line application, @@ -15147,23 +15124,23 @@ ndif *Steve Henson* - * ..._ctrl functions now have corresponding ..._callback_ctrl functions - where the 'void *' argument is replaced by a function pointer argument. - Previously 'void *' was abused to point to functions, which works on + * `..._ctrl` functions now have corresponding `..._callback_ctrl` functions + where the `void *` argument is replaced by a function pointer argument. + Previously `void *` was abused to point to functions, which works on many platforms, but is not correct. As these functions are usually called by macros defined in OpenSSL header files, most source code should work without changes. *Richard Levitte* - * (which is created by Configure) now contains + * `` (which is created by Configure) now contains sections with information on -D... compiler switches used for compiling the library so that applications can see them. To enable - one of these sections, a pre-processor symbol OPENSSL_..._DEFINES + one of these sections, a pre-processor symbol `OPENSSL_..._DEFINES` must be defined. E.g., #define OPENSSL_ALGORITHM_DEFINES #include - defines all pertinent NO_ symbols, such as NO_IDEA, NO_RSA, etc. + defines all pertinent `NO_` symbols, such as NO_IDEA, NO_RSA, etc. *Richard Levitte, Ulf and Bodo Möller* @@ -15238,7 +15215,7 @@ ndif *Andy Polyakov* * Bug fix for BN_div() when the first words of num and divisor are - equal (it gave wrong results if (rem=(n1-q*d0)&BN_MASK2) < d0). + equal (it gave wrong results if `(rem=(n1-q*d0)&BN_MASK2) < d0)`. *Ulf Möller* @@ -15257,7 +15234,7 @@ ndif *Ulf Möller* - * Change the SSLeay_add_all_*() functions to OpenSSL_add_all_*() and + * Change the `SSLeay_add_all_*()` functions to `OpenSSL_add_all_*()` and include a #define from the old name to the new. The original intent was that statically linked binaries could for example just call SSLeay_add_all_ciphers() to just add ciphers to the table and not @@ -15282,7 +15259,7 @@ ndif *Martin Kraemer * * Source code cleanups: use const where appropriate, eliminate casts, - use void * instead of char * in lhash. + use `void *` instead of `char *` in lhash. *Ulf Möller* @@ -15357,7 +15334,7 @@ ndif *Ulf Möller, Bodo Möller* * Clean up CRYPTO_EX_DATA functions, some of these didn't have prototypes - used (char *) instead of (void *) and had casts all over the place. + used `char *` instead of `void *` and had casts all over the place. *Steve Henson* @@ -15422,7 +15399,7 @@ ndif *Steve Henson* * Changes to X509_ATTRIBUTE utilities. These have been renamed from - X509_*() to X509at_*() on the grounds that they don't handle X509 + `X509_*()` to `X509at_*()` on the grounds that they don't handle X509 structures and behave in an analogous way to the X509v3 functions: they shouldn't be called directly but wrapper functions should be used instead. @@ -15437,7 +15414,7 @@ ndif * Add missing #ifndefs that caused missing symbols when building libssl as a shared library without RSA. Use #ifndef NO_SSL2 instead of - NO_RSA in ssl/s2*.c. + NO_RSA in `ssl/s2*.c`. *Kris Kennaway , modified by Ulf Möller* @@ -15750,8 +15727,8 @@ ndif There are two big advantages in doing things this way. The extensions can be looked up immediately and no longer need to be "added" using X509V3_add_standard_extensions(): this function now does nothing. - *Side note: I get *lots* of email saying the extension code doesn't - work because people forget to call this function* + Side note: I get *lots* of email saying the extension code doesn't + work because people forget to call this function. Also no dynamic allocation is done unless new extensions are added: so if we don't add custom extensions there is no need to call X509V3_EXT_cleanup(). @@ -15831,10 +15808,10 @@ ndif it clearly returns an error if you try to read the wrong kind of key. Added a -pubkey option to the 'x509' utility to output the public key. - Also rename the EVP_PKEY_get_*() to EVP_PKEY_rget_*() - (renamed to EVP_PKEY_get1_*() in the OpenSSL 0.9.5 release) and add - EVP_PKEY_rset_*() functions (renamed to EVP_PKEY_set1_*()) - that do the same as the EVP_PKEY_assign_*() except they up the + Also rename the `EVP_PKEY_get_*()` to `EVP_PKEY_rget_*()` + (renamed to `EVP_PKEY_get1_*()` in the OpenSSL 0.9.5 release) and add + `EVP_PKEY_rset_*()` functions (renamed to `EVP_PKEY_set1_*()`) + that do the same as the `EVP_PKEY_assign_*()` except they up the reference count of the added key (they don't "swallow" the supplied key). @@ -15969,7 +15946,7 @@ ndif *Steve Henson* - * Fix assembler for Alpha (tested only on DEC OSF not Linux or *BSD). + * Fix assembler for Alpha (tested only on DEC OSF not Linux or `*BSD`). The problem was that one of the replacement routines had not been working since SSLeay releases. For now the offending routine has been replaced with non-optimised assembler. Even so, this now gives around 95% @@ -16060,8 +16037,8 @@ ndif *Steve Henson* * Add function equivalents to the various macros in asn1.h. The old - macros are retained with an M_ prefix. Code inside the library can - use the M_ macros. External code (including the openssl utility) + macros are retained with an `M_` prefix. Code inside the library can + use the `M_` macros. External code (including the openssl utility) should *NOT* in order to be "shared library friendly". *Steve Henson* @@ -16080,7 +16057,7 @@ ndif *Steve Henson* - * New X509V3_{X509,CRL,REVOKED}_get_d2i() functions. These will search + * New `X509V3_{X509,CRL,REVOKED}_get_d2i()` functions. These will search for, obtain and decode and extension and obtain its critical flag. This allows all the necessary extension code to be handled in a single function call. @@ -16142,7 +16119,7 @@ ndif usual with these problems it takes *ages* to find and the fix is trivial: move one line. - *Steve Henson, reported by ian@uns.ns.ac.yu (Ivan Nejgebauer) * + *Steve Henson, reported by ian@uns.ns.ac.yu (Ivan Nejgebauer)* * Ugly workaround to get s_client and s_server working under Windows. The old code wouldn't work because it needed to select() on sockets and the @@ -16319,13 +16296,13 @@ ndif *Bodo Moeller* -### Changes between 0.9.3a and 0.9.4 [09 Aug 1999] ### +### Changes between 0.9.3a and 0.9.4 [09 Aug 1999] * Install libRSAglue.a when OpenSSL is built with RSAref. *Ralf S. Engelschall* - * A few more ``#ifndef NO_FP_API / #endif'' pairs for consistency. + * A few more `#ifndef NO_FP_API / #endif` pairs for consistency. *Andrija Antonijevic * @@ -16340,7 +16317,7 @@ ndif For 1024-bit p, DSA_generate_parameters followed by DSA_dup_DH is much faster than DH_generate_parameters (which creates parameters - where p = 2*q + 1), and also the smaller q makes DH computations + where `p = 2*q + 1`), and also the smaller q makes DH computations much more efficient (160-bit exponentiation instead of 1024-bit exponentiation); so this provides a convenient way to support DHE ciphersuites in SSL/TLS servers (see ssl/ssltest.c). It is of @@ -16388,7 +16365,7 @@ ndif to ....(char *buf, int size, int rwflag, void *userdata); so that applications can pass data to their callbacks: - The PEM[_ASN1]_{read,write}... functions and macros now take an + The `PEM[_ASN1]_{read,write}...` functions and macros now take an additional void * argument, which is just handed through whenever the password callback is called. @@ -16445,7 +16422,7 @@ ndif 1. Casts to avoid "loss of data" warnings in p5_crpt2.c 2. Change unsigned int to int in b_dump.c to avoid "signed/unsigned comparison" warnings. - 3. Add sk__sort to DEF file generator and do make update. + 3. Add `sk__sort` to DEF file generator and do make update. *Steve Henson* @@ -16538,8 +16515,7 @@ ndif store the length when it is first determined and use it later, rather than trying to keep track of where data is copied and updating it to point to the end. - *Steve Henson, reported by Brien Wheeler - * + *Steve Henson, reported by Brien Wheeler * * Add a new function PKCS7_signatureVerify. This allows the verification of a PKCS#7 signature but with the signing certificate passed to the @@ -16550,7 +16526,7 @@ ndif *Steve Henson* - * Complete the PEM_* macros with DECLARE_PEM versions to replace the + * Complete the `PEM_*` macros with DECLARE_PEM versions to replace the function prototypes in pem.h, also change util/mkdef.pl to add the necessary function names. @@ -16608,7 +16584,7 @@ ndif *Steve Henson* * Fix determination of Perl interpreter: A perl or perl5 - _directory_ in $PATH was also accepted as the interpreter. + *directory* in $PATH was also accepted as the interpreter. *Ralf S. Engelschall* @@ -16637,7 +16613,6 @@ ndif *Bodo Moeller* -f 0 * DES CBC did not update the IV. Weird. *Ben Laurie* @@ -16718,7 +16693,7 @@ ndif *Martin Kraemer * - * Make callbacks for key generation use void * instead of char *. + * Make callbacks for key generation use `void *` instead of `char *`. *Ben Laurie* @@ -16734,8 +16709,7 @@ ndif *Bodo Moeller* - -### Changes between 0.9.3 and 0.9.3a [29 May 1999] ### +### Changes between 0.9.3 and 0.9.3a [29 May 1999] * New configuration variant "sco5-gcc". @@ -16768,8 +16742,7 @@ ndif *Richard Levitte* - -### Changes between 0.9.2b and 0.9.3 [24 May 1999] ### +### Changes between 0.9.2b and 0.9.3 [24 May 1999] * Bignum library bug fix. IRIX 6 passes "make test" now! This also avoids the problems with SC4.2 and unpatched SC5. @@ -16836,8 +16809,8 @@ ndif *Steve Henson* * Make SSL library a little more fool-proof by not requiring any longer - that SSL_set_{accept,connect}_state be called before - SSL_{accept,connect} may be used (SSL_set_..._state is omitted + that `SSL_set_{accept,connect}_state` be called before + `SSL_{accept,connect}` may be used (`SSL_set_..._state` is omitted in many applications because usually everything *appeared* to work as intended anyway -- now it really works as intended). @@ -16847,9 +16820,9 @@ ndif *Ulf Möller* - * Fix various things to let OpenSSL even pass ``egcc -pipe -O2 -Wall + * Fix various things to let OpenSSL even pass "egcc -pipe -O2 -Wall -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes - -Wmissing-declarations -Wnested-externs -Winline'' with EGCS 1.1.2+ + -Wmissing-declarations -Wnested-externs -Winline" with EGCS 1.1.2+ *Ralf S. Engelschall* @@ -16861,7 +16834,7 @@ ndif * Create a duplicate of the SSL_CTX's CERT in SSL_new instead of copying pointers. The cert_st handling is changed by this in various ways (and thus what used to be known as ctx->default_cert - is now called ctx->cert, since we don't resort to s->ctx->[default_]cert + is now called ctx->cert, since we don't resort to `s->ctx->[default_]cert` any longer when s->cert does not give us what we need). ssl_cert_instantiate becomes obsolete by this change. As soon as we've got the new code right (possibly it already is?), @@ -16870,7 +16843,7 @@ ndif Note that using the SSL API in certain dirty ways now will result in different behaviour than observed with earlier library versions: - Changing settings for an SSL_CTX *ctx after having done s = SSL_new(ctx) + Changing settings for an `SSL_CTX *ctx` after having done s = SSL_new(ctx) does not influence s as it used to. In order to clean up things more thoroughly, inside SSL_SESSION @@ -16932,7 +16905,7 @@ ndif *Anonymous* - * Add missing sk__unshift() function to safestack.h + * Add missing `sk__unshift()` function to safestack.h *Ralf S. Engelschall* @@ -16992,7 +16965,7 @@ ndif *Niels Poppe * - * New Configure option no- (rsa, idea, rc5, ...). + * New Configure option `no-` (rsa, idea, rc5, ...). *Ulf Möller* @@ -17027,7 +17000,7 @@ ndif *Steve Henson* - * Change #include filenames from to . + * Change #include filenames from `` to ``. *Bodo Moeller* @@ -17147,16 +17120,16 @@ ndif *Ben Laurie* - * Add `openssl ca -revoke ' facility which revokes a certificate - specified in by updating the entry in the index.txt file. + * Add `openssl ca -revoke ` facility which revokes a certificate + specified in `` by updating the entry in the index.txt file. This way one no longer has to edit the index.txt file manually for revoking a certificate. The -revoke option does the gory details now. *Massimiliano Pala , Ralf S. Engelschall* - * Fix `openssl crl -noout -text' combination where `-noout' killed the - `-text' option at all and this way the `-noout -text' combination was - inconsistent in `openssl crl' with the friends in `openssl x509|rsa|dsa'. + * Fix `openssl crl -noout -text` combination where `-noout` killed the + `-text` option at all and this way the `-noout -text` combination was + inconsistent in `openssl crl` with the friends in `openssl x509|rsa|dsa`. *Ralf S. Engelschall* @@ -17166,12 +17139,12 @@ ndif *Ralf S. Engelschall* - * Bugfix: In test/testenc, don't test "openssl " for + * Bugfix: In test/testenc, don't test `openssl ` for ciphers that were excluded, e.g. by -DNO_IDEA. Also, test all available ciphers including rc5, which was forgotten until now. In order to let the testing shell script know which algorithms are available, a new (up to now undocumented) command - "openssl list-cipher-commands" is used. + `openssl list-cipher-commands` is used. *Bodo Moeller* @@ -17260,8 +17233,7 @@ ndif *Soren S. Jorvang * - -### Changes between 0.9.1c and 0.9.2b [22 Mar 1999] ### +### Changes between 0.9.1c and 0.9.2b [22 Mar 1999] * Make SSL_get_peer_cert_chain() work in servers. Unfortunately, it still doesn't work when the session is reused. Coming soon! @@ -17391,13 +17363,14 @@ ndif * Add a useful kludge to allow package maintainers to specify compiler and other platforms details on the command line without having to patch the - Configure script every time: One now can use ``perl Configure - :
'', i.e. platform ids are allowed to have details appended + Configure script every time: One now can use + `perl Configure :
`, + i.e. platform ids are allowed to have details appended to them (separated by colons). This is treated as there would be a static - pre-configured entry in Configure's %table under key with value -
and ``perl Configure '' is called. So, when you want to + pre-configured entry in Configure's %table under key `` with value + `
` and `perl Configure ` is called. So, when you want to perform a quick test-compile under FreeBSD 3.1 with pgcc and without - assembler stuff you can use ``perl Configure "FreeBSD-elf:pgcc:-O6:::"'' + assembler stuff you can use `perl Configure "FreeBSD-elf:pgcc:-O6:::"` now, which overrides the FreeBSD-elf entry on-the-fly. *Ralf S. Engelschall* @@ -17458,7 +17431,7 @@ ndif *Steve Henson* - * Added the new `Includes OpenSSL Cryptography Software' button as + * Added the new 'Includes OpenSSL Cryptography Software' button as doc/openssl_button.{gif,html} which is similar in style to the old SSLeay button and can be used by applications based on OpenSSL to show the relationship to the OpenSSL project. @@ -17494,7 +17467,7 @@ ndif * Experiment with doxygen documentation. Currently only partially applied to ssl/ssl_lib.c. - See http://www.stack.nl/~dimitri/doxygen/index.html, and run doxygen with + See , and run doxygen with openssl.doxy as the configuration file. *Ben Laurie* @@ -17540,13 +17513,13 @@ ndif *Richard Levitte * - * Fix 'port' variable from `int' to `unsigned int' in crypto/bio/b_sock.c + * Fix `port` variable from `int` to `unsigned int` in crypto/bio/b_sock.c *Richard Levitte * * Change type of another md_len variable in pk7_doit.c:PKCS7_dataFinal() - from `int' to `unsigned int' because it's a length and initialized by - EVP_DigestFinal() which expects an `unsigned int *'. + from `int` to `unsigned int` because it is a length and initialized by + EVP_DigestFinal() which expects an `unsigned int *`. *Richard Levitte * @@ -17618,7 +17591,7 @@ ndif foundations than the ad-hoc padding used in PKCS #1 v1.5. It is secure against Bleichbacher's attack on RSA. *Ulf Moeller , reformatted, corrected and integrated by - Ben Laurie* + Ben Laurie* * Updates to the new SSL compression code @@ -17698,7 +17671,7 @@ ndif *Steve Henson* - * Overhauled the Perl interface (perl/*): + * Overhauled the Perl interface: - ported BN stuff to OpenSSL's different BN library - made the perl/ source tree CVS-aware - renamed the package from SSLeay to OpenSSL (the files still contain @@ -17737,7 +17710,7 @@ ndif *Eric A. Young, (from changes to C2Net SSLeay, integrated by Mark Cox)* - * Make sure `make rehash' target really finds the `openssl' program. + * Make sure `make rehash` target really finds the `openssl` program. *Ralf S. Engelschall, Matthias Loepfe * @@ -17750,7 +17723,7 @@ ndif *Alan Batie * - * Fixed ms/32all.bat script: `no_asm' -> `no-asm' + * Fixed ms/32all.bat script: `no_asm` -> `no-asm` *Rainer W. Gerling * @@ -17903,7 +17876,7 @@ ndif *Steve Henson* - * Make _all_ *_free functions accept a NULL pointer. + * Make *all* `*_free` functions accept a NULL pointer. *Frans Heymans * @@ -17966,10 +17939,10 @@ ndif *Steve Henson and Ben Laurie* - * First cut of a cleanup for apps/. First the `ssleay' program is now named - `openssl' and second, the shortcut symlinks for the `openssl ' + * First cut of a cleanup for apps/. First the `ssleay` program is now named + `openssl` and second, the shortcut symlinks for the `openssl ` are no longer created. This way we have a single and consistent command - line interface `openssl ', similar to `cvs '. + line interface `openssl `, similar to `cvs `. *Ralf S. Engelschall, Paul Sutton and Ben Laurie* @@ -18062,8 +18035,7 @@ ndif *Ben Laurie* - -### Changes between 0.9.1b and 0.9.1c [23-Dec-1998] ### +### Changes between 0.9.1b and 0.9.1c [23-Dec-1998] * Added OPENSSL_VERSION_NUMBER to crypto/crypto.h and changed SSLeay to OpenSSL in version strings. @@ -18084,7 +18056,7 @@ ndif *Andrew Cooke / Interrader Ldt., Ralf S. Engelschall* - * Fixed nasty rehash problem under `make -f Makefile.ssl links' + * Fixed nasty rehash problem under `make -f Makefile.ssl links` when "ssleay" is still not found. *Ralf S. Engelschall* @@ -18136,8 +18108,7 @@ ndif *The OpenSSL Project* - -### Changes between 0.9.0b and 0.9.1b [not released] ### +### Changes between 0.9.0b and 0.9.1b [not released] * Updated a few CA certificates under certs/ @@ -18268,7 +18239,6 @@ ndif *Edward Bishop * - [CVE-2019-1563]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1563 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0585cf43..23756a5d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,6 @@ Please visit our [Getting Started][gs] page for other ideas about how to contrib [gs]: https://www.openssl.org/community/getting-started.html - Development is done on GitHub in the [openssl/openssl][gh] repository. [gh]: https://github.com/openssl/openssl @@ -30,14 +29,17 @@ guidelines: [CLA]: https://www.openssl.org/policies/cla.html To amend a missing "`CLA: trivial`" line after submission, do the following: + ``` git commit --amend [add the line, save and quit the editor] git push -f ``` + 2. All source files should start with the following text (with appropriate comment characters at the start of each line and the year(s) updated): + ``` Copyright 20xx-20yy The OpenSSL Project Authors. All Rights Reserved. @@ -70,18 +72,20 @@ guidelines: documentation changes are clean. 7. For user visible changes (API changes, behaviour changes, ...), - consider adding a note in [CHANGES](CHANGES). This could be a summarising - description of the change, and could explain the grander details. + consider adding a note in [CHANGES.md](CHANGES.md). + This could be a summarising description of the change, and could + explain the grander details. Have a look through existing entries for inspiration. Please note that this is NOT simply a copy of git-log one-liners. - Also note that security fixes get an entry in CHANGES. + Also note that security fixes get an entry in CHANGES.md. This file helps users get more in depth information of what comes with a specific release without having to sift through the higher noise ratio in git-log. 8. For larger or more important user visible changes, as well as - security fixes, please add a line in [NEWS](NEWS). On exception, it might be - worth adding a multi-line entry (such as the entry that announces all - the types that became opaque with OpenSSL 1.1.0). + security fixes, please add a line in [NEWS.md](NEWS.md). + On exception, it might be worth adding a multi-line entry (such as + the entry that announces all the types that became opaque with + OpenSSL 1.1.0). This file helps users get a very quick summary of what comes with a specific release, to see if an upgrade is worth the effort. diff --git a/Configurations/00-base-templates.conf b/Configurations/00-base-templates.conf index 451a808f..821a211c 100644 --- a/Configurations/00-base-templates.conf +++ b/Configurations/00-base-templates.conf @@ -10,7 +10,7 @@ my %targets=( includes => [], lib_cflags => "", lib_cppflags => "", - lib_defines => [ 'OPENSSL_BUILDING_OPENSSL' ], + lib_defines => [], thread_scheme => "(unknown)", # Assume we don't know thread_defines => [], @@ -47,7 +47,7 @@ my %targets=( defines => sub { - my @defs = (); + my @defs = ( 'OPENSSL_BUILDING_OPENSSL' ); push @defs, "ZLIB" unless $disabled{zlib}; push @defs, "ZLIB_SHARED" unless $disabled{"zlib-dynamic"}; return [ @defs ]; diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index a462f9e7..7b5da5c4 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -790,7 +790,7 @@ my %targets = ( inherit_from => [ "linux-generic32" ], cflags => add("-mabi=n32"), cxxflags => add("-mabi=n32"), - bn_ops => "SIXTY_FOUR_BIT RC4_CHAR", + bn_ops => "RC4_CHAR", asm_arch => 'mips64', perlasm_scheme => "n32", multilib => "32", diff --git a/Configurations/shared-info.pl b/Configurations/shared-info.pl index a673c7ca..42435914 100644 --- a/Configurations/shared-info.pl +++ b/Configurations/shared-info.pl @@ -1,6 +1,6 @@ #! /usr/bin/env perl # -*- mode: perl; -*- -# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -36,7 +36,7 @@ my %shared_info; (grep /(?:^|\s)-fsanitize/, @{$config{CFLAGS}}, @{$config{cflags}}) ? '' - : '-z defs', + : '-Wl,-z,defs', }; }, 'bsd-gcc-shared' => sub { return $shared_info{'linux-shared'}; }, diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl index e7f5f405..126180ac 100644 --- a/Configurations/unix-Makefile.tmpl +++ b/Configurations/unix-Makefile.tmpl @@ -519,7 +519,7 @@ clean: libclean -$(RM) `find . -name '*{- platform->depext() -}' \! -name '.*' \! -type d -print` -$(RM) `find . -name '*{- platform->objext() -}' \! -name '.*' \! -type d -print` $(RM) core - $(RM) tags TAGS doc-nits cmd-nits + $(RM) tags TAGS doc-nits cmd-nits md-nits $(RM) -r test/test-runs $(RM) openssl.pc libcrypto.pc libssl.pc -$(RM) `find . -type l \! -name '.*' -print` @@ -859,30 +859,30 @@ install_man_docs: build_man_docs @set -e; for x in dummy $(MANDOCS1); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man1/$$fn"; \ - cp $$x $(DESTDIR)$(MANDIR)/man1/$$fn$(MANSUFFIX); \ - chmod 755 $(DESTDIR)$(MANDIR)/man1/$$fn$(MANSUFFIX); \ + $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \ + cp $$x $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX); \ + chmod 755 $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX); \ done @set -e; for x in dummy $(MANDOCS3); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man3/$$fn"; \ - cp $$x $(DESTDIR)$(MANDIR)/man3/$$fn$(MANSUFFIX); \ - chmod 755 $(DESTDIR)$(MANDIR)/man3/$$fn$(MANSUFFIX); \ + $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \ + cp $$x $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX); \ + chmod 755 $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX); \ done @set -e; for x in dummy $(MANDOCS5); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man5/$$fn"; \ - cp $$x $(DESTDIR)$(MANDIR)/man5/$$fn$(MANSUFFIX); \ - chmod 755 $(DESTDIR)$(MANDIR)/man5/$$fn$(MANSUFFIX); \ + $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \ + cp $$x $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX); \ + chmod 755 $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX); \ done @set -e; for x in dummy $(MANDOCS7); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man7/$$fn"; \ - cp $$x $(DESTDIR)$(MANDIR)/man7/$$fn$(MANSUFFIX); \ - chmod 755 $(DESTDIR)$(MANDIR)/man7/$$fn$(MANSUFFIX); \ + $(ECHO) "install $$x -> $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \ + cp $$x $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX); \ + chmod 755 $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX); \ done uninstall_man_docs: @@ -890,26 +890,26 @@ uninstall_man_docs: @set -e; for x in dummy $(MANDOCS1); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man1/$$fn"; \ - $(RM) $(DESTDIR)$(MANDIR)/man1/$$fn$(MANSUFFIX); \ + $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX)"; \ + $(RM) $(DESTDIR)$(MANDIR)/man1/$${fn}$(MANSUFFIX); \ done @set -e; for x in dummy $(MANDOCS3); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man3/$$fn"; \ - $(RM) $(DESTDIR)$(MANDIR)/man3/$$fn$(MANSUFFIX); \ + $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX)"; \ + $(RM) $(DESTDIR)$(MANDIR)/man3/$${fn}$(MANSUFFIX); \ done @set -e; for x in dummy $(MANDOCS5); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man5/$$fn"; \ - $(RM) $(DESTDIR)$(MANDIR)/man5/$$fn$(MANSUFFIX); \ + $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX)"; \ + $(RM) $(DESTDIR)$(MANDIR)/man5/$${fn}$(MANSUFFIX); \ done @set -e; for x in dummy $(MANDOCS7); do \ if [ "$$x" = "dummy" ]; then continue; fi; \ fn=`basename $$x`; \ - $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man7/$$fn"; \ - $(RM) $(DESTDIR)$(MANDIR)/man7/$$fn$(MANSUFFIX); \ + $(ECHO) "$(RM) $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX)"; \ + $(RM) $(DESTDIR)$(MANDIR)/man7/$${fn}$(MANSUFFIX); \ done install_html_docs: build_html_docs @@ -982,13 +982,22 @@ update: generate errors ordinals generate: generate_apps generate_crypto_bn generate_crypto_objects \ generate_crypto_conf generate_crypto_asn1 generate_fuzz_oids -.PHONY: doc-nits cmd-nits +.PHONY: doc-nits cmd-nits md-nits doc-nits: build_generated $(PERL) $(SRCDIR)/util/find-doc-nits -n -l -e cmd-nits: build_generated apps/openssl $(PERL) $(SRCDIR)/util/find-doc-nits -c +# This uses "mdl", the markdownlint application, which is written in ruby. +# The source is at https://github.com/markdownlint/markdownlint +# If you have ruby installed, "gem install mdl" should work. +# Another option is at https://snapcraft.io/install/mdl/debian +# Finally, there's a Node.js version, which we haven't tried, that +# can be found at https://github.com/DavidAnson/markdownlint +md-nits: + mdl -s util/markdownlint.rb . + # Test coverage is a good idea for the future #coverage: $(PROGRAMS) $(TESTPROGRAMS) # ... @@ -1268,7 +1277,7 @@ EOF if ($args{generator}->[0] =~ /\.pl$/) { $generator = 'CC="$(CC)" $(PERL)'.$generator_incs.' '.$generator - .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSSOR)'; + .' "$(PERLASM_SCHEME)"'.$incs.' '.$cppflags.$defs.' $(PROCESSOR)'; } elsif ($args{generator}->[0] =~ /\.m4$/) { $generator = 'm4 -B 8192'.$generator_incs.' '.$generator.' >' } elsif ($args{generator}->[0] =~ /\.S$/) { diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl index c9f6ccfc..7246ed16 100644 --- a/Configurations/windows-makefile.tmpl +++ b/Configurations/windows-makefile.tmpl @@ -95,12 +95,10 @@ INSTALL_ENGINEPDBS={- @{$unified_info{modules}}) -} INSTALL_MODULES={- - join(" \\\n" . ' ' x 16, - fill_lines(" ", $COLUMNS - 16, - map { platform->dso($_) } - grep { !$unified_info{attributes}->{modules}->{$_}->{noinst} - && !$unified_info{attributes}->{modules}->{$_}->{engine} } - @{$unified_info{modules}})) + join(" ", map { platform->dso($_) } + grep { !$unified_info{attributes}->{modules}->{$_}->{noinst} + && !$unified_info{attributes}->{modules}->{$_}->{engine} } + @{$unified_info{modules}}) -} INSTALL_MODULEPDBS={- join(" ", map { quotify1(platform->dsopdb($_)) } diff --git a/Configure b/Configure index 48ebe4eb..77380734 100755 --- a/Configure +++ b/Configure @@ -21,7 +21,7 @@ use OpenSSL::fallback "$FindBin::Bin/external/perl/MODULES.txt"; use OpenSSL::Glob; use OpenSSL::Template; -# see INSTALL for instructions. +# see INSTALL.md for instructions. my $orig_death_handler = $SIG{__DIE__}; $SIG{__DIE__} = \&death_handler; @@ -1136,7 +1136,8 @@ will not work unless the random generator is seeded manually by the application. Please read the 'Note on random number generation' section in the -INSTALL instructions and the RAND_DRBG(7) manual page for more details. +INSTALL.md instructions and the RAND_DRBG(7) manual page for more +details. ============================== WARNING =============================== _____ @@ -1830,23 +1831,13 @@ if ($builder eq "unified") { my $variable_name_re = qr/(?P[[:alpha:]][[:alnum:]_]*)/; # Value modifier syntaxes my $variable_subst_re = qr/\/(?P(?:\\\/|.)*?)\/(?P.*?)/; - # Put it all together - my $variable_re = qr/\$ - (?| - # Simple case, just the name - ${variable_name_re} - | - # Expressive case, with braces and possible - # modifier expressions - \{ - ${variable_name_re} - (?: - # Pile on modifier expressions, - # separated by | - ${variable_subst_re} - ) - \} - )/x; + # Variable reference + my $variable_simple_re = qr/(?(?:\\\/|.)*?)\}/; + # Tie it all together + my $variable_re = qr/${variable_simple_re}|${variable_w_mod_re}/; + my $expand_variables = sub { my $value = ''; my $value_rest = shift; @@ -1855,25 +1846,29 @@ if ($builder eq "unified") { print STDERR "DEBUG[\$expand_variables] Parsed '$value_rest' ...\n" } - while ($value_rest =~ /(?. For more details on how the make variables TESTS can be used, see section [Running Selected Tests](#running-selected-tests) below. - Notes ===== @@ -1803,20 +1777,19 @@ to install additional support software to obtain a random seed and reseed the CSPRNG manually. Please check out the manual pages for RAND_add(), RAND_bytes(), RAND_egd(), and the FAQ for more information. - [openssl-users]: - https://mta.openssl.org/mailman/listinfo/openssl-users + [SUPPORT]: ./SUPPORT.md [GitHub Issues]: - https://github.com/openssl/openssl/issues + [raise an issue]: - https://github.com/openssl/openssl/issues/new/choose + [10-main.conf]: Configurations/10-main.conf diff --git a/NEWS.md b/NEWS.md index 59081b0c..c09e9599 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,3 @@ - NEWS ==== @@ -19,7 +18,7 @@ OpenSSL Releases OpenSSL 3.0 ----------- -### Major changes between OpenSSL 1.1.1 and OpenSSL 3.0 [under development] ### +### Major changes between OpenSSL 1.1.1 and OpenSSL 3.0 [under development] * The X25519, X448, Ed25519, Ed448 and SHAKE256 algorithms are included in the FIPS provider. None have the "fips=yes" property set and, as such, @@ -35,7 +34,7 @@ OpenSSL 3.0 disabled; the project uses address sanitize/leak-detect instead. * Added a Certificate Management Protocol (CMP, RFC 4210) implementation also covering CRMF (RFC 4211) and HTTP transfer (RFC 6712). - It is part of the crypto lib, while a 'cmp' app using it is in preparation. + It is part of the crypto lib and adds a 'cmp' app with a demo configuration. All widely used CMP features are supported for both clients and servers. * Added a proper HTTP(S) client to libcrypto supporting GET and POST, redirection, plain and ASN.1-encoded contents, proxies, and timeouts. @@ -67,16 +66,16 @@ OpenSSL 3.0 OpenSSL 1.1.1 ------------- -### Major changes between OpenSSL 1.1.1e and OpenSSL 1.1.1f [under development] ### +### Major changes between OpenSSL 1.1.1e and OpenSSL 1.1.1f [under development] - * + * -### Major changes between OpenSSL 1.1.1d and OpenSSL 1.1.1e [17 Mar 2020] ### +### Major changes between OpenSSL 1.1.1d and OpenSSL 1.1.1e [17 Mar 2020] * Fixed an overflow bug in the x64_64 Montgomery squaring procedure used in exponentiation with 512-bit moduli ([CVE-2019-1551][]) -### Major changes between OpenSSL 1.1.1c and OpenSSL 1.1.1d [10 Sep 2019] ### +### Major changes between OpenSSL 1.1.1c and OpenSSL 1.1.1d [10 Sep 2019] * Fixed a fork protection issue ([CVE-2019-1549][]) * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey @@ -93,36 +92,36 @@ OpenSSL 1.1.1 * Significantly reduce secure memory usage by the randomness pools * Revert the DEVRANDOM_WAIT feature for Linux systems -### Major changes between OpenSSL 1.1.1b and OpenSSL 1.1.1c [28 May 2019] ### +### Major changes between OpenSSL 1.1.1b and OpenSSL 1.1.1c [28 May 2019] * Prevent over long nonces in ChaCha20-Poly1305 ([CVE-2019-1543][]) -### Major changes between OpenSSL 1.1.1a and OpenSSL 1.1.1b [26 Feb 2019] ### +### Major changes between OpenSSL 1.1.1a and OpenSSL 1.1.1b [26 Feb 2019] * Change the info callback signals for the start and end of a post-handshake message exchange in TLSv1.3. * Fix a bug in DTLS over SCTP. This breaks interoperability with older versions of OpenSSL like OpenSSL 1.1.0 and OpenSSL 1.0.2. -### Major changes between OpenSSL 1.1.1 and OpenSSL 1.1.1a [20 Nov 2018] ### +### Major changes between OpenSSL 1.1.1 and OpenSSL 1.1.1a [20 Nov 2018] * Timing vulnerability in DSA signature generation ([CVE-2018-0734][]) * Timing vulnerability in ECDSA signature generation ([CVE-2018-0735][]) -### Major changes between OpenSSL 1.1.0i and OpenSSL 1.1.1 [11 Sep 2018] ### +### Major changes between OpenSSL 1.1.0i and OpenSSL 1.1.1 [11 Sep 2018] * Support for TLSv1.3 added. The TLSv1.3 implementation includes: - * Fully compliant implementation of RFC8446 (TLSv1.3) on by default - * Early data (0-RTT) - * Post-handshake authentication and key update - * Middlebox Compatibility Mode - * TLSv1.3 PSKs - * Support for all five RFC8446 ciphersuites - * RSA-PSS signature algorithms (backported to TLSv1.2) - * Configurable session ticket support - * Stateless server support - * Rewrite of the packet construction code for "safer" packet handling - * Rewrite of the extension handling code + * Fully compliant implementation of RFC8446 (TLSv1.3) on by default + * Early data (0-RTT) + * Post-handshake authentication and key update + * Middlebox Compatibility Mode + * TLSv1.3 PSKs + * Support for all five RFC8446 ciphersuites + * RSA-PSS signature algorithms (backported to TLSv1.2) + * Configurable session ticket support + * Stateless server support + * Rewrite of the packet construction code for "safer" packet handling + * Rewrite of the extension handling code For further important information, see the [TLS1.3 page]( https://wiki.openssl.org/index.php/TLS1.3) in the OpenSSL Wiki. @@ -159,11 +158,10 @@ OpenSSL 1.1.1 * Claim the namespaces OSSL and OPENSSL, represented as symbol prefixes * Rewrite of devcrypto engine - OpenSSL 1.1.0 ------------- -### Major changes between OpenSSL 1.1.0k and OpenSSL 1.1.0l [10 Sep 2019] ### +### Major changes between OpenSSL 1.1.0k and OpenSSL 1.1.0l [10 Sep 2019] * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey ([CVE-2019-1563][]) @@ -173,57 +171,57 @@ OpenSSL 1.1.0 ([CVE-2019-1547][]) * Use Windows installation paths in the mingw builds ([CVE-2019-1552][]) -### Major changes between OpenSSL 1.1.0j and OpenSSL 1.1.0k [28 May 2019] ### +### Major changes between OpenSSL 1.1.0j and OpenSSL 1.1.0k [28 May 2019] * Prevent over long nonces in ChaCha20-Poly1305 ([CVE-2019-1543][]) -### Major changes between OpenSSL 1.1.0i and OpenSSL 1.1.0j [20 Nov 2018] ### +### Major changes between OpenSSL 1.1.0i and OpenSSL 1.1.0j [20 Nov 2018] * Timing vulnerability in DSA signature generation ([CVE-2018-0734][]) * Timing vulnerability in ECDSA signature generation ([CVE-2018-0735][]) -### Major changes between OpenSSL 1.1.0h and OpenSSL 1.1.0i [14 Aug 2018] ### +### Major changes between OpenSSL 1.1.0h and OpenSSL 1.1.0i [14 Aug 2018] * Client DoS due to large DH parameter ([CVE-2018-0732][]) * Cache timing vulnerability in RSA Key Generation ([CVE-2018-0737][]) -### Major changes between OpenSSL 1.1.0g and OpenSSL 1.1.0h [27 Mar 2018] ### +### Major changes between OpenSSL 1.1.0g and OpenSSL 1.1.0h [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack ([CVE-2018-0739][]) * Incorrect CRYPTO_memcmp on HP-UX PA-RISC ([CVE-2018-0733][]) * rsaz_1024_mul_avx2 overflow bug on x86_64 ([CVE-2017-3738][]) -### Major changes between OpenSSL 1.1.0f and OpenSSL 1.1.0g [2 Nov 2017] ### +### Major changes between OpenSSL 1.1.0f and OpenSSL 1.1.0g [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 ([CVE-2017-3736][]) * Malformed X.509 IPAddressFamily could cause OOB read ([CVE-2017-3735][]) -### Major changes between OpenSSL 1.1.0e and OpenSSL 1.1.0f [25 May 2017] ### +### Major changes between OpenSSL 1.1.0e and OpenSSL 1.1.0f [25 May 2017] * config now recognises 64-bit mingw and chooses mingw64 instead of mingw -### Major changes between OpenSSL 1.1.0d and OpenSSL 1.1.0e [16 Feb 2017] ### +### Major changes between OpenSSL 1.1.0d and OpenSSL 1.1.0e [16 Feb 2017] * Encrypt-Then-Mac renegotiation crash ([CVE-2017-3733][]) -### Major changes between OpenSSL 1.1.0c and OpenSSL 1.1.0d [26 Jan 2017] ### +### Major changes between OpenSSL 1.1.0c and OpenSSL 1.1.0d [26 Jan 2017] * Truncated packet could crash via OOB read ([CVE-2017-3731][]) * Bad (EC)DHE parameters cause a client crash ([CVE-2017-3730][]) * BN_mod_exp may produce incorrect results on x86_64 ([CVE-2017-3732][]) -### Major changes between OpenSSL 1.1.0b and OpenSSL 1.1.0c [10 Nov 2016] ### +### Major changes between OpenSSL 1.1.0b and OpenSSL 1.1.0c [10 Nov 2016] * ChaCha20/Poly1305 heap-buffer-overflow ([CVE-2016-7054][]) * CMS Null dereference ([CVE-2016-7053][]) * Montgomery multiplication may produce incorrect results ([CVE-2016-7055][]) -### Major changes between OpenSSL 1.1.0a and OpenSSL 1.1.0b [26 Sep 2016] ### +### Major changes between OpenSSL 1.1.0a and OpenSSL 1.1.0b [26 Sep 2016] * Fix Use After Free for large message sizes ([CVE-2016-6309][]) -### Major changes between OpenSSL 1.1.0 and OpenSSL 1.1.0a [22 Sep 2016] ### +### Major changes between OpenSSL 1.1.0 and OpenSSL 1.1.0a [22 Sep 2016] * OCSP Status Request extension unbounded memory growth ([CVE-2016-6304][]) * SSL_peek() hang on empty record ([CVE-2016-6305][]) @@ -232,7 +230,7 @@ OpenSSL 1.1.0 * Excessive allocation of memory in dtls1_preprocess_fragment() ([CVE-2016-6308][]) -### Major changes between OpenSSL 1.0.2h and OpenSSL 1.1.0 [25 Aug 2016] ### +### Major changes between OpenSSL 1.0.2h and OpenSSL 1.1.0 [25 Aug 2016] * Copyright text was shrunk to a boilerplate that points to the license * "shared" builds are now the default when possible @@ -280,11 +278,10 @@ OpenSSL 1.1.0 * Support for Certificate Transparency * HKDF support. - OpenSSL 1.0.2 ------------- -### Major changes between OpenSSL 1.0.2s and OpenSSL 1.0.2t [10 Sep 2019] ### +### Major changes between OpenSSL 1.0.2s and OpenSSL 1.0.2t [10 Sep 2019] * Fixed a padding oracle in PKCS7_dataDecode and CMS_decrypt_set1_pkey ([CVE-2019-1563][]) @@ -295,54 +292,54 @@ OpenSSL 1.0.2 * Document issue with installation paths in diverse Windows builds ([CVE-2019-1552][]) -### Major changes between OpenSSL 1.0.2r and OpenSSL 1.0.2s [28 May 2019] ### +### Major changes between OpenSSL 1.0.2r and OpenSSL 1.0.2s [28 May 2019] * None -### Major changes between OpenSSL 1.0.2q and OpenSSL 1.0.2r [26 Feb 2019] ### +### Major changes between OpenSSL 1.0.2q and OpenSSL 1.0.2r [26 Feb 2019] * 0-byte record padding oracle ([CVE-2019-1559][]) -### Major changes between OpenSSL 1.0.2p and OpenSSL 1.0.2q [20 Nov 2018] ### +### Major changes between OpenSSL 1.0.2p and OpenSSL 1.0.2q [20 Nov 2018] * Microarchitecture timing vulnerability in ECC scalar multiplication ([CVE-2018-5407][]) * Timing vulnerability in DSA signature generation ([CVE-2018-0734][]) -### Major changes between OpenSSL 1.0.2o and OpenSSL 1.0.2p [14 Aug 2018] ### +### Major changes between OpenSSL 1.0.2o and OpenSSL 1.0.2p [14 Aug 2018] * Client DoS due to large DH parameter ([CVE-2018-0732][]) * Cache timing vulnerability in RSA Key Generation ([CVE-2018-0737][]) -### Major changes between OpenSSL 1.0.2n and OpenSSL 1.0.2o [27 Mar 2018] ### +### Major changes between OpenSSL 1.0.2n and OpenSSL 1.0.2o [27 Mar 2018] * Constructed ASN.1 types with a recursive definition could exceed the stack ([CVE-2018-0739][]) -### Major changes between OpenSSL 1.0.2m and OpenSSL 1.0.2n [7 Dec 2017] ### +### Major changes between OpenSSL 1.0.2m and OpenSSL 1.0.2n [7 Dec 2017] * Read/write after SSL object in error state ([CVE-2017-3737][]) * rsaz_1024_mul_avx2 overflow bug on x86_64 ([CVE-2017-3738][]) -### Major changes between OpenSSL 1.0.2l and OpenSSL 1.0.2m [2 Nov 2017] ### +### Major changes between OpenSSL 1.0.2l and OpenSSL 1.0.2m [2 Nov 2017] * bn_sqrx8x_internal carry bug on x86_64 ([CVE-2017-3736][]) * Malformed X.509 IPAddressFamily could cause OOB read ([CVE-2017-3735][]) -### Major changes between OpenSSL 1.0.2k and OpenSSL 1.0.2l [25 May 2017] ### +### Major changes between OpenSSL 1.0.2k and OpenSSL 1.0.2l [25 May 2017] * config now recognises 64-bit mingw and chooses mingw64 instead of mingw -### Major changes between OpenSSL 1.0.2j and OpenSSL 1.0.2k [26 Jan 2017] ### +### Major changes between OpenSSL 1.0.2j and OpenSSL 1.0.2k [26 Jan 2017] * Truncated packet could crash via OOB read ([CVE-2017-3731][]) * BN_mod_exp may produce incorrect results on x86_64 ([CVE-2017-3732][]) * Montgomery multiplication may produce incorrect results ([CVE-2016-7055][]) -### Major changes between OpenSSL 1.0.2i and OpenSSL 1.0.2j [26 Sep 2016] ### +### Major changes between OpenSSL 1.0.2i and OpenSSL 1.0.2j [26 Sep 2016] * Missing CRL sanity check ([CVE-2016-7052][]) -### Major changes between OpenSSL 1.0.2h and OpenSSL 1.0.2i [22 Sep 2016] ### +### Major changes between OpenSSL 1.0.2h and OpenSSL 1.0.2i [22 Sep 2016] * OCSP Status Request extension unbounded memory growth ([CVE-2016-6304][]) * SWEET32 Mitigation ([CVE-2016-2183][]) @@ -356,7 +353,7 @@ OpenSSL 1.0.2 * DTLS replay protection DoS ([CVE-2016-2181][]) * Certificate message OOB reads ([CVE-2016-6306][]) -### Major changes between OpenSSL 1.0.2g and OpenSSL 1.0.2h [3 May 2016] ### +### Major changes between OpenSSL 1.0.2g and OpenSSL 1.0.2h [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check ([CVE-2016-2107][]) * Fix EVP_EncodeUpdate overflow ([CVE-2016-2105][]) @@ -369,7 +366,7 @@ OpenSSL 1.0.2 the default. * Only remove the SSLv2 methods with the no-ssl2-method option. -### Major changes between OpenSSL 1.0.2f and OpenSSL 1.0.2g [1 Mar 2016] ### +### Major changes between OpenSSL 1.0.2f and OpenSSL 1.0.2g [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. * Disable SSLv2 default build, default negotiation and weak ciphers @@ -382,12 +379,12 @@ OpenSSL 1.0.2 * Fix memory issues in BIO_*printf functions ([CVE-2016-0799][]) * Fix side channel attack on modular exponentiation ([CVE-2016-0702][]) -### Major changes between OpenSSL 1.0.2e and OpenSSL 1.0.2f [28 Jan 2016] ### +### Major changes between OpenSSL 1.0.2e and OpenSSL 1.0.2f [28 Jan 2016] * DH small subgroups ([CVE-2016-0701][]) * SSLv2 doesn't block disabled ciphers ([CVE-2015-3197][]) -### Major changes between OpenSSL 1.0.2d and OpenSSL 1.0.2e [3 Dec 2015] ### +### Major changes between OpenSSL 1.0.2d and OpenSSL 1.0.2e [3 Dec 2015] * BN_mod_exp may produce incorrect results on x86_64 ([CVE-2015-3193][]) * Certificate verify crash with missing PSS parameter ([CVE-2015-3194][]) @@ -396,16 +393,16 @@ OpenSSL 1.0.2 * In DSA_generate_parameters_ex, if the provided seed is too short, return an error -### Major changes between OpenSSL 1.0.2c and OpenSSL 1.0.2d [9 Jul 2015] ### +### Major changes between OpenSSL 1.0.2c and OpenSSL 1.0.2d [9 Jul 2015] * Alternate chains certificate forgery ([CVE-2015-1793][]) * Race condition handling PSK identify hint ([CVE-2015-3196][]) -### Major changes between OpenSSL 1.0.2b and OpenSSL 1.0.2c [12 Jun 2015] ### +### Major changes between OpenSSL 1.0.2b and OpenSSL 1.0.2c [12 Jun 2015] * Fix HMAC ABI incompatibility -### Major changes between OpenSSL 1.0.2a and OpenSSL 1.0.2b [11 Jun 2015] ### +### Major changes between OpenSSL 1.0.2a and OpenSSL 1.0.2b [11 Jun 2015] * Malformed ECParameters causes infinite loop ([CVE-2015-1788][]) * Exploitable out-of-bounds read in X509_cmp_time ([CVE-2015-1789][]) @@ -413,7 +410,7 @@ OpenSSL 1.0.2 * CMS verify infinite loop with unknown hash function ([CVE-2015-1792][]) * Race condition handling NewSessionTicket ([CVE-2015-1791][]) -### Major changes between OpenSSL 1.0.2 and OpenSSL 1.0.2a [19 Mar 2015] ### +### Major changes between OpenSSL 1.0.2 and OpenSSL 1.0.2a [19 Mar 2015] * OpenSSL 1.0.2 ClientHello sigalgs DoS fix ([CVE-2015-0291][]) * Multiblock corrupted pointer fix ([CVE-2015-0290][]) @@ -429,7 +426,7 @@ OpenSSL 1.0.2 * X509_to_X509_REQ NULL pointer deref fix ([CVE-2015-0288][]) * Removed the export ciphers from the DEFAULT ciphers -### Major changes between OpenSSL 1.0.1l and OpenSSL 1.0.2 [22 Jan 2015] ### +### Major changes between OpenSSL 1.0.1l and OpenSSL 1.0.2 [22 Jan 2015] * Suite B support for TLS 1.2 and DTLS 1.2 * Support for DTLS 1.2 @@ -440,11 +437,10 @@ OpenSSL 1.0.2 * ALPN support. * CMS support for RSA-PSS, RSA-OAEP, ECDH and X9.42 DH. - OpenSSL 1.0.1 ------------- -### Major changes between OpenSSL 1.0.1t and OpenSSL 1.0.1u [22 Sep 2016] ### +### Major changes between OpenSSL 1.0.1t and OpenSSL 1.0.1u [22 Sep 2016] * OCSP Status Request extension unbounded memory growth ([CVE-2016-6304][]) * SWEET32 Mitigation ([CVE-2016-2183][]) @@ -458,7 +454,7 @@ OpenSSL 1.0.1 * DTLS replay protection DoS ([CVE-2016-2181][]) * Certificate message OOB reads ([CVE-2016-6306][]) -### Major changes between OpenSSL 1.0.1s and OpenSSL 1.0.1t [3 May 2016] ### +### Major changes between OpenSSL 1.0.1s and OpenSSL 1.0.1t [3 May 2016] * Prevent padding oracle in AES-NI CBC MAC check ([CVE-2016-2107][]) * Fix EVP_EncodeUpdate overflow ([CVE-2016-2105][]) @@ -471,7 +467,7 @@ OpenSSL 1.0.1 the default. * Only remove the SSLv2 methods with the no-ssl2-method option. -### Major changes between OpenSSL 1.0.1r and OpenSSL 1.0.1s [1 Mar 2016] ### +### Major changes between OpenSSL 1.0.1r and OpenSSL 1.0.1s [1 Mar 2016] * Disable weak ciphers in SSLv3 and up in default builds of OpenSSL. * Disable SSLv2 default build, default negotiation and weak ciphers @@ -484,12 +480,12 @@ OpenSSL 1.0.1 * Fix memory issues in BIO_*printf functions ([CVE-2016-0799][]) * Fix side channel attack on modular exponentiation ([CVE-2016-0702][]) -### Major changes between OpenSSL 1.0.1q and OpenSSL 1.0.1r [28 Jan 2016] ### +### Major changes between OpenSSL 1.0.1q and OpenSSL 1.0.1r [28 Jan 2016] * Protection for DH small subgroup attacks * SSLv2 doesn't block disabled ciphers ([CVE-2015-3197][]) -### Major changes between OpenSSL 1.0.1p and OpenSSL 1.0.1q [3 Dec 2015] ### +### Major changes between OpenSSL 1.0.1p and OpenSSL 1.0.1q [3 Dec 2015] * Certificate verify crash with missing PSS parameter ([CVE-2015-3194][]) * X509_ATTRIBUTE memory leak ([CVE-2015-3195][]) @@ -497,16 +493,16 @@ OpenSSL 1.0.1 * In DSA_generate_parameters_ex, if the provided seed is too short, return an error -### Major changes between OpenSSL 1.0.1o and OpenSSL 1.0.1p [9 Jul 2015] ### +### Major changes between OpenSSL 1.0.1o and OpenSSL 1.0.1p [9 Jul 2015] * Alternate chains certificate forgery ([CVE-2015-1793][]) * Race condition handling PSK identify hint ([CVE-2015-3196][]) -### Major changes between OpenSSL 1.0.1n and OpenSSL 1.0.1o [12 Jun 2015] ### +### Major changes between OpenSSL 1.0.1n and OpenSSL 1.0.1o [12 Jun 2015] * Fix HMAC ABI incompatibility -### Major changes between OpenSSL 1.0.1m and OpenSSL 1.0.1n [11 Jun 2015] ### +### Major changes between OpenSSL 1.0.1m and OpenSSL 1.0.1n [11 Jun 2015] * Malformed ECParameters causes infinite loop ([CVE-2015-1788][]) * Exploitable out-of-bounds read in X509_cmp_time ([CVE-2015-1789][]) @@ -514,7 +510,7 @@ OpenSSL 1.0.1 * CMS verify infinite loop with unknown hash function ([CVE-2015-1792][]) * Race condition handling NewSessionTicket ([CVE-2015-1791][]) -### Major changes between OpenSSL 1.0.1l and OpenSSL 1.0.1m [19 Mar 2015] ### +### Major changes between OpenSSL 1.0.1l and OpenSSL 1.0.1m [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix ([CVE-2015-0286][]) * ASN.1 structure reuse memory corruption fix ([CVE-2015-0287][]) @@ -524,11 +520,11 @@ OpenSSL 1.0.1 * X509_to_X509_REQ NULL pointer deref fix ([CVE-2015-0288][]) * Removed the export ciphers from the DEFAULT ciphers -### Major changes between OpenSSL 1.0.1k and OpenSSL 1.0.1l [15 Jan 2015] ### +### Major changes between OpenSSL 1.0.1k and OpenSSL 1.0.1l [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms -### Major changes between OpenSSL 1.0.1j and OpenSSL 1.0.1k [8 Jan 2015] ### +### Major changes between OpenSSL 1.0.1j and OpenSSL 1.0.1k [8 Jan 2015] * Fix for [CVE-2014-3571][] * Fix for [CVE-2015-0206][] @@ -539,14 +535,14 @@ OpenSSL 1.0.1 * Fix for [CVE-2014-8275][] * Fix for [CVE-2014-3570][] -### Major changes between OpenSSL 1.0.1i and OpenSSL 1.0.1j [15 Oct 2014] ### +### Major changes between OpenSSL 1.0.1i and OpenSSL 1.0.1j [15 Oct 2014] * Fix for [CVE-2014-3513][] * Fix for [CVE-2014-3567][] * Mitigation for [CVE-2014-3566][] (SSL protocol vulnerability) * Fix for [CVE-2014-3568][] -### Major changes between OpenSSL 1.0.1h and OpenSSL 1.0.1i [6 Aug 2014] ### +### Major changes between OpenSSL 1.0.1h and OpenSSL 1.0.1i [6 Aug 2014] * Fix for [CVE-2014-3512][] * Fix for [CVE-2014-3511][] @@ -558,7 +554,7 @@ OpenSSL 1.0.1 * Fix for [CVE-2014-5139][] * Fix for [CVE-2014-3508][] -### Major changes between OpenSSL 1.0.1g and OpenSSL 1.0.1h [5 Jun 2014] ### +### Major changes between OpenSSL 1.0.1g and OpenSSL 1.0.1h [5 Jun 2014] * Fix for [CVE-2014-0224][] * Fix for [CVE-2014-0221][] @@ -567,24 +563,24 @@ OpenSSL 1.0.1 * Fix for [CVE-2014-3470][] * Fix for [CVE-2010-5298][] -### Major changes between OpenSSL 1.0.1f and OpenSSL 1.0.1g [7 Apr 2014] ### +### Major changes between OpenSSL 1.0.1f and OpenSSL 1.0.1g [7 Apr 2014] * Fix for [CVE-2014-0160][] * Add TLS padding extension workaround for broken servers. * Fix for [CVE-2014-0076][] -### Major changes between OpenSSL 1.0.1e and OpenSSL 1.0.1f [6 Jan 2014] ### +### Major changes between OpenSSL 1.0.1e and OpenSSL 1.0.1f [6 Jan 2014] * Don't include gmt_unix_time in TLS server and client random values * Fix for TLS record tampering bug [CVE-2013-4353][] * Fix for TLS version checking bug [CVE-2013-6449][] * Fix for DTLS retransmission bug [CVE-2013-6450][] -### Major changes between OpenSSL 1.0.1d and OpenSSL 1.0.1e [11 Feb 2013] ### +### Major changes between OpenSSL 1.0.1d and OpenSSL 1.0.1e [11 Feb 2013] * Corrected fix for [CVE-2013-0169][] -### Major changes between OpenSSL 1.0.1c and OpenSSL 1.0.1d [4 Feb 2013] ### +### Major changes between OpenSSL 1.0.1c and OpenSSL 1.0.1d [4 Feb 2013] * Fix renegotiation in TLS 1.1, 1.2 by using the correct TLS version. * Include the fips configuration module. @@ -592,24 +588,24 @@ OpenSSL 1.0.1 * Fix for SSL/TLS/DTLS CBC plaintext recovery attack [CVE-2013-0169][] * Fix for TLS AESNI record handling flaw [CVE-2012-2686][] -### Major changes between OpenSSL 1.0.1b and OpenSSL 1.0.1c [10 May 2012] ### +### Major changes between OpenSSL 1.0.1b and OpenSSL 1.0.1c [10 May 2012] * Fix TLS/DTLS record length checking bug [CVE-2012-2333][] * Don't attempt to use non-FIPS composite ciphers in FIPS mode. -### Major changes between OpenSSL 1.0.1a and OpenSSL 1.0.1b [26 Apr 2012] ### +### Major changes between OpenSSL 1.0.1a and OpenSSL 1.0.1b [26 Apr 2012] * Fix compilation error on non-x86 platforms. * Make FIPS capable OpenSSL ciphers work in non-FIPS mode. * Fix SSL_OP_NO_TLSv1_1 clash with SSL_OP_ALL in OpenSSL 1.0.0 -### Major changes between OpenSSL 1.0.1 and OpenSSL 1.0.1a [19 Apr 2012] ### +### Major changes between OpenSSL 1.0.1 and OpenSSL 1.0.1a [19 Apr 2012] * Fix for ASN1 overflow bug [CVE-2012-2110][] * Workarounds for some servers that hang on long client hellos. * Fix SEGV in AES code. -### Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.1 [14 Mar 2012] ### +### Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.1 [14 Mar 2012] * TLS/DTLS heartbeat support. * SCTP support. @@ -622,16 +618,15 @@ OpenSSL 1.0.1 * Preliminary FIPS capability for unvalidated 2.0 FIPS module. * SRP support. - OpenSSL 1.0.0 ------------- -### Major changes between OpenSSL 1.0.0s and OpenSSL 1.0.0t [3 Dec 2015] ### +### Major changes between OpenSSL 1.0.0s and OpenSSL 1.0.0t [3 Dec 2015] * X509_ATTRIBUTE memory leak ([CVE-2015-3195][]) * Race condition handling PSK identify hint ([CVE-2015-3196][]) -### Major changes between OpenSSL 1.0.0r and OpenSSL 1.0.0s [11 Jun 2015] ### +### Major changes between OpenSSL 1.0.0r and OpenSSL 1.0.0s [11 Jun 2015] * Malformed ECParameters causes infinite loop ([CVE-2015-1788][]) * Exploitable out-of-bounds read in X509_cmp_time ([CVE-2015-1789][]) @@ -639,7 +634,7 @@ OpenSSL 1.0.0 * CMS verify infinite loop with unknown hash function ([CVE-2015-1792][]) * Race condition handling NewSessionTicket ([CVE-2015-1791][]) -### Major changes between OpenSSL 1.0.0q and OpenSSL 1.0.0r [19 Mar 2015] ### +### Major changes between OpenSSL 1.0.0q and OpenSSL 1.0.0r [19 Mar 2015] * Segmentation fault in ASN1_TYPE_cmp fix ([CVE-2015-0286][]) * ASN.1 structure reuse memory corruption fix ([CVE-2015-0287][]) @@ -649,11 +644,11 @@ OpenSSL 1.0.0 * X509_to_X509_REQ NULL pointer deref fix ([CVE-2015-0288][]) * Removed the export ciphers from the DEFAULT ciphers -### Major changes between OpenSSL 1.0.0p and OpenSSL 1.0.0q [15 Jan 2015] ### +### Major changes between OpenSSL 1.0.0p and OpenSSL 1.0.0q [15 Jan 2015] * Build fixes for the Windows and OpenVMS platforms -### Major changes between OpenSSL 1.0.0o and OpenSSL 1.0.0p [8 Jan 2015] ### +### Major changes between OpenSSL 1.0.0o and OpenSSL 1.0.0p [8 Jan 2015] * Fix for [CVE-2014-3571][] * Fix for [CVE-2015-0206][] @@ -664,14 +659,14 @@ OpenSSL 1.0.0 * Fix for [CVE-2014-8275][] * Fix for [CVE-2014-3570][] -### Major changes between OpenSSL 1.0.0n and OpenSSL 1.0.0o [15 Oct 2014] ### +### Major changes between OpenSSL 1.0.0n and OpenSSL 1.0.0o [15 Oct 2014] * Fix for [CVE-2014-3513][] * Fix for [CVE-2014-3567][] * Mitigation for [CVE-2014-3566][] (SSL protocol vulnerability) * Fix for [CVE-2014-3568][] -### Major changes between OpenSSL 1.0.0m and OpenSSL 1.0.0n [6 Aug 2014] ### +### Major changes between OpenSSL 1.0.0m and OpenSSL 1.0.0n [6 Aug 2014] * Fix for [CVE-2014-3510][] * Fix for [CVE-2014-3507][] @@ -685,9 +680,9 @@ OpenSSL 1.0.0 * EAP-FAST and other applications using tls_session_secret_cb wont resume sessions. Fixed in 1.0.0n-dev * Compilation failure of s3_pkt.c on some platforms due to missing - include. Fixed in 1.0.0n-dev + `` include. Fixed in 1.0.0n-dev -### Major changes between OpenSSL 1.0.0l and OpenSSL 1.0.0m [5 Jun 2014] ### +### Major changes between OpenSSL 1.0.0l and OpenSSL 1.0.0m [5 Jun 2014] * Fix for [CVE-2014-0224][] * Fix for [CVE-2014-0221][] @@ -697,35 +692,34 @@ OpenSSL 1.0.0 * Fix for [CVE-2014-0076][] * Fix for [CVE-2010-5298][] -### Major changes between OpenSSL 1.0.0k and OpenSSL 1.0.0l [6 Jan 2014] ### +### Major changes between OpenSSL 1.0.0k and OpenSSL 1.0.0l [6 Jan 2014] * Fix for DTLS retransmission bug [CVE-2013-6450][] -### Major changes between OpenSSL 1.0.0j and OpenSSL 1.0.0k [5 Feb 2013] ### +### Major changes between OpenSSL 1.0.0j and OpenSSL 1.0.0k [5 Feb 2013] * Fix for SSL/TLS/DTLS CBC plaintext recovery attack [CVE-2013-0169][] * Fix OCSP bad key DoS attack [CVE-2013-0166][] -### Major changes between OpenSSL 1.0.0i and OpenSSL 1.0.0j [10 May 2012] ### +### Major changes between OpenSSL 1.0.0i and OpenSSL 1.0.0j [10 May 2012] * Fix DTLS record length checking bug [CVE-2012-2333][] -### Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.0i [19 Apr 2012] ### +### Major changes between OpenSSL 1.0.0h and OpenSSL 1.0.0i [19 Apr 2012] * Fix for ASN1 overflow bug [CVE-2012-2110][] - -### Major changes between OpenSSL 1.0.0g and OpenSSL 1.0.0h [12 Mar 2012] ### +### Major changes between OpenSSL 1.0.0g and OpenSSL 1.0.0h [12 Mar 2012] * Fix for CMS/PKCS#7 MMA [CVE-2012-0884][] * Corrected fix for [CVE-2011-4619][] * Various DTLS fixes. -### Major changes between OpenSSL 1.0.0f and OpenSSL 1.0.0g [18 Jan 2012] ### +### Major changes between OpenSSL 1.0.0f and OpenSSL 1.0.0g [18 Jan 2012] * Fix for DTLS DoS issue [CVE-2012-0050][] -### Major changes between OpenSSL 1.0.0e and OpenSSL 1.0.0f [4 Jan 2012] ### +### Major changes between OpenSSL 1.0.0e and OpenSSL 1.0.0f [4 Jan 2012] * Fix for DTLS plaintext recovery attack [CVE-2011-4108][] * Clear block padding bytes of SSL 3.0 records [CVE-2011-4576][] @@ -733,7 +727,7 @@ OpenSSL 1.0.0 * Check parameters are not NULL in GOST ENGINE [CVE-2012-0027][] * Check for malformed RFC3779 data [CVE-2011-4577][] -### Major changes between OpenSSL 1.0.0d and OpenSSL 1.0.0e [6 Sep 2011] ### +### Major changes between OpenSSL 1.0.0d and OpenSSL 1.0.0e [6 Sep 2011] * Fix for CRL vulnerability issue [CVE-2011-3207][] * Fix for ECDH crashes [CVE-2011-3210][] @@ -741,11 +735,11 @@ OpenSSL 1.0.0 * Support ECDH ciphersuites for certificates using SHA2 algorithms. * Various DTLS fixes. -### Major changes between OpenSSL 1.0.0c and OpenSSL 1.0.0d [8 Feb 2011] ### +### Major changes between OpenSSL 1.0.0c and OpenSSL 1.0.0d [8 Feb 2011] * Fix for security issue [CVE-2011-0014][] -### Major changes between OpenSSL 1.0.0b and OpenSSL 1.0.0c [2 Dec 2010] ### +### Major changes between OpenSSL 1.0.0b and OpenSSL 1.0.0c [2 Dec 2010] * Fix for security issue [CVE-2010-4180][] * Fix for [CVE-2010-4252][] @@ -753,18 +747,18 @@ OpenSSL 1.0.0 * Fix various platform compilation issues. * Corrected fix for security issue [CVE-2010-3864][]. -### Major changes between OpenSSL 1.0.0a and OpenSSL 1.0.0b [16 Nov 2010] ### +### Major changes between OpenSSL 1.0.0a and OpenSSL 1.0.0b [16 Nov 2010] * Fix for security issue [CVE-2010-3864][]. * Fix for [CVE-2010-2939][] * Fix WIN32 build system for GOST ENGINE. -### Major changes between OpenSSL 1.0.0 and OpenSSL 1.0.0a [1 Jun 2010] ### +### Major changes between OpenSSL 1.0.0 and OpenSSL 1.0.0a [1 Jun 2010] * Fix for security issue [CVE-2010-1633][]. * GOST MAC and CFB fixes. -### Major changes between OpenSSL 0.9.8n and OpenSSL 1.0.0 [29 Mar 2010] ### +### Major changes between OpenSSL 0.9.8n and OpenSSL 1.0.0 [29 Mar 2010] * RFC3280 path validation: sufficient to process PKITS tests. * Integrated support for PVK files and keyblobs. @@ -790,12 +784,12 @@ OpenSSL 1.0.0 OpenSSL 0.9.x ------------- -### Major changes between OpenSSL 0.9.8m and OpenSSL 0.9.8n [24 Mar 2010] ### +### Major changes between OpenSSL 0.9.8m and OpenSSL 0.9.8n [24 Mar 2010] * CFB cipher definition fixes. * Fix security issues [CVE-2010-0740][] and [CVE-2010-0433][]. -### Major changes between OpenSSL 0.9.8l and OpenSSL 0.9.8m [25 Feb 2010] ### +### Major changes between OpenSSL 0.9.8l and OpenSSL 0.9.8m [25 Feb 2010] * Cipher definition fixes. * Workaround for slow RAND_poll() on some WIN32 versions. @@ -807,33 +801,33 @@ OpenSSL 0.9.x * Ticket and SNI coexistence fixes. * Many fixes to DTLS handling. -### Major changes between OpenSSL 0.9.8k and OpenSSL 0.9.8l [5 Nov 2009] ### +### Major changes between OpenSSL 0.9.8k and OpenSSL 0.9.8l [5 Nov 2009] * Temporary work around for [CVE-2009-3555][]: disable renegotiation. -### Major changes between OpenSSL 0.9.8j and OpenSSL 0.9.8k [25 Mar 2009] ### +### Major changes between OpenSSL 0.9.8j and OpenSSL 0.9.8k [25 Mar 2009] * Fix various build issues. * Fix security issues ([CVE-2009-0590][], [CVE-2009-0591][], [CVE-2009-0789][]) -### Major changes between OpenSSL 0.9.8i and OpenSSL 0.9.8j [7 Jan 2009] ### +### Major changes between OpenSSL 0.9.8i and OpenSSL 0.9.8j [7 Jan 2009] * Fix security issue ([CVE-2008-5077][]) * Merge FIPS 140-2 branch code. -### Major changes between OpenSSL 0.9.8g and OpenSSL 0.9.8h [28 May 2008] ### +### Major changes between OpenSSL 0.9.8g and OpenSSL 0.9.8h [28 May 2008] * CryptoAPI ENGINE support. * Various precautionary measures. * Fix for bugs affecting certificate request creation. * Support for local machine keyset attribute in PKCS#12 files. -### Major changes between OpenSSL 0.9.8f and OpenSSL 0.9.8g [19 Oct 2007] ### +### Major changes between OpenSSL 0.9.8f and OpenSSL 0.9.8g [19 Oct 2007] * Backport of CMS functionality to 0.9.8. * Fixes for bugs introduced with 0.9.8f. -### Major changes between OpenSSL 0.9.8e and OpenSSL 0.9.8f [11 Oct 2007] ### +### Major changes between OpenSSL 0.9.8e and OpenSSL 0.9.8f [11 Oct 2007] * Add gcc 4.2 support. * Add support for AES and SSE2 assembly language optimization @@ -844,23 +838,23 @@ OpenSSL 0.9.x * RFC4507bis support. * TLS Extensions support. -### Major changes between OpenSSL 0.9.8d and OpenSSL 0.9.8e [23 Feb 2007] ### +### Major changes between OpenSSL 0.9.8d and OpenSSL 0.9.8e [23 Feb 2007] * Various ciphersuite selection fixes. * RFC3779 support. -### Major changes between OpenSSL 0.9.8c and OpenSSL 0.9.8d [28 Sep 2006] ### +### Major changes between OpenSSL 0.9.8c and OpenSSL 0.9.8d [28 Sep 2006] * Introduce limits to prevent malicious key DoS ([CVE-2006-2940][]) * Fix security issues ([CVE-2006-2937][], [CVE-2006-3737][], [CVE-2006-4343][]) * Changes to ciphersuite selection algorithm -### Major changes between OpenSSL 0.9.8b and OpenSSL 0.9.8c [5 Sep 2006] ### +### Major changes between OpenSSL 0.9.8b and OpenSSL 0.9.8c [5 Sep 2006] * Fix Daniel Bleichenbacher forged signature attack, [CVE-2006-4339][] * New cipher Camellia -### Major changes between OpenSSL 0.9.8a and OpenSSL 0.9.8b [4 May 2006] ### +### Major changes between OpenSSL 0.9.8a and OpenSSL 0.9.8b [4 May 2006] * Cipher string fixes. * Fixes for VC++ 2005. @@ -870,12 +864,12 @@ OpenSSL 0.9.x * Built in dynamic engine compilation support on Win32. * Fixes auto dynamic engine loading in Win32. -### Major changes between OpenSSL 0.9.8 and OpenSSL 0.9.8a [11 Oct 2005] ### +### Major changes between OpenSSL 0.9.8 and OpenSSL 0.9.8a [11 Oct 2005] * Fix potential SSL 2.0 rollback, [CVE-2005-2969][] * Extended Windows CE support -### Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.8 [5 Jul 2005] ### +### Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.8 [5 Jul 2005] * Major work on the BIGNUM library for higher efficiency and to make operations more streamlined and less contradictory. This @@ -949,36 +943,36 @@ OpenSSL 0.9.x * Added initial support for Win64. * Added alternate pkg-config files. -### Major changes between OpenSSL 0.9.7l and OpenSSL 0.9.7m [23 Feb 2007] ### +### Major changes between OpenSSL 0.9.7l and OpenSSL 0.9.7m [23 Feb 2007] * FIPS 1.1.1 module linking. * Various ciphersuite selection fixes. -### Major changes between OpenSSL 0.9.7k and OpenSSL 0.9.7l [28 Sep 2006] ### +### Major changes between OpenSSL 0.9.7k and OpenSSL 0.9.7l [28 Sep 2006] * Introduce limits to prevent malicious key DoS ([CVE-2006-2940][]) * Fix security issues ([CVE-2006-2937][], [CVE-2006-3737][], [CVE-2006-4343][]) -### Major changes between OpenSSL 0.9.7j and OpenSSL 0.9.7k [5 Sep 2006] ### +### Major changes between OpenSSL 0.9.7j and OpenSSL 0.9.7k [5 Sep 2006] * Fix Daniel Bleichenbacher forged signature attack, [CVE-2006-4339][] -### Major changes between OpenSSL 0.9.7i and OpenSSL 0.9.7j [4 May 2006] ### +### Major changes between OpenSSL 0.9.7i and OpenSSL 0.9.7j [4 May 2006] * Visual C++ 2005 fixes. * Update Windows build system for FIPS. -### Major changes between OpenSSL 0.9.7h and OpenSSL 0.9.7i [14 Oct 2005] ### +### Major changes between OpenSSL 0.9.7h and OpenSSL 0.9.7i [14 Oct 2005] * Give EVP_MAX_MD_SIZE its old value, except for a FIPS build. -### Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.7h [11 Oct 2005] ### +### Major changes between OpenSSL 0.9.7g and OpenSSL 0.9.7h [11 Oct 2005] * Fix SSL 2.0 Rollback, [CVE-2005-2969][] * Allow use of fixed-length exponent on DSA signing * Default fixed-window RSA, DSA, DH private-key operations -### Major changes between OpenSSL 0.9.7f and OpenSSL 0.9.7g [11 Apr 2005] ### +### Major changes between OpenSSL 0.9.7f and OpenSSL 0.9.7g [11 Apr 2005] * More compilation issues fixed. * Adaptation to more modern Kerberos API. @@ -987,7 +981,7 @@ OpenSSL 0.9.x * More constification. * Added processing of proxy certificates (RFC 3820). -### Major changes between OpenSSL 0.9.7e and OpenSSL 0.9.7f [22 Mar 2005] ### +### Major changes between OpenSSL 0.9.7e and OpenSSL 0.9.7f [22 Mar 2005] * Several compilation issues fixed. * Many memory allocation failure checks added. @@ -995,12 +989,12 @@ OpenSSL 0.9.x * Mandatory basic checks on certificates. * Performance improvements. -### Major changes between OpenSSL 0.9.7d and OpenSSL 0.9.7e [25 Oct 2004] ### +### Major changes between OpenSSL 0.9.7d and OpenSSL 0.9.7e [25 Oct 2004] * Fix race condition in CRL checking code. * Fixes to PKCS#7 (S/MIME) code. -### Major changes between OpenSSL 0.9.7c and OpenSSL 0.9.7d [17 Mar 2004] ### +### Major changes between OpenSSL 0.9.7c and OpenSSL 0.9.7d [17 Mar 2004] * Security: Fix Kerberos ciphersuite SSL/TLS handshaking bug * Security: Fix null-pointer assignment in do_change_cipher_spec() @@ -1008,14 +1002,14 @@ OpenSSL 0.9.x * Multiple X509 verification fixes * Speed up HMAC and other operations -### Major changes between OpenSSL 0.9.7b and OpenSSL 0.9.7c [30 Sep 2003] ### +### Major changes between OpenSSL 0.9.7b and OpenSSL 0.9.7c [30 Sep 2003] * Security: fix various ASN1 parsing bugs. * New -ignore_err option to OCSP utility. * Various interop and bug fixes in S/MIME code. * SSL/TLS protocol fix for unrequested client certificates. -### Major changes between OpenSSL 0.9.7a and OpenSSL 0.9.7b [10 Apr 2003] ### +### Major changes between OpenSSL 0.9.7a and OpenSSL 0.9.7b [10 Apr 2003] * Security: counter the Klima-Pokorny-Rosa extension of Bleichbacher's attack @@ -1026,7 +1020,7 @@ OpenSSL 0.9.x * ASN.1: treat domainComponent correctly. * Documentation: fixes and additions. -### Major changes between OpenSSL 0.9.7 and OpenSSL 0.9.7a [19 Feb 2003] ### +### Major changes between OpenSSL 0.9.7 and OpenSSL 0.9.7a [19 Feb 2003] * Security: Important security related bugfixes. * Enhanced compatibility with MIT Kerberos. @@ -1037,7 +1031,7 @@ OpenSSL 0.9.x * SSL/TLS: now handles manual certificate chain building. * SSL/TLS: certain session ID malfunctions corrected. -### Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.7 [30 Dec 2002] ### +### Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.7 [30 Dec 2002] * New library section OCSP. * Complete rewrite of ASN1 code. @@ -1083,23 +1077,23 @@ OpenSSL 0.9.x * SSL/TLS: add callback to retrieve SSL/TLS messages. * SSL/TLS: support AES cipher suites (RFC3268). -### Major changes between OpenSSL 0.9.6j and OpenSSL 0.9.6k [30 Sep 2003] ### +### Major changes between OpenSSL 0.9.6j and OpenSSL 0.9.6k [30 Sep 2003] * Security: fix various ASN1 parsing bugs. * SSL/TLS protocol fix for unrequested client certificates. -### Major changes between OpenSSL 0.9.6i and OpenSSL 0.9.6j [10 Apr 2003] ### +### Major changes between OpenSSL 0.9.6i and OpenSSL 0.9.6j [10 Apr 2003] * Security: counter the Klima-Pokorny-Rosa extension of Bleichbacher's attack * Security: make RSA blinding default. * Build: shared library support fixes. -### Major changes between OpenSSL 0.9.6h and OpenSSL 0.9.6i [19 Feb 2003] ### +### Major changes between OpenSSL 0.9.6h and OpenSSL 0.9.6i [19 Feb 2003] * Important security related bugfixes. -### Major changes between OpenSSL 0.9.6g and OpenSSL 0.9.6h [5 Dec 2002] ### +### Major changes between OpenSSL 0.9.6g and OpenSSL 0.9.6h [5 Dec 2002] * New configuration targets for Tandem OSS and A/UX. * New OIDs for Microsoft attributes. @@ -1113,25 +1107,25 @@ OpenSSL 0.9.x * Fixes for smaller building problems. * Updates of manuals, FAQ and other instructive documents. -### Major changes between OpenSSL 0.9.6f and OpenSSL 0.9.6g [9 Aug 2002] ### +### Major changes between OpenSSL 0.9.6f and OpenSSL 0.9.6g [9 Aug 2002] * Important building fixes on Unix. -### Major changes between OpenSSL 0.9.6e and OpenSSL 0.9.6f [8 Aug 2002] ### +### Major changes between OpenSSL 0.9.6e and OpenSSL 0.9.6f [8 Aug 2002] * Various important bugfixes. -### Major changes between OpenSSL 0.9.6d and OpenSSL 0.9.6e [30 Jul 2002] ### +### Major changes between OpenSSL 0.9.6d and OpenSSL 0.9.6e [30 Jul 2002] * Important security related bugfixes. * Various SSL/TLS library bugfixes. -### Major changes between OpenSSL 0.9.6c and OpenSSL 0.9.6d [9 May 2002] ### +### Major changes between OpenSSL 0.9.6c and OpenSSL 0.9.6d [9 May 2002] * Various SSL/TLS library bugfixes. * Fix DH parameter generation for 'non-standard' generators. -### Major changes between OpenSSL 0.9.6b and OpenSSL 0.9.6c [21 Dec 2001] ### +### Major changes between OpenSSL 0.9.6b and OpenSSL 0.9.6c [21 Dec 2001] * Various SSL/TLS library bugfixes. * BIGNUM library fixes. @@ -1144,7 +1138,7 @@ OpenSSL 0.9.x Broadcom and Cryptographic Appliance's keyserver [in 0.9.6c-engine release]. -### Major changes between OpenSSL 0.9.6a and OpenSSL 0.9.6b [9 Jul 2001] ### +### Major changes between OpenSSL 0.9.6a and OpenSSL 0.9.6b [9 Jul 2001] * Security fix: PRNG improvements. * Security fix: RSA OAEP check. @@ -1161,7 +1155,7 @@ OpenSSL 0.9.x * Increase default size for BIO buffering filter. * Compatibility fixes in some scripts. -### Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.6a [5 Apr 2001] ### +### Major changes between OpenSSL 0.9.6 and OpenSSL 0.9.6a [5 Apr 2001] * Security fix: change behavior of OpenSSL to avoid using environment variables when running as root. @@ -1186,7 +1180,7 @@ OpenSSL 0.9.x * New function BN_rand_range(). * Add "-rand" option to openssl s_client and s_server. -### Major changes between OpenSSL 0.9.5a and OpenSSL 0.9.6 [10 Oct 2000] ### +### Major changes between OpenSSL 0.9.5a and OpenSSL 0.9.6 [10 Oct 2000] * Some documentation for BIO and SSL libraries. * Enhanced chain verification using key identifiers. @@ -1201,7 +1195,7 @@ OpenSSL 0.9.x [1] The support for external crypto devices is currently a separate distribution. See the file README.ENGINE. -### Major changes between OpenSSL 0.9.5 and OpenSSL 0.9.5a [1 Apr 2000] ### +### Major changes between OpenSSL 0.9.5 and OpenSSL 0.9.5a [1 Apr 2000] * Bug fixes for Win32, SuSE Linux, NeXTSTEP and FreeBSD 2.2.8 * Shared library support for HPUX and Solaris-gcc @@ -1210,7 +1204,7 @@ OpenSSL 0.9.x * New 'rand' application * New way to check for existence of algorithms from scripts -### Major changes between OpenSSL 0.9.4 and OpenSSL 0.9.5 [25 May 2000] ### +### Major changes between OpenSSL 0.9.4 and OpenSSL 0.9.5 [25 May 2000] * S/MIME support in new 'smime' command * Documentation for the OpenSSL command line application @@ -1246,7 +1240,7 @@ OpenSSL 0.9.x * Enhanced support for Alpha Linux * Experimental MacOS support -### Major changes between OpenSSL 0.9.3 and OpenSSL 0.9.4 [9 Aug 1999] ### +### Major changes between OpenSSL 0.9.3 and OpenSSL 0.9.4 [9 Aug 1999] * Transparent support for PKCS#8 format private keys: these are used by several software packages and are more secure than the standard @@ -1257,7 +1251,7 @@ OpenSSL 0.9.x * New pipe-like BIO that allows using the SSL library when actual I/O must be handled by the application (BIO pair) -### Major changes between OpenSSL 0.9.2b and OpenSSL 0.9.3 [24 May 1999] ### +### Major changes between OpenSSL 0.9.2b and OpenSSL 0.9.3 [24 May 1999] * Lots of enhancements and cleanups to the Configuration mechanism * RSA OEAP related fixes @@ -1272,7 +1266,7 @@ OpenSSL 0.9.x * Sparc assembler bignum implementation, optimized hash functions * Option to disable selected ciphers -### Major changes between OpenSSL 0.9.1c and OpenSSL 0.9.2b [22 Mar 1999] ### +### Major changes between OpenSSL 0.9.1c and OpenSSL 0.9.2b [22 Mar 1999] * Fixed a security hole related to session resumption * Fixed RSA encryption routines for the p < q case @@ -1295,7 +1289,7 @@ OpenSSL 0.9.x * Lots of memory leak fixes. * Lots of bug fixes. -### Major changes between SSLeay 0.9.0b and OpenSSL 0.9.1c [23 Dec 1998] ### +### Major changes between SSLeay 0.9.0b and OpenSSL 0.9.1c [23 Dec 1998] * Integration of the popular NO_RSA/NO_DSA patches * Initial support for compression inside the SSL record layer @@ -1307,8 +1301,6 @@ OpenSSL 0.9.x * Adjustments of the source tree for CVS * Support for various new platforms - - [CVE-2019-1563]: https://www.openssl.org/news/vulnerabilities.html#CVE-2019-1563 diff --git a/README.md b/README.md index 98a07f7f..e566d316 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ +Welcome to the OpenSSL Project +============================== + [![openssl logo][]][www.openssl.org] [![travis badge][]][travis jobs] [![appveyor badge][]][appveyor jobs] - - -Welcome to the OpenSSL Project -============================== - OpenSSL is a robust, commercial-grade, full-featured Open Source Toolkit for the Transport Layer Security (TLS) protocol formerly known as the Secure Sockets Layer (SSL) protocol. The protocol implementation is based @@ -19,7 +17,6 @@ and Tim J. Hudson. The official Home Page of the OpenSSL Project is [www.openssl.org][]. - Table of Contents ================= @@ -47,13 +44,13 @@ The OpenSSL toolkit includes: - **openssl** the OpenSSL command line tool, a swiss army knife for cryptographic tasks, testing and analyzing. It can be used for - - creation of key parameters - - creation of X.509 certificates, CSRs and CRLs - - calculation of message digests - - encryption and decryption - - SSL/TLS client and server tests - - handling of S/MIME signed or encrypted mail - - and more... + - creation of key parameters + - creation of X.509 certificates, CSRs and CRLs + - calculation of message digests + - encryption and decryption + - SSL/TLS client and server tests + - handling of S/MIME signed or encrypted mail + - and more... Download ======== @@ -70,7 +67,6 @@ of the OpenSSL toolkit are available. In particular on Linux and other Unix operating systems it is normally recommended to link against the precompiled shared libraries provided by the distributor or vendor. - For Testing and Development --------------------------- @@ -86,22 +82,21 @@ which is updated automatically from the former on every commit. A local copy of the Git Repository can be obtained by cloning it from the original OpenSSL repository using - git clone git://git.openssl.org/openssl.git + git clone git://git.openssl.org/openssl.git or from the GitHub mirror using - git clone https://github.com/openssl/openssl.git + git clone https://github.com/openssl/openssl.git If you intend to contribute to OpenSSL, either to fix bugs or contribute new features, you need to fork the OpenSSL repository openssl/openssl on GitHub and clone your public fork instead. - git clone https://github.com/yourname/openssl.git + git clone https://github.com/yourname/openssl.git This is necessary, because all development of OpenSSL nowadays is done via GitHub pull requests. For more details, see [Contributing](#contributing). - Build and Install ================= @@ -166,7 +161,6 @@ platform. The OpenSSL Project Pages at [openssl.github.io][] are a valuable source of information if you want to get familiar with our development process on GitHub. - Legalities ========== @@ -174,7 +168,6 @@ A number of nations restrict the use or export of cryptography. If you are potentially subject to such restrictions you should seek legal advice before attempting to develop or distribute cryptographic code. - Copyright ========= @@ -184,37 +177,34 @@ Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson All rights reserved. - [www.openssl.org]: - https://www.openssl.org + "OpenSSL Homepage" [git.openssl.org]: - https://git.openssl.org + "OpenSSL Git Repository" [git.openssl.org]: - https://git.openssl.org + "OpenSSL Git Repository" [github.com/openssl/openssl]: - https://github.com/openssl/openssl + "OpenSSL GitHub Mirror" [openssl.github.io]: - https://mspncp.github.io + "OpenSSL Project Pages" [wiki.openssl.org]: - https://wiki.openssl.org + "OpenSSL Wiki" - [RFC 8446]: - https://tools.ietf.org/html/rfc8446 - + [mailing lists]: https://www.openssl.org/community/mailinglists.html diff --git a/VERSION b/VERSION index dde825f8..a342bef4 100644 --- a/VERSION +++ b/VERSION @@ -1,7 +1,7 @@ MAJOR=3 MINOR=0 PATCH=0 -PRE_RELEASE_TAG=alpha2-dev +PRE_RELEASE_TAG=alpha3-dev BUILD_METADATA= RELEASE_DATE="" SHLIB_VERSION=3 diff --git a/apps/asn1pars.c b/apps/asn1pars.c index 342e12d9..9f21f0c7 100644 --- a/apps/asn1pars.c +++ b/apps/asn1pars.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -18,6 +18,9 @@ #include #include +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF_STRING() + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_INFORM, OPT_IN, OPT_OUT, OPT_INDENT, OPT_NOOUT, diff --git a/apps/build.info b/apps/build.info index 30e0c751..1bbedc1b 100644 --- a/apps/build.info +++ b/apps/build.info @@ -44,7 +44,7 @@ IF[{- !$disabled{'engine'} -}] $OPENSSLSRC=$OPENSSLSRC engine.c ENDIF IF[{- !$disabled{'cmp'} -}] - $OPENSSLSRC=$OPENSSLSRC cmp_mock_srv.c + $OPENSSLSRC=$OPENSSLSRC cmp.c cmp_mock_srv.c ENDIF IF[{- !$disabled{apps} -}] @@ -59,6 +59,9 @@ IF[{- !$disabled{apps} -}] # progs.pl tries to read all 'openssl' sources, including progs.c, so we make # sure things are generated in the correct order. DEPEND[progs.h]=progs.c + # Because the files to look through may change (depends on $OPENSSLSRC), + # always depend on a changed configuration. + DEPEND[progs.c]=../configdata.pm IF[{- $config{target} =~ /^(?:Cygwin|mingw|VC-)/ -}] GENERATE[openssl.rc]=../util/mkrc.pl openssl diff --git a/apps/ca.c b/apps/ca.c index 2481ddc2..d91b39c9 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -34,6 +34,11 @@ #include "apps.h" #include "progs.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF_STRING() + #ifndef W_OK # define F_OK 0 # define W_OK 2 @@ -210,12 +215,12 @@ const OPTIONS ca_options[] = { OPT_SECTION("Signing"), {"md", OPT_MD, 's', "md to use; one of md2, md5, sha or sha1"}, {"keyfile", OPT_KEYFILE, 's', "Private key"}, - {"keyform", OPT_KEYFORM, 'f', "Private key file format (PEM or ENGINE)"}, + {"keyform", OPT_KEYFORM, 'f', "Private key file format (ENGINE, other values ignored)"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, {"key", OPT_KEY, 's', "Key to decode the private key if it is encrypted"}, {"cert", OPT_CERT, '<', "The CA cert"}, {"certform", OPT_CERTFORM, 'F', - "certificate input format (DER or PEM); default PEM"}, + "certificate input format (DER/PEM/P12); has no effect"}, {"selfsign", OPT_SELFSIGN, '-', "Sign a cert with the key associated with it"}, {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"}, @@ -380,7 +385,7 @@ opthelp: certfile = opt_arg(); break; case OPT_CERTFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &certformat)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &certformat)) goto opthelp; break; case OPT_SELFSIGN: @@ -568,8 +573,7 @@ end_of_options: } } pkey = load_key(keyfile, keyformat, 0, key, e, "CA private key"); - if (key != NULL) - OPENSSL_cleanse(key, strlen(key)); + cleanse(key); if (pkey == NULL) /* load_key() has already printed an appropriate message */ goto end; diff --git a/apps/ciphers.c b/apps/ciphers.c index 500b4160..380091f1 100644 --- a/apps/ciphers.c +++ b/apps/ciphers.c @@ -15,6 +15,8 @@ #include #include +DEFINE_STACK_OF_CONST(SSL_CIPHER) + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_STDNAME, diff --git a/apps/cmp.c b/apps/cmp.c new file mode 100644 index 00000000..72ebe34d --- /dev/null +++ b/apps/cmp.c @@ -0,0 +1,3174 @@ +/* + * Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved. + * Copyright Nokia 2007-2019 + * Copyright Siemens AG 2015-2019 + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include + +#include "apps.h" +#include "http_server.h" +#include "s_apps.h" +#include "progs.h" + +#include "cmp_mock_srv.h" + +/* tweaks needed due to missing unistd.h on Windows */ +#ifdef _WIN32 +# define access _access +#endif +#ifndef F_OK +# define F_OK 0 +#endif + +#include +#include +#include + +/* explicit #includes not strictly needed since implied by the above: */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(OSSL_CMP_ITAV) + +static char *opt_config = NULL; +#define CMP_SECTION "cmp" +#define SECTION_NAME_MAX 40 /* max length of section name */ +#define DEFAULT_SECTION "default" +static char *opt_section = CMP_SECTION; + +#undef PROG +#define PROG cmp_main +static char *prog = "cmp"; + +static int read_config(void); + +static CONF *conf = NULL; /* OpenSSL config file context structure */ +static OSSL_CMP_CTX *cmp_ctx = NULL; /* the client-side CMP context */ + +/* the type of cmp command we want to send */ +typedef enum { + CMP_IR, + CMP_KUR, + CMP_CR, + CMP_P10CR, + CMP_RR, + CMP_GENM +} cmp_cmd_t; + +/* message transfer */ +static char *opt_server = NULL; +static char server_port_s[32] = { '\0' }; +static int server_port = 0; +static char *opt_proxy = NULL; +static char *opt_no_proxy = NULL; +static char *opt_path = "/"; +static int opt_msg_timeout = -1; +static int opt_total_timeout = -1; + +/* server authentication */ +static char *opt_trusted = NULL; +static char *opt_untrusted = NULL; +static char *opt_srvcert = NULL; +static char *opt_recipient = NULL; +static char *opt_expect_sender = NULL; +static int opt_ignore_keyusage = 0; +static int opt_unprotected_errors = 0; +static char *opt_extracertsout = NULL; +static char *opt_cacertsout = NULL; + +/* client authentication */ +static char *opt_ref = NULL; +static char *opt_secret = NULL; +static char *opt_cert = NULL; +static char *opt_key = NULL; +static char *opt_keypass = NULL; +static char *opt_digest = NULL; +static char *opt_mac = NULL; +static char *opt_extracerts = NULL; +static int opt_unprotected_requests = 0; + +/* generic message */ +static char *opt_cmd_s = NULL; +static int opt_cmd = -1; +static char *opt_geninfo = NULL; +static char *opt_infotype_s = NULL; +static int opt_infotype = NID_undef; + +/* certificate enrollment */ +static char *opt_newkey = NULL; +static char *opt_newkeypass = NULL; +static char *opt_subject = NULL; +static char *opt_issuer = NULL; +static int opt_days = 0; +static char *opt_reqexts = NULL; +static char *opt_sans = NULL; +static int opt_san_nodefault = 0; +static char *opt_policies = NULL; +static char *opt_policy_oids = NULL; +static int opt_policy_oids_critical = 0; +static int opt_popo = OSSL_CRMF_POPO_NONE - 1; +static char *opt_csr = NULL; +static char *opt_out_trusted = NULL; +static int opt_implicit_confirm = 0; +static int opt_disable_confirm = 0; +static char *opt_certout = NULL; + +/* certificate enrollment and revocation */ +static char *opt_oldcert = NULL; +static int opt_revreason = CRL_REASON_NONE; + +/* credentials format */ +static char *opt_certform_s = "PEM"; +static int opt_certform = FORMAT_PEM; +static char *opt_keyform_s = "PEM"; +static int opt_keyform = FORMAT_PEM; +static char *opt_certsform_s = "PEM"; +static int opt_certsform = FORMAT_PEM; +static char *opt_otherpass = NULL; +static char *opt_engine = NULL; + +/* TLS connection */ +static int opt_tls_used = 0; +static char *opt_tls_cert = NULL; +static char *opt_tls_key = NULL; +static char *opt_tls_keypass = NULL; +static char *opt_tls_extra = NULL; +static char *opt_tls_trusted = NULL; +static char *opt_tls_host = NULL; + +/* client-side debugging */ +static int opt_batch = 0; +static int opt_repeat = 1; +static char *opt_reqin = NULL; +static int opt_reqin_new_tid = 0; +static char *opt_reqout = NULL; +static char *opt_rspin = NULL; +static char *opt_rspout = NULL; +static int opt_use_mock_srv = 0; + +/* server-side debugging */ +static char *opt_port = NULL; +static int opt_max_msgs = 0; + +static char *opt_srv_ref = NULL; +static char *opt_srv_secret = NULL; +static char *opt_srv_cert = NULL; +static char *opt_srv_key = NULL; +static char *opt_srv_keypass = NULL; + +static char *opt_srv_trusted = NULL; +static char *opt_srv_untrusted = NULL; +static char *opt_rsp_cert = NULL; +static char *opt_rsp_extracerts = NULL; +static char *opt_rsp_capubs = NULL; +static int opt_poll_count = 0; +static int opt_check_after = 1; +static int opt_grant_implicitconf = 0; + +static int opt_pkistatus = OSSL_CMP_PKISTATUS_accepted; +static int opt_failure = INT_MIN; +static int opt_failurebits = 0; +static char *opt_statusstring = NULL; +static int opt_send_error = 0; +static int opt_send_unprotected = 0; +static int opt_send_unprot_err = 0; +static int opt_accept_unprotected = 0; +static int opt_accept_unprot_err = 0; +static int opt_accept_raverified = 0; + +static X509_VERIFY_PARAM *vpm = NULL; + +typedef enum OPTION_choice { + OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, + OPT_CONFIG, OPT_SECTION, + + OPT_CMD, OPT_INFOTYPE, OPT_GENINFO, + + OPT_NEWKEY, OPT_NEWKEYPASS, OPT_SUBJECT, OPT_ISSUER, + OPT_DAYS, OPT_REQEXTS, + OPT_SANS, OPT_SAN_NODEFAULT, + OPT_POLICIES, OPT_POLICY_OIDS, OPT_POLICY_OIDS_CRITICAL, + OPT_POPO, OPT_CSR, + OPT_OUT_TRUSTED, OPT_IMPLICIT_CONFIRM, OPT_DISABLE_CONFIRM, + OPT_CERTOUT, + + OPT_OLDCERT, OPT_REVREASON, + + OPT_SERVER, OPT_PROXY, OPT_NO_PROXY, OPT_PATH, + OPT_MSG_TIMEOUT, OPT_TOTAL_TIMEOUT, + + OPT_TRUSTED, OPT_UNTRUSTED, OPT_SRVCERT, + OPT_RECIPIENT, OPT_EXPECT_SENDER, + OPT_IGNORE_KEYUSAGE, OPT_UNPROTECTED_ERRORS, + OPT_EXTRACERTSOUT, OPT_CACERTSOUT, + + OPT_REF, OPT_SECRET, OPT_CERT, OPT_KEY, OPT_KEYPASS, + OPT_DIGEST, OPT_MAC, OPT_EXTRACERTS, + OPT_UNPROTECTED_REQUESTS, + + OPT_CERTFORM, OPT_KEYFORM, OPT_CERTSFORM, + OPT_OTHERPASS, +#ifndef OPENSSL_NO_ENGINE + OPT_ENGINE, +#endif + OPT_PROV_ENUM, + + OPT_TLS_USED, OPT_TLS_CERT, OPT_TLS_KEY, + OPT_TLS_KEYPASS, + OPT_TLS_EXTRA, OPT_TLS_TRUSTED, OPT_TLS_HOST, + + OPT_BATCH, OPT_REPEAT, + OPT_REQIN, OPT_REQIN_NEW_TID, OPT_REQOUT, OPT_RSPIN, OPT_RSPOUT, + + OPT_USE_MOCK_SRV, OPT_PORT, OPT_MAX_MSGS, + OPT_SRV_REF, OPT_SRV_SECRET, + OPT_SRV_CERT, OPT_SRV_KEY, OPT_SRV_KEYPASS, + OPT_SRV_TRUSTED, OPT_SRV_UNTRUSTED, + OPT_RSP_CERT, OPT_RSP_EXTRACERTS, OPT_RSP_CAPUBS, + OPT_POLL_COUNT, OPT_CHECK_AFTER, + OPT_GRANT_IMPLICITCONF, + OPT_PKISTATUS, OPT_FAILURE, + OPT_FAILUREBITS, OPT_STATUSSTRING, + OPT_SEND_ERROR, OPT_SEND_UNPROTECTED, + OPT_SEND_UNPROT_ERR, OPT_ACCEPT_UNPROTECTED, + OPT_ACCEPT_UNPROT_ERR, OPT_ACCEPT_RAVERIFIED, + + OPT_V_ENUM +} OPTION_CHOICE; + +const OPTIONS cmp_options[] = { + /* entries must be in the same order as enumerated above!! */ + {"help", OPT_HELP, '-', "Display this summary"}, + {"config", OPT_CONFIG, 's', + "Configuration file to use. \"\" = none. Default from env variable OPENSSL_CONF"}, + {"section", OPT_SECTION, 's', + "Section(s) in config file to get options from. \"\" = 'default'. Default 'cmp'"}, + + OPT_SECTION("Generic message"), + {"cmd", OPT_CMD, 's', "CMP request to send: ir/cr/kur/p10cr/rr/genm"}, + {"infotype", OPT_INFOTYPE, 's', + "InfoType name for requesting specific info in genm, e.g. 'signKeyPairTypes'"}, + {"geninfo", OPT_GENINFO, 's', + "generalInfo integer values to place in request PKIHeader with given OID"}, + {OPT_MORE_STR, 0, 0, + "specified in the form :int:, e.g. \"1.2.3:int:987\""}, + + OPT_SECTION("Certificate enrollment"), + {"newkey", OPT_NEWKEY, 's', + "Private or public key for the requested cert. Default: CSR key or client key"}, + {"newkeypass", OPT_NEWKEYPASS, 's', "New private key pass phrase source"}, + {"subject", OPT_SUBJECT, 's', + "Distinguished Name (DN) of subject to use in the requested cert template"}, + {OPT_MORE_STR, 0, 0, + "For kur, default is the subject DN of the reference cert (see -oldcert);"}, + {OPT_MORE_STR, 0, 0, + "this default is used for ir and cr only if no Subject Alt Names are set"}, + {"issuer", OPT_ISSUER, 's', + "DN of the issuer to place in the requested certificate template"}, + {OPT_MORE_STR, 0, 0, + "also used as recipient if neither -recipient nor -srvcert are given"}, + {"days", OPT_DAYS, 'n', + "Requested validity time of the new certificate in number of days"}, + {"reqexts", OPT_REQEXTS, 's', + "Name of config file section defining certificate request extensions"}, + {"sans", OPT_SANS, 's', + "Subject Alt Names (IPADDR/DNS/URI) to add as (critical) cert req extension"}, + {"san_nodefault", OPT_SAN_NODEFAULT, '-', + "Do not take default SANs from reference certificate (see -oldcert)"}, + {"policies", OPT_POLICIES, 's', + "Name of config file section defining policies certificate request extension"}, + {"policy_oids", OPT_POLICY_OIDS, 's', + "Policy OID(s) to add as policies certificate request extension"}, + {"policy_oids_critical", OPT_POLICY_OIDS_CRITICAL, '-', + "Flag the policy OID(s) given with -policy_oids as critical"}, + {"popo", OPT_POPO, 'n', + "Proof-of-Possession (POPO) method to use for ir/cr/kur where"}, + {OPT_MORE_STR, 0, 0, + "-1 = NONE, 0 = RAVERIFIED, 1 = SIGNATURE (default), 2 = KEYENC"}, + {"csr", OPT_CSR, 's', + "CSR file in PKCS#10 format to use in p10cr for legacy support"}, + {"out_trusted", OPT_OUT_TRUSTED, 's', + "Certificates to trust when verifying newly enrolled certificates"}, + {"implicit_confirm", OPT_IMPLICIT_CONFIRM, '-', + "Request implicit confirmation of newly enrolled certificates"}, + {"disable_confirm", OPT_DISABLE_CONFIRM, '-', + "Do not confirm newly enrolled certificate w/o requesting implicit"}, + {OPT_MORE_STR, 0, 0, + "confirmation. WARNING: This leads to behavior violating RFC 4210"}, + {"certout", OPT_CERTOUT, 's', + "File to save newly enrolled certificate"}, + + OPT_SECTION("Certificate enrollment and revocation"), + + {"oldcert", OPT_OLDCERT, 's', + "Certificate to be updated (defaulting to -cert) or to be revoked in rr;"}, + {OPT_MORE_STR, 0, 0, + "also used as reference (defaulting to -cert) for subject DN and SANs."}, + {OPT_MORE_STR, 0, 0, + "Its issuer is used as recipient unless -srvcert, -recipient or -issuer given"}, + {"revreason", OPT_REVREASON, 'n', + "Reason code to include in revocation request (rr); possible values:"}, + {OPT_MORE_STR, 0, 0, + "0..6, 8..10 (see RFC5280, 5.3.1) or -1. Default -1 = none included"}, + + OPT_SECTION("Message transfer"), + {"server", OPT_SERVER, 's', + "[http[s]://]address[:port] of CMP server. Default port 80 or 443."}, + {OPT_MORE_STR, 0, 0, + "The address may be a DNS name or an IP address"}, + {"proxy", OPT_PROXY, 's', + "[http[s]://]address[:port][/path] of HTTP(S) proxy to use; path is ignored"}, + {"no_proxy", OPT_NO_PROXY, 's', + "List of addresses of servers not to use HTTP(S) proxy for"}, + {OPT_MORE_STR, 0, 0, + "Default from environment variable 'no_proxy', else 'NO_PROXY', else none"}, + {"path", OPT_PATH, 's', + "HTTP path (aka CMP alias) at the CMP server. Default \"/\""}, + {"msg_timeout", OPT_MSG_TIMEOUT, 'n', + "Timeout per CMP message round trip (or 0 for none). Default 120 seconds"}, + {"total_timeout", OPT_TOTAL_TIMEOUT, 'n', + "Overall time an enrollment incl. polling may take. Default 0 = infinite"}, + + OPT_SECTION("Server authentication"), + {"trusted", OPT_TRUSTED, 's', + "Trusted certs used for CMP server authentication when verifying responses"}, + {OPT_MORE_STR, 0, 0, "unless -srvcert is given"}, + {"untrusted", OPT_UNTRUSTED, 's', + "Intermediate certs for chain construction verifying CMP/TLS/enrolled certs"}, + {"srvcert", OPT_SRVCERT, 's', + "Specific CMP server cert to use and trust directly when verifying responses"}, + {"recipient", OPT_RECIPIENT, 's', + "Distinguished Name (DN) of the recipient to use unless -srvcert is given"}, + {"expect_sender", OPT_EXPECT_SENDER, 's', + "DN of expected response sender. Defaults to DN of -srvcert, if provided"}, + {"ignore_keyusage", OPT_IGNORE_KEYUSAGE, '-', + "Ignore CMP signer cert key usage, else 'digitalSignature' must be allowed"}, + {"unprotected_errors", OPT_UNPROTECTED_ERRORS, '-', + "Accept missing or invalid protection of regular error messages and negative"}, + {OPT_MORE_STR, 0, 0, + "certificate responses (ip/cp/kup), revocation responses (rp), and PKIConf"}, + {OPT_MORE_STR, 0, 0, + "WARNING: This setting leads to behavior allowing violation of RFC 4210"}, + {"extracertsout", OPT_EXTRACERTSOUT, 's', + "File to save extra certificates received in the extraCerts field"}, + {"cacertsout", OPT_CACERTSOUT, 's', + "File to save CA certificates received in the caPubs field of 'ip' messages"}, + + OPT_SECTION("Client authentication"), + {"ref", OPT_REF, 's', + "Reference value to use as senderKID in case no -cert is given"}, + {"secret", OPT_SECRET, 's', + "Password source for client authentication with a pre-shared key (secret)"}, + {"cert", OPT_CERT, 's', + "Client's current certificate (needed unless using -secret for PBM);"}, + {OPT_MORE_STR, 0, 0, + "any further certs included are appended in extraCerts field"}, + {"key", OPT_KEY, 's', "Private key for the client's current certificate"}, + {"keypass", OPT_KEYPASS, 's', + "Client private key (and cert and old cert file) pass phrase source"}, + {"digest", OPT_DIGEST, 's', + "Digest to use in message protection and POPO signatures. Default \"sha256\""}, + {"mac", OPT_MAC, 's', + "MAC algorithm to use in PBM-based message protection. Default \"hmac-sha1\""}, + {"extracerts", OPT_EXTRACERTS, 's', + "Certificates to append in extraCerts field of outgoing messages"}, + {"unprotected_requests", OPT_UNPROTECTED_REQUESTS, '-', + "Send messages without CMP-level protection"}, + + OPT_SECTION("Credentials format"), + {"certform", OPT_CERTFORM, 's', + "Format (PEM or DER) to use when saving a certificate to a file. Default PEM"}, + {OPT_MORE_STR, 0, 0, + "This also determines format to use for writing (not supported for P12)"}, + {"keyform", OPT_KEYFORM, 's', + "Format to assume when reading key files. Default PEM"}, + {"certsform", OPT_CERTSFORM, 's', + "Format (PEM/DER/P12) to try first reading multiple certs. Default PEM"}, + {"otherpass", OPT_OTHERPASS, 's', + "Pass phrase source potentially needed for loading certificates of others"}, +#ifndef OPENSSL_NO_ENGINE + {"engine", OPT_ENGINE, 's', + "Use crypto engine with given identifier, possibly a hardware device."}, + {OPT_MORE_STR, 0, 0, + "Engines may be defined in OpenSSL config file engine section."}, + {OPT_MORE_STR, 0, 0, + "Options like -key specifying keys held in the engine can give key IDs"}, + {OPT_MORE_STR, 0, 0, + "prefixed by 'engine:', e.g. '-key engine:pkcs11:object=mykey;pin-value=1234'"}, +#endif + OPT_PROV_OPTIONS, + + OPT_SECTION("TLS connection"), + {"tls_used", OPT_TLS_USED, '-', + "Enable using TLS (also when other TLS options are not set)"}, + {"tls_cert", OPT_TLS_CERT, 's', + "Client's TLS certificate. May include chain to be provided to TLS server"}, + {"tls_key", OPT_TLS_KEY, 's', + "Private key for the client's TLS certificate"}, + {"tls_keypass", OPT_TLS_KEYPASS, 's', + "Pass phrase source for the client's private TLS key (and TLS cert file)"}, + {"tls_extra", OPT_TLS_EXTRA, 's', + "Extra certificates to provide to TLS server during TLS handshake"}, + {"tls_trusted", OPT_TLS_TRUSTED, 's', + "Trusted certificates to use for verifying the TLS server certificate;"}, + {OPT_MORE_STR, 0, 0, "this implies host name validation"}, + {"tls_host", OPT_TLS_HOST, 's', + "Address to be checked (rather than -server) during TLS host name validation"}, + + OPT_SECTION("Client-side debugging"), + {"batch", OPT_BATCH, '-', + "Do not interactively prompt for input when a password is required etc."}, + {"repeat", OPT_REPEAT, 'n', + "Invoke the transaction the given number of times. Default 1"}, + {"reqin", OPT_REQIN, 's', "Take sequence of CMP requests from file(s)"}, + {"reqin_new_tid", OPT_REQIN_NEW_TID, '-', + "Use fresh transactionID for CMP requests read from -reqin"}, + {"reqout", OPT_REQOUT, 's', "Save sequence of CMP requests to file(s)"}, + {"rspin", OPT_RSPIN, 's', + "Process sequence of CMP responses provided in file(s), skipping server"}, + {"rspout", OPT_RSPOUT, 's', "Save sequence of CMP responses to file(s)"}, + + {"use_mock_srv", OPT_USE_MOCK_SRV, '-', "Use mock server at API level, bypassing HTTP"}, + + OPT_SECTION("Mock server"), + {"port", OPT_PORT, 's', "Act as HTTP mock server listening on given port"}, + {"max_msgs", OPT_MAX_MSGS, 'n', + "max number of messages handled by HTTP mock server. Default: 0 = unlimited"}, + + {"srv_ref", OPT_SRV_REF, 's', + "Reference value to use as senderKID of server in case no -srv_cert is given"}, + {"srv_secret", OPT_SRV_SECRET, 's', + "Password source for server authentication with a pre-shared key (secret)"}, + {"srv_cert", OPT_SRV_CERT, 's', "Certificate of the server"}, + {"srv_key", OPT_SRV_KEY, 's', + "Private key used by the server for signing messages"}, + {"srv_keypass", OPT_SRV_KEYPASS, 's', + "Server private key (and cert) file pass phrase source"}, + + {"srv_trusted", OPT_SRV_TRUSTED, 's', + "Trusted certificates for client authentication"}, + {"srv_untrusted", OPT_SRV_UNTRUSTED, 's', + "Intermediate certs that may be useful for verifying CMP protection"}, + {"rsp_cert", OPT_RSP_CERT, 's', + "Certificate to be returned as mock enrollment result"}, + {"rsp_extracerts", OPT_RSP_EXTRACERTS, 's', + "Extra certificates to be included in mock certification responses"}, + {"rsp_capubs", OPT_RSP_CAPUBS, 's', + "CA certificates to be included in mock ip response"}, + {"poll_count", OPT_POLL_COUNT, 'n', + "Number of times the client must poll before receiving a certificate"}, + {"check_after", OPT_CHECK_AFTER, 'n', + "The check_after value (time to wait) to include in poll response"}, + {"grant_implicitconf", OPT_GRANT_IMPLICITCONF, '-', + "Grant implicit confirmation of newly enrolled certificate"}, + + {"pkistatus", OPT_PKISTATUS, 'n', + "PKIStatus to be included in server response. Possible values: 0..6"}, + {"failure", OPT_FAILURE, 'n', + "A single failure info bit number to include in server response, 0..26"}, + {"failurebits", OPT_FAILUREBITS, 'n', + "Number representing failure bits to include in server response, 0..2^27 - 1"}, + {"statusstring", OPT_STATUSSTRING, 's', + "Status string to be included in server response"}, + {"send_error", OPT_SEND_ERROR, '-', + "Force server to reply with error message"}, + {"send_unprotected", OPT_SEND_UNPROTECTED, '-', + "Send response messages without CMP-level protection"}, + {"send_unprot_err", OPT_SEND_UNPROT_ERR, '-', + "In case of negative responses, server shall send unprotected error messages,"}, + {OPT_MORE_STR, 0, 0, + "certificate responses (ip/cp/kup), and revocation responses (rp)."}, + {OPT_MORE_STR, 0, 0, + "WARNING: This setting leads to behavior violating RFC 4210"}, + {"accept_unprotected", OPT_ACCEPT_UNPROTECTED, '-', + "Accept missing or invalid protection of requests"}, + {"accept_unprot_err", OPT_ACCEPT_UNPROT_ERR, '-', + "Accept unprotected error messages from client"}, + {"accept_raverified", OPT_ACCEPT_RAVERIFIED, '-', + "Accept RAVERIFIED as proof-of-possession (POPO)"}, + + OPT_V_OPTIONS, + {NULL} +}; + +typedef union { + char **txt; + int *num; + long *num_long; +} varref; +static varref cmp_vars[] = { /* must be in same order as enumerated above! */ + {&opt_config}, {&opt_section}, + + {&opt_cmd_s}, {&opt_infotype_s}, {&opt_geninfo}, + + {&opt_newkey}, {&opt_newkeypass}, {&opt_subject}, {&opt_issuer}, + {(char **)&opt_days}, {&opt_reqexts}, + {&opt_sans}, {(char **)&opt_san_nodefault}, + {&opt_policies}, {&opt_policy_oids}, {(char **)&opt_policy_oids_critical}, + {(char **)&opt_popo}, {&opt_csr}, + {&opt_out_trusted}, + {(char **)&opt_implicit_confirm}, {(char **)&opt_disable_confirm}, + {&opt_certout}, + + {&opt_oldcert}, {(char **)&opt_revreason}, + + {&opt_server}, {&opt_proxy}, {&opt_no_proxy}, {&opt_path}, + {(char **)&opt_msg_timeout}, {(char **)&opt_total_timeout}, + + {&opt_trusted}, {&opt_untrusted}, {&opt_srvcert}, + {&opt_recipient}, {&opt_expect_sender}, + {(char **)&opt_ignore_keyusage}, {(char **)&opt_unprotected_errors}, + {&opt_extracertsout}, {&opt_cacertsout}, + + {&opt_ref}, {&opt_secret}, {&opt_cert}, {&opt_key}, {&opt_keypass}, + {&opt_digest}, {&opt_mac}, {&opt_extracerts}, + {(char **)&opt_unprotected_requests}, + + {&opt_certform_s}, {&opt_keyform_s}, {&opt_certsform_s}, + {&opt_otherpass}, +#ifndef OPENSSL_NO_ENGINE + {&opt_engine}, +#endif + + {(char **)&opt_tls_used}, {&opt_tls_cert}, {&opt_tls_key}, + {&opt_tls_keypass}, + {&opt_tls_extra}, {&opt_tls_trusted}, {&opt_tls_host}, + + {(char **)&opt_batch}, {(char **)&opt_repeat}, + {&opt_reqin}, {(char **)&opt_reqin_new_tid}, + {&opt_reqout}, {&opt_rspin}, {&opt_rspout}, + + {(char **)&opt_use_mock_srv}, {&opt_port}, {(char **)&opt_max_msgs}, + {&opt_srv_ref}, {&opt_srv_secret}, + {&opt_srv_cert}, {&opt_srv_key}, {&opt_srv_keypass}, + {&opt_srv_trusted}, {&opt_srv_untrusted}, + {&opt_rsp_cert}, {&opt_rsp_extracerts}, {&opt_rsp_capubs}, + {(char **)&opt_poll_count}, {(char **)&opt_check_after}, + {(char **)&opt_grant_implicitconf}, + {(char **)&opt_pkistatus}, {(char **)&opt_failure}, + {(char **)&opt_failurebits}, {&opt_statusstring}, + {(char **)&opt_send_error}, {(char **)&opt_send_unprotected}, + {(char **)&opt_send_unprot_err}, {(char **)&opt_accept_unprotected}, + {(char **)&opt_accept_unprot_err}, {(char **)&opt_accept_raverified}, + + {NULL} +}; + +#ifndef NDEBUG +# define FUNC (strcmp(OPENSSL_FUNC, "(unknown function)") == 0 \ + ? "CMP" : "OPENSSL_FUNC") +# define PRINT_LOCATION(bio) BIO_printf(bio, "%s:%s:%d:", \ + FUNC, OPENSSL_FILE, OPENSSL_LINE) +#else +# define PRINT_LOCATION(bio) ((void)0) +#endif +#define CMP_print(bio, prefix, msg, a1, a2, a3) \ + (PRINT_LOCATION(bio), \ + BIO_printf(bio, "CMP %s: " msg "\n", prefix, a1, a2, a3)) +#define CMP_INFO(msg, a1, a2, a3) CMP_print(bio_out, "info", msg, a1, a2, a3) +#define CMP_info(msg) CMP_INFO(msg"%s%s%s", "", "", "") +#define CMP_info1(msg, a1) CMP_INFO(msg"%s%s", a1, "", "") +#define CMP_info2(msg, a1, a2) CMP_INFO(msg"%s", a1, a2, "") +#define CMP_info3(msg, a1, a2, a3) CMP_INFO(msg, a1, a2, a3) +#define CMP_WARN(m, a1, a2, a3) CMP_print(bio_out, "warning", m, a1, a2, a3) +#define CMP_warn(msg) CMP_WARN(msg"%s%s%s", "", "", "") +#define CMP_warn1(msg, a1) CMP_WARN(msg"%s%s", a1, "", "") +#define CMP_warn2(msg, a1, a2) CMP_WARN(msg"%s", a1, a2, "") +#define CMP_warn3(msg, a1, a2, a3) CMP_WARN(msg, a1, a2, a3) +#define CMP_ERR(msg, a1, a2, a3) CMP_print(bio_err, "error", msg, a1, a2, a3) +#define CMP_err(msg) CMP_ERR(msg"%s%s%s", "", "", "") +#define CMP_err1(msg, a1) CMP_ERR(msg"%s%s", a1, "", "") +#define CMP_err2(msg, a1, a2) CMP_ERR(msg"%s", a1, a2, "") +#define CMP_err3(msg, a1, a2, a3) CMP_ERR(msg, a1, a2, a3) + +static int print_to_bio_out(const char *func, const char *file, int line, + OSSL_CMP_severity level, const char *msg) +{ + return OSSL_CMP_print_to_bio(bio_out, func, file, line, level, msg); +} + +/* code duplicated from crypto/cmp/cmp_util.c */ +static int sk_X509_add1_cert(STACK_OF(X509) *sk, X509 *cert, + int no_dup, int prepend) +{ + if (no_dup) { + /* + * not using sk_X509_set_cmp_func() and sk_X509_find() + * because this re-orders the certs on the stack + */ + int i; + + for (i = 0; i < sk_X509_num(sk); i++) { + if (X509_cmp(sk_X509_value(sk, i), cert) == 0) + return 1; + } + } + if (!X509_up_ref(cert)) + return 0; + if (!sk_X509_insert(sk, cert, prepend ? 0 : -1)) { + X509_free(cert); + return 0; + } + return 1; +} + +/* code duplicated from crypto/cmp/cmp_util.c */ +static int sk_X509_add1_certs(STACK_OF(X509) *sk, STACK_OF(X509) *certs, + int no_self_signed, int no_dups, int prepend) +/* compiler would allow 'const' for the list of certs, yet they are up-ref'ed */ +{ + int i; + + if (sk == NULL) + return 0; + if (certs == NULL) + return 1; + for (i = 0; i < sk_X509_num(certs); i++) { + X509 *cert = sk_X509_value(certs, i); + + if (!no_self_signed || X509_check_issued(cert, cert) != X509_V_OK) { + if (!sk_X509_add1_cert(sk, cert, no_dups, prepend)) + return 0; + } + } + return 1; +} + +/* TODO potentially move to apps/lib/apps.c */ +static char *next_item(char *opt) /* in list separated by comma and/or space */ +{ + /* advance to separator (comma or whitespace), if any */ + while (*opt != ',' && !isspace(*opt) && *opt != '\0') { + if (*opt == '\\' && opt[1] != '\0') + /* skip and unescape '\' escaped char */ + memmove(opt, opt + 1, strlen(opt)); + opt++; + } + if (*opt != '\0') { + /* terminate current item */ + *opt++ = '\0'; + /* skip over any whitespace after separator */ + while (isspace(*opt)) + opt++; + } + return *opt == '\0' ? NULL : opt; /* NULL indicates end of input */ +} + +static EVP_PKEY *load_key_pwd(const char *uri, int format, + const char *pass, ENGINE *e, const char *desc) +{ + char *pass_string = get_passwd(pass, desc); + EVP_PKEY *pkey = load_key(uri, format, 0, pass_string, e, desc); + + clear_free(pass_string); + return pkey; +} + +static X509 *load_cert_pwd(const char *uri, const char *pass, const char *desc) +{ + X509 *cert; + char *pass_string = get_passwd(pass, desc); + + cert = load_cert_pass(uri, 0, pass_string, desc); + clear_free(pass_string); + return cert; +} + +/* TODO remove when PR #4930 is merged */ +static int load_pkcs12(BIO *in, const char *desc, + pem_password_cb *pem_cb, void *cb_data, + EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca) +{ + const char *pass; + char tpass[PEM_BUFSIZE]; + int len; + int ret = 0; + PKCS12 *p12 = d2i_PKCS12_bio(in, NULL); + + if (desc == NULL) + desc = "PKCS12 input"; + if (p12 == NULL) { + BIO_printf(bio_err, "error loading PKCS12 file for %s\n", desc); + goto die; + } + + /* See if an empty password will do */ + if (PKCS12_verify_mac(p12, "", 0) || PKCS12_verify_mac(p12, NULL, 0)) { + pass = ""; + } else { + if (pem_cb == NULL) + pem_cb = wrap_password_callback; + len = pem_cb(tpass, PEM_BUFSIZE, 0, cb_data); + if (len < 0) { + BIO_printf(bio_err, "passphrase callback error for %s\n", desc); + goto die; + } + if (len < PEM_BUFSIZE) + tpass[len] = 0; + if (!PKCS12_verify_mac(p12, tpass, len)) { + BIO_printf(bio_err, + "mac verify error (wrong password?) in PKCS12 file for %s\n", + desc); + goto die; + } + pass = tpass; + } + ret = PKCS12_parse(p12, pass, pkey, cert, ca); + die: + PKCS12_free(p12); + return ret; +} + +/* TODO potentially move this and related functions to apps/lib/apps.c */ +static int adjust_format(const char **infile, int format, int engine_ok) +{ + if (!strncasecmp(*infile, "http://", 7) + || !strncasecmp(*infile, "https://", 8)) { + format = FORMAT_HTTP; + } else if (engine_ok && strncasecmp(*infile, "engine:", 7) == 0) { + *infile += 7; + format = FORMAT_ENGINE; + } else { + if (strncasecmp(*infile, "file:", 5) == 0) + *infile += 5; + /* + * the following is a heuristic whether first to try PEM or DER + * or PKCS12 as the input format for files + */ + if (strlen(*infile) >= 4) { + const char *extension = *infile + strlen(*infile) - 4; + + if (strncasecmp(extension, ".crt", 4) == 0 + || strncasecmp(extension, ".pem", 4) == 0) + /* weak recognition of PEM format */ + format = FORMAT_PEM; + else if (strncasecmp(extension, ".cer", 4) == 0 + || strncasecmp(extension, ".der", 4) == 0) + /* weak recognition of DER format */ + format = FORMAT_ASN1; + else if (strncasecmp(extension, ".p12", 4) == 0) + /* weak recognition of PKCS#12 format */ + format = FORMAT_PKCS12; + /* else retain given format */ + } + } + return format; +} + +/* + * TODO potentially move this and related functions to apps/lib/ + * or even better extend OSSL_STORE with type OSSL_STORE_INFO_CRL + */ +static X509_REQ *load_csr_autofmt(const char *infile, const char *desc) +{ + X509_REQ *csr; + BIO *bio_bak = bio_err; + int can_retry; + int format = adjust_format(&infile, FORMAT_PEM, 0); + + can_retry = format == FORMAT_PEM || format == FORMAT_ASN1; + if (can_retry) + bio_err = NULL; /* do not show errors on more than one try */ + csr = load_csr(infile, format, desc); + bio_err = bio_bak; + if (csr == NULL && can_retry) { + ERR_clear_error(); + format = (format == FORMAT_PEM ? FORMAT_ASN1 : FORMAT_PEM); + csr = load_csr(infile, format, desc); + } + if (csr == NULL) { + ERR_print_errors(bio_err); + BIO_printf(bio_err, "error: unable to load %s from file '%s'\n", desc, + infile); + } + return csr; +} + +/* TODO replace by calling generalized load_certs() when PR #4930 is merged */ +static int load_certs_preliminary(const char *file, STACK_OF(X509) **certs, + int format, const char *pass, + const char *desc) +{ + X509 *cert = NULL; + int ret = 0; + + if (format == FORMAT_PKCS12) { + BIO *bio = bio_open_default(file, 'r', format); + + if (bio != NULL) { + EVP_PKEY *pkey = NULL; /* pkey is needed until PR #4930 is merged */ + PW_CB_DATA cb_data; + + cb_data.password = pass; + cb_data.prompt_info = file; + ret = load_pkcs12(bio, desc, wrap_password_callback, + &cb_data, &pkey, &cert, certs); + EVP_PKEY_free(pkey); + BIO_free(bio); + } + } else if (format == FORMAT_ASN1) { /* load only one cert in this case */ + CMP_warn1("can load only one certificate in DER format from %s", file); + cert = load_cert_pass(file, 0, pass, desc); + } + if (format == FORMAT_PKCS12 || format == FORMAT_ASN1) { + if (cert) { + if (*certs == NULL) + *certs = sk_X509_new_null(); + if (*certs != NULL) + ret = sk_X509_insert(*certs, cert, 0); + else + X509_free(cert); + } + } else { + ret = load_certs(file, certs, format, pass, desc); + } + return ret; +} + +static void warn_certs_expired(const char *file, STACK_OF(X509) **certs) +{ + int i, res; + X509 *cert; + char *subj; + + for (i = 0; i < sk_X509_num(*certs); i++) { + cert = sk_X509_value(*certs, i); + res = X509_cmp_timeframe(vpm, X509_get0_notBefore(cert), + X509_get0_notAfter(cert)); + if (res != 0) { + subj = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0); + CMP_warn3("certificate from '%s' with subject '%s' %s", file, subj, + res > 0 ? "has expired" : "not yet valid"); + OPENSSL_free(subj); + } + } +} + +/* + * TODO potentially move this and related functions to apps/lib/ + * or even better extend OSSL_STORE with type OSSL_STORE_INFO_CERTS + */ +static int load_certs_autofmt(const char *infile, STACK_OF(X509) **certs, + int exclude_http, const char *pass, + const char *desc) +{ + int ret = 0; + char *pass_string; + BIO *bio_bak = bio_err; + int format = adjust_format(&infile, opt_certsform, 0); + + if (exclude_http && format == FORMAT_HTTP) { + BIO_printf(bio_err, "error: HTTP retrieval not allowed for %s\n", desc); + return ret; + } + pass_string = get_passwd(pass, desc); + if (format != FORMAT_HTTP) + bio_err = NULL; /* do not show errors on more than one try */ + ret = load_certs_preliminary(infile, certs, format, pass_string, desc); + bio_err = bio_bak; + if (!ret && format != FORMAT_HTTP) { + int format2 = format == FORMAT_PEM ? FORMAT_ASN1 : FORMAT_PEM; + + ERR_clear_error(); + ret = load_certs_preliminary(infile, certs, format2, pass_string, desc); + } + clear_free(pass_string); + + if (ret) + warn_certs_expired(infile, certs); + return ret; +} + +/* set expected host name/IP addr and clears the email addr in the given ts */ +static int truststore_set_host_etc(X509_STORE *ts, char *host) +{ + X509_VERIFY_PARAM *ts_vpm = X509_STORE_get0_param(ts); + + /* first clear any host names, IP, and email addresses */ + if (!X509_VERIFY_PARAM_set1_host(ts_vpm, NULL, 0) + || !X509_VERIFY_PARAM_set1_ip(ts_vpm, NULL, 0) + || !X509_VERIFY_PARAM_set1_email(ts_vpm, NULL, 0)) + return 0; + X509_VERIFY_PARAM_set_hostflags(ts_vpm, + X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT | + X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); + return (host != NULL && X509_VERIFY_PARAM_set1_ip_asc(ts_vpm, host)) + || X509_VERIFY_PARAM_set1_host(ts_vpm, host, 0); +} + +static X509_STORE *sk_X509_to_store(X509_STORE *store /* may be NULL */, + const STACK_OF(X509) *certs /* may NULL */) +{ + int i; + + if (store == NULL) + store = X509_STORE_new(); + if (store == NULL) + return NULL; + for (i = 0; i < sk_X509_num(certs); i++) { + if (!X509_STORE_add_cert(store, sk_X509_value(certs, i))) { + X509_STORE_free(store); + return NULL; + } + } + return store; +} + +/* write OSSL_CMP_MSG DER-encoded to the specified file name item */ +static int write_PKIMESSAGE(const OSSL_CMP_MSG *msg, char **filenames) +{ + char *file; + BIO *bio; + + if (msg == NULL || filenames == NULL) { + CMP_err("NULL arg to write_PKIMESSAGE"); + return 0; + } + if (*filenames == NULL) { + CMP_err("Not enough file names provided for writing PKIMessage"); + return 0; + } + + file = *filenames; + *filenames = next_item(file); + bio = BIO_new_file(file, "wb"); + if (bio == NULL) { + CMP_err1("Cannot open file '%s' for writing", file); + return 0; + } + if (i2d_OSSL_CMP_MSG_bio(bio, msg) < 0) { + CMP_err1("Cannot write PKIMessage to file '%s'", file); + BIO_free(bio); + return 0; + } + BIO_free(bio); + return 1; +} + +/* read DER-encoded OSSL_CMP_MSG from the specified file name item */ +static OSSL_CMP_MSG *read_PKIMESSAGE(char **filenames) +{ + char *file; + BIO *bio; + OSSL_CMP_MSG *ret; + + if (filenames == NULL) { + CMP_err("NULL arg to read_PKIMESSAGE"); + return NULL; + } + if (*filenames == NULL) { + CMP_err("Not enough file names provided for reading PKIMessage"); + return NULL; + } + + file = *filenames; + *filenames = next_item(file); + bio = BIO_new_file(file, "rb"); + if (bio == NULL) { + CMP_err1("Cannot open file '%s' for reading", file); + return NULL; + } + ret = d2i_OSSL_CMP_MSG_bio(bio, NULL); + if (ret == NULL) + CMP_err1("Cannot read PKIMessage from file '%s'", file); + BIO_free(bio); + return ret; +} + +/*- + * Sends the PKIMessage req and on success place the response in *res + * basically like OSSL_CMP_MSG_http_perform(), but in addition allows + * to dump the sequence of requests and responses to files and/or + * to take the sequence of requests and responses from files. + */ +static OSSL_CMP_MSG *read_write_req_resp(OSSL_CMP_CTX *ctx, + const OSSL_CMP_MSG *req) +{ + OSSL_CMP_MSG *req_new = NULL; + OSSL_CMP_MSG *res = NULL; + OSSL_CMP_PKIHEADER *hdr; + + if (req != NULL && opt_reqout != NULL + && !write_PKIMESSAGE(req, &opt_reqout)) + goto err; + if (opt_reqin != NULL && opt_rspin == NULL) { + if ((req_new = read_PKIMESSAGE(&opt_reqin)) == NULL) + goto err; + /*- + * The transaction ID in req_new read from opt_reqin may not be fresh. + * In this case the server may complain "Transaction id already in use." + * The following workaround unfortunately requires re-protection. + */ + if (opt_reqin_new_tid + && !OSSL_CMP_MSG_update_transactionID(ctx, req_new)) + goto err; + } + + if (opt_rspin != NULL) { + res = read_PKIMESSAGE(&opt_rspin); + } else { + const OSSL_CMP_MSG *actual_req = opt_reqin != NULL ? req_new : req; + + res = opt_use_mock_srv + ? OSSL_CMP_CTX_server_perform(ctx, actual_req) + : OSSL_CMP_MSG_http_perform(ctx, actual_req); + } + if (res == NULL) + goto err; + + if (opt_reqin != NULL || opt_rspin != NULL) { + /* need to satisfy nonce and transactionID checks */ + ASN1_OCTET_STRING *nonce; + ASN1_OCTET_STRING *tid; + + hdr = OSSL_CMP_MSG_get0_header(res); + nonce = OSSL_CMP_HDR_get0_recipNonce(hdr); + tid = OSSL_CMP_HDR_get0_transactionID(hdr); + if (!OSSL_CMP_CTX_set1_senderNonce(ctx, nonce) + || !OSSL_CMP_CTX_set1_transactionID(ctx, tid)) { + OSSL_CMP_MSG_free(res); + res = NULL; + goto err; + } + } + + if (opt_rspout != NULL && !write_PKIMESSAGE(res, &opt_rspout)) { + OSSL_CMP_MSG_free(res); + res = NULL; + } + + err: + OSSL_CMP_MSG_free(req_new); + return res; +} + +/* + * parse string as integer value, not allowing trailing garbage, see also + * https://www.gnu.org/software/libc/manual/html_node/Parsing-of-Integers.html + * + * returns integer value, or INT_MIN on error + */ +static int atoint(const char *str) +{ + char *tailptr; + long res = strtol(str, &tailptr, 10); + + if ((*tailptr != '\0') || (res < INT_MIN) || (res > INT_MAX)) + return INT_MIN; + else + return (int)res; +} + +static int parse_addr(char **opt_string, int port, const char *name) +{ + char *port_string; + + if (strncasecmp(*opt_string, OSSL_HTTP_PREFIX, + strlen(OSSL_HTTP_PREFIX)) == 0) { + *opt_string += strlen(OSSL_HTTP_PREFIX); + } else if (strncasecmp(*opt_string, OSSL_HTTPS_PREFIX, + strlen(OSSL_HTTPS_PREFIX)) == 0) { + *opt_string += strlen(OSSL_HTTPS_PREFIX); + if (port == 0) + port = 443; /* == integer value of OSSL_HTTPS_PORT */ + } + + if ((port_string = strrchr(*opt_string, ':')) == NULL) + return port; /* using default */ + *(port_string++) = '\0'; + port = atoint(port_string); + if ((port <= 0) || (port > 65535)) { + CMP_err2("invalid %s port '%s' given, sane range 1-65535", + name, port_string); + return -1; + } + return port; +} + +static int set1_store_parameters(X509_STORE *ts) +{ + if (ts == NULL) + return 0; + + /* copy vpm to store */ + if (!X509_STORE_set1_param(ts, vpm /* may be NULL */)) { + BIO_printf(bio_err, "error setting verification parameters\n"); + OSSL_CMP_CTX_print_errors(cmp_ctx); + return 0; + } + + X509_STORE_set_verify_cb(ts, X509_STORE_CTX_print_verify_cb); + + return 1; +} + +static int set_name(const char *str, + int (*set_fn) (OSSL_CMP_CTX *ctx, const X509_NAME *name), + OSSL_CMP_CTX *ctx, const char *desc) +{ + if (str != NULL) { + X509_NAME *n = parse_name(str, MBSTRING_ASC, 0); + + if (n == NULL) { + CMP_err2("cannot parse %s DN '%s'", desc, str); + return 0; + } + if (!(*set_fn) (ctx, n)) { + X509_NAME_free(n); + CMP_err("out of memory"); + return 0; + } + X509_NAME_free(n); + } + return 1; +} + +static int set_gennames(OSSL_CMP_CTX *ctx, char *names, const char *desc) +{ + char *next; + + for (; names != NULL; names = next) { + GENERAL_NAME *n; + + next = next_item(names); + if (strcmp(names, "critical") == 0) { + (void)OSSL_CMP_CTX_set_option(ctx, + OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL, + 1); + continue; + } + + /* try IP address first, then URI or domain name */ + (void)ERR_set_mark(); + n = a2i_GENERAL_NAME(NULL, NULL, NULL, GEN_IPADD, names, 0); + if (n == NULL) + n = a2i_GENERAL_NAME(NULL, NULL, NULL, + strchr(names, ':') != NULL ? GEN_URI : GEN_DNS, + names, 0); + (void)ERR_pop_to_mark(); + + if (n == NULL) { + CMP_err2("bad syntax of %s '%s'", desc, names); + return 0; + } + if (!OSSL_CMP_CTX_push1_subjectAltName(ctx, n)) { + GENERAL_NAME_free(n); + CMP_err("out of memory"); + return 0; + } + GENERAL_NAME_free(n); + } + return 1; +} + +/* TODO potentially move to apps/lib/apps.c */ +/* + * create cert store structure with certificates read from given file(s) + * returns pointer to created X509_STORE on success, NULL on error + */ +static X509_STORE *load_certstore(char *input, const char *desc) +{ + X509_STORE *store = NULL; + STACK_OF(X509) *certs = NULL; + + if (input == NULL) + goto err; + + while (input != NULL) { + char *next = next_item(input); \ + + if (!load_certs_autofmt(input, &certs, 1, opt_otherpass, desc) + || !(store = sk_X509_to_store(store, certs))) { + /* CMP_err("out of memory"); */ + X509_STORE_free(store); + store = NULL; + goto err; + } + sk_X509_pop_free(certs, X509_free); + certs = NULL; + input = next; + } + err: + sk_X509_pop_free(certs, X509_free); + return store; +} + +/* TODO potentially move to apps/lib/apps.c */ +static STACK_OF(X509) *load_certs_multifile(char *files, + const char *pass, const char *desc) +{ + STACK_OF(X509) *certs = NULL; + STACK_OF(X509) *result = sk_X509_new_null(); + + if (files == NULL) + goto err; + if (result == NULL) + goto oom; + + while (files != NULL) { + char *next = next_item(files); + + if (!load_certs_autofmt(files, &certs, 0, pass, desc)) + goto err; + if (!sk_X509_add1_certs(result, certs, 0, 1 /* no dups */, 0)) + goto oom; + sk_X509_pop_free(certs, X509_free); + certs = NULL; + files = next; + } + return result; + + oom: + BIO_printf(bio_err, "out of memory\n"); + err: + sk_X509_pop_free(certs, X509_free); + sk_X509_pop_free(result, X509_free); + return NULL; +} + +typedef int (*add_X509_stack_fn_t)(void *ctx, const STACK_OF(X509) *certs); +typedef int (*add_X509_fn_t)(void *ctx, const X509 *cert); + +static int setup_certs(char *files, const char *desc, void *ctx, + add_X509_stack_fn_t addn_fn, add_X509_fn_t add1_fn) +{ + int ret = 1; + + if (files != NULL) { + STACK_OF(X509) *certs = load_certs_multifile(files, opt_otherpass, + desc); + if (certs == NULL) { + ret = 0; + } else { + if (addn_fn != NULL) { + ret = (*addn_fn)(ctx, certs); + } else { + int i; + + for (i = 0; i < sk_X509_num(certs /* may be NULL */); i++) + ret &= (*add1_fn)(ctx, sk_X509_value(certs, i)); + } + sk_X509_pop_free(certs, X509_free); + } + } + return ret; +} + + +/* + * parse and transform some options, checking their syntax. + * Returns 1 on success, 0 on error + */ +static int transform_opts(void) +{ + if (opt_cmd_s != NULL) { + if (!strcmp(opt_cmd_s, "ir")) { + opt_cmd = CMP_IR; + } else if (!strcmp(opt_cmd_s, "kur")) { + opt_cmd = CMP_KUR; + } else if (!strcmp(opt_cmd_s, "cr")) { + opt_cmd = CMP_CR; + } else if (!strcmp(opt_cmd_s, "p10cr")) { + opt_cmd = CMP_P10CR; + } else if (!strcmp(opt_cmd_s, "rr")) { + opt_cmd = CMP_RR; + } else if (!strcmp(opt_cmd_s, "genm")) { + opt_cmd = CMP_GENM; + } else { + CMP_err1("unknown cmp command '%s'", opt_cmd_s); + return 0; + } + } else { + CMP_err("no cmp command to execute"); + return 0; + } + +#ifdef OPENSSL_NO_ENGINE +# define FORMAT_OPTIONS (OPT_FMT_PEMDER | OPT_FMT_PKCS12 | OPT_FMT_ENGINE) +#else +# define FORMAT_OPTIONS (OPT_FMT_PEMDER | OPT_FMT_PKCS12) +#endif + + if (opt_keyform_s != NULL + && !opt_format(opt_keyform_s, FORMAT_OPTIONS, &opt_keyform)) { + CMP_err("unknown option given for key loading format"); + return 0; + } + +#undef FORMAT_OPTIONS + + if (opt_certform_s != NULL + && !opt_format(opt_certform_s, OPT_FMT_PEMDER, &opt_certform)) { + CMP_err("unknown option given for certificate storing format"); + return 0; + } + + if (opt_certsform_s != NULL + && !opt_format(opt_certsform_s, OPT_FMT_PEMDER | OPT_FMT_PKCS12, + &opt_certsform)) { + CMP_err("unknown option given for certificate list loading format"); + return 0; + } + + return 1; +} + +static OSSL_CMP_SRV_CTX *setup_srv_ctx(ENGINE *e) +{ + OSSL_CMP_CTX *ctx; /* extra CMP (client) ctx partly used by server */ + OSSL_CMP_SRV_CTX *srv_ctx = ossl_cmp_mock_srv_new(); + + if (srv_ctx == NULL) + return NULL; + ctx = OSSL_CMP_SRV_CTX_get0_cmp_ctx(srv_ctx); + + if (opt_srv_ref == NULL) { + if (opt_srv_cert == NULL) { + /* opt_srv_cert should determine the sender */ + CMP_err("must give -srv_ref for server if no -srv_cert given"); + goto err; + } + } else { + if (!OSSL_CMP_CTX_set1_referenceValue(ctx, (unsigned char *)opt_srv_ref, + strlen(opt_srv_ref))) + goto err; + } + + if (opt_srv_secret != NULL) { + int res; + char *pass_str = get_passwd(opt_srv_secret, "PBMAC secret of server"); + + if (pass_str != NULL) { + cleanse(opt_srv_secret); + res = OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)pass_str, + strlen(pass_str)); + clear_free(pass_str); + if (res == 0) + goto err; + } + } else if (opt_srv_cert == NULL) { + CMP_err("server credentials must be given if -use_mock_srv or -port is used"); + goto err; + } else { + CMP_warn("server will not be able to handle PBM-protected requests since -srv_secret is not given"); + } + + if (opt_srv_secret == NULL + && ((opt_srv_cert == NULL) != (opt_srv_key == NULL))) { + CMP_err("must give both -srv_cert and -srv_key options or neither"); + goto err; + } + if (opt_srv_cert != NULL) { + X509 *srv_cert = load_cert_pwd(opt_srv_cert, opt_srv_keypass, + "certificate of the server"); + + if (srv_cert == NULL || !OSSL_CMP_CTX_set1_cert(ctx, srv_cert)) { + X509_free(srv_cert); + goto err; + } + X509_free(srv_cert); + } + if (opt_srv_key != NULL) { + EVP_PKEY *pkey = load_key_pwd(opt_srv_key, opt_keyform, + opt_srv_keypass, + e, "private key for server cert"); + + if (pkey == NULL || !OSSL_CMP_CTX_set1_pkey(ctx, pkey)) { + EVP_PKEY_free(pkey); + goto err; + } + EVP_PKEY_free(pkey); + } + cleanse(opt_srv_keypass); + + if (opt_srv_trusted != NULL) { + X509_STORE *ts = + load_certstore(opt_srv_trusted, "certificates trusted by server"); + + if (ts == NULL) + goto err; + if (!set1_store_parameters(ts) + || !truststore_set_host_etc(ts, NULL) + || !OSSL_CMP_CTX_set0_trustedStore(ctx, ts)) { + X509_STORE_free(ts); + goto err; + } + } else { + CMP_warn("server will not be able to handle signature-protected requests since -srv_trusted is not given"); + } + if (!setup_certs(opt_srv_untrusted, "untrusted certificates", ctx, + (add_X509_stack_fn_t)OSSL_CMP_CTX_set1_untrusted_certs, + NULL)) + goto err; + + if (opt_rsp_cert == NULL) { + CMP_err("must give -rsp_cert for mock server"); + goto err; + } else { + X509 *cert = load_cert_pwd(opt_rsp_cert, opt_keypass, + "cert to be returned by the mock server"); + + if (cert == NULL) + goto err; + /* from server perspective the server is the client */ + if (!ossl_cmp_mock_srv_set1_certOut(srv_ctx, cert)) { + X509_free(cert); + goto err; + } + X509_free(cert); + } + /* TODO find a cleaner solution not requiring type casts */ + if (!setup_certs(opt_rsp_extracerts, + "CMP extra certificates for mock server", srv_ctx, + (add_X509_stack_fn_t)ossl_cmp_mock_srv_set1_chainOut, + NULL)) + goto err; + if (!setup_certs(opt_rsp_capubs, "caPubs for mock server", srv_ctx, + (add_X509_stack_fn_t)ossl_cmp_mock_srv_set1_caPubsOut, + NULL)) + goto err; + (void)ossl_cmp_mock_srv_set_pollCount(srv_ctx, opt_poll_count); + (void)ossl_cmp_mock_srv_set_checkAfterTime(srv_ctx, opt_check_after); + if (opt_grant_implicitconf) + (void)OSSL_CMP_SRV_CTX_set_grant_implicit_confirm(srv_ctx, 1); + + if (opt_failure != INT_MIN) { /* option has been set explicity */ + if (opt_failure < 0 || OSSL_CMP_PKIFAILUREINFO_MAX < opt_failure) { + CMP_err1("-failure out of range, should be >= 0 and <= %d", + OSSL_CMP_PKIFAILUREINFO_MAX); + goto err; + } + if (opt_failurebits != 0) + CMP_warn("-failurebits overrides -failure"); + else + opt_failurebits = 1 << opt_failure; + } + if ((unsigned)opt_failurebits > OSSL_CMP_PKIFAILUREINFO_MAX_BIT_PATTERN) { + CMP_err("-failurebits out of range"); + goto err; + } + if (!ossl_cmp_mock_srv_set_statusInfo(srv_ctx, opt_pkistatus, + opt_failurebits, opt_statusstring)) + goto err; + + if (opt_send_error) + (void)ossl_cmp_mock_srv_set_send_error(srv_ctx, 1); + + if (opt_send_unprotected) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_SEND, 1); + if (opt_send_unprot_err) + (void)OSSL_CMP_SRV_CTX_set_send_unprotected_errors(srv_ctx, 1); + if (opt_accept_unprotected) + (void)OSSL_CMP_SRV_CTX_set_accept_unprotected(srv_ctx, 1); + if (opt_accept_unprot_err) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_ERRORS, 1); + if (opt_accept_raverified) + (void)OSSL_CMP_SRV_CTX_set_accept_raverified(srv_ctx, 1); + + return srv_ctx; + + err: + ossl_cmp_mock_srv_free(srv_ctx); + return NULL; +} + +/* + * set up verification aspects of OSSL_CMP_CTX w.r.t. opts from config file/CLI. + * Returns pointer on success, NULL on error + */ +static int setup_verification_ctx(OSSL_CMP_CTX *ctx) +{ + if (!setup_certs(opt_untrusted, "untrusted certificates", ctx, + (add_X509_stack_fn_t)OSSL_CMP_CTX_set1_untrusted_certs, + NULL)) + goto err; + + if (opt_srvcert != NULL || opt_trusted != NULL) { + X509_STORE *ts = NULL; + + if (opt_srvcert != NULL) { + X509 *srvcert; + + if (opt_trusted != NULL) { + CMP_warn("-trusted option is ignored since -srvcert option is present"); + opt_trusted = NULL; + } + if (opt_recipient != NULL) { + CMP_warn("-recipient option is ignored since -srvcert option is present"); + opt_recipient = NULL; + } + srvcert = load_cert_pwd(opt_srvcert, opt_otherpass, + "directly trusted CMP server certificate"); + if (srvcert == NULL) + /* + * opt_otherpass is needed in case + * opt_srvcert is an encrypted PKCS#12 file + */ + goto err; + if (!OSSL_CMP_CTX_set1_srvCert(ctx, srvcert)) { + X509_free(srvcert); + goto oom; + } + X509_free(srvcert); + if ((ts = X509_STORE_new()) == NULL) + goto oom; + } + if (opt_trusted != NULL + && (ts = load_certstore(opt_trusted, "trusted certificates")) + == NULL) + goto err; + if (!set1_store_parameters(ts) /* also copies vpm */ + /* + * clear any expected host/ip/email address; + * opt_expect_sender is used instead + */ + || !truststore_set_host_etc(ts, NULL) + || !OSSL_CMP_CTX_set0_trustedStore(ctx, ts)) { + X509_STORE_free(ts); + goto oom; + } + } + + if (opt_ignore_keyusage) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_IGNORE_KEYUSAGE, 1); + + if (opt_unprotected_errors) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_ERRORS, 1); + + if (opt_out_trusted != NULL) { /* for use in OSSL_CMP_certConf_cb() */ + X509_VERIFY_PARAM *out_vpm = NULL; + X509_STORE *out_trusted = + load_certstore(opt_out_trusted, + "trusted certs for verifying newly enrolled cert"); + + if (out_trusted == NULL) + goto err; + /* any -verify_hostname, -verify_ip, and -verify_email apply here */ + if (!set1_store_parameters(out_trusted)) + goto oom; + /* ignore any -attime here, new certs are current anyway */ + out_vpm = X509_STORE_get0_param(out_trusted); + X509_VERIFY_PARAM_clear_flags(out_vpm, X509_V_FLAG_USE_CHECK_TIME); + + (void)OSSL_CMP_CTX_set_certConf_cb_arg(ctx, out_trusted); + } + + if (opt_disable_confirm) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_DISABLE_CONFIRM, 1); + + if (opt_implicit_confirm) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_IMPLICIT_CONFIRM, 1); + + (void)OSSL_CMP_CTX_set_certConf_cb(ctx, OSSL_CMP_certConf_cb); + + return 1; + + oom: + CMP_err("out of memory"); + err: + return 0; +} + +#ifndef OPENSSL_NO_SOCK +/* + * set up ssl_ctx for the OSSL_CMP_CTX based on options from config file/CLI. + * Returns pointer on success, NULL on error + */ +static SSL_CTX *setup_ssl_ctx(OSSL_CMP_CTX *ctx, ENGINE *e) +{ + STACK_OF(X509) *untrusted_certs = OSSL_CMP_CTX_get0_untrusted_certs(ctx); + EVP_PKEY *pkey = NULL; + X509_STORE *trust_store = NULL; + SSL_CTX *ssl_ctx; + int i; + + ssl_ctx = SSL_CTX_new(TLS_client_method()); + if (ssl_ctx == NULL) + return NULL; + + SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY); + + if (opt_tls_trusted != NULL) { + if ((trust_store = load_certstore(opt_tls_trusted, + "trusted TLS certificates")) == NULL) + goto err; + SSL_CTX_set_cert_store(ssl_ctx, trust_store); + /* for improved diagnostics on SSL_CTX_build_cert_chain() errors: */ + X509_STORE_set_verify_cb(trust_store, X509_STORE_CTX_print_verify_cb); + } + + if (opt_tls_cert != NULL && opt_tls_key != NULL) { + X509 *cert; + STACK_OF(X509) *certs = NULL; + + if (!load_certs_autofmt(opt_tls_cert, &certs, 0, opt_tls_keypass, + "TLS client certificate (optionally with chain)")) + /* + * opt_tls_keypass is needed in case opt_tls_cert is an encrypted + * PKCS#12 file + */ + goto err; + + cert = sk_X509_delete(certs, 0); + if (cert == NULL || SSL_CTX_use_certificate(ssl_ctx, cert) <= 0) { + CMP_err1("unable to use client TLS certificate file '%s'", + opt_tls_cert); + X509_free(cert); + sk_X509_pop_free(certs, X509_free); + goto err; + } + X509_free(cert); /* we do not need the handle any more */ + + /* + * Any further certs and any untrusted certs are used for constructing + * the client cert chain to be provided along with the TLS client cert + * to the TLS server. + */ + if (!SSL_CTX_set0_chain(ssl_ctx, certs)) { + CMP_err("could not set TLS client cert chain"); + sk_X509_pop_free(certs, X509_free); + goto err; + } + for (i = 0; i < sk_X509_num(untrusted_certs); i++) { + cert = sk_X509_value(untrusted_certs, i); + if (!SSL_CTX_add1_chain_cert(ssl_ctx, cert)) { + CMP_err("could not add untrusted cert to TLS client cert chain"); + goto err; + } + } + if (!SSL_CTX_build_cert_chain(ssl_ctx, + SSL_BUILD_CHAIN_FLAG_UNTRUSTED | + SSL_BUILD_CHAIN_FLAG_NO_ROOT)) { + CMP_warn("could not build cert chain for own TLS cert"); + OSSL_CMP_CTX_print_errors(ctx); + } + + /* If present we append to the list also the certs from opt_tls_extra */ + if (opt_tls_extra != NULL) { + STACK_OF(X509) *tls_extra = load_certs_multifile(opt_tls_extra, + opt_otherpass, + "extra certificates for TLS"); + int res = 1; + + if (tls_extra == NULL) + goto err; + for (i = 0; i < sk_X509_num(tls_extra); i++) { + cert = sk_X509_value(tls_extra, i); + if (res != 0) + res = SSL_CTX_add_extra_chain_cert(ssl_ctx, cert); + if (res == 0) + X509_free(cert); + } + sk_X509_free(tls_extra); + if (res == 0) { + BIO_printf(bio_err, "error: unable to add TLS extra certs\n"); + goto err; + } + } + + pkey = load_key_pwd(opt_tls_key, opt_keyform, opt_tls_keypass, + e, "TLS client private key"); + cleanse(opt_tls_keypass); + if (pkey == NULL) + goto err; + /* + * verify the key matches the cert, + * not using SSL_CTX_check_private_key(ssl_ctx) + * because it gives poor and sometimes misleading diagnostics + */ + if (!X509_check_private_key(SSL_CTX_get0_certificate(ssl_ctx), + pkey)) { + CMP_err2("TLS private key '%s' does not match the TLS certificate '%s'\n", + opt_tls_key, opt_tls_cert); + EVP_PKEY_free(pkey); + pkey = NULL; /* otherwise, for some reason double free! */ + goto err; + } + if (SSL_CTX_use_PrivateKey(ssl_ctx, pkey) <= 0) { + CMP_err1("unable to use TLS client private key '%s'", opt_tls_key); + EVP_PKEY_free(pkey); + pkey = NULL; /* otherwise, for some reason double free! */ + goto err; + } + EVP_PKEY_free(pkey); /* we do not need the handle any more */ + } + if (opt_tls_trusted != NULL) { + /* enable and parameterize server hostname/IP address check */ + if (!truststore_set_host_etc(trust_store, + opt_tls_host != NULL ? + opt_tls_host : opt_server)) + /* TODO: is the server host name correct for TLS via proxy? */ + goto err; + SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, NULL); + } + return ssl_ctx; + err: + SSL_CTX_free(ssl_ctx); + return NULL; +} +#endif + +/* + * set up protection aspects of OSSL_CMP_CTX based on options from config + * file/CLI while parsing options and checking their consistency. + * Returns 1 on success, 0 on error + */ +static int setup_protection_ctx(OSSL_CMP_CTX *ctx, ENGINE *e) +{ + if (!opt_unprotected_requests && opt_secret == NULL && opt_cert == NULL) { + CMP_err("must give client credentials unless -unprotected_requests is set"); + goto err; + } + + if (opt_ref == NULL && opt_cert == NULL && opt_subject == NULL) { + /* cert or subject should determine the sender */ + CMP_err("must give -ref if no -cert and no -subject given"); + goto err; + } + if (!opt_secret && ((opt_cert == NULL) != (opt_key == NULL))) { + CMP_err("must give both -cert and -key options or neither"); + goto err; + } + if (opt_secret != NULL) { + char *pass_string = get_passwd(opt_secret, "PBMAC"); + int res; + + if (pass_string != NULL) { + cleanse(opt_secret); + res = OSSL_CMP_CTX_set1_secretValue(ctx, + (unsigned char *)pass_string, + strlen(pass_string)); + clear_free(pass_string); + if (res == 0) + goto err; + } + if (opt_cert != NULL || opt_key != NULL) + CMP_warn("no signature-based protection used since -secret is given"); + } + if (opt_ref != NULL + && !OSSL_CMP_CTX_set1_referenceValue(ctx, (unsigned char *)opt_ref, + strlen(opt_ref))) + goto err; + + if (opt_key != NULL) { + EVP_PKEY *pkey = load_key_pwd(opt_key, opt_keyform, opt_keypass, e, + "private key for CMP client certificate"); + + if (pkey == NULL || !OSSL_CMP_CTX_set1_pkey(ctx, pkey)) { + EVP_PKEY_free(pkey); + goto err; + } + EVP_PKEY_free(pkey); + } + if (opt_secret == NULL && opt_srvcert == NULL && opt_trusted == NULL) { + CMP_err("missing -secret or -srvcert or -trusted"); + goto err; + } + + if (opt_cert != NULL) { + X509 *cert; + STACK_OF(X509) *certs = NULL; + int ok; + + if (!load_certs_autofmt(opt_cert, &certs, 0, opt_keypass, + "CMP client certificate (and optionally extra certs)")) + /* opt_keypass is needed if opt_cert is an encrypted PKCS#12 file */ + goto err; + + cert = sk_X509_delete(certs, 0); + if (cert == NULL) { + CMP_err("no client certificate found"); + sk_X509_pop_free(certs, X509_free); + goto err; + } + ok = OSSL_CMP_CTX_set1_cert(ctx, cert); + X509_free(cert); + + if (ok) { + /* add any remaining certs to the list of untrusted certs */ + STACK_OF(X509) *untrusted = OSSL_CMP_CTX_get0_untrusted_certs(ctx); + ok = untrusted != NULL ? + sk_X509_add1_certs(untrusted, certs, 0, 1 /* no dups */, 0) : + OSSL_CMP_CTX_set1_untrusted_certs(ctx, certs); + } + sk_X509_pop_free(certs, X509_free); + if (!ok) + goto oom; + } + + if (!setup_certs(opt_extracerts, "extra certificates for CMP", ctx, + (add_X509_stack_fn_t)OSSL_CMP_CTX_set1_extraCertsOut, + NULL)) + goto err; + cleanse(opt_otherpass); + + if (opt_unprotected_requests) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_UNPROTECTED_SEND, 1); + + if (opt_digest != NULL) { + int digest = OBJ_ln2nid(opt_digest); + + if (digest == NID_undef) { + CMP_err1("digest algorithm name not recognized: '%s'", opt_digest); + goto err; + } + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_DIGEST_ALGNID, digest); + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_OWF_ALGNID, digest); + } + + if (opt_mac != NULL) { + int mac = OBJ_ln2nid(opt_mac); + if (mac == NID_undef) { + CMP_err1("MAC algorithm name not recognized: '%s'", opt_mac); + goto err; + } + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_MAC_ALGNID, mac); + } + return 1; + + oom: + CMP_err("out of memory"); + err: + return 0; +} + +/* + * set up IR/CR/KUR/CertConf/RR specific parts of the OSSL_CMP_CTX + * based on options from config file/CLI. + * Returns pointer on success, NULL on error + */ +static int setup_request_ctx(OSSL_CMP_CTX *ctx, ENGINE *e) +{ + if (opt_subject == NULL && opt_oldcert == NULL && opt_cert == NULL) + CMP_warn("no -subject given, neither -oldcert nor -cert available as default"); + if (!set_name(opt_subject, OSSL_CMP_CTX_set1_subjectName, ctx, "subject") + || !set_name(opt_issuer, OSSL_CMP_CTX_set1_issuer, ctx, "issuer")) + goto err; + + if (opt_newkey != NULL) { + const char *file = opt_newkey; + const int format = opt_keyform; + const char *pass = opt_newkeypass; + const char *desc = "new private or public key for cert to be enrolled"; + EVP_PKEY *pkey = load_key_pwd(file, format, pass, e, NULL); + int priv = 1; + + if (pkey == NULL) { + ERR_clear_error(); + pkey = load_pubkey(file, format, 0, pass, e, desc); + priv = 0; + } + cleanse(opt_newkeypass); + if (pkey == NULL || !OSSL_CMP_CTX_set0_newPkey(ctx, priv, pkey)) { + EVP_PKEY_free(pkey); + goto err; + } + } + + if (opt_days > 0) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_VALIDITY_DAYS, + opt_days); + + if (opt_policies != NULL && opt_policy_oids != NULL) { + CMP_err("cannot have policies both via -policies and via -policy_oids"); + goto err; + } + + if (opt_reqexts != NULL || opt_policies != NULL) { + X509V3_CTX ext_ctx; + X509_EXTENSIONS *exts = sk_X509_EXTENSION_new_null(); + + if (exts == NULL) + goto err; + X509V3_set_ctx(&ext_ctx, NULL, NULL, NULL, NULL, 0); + X509V3_set_nconf(&ext_ctx, conf); + if (opt_reqexts != NULL + && !X509V3_EXT_add_nconf_sk(conf, &ext_ctx, opt_reqexts, &exts)) { + CMP_err1("cannot load certificate request extension section '%s'", + opt_reqexts); + sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); + goto err; + } + if (opt_policies != NULL + && !X509V3_EXT_add_nconf_sk(conf, &ext_ctx, opt_policies, &exts)) { + CMP_err1("cannot load policy cert request extension section '%s'", + opt_policies); + sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); + goto err; + } + OSSL_CMP_CTX_set0_reqExtensions(ctx, exts); + } + if (OSSL_CMP_CTX_reqExtensions_have_SAN(ctx) && opt_sans != NULL) { + CMP_err("cannot have Subject Alternative Names both via -reqexts and via -sans"); + goto err; + } + + if (!set_gennames(ctx, opt_sans, "Subject Alternative Name")) + goto err; + + if (opt_san_nodefault) { + if (opt_sans != NULL) + CMP_warn("-opt_san_nodefault has no effect when -sans is used"); + (void)OSSL_CMP_CTX_set_option(ctx, + OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT, 1); + } + + if (opt_policy_oids_critical) { + if (opt_policy_oids == NULL) + CMP_warn("-opt_policy_oids_critical has no effect unless -policy_oids is given"); + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_POLICIES_CRITICAL, 1); + } + + while (opt_policy_oids != NULL) { + ASN1_OBJECT *policy; + POLICYINFO *pinfo; + char *next = next_item(opt_policy_oids); + + if ((policy = OBJ_txt2obj(opt_policy_oids, 1)) == 0) { + CMP_err1("unknown policy OID '%s'", opt_policy_oids); + goto err; + } + + if ((pinfo = POLICYINFO_new()) == NULL) { + ASN1_OBJECT_free(policy); + goto err; + } + pinfo->policyid = policy; + + if (!OSSL_CMP_CTX_push0_policy(ctx, pinfo)) { + CMP_err1("cannot add policy with OID '%s'", opt_policy_oids); + POLICYINFO_free(pinfo); + goto err; + } + opt_policy_oids = next; + } + + if (opt_popo >= OSSL_CRMF_POPO_NONE) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_POPO_METHOD, opt_popo); + + if (opt_csr != NULL) { + if (opt_cmd != CMP_P10CR) { + CMP_warn("-csr option is ignored for command other than p10cr"); + } else { + X509_REQ *csr = + load_csr_autofmt(opt_csr, "PKCS#10 CSR for p10cr"); + + if (csr == NULL) + goto err; + if (!OSSL_CMP_CTX_set1_p10CSR(ctx, csr)) { + X509_REQ_free(csr); + goto oom; + } + X509_REQ_free(csr); + } + } + + if (opt_oldcert != NULL) { + X509 *oldcert = load_cert_pwd(opt_oldcert, opt_keypass, + "certificate to be updated/revoked"); + /* opt_keypass is needed if opt_oldcert is an encrypted PKCS#12 file */ + + if (oldcert == NULL) + goto err; + if (!OSSL_CMP_CTX_set1_oldCert(ctx, oldcert)) { + X509_free(oldcert); + goto oom; + } + X509_free(oldcert); + } + cleanse(opt_keypass); + if (opt_revreason > CRL_REASON_NONE) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_REVOCATION_REASON, + opt_revreason); + + return 1; + + oom: + CMP_err("out of memory"); + err: + return 0; +} + +static int handle_opt_geninfo(OSSL_CMP_CTX *ctx) +{ + long value; + ASN1_OBJECT *type; + ASN1_INTEGER *aint; + ASN1_TYPE *val; + OSSL_CMP_ITAV *itav; + char *endstr; + char *valptr = strchr(opt_geninfo, ':'); + + if (valptr == NULL) { + CMP_err("missing ':' in -geninfo option"); + return 0; + } + valptr[0] = '\0'; + valptr++; + + if (strncasecmp(valptr, "int:", 4) != 0) { + CMP_err("missing 'int:' in -geninfo option"); + return 0; + } + valptr += 4; + + value = strtol(valptr, &endstr, 10); + if (endstr == valptr || *endstr != '\0') { + CMP_err("cannot parse int in -geninfo option"); + return 0; + } + + type = OBJ_txt2obj(opt_geninfo, 1); + if (type == NULL) { + CMP_err("cannot parse OID in -geninfo option"); + return 0; + } + + aint = ASN1_INTEGER_new(); + if (aint == NULL || !ASN1_INTEGER_set(aint, value)) + goto oom; + + val = ASN1_TYPE_new(); + if (val == NULL) { + ASN1_INTEGER_free(aint); + goto oom; + } + ASN1_TYPE_set(val, V_ASN1_INTEGER, aint); + itav = OSSL_CMP_ITAV_create(type, val); + if (itav == NULL) { + ASN1_TYPE_free(val); + goto oom; + } + + if (!OSSL_CMP_CTX_push0_geninfo_ITAV(ctx, itav)) { + OSSL_CMP_ITAV_free(itav); + return 0; + } + return 1; + + oom: + CMP_err("out of memory"); + return 0; +} + + +/* + * set up the client-side OSSL_CMP_CTX based on options from config file/CLI + * while parsing options and checking their consistency. + * Prints reason for error to bio_err. + * Returns 1 on success, 0 on error + */ +static int setup_client_ctx(OSSL_CMP_CTX *ctx, ENGINE *e) +{ + int ret = 0; + char server_buf[200] = { '\0' }; + char proxy_buf[200] = { '\0' }; + char *proxy_host = NULL; + char *proxy_port_str = NULL; + + if (opt_server == NULL) { + CMP_err("missing server address[:port]"); + goto err; + } else if ((server_port = + parse_addr(&opt_server, server_port, "server")) < 0) { + goto err; + } + if (server_port != 0) + BIO_snprintf(server_port_s, sizeof(server_port_s), "%d", server_port); + if (!OSSL_CMP_CTX_set1_server(ctx, opt_server) + || !OSSL_CMP_CTX_set_serverPort(ctx, server_port) + || !OSSL_CMP_CTX_set1_serverPath(ctx, opt_path)) + goto oom; + if (opt_proxy != NULL && !OSSL_CMP_CTX_set1_proxy(ctx, opt_proxy)) + goto oom; + (void)BIO_snprintf(server_buf, sizeof(server_buf), "http%s://%s%s%s/%s", + opt_tls_used ? "s" : "", opt_server, + server_port == 0 ? "" : ":", server_port_s, + opt_path[0] == '/' ? opt_path + 1 : opt_path); + + if (opt_proxy != NULL) + (void)BIO_snprintf(proxy_buf, sizeof(proxy_buf), " via %s", opt_proxy); + CMP_info2("will contact %s%s", server_buf, proxy_buf); + + if (!transform_opts()) + goto err; + + if (opt_cmd == CMP_IR || opt_cmd == CMP_CR || opt_cmd == CMP_KUR) { + if (opt_newkey == NULL && opt_key == NULL && opt_csr == NULL) { + CMP_err("missing -newkey (or -key) to be certified"); + goto err; + } + if (opt_certout == NULL) { + CMP_err("-certout not given, nowhere to save certificate"); + goto err; + } + } + if (opt_cmd == CMP_KUR) { + char *ref_cert = opt_oldcert != NULL ? opt_oldcert : opt_cert; + + if (ref_cert == NULL) { + CMP_err("missing -oldcert option for certificate to be updated"); + goto err; + } + if (opt_subject != NULL) + CMP_warn2("-subject '%s' given, which overrides the subject of '%s' in KUR", + opt_subject, ref_cert); + } + if (opt_cmd == CMP_RR && opt_oldcert == NULL) { + CMP_err("missing certificate to be revoked"); + goto err; + } + if (opt_cmd == CMP_P10CR && opt_csr == NULL) { + CMP_err("missing PKCS#10 CSR for p10cr"); + goto err; + } + + if (opt_recipient == NULL && opt_srvcert == NULL && opt_issuer == NULL + && opt_oldcert == NULL && opt_cert == NULL) + CMP_warn("missing -recipient, -srvcert, -issuer, -oldcert or -cert; recipient will be set to \"NULL-DN\""); + + if (opt_infotype_s != NULL) { + char id_buf[100] = "id-it-"; + + strncat(id_buf, opt_infotype_s, sizeof(id_buf) - strlen(id_buf) - 1); + if ((opt_infotype = OBJ_sn2nid(id_buf)) == NID_undef) { + CMP_err("unknown OID name in -infotype option"); + goto err; + } + } + + if (!setup_verification_ctx(ctx)) + goto err; + + if (opt_msg_timeout >= 0) /* must do this before setup_ssl_ctx() */ + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_MSG_TIMEOUT, + opt_msg_timeout); + if (opt_total_timeout >= 0) + (void)OSSL_CMP_CTX_set_option(ctx, OSSL_CMP_OPT_TOTAL_TIMEOUT, + opt_total_timeout); + + if (opt_reqin != NULL && opt_rspin != NULL) + CMP_warn("-reqin is ignored since -rspin is present"); + if (opt_reqin_new_tid && opt_reqin == NULL) + CMP_warn("-reqin_new_tid is ignored since -reqin is not present"); + if (opt_reqin != NULL || opt_reqout != NULL + || opt_rspin != NULL || opt_rspout != NULL || opt_use_mock_srv) + (void)OSSL_CMP_CTX_set_transfer_cb(ctx, read_write_req_resp); + + if ((opt_tls_cert != NULL || opt_tls_key != NULL + || opt_tls_keypass != NULL || opt_tls_extra != NULL + || opt_tls_trusted != NULL || opt_tls_host != NULL) + && !opt_tls_used) + CMP_warn("TLS options(s) given but not -tls_used"); + if (opt_tls_used) { +#ifdef OPENSSL_NO_SOCK + BIO_printf(bio_err, "Cannot use TLS - sockets not supported\n"); + goto err; +#else + APP_HTTP_TLS_INFO *info; + + if (opt_tls_cert != NULL + || opt_tls_key != NULL || opt_tls_keypass != NULL) { + if (opt_tls_key == NULL) { + CMP_err("missing -tls_key option"); + goto err; + } else if (opt_tls_cert == NULL) { + CMP_err("missing -tls_cert option"); + goto err; + } + } + if (opt_use_mock_srv) { + CMP_err("cannot use TLS options together with -use_mock_srv"); + goto err; + } + if ((info = OPENSSL_zalloc(sizeof(*info))) == NULL) + goto err; + (void)OSSL_CMP_CTX_set_http_cb_arg(ctx, info); + /* info will be freed along with CMP ctx */ + info->server = opt_server; + info->port = server_port_s; + info->use_proxy = opt_proxy != NULL; + info->timeout = OSSL_CMP_CTX_get_option(ctx, OSSL_CMP_OPT_MSG_TIMEOUT); + info->ssl_ctx = setup_ssl_ctx(ctx, e); + if (info->ssl_ctx == NULL) + goto err; + (void)OSSL_CMP_CTX_set_http_cb(ctx, app_http_tls_cb); +#endif + } + + if (!setup_protection_ctx(ctx, e)) + goto err; + + if (!setup_request_ctx(ctx, e)) + goto err; + + if (!set_name(opt_recipient, OSSL_CMP_CTX_set1_recipient, ctx, "recipient") + || !set_name(opt_expect_sender, OSSL_CMP_CTX_set1_expected_sender, + ctx, "expected sender")) + goto oom; + + if (opt_geninfo != NULL && !handle_opt_geninfo(ctx)) + goto err; + + ret = 1; + + err: + OPENSSL_free(proxy_host); + OPENSSL_free(proxy_port_str); + return ret; + oom: + CMP_err("out of memory"); + goto err; +} + +/* + * write out the given certificate to the output specified by bio. + * Depending on options use either PEM or DER format. + * Returns 1 on success, 0 on error + */ +static int write_cert(BIO *bio, X509 *cert) +{ + if ((opt_certform == FORMAT_PEM && PEM_write_bio_X509(bio, cert)) + || (opt_certform == FORMAT_ASN1 && i2d_X509_bio(bio, cert))) + return 1; + if (opt_certform != FORMAT_PEM && opt_certform != FORMAT_ASN1) + BIO_printf(bio_err, + "error: unsupported type '%s' for writing certificates\n", + opt_certform_s); + return 0; +} + +/* + * writes out a stack of certs to the given file. + * Depending on options use either PEM or DER format, + * where DER does not make much sense for writing more than one cert! + * Returns number of written certificates on success, 0 on error. + */ +static int save_certs(OSSL_CMP_CTX *ctx, + STACK_OF(X509) *certs, char *destFile, char *desc) +{ + BIO *bio = NULL; + int i; + int n = sk_X509_num(certs); + + CMP_info3("received %d %s certificate(s), saving to file '%s'", + n, desc, destFile); + if (n > 1 && opt_certform != FORMAT_PEM) + CMP_warn("saving more than one certificate in non-PEM format"); + + if (destFile == NULL || (bio = BIO_new(BIO_s_file())) == NULL + || !BIO_write_filename(bio, (char *)destFile)) { + CMP_err1("could not open file '%s' for writing", destFile); + n = -1; + goto err; + } + + for (i = 0; i < n; i++) { + if (!write_cert(bio, sk_X509_value(certs, i))) { + CMP_err1("cannot write certificate to file '%s'", destFile); + n = -1; + goto err; + } + } + + err: + BIO_free(bio); + return n; +} + +static void print_itavs(STACK_OF(OSSL_CMP_ITAV) *itavs) +{ + OSSL_CMP_ITAV *itav = NULL; + char buf[128]; + int i; + int n = sk_OSSL_CMP_ITAV_num(itavs); /* itavs == NULL leads to 0 */ + + if (n == 0) { + CMP_info("genp contains no ITAV"); + return; + } + + for (i = 0; i < n; i++) { + itav = sk_OSSL_CMP_ITAV_value(itavs, i); + OBJ_obj2txt(buf, 128, OSSL_CMP_ITAV_get0_type(itav), 0); + CMP_info1("genp contains ITAV of type: %s", buf); + } +} + +static char opt_item[SECTION_NAME_MAX + 1]; +/* get previous name from a comma-separated list of names */ +static const char *prev_item(const char *opt, const char *end) +{ + const char *beg; + size_t len; + + if (end == opt) + return NULL; + beg = end; + while (beg != opt && beg[-1] != ',' && !isspace(beg[-1])) + beg--; + len = end - beg; + if (len > SECTION_NAME_MAX) + len = SECTION_NAME_MAX; + strncpy(opt_item, beg, len); + opt_item[SECTION_NAME_MAX] = '\0'; /* avoid gcc v8 O3 stringop-truncation */ + opt_item[len] = '\0'; + if (len > SECTION_NAME_MAX) + CMP_warn2("using only first %d characters of section name starting with \"%s\"", + SECTION_NAME_MAX, opt_item); + while (beg != opt && (beg[-1] == ',' || isspace(beg[-1]))) + beg--; + return beg; +} + +/* get str value for name from a comma-separated hierarchy of config sections */ +static char *conf_get_string(const CONF *src_conf, const char *groups, + const char *name) +{ + char *res = NULL; + const char *end = groups + strlen(groups); + + while ((end = prev_item(groups, end)) != NULL) { + if ((res = NCONF_get_string(src_conf, opt_item, name)) != NULL) + return res; + } + return res; +} + +/* get long val for name from a comma-separated hierarchy of config sections */ +static int conf_get_number_e(const CONF *conf_, const char *groups, + const char *name, long *result) +{ + char *str = conf_get_string(conf_, groups, name); + char *tailptr; + long res; + + if (str == NULL || *str == '\0') + return 0; + + res = strtol(str, &tailptr, 10); + if (res == LONG_MIN || res == LONG_MAX || *tailptr != '\0') + return 0; + + *result = res; + return 1; +} + +/* + * use the command line option table to read values from the CMP section + * of openssl.cnf. Defaults are taken from the config file, they can be + * overwritten on the command line. + */ +static int read_config(void) +{ + unsigned int i; + long num = 0; + char *txt = NULL; + const OPTIONS *opt; + int provider_option; + int verification_option; + + /* + * starting with offset OPT_SECTION because OPT_CONFIG and OPT_SECTION would + * not make sense within the config file. They have already been handled. + */ + for (i = OPT_SECTION - OPT_HELP, opt = &cmp_options[OPT_SECTION]; + opt->name; i++, opt++) { + if (!strcmp(opt->name, OPT_SECTION_STR) + || !strcmp(opt->name, OPT_MORE_STR)) { + i--; + continue; + } + provider_option = (OPT_PROV__FIRST <= opt->retval + && opt->retval < OPT_PROV__LAST); + verification_option = (OPT_V__FIRST <= opt->retval + && opt->retval < OPT_V__LAST); + if (provider_option || verification_option) + i--; + if (cmp_vars[i].txt == NULL) { + CMP_err1("internal: cmp_vars array too short, i=%d", i); + return 0; + } + switch (opt->valtype) { + case '-': + case 'n': + case 'l': + if (!conf_get_number_e(conf, opt_section, opt->name, &num)) { + ERR_clear_error(); + continue; /* option not provided */ + } + break; + /* + * do not use '<' in cmp_options. Incorrect treatment + * somewhere in args_verify() can wrongly set badarg = 1 + */ + case '<': + case 's': + case 'M': + txt = conf_get_string(conf, opt_section, opt->name); + if (txt == NULL) { + ERR_clear_error(); + continue; /* option not provided */ + } + break; + default: + CMP_err2("internal: unsupported type '%c' for option '%s'", + opt->valtype, opt->name); + return 0; + break; + } + if (provider_option || verification_option) { + int conf_argc = 1; + char *conf_argv[3]; + char arg1[82]; + + BIO_snprintf(arg1, 81, "-%s", (char *)opt->name); + conf_argv[0] = prog; + conf_argv[1] = arg1; + if (opt->valtype == '-') { + if (num != 0) + conf_argc = 2; + } else { + conf_argc = 3; + conf_argv[2] = conf_get_string(conf, opt_section, opt->name); + /* not NULL */ + } + if (conf_argc > 1) { + (void)opt_init(conf_argc, conf_argv, cmp_options); + + if (provider_option + ? !opt_provider(opt_next()) + : !opt_verify(opt_next(), vpm)) { + CMP_err2("for option '%s' in config file section '%s'", + opt->name, opt_section); + return 0; + } + } + } else { + switch (opt->valtype) { + case '-': + case 'n': + if (num < INT_MIN || INT_MAX < num) { + BIO_printf(bio_err, + "integer value out of range for option '%s'\n", + opt->name); + return 0; + } + *cmp_vars[i].num = (int)num; + break; + case 'l': + *cmp_vars[i].num_long = num; + break; + default: + if (txt != NULL && txt[0] == '\0') + txt = NULL; /* reset option on empty string input */ + *cmp_vars[i].txt = txt; + break; + } + } + } + + return 1; +} + +static char *opt_str(char *opt) +{ + char *arg = opt_arg(); + + if (arg[0] == '\0') { + CMP_warn1("argument of -%s option is empty string, resetting option", + opt); + arg = NULL; + } else if (arg[0] == '-') { + CMP_warn1("argument of -%s option starts with hyphen", opt); + } + return arg; +} + +static int opt_nat(void) +{ + int result = -1; + + if (opt_int(opt_arg(), &result) && result < 0) + BIO_printf(bio_err, "error: argument '%s' must not be negative\n", + opt_arg()); + return result; +} + +/* returns 1 on success, 0 on error, -1 on -help (i.e., stop with success) */ +static int get_opts(int argc, char **argv) +{ + OPTION_CHOICE o; + + prog = opt_init(argc, argv, cmp_options); + + while ((o = opt_next()) != OPT_EOF) { + switch (o) { + case OPT_EOF: + case OPT_ERR: + goto opt_err; + case OPT_HELP: + opt_help(cmp_options); + return -1; + case OPT_CONFIG: /* has already been handled */ + break; + case OPT_SECTION: /* has already been handled */ + break; + case OPT_SERVER: + opt_server = opt_str("server"); + break; + case OPT_PROXY: + opt_proxy = opt_str("proxy"); + break; + case OPT_NO_PROXY: + opt_no_proxy = opt_str("no_proxy"); + break; + case OPT_PATH: + opt_path = opt_str("path"); + break; + case OPT_MSG_TIMEOUT: + if ((opt_msg_timeout = opt_nat()) < 0) + goto opt_err; + break; + case OPT_TOTAL_TIMEOUT: + if ((opt_total_timeout = opt_nat()) < 0) + goto opt_err; + break; + case OPT_TLS_USED: + opt_tls_used = 1; + break; + case OPT_TLS_CERT: + opt_tls_cert = opt_str("tls_cert"); + break; + case OPT_TLS_KEY: + opt_tls_key = opt_str("tls_key"); + break; + case OPT_TLS_KEYPASS: + opt_tls_keypass = opt_str("tls_keypass"); + break; + case OPT_TLS_EXTRA: + opt_tls_extra = opt_str("tls_extra"); + break; + case OPT_TLS_TRUSTED: + opt_tls_trusted = opt_str("tls_trusted"); + break; + case OPT_TLS_HOST: + opt_tls_host = opt_str("tls_host"); + break; + case OPT_REF: + opt_ref = opt_str("ref"); + break; + case OPT_SECRET: + opt_secret = opt_str("secret"); + break; + case OPT_CERT: + opt_cert = opt_str("cert"); + break; + case OPT_KEY: + opt_key = opt_str("key"); + break; + case OPT_KEYPASS: + opt_keypass = opt_str("keypass"); + break; + case OPT_DIGEST: + opt_digest = opt_str("digest"); + break; + case OPT_MAC: + opt_mac = opt_str("mac"); + break; + case OPT_EXTRACERTS: + opt_extracerts = opt_str("extracerts"); + break; + case OPT_UNPROTECTED_REQUESTS: + opt_unprotected_requests = 1; + break; + + case OPT_TRUSTED: + opt_trusted = opt_str("trusted"); + break; + case OPT_UNTRUSTED: + opt_untrusted = opt_str("untrusted"); + break; + case OPT_SRVCERT: + opt_srvcert = opt_str("srvcert"); + break; + case OPT_RECIPIENT: + opt_recipient = opt_str("recipient"); + break; + case OPT_EXPECT_SENDER: + opt_expect_sender = opt_str("expect_sender"); + break; + case OPT_IGNORE_KEYUSAGE: + opt_ignore_keyusage = 1; + break; + case OPT_UNPROTECTED_ERRORS: + opt_unprotected_errors = 1; + break; + case OPT_EXTRACERTSOUT: + opt_extracertsout = opt_str("extracertsout"); + break; + case OPT_CACERTSOUT: + opt_cacertsout = opt_str("cacertsout"); + break; + + case OPT_V_CASES: + if (!opt_verify(o, vpm)) + goto opt_err; + break; + case OPT_CMD: + opt_cmd_s = opt_str("cmd"); + break; + case OPT_INFOTYPE: + opt_infotype_s = opt_str("infotype"); + break; + case OPT_GENINFO: + opt_geninfo = opt_str("geninfo"); + break; + + case OPT_NEWKEY: + opt_newkey = opt_str("newkey"); + break; + case OPT_NEWKEYPASS: + opt_newkeypass = opt_str("newkeypass"); + break; + case OPT_SUBJECT: + opt_subject = opt_str("subject"); + break; + case OPT_ISSUER: + opt_issuer = opt_str("issuer"); + break; + case OPT_DAYS: + if ((opt_days = opt_nat()) < 0) + goto opt_err; + break; + case OPT_REQEXTS: + opt_reqexts = opt_str("reqexts"); + break; + case OPT_SANS: + opt_sans = opt_str("sans"); + break; + case OPT_SAN_NODEFAULT: + opt_san_nodefault = 1; + break; + case OPT_POLICIES: + opt_policies = opt_str("policies"); + break; + case OPT_POLICY_OIDS: + opt_policy_oids = opt_str("policy_oids"); + break; + case OPT_POLICY_OIDS_CRITICAL: + opt_policy_oids_critical = 1; + break; + case OPT_POPO: + if (!opt_int(opt_arg(), &opt_popo) + || opt_popo < OSSL_CRMF_POPO_NONE + || opt_popo > OSSL_CRMF_POPO_KEYENC) { + CMP_err("invalid popo spec. Valid values are -1 .. 2"); + goto opt_err; + } + break; + case OPT_CSR: + opt_csr = opt_arg(); + break; + case OPT_OUT_TRUSTED: + opt_out_trusted = opt_str("out_trusted"); + break; + case OPT_IMPLICIT_CONFIRM: + opt_implicit_confirm = 1; + break; + case OPT_DISABLE_CONFIRM: + opt_disable_confirm = 1; + break; + case OPT_CERTOUT: + opt_certout = opt_str("certout"); + break; + case OPT_OLDCERT: + opt_oldcert = opt_str("oldcert"); + break; + case OPT_REVREASON: + if (!opt_int(opt_arg(), &opt_revreason) + || opt_revreason < CRL_REASON_NONE + || opt_revreason > CRL_REASON_AA_COMPROMISE + || opt_revreason == 7) { + CMP_err("invalid revreason. Valid values are -1 .. 6, 8 .. 10"); + goto opt_err; + } + break; + case OPT_CERTFORM: + opt_certform_s = opt_str("certform"); + break; + case OPT_KEYFORM: + opt_keyform_s = opt_str("keyform"); + break; + case OPT_CERTSFORM: + opt_certsform_s = opt_str("certsform"); + break; + case OPT_OTHERPASS: + opt_otherpass = opt_str("otherpass"); + break; +#ifndef OPENSSL_NO_ENGINE + case OPT_ENGINE: + opt_engine = opt_str("engine"); + break; +#endif + case OPT_PROV_CASES: + if (!opt_provider(o)) + goto opt_err; + break; + + case OPT_BATCH: + opt_batch = 1; + break; + case OPT_REPEAT: + opt_repeat = opt_nat(); + break; + case OPT_REQIN: + opt_reqin = opt_str("reqin"); + break; + case OPT_REQIN_NEW_TID: + opt_reqin_new_tid = 1; + break; + case OPT_REQOUT: + opt_reqout = opt_str("reqout"); + break; + case OPT_RSPIN: + opt_rspin = opt_str("rspin"); + break; + case OPT_RSPOUT: + opt_rspout = opt_str("rspout"); + break; + case OPT_USE_MOCK_SRV: + opt_use_mock_srv = 1; + break; + case OPT_PORT: + opt_port = opt_str("port"); + break; + case OPT_MAX_MSGS: + if ((opt_max_msgs = opt_nat()) < 0) + goto opt_err; + break; + case OPT_SRV_REF: + opt_srv_ref = opt_str("srv_ref"); + break; + case OPT_SRV_SECRET: + opt_srv_secret = opt_str("srv_secret"); + break; + case OPT_SRV_CERT: + opt_srv_cert = opt_str("srv_cert"); + break; + case OPT_SRV_KEY: + opt_srv_key = opt_str("srv_key"); + break; + case OPT_SRV_KEYPASS: + opt_srv_keypass = opt_str("srv_keypass"); + break; + case OPT_SRV_TRUSTED: + opt_srv_trusted = opt_str("srv_trusted"); + break; + case OPT_SRV_UNTRUSTED: + opt_srv_untrusted = opt_str("srv_untrusted"); + break; + case OPT_RSP_CERT: + opt_rsp_cert = opt_str("rsp_cert"); + break; + case OPT_RSP_EXTRACERTS: + opt_rsp_extracerts = opt_str("rsp_extracerts"); + break; + case OPT_RSP_CAPUBS: + opt_rsp_capubs = opt_str("rsp_capubs"); + break; + case OPT_POLL_COUNT: + opt_poll_count = opt_nat(); + break; + case OPT_CHECK_AFTER: + opt_check_after = opt_nat(); + break; + case OPT_GRANT_IMPLICITCONF: + opt_grant_implicitconf = 1; + break; + case OPT_PKISTATUS: + opt_pkistatus = opt_nat(); + break; + case OPT_FAILURE: + opt_failure = opt_nat(); + break; + case OPT_FAILUREBITS: + opt_failurebits = opt_nat(); + break; + case OPT_STATUSSTRING: + opt_statusstring = opt_str("statusstring"); + break; + case OPT_SEND_ERROR: + opt_send_error = 1; + break; + case OPT_SEND_UNPROTECTED: + opt_send_unprotected = 1; + break; + case OPT_SEND_UNPROT_ERR: + opt_send_unprot_err = 1; + break; + case OPT_ACCEPT_UNPROTECTED: + opt_accept_unprotected = 1; + break; + case OPT_ACCEPT_UNPROT_ERR: + opt_accept_unprot_err = 1; + break; + case OPT_ACCEPT_RAVERIFIED: + opt_accept_raverified = 1; + break; + } + } + argc = opt_num_rest(); + argv = opt_rest(); + if (argc != 0) { + CMP_err1("unknown parameter %s", argv[0]); + goto opt_err; + } + return 1; + + opt_err: + CMP_err1("use -help for summary of '%s' options", prog); + return 0; +} + +int cmp_main(int argc, char **argv) +{ + char *configfile = NULL; + int i; + X509 *newcert = NULL; + ENGINE *e = NULL; + char mock_server[] = "mock server:1"; + int ret = 0; /* default: failure */ + + if (argc <= 1) { + opt_help(cmp_options); + goto err; + } + + /* + * handle OPT_CONFIG and OPT_SECTION upfront to take effect for other opts + */ + for (i = 1; i < argc - 1; i++) { + if (*argv[i] == '-') { + if (!strcmp(argv[i] + 1, cmp_options[OPT_CONFIG - OPT_HELP].name)) + opt_config = argv[i + 1]; + else if (!strcmp(argv[i] + 1, + cmp_options[OPT_SECTION - OPT_HELP].name)) + opt_section = argv[i + 1]; + } + } + if (opt_section[0] == '\0') /* empty string */ + opt_section = DEFAULT_SECTION; + + vpm = X509_VERIFY_PARAM_new(); + if (vpm == NULL) { + CMP_err("out of memory"); + goto err; + } + + /* read default values for options from config file */ + configfile = opt_config != NULL ? opt_config : default_config_file; + if (configfile && configfile[0] != '\0' /* non-empty string */ + && (configfile != default_config_file + || access(configfile, F_OK) != -1)) { + CMP_info1("using OpenSSL configuration file '%s'", configfile); + conf = app_load_config(configfile); + if (conf == NULL) { + goto err; + } else { + if (strcmp(opt_section, CMP_SECTION) == 0) { /* default */ + if (!NCONF_get_section(conf, opt_section)) + CMP_info2("no [%s] section found in config file '%s';" + " will thus use just [default] and unnamed section if present", + opt_section, configfile); + } else { + const char *end = opt_section + strlen(opt_section); + while ((end = prev_item(opt_section, end)) != NULL) { + if (!NCONF_get_section(conf, opt_item)) { + CMP_err2("no [%s] section found in config file '%s'", + opt_item, configfile); + goto err; + } + } + } + if (!read_config()) + goto err; + } + } + (void)BIO_flush(bio_err); /* prevent interference with opt_help() */ + + ret = get_opts(argc, argv); + if (ret <= 0) + goto err; + ret = 0; + + if (opt_batch) { +#ifndef OPENSSL_NO_ENGINE + UI_METHOD *ui_fallback_method; +# ifndef OPENSSL_NO_UI_CONSOLE + ui_fallback_method = UI_OpenSSL(); +# else + ui_fallback_method = (UI_METHOD *)UI_null(); +# endif + UI_method_set_reader(ui_fallback_method, NULL); +#endif + } + + if (opt_engine != NULL) + e = setup_engine_methods(opt_engine, 0 /* not: ENGINE_METHOD_ALL */, 0); + + if (opt_port != NULL) { + if (opt_use_mock_srv) { + CMP_err("cannot use both -port and -use_mock_srv options"); + goto err; + } + if (opt_server != NULL) { + CMP_err("cannot use both -port and -server options"); + goto err; + } + } + + if ((cmp_ctx = OSSL_CMP_CTX_new()) == NULL) { + CMP_err("out of memory"); + goto err; + } + if (!OSSL_CMP_CTX_set_log_cb(cmp_ctx, print_to_bio_out)) { + CMP_err1("cannot set up error reporting and logging for %s", prog); + goto err; + } + if ((opt_use_mock_srv || opt_port != NULL)) { + OSSL_CMP_SRV_CTX *srv_ctx; + + if ((srv_ctx = setup_srv_ctx(e)) == NULL) + goto err; + OSSL_CMP_CTX_set_transfer_cb_arg(cmp_ctx, srv_ctx); + if (!OSSL_CMP_CTX_set_log_cb(OSSL_CMP_SRV_CTX_get0_cmp_ctx(srv_ctx), + print_to_bio_out)) { + CMP_err1("cannot set up error reporting and logging for %s", prog); + goto err; + } + } + + + if (opt_port != NULL) { /* act as very basic CMP HTTP server */ +#ifdef OPENSSL_NO_SOCK + BIO_printf(bio_err, "Cannot act as server - sockets not supported\n"); +#else + BIO *acbio; + BIO *cbio = NULL; + int msgs = 0; + + if ((acbio = http_server_init_bio(prog, opt_port)) == NULL) + goto err; + while (opt_max_msgs <= 0 || msgs < opt_max_msgs) { + OSSL_CMP_MSG *req = NULL; + OSSL_CMP_MSG *resp = NULL; + + ret = http_server_get_asn1_req(ASN1_ITEM_rptr(OSSL_CMP_MSG), + (ASN1_VALUE **)&req, &cbio, acbio, + prog, 0, 0); + if (ret == 0) + continue; + if (ret++ == -1) + break; /* fatal error */ + + ret = 0; + msgs++; + if (req != NULL) { + resp = OSSL_CMP_CTX_server_perform(cmp_ctx, req); + OSSL_CMP_MSG_free(req); + if (resp == NULL) + break; /* treated as fatal error */ + ret = http_server_send_asn1_resp(cbio, "application/pkixcmp", + ASN1_ITEM_rptr(OSSL_CMP_MSG), + (const ASN1_VALUE *)resp); + OSSL_CMP_MSG_free(resp); + if (!ret) + break; /* treated as fatal error */ + } + BIO_free_all(cbio); + cbio = NULL; + } + BIO_free_all(cbio); + BIO_free_all(acbio); +#endif + goto err; + } + /* else act as CMP client */ + + if (opt_use_mock_srv) { + if (opt_server != NULL) { + CMP_err("cannot use both -use_mock_srv and -server options"); + goto err; + } + if (opt_proxy != NULL) { + CMP_err("cannot use both -use_mock_srv and -proxy options"); + goto err; + } + opt_server = mock_server; + opt_proxy = "API"; + } else { + if (opt_server == NULL) { + CMP_err("missing -server option"); + goto err; + } + } + + if (!setup_client_ctx(cmp_ctx, e)) { + CMP_err("cannot set up CMP context"); + goto err; + } + for (i = 0; i < opt_repeat; i++) { + /* everything is ready, now connect and perform the command! */ + switch (opt_cmd) { + case CMP_IR: + newcert = OSSL_CMP_exec_IR_ses(cmp_ctx); + if (newcert == NULL) + goto err; + break; + case CMP_KUR: + newcert = OSSL_CMP_exec_KUR_ses(cmp_ctx); + if (newcert == NULL) + goto err; + break; + case CMP_CR: + newcert = OSSL_CMP_exec_CR_ses(cmp_ctx); + if (newcert == NULL) + goto err; + break; + case CMP_P10CR: + newcert = OSSL_CMP_exec_P10CR_ses(cmp_ctx); + if (newcert == NULL) + goto err; + break; + case CMP_RR: + if (OSSL_CMP_exec_RR_ses(cmp_ctx) == NULL) + goto err; + break; + case CMP_GENM: + { + STACK_OF(OSSL_CMP_ITAV) *itavs; + + if (opt_infotype != NID_undef) { + OSSL_CMP_ITAV *itav = + OSSL_CMP_ITAV_create(OBJ_nid2obj(opt_infotype), NULL); + if (itav == NULL) + goto err; + OSSL_CMP_CTX_push0_genm_ITAV(cmp_ctx, itav); + } + + if ((itavs = OSSL_CMP_exec_GENM_ses(cmp_ctx)) == NULL) + goto err; + print_itavs(itavs); + sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free); + break; + } + default: + break; + } + + { + /* print PKIStatusInfo (this is in case there has been no error) */ + int status = OSSL_CMP_CTX_get_status(cmp_ctx); + char *buf = app_malloc(OSSL_CMP_PKISI_BUFLEN, "PKIStatusInfo buf"); + const char *string = + OSSL_CMP_CTX_snprint_PKIStatus(cmp_ctx, buf, + OSSL_CMP_PKISI_BUFLEN); + + CMP_print(bio_err, + status == OSSL_CMP_PKISTATUS_accepted ? "info" : + status == OSSL_CMP_PKISTATUS_rejection ? "server error" : + status == OSSL_CMP_PKISTATUS_waiting ? "internal error" + : "warning", + "received from %s %s %s", opt_server, + string != NULL ? string : "", ""); + OPENSSL_free(buf); + } + + if (opt_cacertsout != NULL) { + STACK_OF(X509) *certs = OSSL_CMP_CTX_get1_caPubs(cmp_ctx); + + if (sk_X509_num(certs) > 0 + && save_certs(cmp_ctx, certs, opt_cacertsout, "CA") < 0) { + sk_X509_pop_free(certs, X509_free); + goto err; + } + sk_X509_pop_free(certs, X509_free); + } + + if (opt_extracertsout != NULL) { + STACK_OF(X509) *certs = OSSL_CMP_CTX_get1_extraCertsIn(cmp_ctx); + if (sk_X509_num(certs) > 0 + && save_certs(cmp_ctx, certs, opt_extracertsout, + "extra") < 0) { + sk_X509_pop_free(certs, X509_free); + goto err; + } + sk_X509_pop_free(certs, X509_free); + } + + if (opt_certout != NULL && newcert != NULL) { + STACK_OF(X509) *certs = sk_X509_new_null(); + + if (certs == NULL || !sk_X509_push(certs, newcert) + || save_certs(cmp_ctx, certs, opt_certout, + "enrolled") < 0) { + sk_X509_free(certs); + goto err; + } + sk_X509_free(certs); + } + if (!OSSL_CMP_CTX_reinit(cmp_ctx)) + goto err; + } + ret = 1; + + err: + /* in case we ended up here on error without proper cleaning */ + cleanse(opt_keypass); + cleanse(opt_newkeypass); + cleanse(opt_otherpass); + cleanse(opt_tls_keypass); + cleanse(opt_secret); + cleanse(opt_srv_keypass); + cleanse(opt_srv_secret); + + if (ret != 1) + OSSL_CMP_CTX_print_errors(cmp_ctx); + + ossl_cmp_mock_srv_free(OSSL_CMP_CTX_get_transfer_cb_arg(cmp_ctx)); + { + APP_HTTP_TLS_INFO *http_tls_info = + OSSL_CMP_CTX_get_http_cb_arg(cmp_ctx); + + if (http_tls_info != NULL) { + SSL_CTX_free(http_tls_info->ssl_ctx); + OPENSSL_free(http_tls_info); + } + } + X509_STORE_free(OSSL_CMP_CTX_get_certConf_cb_arg(cmp_ctx)); + OSSL_CMP_CTX_free(cmp_ctx); + X509_VERIFY_PARAM_free(vpm); + release_engine(e); + + NCONF_free(conf); /* must not do as long as opt_... variables are used */ + OSSL_CMP_log_close(); + + return ret == 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/apps/cmp_mock_srv.c b/apps/cmp_mock_srv.c index 8ffe4ca5..b45f9855 100644 --- a/apps/cmp_mock_srv.c +++ b/apps/cmp_mock_srv.c @@ -15,6 +15,10 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(OSSL_CMP_ITAV) +DEFINE_STACK_OF(ASN1_UTF8STRING) + /* the context for the CMP mock server */ typedef struct { diff --git a/apps/cms.c b/apps/cms.c index 0d89085c..6b5577ec 100644 --- a/apps/cms.c +++ b/apps/cms.c @@ -23,6 +23,12 @@ # include # include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(CMS_SignerInfo) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(GENERAL_NAMES) +DEFINE_STACK_OF_STRING() + static int save_certs(char *signerfile, STACK_OF(X509) *signers); static int cms_cb(int ok, X509_STORE_CTX *ctx); static void receipt_request_print(CMS_ContentInfo *cms); @@ -190,7 +196,7 @@ const OPTIONS cms_options[] = { {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, {"inkey", OPT_INKEY, 's', "Input private key (if not signer or recipient)"}, - {"keyform", OPT_KEYFORM, 'f', "Input private key format (PEM or ENGINE)"}, + {"keyform", OPT_KEYFORM, 'f', "Input private key format (ENGINE, other values ignored)"}, {"keyopt", OPT_KEYOPT, 's', "Set public key parameters as n:v pairs"}, OPT_SECTION("Mail header"), @@ -570,7 +576,7 @@ int cms_main(int argc, char **argv) if (operation == SMIME_ENCRYPT) { if (encerts == NULL && (encerts = sk_X509_new_null()) == NULL) goto end; - cert = load_cert(opt_arg(), FORMAT_PEM, + cert = load_cert(opt_arg(), FORMAT_UNDEF, "recipient certificate file"); if (cert == NULL) goto end; @@ -750,7 +756,7 @@ int cms_main(int argc, char **argv) if ((encerts = sk_X509_new_null()) == NULL) goto end; while (*argv) { - if ((cert = load_cert(*argv, FORMAT_PEM, + if ((cert = load_cert(*argv, FORMAT_UNDEF, "recipient certificate file")) == NULL) goto end; sk_X509_push(encerts, cert); @@ -768,7 +774,7 @@ int cms_main(int argc, char **argv) } if (recipfile != NULL && (operation == SMIME_DECRYPT)) { - if ((recip = load_cert(recipfile, FORMAT_PEM, + if ((recip = load_cert(recipfile, FORMAT_UNDEF, "recipient certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; @@ -776,7 +782,7 @@ int cms_main(int argc, char **argv) } if (originatorfile != NULL) { - if ((originator = load_cert(originatorfile, FORMAT_PEM, + if ((originator = load_cert(originatorfile, FORMAT_UNDEF, "originator certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; @@ -784,7 +790,7 @@ int cms_main(int argc, char **argv) } if (operation == SMIME_SIGN_RECEIPT) { - if ((signer = load_cert(signerfile, FORMAT_PEM, + if ((signer = load_cert(signerfile, FORMAT_UNDEF, "receipt signer certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; @@ -1013,7 +1019,8 @@ int cms_main(int argc, char **argv) signerfile = sk_OPENSSL_STRING_value(sksigners, i); keyfile = sk_OPENSSL_STRING_value(skkeys, i); - signer = load_cert(signerfile, FORMAT_PEM, "signer certificate"); + signer = load_cert(signerfile, FORMAT_UNDEF, + "signer certificate"); if (signer == NULL) { ret = 2; goto end; diff --git a/apps/crl.c b/apps/crl.c index 8028fef5..d417642c 100644 --- a/apps/crl.c +++ b/apps/crl.c @@ -34,9 +34,9 @@ const OPTIONS crl_options[] = { OPT_SECTION("Input"), {"in", OPT_IN, '<', "Input file - default stdin"}, - {"inform", OPT_INFORM, 'F', "Input format; default PEM"}, + {"inform", OPT_INFORM, 'F', "CRL input format (DER or PEM); has no effect"}, {"key", OPT_KEY, '<', "CRL signing Private key to use"}, - {"keyform", OPT_KEYFORM, 'F', "Private key file format (PEM or ENGINE)"}, + {"keyform", OPT_KEYFORM, 'F', "Private key file format (DER/PEM/P12); has no effect"}, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "output file - default stdout"}, @@ -122,7 +122,7 @@ int crl_main(int argc, char **argv) outfile = opt_arg(); break; case OPT_KEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &keyformat)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat)) goto opthelp; break; case OPT_KEY: diff --git a/apps/crl2p7.c b/apps/crl2p7.c index 9137f872..e0de95a1 100644 --- a/apps/crl2p7.c +++ b/apps/crl2p7.c @@ -19,6 +19,11 @@ #include #include +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_INFO) +DEFINE_STACK_OF_STRING() + static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile); typedef enum OPTION_choice { diff --git a/apps/dgst.c b/apps/dgst.c index 23faa340..da162e6e 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -21,6 +21,8 @@ #include #include +DEFINE_STACK_OF_STRING() + #undef BUFSIZE #define BUFSIZE 1024*8 @@ -62,7 +64,7 @@ const OPTIONS dgst_options[] = { {"c", OPT_C, '-', "Print the digest with separating colons"}, {"r", OPT_R, '-', "Print the digest in coreutils format"}, {"out", OPT_OUT, '>', "Output to filename rather than stdout"}, - {"keyform", OPT_KEYFORM, 'f', "Key file format (PEM or ENGINE)"}, + {"keyform", OPT_KEYFORM, 'f', "Key file format (ENGINE, other values ignored)"}, {"hex", OPT_HEX, '-', "Print as hex dump"}, {"binary", OPT_BINARY, '-', "Print in binary form"}, {"d", OPT_DEBUG, '-', "Print debug info"}, diff --git a/apps/dsa.c b/apps/dsa.c index 65397ab0..8ef802e0 100644 --- a/apps/dsa.c +++ b/apps/dsa.c @@ -48,7 +48,7 @@ const OPTIONS dsa_options[] = { OPT_SECTION("Input"), {"in", OPT_IN, 's', "Input key"}, - {"inform", OPT_INFORM, 'f', "Input format, DER PEM PVK"}, + {"inform", OPT_INFORM, 'f', "Input format (DER/PEM/PVK); has no effect"}, {"pubin", OPT_PUBIN, '-', "Expect a public key in input file"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, diff --git a/apps/ec.c b/apps/ec.c index 9cf6e1a5..43e2be13 100644 --- a/apps/ec.c +++ b/apps/ec.c @@ -49,7 +49,7 @@ const OPTIONS ec_options[] = { OPT_SECTION("Input"), {"in", OPT_IN, 's', "Input file"}, - {"inform", OPT_INFORM, 'f', "Input format - DER or PEM"}, + {"inform", OPT_INFORM, 'f', "Input format (DER/PEM/P12/ENGINE)"}, {"pubin", OPT_PUBIN, '-', "Expect a public key in input file"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, {"check", OPT_CHECK, '-', "check key consistency"}, diff --git a/apps/enc.c b/apps/enc.c index d7e99b43..4d59391c 100644 --- a/apps/enc.c +++ b/apps/enc.c @@ -538,7 +538,7 @@ int enc_main(int argc, char **argv) goto end; } /* wiping secret data as we no longer need it */ - OPENSSL_cleanse(hkey, strlen(hkey)); + cleanse(hkey); } if ((benc = BIO_new(BIO_f_cipher())) == NULL) diff --git a/apps/engine.c b/apps/engine.c index 2b295fde..6d788ac8 100644 --- a/apps/engine.c +++ b/apps/engine.c @@ -19,6 +19,9 @@ #include #include +DEFINE_STACK_OF_STRING() +DEFINE_STACK_OF_CSTRING() + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_C, OPT_T, OPT_TT, OPT_PRE, OPT_POST, diff --git a/apps/fipsinstall.c b/apps/fipsinstall.c index 157f08b1..1eb183f3 100644 --- a/apps/fipsinstall.c +++ b/apps/fipsinstall.c @@ -18,6 +18,8 @@ #include "apps.h" #include "progs.h" +DEFINE_STACK_OF_STRING() + #define BUFSIZE 4096 #define DEFAULT_MAC_NAME "HMAC" #define DEFAULT_FIPS_SECTION "fips_check_section" diff --git a/apps/include/apps.h b/apps/include/apps.h index e168942e..b0512222 100644 --- a/apps/include/apps.h +++ b/apps/include/apps.h @@ -12,6 +12,7 @@ # include "e_os.h" /* struct timeval for DTLS */ # include "internal/nelem.h" +# include "internal/sockets.h" /* for openssl_fdset() */ # include # include @@ -35,19 +36,12 @@ # include "fmt.h" # include "platform.h" -/* also in include/internal/sockets.h */ -# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE) -# define openssl_fdset(a,b) FD_SET((unsigned int)a, b) -# else -# define openssl_fdset(a,b) FD_SET(a, b) -# endif - /* * quick macro when you need to pass an unsigned char instead of a char. * this is true for some implementations of the is*() functions, for * example. */ -#define _UC(c) ((unsigned char)(c)) +# define _UC(c) ((unsigned char)(c)) void app_RAND_load_conf(CONF *c, const char *section); void app_RAND_write(void); @@ -102,19 +96,28 @@ int set_cert_ex(unsigned long *flags, const char *arg); int set_name_ex(unsigned long *flags, const char *arg); int set_ext_copy(int *copy_type, const char *arg); int copy_extensions(X509 *x, X509_REQ *req, int copy_type); +char *get_passwd(const char *pass, const char *desc); int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2); int add_oid_section(CONF *conf); X509_REQ *load_csr(const char *file, int format, const char *desc); -X509 *load_cert(const char *file, int format, const char *desc); -X509_CRL *load_crl(const char *infile, int format, const char *desc); -EVP_PKEY *load_key(const char *file, int format, int maybe_stdin, +X509 *load_cert_pass(const char *uri, int maybe_stdin, + const char *pass, const char *desc); +/* the format parameter is meanwhile not needed anymore and thus ignored */ +X509 *load_cert(const char *uri, int format, const char *desc); +X509_CRL *load_crl(const char *uri, int format, const char *desc); +void cleanse(char *str); +void clear_free(char *str); +EVP_PKEY *load_key(const char *uri, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *desc); -EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin, +EVP_PKEY *load_pubkey(const char *uri, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *desc); int load_certs(const char *file, STACK_OF(X509) **certs, int format, const char *pass, const char *desc); int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format, const char *pass, const char *desc); +int load_key_cert_crl(const char *uri, int maybe_stdin, + const char *pass, const char *desc, + EVP_PKEY **ppkey, X509 **pcert, X509_CRL **pcrl); X509_STORE *setup_verify(const char *CAfile, int noCAfile, const char *CApath, int noCApath, const char *CAstore, int noCAstore); @@ -123,7 +126,7 @@ __owur int ctx_set_verify_locations(SSL_CTX *ctx, const char *CApath, int noCApath, const char *CAstore, int noCAstore); -#ifndef OPENSSL_NO_CT +# ifndef OPENSSL_NO_CT /* * Sets the file to load the Certificate Transparency log list from. @@ -132,9 +135,10 @@ __owur int ctx_set_verify_locations(SSL_CTX *ctx, */ __owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path); -#endif +# endif -ENGINE *setup_engine(const char *engine, int debug); +ENGINE *setup_engine_methods(const char *id, unsigned int methods, int debug); +# define setup_engine(e, debug) setup_engine_methods(e, (unsigned int)-1, debug) void release_engine(ENGINE *e); # ifndef OPENSSL_NO_OCSP diff --git a/apps/include/apps_ui.h b/apps/include/apps_ui.h index 55a6b510..67d61e13 100644 --- a/apps/include/apps_ui.h +++ b/apps/include/apps_ui.h @@ -1,7 +1,7 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/apps/include/fmt.h b/apps/include/fmt.h index 01acf866..c9edd470 100644 --- a/apps/include/fmt.h +++ b/apps/include/fmt.h @@ -1,7 +1,7 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/apps/include/http_server.h b/apps/include/http_server.h new file mode 100644 index 00000000..8c655213 --- /dev/null +++ b/apps/include/http_server.h @@ -0,0 +1,102 @@ +/* + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef OSSL_HTTP_SERVER_H +# define OSSL_HTTP_SERVER_H + +# include "apps.h" + +# ifndef HAVE_FORK +# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) +# define HAVE_FORK 0 +# else +# define HAVE_FORK 1 +# endif +# endif + +# if HAVE_FORK +# undef NO_FORK +# else +# define NO_FORK +# endif + +# if !defined(NO_FORK) && !defined(OPENSSL_NO_SOCK) \ + && !defined(OPENSSL_NO_POSIX_IO) +# define HTTP_DAEMON +# include +# include +# include +# include +# define MAXERRLEN 1000 /* limit error text sent to syslog to 1000 bytes */ +# else +# undef LOG_INFO +# undef LOG_WARNING +# undef LOG_ERR +# define LOG_INFO 0 +# define LOG_WARNING 1 +# define LOG_ERR 2 +# endif + +/*- + * Log a message to syslog if multi-threaded HTTP_DAEMON, else to bio_err + * prog: the name of the current app + * level: the severity of the message, e.g., LOG_ERR + * fmt: message with potential extra parameters like with printf() + * returns nothing + */ +void log_message(const char *prog, int level, const char *fmt, ...); + +# ifndef OPENSSL_NO_SOCK +/*- + * Initialize an HTTP server by setting up its listening BIO + * prog: the name of the current app + * port: the port to listen on + * returns a BIO for accepting requests, NULL on error + */ +BIO *http_server_init_bio(const char *prog, const char *port); +/*- + * Accept an ASN.1-formatted HTTP request + * it: the expected request ASN.1 type + * preq: pointer to variable where to place the parsed request + * pcbio: pointer to variable where to place the BIO for sending the response to + * acbio: the listening bio (typically as returned by http_server_init_bio()) + * prog: the name of the current app + * accept_get: wheter to accept GET requests (in addition to POST requests) + * timeout: connection timeout (in seconds), or 0 for none/infinite + * returns 0 in case caller should retry, then *preq == *pcbio == NULL + * returns -1 on fatal error; also in this case *preq == *pcbio == NULL + * returns 1 otherwise. In this case it is guaranteed that *pcbio != NULL + * while *preq == NULL if and only if request is invalid + */ +int http_server_get_asn1_req(const ASN1_ITEM *it, ASN1_VALUE **preq, + BIO **pcbio, BIO *acbio, + const char *prog, int accept_get, int timeout); +/*- + * Send an ASN.1-formatted HTTP response + * cbio: destination BIO (typically as returned by http_server_get_asn1_req()) + * note: cbio should not do an encoding that changes the output length + * content_type: string identifying the type of the response + * it: the response ASN.1 type + * valit: the response ASN.1 type + * resp: the response to send + * returns 1 on success, 0 on failure + */ +int http_server_send_asn1_resp(BIO *cbio, const char *content_type, + const ASN1_ITEM *it, const ASN1_VALUE *resp); +# endif + +# ifdef HTTP_DAEMON +extern int multi; +extern int acfd; + +void socket_timeout(int signum); +void spawn_loop(const char *prog); +# endif + +#endif diff --git a/apps/include/opt.h b/apps/include/opt.h index 1bf46215..5afbad1b 100644 --- a/apps/include/opt.h +++ b/apps/include/opt.h @@ -1,7 +1,7 @@ /* * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -132,9 +132,9 @@ { "xchain_build", OPT_X_CHAIN_BUILD, '-', \ "build certificate chain for the extended certificates"}, \ { "xcertform", OPT_X_CERTFORM, 'F', \ - "format of Extended certificate (PEM or DER) PEM default " }, \ + "format of Extended certificate (PEM/DER/P12); has no effect" }, \ { "xkeyform", OPT_X_KEYFORM, 'F', \ - "format of Extended certificate's key (PEM or DER) PEM default"} + "format of Extended certificate's key (DER/PEM/P12); has no effect"} # define OPT_X_CASES \ OPT_X__FIRST: case OPT_X__LAST: break; \ diff --git a/apps/include/s_apps.h b/apps/include/s_apps.h index 1bbe5fe0..0a1ae526 100644 --- a/apps/include/s_apps.h +++ b/apps/include/s_apps.h @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -32,6 +32,7 @@ int init_client(int *sock, const char *host, const char *port, const char *bindhost, const char *bindport, int family, int type, int protocol); int should_retry(int i); +void do_ssl_shutdown(SSL *ssl); long bio_dump_callback(BIO *bio, int cmd, const char *argp, int argi, long argl, long ret); diff --git a/apps/kdf.c b/apps/kdf.c index 0b577b2b..8d11807f 100644 --- a/apps/kdf.c +++ b/apps/kdf.c @@ -1,7 +1,7 @@ /* * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -17,6 +17,8 @@ #include #include +DEFINE_STACK_OF_STRING() + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_KDFOPT, OPT_BIN, OPT_KEYLEN, OPT_OUT, diff --git a/apps/lib/app_x509.c b/apps/lib/app_x509.c index 89c5960f..00581aab 100644 --- a/apps/lib/app_x509.c +++ b/apps/lib/app_x509.c @@ -106,12 +106,15 @@ static int do_x509_ctrl_string(int (*ctrl)(void *object, int cmd, cmd = EVP_PKEY_CTRL_SET1_ID; /* ... except we put it in X509 */ #endif } else if (strcmp(stmp, "hexdistid") == 0) { - long hexid_len = 0; - void *hexid = OPENSSL_hexstr2buf((const char *)vtmp, &hexid_len); + if (vtmp != NULL) { + void *hexid; + long hexid_len = 0; - OPENSSL_free(stmp); - stmp = vtmp = hexid; - vtmp_len = (size_t)hexid_len; + hexid = OPENSSL_hexstr2buf((const char *)vtmp, &hexid_len); + OPENSSL_free(stmp); + stmp = vtmp = hexid; + vtmp_len = (size_t)hexid_len; + } #ifdef EVP_PKEY_CTRL_SET1_ID cmd = EVP_PKEY_CTRL_SET1_ID; /* ... except we put it in X509 */ #endif diff --git a/apps/lib/apps.c b/apps/lib/apps.c index 61e3ab19..4337cc6c 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,17 @@ static int WIN32_rename(const char *from, const char *to); #define PASS_SOURCE_SIZE_MAX 4 +DEFINE_STACK_OF(CONF) +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(X509_INFO) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(X509_POLICY_NODE) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(DIST_POINT) +DEFINE_STACK_OF_STRING() + typedef struct { const char *name; unsigned long flag; @@ -198,6 +210,24 @@ int wrap_password_callback(char *buf, int bufsiz, int verify, void *userdata) static char *app_get_pass(const char *arg, int keepbio); +char *get_passwd(const char *pass, const char *desc) +{ + char *result = NULL; + + if (desc == NULL) + desc = ""; + if (!app_passwd(pass, NULL, &result, NULL)) + BIO_printf(bio_err, "Error getting password for %s\n", desc); + if (pass != NULL && result == NULL) { + BIO_printf(bio_err, + "Trying plain input string (better precede with 'pass:')\n"); + result = OPENSSL_strdup(pass); + if (result == NULL) + BIO_printf(bio_err, "Out of memory getting password for %s\n", desc); + } + return result; +} + int app_passwd(const char *arg1, const char *arg2, char **pass1, char **pass2) { int same = arg1 != NULL && arg2 != NULL && strcmp(arg1, arg2) == 0; @@ -401,122 +431,44 @@ int add_oid_section(CONF *conf) return 1; } -static int load_pkcs12(BIO *in, const char *desc, - pem_password_cb *pem_cb, PW_CB_DATA *cb_data, - EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca) +X509 *load_cert_pass(const char *uri, int maybe_stdin, + const char *pass, const char *desc) { - const char *pass; - char tpass[PEM_BUFSIZE]; - int len, ret = 0; - PKCS12 *p12; - p12 = d2i_PKCS12_bio(in, NULL); - if (p12 == NULL && desc != NULL) { - BIO_printf(bio_err, "Error loading PKCS12 file for %s\n", desc); - goto die; - } - /* See if an empty password will do */ - if (PKCS12_verify_mac(p12, "", 0) || PKCS12_verify_mac(p12, NULL, 0)) { - pass = ""; - } else { - if (pem_cb == NULL) - pem_cb = (pem_password_cb *)password_callback; - len = pem_cb(tpass, PEM_BUFSIZE, 0, cb_data); - if (len < 0) { - BIO_printf(bio_err, "Passphrase callback error for %s\n", - desc != NULL ? desc : "PKCS12 input"); - goto die; - } - if (len < PEM_BUFSIZE) - tpass[len] = 0; - if (!PKCS12_verify_mac(p12, tpass, len)) { - BIO_printf(bio_err, - "Mac verify error (wrong password?) in PKCS12 file for %s\n", - desc != NULL ? desc : "PKCS12 input"); - goto die; - } - pass = tpass; - } - ret = PKCS12_parse(p12, pass, pkey, cert, ca); - die: - PKCS12_free(p12); - return ret; -} + X509 *cert = NULL; -X509 *load_cert(const char *file, int format, const char *desc) -{ - X509 *x = NULL; - BIO *cert; - - if (format == FORMAT_HTTP) { -#if !defined(OPENSSL_NO_SOCK) - x = X509_load_http(file, NULL, NULL, 0 /* timeout */); -#endif - return x; - } - - if (file == NULL) { + if (desc == NULL) + desc = "certificate"; + if (uri == NULL) { unbuffer(stdin); - cert = dup_bio_in(format); - } else { - cert = bio_open_default(file, 'r', format); + uri = ""; } - if (cert == NULL) - goto end; - - if (format == FORMAT_ASN1) { - x = d2i_X509_bio(cert, NULL); - } else if (format == FORMAT_PEM) { - x = PEM_read_bio_X509_AUX(cert, NULL, - (pem_password_cb *)password_callback, NULL); - } else if (format == FORMAT_PKCS12) { - if (!load_pkcs12(cert, desc, NULL, NULL, NULL, &x, NULL)) - goto end; - } else { - print_format_error(format, -#if !defined(OPENSSL_NO_OCSP) && !defined(OPENSSL_NO_SOCK) - OPT_FMT_HTTP | -#endif - OPT_FMT_PEMDER | OPT_FMT_PKCS12); - } - - end: - if (x == NULL && desc != NULL) { + (void)load_key_cert_crl(uri, maybe_stdin, pass, desc, NULL, &cert, NULL); + if (cert == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } - BIO_free(cert); - return x; + return cert; } -X509_CRL *load_crl(const char *infile, int format, const char *desc) +/* the format parameter is meanwhile not needed anymore and thus ignored */ +X509 *load_cert(const char *uri, int format, const char *desc) { - X509_CRL *x = NULL; - BIO *in = NULL; + return load_cert_pass(uri, 0, NULL, desc); +} - if (format == FORMAT_HTTP) { -#if !defined(OPENSSL_NO_SOCK) - x = X509_CRL_load_http(infile, NULL, NULL, 0 /* timeout */); -#endif - return x; - } +/* the format parameter is meanwhile not needed anymore and thus ignored */ +X509_CRL *load_crl(const char *uri, int format, const char *desc) +{ + X509_CRL *crl = NULL; - in = bio_open_default(infile, 'r', format); - if (in == NULL) - goto end; - if (format == FORMAT_ASN1) { - x = d2i_X509_CRL_bio(in, NULL); - } else if (format == FORMAT_PEM) { - x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); - } else - print_format_error(format, OPT_FMT_PEMDER); - - end: - if (x == NULL && desc != NULL) { + if (desc == NULL) + desc = "CRL"; + (void)load_key_cert_crl(uri, 0, NULL, desc, NULL, NULL, &crl); + if (crl == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } - BIO_free(in); - return x; + return crl; } X509_REQ *load_csr(const char *file, int format, const char *desc) @@ -524,6 +476,8 @@ X509_REQ *load_csr(const char *file, int format, const char *desc) X509_REQ *req = NULL; BIO *in; + if (desc == NULL) + desc = "CSR"; in = bio_open_default(file, 'r', format); if (in == NULL) goto end; @@ -536,7 +490,7 @@ X509_REQ *load_csr(const char *file, int format, const char *desc) print_format_error(format, OPT_FMT_PEMDER); end: - if (req == NULL && desc != NULL) { + if (req == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } @@ -544,173 +498,92 @@ X509_REQ *load_csr(const char *file, int format, const char *desc) return req; } -EVP_PKEY *load_key(const char *file, int format, int maybe_stdin, +void cleanse(char *str) +{ + if (str != NULL) + OPENSSL_cleanse(str, strlen(str)); +} + +void clear_free(char *str) +{ + if (str != NULL) + OPENSSL_clear_free(str, strlen(str)); +} + +EVP_PKEY *load_key(const char *uri, int format, int may_stdin, const char *pass, ENGINE *e, const char *desc) { - BIO *key = NULL; EVP_PKEY *pkey = NULL; - PW_CB_DATA cb_data; - cb_data.password = pass; - cb_data.prompt_info = file; + if (desc == NULL) + desc = "private key"; - if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE)) { - BIO_printf(bio_err, "No keyfile specified\n"); - goto end; - } if (format == FORMAT_ENGINE) { if (e == NULL) { - BIO_printf(bio_err, "No engine specified\n"); + BIO_printf(bio_err, "No engine specified for loading %s\n", desc); } else { #ifndef OPENSSL_NO_ENGINE + PW_CB_DATA cb_data; + + cb_data.password = pass; + cb_data.prompt_info = uri; if (ENGINE_init(e)) { - pkey = ENGINE_load_private_key(e, file, + pkey = ENGINE_load_private_key(e, uri, (UI_METHOD *)get_ui_method(), &cb_data); ENGINE_finish(e); } - if (pkey == NULL && desc != NULL) { + if (pkey == NULL) { BIO_printf(bio_err, "Cannot load %s from engine\n", desc); ERR_print_errors(bio_err); } #else - BIO_printf(bio_err, "Engines not supported\n"); + BIO_printf(bio_err, "Engines not supported for loading %s\n", desc); #endif } - goto end; - } - if (file == NULL && maybe_stdin) { - unbuffer(stdin); - key = dup_bio_in(format); } else { - key = bio_open_default(file, 'r', format); - } - if (key == NULL) - goto end; - if (format == FORMAT_ASN1) { - pkey = d2i_PrivateKey_bio(key, NULL); - } else if (format == FORMAT_PEM) { - pkey = PEM_read_bio_PrivateKey(key, NULL, wrap_password_callback, &cb_data); - } else if (format == FORMAT_PKCS12) { - if (!load_pkcs12(key, desc, - (pem_password_cb *)password_callback, &cb_data, - &pkey, NULL, NULL)) - goto end; -#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4) - } else if (format == FORMAT_MSBLOB) { - pkey = b2i_PrivateKey_bio(key); - } else if (format == FORMAT_PVK) { - pkey = b2i_PVK_bio(key, wrap_password_callback, &cb_data); -#endif - } else { - print_format_error(format, OPT_FMT_PEMDER | OPT_FMT_PKCS12 -#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4) - | OPT_FMT_MSBLOB | FORMAT_PVK -#endif -#ifndef OPENSSL_NO_ENGINE - | OPT_FMT_ENGINE -#endif - ); + (void)load_key_cert_crl(uri, may_stdin, pass, desc, &pkey, NULL, NULL); } - end: - BIO_free(key); - if (pkey == NULL && desc != NULL) { + if (pkey == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } return pkey; } -EVP_PKEY *load_pubkey(const char *file, int format, int maybe_stdin, +EVP_PKEY *load_pubkey(const char *uri, int format, int maybe_stdin, const char *pass, ENGINE *e, const char *desc) { - BIO *key = NULL; EVP_PKEY *pkey = NULL; - PW_CB_DATA cb_data; - cb_data.password = pass; - cb_data.prompt_info = file; + if (desc == NULL) + desc = "public key"; - if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE)) { - BIO_printf(bio_err, "No keyfile specified\n"); - goto end; - } if (format == FORMAT_ENGINE) { if (e == NULL) { - BIO_printf(bio_err, "No engine specified\n"); + BIO_printf(bio_err, "No engine specified for loading %s\n", desc); } else { #ifndef OPENSSL_NO_ENGINE - pkey = ENGINE_load_public_key(e, file, (UI_METHOD *)get_ui_method(), + PW_CB_DATA cb_data; + + cb_data.password = pass; + cb_data.prompt_info = uri; + pkey = ENGINE_load_public_key(e, uri, (UI_METHOD *)get_ui_method(), &cb_data); - if (pkey == NULL && desc != NULL) { + if (pkey == NULL) { BIO_printf(bio_err, "Cannot load %s from engine\n", desc); ERR_print_errors(bio_err); } #else - BIO_printf(bio_err, "Engines not supported\n"); + BIO_printf(bio_err, "Engines not supported for loading %s\n", desc); #endif } - goto end; - } - if (file == NULL && maybe_stdin) { - unbuffer(stdin); - key = dup_bio_in(format); } else { - key = bio_open_default(file, 'r', format); + (void)load_key_cert_crl(uri, maybe_stdin, pass, desc, &pkey, + NULL, NULL); } - if (key == NULL) - goto end; - if (format == FORMAT_ASN1) { - pkey = d2i_PUBKEY_bio(key, NULL); - } else if (format == FORMAT_ASN1RSA) { -#ifndef OPENSSL_NO_RSA - RSA *rsa; - rsa = d2i_RSAPublicKey_bio(key, NULL); - if (rsa) { - pkey = EVP_PKEY_new(); - if (pkey != NULL) - EVP_PKEY_set1_RSA(pkey, rsa); - RSA_free(rsa); - } else -#else - BIO_printf(bio_err, "RSA keys not supported\n"); -#endif - pkey = NULL; - } else if (format == FORMAT_PEMRSA) { -#ifndef OPENSSL_NO_RSA - RSA *rsa; - rsa = PEM_read_bio_RSAPublicKey(key, NULL, - (pem_password_cb *)password_callback, - &cb_data); - if (rsa != NULL) { - pkey = EVP_PKEY_new(); - if (pkey != NULL) - EVP_PKEY_set1_RSA(pkey, rsa); - RSA_free(rsa); - } else -#else - BIO_printf(bio_err, "RSA keys not supported\n"); -#endif - pkey = NULL; - } else if (format == FORMAT_PEM) { - pkey = PEM_read_bio_PUBKEY(key, NULL, - (pem_password_cb *)password_callback, - &cb_data); -#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) - } else if (format == FORMAT_MSBLOB) { - pkey = b2i_PublicKey_bio(key); -#endif - } else { - print_format_error(format, OPT_FMT_PEMDER -#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) - | OPT_FMT_MSBLOB -#endif - ); - } - end: - BIO_free(key); - if (pkey == NULL && desc != NULL) { + if (pkey == NULL) { BIO_printf(bio_err, "Unable to load %s\n", desc); ERR_print_errors(bio_err); } @@ -792,11 +665,8 @@ static int load_certs_crls(const char *file, int format, sk_X509_CRL_pop_free(*pcrls, X509_CRL_free); *pcrls = NULL; } - if (desc != NULL) { - BIO_printf(bio_err, "Unable to load %s for %s\n", - pcerts ? "certificates" : "CRLs", desc); - ERR_print_errors(bio_err); - } + BIO_printf(bio_err, "Unable to load %s\n", desc != NULL ? desc : + pcerts != NULL ? "certificates" : "CRLs"); } return rv; } @@ -832,6 +702,102 @@ int load_crls(const char *file, STACK_OF(X509_CRL) **crls, int format, return load_certs_crls(file, format, pass, desc, NULL, crls); } +/* + * Load those types of credentials for which the result pointer is not NULL. + * Reads from stdio if uri is NULL and maybe_stdin is nonzero. + * For each type the first credential found in the store is loaded. + * May yield partial result even if rv == 0. + */ +int load_key_cert_crl(const char *uri, int maybe_stdin, + const char *pass, const char *desc, + EVP_PKEY **ppkey, X509 **pcert, X509_CRL **pcrl) +{ + PW_CB_DATA uidata; + OSSL_STORE_CTX *ctx = NULL; + int ret = 0; + /* TODO make use of the engine reference 'eng' when loading pkeys */ + + if (ppkey != NULL) + *ppkey = NULL; + if (pcert != NULL) + *pcert = NULL; + if (pcrl != NULL) + *pcrl = NULL; + + if (desc == NULL) + desc = "key/certificate/CRL"; + uidata.password = pass; + uidata.prompt_info = uri; + + if (uri == NULL) { + BIO *bio; + + if (!maybe_stdin) { + BIO_printf(bio_err, "No filename or uri specified for loading %s\n", + desc); + goto end; + } + unbuffer(stdin); + bio = BIO_new_fp(stdin, 0); + if (bio != NULL) + ctx = OSSL_STORE_attach(bio, NULL, "file", NULL, + get_ui_method(), &uidata, NULL, NULL); + uri = ""; + } else { + ctx = OSSL_STORE_open(uri, get_ui_method(), &uidata, NULL, NULL); + } + if (ctx == NULL) { + BIO_printf(bio_err, "Could not open file or uri %s for loading %s\n", + uri, desc); + goto end; + } + + for (;;) { + OSSL_STORE_INFO *info = OSSL_STORE_load(ctx); + int type = info == NULL ? 0 : OSSL_STORE_INFO_get_type(info); + const char *infostr = + info == NULL ? NULL : OSSL_STORE_INFO_type_string(type); + int err = 0; + + if (info == NULL) { + if (OSSL_STORE_eof(ctx)) + ret = 1; + break; + } + + switch (type) { + case OSSL_STORE_INFO_PKEY: + if (ppkey != NULL && *ppkey == NULL) + err = ((*ppkey = OSSL_STORE_INFO_get1_PKEY(info)) == NULL); + break; + case OSSL_STORE_INFO_CERT: + if (pcert != NULL && *pcert == NULL) + err = ((*pcert = OSSL_STORE_INFO_get1_CERT(info)) == NULL); + break; + case OSSL_STORE_INFO_CRL: + if (pcrl != NULL && *pcrl == NULL) + err = ((*pcrl = OSSL_STORE_INFO_get1_CRL(info)) == NULL); + break; + default: + /* skip any other type */ + break; + } + OSSL_STORE_INFO_free(info); + if (err) { + BIO_printf(bio_err, "Could not read %s of %s from %s\n", + infostr, desc, uri); + break; + } + } + + end: + OSSL_STORE_close(ctx); + if (!ret) + ERR_print_errors(bio_err); + return ret; +} + + #define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) /* Return error for unknown extensions */ #define X509V3_EXT_DEFAULT 0 @@ -1149,29 +1115,28 @@ static ENGINE *try_load_engine(const char *engine) } #endif -ENGINE *setup_engine(const char *engine, int debug) +ENGINE *setup_engine_methods(const char *id, unsigned int methods, int debug) { ENGINE *e = NULL; #ifndef OPENSSL_NO_ENGINE - if (engine != NULL) { - if (strcmp(engine, "auto") == 0) { + if (id != NULL) { + if (strcmp(id, "auto") == 0) { BIO_printf(bio_err, "Enabling auto ENGINE support\n"); ENGINE_register_all_complete(); return NULL; } - if ((e = ENGINE_by_id(engine)) == NULL - && (e = try_load_engine(engine)) == NULL) { - BIO_printf(bio_err, "Invalid engine \"%s\"\n", engine); + if ((e = ENGINE_by_id(id)) == NULL + && (e = try_load_engine(id)) == NULL) { + BIO_printf(bio_err, "Invalid engine \"%s\"\n", id); ERR_print_errors(bio_err); return NULL; } - if (debug) { - ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM, 0, bio_err, 0); - } - ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0, (void *)get_ui_method(), - 0, 1); - if (!ENGINE_set_default(e, ENGINE_METHOD_ALL)) { + if (debug) + (void)ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM, 0, bio_err, 0); + if (!ENGINE_ctrl_cmd(e, "SET_USER_INTERFACE", 0, + (void *)get_ui_method(), 0, 1) + || !ENGINE_set_default(e, methods)) { BIO_printf(bio_err, "Cannot use engine \"%s\"\n", ENGINE_get_id(e)); ERR_print_errors(bio_err); ENGINE_free(e); @@ -2305,17 +2270,30 @@ double app_tminterval(int stop, int usertime) double app_tminterval(int stop, int usertime) { double ret = 0; - struct tms rus; - clock_t now = times(&rus); + clock_t now; static clock_t tmstart; + long int tck = sysconf(_SC_CLK_TCK); +# ifdef __TMS + struct tms rus; + now = times(&rus); if (usertime) now = rus.tms_utime; +# else + if (usertime) + now = clock(); /* sum of user and kernel times */ + else { + struct timeval tv; + gettimeofday(&tv, NULL); + now = (clock_t)((unsigned long long)tv.tv_sec * tck + + (unsigned long long)tv.tv_usec * (1000000 / tck) + ); + } +# endif if (stop == TM_START) { tmstart = now; } else { - long int tck = sysconf(_SC_CLK_TCK); ret = (now - tmstart) / (double)tck; } diff --git a/apps/lib/apps_ui.c b/apps/lib/apps_ui.c index bcfe5554..2a6e01ec 100644 --- a/apps/lib/apps_ui.c +++ b/apps/lib/apps_ui.c @@ -1,7 +1,7 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/apps/lib/build.info b/apps/lib/build.info index 129ffce9..22db095c 100644 --- a/apps/lib/build.info +++ b/apps/lib/build.info @@ -9,7 +9,7 @@ ENDIF # Source for libapps $LIBAPPSSRC=apps.c apps_ui.c opt.c fmt.c s_cb.c s_socket.c app_rand.c \ - columns.c app_params.c names.c app_provider.c app_x509.c + columns.c app_params.c names.c app_provider.c app_x509.c http_server.c IF[{- !$disabled{apps} -}] LIBS{noinst}=../libapps.a diff --git a/apps/lib/fmt.c b/apps/lib/fmt.c index 5cb4c041..af0e63b8 100644 --- a/apps/lib/fmt.c +++ b/apps/lib/fmt.c @@ -1,7 +1,7 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/apps/lib/http_server.c b/apps/lib/http_server.c new file mode 100644 index 00000000..2b5c9f5d --- /dev/null +++ b/apps/lib/http_server.c @@ -0,0 +1,395 @@ +/* + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* Very basic HTTP server */ + +#if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS) +/* + * On VMS, you need to define this to get the declaration of fileno(). The + * value 2 is to make sure no function defined in POSIX-2 is left undefined. + */ +# define _POSIX_C_SOURCE 2 +#endif + +#include +#include +#include "http_server.h" +#include "internal/sockets.h" +#include +#include + +int multi = 0; /* run multiple responder processes */ + +#ifdef HTTP_DAEMON +int acfd = (int) INVALID_SOCKET; +#endif + +#ifdef HTTP_DAEMON +static int print_syslog(const char *str, size_t len, void *levPtr) +{ + int level = *(int *)levPtr; + int ilen = len > MAXERRLEN ? MAXERRLEN : len; + + syslog(level, "%.*s", ilen, str); + + return ilen; +} +#endif + +void log_message(const char *prog, int level, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); +#ifdef HTTP_DAEMON + if (multi) { + char buf[1024]; + + if (vsnprintf(buf, sizeof(buf), fmt, ap) > 0) + syslog(level, "%s", buf); + if (level >= LOG_ERR) + ERR_print_errors_cb(print_syslog, &level); + } +#endif + if (!multi) { + BIO_printf(bio_err, "%s: ", prog); + BIO_vprintf(bio_err, fmt, ap); + BIO_printf(bio_err, "\n"); + } + va_end(ap); +} + +#ifdef HTTP_DAEMON +void socket_timeout(int signum) +{ + if (acfd != (int)INVALID_SOCKET) + (void)shutdown(acfd, SHUT_RD); +} + +static void killall(int ret, pid_t *kidpids) +{ + int i; + + for (i = 0; i < multi; ++i) + if (kidpids[i] != 0) + (void)kill(kidpids[i], SIGTERM); + OPENSSL_free(kidpids); + sleep(1); + exit(ret); +} + +static int termsig = 0; + +static void noteterm(int sig) +{ + termsig = sig; +} + +/* + * Loop spawning up to `multi` child processes, only child processes return + * from this function. The parent process loops until receiving a termination + * signal, kills extant children and exits without returning. + */ +void spawn_loop(const char *prog) +{ + pid_t *kidpids = NULL; + int status; + int procs = 0; + int i; + + openlog(prog, LOG_PID, LOG_DAEMON); + + if (setpgid(0, 0)) { + syslog(LOG_ERR, "fatal: error detaching from parent process group: %s", + strerror(errno)); + exit(1); + } + kidpids = app_malloc(multi * sizeof(*kidpids), "child PID array"); + for (i = 0; i < multi; ++i) + kidpids[i] = 0; + + signal(SIGINT, noteterm); + signal(SIGTERM, noteterm); + + while (termsig == 0) { + pid_t fpid; + + /* + * Wait for a child to replace when we're at the limit. + * Slow down if a child exited abnormally or waitpid() < 0 + */ + while (termsig == 0 && procs >= multi) { + if ((fpid = waitpid(-1, &status, 0)) > 0) { + for (i = 0; i < procs; ++i) { + if (kidpids[i] == fpid) { + kidpids[i] = 0; + --procs; + break; + } + } + if (i >= multi) { + syslog(LOG_ERR, "fatal: internal error: " + "no matching child slot for pid: %ld", + (long) fpid); + killall(1, kidpids); + } + if (status != 0) { + if (WIFEXITED(status)) + syslog(LOG_WARNING, "child process: %ld, exit status: %d", + (long)fpid, WEXITSTATUS(status)); + else if (WIFSIGNALED(status)) + syslog(LOG_WARNING, "child process: %ld, term signal %d%s", + (long)fpid, WTERMSIG(status), +# ifdef WCOREDUMP + WCOREDUMP(status) ? " (core dumped)" : +# endif + ""); + sleep(1); + } + break; + } else if (errno != EINTR) { + syslog(LOG_ERR, "fatal: waitpid(): %s", strerror(errno)); + killall(1, kidpids); + } + } + if (termsig) + break; + + switch (fpid = fork()) { + case -1: /* error */ + /* System critically low on memory, pause and try again later */ + sleep(30); + break; + case 0: /* child */ + OPENSSL_free(kidpids); + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + if (termsig) + _exit(0); + if (RAND_poll() <= 0) { + syslog(LOG_ERR, "fatal: RAND_poll() failed"); + _exit(1); + } + return; + default: /* parent */ + for (i = 0; i < multi; ++i) { + if (kidpids[i] == 0) { + kidpids[i] = fpid; + procs++; + break; + } + } + if (i >= multi) { + syslog(LOG_ERR, "fatal: internal error: no free child slots"); + killall(1, kidpids); + } + break; + } + } + + /* The loop above can only break on termsig */ + syslog(LOG_INFO, "terminating on signal: %d", termsig); + killall(0, kidpids); +} +#endif + +#ifndef OPENSSL_NO_SOCK +BIO *http_server_init_bio(const char *prog, const char *port) +{ + BIO *acbio = NULL, *bufbio; + + bufbio = BIO_new(BIO_f_buffer()); + if (bufbio == NULL) + goto err; + acbio = BIO_new(BIO_s_accept()); + if (acbio == NULL + || BIO_set_bind_mode(acbio, BIO_BIND_REUSEADDR) < 0 + || BIO_set_accept_port(acbio, port) < 0) { + log_message(prog, LOG_ERR, "Error setting up accept BIO"); + goto err; + } + + BIO_set_accept_bios(acbio, bufbio); + bufbio = NULL; + if (BIO_do_accept(acbio) <= 0) { + log_message(prog, LOG_ERR, "Error starting accept"); + goto err; + } + + return acbio; + + err: + BIO_free_all(acbio); + BIO_free(bufbio); + return NULL; +} + +/* + * Decode %xx URL-decoding in-place. Ignores malformed sequences. + */ +static int urldecode(char *p) +{ + unsigned char *out = (unsigned char *)p; + unsigned char *save = out; + + for (; *p; p++) { + if (*p != '%') { + *out++ = *p; + } else if (isxdigit(_UC(p[1])) && isxdigit(_UC(p[2]))) { + /* Don't check, can't fail because of ixdigit() call. */ + *out++ = (OPENSSL_hexchar2int(p[1]) << 4) + | OPENSSL_hexchar2int(p[2]); + p += 2; + } else { + return -1; + } + } + *out = '\0'; + return (int)(out - save); +} + +int http_server_get_asn1_req(const ASN1_ITEM *it, ASN1_VALUE **preq, + BIO **pcbio, BIO *acbio, + const char *prog, int accept_get, int timeout) +{ + BIO *cbio = NULL, *getbio = NULL, *b64 = NULL; + int len; + char reqbuf[2048], inbuf[2048]; + char *url, *end; + ASN1_VALUE *req; + int ret = 1; + + *preq = NULL; + *pcbio = NULL; + + /* Connection loss before accept() is routine, ignore silently */ + if (BIO_do_accept(acbio) <= 0) + return 0; + + cbio = BIO_pop(acbio); + *pcbio = cbio; + if (cbio == NULL) { + ret = -1; + goto out; + } + +# ifdef HTTP_DAEMON + if (timeout > 0) { + (void)BIO_get_fd(cbio, &acfd); + alarm(timeout); + } +# endif + + /* Read the request line. */ + len = BIO_gets(cbio, reqbuf, sizeof(reqbuf)); + if (len <= 0) + goto out; + + if (accept_get && strncmp(reqbuf, "GET ", 4) == 0) { + /* Expecting GET {sp} /URL {sp} HTTP/1.x */ + for (url = reqbuf + 4; *url == ' '; ++url) + continue; + if (*url != '/') { + log_message(prog, LOG_INFO, + "Invalid GET -- URL does not begin with '/': %s", url); + goto out; + } + url++; + + /* Splice off the HTTP version identifier. */ + for (end = url; *end != '\0'; end++) + if (*end == ' ') + break; + if (strncmp(end, " HTTP/1.", 7) != 0) { + log_message(prog, LOG_INFO, + "Invalid GET -- bad HTTP/version string: %s", end + 1); + goto out; + } + *end = '\0'; + + /*- + * Skip "GET / HTTP..." requests often used by load-balancers. + * 'url' was incremented above to point to the first byte *after* + * the leading slash, so in case 'GET / ' it is now an empty string. + */ + if (url[0] == '\0') + goto out; + + len = urldecode(url); + if (len <= 0) { + log_message(prog, LOG_INFO, + "Invalid GET request -- bad URL encoding: %s", url); + goto out; + } + if ((getbio = BIO_new_mem_buf(url, len)) == NULL + || (b64 = BIO_new(BIO_f_base64())) == NULL) { + log_message(prog, LOG_ERR, + "Could not allocate base64 bio with size = %d", len); + BIO_free_all(cbio); + *pcbio = NULL; + ret = -1; + goto out; + } + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + getbio = BIO_push(b64, getbio); + } else if (strncmp(reqbuf, "POST ", 5) != 0) { + log_message(prog, LOG_INFO, + "HTTP request does not start with GET/POST: %s", reqbuf); + /* TODO provide better diagnosis in case client tries TLS */ + goto out; + } + + /* Read and skip past the headers. */ + for (;;) { + len = BIO_gets(cbio, inbuf, sizeof(inbuf)); + if (len <= 0) { + log_message(prog, LOG_ERR, + "Error skipping remaining HTTP headers"); + goto out; + } + if ((inbuf[0] == '\r') || (inbuf[0] == '\n')) + break; + } + +# ifdef HTTP_DAEMON + /* Clear alarm before we close the client socket */ + alarm(0); + timeout = 0; +# endif + + /* Try to read and parse request */ + req = ASN1_item_d2i_bio(it, getbio != NULL ? getbio : cbio, NULL); + if (req == NULL) + log_message(prog, LOG_ERR, "Error parsing request"); + + *preq = req; + + out: + BIO_free_all(getbio); +# ifdef HTTP_DAEMON + if (timeout > 0) + alarm(0); + acfd = (int)INVALID_SOCKET; +# endif + return ret; +} + +/* assumes that cbio does not do an encoding that changes the output length */ +int http_server_send_asn1_resp(BIO *cbio, const char *content_type, + const ASN1_ITEM *it, const ASN1_VALUE *resp) +{ + int ret = BIO_printf(cbio, "HTTP/1.0 200 OK\r\nContent-type: %s\r\n" + "Content-Length: %d\r\n\r\n", content_type, + ASN1_item_i2d(resp, NULL, it)) > 0 + && ASN1_item_i2d_bio(it, cbio, resp) > 0; + + (void)BIO_flush(cbio); + return ret; +} +#endif diff --git a/apps/lib/names.c b/apps/lib/names.c index 09ee16fd..42b9e906 100644 --- a/apps/lib/names.c +++ b/apps/lib/names.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,6 +12,8 @@ #include #include "names.h" +DEFINE_STACK_OF_CSTRING() + #ifdef _WIN32 # define strcasecmp _stricmp #endif diff --git a/apps/lib/s_cb.c b/apps/lib/s_cb.c index 16ce65d4..34bc4a99 100644 --- a/apps/lib/s_cb.c +++ b/apps/lib/s_cb.c @@ -26,6 +26,11 @@ #define COOKIE_SECRET_LENGTH 16 +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(X509_NAME) +DEFINE_STACK_OF_STRING() + VERIFY_CB_ARGS verify_args = { -1, 0, X509_V_OK, 0 }; #ifndef OPENSSL_NO_SOCK @@ -1089,11 +1094,11 @@ int args_excert(int opt, SSL_EXCERT **pexc) exc->build_chain = 1; break; case OPT_X_CERTFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &exc->certform)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &exc->certform)) return 0; break; case OPT_X_KEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &exc->keyform)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &exc->keyform)) return 0; break; } diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c index 7dd95e9f..b9baef91 100644 --- a/apps/lib/s_socket.c +++ b/apps/lib/s_socket.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -392,4 +392,25 @@ int do_server(int *accept_sock, const char *host, const char *port, return ret; } +void do_ssl_shutdown(SSL *ssl) +{ + int ret; + + do { + /* We only do unidirectional shutdown */ + ret = SSL_shutdown(ssl); + if (ret < 0) { + switch (SSL_get_error(ssl, ret)) { + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_ASYNC: + case SSL_ERROR_WANT_ASYNC_JOB: + /* We just do busy waiting. Nothing clever */ + continue; + } + ret = 0; + } + } while (ret < 0); +} + #endif /* OPENSSL_NO_SOCK */ diff --git a/apps/list.c b/apps/list.c index b30632a6..a28f6b67 100644 --- a/apps/list.c +++ b/apps/list.c @@ -19,6 +19,8 @@ #include "opt.h" #include "names.h" +DEFINE_STACK_OF_CSTRING() + static int verbose = 0; static void legacy_cipher_fn(const EVP_CIPHER *c, diff --git a/apps/mac.c b/apps/mac.c index 6e322fd2..30f0daab 100644 --- a/apps/mac.c +++ b/apps/mac.c @@ -1,7 +1,7 @@ /* * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -16,6 +16,8 @@ #include #include +DEFINE_STACK_OF_STRING() + #undef BUFSIZE #define BUFSIZE 1024*8 diff --git a/apps/nseq.c b/apps/nseq.c index 92ae7bd3..de189632 100644 --- a/apps/nseq.c +++ b/apps/nseq.c @@ -14,6 +14,8 @@ #include #include +DEFINE_STACK_OF(X509) + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_TOSEQ, OPT_IN, OPT_OUT, diff --git a/apps/ocsp.c b/apps/ocsp.c index 7bd1765b..fd03611f 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -22,6 +22,7 @@ /* Needs to be included before the openssl headers */ #include "apps.h" +#include "http_server.h" #include "progs.h" #include "internal/sockets.h" #include @@ -31,38 +32,11 @@ #include #include #include -#include -#ifndef HAVE_FORK -# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) -# define HAVE_FORK 0 -# else -# define HAVE_FORK 1 -# endif -#endif - -#if HAVE_FORK -# undef NO_FORK -#else -# define NO_FORK -#endif - -#if !defined(NO_FORK) && !defined(OPENSSL_NO_SOCK) \ - && !defined(OPENSSL_NO_POSIX_IO) -# define OCSP_DAEMON -# include -# include -# include -# include -# define MAXERRLEN 1000 /* limit error text sent to syslog to 1000 bytes */ -#else -# undef LOG_INFO -# undef LOG_WARNING -# undef LOG_ERR -# define LOG_INFO 0 -# define LOG_WARNING 1 -# define LOG_ERR 2 -#endif +DEFINE_STACK_OF(OCSP_CERTID) +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF_STRING() #if defined(OPENSSL_SYS_VXWORKS) /* not supported */ @@ -100,19 +74,13 @@ static void make_ocsp_response(BIO *err, OCSP_RESPONSE **resp, OCSP_REQUEST *req const EVP_MD *resp_md); static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser); -static BIO *init_responder(const char *port); -static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, int timeout); -static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp); -static void log_message(int level, const char *fmt, ...); +static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, + int timeout); +static int send_ocsp_response(BIO *cbio, const OCSP_RESPONSE *resp); static char *prog; -static int multi = 0; -#ifdef OCSP_DAEMON -static int acfd = (int) INVALID_SOCKET; +#ifdef HTTP_DAEMON static int index_changed(CA_DB *); -static void spawn_loop(void); -static int print_syslog(const char *str, size_t len, void *levPtr); -static void socket_timeout(int signum); #endif typedef enum OPTION_choice { @@ -157,7 +125,7 @@ const OPTIONS ocsp_options[] = { "Connection timeout (in seconds) to the OCSP responder"}, {"resp_no_certs", OPT_RESP_NO_CERTS, '-', "Don't include any certificates in response"}, -#ifdef OCSP_DAEMON +#ifdef HTTP_DAEMON {"multi", OPT_MULTI, 'p', "run multiple responder processes"}, #endif {"no_certs", OPT_NO_CERTS, '-', @@ -436,7 +404,8 @@ int ocsp_main(int argc, char **argv) path = opt_arg(); break; case OPT_ISSUER: - issuer = load_cert(opt_arg(), FORMAT_PEM, "issuer certificate"); + issuer = load_cert(opt_arg(), FORMAT_UNDEF, + "issuer certificate"); if (issuer == NULL) goto end; if (issuers == NULL) { @@ -448,7 +417,7 @@ int ocsp_main(int argc, char **argv) break; case OPT_CERT: X509_free(cert); - cert = load_cert(opt_arg(), FORMAT_PEM, "certificate"); + cert = load_cert(opt_arg(), FORMAT_UNDEF, "certificate"); if (cert == NULL) goto end; if (cert_id_md == NULL) @@ -535,7 +504,7 @@ int ocsp_main(int argc, char **argv) trailing_md = 1; break; case OPT_MULTI: -#ifdef OCSP_DAEMON +#ifdef HTTP_DAEMON multi = atoi(opt_arg()); #endif break; @@ -579,15 +548,21 @@ int ocsp_main(int argc, char **argv) } if (req == NULL && port != NULL) { - acbio = init_responder(port); +#ifndef OPENSSL_NO_SOCK + acbio = http_server_init_bio(prog, port); if (acbio == NULL) goto end; +#else + BIO_printf(bio_err, "Cannot act as server - sockets not supported\n"); + goto end; +#endif } if (rsignfile != NULL) { if (rkeyfile == NULL) rkeyfile = rsignfile; - rsigner = load_cert(rsignfile, FORMAT_PEM, "responder certificate"); + rsigner = load_cert(rsignfile, FORMAT_UNDEF, + "responder certificate"); if (rsigner == NULL) { BIO_printf(bio_err, "Error loading responder certificate\n"); goto end; @@ -625,20 +600,20 @@ int ocsp_main(int argc, char **argv) } } -#ifdef OCSP_DAEMON +#ifdef HTTP_DAEMON if (multi && acbio != NULL) - spawn_loop(); + spawn_loop(prog); if (acbio != NULL && req_timeout > 0) signal(SIGALRM, socket_timeout); #endif if (acbio != NULL) - log_message(LOG_INFO, "waiting for OCSP client connections..."); + log_message(prog, LOG_INFO, "waiting for OCSP client connections..."); redo_accept: if (acbio != NULL) { -#ifdef OCSP_DAEMON +#ifdef HTTP_DAEMON if (index_changed(rdb)) { CA_DB *newrdb = load_index(ridx_filename, NULL); @@ -647,7 +622,7 @@ redo_accept: rdb = newrdb; } else { free_index(newrdb); - log_message(LOG_ERR, "error reloading updated index: %s", + log_message(prog, LOG_ERR, "error reloading updated index: %s", ridx_filename); } } @@ -658,9 +633,8 @@ redo_accept: goto redo_accept; if (req == NULL) { - resp = - OCSP_response_create(OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, - NULL); + resp = OCSP_response_create(OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, + NULL); send_ocsp_response(cbio, resp); goto done_resp; } @@ -681,7 +655,7 @@ redo_accept: if (signfile != NULL) { if (keyfile == NULL) keyfile = signfile; - signer = load_cert(signfile, FORMAT_PEM, "signer certificate"); + signer = load_cert(signfile, FORMAT_UNDEF, "signer certificate"); if (signer == NULL) { BIO_printf(bio_err, "Error loading signer certificate\n"); goto end; @@ -728,7 +702,7 @@ redo_accept: goto end; #else BIO_printf(bio_err, - "Error creating connect BIO - sockets not supported.\n"); + "Error creating connect BIO - sockets not supported\n"); goto end; #endif } else if (respin != NULL) { @@ -868,41 +842,7 @@ redo_accept: return ret; } -static void -log_message(int level, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); -#ifdef OCSP_DAEMON - if (multi) { - char buf[1024]; - if (vsnprintf(buf, sizeof(buf), fmt, ap) > 0) { - syslog(level, "%s", buf); - } - if (level >= LOG_ERR) - ERR_print_errors_cb(print_syslog, &level); - } -#endif - if (!multi) { - BIO_printf(bio_err, "%s: ", prog); - BIO_vprintf(bio_err, fmt, ap); - BIO_printf(bio_err, "\n"); - } - va_end(ap); -} - -#ifdef OCSP_DAEMON - -static int print_syslog(const char *str, size_t len, void *levPtr) -{ - int level = *(int *)levPtr; - int ilen = (len > MAXERRLEN) ? MAXERRLEN : len; - - syslog(level, "%.*s", ilen, str); - - return ilen; -} +#ifdef HTTP_DAEMON static int index_changed(CA_DB *rdb) { @@ -920,131 +860,6 @@ static int index_changed(CA_DB *rdb) return 0; } -static void killall(int ret, pid_t *kidpids) -{ - int i; - - for (i = 0; i < multi; ++i) - if (kidpids[i] != 0) - (void)kill(kidpids[i], SIGTERM); - OPENSSL_free(kidpids); - sleep(1); - exit(ret); -} - -static int termsig = 0; - -static void noteterm (int sig) -{ - termsig = sig; -} - -/* - * Loop spawning up to `multi` child processes, only child processes return - * from this function. The parent process loops until receiving a termination - * signal, kills extant children and exits without returning. - */ -static void spawn_loop(void) -{ - pid_t *kidpids = NULL; - int status; - int procs = 0; - int i; - - openlog(prog, LOG_PID, LOG_DAEMON); - - if (setpgid(0, 0)) { - syslog(LOG_ERR, "fatal: error detaching from parent process group: %s", - strerror(errno)); - exit(1); - } - kidpids = app_malloc(multi * sizeof(*kidpids), "child PID array"); - for (i = 0; i < multi; ++i) - kidpids[i] = 0; - - signal(SIGINT, noteterm); - signal(SIGTERM, noteterm); - - while (termsig == 0) { - pid_t fpid; - - /* - * Wait for a child to replace when we're at the limit. - * Slow down if a child exited abnormally or waitpid() < 0 - */ - while (termsig == 0 && procs >= multi) { - if ((fpid = waitpid(-1, &status, 0)) > 0) { - for (i = 0; i < procs; ++i) { - if (kidpids[i] == fpid) { - kidpids[i] = 0; - --procs; - break; - } - } - if (i >= multi) { - syslog(LOG_ERR, "fatal: internal error: " - "no matching child slot for pid: %ld", - (long) fpid); - killall(1, kidpids); - } - if (status != 0) { - if (WIFEXITED(status)) - syslog(LOG_WARNING, "child process: %ld, exit status: %d", - (long)fpid, WEXITSTATUS(status)); - else if (WIFSIGNALED(status)) - syslog(LOG_WARNING, "child process: %ld, term signal %d%s", - (long)fpid, WTERMSIG(status), -#ifdef WCOREDUMP - WCOREDUMP(status) ? " (core dumped)" : -#endif - ""); - sleep(1); - } - break; - } else if (errno != EINTR) { - syslog(LOG_ERR, "fatal: waitpid(): %s", strerror(errno)); - killall(1, kidpids); - } - } - if (termsig) - break; - - switch(fpid = fork()) { - case -1: /* error */ - /* System critically low on memory, pause and try again later */ - sleep(30); - break; - case 0: /* child */ - OPENSSL_free(kidpids); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - if (termsig) - _exit(0); - if (RAND_poll() <= 0) { - syslog(LOG_ERR, "fatal: RAND_poll() failed"); - _exit(1); - } - return; - default: /* parent */ - for (i = 0; i < multi; ++i) { - if (kidpids[i] == 0) { - kidpids[i] = fpid; - procs++; - break; - } - } - if (i >= multi) { - syslog(LOG_ERR, "fatal: internal error: no free child slots"); - killall(1, kidpids); - } - break; - } - } - - /* The loop above can only break on termsig */ - syslog(LOG_INFO, "terminating on signal: %d", termsig); - killall(0, kidpids); -} #endif static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, @@ -1331,209 +1146,32 @@ static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser) return rrow; } -/* Quick and dirty OCSP server: read in and parse input request */ - -static BIO *init_responder(const char *port) -{ -#ifdef OPENSSL_NO_SOCK - BIO_printf(bio_err, - "Error setting up accept BIO - sockets not supported.\n"); - return NULL; -#else - BIO *acbio = NULL, *bufbio = NULL; - - bufbio = BIO_new(BIO_f_buffer()); - if (bufbio == NULL) - goto err; - acbio = BIO_new(BIO_s_accept()); - if (acbio == NULL - || BIO_set_bind_mode(acbio, BIO_BIND_REUSEADDR) < 0 - || BIO_set_accept_port(acbio, port) < 0) { - log_message(LOG_ERR, "Error setting up accept BIO"); - goto err; - } - - BIO_set_accept_bios(acbio, bufbio); - bufbio = NULL; - if (BIO_do_accept(acbio) <= 0) { - log_message(LOG_ERR, "Error starting accept"); - goto err; - } - - return acbio; - - err: - BIO_free_all(acbio); - BIO_free(bufbio); - return NULL; -#endif -} - -#ifndef OPENSSL_NO_SOCK -/* - * Decode %xx URL-decoding in-place. Ignores mal-formed sequences. - */ -static int urldecode(char *p) -{ - unsigned char *out = (unsigned char *)p; - unsigned char *save = out; - - for (; *p; p++) { - if (*p != '%') - *out++ = *p; - else if (isxdigit(_UC(p[1])) && isxdigit(_UC(p[2]))) { - /* Don't check, can't fail because of ixdigit() call. */ - *out++ = (OPENSSL_hexchar2int(p[1]) << 4) - | OPENSSL_hexchar2int(p[2]); - p += 2; - } - else - return -1; - } - *out = '\0'; - return (int)(out - save); -} -#endif - -#ifdef OCSP_DAEMON -static void socket_timeout(int signum) -{ - if (acfd != (int)INVALID_SOCKET) - (void)shutdown(acfd, SHUT_RD); -} -#endif - static int do_responder(OCSP_REQUEST **preq, BIO **pcbio, BIO *acbio, int timeout) { -#ifdef OPENSSL_NO_SOCK - return 0; +#ifndef OPENSSL_NO_SOCK + return http_server_get_asn1_req(ASN1_ITEM_rptr(OCSP_RESPONSE), + (ASN1_VALUE **)preq, pcbio, acbio, + prog, 1 /* accept_get */, timeout); #else - int len; - OCSP_REQUEST *req = NULL; - char inbuf[2048], reqbuf[2048]; - char *p, *q; - BIO *cbio = NULL, *getbio = NULL, *b64 = NULL; - const char *client; - + BIO_printf(bio_err, + "Error getting OCSP request - sockets not supported\n"); *preq = NULL; - - /* Connection loss before accept() is routine, ignore silently */ - if (BIO_do_accept(acbio) <= 0) - return 0; - - cbio = BIO_pop(acbio); - *pcbio = cbio; - client = BIO_get_peer_name(cbio); - -# ifdef OCSP_DAEMON - if (timeout > 0) { - (void) BIO_get_fd(cbio, &acfd); - alarm(timeout); - } -# endif - - /* Read the request line. */ - len = BIO_gets(cbio, reqbuf, sizeof(reqbuf)); - if (len <= 0) - goto out; - - if (strncmp(reqbuf, "GET ", 4) == 0) { - /* Expecting GET {sp} /URL {sp} HTTP/1.x */ - for (p = reqbuf + 4; *p == ' '; ++p) - continue; - if (*p != '/') { - log_message(LOG_INFO, "Invalid request -- bad URL: %s", client); - goto out; - } - p++; - - /* Splice off the HTTP version identifier. */ - for (q = p; *q; q++) - if (*q == ' ') - break; - if (strncmp(q, " HTTP/1.", 8) != 0) { - log_message(LOG_INFO, - "Invalid request -- bad HTTP version: %s", client); - goto out; - } - *q = '\0'; - - /* - * Skip "GET / HTTP..." requests often used by load-balancers. Note: - * 'p' was incremented above to point to the first byte *after* the - * leading slash, so with 'GET / ' it is now an empty string. - */ - if (p[0] == '\0') - goto out; - - len = urldecode(p); - if (len <= 0) { - log_message(LOG_INFO, - "Invalid request -- bad URL encoding: %s", client); - goto out; - } - if ((getbio = BIO_new_mem_buf(p, len)) == NULL - || (b64 = BIO_new(BIO_f_base64())) == NULL) { - log_message(LOG_ERR, "Could not allocate base64 bio: %s", client); - goto out; - } - BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); - getbio = BIO_push(b64, getbio); - } else if (strncmp(reqbuf, "POST ", 5) != 0) { - log_message(LOG_INFO, "Invalid request -- bad HTTP verb: %s", client); - goto out; - } - - /* Read and skip past the headers. */ - for (;;) { - len = BIO_gets(cbio, inbuf, sizeof(inbuf)); - if (len <= 0) - goto out; - if ((inbuf[0] == '\r') || (inbuf[0] == '\n')) - break; - } - -# ifdef OCSP_DAEMON - /* Clear alarm before we close the client socket */ - alarm(0); - timeout = 0; -# endif - - /* Try to read OCSP request */ - if (getbio != NULL) { - req = d2i_OCSP_REQUEST_bio(getbio, NULL); - BIO_free_all(getbio); - } else { - req = d2i_OCSP_REQUEST_bio(cbio, NULL); - } - - if (req == NULL) - log_message(LOG_ERR, "Error parsing OCSP request"); - - *preq = req; - -out: -# ifdef OCSP_DAEMON - if (timeout > 0) - alarm(0); - acfd = (int)INVALID_SOCKET; -# endif - return 1; + return 0; #endif } -static int send_ocsp_response(BIO *cbio, OCSP_RESPONSE *resp) +static int send_ocsp_response(BIO *cbio, const OCSP_RESPONSE *resp) { - char http_resp[] = - "HTTP/1.0 200 OK\r\nContent-type: application/ocsp-response\r\n" - "Content-Length: %d\r\n\r\n"; - if (cbio == NULL) - return 0; - BIO_printf(cbio, http_resp, i2d_OCSP_RESPONSE(resp, NULL)); - i2d_OCSP_RESPONSE_bio(cbio, resp); - (void)BIO_flush(cbio); - return 1; +#ifndef OPENSSL_NO_SOCK + return http_server_send_asn1_resp(cbio, "application/ocsp-response", + ASN1_ITEM_rptr(OCSP_RESPONSE), + (const ASN1_VALUE *)resp); +#else + BIO_printf(bio_err, + "Error sending OCSP response - sockets not supported\n"); + return 0; +#endif } #ifndef OPENSSL_NO_SOCK diff --git a/apps/openssl-vms.cnf b/apps/openssl-vms.cnf index e64cc9f3..c7e7abe9 100644 --- a/apps/openssl-vms.cnf +++ b/apps/openssl-vms.cnf @@ -348,3 +348,59 @@ ess_cert_id_chain = no # Must the ESS cert id chain be included? # (optional, default: no) ess_cert_id_alg = sha1 # algorithm to compute certificate # identifier (optional, default: sha1) + +[insta] # CMP using Insta Demo CA +# Message transfer +server = pki.certificate.fi:8700 +# proxy = # set this as far as needed, e.g., http://192.168.1.1:8080 +# tls_use = 0 +path = pkix/ + +# Server authentication +recipient = "/C=FI/O=Insta Demo/CN=Insta Demo CA" # or set srvcert or issuer +ignore_keyusage = 1 # potentially needed quirk +unprotected_errors = 1 # potentially needed quirk +extracertsout = insta.extracerts.pem + +# Client authentication +ref = 3078 # user identification +secret = pass:insta # can be used for both client and server side + +# Generic message options +cmd = ir # default operation, can be overridden on cmd line with, e.g., kur + +# Certificate enrollment +subject = "/CN=openssl-cmp-test" +newkey = insta.priv.pem +out_trusted = insta.ca.crt +certout = insta.cert.pem + +[pbm] # Password-based protection for Insta CA +# Server and client authentication +ref = $insta::ref # 3078 +secret = $insta::secret # pass:insta + +[signature] # Signature-based protection for Insta CA +# Server authentication +trusted = insta.ca.crt # does not include keyUsage digitalSignature + +# Client authentication +secret = # disable PBM +key = $insta::newkey # insta.priv.pem +cert = $insta::certout # insta.cert.pem + +[ir] +cmd = ir + +[cr] +cmd = cr + +[kur] +# Certificate update +cmd = kur +oldcert = $insta::certout # insta.cert.pem + +[rr] +# Certificate revocation +cmd = rr +oldcert = $insta::certout # insta.cert.pem diff --git a/apps/openssl.cnf b/apps/openssl.cnf index 4acca4b0..52706ae1 100644 --- a/apps/openssl.cnf +++ b/apps/openssl.cnf @@ -348,3 +348,59 @@ ess_cert_id_chain = no # Must the ESS cert id chain be included? # (optional, default: no) ess_cert_id_alg = sha1 # algorithm to compute certificate # identifier (optional, default: sha1) + +[insta] # CMP using Insta Demo CA +# Message transfer +server = pki.certificate.fi:8700 +# proxy = # set this as far as needed, e.g., http://192.168.1.1:8080 +# tls_use = 0 +path = pkix/ + +# Server authentication +recipient = "/C=FI/O=Insta Demo/CN=Insta Demo CA" # or set srvcert or issuer +ignore_keyusage = 1 # potentially needed quirk +unprotected_errors = 1 # potentially needed quirk +extracertsout = insta.extracerts.pem + +# Client authentication +ref = 3078 # user identification +secret = pass:insta # can be used for both client and server side + +# Generic message options +cmd = ir # default operation, can be overridden on cmd line with, e.g., kur + +# Certificate enrollment +subject = "/CN=openssl-cmp-test" +newkey = insta.priv.pem +out_trusted = insta.ca.crt +certout = insta.cert.pem + +[pbm] # Password-based protection for Insta CA +# Server and client authentication +ref = $insta::ref # 3078 +secret = $insta::secret # pass:insta + +[signature] # Signature-based protection for Insta CA +# Server authentication +trusted = insta.ca.crt # does not include keyUsage digitalSignature + +# Client authentication +secret = # disable PBM +key = $insta::newkey # insta.priv.pem +cert = $insta::certout # insta.cert.pem + +[ir] +cmd = ir + +[cr] +cmd = cr + +[kur] +# Certificate update +cmd = kur +oldcert = $insta::certout # insta.cert.pem + +[rr] +# Certificate revocation +cmd = rr +oldcert = $insta::certout # insta.cert.pem diff --git a/apps/pkcs12.c b/apps/pkcs12.c index 69bbe94c..18f9550d 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -19,6 +19,12 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(PKCS7) +DEFINE_STACK_OF(PKCS12_SAFEBAG) +DEFINE_STACK_OF(X509_ATTRIBUTE) +DEFINE_STACK_OF_STRING() + #define NOKEYS 0x1 #define NOCERTS 0x2 #define INFO 0x4 diff --git a/apps/pkcs7.c b/apps/pkcs7.c index dba9751e..2416584d 100644 --- a/apps/pkcs7.c +++ b/apps/pkcs7.c @@ -20,6 +20,9 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_INFORM, OPT_OUTFORM, OPT_IN, OPT_OUT, OPT_NOOUT, diff --git a/apps/pkey.c b/apps/pkey.c index ec681856..8aafcb42 100644 --- a/apps/pkey.c +++ b/apps/pkey.c @@ -57,7 +57,7 @@ const OPTIONS pkey_options[] = { OPT_SECTION("Input"), {"in", OPT_IN, 's', "Input key"}, - {"inform", OPT_INFORM, 'f', "Input format (DER or PEM)"}, + {"inform", OPT_INFORM, 'f', "Input format (DER/PEM/P12/ENGINE)"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, {"pubin", OPT_PUBIN, '-', "Read public key from input (default is private key)"}, diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c index 34251d5a..231547e2 100644 --- a/apps/pkeyutl.c +++ b/apps/pkeyutl.c @@ -15,6 +15,8 @@ #include #include +DEFINE_STACK_OF_STRING() + #define KEY_NONE 0 #define KEY_PRIVKEY 1 #define KEY_PUBKEY 2 @@ -69,11 +71,11 @@ const OPTIONS pkeyutl_options[] = { {"inkey", OPT_INKEY, 's', "Input private key file"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, {"peerkey", OPT_PEERKEY, 's', "Peer key file used in key derivation"}, - {"peerform", OPT_PEERFORM, 'E', "Peer key format - default PEM"}, + {"peerform", OPT_PEERFORM, 'E', "Peer key format (DER/PEM/P12/ENGINE)"}, {"certin", OPT_CERTIN, '-', "Input is a cert with a public key"}, {"rev", OPT_REV, '-', "Reverse the order of the input buffer"}, {"sigfile", OPT_SIGFILE, '<', "Signature file (verify operation only)"}, - {"keyform", OPT_KEYFORM, 'E', "Private key format - default PEM"}, + {"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"}, OPT_SECTION("Output"), {"out", OPT_OUT, '>', "Output file - default stdout"}, @@ -155,11 +157,11 @@ int pkeyutl_main(int argc, char **argv) passinarg = opt_arg(); break; case OPT_PEERFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &peerform)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &peerform)) goto opthelp; break; case OPT_KEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyform)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyform)) goto opthelp; break; case OPT_R_CASES: @@ -517,7 +519,7 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize, break; case KEY_CERT: - x = load_cert(keyfile, keyform, "Certificate"); + x = load_cert(keyfile, FORMAT_UNDEF, "Certificate"); if (x) { pkey = X509_get_pubkey(x); X509_free(x); diff --git a/apps/provider.c b/apps/provider.c index 87231cd2..d1a1ce7e 100644 --- a/apps/provider.c +++ b/apps/provider.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,6 +20,8 @@ #include #include +DEFINE_STACK_OF_CSTRING() + typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_V = 100, OPT_VV, OPT_VVV diff --git a/apps/rehash.c b/apps/rehash.c index e21b1b84..866b8cfe 100644 --- a/apps/rehash.c +++ b/apps/rehash.c @@ -42,6 +42,8 @@ # include # include +DEFINE_STACK_OF(X509_INFO) +DEFINE_STACK_OF_STRING() # ifndef PATH_MAX # define PATH_MAX 4096 diff --git a/apps/req.c b/apps/req.c index 848c8d4f..a2212b98 100644 --- a/apps/req.c +++ b/apps/req.c @@ -32,6 +32,8 @@ # include #endif +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF_STRING() #define BITS "default_bits" #define KEYFILE "default_keyfile" @@ -135,7 +137,7 @@ const OPTIONS req_options[] = { OPT_SECTION("Keys and Signing"), {"key", OPT_KEY, 's', "Private key to use"}, - {"keyform", OPT_KEYFORM, 'f', "Key file format"}, + {"keyform", OPT_KEYFORM, 'f', "Key file format (ENGINE, other values ignored)"}, {"pubkey", OPT_PUBKEY, '-', "Output public key"}, {"keyout", OPT_KEYOUT, '>', "File to send the key to"}, {"passin", OPT_PASSIN, 's', "Private key password source"}, diff --git a/apps/rsa.c b/apps/rsa.c index bb9bcb0b..9f91b72d 100644 --- a/apps/rsa.c +++ b/apps/rsa.c @@ -45,7 +45,7 @@ const OPTIONS rsa_options[] = { OPT_SECTION("Input"), {"in", OPT_IN, 's', "Input file"}, - {"inform", OPT_INFORM, 'f', "Input format, one of DER PEM"}, + {"inform", OPT_INFORM, 'f', "Input format (DER/PEM/P12/ENGINE"}, {"pubin", OPT_PUBIN, '-', "Expect a public key in input file"}, {"RSAPublicKey_in", OPT_RSAPUBKEY_IN, '-', "Input is an RSAPublicKey"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, diff --git a/apps/rsa8192.pem b/apps/rsa8192.pem index 946a6e54..83d962f4 100644 --- a/apps/rsa8192.pem +++ b/apps/rsa8192.pem @@ -1,5 +1,4 @@ -----BEGIN RSA PRIVATE KEY----- - MIISKAIBAAKCBAEAiQ2f1X6Bte1DKD0OoCBKEikzPW+5w3oXk3WwnE97Wxzy6wJZ ebbZC3CZKKBnJeBMrysPf+lK+9+fP6Vm8bp1wvbcSIA59BDrX6irFSuM/bdnkbuF MFlDjt+uVrxwoyqfPi2IPot1HQg3l5mdyBqcTWvbOnU2L9HZxJfPUCjfzdTMPrMY @@ -62,7 +61,7 @@ JH1/Qx7C/mTAMRsN5SkOthnGq0djCNWfPv/3JV0H67Uf5krFlnwLebrgfTYoPPdo yO7iBUNJzv6Qh22malLp4P8gzACkD7DGlSTnoB5cLwcjmDGg+i9WrUBbOiVTeQfZ kOj1o+Tz35ndpq/DDUVlqliB9krcxva+QHeJPH53EGI+YVg1nD+s/vUDZ3mQMGX9 DQou2L8uU6RnWNv/BihGcL8QvS4Ty6QyPOUPpD3zc70JQAEcQk9BxQNaELgJX0IN -22cYn22tYvElew9G41OpDqzBRcfbdJmKXQ2HcroShutYJQRGUpAXHk24fy6JVkIU +2cYUn22tYvElew9G41OpDqzBRcfbdJmKXQ2HcroShutYJQRGUpAXHk24fy6JVkIU ojF5U6cwextMja1ZIIZgh9eugIRUeIE7319nQNDzuXWjRCcoBLA25P7wnpHWDRpz D9ovXCIvdja74lL5psqobV6L5+fbLPkSgXoImKR0LQKCAgAIC9Jk8kxumCyIVGCP PeM5Uby9M3GMuKrfYsn0Y5e97+kSJF1dpojTodBgR2KQar6eVrvXt+8uZCcIjfx8 @@ -98,4 +97,3 @@ TwEgE67iOb2iIoUpon/NyP4LesMzvdpsu2JFlfz13PmmQ34mFI7tWvOb3NA5DP3c rMlMLtKfp2w8HlMZpsUlToNCx6CI+tJrohzcs3BAVAbjFAXRKWGijB1rxwyDdHPv I+/wJTNaRNPQ1M0SwtEL/zJd21y3KSPn4eL+GP3efhlDSjtlDvZqkdAUsU8= -----END RSA PRIVATE KEY----- - diff --git a/apps/rsautl.c b/apps/rsautl.c index b5ebc883..c5bc6c15 100644 --- a/apps/rsautl.c +++ b/apps/rsautl.c @@ -48,7 +48,7 @@ const OPTIONS rsautl_options[] = { OPT_SECTION("Input"), {"in", OPT_IN, '<', "Input file"}, {"inkey", OPT_INKEY, 's', "Input key"}, - {"keyform", OPT_KEYFORM, 'E', "Private key format - default PEM"}, + {"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"}, {"pubin", OPT_PUBIN, '-', "Input is an RSA public"}, {"certin", OPT_CERTIN, '-', "Input is a cert carrying an RSA public key"}, {"rev", OPT_REV, '-', "Reverse the order of the input buffer"}, @@ -98,7 +98,7 @@ int rsautl_main(int argc, char **argv) ret = 0; goto end; case OPT_KEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyformat)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat)) goto opthelp; break; case OPT_IN: @@ -194,7 +194,7 @@ int rsautl_main(int argc, char **argv) break; case KEY_CERT: - x = load_cert(keyfile, keyformat, "Certificate"); + x = load_cert(keyfile, FORMAT_UNDEF, "Certificate"); if (x) { pkey = X509_get_pubkey(x); X509_free(x); diff --git a/apps/s_client.c b/apps/s_client.c index 0fdd85ce..8bab4e28 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -56,6 +56,12 @@ typedef unsigned int u_int; # endif #endif +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(X509_NAME) +DEFINE_STACK_OF(SCT) +DEFINE_STACK_OF_STRING() + #undef BUFSIZZ #define BUFSIZZ 1024*8 #define S_CLIENT_IRC_READ_TIMEOUT 8 @@ -92,27 +98,6 @@ static int restore_errno(void) return ret; } -static void do_ssl_shutdown(SSL *ssl) -{ - int ret; - - do { - /* We only do unidirectional shutdown */ - ret = SSL_shutdown(ssl); - if (ret < 0) { - switch (SSL_get_error(ssl, ret)) { - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - case SSL_ERROR_WANT_ASYNC: - case SSL_ERROR_WANT_ASYNC_JOB: - /* We just do busy waiting. Nothing clever */ - continue; - } - ret = 0; - } - } while (ret < 0); -} - /* Default PSK identity and key */ static char *psk_identity = "Client_identity"; @@ -651,12 +636,12 @@ const OPTIONS s_client_options[] = { OPT_SECTION("Identity"), {"cert", OPT_CERT, '<', "Client certificate file to use"}, {"certform", OPT_CERTFORM, 'F', - "Client certificate file format (PEM or DER) PEM default"}, + "Client certificate file format (PEM/DER/P12); has no effect"}, {"cert_chain", OPT_CERT_CHAIN, '<', "Client certificate chain file (in PEM format)"}, {"build_chain", OPT_BUILD_CHAIN, '-', "Build client certificate chain"}, {"key", OPT_KEY, 's', "Private key file to use; default is: -cert file"}, - {"keyform", OPT_KEYFORM, 'E', "Key format (PEM, DER or engine) PEM default"}, + {"keyform", OPT_KEYFORM, 'E', "Key format (ENGINE, other values ignored)"}, {"pass", OPT_PASS, 's', "Private key file pass phrase source"}, {"verify", OPT_VERIFY, 'p', "Turn on peer certificate verification"}, {"nameopt", OPT_NAMEOPT, 's', "Certificate subject/issuer name printing options"}, @@ -1159,7 +1144,7 @@ int s_client_main(int argc, char **argv) sess_in = opt_arg(); break; case OPT_CERTFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &cert_format)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &cert_format)) goto opthelp; break; case OPT_CRLFORM: @@ -1393,7 +1378,7 @@ int s_client_main(int argc, char **argv) fallback_scsv = 1; break; case OPT_KEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &key_format)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &key_format)) goto opthelp; break; case OPT_PASS: @@ -3152,8 +3137,7 @@ int s_client_main(int argc, char **argv) OPENSSL_clear_free(cbuf, BUFSIZZ); OPENSSL_clear_free(sbuf, BUFSIZZ); OPENSSL_clear_free(mbuf, BUFSIZZ); - if (proxypass != NULL) - OPENSSL_clear_free(proxypass, strlen(proxypass)); + clear_free(proxypass); release_engine(e); BIO_free(bio_c_out); bio_c_out = NULL; diff --git a/apps/s_server.c b/apps/s_server.c index a5e15920..09bcc0cf 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -60,6 +60,12 @@ typedef unsigned int u_int; #endif #include "internal/sockets.h" +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(SSL_CIPHER) +DEFINE_STACK_OF_STRING() + static int not_resumable_sess_cb(SSL *s, int is_forward_secure); static int sv_body(int s, int stype, int prot, unsigned char *context); static int www_body(int s, int stype, int prot, unsigned char *context); @@ -755,7 +761,7 @@ typedef enum OPTION_choice { OPT_SRTP_PROFILES, OPT_KEYMATEXPORT, OPT_KEYMATEXPORTLEN, OPT_KEYLOG_FILE, OPT_MAX_EARLY, OPT_RECV_MAX_EARLY, OPT_EARLY_DATA, OPT_S_NUM_TICKETS, OPT_ANTI_REPLAY, OPT_NO_ANTI_REPLAY, OPT_SCTP_LABEL_BUG, - OPT_HTTP_SERVER_BINMODE, + OPT_HTTP_SERVER_BINMODE, OPT_NOCANAMES, OPT_R_ENUM, OPT_S_ENUM, OPT_V_ENUM, @@ -807,7 +813,7 @@ const OPTIONS s_server_options[] = { {"cert2", OPT_CERT2, '<', "Certificate file to use for servername; default is" TEST_CERT2}, {"certform", OPT_CERTFORM, 'F', - "Server certificate file format (PEM or DER) PEM default"}, + "Server certificate file format (PEM/DER/P12); has no effect"}, {"cert_chain", OPT_CERT_CHAIN, '<', "Server certificate chain file in PEM format"}, {"build_chain", OPT_BUILD_CHAIN, '-', "Build server certificate chain"}, @@ -817,19 +823,18 @@ const OPTIONS s_server_options[] = { "Private key file to use; default is -cert file or else" TEST_CERT}, {"key2", OPT_KEY2, '<', "-Private Key file to use for servername if not in -cert2"}, - {"keyform", OPT_KEYFORM, 'f', - "Key format (PEM, DER or ENGINE) PEM default"}, + {"keyform", OPT_KEYFORM, 'f', "Key format (ENGINE, other values ignored)"}, {"pass", OPT_PASS, 's', "Private key file pass phrase source"}, {"dcert", OPT_DCERT, '<', "Second server certificate file to use (usually for DSA)"}, {"dcertform", OPT_DCERTFORM, 'F', - "Second server certificate file format (PEM or DER) PEM default"}, + "Second server certificate file format (PEM/DER/P12); has no effect"}, {"dcert_chain", OPT_DCERT_CHAIN, '<', "second server certificate chain file in PEM format"}, {"dkey", OPT_DKEY, '<', "Second private key file to use (usually for DSA)"}, {"dkeyform", OPT_DKEYFORM, 'F', - "Second key file format (PEM, DER or ENGINE) PEM default"}, + "Second key file format (ENGINE, other values ignored)"}, {"dpass", OPT_DPASS, 's', "Second private key file pass phrase source"}, {"dhparam", OPT_DHPARAM, '<', "DH parameters file to use"}, {"servername", OPT_SERVERNAME, 's', @@ -946,6 +951,8 @@ const OPTIONS s_server_options[] = { {"anti_replay", OPT_ANTI_REPLAY, '-', "Switch on anti-replay protection (default)"}, {"no_anti_replay", OPT_NO_ANTI_REPLAY, '-', "Switch off anti-replay protection"}, {"http_server_binmode", OPT_HTTP_SERVER_BINMODE, '-', "opening files in binary mode when acting as http server (-WWW and -HTTP)"}, + {"no_ca_names", OPT_NOCANAMES, '-', + "Disable TLS Extension CA Names"}, {"stateless", OPT_STATELESS, '-', "Require TLSv1.3 cookies"}, #ifndef OPENSSL_NO_SSL3 {"ssl3", OPT_SSL3, '-', "Just talk SSLv3"}, @@ -1083,6 +1090,7 @@ int s_server_main(int argc, char *argv[]) const char *keylog_file = NULL; int max_early_data = -1, recv_max_early_data = -1; char *psksessf = NULL; + int no_ca_names = 0; #ifndef OPENSSL_NO_SCTP int sctp_label_bug = 0; #endif @@ -1237,14 +1245,14 @@ int s_server_main(int argc, char *argv[]) s_serverinfo_file = opt_arg(); break; case OPT_CERTFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &s_cert_format)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_cert_format)) goto opthelp; break; case OPT_KEY: s_key_file = opt_arg(); break; case OPT_KEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &s_key_format)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_key_format)) goto opthelp; break; case OPT_PASS: @@ -1259,14 +1267,14 @@ int s_server_main(int argc, char *argv[]) #endif break; case OPT_DCERTFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &s_dcert_format)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_dcert_format)) goto opthelp; break; case OPT_DCERT: s_dcert_file = opt_arg(); break; case OPT_DKEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &s_dkey_format)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_dkey_format)) goto opthelp; break; case OPT_DPASS: @@ -1568,7 +1576,9 @@ int s_server_main(int argc, char *argv[]) session_id_prefix = opt_arg(); break; case OPT_ENGINE: - engine = setup_engine(opt_arg(), 1); +#ifndef OPENSSL_NO_ENGINE + engine = setup_engine(opt_arg(), s_debug); +#endif break; case OPT_R_CASES: if (!opt_rand(o)) @@ -1649,6 +1659,9 @@ int s_server_main(int argc, char *argv[]) case OPT_HTTP_SERVER_BINMODE: http_server_binmode = 1; break; + case OPT_NOCANAMES: + no_ca_names = 1; + break; case OPT_SENDFILE: #ifndef OPENSSL_NO_KTLS use_sendfile = 1; @@ -1878,7 +1891,6 @@ int s_server_main(int argc, char *argv[]) } BIO_printf(bio_err, "id_prefix '%s' set.\n", session_id_prefix); } - SSL_CTX_set_quiet_shutdown(ctx, 1); if (exc != NULL) ssl_ctx_set_excert(ctx, exc); @@ -1895,6 +1907,10 @@ int s_server_main(int argc, char *argv[]) SSL_CTX_set_mode(ctx, SSL_MODE_ASYNC); } + if (no_ca_names) { + SSL_CTX_set_options(ctx, SSL_OP_DISABLE_TLSEXT_CA_NAMES); + } + if (max_send_fragment > 0 && !SSL_CTX_set_max_send_fragment(ctx, max_send_fragment)) { BIO_printf(bio_err, "%s: Max send fragment size %u is out of permitted range\n", @@ -1976,7 +1992,6 @@ int s_server_main(int argc, char *argv[]) } BIO_printf(bio_err, "id_prefix '%s' set.\n", session_id_prefix); } - SSL_CTX_set_quiet_shutdown(ctx2, 1); if (exc != NULL) ssl_ctx_set_excert(ctx2, exc); @@ -2764,7 +2779,7 @@ static int sv_body(int s, int stype, int prot, unsigned char *context) err: if (con != NULL) { BIO_printf(bio_s_out, "shutting down SSL\n"); - SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); + do_ssl_shutdown(con); SSL_free(con); } BIO_printf(bio_s_out, "CONNECTION CLOSED\n"); @@ -3433,7 +3448,7 @@ static int www_body(int s, int stype, int prot, unsigned char *context) } end: /* make sure we re-use sessions */ - SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); + do_ssl_shutdown(con); err: OPENSSL_free(buf); @@ -3587,7 +3602,7 @@ static int rev_body(int s, int stype, int prot, unsigned char *context) } end: /* make sure we re-use sessions */ - SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); + do_ssl_shutdown(con); err: diff --git a/apps/smime.c b/apps/smime.c index 27fc7905..6b7d51b7 100644 --- a/apps/smime.c +++ b/apps/smime.c @@ -19,6 +19,9 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF_STRING() + static int save_certs(char *signerfile, STACK_OF(X509) *signers); static int smime_cb(int ok, X509_STORE_CTX *ctx); @@ -60,7 +63,7 @@ const OPTIONS smime_options[] = { "Output format SMIME (default), PEM or DER"}, {"inkey", OPT_INKEY, 's', "Input private key (if not signer or recipient)"}, - {"keyform", OPT_KEYFORM, 'f', "Input private key format (PEM or ENGINE)"}, + {"keyform", OPT_KEYFORM, 'f', "Input private key format (ENGINE, other values ignored)"}, #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, #endif @@ -426,7 +429,7 @@ int smime_main(int argc, char **argv) if (encerts == NULL) goto end; while (*argv != NULL) { - cert = load_cert(*argv, FORMAT_PEM, + cert = load_cert(*argv, FORMAT_UNDEF, "recipient certificate file"); if (cert == NULL) goto end; @@ -445,7 +448,7 @@ int smime_main(int argc, char **argv) } if (recipfile != NULL && (operation == SMIME_DECRYPT)) { - if ((recip = load_cert(recipfile, FORMAT_PEM, + if ((recip = load_cert(recipfile, FORMAT_UNDEF, "recipient certificate file")) == NULL) { ERR_print_errors(bio_err); goto end; @@ -545,7 +548,7 @@ int smime_main(int argc, char **argv) for (i = 0; i < sk_OPENSSL_STRING_num(sksigners); i++) { signerfile = sk_OPENSSL_STRING_value(sksigners, i); keyfile = sk_OPENSSL_STRING_value(skkeys, i); - signer = load_cert(signerfile, FORMAT_PEM, + signer = load_cert(signerfile, FORMAT_UNDEF, "signer certificate"); if (signer == NULL) goto end; diff --git a/apps/spkac.c b/apps/spkac.c index 03cc3d91..2b4009d4 100644 --- a/apps/spkac.c +++ b/apps/spkac.c @@ -40,7 +40,7 @@ const OPTIONS spkac_options[] = { OPT_SECTION("Input"), {"in", OPT_IN, '<', "Input file"}, {"key", OPT_KEY, '<', "Create SPKAC using private key"}, - {"keyform", OPT_KEYFORM, 'f', "Private key file format - default PEM (PEM, DER, or ENGINE)"}, + {"keyform", OPT_KEYFORM, 'f', "Private key file format (ENGINE, other values ignored)"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, {"challenge", OPT_CHALLENGE, 's', "Challenge string"}, {"spkac", OPT_SPKAC, 's', "Alternative SPKAC name"}, diff --git a/apps/verify.c b/apps/verify.c index 0e423ca8..e0eaaabe 100644 --- a/apps/verify.c +++ b/apps/verify.c @@ -18,6 +18,10 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF_STRING() + static int cb(int ok, X509_STORE_CTX *ctx); static int check(X509_STORE *ctx, const char *file, STACK_OF(X509) *uchain, STACK_OF(X509) *tchain, @@ -252,7 +256,7 @@ static int check(X509_STORE *ctx, const char *file, STACK_OF(X509) *chain = NULL; int num_untrusted; - x = load_cert(file, FORMAT_PEM, "certificate file"); + x = load_cert(file, FORMAT_UNDEF, "certificate file"); if (x == NULL) goto end; diff --git a/apps/x509.c b/apps/x509.c index 24e813cb..ea083abc 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -28,6 +28,10 @@ # include #endif +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF_STRING() + #undef POSTFIX #define POSTFIX ".srl" #define DEF_DAYS 30 @@ -74,13 +78,13 @@ const OPTIONS x509_options[] = { #endif {"inform", OPT_INFORM, 'f', - "Input format - default PEM (one of DER or PEM)"}, + "CSR input format (DER or PEM) - default PEM"}, {"in", OPT_IN, '<', "Input file - default stdin"}, {"passin", OPT_PASSIN, 's', "Private key password/pass-phrase source"}, {"outform", OPT_OUTFORM, 'f', - "Output format - default PEM (one of DER or PEM)"}, + "Output format (DER or PEM) - default PEM"}, {"out", OPT_OUT, '>', "Output file - default stdout"}, - {"keyform", OPT_KEYFORM, 'E', "Private key format - default PEM"}, + {"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"}, {"req", OPT_REQ, '-', "Input is a certificate request, sign and output"}, {"vfyopt", OPT_VFYOPT, 's', "Verification parameter in n:v form"}, @@ -148,8 +152,8 @@ const OPTIONS x509_options[] = { {"extfile", OPT_EXTFILE, '<', "File with X509V3 extensions to add"}, OPT_R_OPTIONS, OPT_PROV_OPTIONS, - {"CAform", OPT_CAFORM, 'F', "CA format - default PEM"}, - {"CAkeyform", OPT_CAKEYFORM, 'E', "CA key format - default PEM"}, + {"CAform", OPT_CAFORM, 'F', "CA cert format (PEM/DER/P12); has no effect"}, + {"CAkeyform", OPT_CAKEYFORM, 'E', "CA key format (ENGINE, other values ignored)"}, {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"}, {"CAcreateserial", OPT_CACREATESERIAL, '-', "Create serial number file if it does not exist"}, @@ -224,7 +228,7 @@ int x509_main(int argc, char **argv) ret = 0; goto end; case OPT_INFORM: - if (!opt_format(opt_arg(), OPT_FMT_ANY, &informat)) + if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat)) goto opthelp; break; case OPT_IN: @@ -235,15 +239,15 @@ int x509_main(int argc, char **argv) goto opthelp; break; case OPT_KEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyformat)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat)) goto opthelp; break; case OPT_CAFORM: - if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &CAformat)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &CAformat)) goto opthelp; break; case OPT_CAKEYFORM: - if (!opt_format(opt_arg(), OPT_FMT_PDE, &CAkeyformat)) + if (!opt_format(opt_arg(), OPT_FMT_ANY, &CAkeyformat)) goto opthelp; break; case OPT_OUT: @@ -627,7 +631,7 @@ int x509_main(int argc, char **argv) if (!X509_set_pubkey(x, fkey != NULL ? fkey : X509_REQ_get0_pubkey(req))) goto end; } else { - x = load_cert(infile, informat, "Certificate"); + x = load_cert(infile, FORMAT_UNDEF, "Certificate"); if (x == NULL) goto end; if (fkey != NULL && !X509_set_pubkey(x, fkey)) diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c index ab547397..b2be4612 100644 --- a/crypto/asn1/a_strnid.c +++ b/crypto/asn1/a_strnid.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,6 +12,8 @@ #include #include +DEFINE_STACK_OF(ASN1_STRING_TABLE) + static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; static void st_free(ASN1_STRING_TABLE *tbl); static int sk_table_cmp(const ASN1_STRING_TABLE *const *a, diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c index 7b50a0ce..9723da0a 100644 --- a/crypto/asn1/asn1_gen.c +++ b/crypto/asn1/asn1_gen.c @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -23,6 +23,9 @@ #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val} +DEFINE_STACK_OF(ASN1_TYPE) +DEFINE_STACK_OF(CONF_VALUE) + #define ASN1_FLAG_EXP_MAX 20 /* Maximum number of nested sequences */ #define ASN1_GEN_SEQ_MAX_DEPTH 50 diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index 1331f608..47ae801b 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -13,6 +13,8 @@ #include #include "asn1_local.h" +DEFINE_STACK_OF(ASN1_UTF8STRING) + static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, long max); static void asn1_put_length(unsigned char **pp, int length); diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 30da0298..4eb92d68 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -18,6 +18,9 @@ #include "internal/bio.h" #include "asn1_local.h" +DEFINE_STACK_OF(BIO) +DEFINE_STACK_OF(X509_ALGOR) + /* * Generalised MIME like utilities for streaming ASN1. Although many have a * PKCS7/CMS like flavour others are more general purpose. diff --git a/crypto/asn1/asn_moid.c b/crypto/asn1/asn_moid.c index 90f80760..676d1eca 100644 --- a/crypto/asn1/asn_moid.c +++ b/crypto/asn1/asn_moid.c @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,6 +16,8 @@ #include "crypto/asn1.h" #include "crypto/objects.h" +DEFINE_STACK_OF(CONF_VALUE) + /* Simple ASN1 OID module: add all objects in a given section */ static int do_create(const char *value, const char *name); diff --git a/crypto/asn1/asn_mstbl.c b/crypto/asn1/asn_mstbl.c index 3139ab07..fc21cb30 100644 --- a/crypto/asn1/asn_mstbl.c +++ b/crypto/asn1/asn_mstbl.c @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2012-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,6 +13,7 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) /* Multi string module: add table entries from a given section */ static int do_tcreate(const char *value, const char *name); diff --git a/crypto/asn1/d2i_pr.c b/crypto/asn1/d2i_pr.c index a4f3dd53..3ddc56d4 100644 --- a/crypto/asn1/d2i_pr.c +++ b/crypto/asn1/d2i_pr.c @@ -18,6 +18,7 @@ #include "crypto/asn1.h" #include "crypto/evp.h" +DEFINE_STACK_OF(ASN1_TYPE) EVP_PKEY *d2i_PrivateKey_ex(int type, EVP_PKEY **a, const unsigned char **pp, long length, OPENSSL_CTX *libctx, const char *propq) { @@ -57,6 +58,8 @@ EVP_PKEY *d2i_PrivateKey_ex(int type, EVP_PKEY **a, const unsigned char **pp, goto err; EVP_PKEY_free(ret); ret = tmp; + if (EVP_PKEY_type(type) != EVP_PKEY_base_id(ret)) + goto err; } else { ASN1err(0, ERR_R_ASN1_LIB); goto err; diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c index f720c602..379d1e6e 100644 --- a/crypto/asn1/tasn_dec.c +++ b/crypto/asn1/tasn_dec.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,7 @@ #include "internal/numbers.h" #include "asn1_local.h" +DEFINE_STACK_OF(ASN1_VALUE) /* * Constructed types with a recursive definition (such as can be found in PKCS7) diff --git a/crypto/asn1/tasn_fre.c b/crypto/asn1/tasn_fre.c index e8d57bda..9bd2099c 100644 --- a/crypto/asn1/tasn_fre.c +++ b/crypto/asn1/tasn_fre.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,6 +13,8 @@ #include #include "asn1_local.h" +DEFINE_STACK_OF(ASN1_VALUE) + /* Free up an ASN1 structure */ void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c index 155080dd..48ba9f3f 100644 --- a/crypto/asn1/tasn_new.c +++ b/crypto/asn1/tasn_new.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,8 @@ #include #include "asn1_local.h" +DEFINE_STACK_OF(ASN1_VALUE) + static int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed); static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it, diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index c625833c..1579f7c3 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -788,7 +788,9 @@ void bio_cleanup(void) /* Internal variant of the below BIO_wait() not calling BIOerr() */ static int bio_wait(BIO *bio, time_t max_time, unsigned int milliseconds) { +#ifndef OPENSSL_NO_SOCK int fd; +#endif if (max_time == 0) return 1; diff --git a/crypto/bn/bn_conv.c b/crypto/bn/bn_conv.c index fd21464d..15f94079 100644 --- a/crypto/bn/bn_conv.c +++ b/crypto/bn/bn_conv.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -46,8 +46,8 @@ char *BN_bn2hex(const BIGNUM *a) return buf; } -#ifndef FIPS_MODE -/* No BIO_snprintf in FIPS_MODE */ +#ifndef FIPS_MODULE +/* No BIO_snprintf in FIPS_MODULE */ /* Must 'OPENSSL_free' the returned data */ char *BN_bn2dec(const BIGNUM *a) { diff --git a/crypto/bn/bn_ctx.c b/crypto/bn/bn_ctx.c index ecc0034b..d6c55cb1 100644 --- a/crypto/bn/bn_ctx.c +++ b/crypto/bn/bn_ctx.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -90,7 +90,7 @@ struct bignum_ctx { OPENSSL_CTX *libctx; }; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* Debugging functionality */ static void ctxdbg(BIO *channel, const char *text, BN_CTX *ctx) { @@ -126,7 +126,7 @@ static void ctxdbg(BIO *channel, const char *text, BN_CTX *ctx) #else /* TODO(3.0): Consider if we want to do this in FIPS mode */ # define CTXDBG(str, ctx) do {} while(0) -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ BN_CTX *BN_CTX_new_ex(OPENSSL_CTX *ctx) { @@ -143,7 +143,7 @@ BN_CTX *BN_CTX_new_ex(OPENSSL_CTX *ctx) return ret; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *BN_CTX_new(void) { return BN_CTX_new_ex(NULL); @@ -159,7 +159,7 @@ BN_CTX *BN_CTX_secure_new_ex(OPENSSL_CTX *ctx) return ret; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *BN_CTX_secure_new(void) { return BN_CTX_secure_new_ex(NULL); @@ -170,7 +170,7 @@ void BN_CTX_free(BN_CTX *ctx) { if (ctx == NULL) return; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE OSSL_TRACE_BEGIN(BN_CTX) { BN_POOL_ITEM *pool = ctx->pool.head; BIO_printf(trc_out, diff --git a/crypto/bn/bn_dh.c b/crypto/bn/bn_dh.c index 9ffb6d8d..9a7cc17f 100644 --- a/crypto/bn/bn_dh.c +++ b/crypto/bn/bn_dh.c @@ -22,7 +22,7 @@ /* DH parameters from RFC3526 */ -# ifndef FIPS_MODE +# ifndef FIPS_MODULE /* * "1536-bit MODP Group" from RFC3526, Section 2. * @@ -60,7 +60,7 @@ static const BN_ULONG modp_1536_q[] = { BN_DEF(0x4533E63A, 0x94812704), BN_DEF(0xC06E0E68, 0x62633145), BN_DEF(0x10B4611A, 0xE487ED51), BN_DEF(0xFFFFFFFF, 0x7FFFFFFF) }; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ /*- * "2048-bit MODP Group" from RFC3526, Section 3. @@ -1037,7 +1037,7 @@ make_dh_bn(ffdhe6144_q) make_dh_bn(ffdhe8192_p) make_dh_bn(ffdhe8192_q) -# ifndef FIPS_MODE +# ifndef FIPS_MODULE make_dh_bn(modp_1536_p) make_dh_bn(modp_1536_q) # endif diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c index ce5789ea..579a386f 100644 --- a/crypto/bn/bn_prime.c +++ b/crypto/bn/bn_prime.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -207,7 +207,7 @@ int BN_generate_prime_ex2(BIGNUM *ret, int bits, int safe, return found; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb) { @@ -265,7 +265,7 @@ static int bn_is_prime_int(const BIGNUM *w, int checks, BN_CTX *ctx, int do_trial_division, BN_GENCB *cb) { int i, status, ret = -1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *ctxlocal = NULL; #else @@ -301,7 +301,7 @@ static int bn_is_prime_int(const BIGNUM *w, int checks, BN_CTX *ctx, if (!BN_GENCB_call(cb, 1, -1)) return -1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL && (ctxlocal = ctx = BN_CTX_new()) == NULL) goto err; #endif @@ -311,7 +311,7 @@ static int bn_is_prime_int(const BIGNUM *w, int checks, BN_CTX *ctx, goto err; ret = (status == BN_PRIMETEST_PROBABLY_PRIME); err: -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(ctxlocal); #endif return ret; diff --git a/crypto/bn/bn_rand.c b/crypto/bn/bn_rand.c index 91cb39ee..e603bb70 100644 --- a/crypto/bn/bn_rand.c +++ b/crypto/bn/bn_rand.c @@ -103,7 +103,7 @@ int BN_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx) { return bnrand(NORMAL, rnd, bits, top, bottom, ctx); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) { return bnrand(NORMAL, rnd, bits, top, bottom, NULL); @@ -120,7 +120,7 @@ int BN_priv_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx) return bnrand(PRIVATE, rnd, bits, top, bottom, ctx); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom) { return bnrand(PRIVATE, rnd, bits, top, bottom, NULL); @@ -199,7 +199,7 @@ int BN_rand_range_ex(BIGNUM *r, const BIGNUM *range, BN_CTX *ctx) return bnrand_range(NORMAL, r, range, ctx); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int BN_rand_range(BIGNUM *r, const BIGNUM *range) { return bnrand_range(NORMAL, r, range, NULL); @@ -211,7 +211,7 @@ int BN_priv_rand_range_ex(BIGNUM *r, const BIGNUM *range, BN_CTX *ctx) return bnrand_range(PRIVATE, r, range, ctx); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int BN_priv_rand_range(BIGNUM *r, const BIGNUM *range) { return bnrand_range(PRIVATE, r, range, NULL); diff --git a/crypto/bn/bn_rsa_fips186_4.c b/crypto/bn/bn_rsa_fips186_4.c index 492eb297..935320ff 100644 --- a/crypto/bn/bn_rsa_fips186_4.c +++ b/crypto/bn/bn_rsa_fips186_4.c @@ -1,8 +1,8 @@ /* - * Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2018-2019, Oracle and/or its affiliates. All rights reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/bn/build.info b/crypto/bn/build.info index 5e04ed00..a40bcdca 100644 --- a/crypto/bn/build.info +++ b/crypto/bn/build.info @@ -112,16 +112,18 @@ $COMMON=bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c \ bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_sqr.c \ bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \ bn_x931p.c bn_intern.c bn_dh.c \ - bn_rsa_fips186_4.c $BNDH $BNASM -SOURCE[../../libcrypto]=$COMMON bn_print.c bn_err.c bn_srp.c + bn_rsa_fips186_4.c $BNDH +SOURCE[../../libcrypto]=$COMMON $BNASM bn_print.c bn_err.c bn_srp.c IF[{- !$disabled{'deprecated-3.0'} -}] SOURCE[../../libcrypto]=bn_depr.c ENDIF -SOURCE[../../providers/libfips.a]=$COMMON +SOURCE[../../providers/libfips.a]=$COMMON $BNASM +SOURCE[../../providers/liblegacy.a]=$BNASM # Implementations are now spread across several libraries, so the defines # need to be applied to all affected libraries and modules. DEFINE[../../libcrypto]=$BNDEF DEFINE[../../providers/libfips.a]=$BNDEF +DEFINE[../../providers/liblegacy.a]=$BNDEF DEFINE[../../providers/libimplementations.a]=$BNDEF INCLUDE[../../libcrypto]=../../crypto/include diff --git a/crypto/build.info b/crypto/build.info index 860b8bb8..83625029 100644 --- a/crypto/build.info +++ b/crypto/build.info @@ -77,7 +77,7 @@ $UTIL_DEFINE=$CPUIDDEF SOURCE[../libcrypto]=$UTIL_COMMON \ mem.c mem_sec.c \ cversion.c info.c cpt_err.c ebcdic.c uid.c o_time.c o_dir.c \ - o_fopen.c getenv.c o_init.c o_fips.c init.c trace.c provider.c \ + o_fopen.c getenv.c o_init.c init.c trace.c provider.c \ $UPLINKSRC SOURCE[../providers/libfips.a]=$UTIL_COMMON SOURCE[../providers/liblegacy.a]=$UTIL_COMMON @@ -94,7 +94,6 @@ DEFINE[../providers/libcommon.a]=$UTIL_DEFINE DEPEND[info.o]=buildinf.h DEPEND[cversion.o]=buildinf.h GENERATE[buildinf.h]=../util/mkbuildinf.pl "$(CC) $(LIB_CFLAGS) $(CPPFLAGS_Q)" "$(PLATFORM)" -DEPEND[buildinf.h]=../configdata.pm GENERATE[uplink-x86.s]=../ms/uplink-x86.pl GENERATE[uplink-x86_64.s]=../ms/uplink-x86_64.pl diff --git a/crypto/cmp/cmp_asn.c b/crypto/cmp/cmp_asn.c index ae318db6..f109af05 100644 --- a/crypto/cmp/cmp_asn.c +++ b/crypto/cmp/cmp_asn.c @@ -17,6 +17,8 @@ #include #include +DEFINE_STACK_OF(OSSL_CMP_ITAV) + /* ASN.1 declarations from RFC4210 */ ASN1_SEQUENCE(OSSL_CMP_REVANNCONTENT) = { /* OSSL_CMP_PKISTATUS is effectively ASN1_INTEGER so it is used directly */ @@ -68,7 +70,8 @@ ASN1_SEQUENCE(OSSL_CMP_ERRORMSGCONTENT) = { * so it is used directly * */ - ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ERRORMSGCONTENT, errorDetails, ASN1_UTF8STRING) + ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ERRORMSGCONTENT, errorDetails, + ASN1_UTF8STRING) } ASN1_SEQUENCE_END(OSSL_CMP_ERRORMSGCONTENT) IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_ERRORMSGCONTENT) @@ -350,8 +353,10 @@ ASN1_CHOICE(OSSL_CMP_PKIBODY) = { ASN1_EXP(OSSL_CMP_PKIBODY, value.cr, OSSL_CRMF_MSGS, 2), ASN1_EXP(OSSL_CMP_PKIBODY, value.cp, OSSL_CMP_CERTREPMESSAGE, 3), ASN1_EXP(OSSL_CMP_PKIBODY, value.p10cr, X509_REQ, 4), - ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecc, OSSL_CMP_POPODECKEYCHALLCONTENT, 5), - ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecr, OSSL_CMP_POPODECKEYRESPCONTENT, 6), + ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecc, + OSSL_CMP_POPODECKEYCHALLCONTENT, 5), + ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecr, + OSSL_CMP_POPODECKEYRESPCONTENT, 6), ASN1_EXP(OSSL_CMP_PKIBODY, value.kur, OSSL_CRMF_MSGS, 7), ASN1_EXP(OSSL_CMP_PKIBODY, value.kup, OSSL_CMP_CERTREPMESSAGE, 8), ASN1_EXP(OSSL_CMP_PKIBODY, value.krr, OSSL_CRMF_MSGS, 9), diff --git a/crypto/cmp/cmp_client.c b/crypto/cmp/cmp_client.c index 6e992902..d309f84a 100644 --- a/crypto/cmp/cmp_client.c +++ b/crypto/cmp/cmp_client.c @@ -21,6 +21,12 @@ #include "openssl/cmp_util.h" +DEFINE_STACK_OF(ASN1_UTF8STRING) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(OSSL_CMP_CERTRESPONSE) +DEFINE_STACK_OF(OSSL_CMP_PKISI) +DEFINE_STACK_OF(OSSL_CRMF_CERTID) + #define IS_CREP(t) ((t) == OSSL_CMP_PKIBODY_IP || (t) == OSSL_CMP_PKIBODY_CP \ || (t) == OSSL_CMP_PKIBODY_KUP) @@ -170,7 +176,7 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, if (*rep == NULL) { CMPerr(0, CMP_R_TRANSFER_ERROR); /* or receiving response */ - ERR_add_error_data(1, req_type_str); + ERR_add_error_data(2, "request sent: ", req_type_str); ERR_add_error_data(2, ", expected response: ", expected_type_str); return 0; } @@ -205,7 +211,8 @@ static int send_receive_check(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *req, char buf[OSSL_CMP_PKISI_BUFLEN]; if (save_statusInfo(ctx, si) - && OSSL_CMP_CTX_snprint_PKIStatus(ctx, buf, sizeof(buf)) != NULL) + && OSSL_CMP_CTX_snprint_PKIStatus(ctx, buf, + sizeof(buf)) != NULL) ERR_add_error_data(1, buf); if (emc->errorCode != NULL && BIO_snprintf(buf, sizeof(buf), "; errorCode: %ld", diff --git a/crypto/cmp/cmp_ctx.c b/crypto/cmp/cmp_ctx.c index e34ad847..9aeee7f5 100644 --- a/crypto/cmp/cmp_ctx.c +++ b/crypto/cmp/cmp_ctx.c @@ -20,7 +20,16 @@ #include #include -/* Get current certificate store containing trusted root CA certs */ +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(POLICYINFO) +DEFINE_STACK_OF(ASN1_UTF8STRING) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(OSSL_CMP_ITAV) + +/* + * Get current certificate store containing trusted root CA certs + */ X509_STORE *OSSL_CMP_CTX_get0_trustedStore(const OSSL_CMP_CTX *ctx) { if (ctx == NULL) { @@ -155,7 +164,7 @@ void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx) X509_STORE_free(ctx->trusted); sk_X509_pop_free(ctx->untrusted_certs, X509_free); - X509_free(ctx->clCert); + X509_free(ctx->cert); EVP_PKEY_free(ctx->pkey); ASN1_OCTET_STRING_free(ctx->referenceValue); if (ctx->secretValue != NULL) @@ -667,12 +676,12 @@ int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx, * Set our own client certificate, used for example in KUR and when * doing the IR with existing certificate. */ -DEFINE_OSSL_CMP_CTX_set1_up_ref(clCert, X509) +DEFINE_OSSL_CMP_CTX_set1_up_ref(cert, X509) /* * Set the old certificate that we are updating in KUR * or the certificate to be revoked in RR, respectively. - * Also used as reference cert (defaulting to clCert) for deriving subject DN + * Also used as reference cert (defaulting to cert) for deriving subject DN * and SANs. Its issuer is used as default recipient in the CMP message header. */ DEFINE_OSSL_CMP_CTX_set1_up_ref(oldCert, X509) diff --git a/crypto/cmp/cmp_hdr.c b/crypto/cmp/cmp_hdr.c index 99953d9c..b07bf031 100644 --- a/crypto/cmp/cmp_hdr.c +++ b/crypto/cmp/cmp_hdr.c @@ -20,6 +20,9 @@ #include #include +DEFINE_STACK_OF(ASN1_UTF8STRING) +DEFINE_STACK_OF(OSSL_CMP_ITAV) + int ossl_cmp_hdr_set_pvno(OSSL_CMP_PKIHEADER *hdr, int pvno) { if (!ossl_assert(hdr != NULL)) @@ -38,7 +41,8 @@ int ossl_cmp_hdr_get_pvno(const OSSL_CMP_PKIHEADER *hdr) return (int)pvno; } -ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_transactionID(const OSSL_CMP_PKIHEADER *hdr) +ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_transactionID(const + OSSL_CMP_PKIHEADER *hdr) { if (hdr == NULL) { CMPerr(0, CMP_R_NULL_ARGUMENT); @@ -263,6 +267,25 @@ int ossl_cmp_hdr_has_implicitConfirm(const OSSL_CMP_PKIHEADER *hdr) return 0; } +/* + * set ctx->transactionID in CMP header + * if ctx->transactionID is NULL, a random one is created with 128 bit + * according to section 5.1.1: + * + * It is RECOMMENDED that the clients fill the transactionID field with + * 128 bits of (pseudo-) random data for the start of a transaction to + * reduce the probability of having the transactionID in use at the server. + */ +int ossl_cmp_hdr_set_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr) +{ + if (ctx->transactionID == NULL + && !set1_aostr_else_random(&ctx->transactionID, NULL, + OSSL_CMP_TRANSACTIONID_LENGTH)) + return 0; + return ossl_cmp_asn1_octet_string_set1(&hdr->transactionID, + ctx->transactionID); +} + /* fill in all fields of the hdr according to the info given in ctx */ int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr) { @@ -280,8 +303,8 @@ int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr) * The sender name is copied from the subject of the client cert, if any, * or else from the subject name provided for certification requests. */ - sender = ctx->clCert != NULL ? - X509_get_subject_name(ctx->clCert) : ctx->subjectName; + sender = ctx->cert != NULL ? + X509_get_subject_name(ctx->cert) : ctx->subjectName; if (!ossl_cmp_hdr_set1_sender(hdr, sender)) return 0; @@ -298,8 +321,8 @@ int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr) rcp = ctx->issuer; } else if (ctx->oldCert != NULL) { rcp = X509_get_issuer_name(ctx->oldCert); - } else if (ctx->clCert != NULL) { - rcp = X509_get_issuer_name(ctx->clCert); + } else if (ctx->cert != NULL) { + rcp = X509_get_issuer_name(ctx->cert); } if (!ossl_cmp_hdr_set1_recipient(hdr, rcp)) return 0; @@ -313,21 +336,7 @@ int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr) ctx->recipNonce)) return 0; - /* - * set ctx->transactionID in CMP header - * if ctx->transactionID is NULL, a random one is created with 128 bit - * according to section 5.1.1: - * - * It is RECOMMENDED that the clients fill the transactionID field with - * 128 bits of (pseudo-) random data for the start of a transaction to - * reduce the probability of having the transactionID in use at the server. - */ - if (ctx->transactionID == NULL - && !set1_aostr_else_random(&ctx->transactionID, NULL, - OSSL_CMP_TRANSACTIONID_LENGTH)) - return 0; - if (!ossl_cmp_asn1_octet_string_set1(&hdr->transactionID, - ctx->transactionID)) + if (!ossl_cmp_hdr_set_transactionID(ctx, hdr)) return 0; /*- diff --git a/crypto/cmp/cmp_http.c b/crypto/cmp/cmp_http.c index 6b3849fc..3804f249 100644 --- a/crypto/cmp/cmp_http.c +++ b/crypto/cmp/cmp_http.c @@ -28,6 +28,8 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) + /* * Send the PKIMessage req and on success return the response, else NULL. * Any previous error queue entries will likely be removed by ERR_clear_error(). @@ -56,8 +58,8 @@ OSSL_CMP_MSG *OSSL_CMP_MSG_http_perform(OSSL_CMP_CTX *ctx, OSSL_CMP_CTX_get_http_cb_arg(ctx) != NULL, ctx->proxy, ctx->no_proxy, NULL, NULL, ctx->http_cb, OSSL_CMP_CTX_get_http_cb_arg(ctx), - headers, content_type_pkix, - (ASN1_VALUE *)req, ASN1_ITEM_rptr(OSSL_CMP_MSG), + headers, content_type_pkix, (const ASN1_VALUE *)req, + ASN1_ITEM_rptr(OSSL_CMP_MSG), 0, 0, ctx->msg_timeout, content_type_pkix, ASN1_ITEM_rptr(OSSL_CMP_MSG)); diff --git a/crypto/cmp/cmp_local.h b/crypto/cmp/cmp_local.h index 9acafbae..04abcf50 100644 --- a/crypto/cmp/cmp_local.h +++ b/crypto/cmp/cmp_local.h @@ -68,8 +68,8 @@ struct ossl_cmp_ctx_st { /* client authentication */ int unprotectedSend; /* send unprotected PKI messages */ - X509 *clCert; /* client cert used to identify and sign for MSG_SIG_ALG */ - EVP_PKEY *pkey; /* the key pair corresponding to clCert */ + X509 *cert; /* protection cert used to identify and sign for MSG_SIG_ALG */ + EVP_PKEY *pkey; /* the key pair corresponding to cert */ ASN1_OCTET_STRING *referenceValue; /* optional user name for MSG_MAC_ALG */ ASN1_OCTET_STRING *secretValue; /* password/shared secret for MSG_MAC_ALG */ /* PBMParameters for MSG_MAC_ALG */ @@ -790,7 +790,7 @@ int ossl_cmp_ctx_set1_recipNonce(OSSL_CMP_CTX *ctx, /* from cmp_status.c */ int ossl_cmp_pkisi_get_status(const OSSL_CMP_PKISI *si); const char *ossl_cmp_PKIStatus_to_string(int status); -OSSL_CMP_PKIFREETEXT *ossl_cmp_pkisi_get0_statusString(const OSSL_CMP_PKISI *si); +OSSL_CMP_PKIFREETEXT *ossl_cmp_pkisi_get0_statusString(const OSSL_CMP_PKISI *s); int ossl_cmp_pkisi_get_pkifailureinfo(const OSSL_CMP_PKISI *si); int ossl_cmp_pkisi_check_pkifailureinfo(const OSSL_CMP_PKISI *si, int index); @@ -814,6 +814,7 @@ int ossl_cmp_hdr_set_implicitConfirm(OSSL_CMP_PKIHEADER *hdr); int ossl_cmp_hdr_has_implicitConfirm(const OSSL_CMP_PKIHEADER *hdr); # define OSSL_CMP_TRANSACTIONID_LENGTH 16 # define OSSL_CMP_SENDERNONCE_LENGTH 16 +int ossl_cmp_hdr_set_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr); int ossl_cmp_hdr_init(OSSL_CMP_CTX *ctx, OSSL_CMP_PKIHEADER *hdr); /* from cmp_msg.c */ @@ -885,13 +886,13 @@ OSSL_CMP_MSG *ossl_cmp_pollRep_new(OSSL_CMP_CTX *ctx, int crid, int64_t poll_after); OSSL_CMP_PKISI * ossl_cmp_revrepcontent_get_pkisi(OSSL_CMP_REVREPCONTENT *rrep, int rsid); -OSSL_CRMF_CERTID *ossl_cmp_revrepcontent_get_CertId(OSSL_CMP_REVREPCONTENT *rrep, +OSSL_CRMF_CERTID *ossl_cmp_revrepcontent_get_CertId(OSSL_CMP_REVREPCONTENT *rc, int rsid); OSSL_CMP_POLLREP * ossl_cmp_pollrepcontent_get0_pollrep(const OSSL_CMP_POLLREPCONTENT *prc, int rid); OSSL_CMP_CERTRESPONSE * -ossl_cmp_certrepmessage_get0_certresponse(const OSSL_CMP_CERTREPMESSAGE *crepmsg, +ossl_cmp_certrepmessage_get0_certresponse(const OSSL_CMP_CERTREPMESSAGE *crm, int rid); X509 *ossl_cmp_certresponse_get1_certificate(EVP_PKEY *privkey, const OSSL_CMP_CERTRESPONSE *crep); @@ -916,6 +917,6 @@ int ossl_cmp_verify_popo(const OSSL_CMP_MSG *msg, int accept_RAVerified); int ossl_cmp_exchange_certConf(OSSL_CMP_CTX *ctx, int fail_info, const char *txt); int ossl_cmp_exchange_error(OSSL_CMP_CTX *ctx, int status, int fail_info, - const char *txt, int errorCode, const char *details); + const char *txt, int errorCode, const char *detail); #endif /* !defined(OSSL_CRYPTO_CMP_LOCAL_H) */ diff --git a/crypto/cmp/cmp_msg.c b/crypto/cmp/cmp_msg.c index d98cefe7..7b338b2b 100644 --- a/crypto/cmp/cmp_msg.c +++ b/crypto/cmp/cmp_msg.c @@ -20,6 +20,16 @@ #include #include +DEFINE_STACK_OF(OSSL_CMP_CERTSTATUS) +DEFINE_STACK_OF(OSSL_CMP_ITAV) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(OSSL_CMP_PKISI) +DEFINE_STACK_OF(OSSL_CRMF_MSG) +DEFINE_STACK_OF(OSSL_CMP_CERTRESPONSE) +DEFINE_STACK_OF(OSSL_CRMF_CERTID) +DEFINE_STACK_OF(ASN1_UTF8STRING) + OSSL_CMP_PKIHEADER *OSSL_CMP_MSG_get0_header(const OSSL_CMP_MSG *msg) { if (msg == NULL) { @@ -208,7 +218,7 @@ static const X509_NAME *determine_subj(OSSL_CMP_CTX *ctx, X509 *refcert, static OSSL_CRMF_MSG *crm_new(OSSL_CMP_CTX *ctx, int bodytype, int rid) { OSSL_CRMF_MSG *crm = NULL; - X509 *refcert = ctx->oldCert != NULL ? ctx->oldCert : ctx->clCert; + X509 *refcert = ctx->oldCert != NULL ? ctx->oldCert : ctx->cert; /* refcert defaults to current client cert */ EVP_PKEY *rkey = OSSL_CMP_CTX_get0_newPkey(ctx, 0); STACK_OF(GENERAL_NAME) *default_sans = NULL; @@ -574,9 +584,9 @@ int ossl_cmp_msg_gen_push1_ITAVs(OSSL_CMP_MSG *msg, return 0; for (i = 0; i < sk_OSSL_CMP_ITAV_num(itavs); i++) { - if ((itav = OSSL_CMP_ITAV_dup(sk_OSSL_CMP_ITAV_value(itavs, i))) == NULL) - return 0; - if (!ossl_cmp_msg_gen_push0_ITAV(msg, itav)) { + itav = OSSL_CMP_ITAV_dup(sk_OSSL_CMP_ITAV_value(itavs, i)); + if (itav == NULL + || !ossl_cmp_msg_gen_push0_ITAV(msg, itav)) { OSSL_CMP_ITAV_free(itav); return 0; } @@ -972,6 +982,18 @@ X509 *ossl_cmp_certresponse_get1_certificate(EVP_PKEY *privkey, return crt; } +int OSSL_CMP_MSG_update_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg) +{ + if (ctx == NULL || msg == NULL) { + CMPerr(0, CMP_R_NULL_ARGUMENT); + return 0; + } + if (!ossl_cmp_hdr_set_transactionID(ctx, msg->header)) + return 0; + return msg->header->protectionAlg == NULL + || ossl_cmp_msg_protect(ctx, msg); +} + OSSL_CMP_MSG *ossl_cmp_msg_load(const char *file) { OSSL_CMP_MSG *msg = NULL; diff --git a/crypto/cmp/cmp_protect.c b/crypto/cmp/cmp_protect.c index e1dc8e5f..97600a72 100644 --- a/crypto/cmp/cmp_protect.c +++ b/crypto/cmp/cmp_protect.c @@ -18,6 +18,8 @@ #include #include +DEFINE_STACK_OF(X509) + /* * This function is also used for verification from cmp_vfy. * @@ -143,21 +145,18 @@ int ossl_cmp_msg_add_extraCerts(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg) && (msg->extraCerts = sk_X509_new_null()) == NULL) return 0; - if (ctx->clCert != NULL) { - /* Make sure that our own cert gets sent, in the first position */ - if (!X509_up_ref(ctx->clCert)) + if (ctx->cert != NULL && ctx->pkey != NULL) { + /* make sure that our own cert is included in the first position */ + if (!ossl_cmp_sk_X509_add1_cert(msg->extraCerts, ctx->cert, 1, 1)) return 0; - if (!sk_X509_push(msg->extraCerts, ctx->clCert)) { - X509_free(ctx->clCert); - return 0; - } - /* if we have untrusted store, try to add intermediate certs */ + /* if we have untrusted certs, try to add intermediate certs */ if (ctx->untrusted_certs != NULL) { STACK_OF(X509) *chain = - ossl_cmp_build_cert_chain(ctx->untrusted_certs, ctx->clCert); + ossl_cmp_build_cert_chain(ctx->untrusted_certs, ctx->cert); int res = ossl_cmp_sk_X509_add1_certs(msg->extraCerts, chain, 1 /* no self-issued */, 1 /* no duplicates */, 0); + sk_X509_pop_free(chain, X509_free); if (res == 0) return 0; @@ -225,6 +224,15 @@ int ossl_cmp_msg_protect(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg) if (!ossl_assert(ctx != NULL && msg != NULL)) return 0; + /* + * For the case of re-protection remove pre-existing protection. + * TODO: Consider also removing any pre-existing extraCerts. + */ + X509_ALGOR_free(msg->header->protectionAlg); + msg->header->protectionAlg = NULL; + ASN1_BIT_STRING_free(msg->protection); + msg->protection = NULL; + if (ctx->unprotectedSend) return 1; @@ -236,84 +244,70 @@ int ossl_cmp_msg_protect(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg) && !ossl_cmp_hdr_set1_senderKID(msg->header, ctx->referenceValue)) goto err; - - /* - * add any additional certificates from ctx->extraCertsOut - * while not needed to validate the signing cert, the option to do - * this might be handy for certain use cases - */ - if (!ossl_cmp_msg_add_extraCerts(ctx, msg)) - goto err; - - if ((msg->protection = - ossl_cmp_calc_protection(msg, ctx->secretValue, NULL)) == NULL) - goto err; - } else { + } else if (ctx->cert != NULL && ctx->pkey != NULL) { /* * use MSG_SIG_ALG according to 5.1.3.3 if client Certificate and * private key is given */ - if (ctx->clCert != NULL && ctx->pkey != NULL) { - const ASN1_OCTET_STRING *subjKeyIDStr = NULL; - int algNID = 0; - ASN1_OBJECT *alg = NULL; + const ASN1_OCTET_STRING *subjKeyIDStr = NULL; + int algNID = 0; + ASN1_OBJECT *alg = NULL; - /* make sure that key and certificate match */ - if (!X509_check_private_key(ctx->clCert, ctx->pkey)) { - CMPerr(0, CMP_R_CERT_AND_KEY_DO_NOT_MATCH); - goto err; - } - - if (msg->header->protectionAlg == NULL) - if ((msg->header->protectionAlg = X509_ALGOR_new()) == NULL) - goto err; - - if (!OBJ_find_sigid_by_algs(&algNID, ctx->digest, - EVP_PKEY_id(ctx->pkey))) { - CMPerr(0, CMP_R_UNSUPPORTED_KEY_TYPE); - goto err; - } - if ((alg = OBJ_nid2obj(algNID)) == NULL) - goto err; - if (!X509_ALGOR_set0(msg->header->protectionAlg, - alg, V_ASN1_UNDEF, NULL)) { - ASN1_OBJECT_free(alg); - goto err; - } - - /* - * set senderKID to keyIdentifier of the used certificate according - * to section 5.1.1 - */ - subjKeyIDStr = X509_get0_subject_key_id(ctx->clCert); - if (subjKeyIDStr == NULL) - subjKeyIDStr = ctx->referenceValue; /* fallback */ - if (subjKeyIDStr != NULL - && !ossl_cmp_hdr_set1_senderKID(msg->header, subjKeyIDStr)) - goto err; - - /* - * Add ctx->clCert followed, if possible, by its chain built - * from ctx->untrusted_certs, and then ctx->extraCertsOut - */ - if (!ossl_cmp_msg_add_extraCerts(ctx, msg)) - goto err; - - if ((msg->protection = - ossl_cmp_calc_protection(msg, NULL, ctx->pkey)) == NULL) - goto err; - } else { - CMPerr(0, CMP_R_MISSING_KEY_INPUT_FOR_CREATING_PROTECTION); + /* make sure that key and certificate match */ + if (!X509_check_private_key(ctx->cert, ctx->pkey)) { + CMPerr(0, CMP_R_CERT_AND_KEY_DO_NOT_MATCH); goto err; } + + if (msg->header->protectionAlg == NULL) + if ((msg->header->protectionAlg = X509_ALGOR_new()) == NULL) + goto err; + + if (!OBJ_find_sigid_by_algs(&algNID, ctx->digest, + EVP_PKEY_id(ctx->pkey))) { + CMPerr(0, CMP_R_UNSUPPORTED_KEY_TYPE); + goto err; + } + if ((alg = OBJ_nid2obj(algNID)) == NULL) + goto err; + if (!X509_ALGOR_set0(msg->header->protectionAlg, alg, + V_ASN1_UNDEF, NULL)) { + ASN1_OBJECT_free(alg); + goto err; + } + + /* + * set senderKID to keyIdentifier of the used certificate according + * to section 5.1.1 + */ + subjKeyIDStr = X509_get0_subject_key_id(ctx->cert); + if (subjKeyIDStr == NULL) + subjKeyIDStr = ctx->referenceValue; /* fallback */ + if (subjKeyIDStr != NULL + && !ossl_cmp_hdr_set1_senderKID(msg->header, subjKeyIDStr)) + goto err; + } else { + CMPerr(0, CMP_R_MISSING_KEY_INPUT_FOR_CREATING_PROTECTION); + goto err; } + if ((msg->protection = + ossl_cmp_calc_protection(msg, ctx->secretValue, ctx->pkey)) == NULL) + goto err; + + /* + * If present, add ctx->cert followed by its chain as far as possible. + * Finally add any additional certificates from ctx->extraCertsOut; + * even if not needed to validate the protection + * the option to do this might be handy for certain use cases. + */ + if (!ossl_cmp_msg_add_extraCerts(ctx, msg)) + goto err; /* * As required by RFC 4210 section 5.1.1., if the sender name is not known * to the client it set to NULL-DN. In this case for identification at least * the senderKID must be set, where we took the referenceValue as fallback. */ - if (ossl_cmp_general_name_is_NULL_DN(msg->header->sender) && msg->header->senderKID == NULL) CMPerr(0, CMP_R_MISSING_SENDER_IDENTIFICATION); diff --git a/crypto/cmp/cmp_server.c b/crypto/cmp/cmp_server.c index 2cb264a0..b805dc8b 100644 --- a/crypto/cmp/cmp_server.c +++ b/crypto/cmp/cmp_server.c @@ -19,6 +19,11 @@ #include #include +DEFINE_STACK_OF(OSSL_CRMF_MSG) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(OSSL_CMP_ITAV) +DEFINE_STACK_OF(OSSL_CMP_CERTSTATUS) + /* the context for the generic CMP server */ struct ossl_cmp_srv_ctx_st { @@ -216,7 +221,8 @@ static OSSL_CMP_MSG *process_cert_request(OSSL_CMP_SRV_CTX *srv_ctx, if (si == NULL) goto err; /* set OSSL_CMP_OPT_IMPLICIT_CONFIRM if and only if transaction ends */ - if (!OSSL_CMP_CTX_set_option(srv_ctx->ctx, OSSL_CMP_OPT_IMPLICIT_CONFIRM, + if (!OSSL_CMP_CTX_set_option(srv_ctx->ctx, + OSSL_CMP_OPT_IMPLICIT_CONFIRM, ossl_cmp_hdr_has_implicitConfirm(hdr) && srv_ctx->grantImplicitConfirm /* do not set if polling starts: */ @@ -484,9 +490,9 @@ OSSL_CMP_MSG *OSSL_CMP_SRV_process_request(OSSL_CMP_SRV_CTX *srv_ctx, tid); OPENSSL_free(tid); } - /* start of a new transaction, set transactionID and senderNonce */ - if (!OSSL_CMP_CTX_set1_transactionID(ctx, hdr->transactionID) - || !ossl_cmp_ctx_set1_recipNonce(ctx, hdr->senderNonce)) + /* start of a new transaction, reset transactionID and senderNonce */ + if (!OSSL_CMP_CTX_set1_transactionID(ctx, NULL) + || !OSSL_CMP_CTX_set1_senderNonce(ctx, NULL)) goto err; break; default: @@ -589,7 +595,9 @@ OSSL_CMP_MSG *OSSL_CMP_SRV_process_request(OSSL_CMP_SRV_CTX *srv_ctx, case OSSL_CMP_PKIBODY_GENP: case OSSL_CMP_PKIBODY_ERROR: /* TODO possibly support further terminating response message types */ - (void)OSSL_CMP_CTX_set1_transactionID(ctx, NULL); /* ignore any error */ + /* prepare for next transaction, ignoring any errors here: */ + (void)OSSL_CMP_CTX_set1_transactionID(ctx, NULL); + (void)OSSL_CMP_CTX_set1_senderNonce(ctx, NULL); default: /* not closing transaction in other cases */ break; diff --git a/crypto/cmp/cmp_status.c b/crypto/cmp/cmp_status.c index c9809c5a..8f10a42f 100644 --- a/crypto/cmp/cmp_status.c +++ b/crypto/cmp/cmp_status.c @@ -26,6 +26,8 @@ #include #include /* for ASN1_R_TOO_SMALL and ASN1_R_TOO_LARGE */ +DEFINE_STACK_OF(ASN1_UTF8STRING) + /* CMP functions related to PKIStatus */ int ossl_cmp_pkisi_get_status(const OSSL_CMP_PKISI *si) diff --git a/crypto/cmp/cmp_util.c b/crypto/cmp/cmp_util.c index 785a1bea..570e14cd 100644 --- a/crypto/cmp/cmp_util.c +++ b/crypto/cmp/cmp_util.c @@ -16,6 +16,10 @@ #include /* should be implied by cmperr.h */ #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_OBJECT) +DEFINE_STACK_OF(ASN1_UTF8STRING) + /* * use trace API for CMP-specific logging, prefixed by "CMP " and severity */ diff --git a/crypto/cmp/cmp_vfy.c b/crypto/cmp/cmp_vfy.c index 137b65b0..c124b063 100644 --- a/crypto/cmp/cmp_vfy.c +++ b/crypto/cmp/cmp_vfy.c @@ -22,6 +22,8 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(X509) + /* * Verify a message protected by signature according to section 5.1.3.3 * (sha1+RSA/DSA or any other algorithm supported by OpenSSL). diff --git a/crypto/cms/cms_env.c b/crypto/cms/cms_env.c index af53fc82..a5ef2dde 100644 --- a/crypto/cms/cms_env.c +++ b/crypto/cms/cms_env.c @@ -18,6 +18,10 @@ #include "crypto/asn1.h" #include "crypto/evp.h" +DEFINE_STACK_OF(CMS_RecipientInfo) +DEFINE_STACK_OF(CMS_RevocationInfoChoice) +DEFINE_STACK_OF(X509_ATTRIBUTE) + /* CMS EnvelopedData Utilities */ static void cms_env_set_version(CMS_EnvelopedData *env); diff --git a/crypto/cms/cms_ess.c b/crypto/cms/cms_ess.c index 00a08aaf..39010740 100644 --- a/crypto/cms/cms_ess.c +++ b/crypto/cms/cms_ess.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,6 +19,9 @@ #include "crypto/ess.h" #include "crypto/cms.h" +DEFINE_STACK_OF(GENERAL_NAMES) +DEFINE_STACK_OF(CMS_SignerInfo) + IMPLEMENT_ASN1_FUNCTIONS(CMS_ReceiptRequest) /* ESS services */ diff --git a/crypto/cms/cms_kari.c b/crypto/cms/cms_kari.c index 14a884ca..a2149ce0 100644 --- a/crypto/cms/cms_kari.c +++ b/crypto/cms/cms_kari.c @@ -17,6 +17,8 @@ #include "cms_local.h" #include "crypto/asn1.h" +DEFINE_STACK_OF(CMS_RecipientEncryptedKey) + /* Key Agreement Recipient Info (KARI) routines */ int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri, @@ -380,27 +382,27 @@ int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip, EVP_PKEY *r if (!cms_kari_create_ephemeral_key(kari, recipPubKey)) return 0; } else { - /* Use originator key */ - CMS_OriginatorIdentifierOrKey *oik = ri->d.kari->originator; + /* Use originator key */ + CMS_OriginatorIdentifierOrKey *oik = ri->d.kari->originator; - if (originatorPrivKey == NULL && originator == NULL) + if (originatorPrivKey == NULL || originator == NULL) return 0; - if (flags & CMS_USE_ORIGINATOR_KEYID) { - oik->type = CMS_OIK_KEYIDENTIFIER; - oik->d.subjectKeyIdentifier = ASN1_OCTET_STRING_new(); - if (oik->d.subjectKeyIdentifier == NULL) - return 0; - if (!cms_set1_keyid(&oik->d.subjectKeyIdentifier, originator)) - return 0; - } else { - oik->type = CMS_REK_ISSUER_SERIAL; - if (!cms_set1_ias(&oik->d.issuerAndSerialNumber, originator)) - return 0; - } + if (flags & CMS_USE_ORIGINATOR_KEYID) { + oik->type = CMS_OIK_KEYIDENTIFIER; + oik->d.subjectKeyIdentifier = ASN1_OCTET_STRING_new(); + if (oik->d.subjectKeyIdentifier == NULL) + return 0; + if (!cms_set1_keyid(&oik->d.subjectKeyIdentifier, originator)) + return 0; + } else { + oik->type = CMS_REK_ISSUER_SERIAL; + if (!cms_set1_ias(&oik->d.issuerAndSerialNumber, originator)) + return 0; + } - if (!cms_kari_set_originator_private_key(kari, originatorPrivKey)) - return 0; + if (!cms_kari_set_originator_private_key(kari, originatorPrivKey)) + return 0; } EVP_PKEY_up_ref(recipPubKey); @@ -413,7 +415,7 @@ static int cms_wrap_init(CMS_KeyAgreeRecipientInfo *kari, { EVP_CIPHER_CTX *ctx = kari->ctx; const EVP_CIPHER *kekcipher; - int keylen = EVP_CIPHER_key_length(cipher); + int keylen; int ret; /* If a suitable wrap algorithm is already set nothing to do */ @@ -423,8 +425,10 @@ static int cms_wrap_init(CMS_KeyAgreeRecipientInfo *kari, return 0; return 1; } - else if (cipher != NULL - && (EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_GET_WRAP_CIPHER)) { + if (cipher == NULL) + return 0; + keylen = EVP_CIPHER_key_length(cipher); + if ((EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_GET_WRAP_CIPHER) != 0) { ret = EVP_CIPHER_meth_get_ctrl(cipher)(NULL, EVP_CTRL_GET_WRAP_CIPHER, 0, &kekcipher); if (ret <= 0) diff --git a/crypto/cms/cms_lib.c b/crypto/cms/cms_lib.c index 835e3488..89dfc150 100644 --- a/crypto/cms/cms_lib.c +++ b/crypto/cms/cms_lib.c @@ -16,6 +16,10 @@ #include #include "cms_local.h" +DEFINE_STACK_OF(CMS_RevocationInfoChoice) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) + IMPLEMENT_ASN1_FUNCTIONS(CMS_ContentInfo) IMPLEMENT_ASN1_PRINT_FUNCTION(CMS_ContentInfo) diff --git a/crypto/cms/cms_pwri.c b/crypto/cms/cms_pwri.c index a4c32dcd..47261652 100644 --- a/crypto/cms/cms_pwri.c +++ b/crypto/cms/cms_pwri.c @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -18,6 +18,8 @@ #include "cms_local.h" #include "crypto/asn1.h" +DEFINE_STACK_OF(CMS_RecipientInfo) + int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri, unsigned char *pass, ossl_ssize_t passlen) { diff --git a/crypto/cms/cms_sd.c b/crypto/cms/cms_sd.c index 4a40226c..54a83602 100644 --- a/crypto/cms/cms_sd.c +++ b/crypto/cms/cms_sd.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -21,6 +21,12 @@ #include "crypto/cms.h" #include "crypto/ess.h" +DEFINE_STACK_OF(CMS_RevocationInfoChoice) +DEFINE_STACK_OF(CMS_SignerInfo) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_ALGOR) +DEFINE_STACK_OF(X509_ATTRIBUTE) + /* CMS SignedData Utilities */ static CMS_SignedData *cms_get0_signed(CMS_ContentInfo *cms) @@ -944,8 +950,10 @@ int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs, ASN1_INTEGER *key = NULL; if (keysize > 0) { key = ASN1_INTEGER_new(); - if (key == NULL || !ASN1_INTEGER_set(key, keysize)) + if (key == NULL || !ASN1_INTEGER_set(key, keysize)) { + ASN1_INTEGER_free(key); return 0; + } } alg = X509_ALGOR_new(); if (alg == NULL) { diff --git a/crypto/cms/cms_smime.c b/crypto/cms/cms_smime.c index f07064ea..dbdc815e 100644 --- a/crypto/cms/cms_smime.c +++ b/crypto/cms/cms_smime.c @@ -16,6 +16,12 @@ #include "cms_local.h" #include "crypto/asn1.h" +DEFINE_STACK_OF(CMS_SignerInfo) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(CMS_RecipientEncryptedKey) +DEFINE_STACK_OF(CMS_RecipientInfo) + static BIO *cms_get_text_bio(BIO *out, unsigned int flags) { BIO *rbio; diff --git a/crypto/conf/conf_api.c b/crypto/conf/conf_api.c index 4c7349a3..b4edfb28 100644 --- a/crypto/conf/conf_api.c +++ b/crypto/conf/conf_api.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,6 +16,8 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) + static void value_free_hash(const CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf); static void value_free_stack_doall(CONF_VALUE *a); diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c index 9718b73a..1d34519d 100644 --- a/crypto/conf/conf_def.c +++ b/crypto/conf/conf_def.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -27,6 +27,8 @@ # endif #endif +DEFINE_STACK_OF(BIO) + #ifndef S_ISDIR # define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR) #endif @@ -418,6 +420,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) OPENSSL_strlcpy(include_path, include_dir, newlen); OPENSSL_strlcat(include_path, "/", newlen); OPENSSL_strlcat(include_path, include, newlen); + OPENSSL_free(include); } else { include_path = include; } @@ -427,15 +430,11 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) next = process_include(include_path, &dirctx, &dirpath); if (include_path != dirpath) { /* dirpath will contain include in case of a directory */ - OPENSSL_free(include); - if (include_path != include) - OPENSSL_free(include_path); + OPENSSL_free(include_path); } #else next = BIO_new_file(include_path, "r"); - OPENSSL_free(include); - if (include_path != include) - OPENSSL_free(include_path); + OPENSSL_free(include_path); #endif if (next != NULL) { diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c index 2bbf43b9..504d9b18 100644 --- a/crypto/conf/conf_mod.c +++ b/crypto/conf/conf_mod.c @@ -18,6 +18,10 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(CONF_MODULE) +DEFINE_STACK_OF(CONF_IMODULE) + #define DSO_mod_init_name "OPENSSL_init" #define DSO_mod_finish_name "OPENSSL_finish" diff --git a/crypto/conf/conf_ssl.c b/crypto/conf/conf_ssl.c index 5855c50c..eefd279a 100644 --- a/crypto/conf/conf_ssl.c +++ b/crypto/conf/conf_ssl.c @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include "internal/sslconf.h" #include "conf_local.h" +DEFINE_STACK_OF(CONF_VALUE) + /* * SSL library configuration module placeholder. We load it here but defer * all decisions about its contents to libssl. diff --git a/crypto/context.c b/crypto/context.c index cf3b078b..1c95298e 100644 --- a/crypto/context.c +++ b/crypto/context.c @@ -39,7 +39,7 @@ struct openssl_ctx_st { struct openssl_ctx_onfree_list_st *onfreelist; }; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static OPENSSL_CTX default_context_int; /* Always points at default_context_int if it has been initialised */ @@ -119,7 +119,7 @@ static int context_deinit(OPENSSL_CTX *ctx) return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE void openssl_ctx_default_deinit(void) { context_deinit(default_context); @@ -146,7 +146,7 @@ OPENSSL_CTX *OPENSSL_CTX_new(void) return ctx; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int OPENSSL_CTX_load_config(OPENSSL_CTX *ctx, const char *config_file) { return CONF_modules_load_file_with_libctx(ctx, config_file, NULL, 0) > 0; @@ -162,7 +162,7 @@ void OPENSSL_CTX_free(OPENSSL_CTX *ctx) OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) { if (!RUN_ONCE(&default_context_init, do_default_context_init)) return 0; @@ -174,7 +174,7 @@ OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx) int openssl_ctx_is_default(OPENSSL_CTX *ctx) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL || ctx == default_context) return 1; #endif diff --git a/crypto/core_algorithm.c b/crypto/core_algorithm.c index 2973b376..79625fde 100644 --- a/crypto/core_algorithm.c +++ b/crypto/core_algorithm.c @@ -37,11 +37,11 @@ static int algorithm_do_this(OSSL_PROVIDER *provider, void *cbdata) cur_operation <= last_operation; cur_operation++) { const OSSL_ALGORITHM *map = - ossl_provider_query_operation(provider, data->operation_id, + ossl_provider_query_operation(provider, cur_operation, &no_store); if (map == NULL) - break; + continue; ok = 1; /* As long as we've found *something* */ while (map->algorithm_names != NULL) { diff --git a/crypto/core_namemap.c b/crypto/core_namemap.c index 3d509314..94c80de0 100644 --- a/crypto/core_namemap.c +++ b/crypto/core_namemap.c @@ -136,7 +136,7 @@ int ossl_namemap_name2num_n(const OSSL_NAMEMAP *namemap, NAMENUM_ENTRY *namenum_entry, namenum_tmpl; int number = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (namemap == NULL) namemap = ossl_namemap_stored(NULL); #endif @@ -198,7 +198,7 @@ int ossl_namemap_add_name_n(OSSL_NAMEMAP *namemap, int number, NAMENUM_ENTRY *namenum = NULL; int tmp_number; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (namemap == NULL) namemap = ossl_namemap_stored(NULL); #endif @@ -309,7 +309,7 @@ int ossl_namemap_add_names(OSSL_NAMEMAP *namemap, int number, * ============== */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE #include /* Creates an initial namemap with names found in the legacy method db */ @@ -366,7 +366,7 @@ OSSL_NAMEMAP *ossl_namemap_stored(OPENSSL_CTX *libctx) openssl_ctx_get_data(libctx, OPENSSL_CTX_NAMEMAP_INDEX, &stored_namemap_method); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (namemap != NULL && ossl_namemap_empty(namemap)) { /* Before pilfering, we make sure the legacy database is populated */ OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS diff --git a/crypto/crmf/crmf_lib.c b/crypto/crmf/crmf_lib.c index 8c59e3d0..89eb2c37 100644 --- a/crypto/crmf/crmf_lib.c +++ b/crypto/crmf/crmf_lib.c @@ -36,6 +36,9 @@ #include #include +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(OSSL_CRMF_MSG) + /*- * atyp = Attribute Type * valt = Value Type diff --git a/crypto/ct/ct_log.c b/crypto/ct/ct_log.c index 32a29ed6..73eeee9d 100644 --- a/crypto/ct/ct_log.c +++ b/crypto/ct/ct_log.c @@ -18,6 +18,8 @@ #include "internal/cryptlib.h" +DEFINE_STACK_OF(CTLOG) + /* * Information about a CT log server. */ diff --git a/crypto/ct/ct_oct.c b/crypto/ct/ct_oct.c index bd8d1bb1..4aca0385 100644 --- a/crypto/ct/ct_oct.c +++ b/crypto/ct/ct_oct.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -21,6 +21,8 @@ #include "ct_local.h" +DEFINE_STACK_OF(SCT) + int o2i_SCT_signature(SCT *sct, const unsigned char **in, size_t len) { size_t siglen; diff --git a/crypto/ct/ct_policy.c b/crypto/ct/ct_policy.c index 76e08b8f..e067fd8e 100644 --- a/crypto/ct/ct_policy.c +++ b/crypto/ct/ct_policy.c @@ -40,6 +40,7 @@ CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new_with_libctx(OPENSSL_CTX *libctx, ctx->propq = OPENSSL_strdup(propq); if (ctx->propq == NULL) { CTerr(0, ERR_R_MALLOC_FAILURE); + OPENSSL_free(ctx); return NULL; } } diff --git a/crypto/ct/ct_prn.c b/crypto/ct/ct_prn.c index 4c5760d6..a89b4aa6 100644 --- a/crypto/ct/ct_prn.c +++ b/crypto/ct/ct_prn.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,6 +16,8 @@ #include "ct_local.h" +DEFINE_STACK_OF(SCT) + static void SCT_signature_algorithms_print(const SCT *sct, BIO *out) { int nid = SCT_get_signature_nid(sct); diff --git a/crypto/ct/ct_sct.c b/crypto/ct/ct_sct.c index 1b8e1dc6..f6c262c9 100644 --- a/crypto/ct/ct_sct.c +++ b/crypto/ct/ct_sct.c @@ -19,6 +19,8 @@ #include "ct_local.h" +DEFINE_STACK_OF(SCT) + SCT *SCT_new(void) { SCT *sct = OPENSSL_zalloc(sizeof(*sct)); diff --git a/crypto/ct/ct_sct_ctx.c b/crypto/ct/ct_sct_ctx.c index 99e0c211..ad7b6e6f 100644 --- a/crypto/ct/ct_sct_ctx.c +++ b/crypto/ct/ct_sct_ctx.c @@ -24,8 +24,10 @@ SCT_CTX *SCT_CTX_new(OPENSSL_CTX *libctx, const char *propq) { SCT_CTX *sctx = OPENSSL_zalloc(sizeof(*sctx)); - if (sctx == NULL) + if (sctx == NULL) { CTerr(CT_F_SCT_CTX_NEW, ERR_R_MALLOC_FAILURE); + return NULL; + } sctx->libctx = libctx; if (propq != NULL) { diff --git a/crypto/ct/ct_x509v3.c b/crypto/ct/ct_x509v3.c index 1665b985..51dd779a 100644 --- a/crypto/ct/ct_x509v3.c +++ b/crypto/ct/ct_x509v3.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,6 +13,8 @@ #include "ct_local.h" +DEFINE_STACK_OF(SCT) + static char *i2s_poison(const X509V3_EXT_METHOD *method, void *val) { return OPENSSL_strdup("NULL"); diff --git a/crypto/der_writer.c b/crypto/der_writer.c index 26fd8859..87627875 100644 --- a/crypto/der_writer.c +++ b/crypto/der_writer.c @@ -24,12 +24,24 @@ static int int_start_context(WPACKET *pkt, int tag) static int int_end_context(WPACKET *pkt, int tag) { + /* + * If someone set the flag WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH on this + * sub-packet and this sub-packet has nothing written to it, the DER length + * will not be written, and the total written size will be unchanged before + * and after WPACKET_close(). We use size1 and size2 to determine if + * anything was written, and only write our tag if it has. + * + */ + size_t size1, size2; + if (tag < 0) return 1; if (!ossl_assert(tag <= 30)) return 0; - return WPACKET_close(pkt) - && WPACKET_put_bytes_u8(pkt, DER_C_CONTEXT | tag); + return WPACKET_get_total_written(pkt, &size1) + && WPACKET_close(pkt) + && WPACKET_get_total_written(pkt, &size2) + && (size1 == size2 || WPACKET_put_bytes_u8(pkt, DER_C_CONTEXT | tag)); } int DER_w_precompiled(WPACKET *pkt, int tag, @@ -136,7 +148,24 @@ int DER_w_begin_sequence(WPACKET *pkt, int tag) int DER_w_end_sequence(WPACKET *pkt, int tag) { - return WPACKET_close(pkt) - && WPACKET_put_bytes_u8(pkt, DER_F_CONSTRUCTED | DER_P_SEQUENCE) + /* + * If someone set the flag WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH on this + * sub-packet and this sub-packet has nothing written to it, the DER length + * will not be written, and the total written size will be unchanged before + * and after WPACKET_close(). We use size1 and size2 to determine if + * anything was written, and only write our tag if it has. + * + * Because we know that int_end_context() needs to do the same check, + * we reproduce this flag if the written length was unchanged, or we will + * have an erroneous context tag. + */ + size_t size1, size2; + + return WPACKET_get_total_written(pkt, &size1) + && WPACKET_close(pkt) + && WPACKET_get_total_written(pkt, &size2) + && (size1 == size2 + ? WPACKET_set_flags(pkt, WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH) + : WPACKET_put_bytes_u8(pkt, DER_F_CONSTRUCTED | DER_P_SEQUENCE)) && int_end_context(pkt, tag); } diff --git a/crypto/des/build.info b/crypto/des/build.info index 0e5fd171..eb0c7549 100644 --- a/crypto/des/build.info +++ b/crypto/des/build.info @@ -14,7 +14,7 @@ IF[{- !$disabled{asm} -}] ENDIF LIBS=../../libcrypto -$COMMON=set_key.c ecb3_enc.c $DESASM +$COMMON=set_key.c ecb3_enc.c $ALL=$COMMON\ ecb_enc.c cbc_enc.c \ cfb64enc.c cfb64ede.c cfb_enc.c \ @@ -22,8 +22,10 @@ $ALL=$COMMON\ str2key.c pcbc_enc.c qud_cksm.c rand_key.c \ fcrypt.c xcbc_enc.c cbc_cksm.c -SOURCE[../../libcrypto]=$ALL -SOURCE[../../providers/libfips.a]=$COMMON +SOURCE[../../libcrypto]=$ALL $DESASM +SOURCE[../../providers/libfips.a]=$COMMON $DESASM +SOURCE[../../providers/liblegacy.a]=$DESASM + DEFINE[../../libcrypto]=$DESDEF DEFINE[../../providers/libfips.a]=$DESDEF DEFINE[../../providers/liblegacy.a]=$DESDEF diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c index a25e83f1..9dd595ae 100644 --- a/crypto/dh/dh_check.c +++ b/crypto/dh/dh_check.c @@ -44,7 +44,7 @@ int DH_check_params_ex(const DH *dh) return errflags == 0; } -#ifdef FIPS_MODE +#ifdef FIPS_MODULE int DH_check_params(const DH *dh, int *ret) { int nid; @@ -102,7 +102,7 @@ int DH_check_params(const DH *dh, int *ret) BN_CTX_free(ctx); return ok; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ /*- * Check that p is a safe prime and @@ -140,7 +140,7 @@ int DH_check_ex(const DH *dh) /* Note: according to documentation - this only checks the params */ int DH_check(const DH *dh, int *ret) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return DH_check_params(dh, ret); #else int ok = 0, r; @@ -210,7 +210,7 @@ int DH_check(const DH *dh, int *ret) BN_CTX_end(ctx); BN_CTX_free(ctx); return ok; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ } int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key) diff --git a/crypto/dh/dh_gen.c b/crypto/dh/dh_gen.c index 39bb3652..327f6ff6 100644 --- a/crypto/dh/dh_gen.c +++ b/crypto/dh/dh_gen.c @@ -30,10 +30,10 @@ #include "crypto/dh.h" #include "dh_local.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ int dh_generate_ffc_parameters(DH *dh, int type, int pbits, int qbits, EVP_MD *md, BN_GENCB *cb) @@ -47,7 +47,7 @@ int dh_generate_ffc_parameters(DH *dh, int type, int pbits, qbits = (pbits >= 2048 ? SHA256_DIGEST_LENGTH : SHA_DIGEST_LENGTH) * 8; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (type == DH_PARAMGEN_TYPE_FIPS_186_2) ret = ffc_params_FIPS186_2_generate(dh->libctx, &dh->params, FFC_PARAM_TYPE_DH, @@ -96,7 +96,7 @@ int dh_get_named_group_uid_from_size(int pbits) return nid; } -#ifdef FIPS_MODE +#ifdef FIPS_MODULE static int dh_gen_named_group(OPENSSL_CTX *libctx, DH *ret, int prime_len) { @@ -116,12 +116,12 @@ static int dh_gen_named_group(OPENSSL_CTX *libctx, DH *ret, int prime_len) DH_free(dh); return ok; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE if (generator != 2) return 0; return dh_gen_named_group(ret->libctx, ret, prime_len); @@ -129,10 +129,10 @@ int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, if (ret->meth->generate_params) return ret->meth->generate_params(ret, prime_len, generator, cb); return dh_builtin_genparams(ret, prime_len, generator, cb); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /*- * We generate DH parameters as follows * find a prime p which is prime_len bits long, @@ -238,4 +238,4 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_CTX_free(ctx); return ok; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ diff --git a/crypto/dh/dh_group_params.c b/crypto/dh/dh_group_params.c index 7221e806..e0daa6eb 100644 --- a/crypto/dh/dh_group_params.c +++ b/crypto/dh/dh_group_params.c @@ -59,7 +59,7 @@ static const DH_NAMED_GROUP dh_named_groups[] = { FFDHE(4096), FFDHE(6144), FFDHE(8192), -#ifndef FIPS_MODE +#ifndef FIPS_MODULE MODP(1536), #endif MODP(2048), @@ -71,7 +71,7 @@ static const DH_NAMED_GROUP dh_named_groups[] = { * Additional dh named groups from RFC 5114 that have a different g. * The uid can be any unique identifier. */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE RFC5114("dh_1024_160", 1, 1024, 1024_160), RFC5114("dh_2048_224", 2, 2048, 2048_224), RFC5114("dh_2048_256", 3, 2048, 2048_256), diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 918949d9..1893b487 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -20,7 +20,7 @@ #include "crypto/dh.h" #include "crypto/security_bits.h" -#ifdef FIPS_MODE +#ifdef FIPS_MODULE # define MIN_STRENGTH 112 #else # define MIN_STRENGTH 80 @@ -39,7 +39,7 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) BN_MONT_CTX *mont = NULL; BIGNUM *tmp; int ret = -1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int check_result; #endif @@ -74,7 +74,7 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) goto err; } /* TODO(3.0) : Solve in a PR related to Key validation for DH */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) { DHerr(0, DH_R_INVALID_PUBKEY); goto err; @@ -95,7 +95,7 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return compute_key(key, pub_key, dh); #else return dh->meth->compute_key(key, pub_key, dh); @@ -106,7 +106,7 @@ int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh) { int rv, pad; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE rv = compute_key(key, pub_key, dh); #else rv = dh->meth->compute_key(key, pub_key, dh); @@ -166,16 +166,16 @@ static int dh_finish(DH *dh) return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE void DH_set_default_method(const DH_METHOD *meth) { default_DH_method = meth; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ int DH_generate_key(DH *dh) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return generate_key(dh); #else return dh->meth->generate_key(dh); @@ -214,7 +214,7 @@ static int generate_key(DH *dh) { int ok = 0; int generate_new_key = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE unsigned l; #endif BN_CTX *ctx = NULL; @@ -264,7 +264,7 @@ static int generate_key(DH *dh) max_strength, priv_key)) goto err; } else { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE if (dh->params.q == NULL) goto err; #else diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c index 7e42d13f..c3585f26 100644 --- a/crypto/dh/dh_lib.c +++ b/crypto/dh/dh_lib.c @@ -26,7 +26,7 @@ static DH *dh_new_intern(ENGINE *engine, OPENSSL_CTX *libctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int DH_set_method(DH *dh, const DH_METHOD *meth) { /* @@ -61,7 +61,7 @@ DH *DH_new_method(ENGINE *engine) { return dh_new_intern(engine, NULL); } -#endif /* !FIPS_MODE */ +#endif /* !FIPS_MODULE */ DH *dh_new_with_libctx(OPENSSL_CTX *libctx) { @@ -87,7 +87,7 @@ static DH *dh_new_intern(ENGINE *engine, OPENSSL_CTX *libctx) ret->libctx = libctx; ret->meth = DH_get_default_method(); -#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE) +#if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) ret->flags = ret->meth->flags; /* early default init */ if (engine) { if (!ENGINE_init(engine)) { @@ -108,10 +108,10 @@ static DH *dh_new_intern(ENGINE *engine, OPENSSL_CTX *libctx) ret->flags = ret->meth->flags; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data)) goto err; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { DHerr(0, ERR_R_INIT_FAIL); @@ -140,7 +140,7 @@ void DH_free(DH *r) if (r->meth != NULL && r->meth->finish != NULL) r->meth->finish(r); -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) # if !defined(OPENSSL_NO_ENGINE) ENGINE_finish(r->engine); # endif @@ -167,7 +167,7 @@ int DH_up_ref(DH *r) return ((i > 1) ? 1 : 0); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int DH_set_ex_data(DH *d, int idx, void *arg) { return CRYPTO_set_ex_data(&d->ex_data, idx, arg); @@ -310,12 +310,12 @@ void DH_set_flags(DH *dh, int flags) dh->flags |= flags; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE ENGINE *DH_get0_engine(DH *dh) { return dh->engine; } -#endif /*FIPS_MODE */ +#endif /*FIPS_MODULE */ FFC_PARAMS *dh_get0_params(DH *dh) { @@ -400,7 +400,7 @@ int EVP_PKEY_CTX_set_dh_paramgen_type(EVP_PKEY_CTX *ctx, int typ) if ((ret = dh_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, @@ -426,7 +426,7 @@ int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int pbits) if ((ret = dh_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, @@ -447,7 +447,7 @@ int EVP_PKEY_CTX_set_dh_paramgen_subprime_len(EVP_PKEY_CTX *ctx, int qbits) if ((ret = dh_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, @@ -468,7 +468,7 @@ int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen) if ((ret = dh_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, @@ -490,7 +490,7 @@ int EVP_PKEY_CTX_set_dh_rfc5114(EVP_PKEY_CTX *ctx, int gen) if ((ret = dh_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN, @@ -520,7 +520,7 @@ int EVP_PKEY_CTX_set_dh_nid(EVP_PKEY_CTX *ctx, int nid) if ((ret = dh_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, diff --git a/crypto/dh/dh_local.h b/crypto/dh/dh_local.h index 3b0181f7..a54d25f4 100644 --- a/crypto/dh/dh_local.h +++ b/crypto/dh/dh_local.h @@ -28,7 +28,7 @@ struct dh_st { int flags; BN_MONT_CTX *method_mont_p; CRYPTO_REF_COUNT references; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_EX_DATA ex_data; ENGINE *engine; #endif diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index 0d0b6a84..23527acf 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -306,7 +306,7 @@ static DH *ffc_params_generate(OPENSSL_CTX *libctx, DH_PKEY_CTX *dctx, else md = EVP_sha1(); } -# ifndef FIPS_MODE +# ifndef FIPS_MODULE if (dctx->paramgen_type == DH_PARAMGEN_TYPE_FIPS_186_2) rv = ffc_params_FIPS186_2_generate(libctx, &ret->params, FFC_PARAM_TYPE_DH, @@ -346,7 +346,7 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (dctx->rfc5114_param) { switch (dctx->rfc5114_param) { case 1: @@ -367,7 +367,7 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY_assign(pkey, EVP_PKEY_DHX, dh); return 1; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ if (ctx->pkey_gencb != NULL) { pcb = BN_GENCB_new(); @@ -375,9 +375,9 @@ static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, return 0; evp_pkey_set_cb_translate(pcb, ctx); } -# ifdef FIPS_MODE +# ifdef FIPS_MODULE dctx->paramgen_type = DH_PARAMGEN_TYPE_FIPS_186_4; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ if (dctx->paramgen_type >= DH_PARAMGEN_TYPE_FIPS_186_2) { dh = ffc_params_generate(NULL, dctx, pcb); BN_GENCB_free(pcb); diff --git a/crypto/dsa/dsa_gen.c b/crypto/dsa/dsa_gen.c index 7b72867f..acd088ee 100644 --- a/crypto/dsa/dsa_gen.c +++ b/crypto/dsa/dsa_gen.c @@ -36,7 +36,7 @@ int dsa_generate_ffc_parameters(DSA *dsa, int type, qbits = (pbits >= 2048 ? SHA256_DIGEST_LENGTH : SHA_DIGEST_LENGTH) * 8; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (type == DSA_PARAMGEN_TYPE_FIPS_186_2) ret = ffc_params_FIPS186_2_generate(dsa->libctx, &dsa->params, FFC_PARAM_TYPE_DSA, @@ -51,13 +51,13 @@ int dsa_generate_ffc_parameters(DSA *dsa, int type, return ret; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int DSA_generate_parameters_ex(DSA *dsa, int bits, const unsigned char *seed_in, int seed_len, int *counter_ret, unsigned long *h_ret, BN_GENCB *cb) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (dsa->meth->dsa_paramgen) return dsa->meth->dsa_paramgen(dsa, bits, seed_in, seed_len, counter_ret, h_ret, cb); @@ -66,7 +66,7 @@ int DSA_generate_parameters_ex(DSA *dsa, int bits, && !ffc_params_set_validate_params(&dsa->params, seed_in, seed_len, -1)) return 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* The old code used FIPS 186-2 DSA Parameter generation */ if (bits <= 1024 && seed_len == 20) { if (!dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_2, diff --git a/crypto/dsa/dsa_key.c b/crypto/dsa/dsa_key.c index f9bb3470..7bd9c5ff 100644 --- a/crypto/dsa/dsa_key.c +++ b/crypto/dsa/dsa_key.c @@ -21,7 +21,7 @@ #include "crypto/dsa.h" #include "dsa_local.h" -#ifdef FIPS_MODE +#ifdef FIPS_MODULE # define MIN_STRENGTH 112 #else # define MIN_STRENGTH 80 @@ -32,7 +32,7 @@ static int dsa_keygen_pairwise_test(DSA *dsa, OSSL_CALLBACK *cb, void *cbarg); int DSA_generate_key(DSA *dsa) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (dsa->meth->dsa_keygen != NULL) return dsa->meth->dsa_keygen(dsa); #endif @@ -96,9 +96,9 @@ static int dsa_keygen(DSA *dsa, int pairwise_test) dsa->priv_key = priv_key; dsa->pub_key = pub_key; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE pairwise_test = 1; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ ok = 1; if (pairwise_test) { diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index b773f2c5..e71a8c8f 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -27,7 +27,7 @@ static DSA *dsa_new_intern(ENGINE *engine, OPENSSL_CTX *libctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int DSA_set_ex_data(DSA *d, int idx, void *arg) { @@ -124,7 +124,7 @@ int DSA_set_method(DSA *dsa, const DSA_METHOD *meth) meth->init(dsa); return 1; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ const DSA_METHOD *DSA_get_method(DSA *d) @@ -151,7 +151,7 @@ static DSA *dsa_new_intern(ENGINE *engine, OPENSSL_CTX *libctx) ret->libctx = libctx; ret->meth = DSA_get_default_method(); -#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE) +#if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; /* early default init */ if (engine) { if (!ENGINE_init(engine)) { @@ -172,7 +172,7 @@ static DSA *dsa_new_intern(ENGINE *engine, OPENSSL_CTX *libctx) ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!crypto_new_ex_data_ex(libctx, CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data)) goto err; #endif @@ -199,7 +199,7 @@ DSA *dsa_new_with_ctx(OPENSSL_CTX *libctx) return dsa_new_intern(NULL, libctx); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE DSA *DSA_new(void) { return dsa_new_intern(NULL, NULL); @@ -221,11 +221,11 @@ void DSA_free(DSA *r) if (r->meth != NULL && r->meth->finish != NULL) r->meth->finish(r); -#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE) +#if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) ENGINE_finish(r->engine); #endif -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); #endif @@ -430,7 +430,7 @@ int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits) if ((ret = dsa_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, @@ -452,7 +452,7 @@ int EVP_PKEY_CTX_set_dsa_paramgen_q_bits(EVP_PKEY_CTX *ctx, int qbits) if ((ret = dsa_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, @@ -475,7 +475,7 @@ int EVP_PKEY_CTX_set_dsa_paramgen_md_props(EVP_PKEY_CTX *ctx, if ((ret = dsa_paramgen_check(ctx)) <= 0) return ret; -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): Remove this eventually when no more legacy */ if (ctx->op.keymgmt.genctx == NULL) { const EVP_MD *md = EVP_get_digestbyname(md_name); @@ -495,7 +495,7 @@ int EVP_PKEY_CTX_set_dsa_paramgen_md_props(EVP_PKEY_CTX *ctx, return EVP_PKEY_CTX_set_params(ctx, params); } -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) int EVP_PKEY_CTX_set_dsa_paramgen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { const char *md_name = (md == NULL) ? "" : EVP_MD_name(md); diff --git a/crypto/dsa/dsa_local.h b/crypto/dsa/dsa_local.h index b841595c..7b43ec61 100644 --- a/crypto/dsa/dsa_local.h +++ b/crypto/dsa/dsa_local.h @@ -25,7 +25,7 @@ struct dsa_st { /* Normally used to cache montgomery values */ BN_MONT_CTX *method_mont_p; CRYPTO_REF_COUNT references; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_EX_DATA ex_data; #endif const DSA_METHOD *meth; diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index 7288832e..b52fa1c0 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -50,12 +50,12 @@ static DSA_METHOD openssl_dsa_meth = { static const DSA_METHOD *default_DSA_method = &openssl_dsa_meth; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE void DSA_set_default_method(const DSA_METHOD *meth) { default_DSA_method = meth; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ const DSA_METHOD *DSA_get_default_method(void) { diff --git a/crypto/dso/dso_dlfcn.c b/crypto/dso/dso_dlfcn.c index b01c2f6a..b8bbed87 100644 --- a/crypto/dso/dso_dlfcn.c +++ b/crypto/dso/dso_dlfcn.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,6 +19,8 @@ #include "dso_local.h" #include "e_os.h" +DEFINE_STACK_OF(void) + #ifdef DSO_DLFCN # ifdef HAVE_DLFCN_H diff --git a/crypto/dso/dso_lib.c b/crypto/dso/dso_lib.c index a464c391..6c347b58 100644 --- a/crypto/dso/dso_lib.c +++ b/crypto/dso/dso_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -10,6 +10,8 @@ #include "dso_local.h" #include "internal/refcount.h" +DEFINE_STACK_OF(void) + static DSO_METHOD *default_DSO_meth = NULL; static DSO *DSO_new_method(DSO_METHOD *meth) diff --git a/crypto/dso/dso_win32.c b/crypto/dso/dso_win32.c index adf2e636..49e7100c 100644 --- a/crypto/dso/dso_win32.c +++ b/crypto/dso/dso_win32.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -69,6 +69,8 @@ static void *win32_globallookup(const char *name); static const char *openssl_strnchr(const char *string, int c, size_t len); +DEFINE_STACK_OF(void) + static DSO_METHOD dso_meth_win32 = { "OpenSSL 'win32' shared library method", win32_load, diff --git a/crypto/ec/ec2_oct.c b/crypto/ec/ec2_oct.c index d4a7a1ab..78eea869 100644 --- a/crypto/ec/ec2_oct.c +++ b/crypto/ec/ec2_oct.c @@ -43,7 +43,7 @@ int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, { BIGNUM *tmp, *x, *y, *z; int ret = 0, z0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; /* clear error queue */ @@ -81,7 +81,7 @@ int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, if (!BN_GF2m_add(tmp, x, tmp)) goto err; if (!BN_GF2m_mod_solve_quad_arr(z, tmp, group->poly, ctx)) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE unsigned long err = ERR_peek_last_error(); if (ERR_GET_LIB(err) == ERR_LIB_BN @@ -113,7 +113,7 @@ int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -132,7 +132,7 @@ size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, int used_ctx = 0; BIGNUM *x, *y, *yxi; size_t field_len, i, skip; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif @@ -168,7 +168,7 @@ size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, goto err; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) @@ -236,7 +236,7 @@ size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, if (used_ctx) BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -244,7 +244,7 @@ size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, err: if (used_ctx) BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return 0; @@ -263,7 +263,7 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, BIGNUM *x, *y, *yxi; size_t field_len, enc_len; int ret = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif @@ -305,7 +305,7 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, return 0; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) @@ -358,7 +358,7 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; diff --git a/crypto/ec/ec2_smpl.c b/crypto/ec/ec2_smpl.c index 5d921b66..98d12892 100644 --- a/crypto/ec/ec2_smpl.c +++ b/crypto/ec/ec2_smpl.c @@ -182,7 +182,7 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, { int ret = 0; BIGNUM *b; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; if (ctx == NULL) { @@ -213,7 +213,7 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -361,7 +361,7 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, { BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t; int ret = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif @@ -377,7 +377,7 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) @@ -467,7 +467,7 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -514,7 +514,7 @@ int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif @@ -528,7 +528,7 @@ int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, if (!point->Z_is_one) return -1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) @@ -566,7 +566,7 @@ int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -584,7 +584,7 @@ int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, { BIGNUM *aX, *aY, *bX, *bY; int ret = -1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif @@ -599,7 +599,7 @@ int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, return ((BN_cmp(a->X, b->X) == 0) && BN_cmp(a->Y, b->Y) == 0) ? 0 : 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) @@ -623,7 +623,7 @@ int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -635,14 +635,14 @@ int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point, { BIGNUM *x, *y; int ret = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif if (point->Z_is_one || EC_POINT_is_at_infinity(group, point)) return 1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) @@ -670,7 +670,7 @@ int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c index fcd03965..b2c91efb 100644 --- a/crypto/ec/ec_asn1.c +++ b/crypto/ec/ec_asn1.c @@ -21,7 +21,7 @@ #include "internal/nelem.h" #include "crypto/asn1_dsa.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int EC_GROUP_get_basis_type(const EC_GROUP *group) { @@ -1237,7 +1237,7 @@ int i2o_ECPublicKey(const EC_KEY *a, unsigned char **out) DECLARE_ASN1_FUNCTIONS(ECDSA_SIG) DECLARE_ASN1_ENCODE_FUNCTIONS_name(ECDSA_SIG, ECDSA_SIG) -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ ECDSA_SIG *ECDSA_SIG_new(void) { diff --git a/crypto/ec/ec_check.c b/crypto/ec/ec_check.c index aba437a5..a29519cc 100644 --- a/crypto/ec/ec_check.c +++ b/crypto/ec/ec_check.c @@ -45,7 +45,7 @@ int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only, int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* * ECC domain parameter validation. * See SP800-56A R3 5.5.2 "Assurances of Domain-Parameter Validity" Part 1b. @@ -114,5 +114,5 @@ int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx) BN_CTX_free(new_ctx); EC_POINT_free(point); return ret; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ } diff --git a/crypto/ec/ec_ctrl.c b/crypto/ec/ec_ctrl.c index 314ebe61..9e12b9a1 100644 --- a/crypto/ec/ec_ctrl.c +++ b/crypto/ec/ec_ctrl.c @@ -463,7 +463,7 @@ int EVP_PKEY_CTX_get_ec_paramgen_curve_name(EVP_PKEY_CTX *ctx, return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid) { if (ctx == NULL || !EVP_PKEY_CTX_IS_GEN_OP(ctx)) { diff --git a/crypto/ec/ec_curve.c b/crypto/ec/ec_curve.c index 86e29217..9f929883 100644 --- a/crypto/ec/ec_curve.c +++ b/crypto/ec/ec_curve.c @@ -200,7 +200,7 @@ static const struct { } }; -# ifndef FIPS_MODE +# ifndef FIPS_MODULE /* the x9.62 prime curves (minus the nist prime curves) */ static const struct { EC_CURVE_DATA h; @@ -379,7 +379,7 @@ static const struct { 0x43, 0x21, 0x46, 0x52, 0x65, 0x51 } }; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ static const struct { EC_CURVE_DATA h; @@ -419,7 +419,7 @@ static const struct { } }; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* the secg prime curves (minus the nist and x9.62 prime curves) */ static const struct { EC_CURVE_DATA h; @@ -841,13 +841,13 @@ static const struct { 0x5C, 0x5C, 0x2A, 0x3D } }; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ #ifndef OPENSSL_NO_EC2M /* characteristic two curves */ -# ifndef FIPS_MODE +# ifndef FIPS_MODULE static const struct { EC_CURVE_DATA h; unsigned char data[20 + 15 * 6]; @@ -975,7 +975,7 @@ static const struct { 0x33, 0x04, 0x9B, 0xA9, 0x8F } }; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ static const struct { EC_CURVE_DATA h; @@ -1007,7 +1007,7 @@ static const struct { } }; -# ifndef FIPS_MODE +# ifndef FIPS_MODULE static const struct { EC_CURVE_DATA h; unsigned char data[0 + 21 * 6]; @@ -1036,7 +1036,7 @@ static const struct { 0xAA, 0xB6, 0x89, 0xC2, 0x9C, 0xA7, 0x10, 0x27, 0x9B } }; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ static const struct { EC_CURVE_DATA h; @@ -1067,7 +1067,7 @@ static const struct { } }; -# ifndef FIPS_MODE +# ifndef FIPS_MODULE static const struct { EC_CURVE_DATA h; unsigned char data[20 + 25 * 6]; @@ -1143,7 +1143,7 @@ static const struct { 0xD5 } }; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ static const struct { EC_CURVE_DATA h; @@ -1219,7 +1219,7 @@ static const struct { } }; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static const struct { EC_CURVE_DATA h; unsigned char data[0 + 30 * 6]; @@ -1255,7 +1255,7 @@ static const struct { 0x1D, 0xA8, 0x00, 0xE4, 0x78, 0xA5 } }; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ static const struct { EC_CURVE_DATA h; @@ -1539,7 +1539,7 @@ static const struct { } }; -# ifndef FIPS_MODE +# ifndef FIPS_MODULE static const struct { EC_CURVE_DATA h; unsigned char data[20 + 21 * 6]; @@ -2224,7 +2224,7 @@ static const struct { 0xED, 0xF9, 0x7C, 0x44, 0xDB, 0x9F, 0x24, 0x20, 0xBA, 0xFC, 0xA7, 0x5E } }; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ #endif /* OPENSSL_NO_EC2M */ /* @@ -2235,7 +2235,7 @@ static const struct { * generation mechanism is different from those defined in ANSI X9.62. */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static const struct { EC_CURVE_DATA h; unsigned char data[0 + 20 * 6]; @@ -2775,9 +2775,9 @@ static const struct { 0x9C, 0xA9, 0x00, 0x69 } }; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ -#if !defined(OPENSSL_NO_SM2) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_SM2) && !defined(FIPS_MODULE) static const struct { EC_CURVE_DATA h; unsigned char data[0 + 32 * 6]; @@ -2824,7 +2824,7 @@ typedef struct _ec_list_element_st { const char *comment; } ec_list_element; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE static const ec_list_element curve_list[] = { /* prime field curves */ /* secg curves */ @@ -3113,7 +3113,7 @@ static const ec_list_element curve_list[] = { "SM2 curve over a 256 bit prime field"}, # endif }; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ #define curve_list_length OSSL_NELEM(curve_list) @@ -3165,7 +3165,7 @@ int ec_curve_name2nid(const char *name) if ((nid = EC_curve_nist2nid(name)) != NID_undef) return nid; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * TODO(3.0) Figure out if we can use other names than the NIST names * ("B-163", "K-163" & "P-192") in the FIPS module, or if other names @@ -3302,7 +3302,7 @@ EC_GROUP *EC_GROUP_new_by_curve_name_ex(OPENSSL_CTX *libctx, int nid) return ret; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE EC_GROUP *EC_GROUP_new_by_curve_name(int nid) { return EC_GROUP_new_by_curve_name_ex(NULL, nid); diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c index 72dd4a02..421e87d9 100644 --- a/crypto/ec/ec_key.c +++ b/crypto/ec/ec_key.c @@ -26,7 +26,7 @@ static int ecdsa_keygen_pairwise_test(EC_KEY *eckey, OSSL_CALLBACK *cb, void *cbarg); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE EC_KEY *EC_KEY_new(void) { return ec_key_new_method_int(NULL, NULL); @@ -56,7 +56,7 @@ EC_KEY *EC_KEY_new_by_curve_name_ex(OPENSSL_CTX *ctx, int nid) return ret; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE EC_KEY *EC_KEY_new_by_curve_name(int nid) { return EC_KEY_new_by_curve_name_ex(NULL, nid); @@ -79,14 +79,14 @@ void EC_KEY_free(EC_KEY *r) if (r->meth != NULL && r->meth->finish != NULL) r->meth->finish(r); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(r->engine); #endif if (r->group && r->group->meth->keyfinish) r->group->meth->keyfinish(r); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data); #endif CRYPTO_THREAD_lock_free(r->lock); @@ -108,7 +108,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) dest->meth->finish(dest); if (dest->group && dest->group->meth->keyfinish) dest->group->meth->keyfinish(dest); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if (ENGINE_finish(dest->engine) == 0) return 0; dest->engine = NULL; @@ -156,14 +156,14 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) dest->conv_form = src->conv_form; dest->version = src->version; dest->flags = src->flags; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_EC_KEY, &dest->ex_data, &src->ex_data)) return NULL; #endif if (src->meth != dest->meth) { -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if (src->engine != NULL && ENGINE_init(src->engine) == 0) return NULL; dest->engine = src->engine; @@ -312,9 +312,9 @@ int ec_generate_key(OPENSSL_CTX *libctx, EC_KEY *eckey, int pairwise_test) eckey->dirty_cnt++; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE pairwise_test = 1; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ ok = 1; if (pairwise_test) { diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c index 9ba4f0dd..1f305710 100644 --- a/crypto/ec/ec_kmeth.c +++ b/crypto/ec/ec_kmeth.c @@ -65,7 +65,7 @@ int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth) if (finish != NULL) finish(key); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(key->engine); key->engine = NULL; #endif @@ -96,7 +96,7 @@ EC_KEY *ec_key_new_method_int(OPENSSL_CTX *libctx, ENGINE *engine) } ret->meth = EC_KEY_get_default_method(); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if (engine != NULL) { if (!ENGINE_init(engine)) { ECerr(EC_F_EC_KEY_NEW_METHOD_INT, ERR_R_ENGINE_LIB); @@ -118,7 +118,7 @@ EC_KEY *ec_key_new_method_int(OPENSSL_CTX *libctx, ENGINE *engine) ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; /* No ex_data inside the FIPS provider */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) { goto err; } @@ -135,7 +135,7 @@ EC_KEY *ec_key_new_method_int(OPENSSL_CTX *libctx, ENGINE *engine) return NULL; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE EC_KEY *EC_KEY_new_method(ENGINE *engine) { return ec_key_new_method_int(NULL, engine); diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index 16fe437d..cdeffb42 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -65,7 +65,7 @@ EC_GROUP *EC_GROUP_new_ex(OPENSSL_CTX *libctx, const EC_METHOD *meth) return NULL; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE EC_GROUP *EC_GROUP_new(const EC_METHOD *meth) { return EC_GROUP_new_ex(NULL, meth); @@ -597,7 +597,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) { int r = 0; BIGNUM *a1, *a2, *a3, *b1, *b2, *b3; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *ctx_new = NULL; #endif @@ -612,7 +612,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) if (a->meth->flags & EC_FLAGS_CUSTOM_CURVE) return 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) ctx_new = ctx = BN_CTX_new(); #endif @@ -628,7 +628,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) b3 = BN_CTX_get(ctx); if (b3 == NULL) { BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(ctx_new); #endif return -1; @@ -680,7 +680,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) } end: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(ctx_new); #endif return r; @@ -1041,13 +1041,14 @@ int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, * methods. */ +#ifndef OPENSSL_NO_DEPRECATED_3_0 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) { int ret = 0; size_t i = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif @@ -1066,7 +1067,7 @@ int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, } } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) ctx = new_ctx = BN_CTX_secure_new(); #endif @@ -1081,26 +1082,51 @@ int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, /* use default */ ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; } +#endif int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx) { - /* just a convenient interface to EC_POINTs_mul() */ + int ret = 0; +#ifndef FIPS_MODULE + BN_CTX *new_ctx = NULL; +#endif - const EC_POINT *points[1]; - const BIGNUM *scalars[1]; + if (!ec_point_is_compat(r, group) + || (point != NULL && !ec_point_is_compat(point, group))) { + ECerr(EC_F_EC_POINT_MUL, EC_R_INCOMPATIBLE_OBJECTS); + return 0; + } - points[0] = point; - scalars[0] = p_scalar; + if (g_scalar == NULL && p_scalar == NULL) + return EC_POINT_set_to_infinity(group, r); - return EC_POINTs_mul(group, r, g_scalar, - (point != NULL - && p_scalar != NULL), points, scalars, ctx); +#ifndef FIPS_MODULE + if (ctx == NULL) + ctx = new_ctx = BN_CTX_secure_new(); +#endif + if (ctx == NULL) { + ECerr(EC_F_EC_POINT_MUL, ERR_R_INTERNAL_ERROR); + return 0; + } + + if (group->meth->mul != NULL) + ret = group->meth->mul(group, r, g_scalar, point != NULL + && p_scalar != NULL, &point, &p_scalar, ctx); + else + /* use default */ + ret = ec_wNAF_mul(group, r, g_scalar, point != NULL + && p_scalar != NULL, &point, &p_scalar, ctx); + +#ifndef FIPS_MODULE + BN_CTX_free(new_ctx); +#endif + return ret; } int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx) @@ -1161,7 +1187,7 @@ static int ec_precompute_mont_data(EC_GROUP *group) return ret; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg) { return CRYPTO_set_ex_data(&key->ex_data, idx, arg); @@ -1185,14 +1211,14 @@ static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r, { BIGNUM *e = NULL; int ret = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif if (group->mont_data == NULL) return 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) ctx = new_ctx = BN_CTX_secure_new(); #endif @@ -1222,7 +1248,7 @@ static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r, err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; diff --git a/crypto/ec/ec_local.h b/crypto/ec/ec_local.h index 63e672af..d9383f10 100644 --- a/crypto/ec/ec_local.h +++ b/crypto/ec/ec_local.h @@ -288,7 +288,7 @@ struct ec_key_st { point_conversion_form_t conv_form; CRYPTO_REF_COUNT references; int flags; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_EX_DATA ex_data; #endif CRYPTO_RWLOCK *lock; diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c index 385a4789..33721845 100644 --- a/crypto/ec/ec_mult.c +++ b/crypto/ec/ec_mult.c @@ -833,7 +833,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) EC_POINT **points = NULL; EC_PRE_COMP *pre_comp; int ret = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif @@ -848,7 +848,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) goto err; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) ctx = new_ctx = BN_CTX_new(); #endif @@ -965,7 +965,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif EC_ec_pre_comp_free(pre_comp); diff --git a/crypto/ec/ecp_nistp224.c b/crypto/ec/ecp_nistp224.c index f0c0ad94..1808c4c7 100644 --- a/crypto/ec/ecp_nistp224.c +++ b/crypto/ec/ecp_nistp224.c @@ -1299,7 +1299,7 @@ int ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p, { int ret = 0; BIGNUM *curve_p, *curve_a, *curve_b; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; if (ctx == NULL) @@ -1326,7 +1326,7 @@ int ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p, ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -1617,14 +1617,14 @@ int ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx) BIGNUM *x, *y; EC_POINT *generator = NULL; felem tmp_felems[32]; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif /* throw away old precomputation */ EC_pre_comp_free(group); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) ctx = new_ctx = BN_CTX_new(); #endif @@ -1738,7 +1738,7 @@ int ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx) err: BN_CTX_end(ctx); EC_POINT_free(generator); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif EC_nistp224_pre_comp_free(pre); diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c index 70f5792e..fb9b2255 100644 --- a/crypto/ec/ecp_nistp256.c +++ b/crypto/ec/ecp_nistp256.c @@ -1912,7 +1912,7 @@ int ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p, { int ret = 0; BIGNUM *curve_p, *curve_a, *curve_b; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; if (ctx == NULL) @@ -1939,7 +1939,7 @@ int ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p, ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -2239,14 +2239,14 @@ int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx) EC_POINT *generator = NULL; smallfelem tmp_smallfelems[32]; felem x_tmp, y_tmp, z_tmp; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif /* throw away old precomputation */ EC_pre_comp_free(group); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) ctx = new_ctx = BN_CTX_new(); #endif @@ -2370,7 +2370,7 @@ int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx) err: BN_CTX_end(ctx); EC_POINT_free(generator); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif EC_nistp256_pre_comp_free(pre); diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c index db99b963..28e048ed 100644 --- a/crypto/ec/ecp_nistp521.c +++ b/crypto/ec/ecp_nistp521.c @@ -1752,7 +1752,7 @@ int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, { int ret = 0; BIGNUM *curve_p, *curve_a, *curve_b; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; if (ctx == NULL) @@ -1779,7 +1779,7 @@ int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); err: BN_CTX_end(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif return ret; @@ -2075,14 +2075,14 @@ int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx) BIGNUM *x, *y; EC_POINT *generator = NULL; felem tmp_felems[16]; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX *new_ctx = NULL; #endif /* throw away old precomputation */ EC_pre_comp_free(group); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (ctx == NULL) ctx = new_ctx = BN_CTX_new(); #endif @@ -2176,7 +2176,7 @@ int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx) err: BN_CTX_end(ctx); EC_POINT_free(generator); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BN_CTX_free(new_ctx); #endif EC_nistp521_pre_comp_free(pre); diff --git a/crypto/ec/ecp_oct.c b/crypto/ec/ecp_oct.c index 57a196cf..38d661e1 100644 --- a/crypto/ec/ecp_oct.c +++ b/crypto/ec/ecp_oct.c @@ -28,7 +28,7 @@ int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, BIGNUM *tmp1, *tmp2, *x, *y; int ret = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* clear error queue */ ERR_clear_error(); #endif @@ -107,7 +107,7 @@ int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, } if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE unsigned long err = ERR_peek_last_error(); if (ERR_GET_LIB(err) == ERR_LIB_BN diff --git a/crypto/ec/ecx_backend.c b/crypto/ec/ecx_backend.c index e6133370..042f9ca8 100644 --- a/crypto/ec/ecx_backend.c +++ b/crypto/ec/ecx_backend.c @@ -9,6 +9,8 @@ #include #include +#include +#include #include "crypto/ecx.h" #include "ecx_backend.h" @@ -18,10 +20,35 @@ * implementations alike. */ +int ecx_public_from_private(ECX_KEY *key) +{ + switch (key->type) { + case ECX_KEY_TYPE_X25519: + X25519_public_from_private(key->pubkey, key->privkey); + break; + case ECX_KEY_TYPE_ED25519: + if (!ED25519_public_from_private(key->libctx, key->pubkey, key->privkey)) { + ECerr(0, EC_R_FAILED_MAKING_PUBLIC_KEY); + return 0; + } + break; + case ECX_KEY_TYPE_X448: + X448_public_from_private(key->pubkey, key->privkey); + break; + case ECX_KEY_TYPE_ED448: + if (!ED448_public_from_private(key->libctx, key->pubkey, key->privkey)) { + ECerr(0, EC_R_FAILED_MAKING_PUBLIC_KEY); + return 0; + } + break; + } + return 1; +} + int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[], int include_private) { - size_t privkeylen = 0, pubkeylen; + size_t privkeylen = 0, pubkeylen = 0; const OSSL_PARAM *param_priv_key = NULL, *param_pub_key; unsigned char *pubkey; @@ -32,11 +59,8 @@ int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[], if (include_private) param_priv_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY); - /* - * If a private key is present then a public key must also be present. - * Alternatively we've just got a public key. - */ - if (param_pub_key == NULL) + + if (param_pub_key == NULL && param_priv_key == NULL) return 0; if (param_priv_key != NULL @@ -46,15 +70,19 @@ int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[], return 0; pubkey = ecx->pubkey; - if (!OSSL_PARAM_get_octet_string(param_pub_key, - (void **)&pubkey, - sizeof(ecx->pubkey), &pubkeylen)) + if (param_pub_key != NULL + && !OSSL_PARAM_get_octet_string(param_pub_key, + (void **)&pubkey, + sizeof(ecx->pubkey), &pubkeylen)) return 0; - if (pubkeylen != ecx->keylen + if ((param_pub_key != NULL && pubkeylen != ecx->keylen) || (param_priv_key != NULL && privkeylen != ecx->keylen)) return 0; + if (param_pub_key == NULL && !ecx_public_from_private(ecx)) + return 0; + ecx->haspubkey = 1; return 1; diff --git a/crypto/ec/ecx_backend.h b/crypto/ec/ecx_backend.h index 50ece17a..2c012947 100644 --- a/crypto/ec/ecx_backend.h +++ b/crypto/ec/ecx_backend.h @@ -13,8 +13,8 @@ : ((id) == EVP_PKEY_X448 ? X448_KEYLEN \ : ED448_KEYLEN)) #define KEYNID2TYPE(id) \ - (IS25519(id) ? ECX_KEY_TYPE_X25519 \ + (IS25519(id) ? ((id) == EVP_PKEY_X25519 ? ECX_KEY_TYPE_X25519 \ + : ECX_KEY_TYPE_ED25519) \ : ((id) == EVP_PKEY_X448 ? ECX_KEY_TYPE_X448 \ - : ((id) == EVP_PKEY_ED25519 ? ECX_KEY_TYPE_ED25519 \ - : ECX_KEY_TYPE_ED448))) + : ECX_KEY_TYPE_ED448)) #define KEYLEN(p) KEYLENID((p)->ameth->pkey_id) diff --git a/crypto/ec/ecx_key.c b/crypto/ec/ecx_key.c index 0b43d26a..46abd57a 100644 --- a/crypto/ec/ecx_key.c +++ b/crypto/ec/ecx_key.c @@ -10,13 +10,14 @@ #include #include "crypto/ecx.h" -ECX_KEY *ecx_key_new(ECX_KEY_TYPE type, int haspubkey) +ECX_KEY *ecx_key_new(OPENSSL_CTX *libctx, ECX_KEY_TYPE type, int haspubkey) { ECX_KEY *ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) return NULL; + ret->libctx = libctx; ret->haspubkey = haspubkey; switch (type) { case ECX_KEY_TYPE_X25519: diff --git a/crypto/ec/ecx_meth.c b/crypto/ec/ecx_meth.c index d23fcd42..eedb1c92 100644 --- a/crypto/ec/ecx_meth.c +++ b/crypto/ec/ecx_meth.c @@ -59,7 +59,7 @@ static int ecx_key_op(EVP_PKEY *pkey, int id, const X509_ALGOR *palg, } } - key = ecx_key_new(KEYNID2TYPE(id), 1); + key = ecx_key_new(libctx, KEYNID2TYPE(id), 1); if (key == NULL) { ECerr(EC_F_ECX_KEY_OP, ERR_R_MALLOC_FAILURE); return 0; @@ -88,25 +88,9 @@ static int ecx_key_op(EVP_PKEY *pkey, int id, const X509_ALGOR *palg, } else { memcpy(privkey, p, KEYLENID(id)); } - switch (id) { - case EVP_PKEY_X25519: - X25519_public_from_private(pubkey, privkey); - break; - case EVP_PKEY_ED25519: - if (!ED25519_public_from_private(libctx, pubkey, privkey)) { - ECerr(EC_F_ECX_KEY_OP, EC_R_FAILED_MAKING_PUBLIC_KEY); - return 0; - } - break; - case EVP_PKEY_X448: - X448_public_from_private(pubkey, privkey); - break; - case EVP_PKEY_ED448: - if (!ED448_public_from_private(libctx, pubkey, privkey)) { - ECerr(EC_F_ECX_KEY_OP, EC_R_FAILED_MAKING_PUBLIC_KEY); - return 0; - } - break; + if (!ecx_public_from_private(key)) { + ECerr(EC_F_ECX_KEY_OP, EC_R_FAILED_MAKING_PUBLIC_KEY); + goto err; } } @@ -455,7 +439,7 @@ static int ecx_generic_import_from(const OSSL_PARAM params[], void *vpctx, { EVP_PKEY_CTX *pctx = vpctx; EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(pctx); - ECX_KEY *ecx = ecx_key_new(KEYNID2TYPE(keytype), 0); + ECX_KEY *ecx = ecx_key_new(pctx->libctx, KEYNID2TYPE(keytype), 0); if (ecx == NULL) { ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); @@ -963,7 +947,7 @@ static int s390x_pkey_ecx_keygen25519(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X25519, 1); + ECX_KEY *key = ecx_key_new(ctx->libctx, ECX_KEY_TYPE_X25519, 1); unsigned char *privkey = NULL, *pubkey; if (key == NULL) { @@ -1005,7 +989,7 @@ static int s390x_pkey_ecx_keygen448(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X448, 1); + ECX_KEY *key = ecx_key_new(ctx->libctx, ECX_KEY_TYPE_X448, 1); unsigned char *privkey = NULL, *pubkey; if (key == NULL) { @@ -1050,7 +1034,7 @@ static int s390x_pkey_ecd_keygen25519(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, }; unsigned char x_dst[32], buff[SHA512_DIGEST_LENGTH]; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED25519, 1); + ECX_KEY *key = ecx_key_new(ctx->libctx, ECX_KEY_TYPE_ED25519, 1); unsigned char *privkey = NULL, *pubkey; unsigned int sz; @@ -1107,7 +1091,7 @@ static int s390x_pkey_ecd_keygen448(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 0x24, 0xbc, 0xb6, 0x6e, 0x71, 0x46, 0x3f, 0x69, 0x00 }; unsigned char x_dst[57], buff[114]; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED448, 1); + ECX_KEY *key = ecx_key_new(ctx->libctx, ECX_KEY_TYPE_ED448, 1); unsigned char *privkey = NULL, *pubkey; EVP_MD_CTX *hashctx = NULL; diff --git a/crypto/engine/eng_cnf.c b/crypto/engine/eng_cnf.c index 22198194..0ddad7dd 100644 --- a/crypto/engine/eng_cnf.c +++ b/crypto/engine/eng_cnf.c @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,6 +11,8 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) + /* ENGINE config module */ static const char *skip_dot(const char *name) diff --git a/crypto/engine/eng_dyn.c b/crypto/engine/eng_dyn.c index 15504410..798ff1e3 100644 --- a/crypto/engine/eng_dyn.c +++ b/crypto/engine/eng_dyn.c @@ -1,5 +1,5 @@ /* - * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,8 @@ * prototypes. */ +DEFINE_STACK_OF_STRING() + /* Our ENGINE handlers */ static int dynamic_init(ENGINE *e); static int dynamic_finish(ENGINE *e); diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt index 044ea94f..39779f42 100644 --- a/crypto/err/openssl.txt +++ b/crypto/err/openssl.txt @@ -696,6 +696,7 @@ EC_F_EC_POINT_INVERT:210:EC_POINT_invert EC_F_EC_POINT_IS_AT_INFINITY:118:EC_POINT_is_at_infinity EC_F_EC_POINT_IS_ON_CURVE:119:EC_POINT_is_on_curve EC_F_EC_POINT_MAKE_AFFINE:120:EC_POINT_make_affine +EC_F_EC_POINT_MUL:309: EC_F_EC_POINT_NEW:121:EC_POINT_new EC_F_EC_POINT_OCT2POINT:122:EC_POINT_oct2point EC_F_EC_POINT_POINT2BUF:281:EC_POINT_point2buf @@ -948,6 +949,7 @@ OCSP_F_OCSP_MATCH_ISSUERID:109:ocsp_match_issuerid OCSP_F_OCSP_REQUEST_SIGN:110:OCSP_request_sign OCSP_F_OCSP_REQUEST_VERIFY:116:OCSP_request_verify OCSP_F_OCSP_RESPONSE_GET1_BASIC:111:OCSP_response_get1_basic +OSSL_STORE_F_FILE_ATTACH:128: OSSL_STORE_F_FILE_CTRL:129:file_ctrl OSSL_STORE_F_FILE_FIND:138:file_find OSSL_STORE_F_FILE_GET_PASS:118:file_get_pass @@ -955,10 +957,8 @@ OSSL_STORE_F_FILE_LOAD:119:file_load OSSL_STORE_F_FILE_LOAD_TRY_DECODE:124:file_load_try_decode OSSL_STORE_F_FILE_NAME_TO_URI:126:file_name_to_uri OSSL_STORE_F_FILE_OPEN:120:file_open -OSSL_STORE_F_OSSL_STORE_ATTACH_PEM_BIO:127:ossl_store_attach_pem_bio +OSSL_STORE_F_OSSL_STORE_ATTACH:127: OSSL_STORE_F_OSSL_STORE_EXPECT:130:OSSL_STORE_expect -OSSL_STORE_F_OSSL_STORE_FILE_ATTACH_PEM_BIO_INT:128:\ - ossl_store_file_attach_pem_bio_int OSSL_STORE_F_OSSL_STORE_FIND:131:OSSL_STORE_find OSSL_STORE_F_OSSL_STORE_GET0_LOADER_INT:100:ossl_store_get0_loader_int OSSL_STORE_F_OSSL_STORE_INFO_GET1_CERT:101:OSSL_STORE_INFO_get1_CERT @@ -1001,17 +1001,17 @@ PEM_F_D2I_PKCS8PRIVATEKEY_BIO:120:d2i_PKCS8PrivateKey_bio PEM_F_D2I_PKCS8PRIVATEKEY_FP:121:d2i_PKCS8PrivateKey_fp PEM_F_DO_B2I:132:do_b2i PEM_F_DO_B2I_BIO:133:do_b2i_bio -PEM_F_DO_BLOB_HEADER:134:do_blob_header PEM_F_DO_I2B:146:do_i2b PEM_F_DO_PK8PKEY:126:do_pk8pkey PEM_F_DO_PK8PKEY_FP:125:do_pk8pkey_fp PEM_F_DO_PVK_BODY:135:do_PVK_body -PEM_F_DO_PVK_HEADER:136:do_PVK_header PEM_F_GET_HEADER_AND_DATA:143:get_header_and_data PEM_F_GET_NAME:144:get_name PEM_F_I2B_PVK:137:i2b_PVK PEM_F_I2B_PVK_BIO:138:i2b_PVK_bio PEM_F_LOAD_IV:101:load_iv +PEM_F_OSSL_DO_BLOB_HEADER:134:ossl_do_blob_header +PEM_F_OSSL_DO_PVK_HEADER:136:ossl_do_PVK_header PEM_F_PEM_ASN1_READ:102:PEM_ASN1_read PEM_F_PEM_ASN1_READ_BIO:103:PEM_ASN1_read_bio PEM_F_PEM_ASN1_WRITE:104:PEM_ASN1_write @@ -2559,6 +2559,7 @@ EVP_R_NO_KEYMGMT_AVAILABLE:199:no keymgmt available EVP_R_NO_KEYMGMT_PRESENT:196:no keymgmt present EVP_R_NO_KEY_SET:154:no key set EVP_R_NO_OPERATION_SET:149:no operation set +EVP_R_NULL_MAC_PKEY_CTX:208:null mac pkey ctx EVP_R_ONLY_ONESHOT_SUPPORTED:177:only oneshot supported EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE:150:\ operation not supported for this keytype @@ -2571,6 +2572,7 @@ EVP_R_PKEY_APPLICATION_ASN1_METHOD_ALREADY_REGISTERED:179:\ EVP_R_PRIVATE_KEY_DECODE_ERROR:145:private key decode error EVP_R_PRIVATE_KEY_ENCODE_ERROR:146:private key encode error EVP_R_PUBLIC_KEY_NOT_RSA:106:public key not rsa +EVP_R_SET_DEFAULT_PROPERTY_FAILURE:209:set default property failure EVP_R_TOO_MANY_RECORDS:183:too many records EVP_R_UNKNOWN_CIPHER:160:unknown cipher EVP_R_UNKNOWN_DIGEST:161:unknown digest @@ -2841,6 +2843,7 @@ PROV_R_INVALID_PADDING_MODE:168:invalid padding mode PROV_R_INVALID_PSS_SALTLEN:169:invalid pss saltlen PROV_R_INVALID_SALT_LENGTH:112:invalid salt length PROV_R_INVALID_SEED_LENGTH:154:invalid seed length +PROV_R_INVALID_SIGNATURE_SIZE:179:invalid signature size PROV_R_INVALID_TAG:110:invalid tag PROV_R_INVALID_TAGLEN:118:invalid taglen PROV_R_INVALID_X931_DIGEST:170:invalid x931 digest @@ -2862,6 +2865,8 @@ PROV_R_NOT_SUPPORTED:136:not supported PROV_R_NOT_XOF_OR_INVALID_LENGTH:113:not xof or invalid length PROV_R_NO_KEY_SET:114:no key set PROV_R_NO_PARAMETERS_SET:177:no parameters set +PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE:178:\ + operation not supported for this keytype PROV_R_OUTPUT_BUFFER_TOO_SMALL:106:output buffer too small PROV_R_PSS_SALTLEN_TOO_SMALL:172:pss saltlen too small PROV_R_READ_KEY:159:read key diff --git a/crypto/ess/ess_lib.c b/crypto/ess/ess_lib.c index a2d6bfe7..9d9defa9 100644 --- a/crypto/ess/ess_lib.c +++ b/crypto/ess/ess_lib.c @@ -13,6 +13,11 @@ #include #include "crypto/ess.h" +DEFINE_STACK_OF(ESS_CERT_ID) +DEFINE_STACK_OF(ESS_CERT_ID_V2) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(GENERAL_NAME) + static ESS_CERT_ID *ESS_CERT_ID_new_init(X509 *cert, int issuer_needed); static ESS_CERT_ID_V2 *ESS_CERT_ID_V2_new_init(const EVP_MD *hash_alg, X509 *cert, int issuer_needed); diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index fba53152..91baa0d4 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -24,7 +24,7 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx) if (ctx == NULL) return 1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */ /* * pctx should be freed by the user of EVP_MD_CTX @@ -59,7 +59,7 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx) OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size); } -#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE) +#if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) ENGINE_finish(ctx->engine); #endif @@ -94,7 +94,7 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) { -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE *tmpimpl = NULL; #endif @@ -114,7 +114,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) ctx->reqdigest = type; /* TODO(3.0): Legacy work around code below. Remove this */ -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) /* * Whether it's nice or not, "Inits" can be used on "Final"'d contexts so * this context may already have an ENGINE! Try to avoid releasing the @@ -145,7 +145,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) */ if (ctx->engine != NULL || impl != NULL -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) || tmpimpl != NULL #endif || (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0) { @@ -164,7 +164,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) /* TODO(3.0): Start of non-legacy code below */ if (type->prov == NULL) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* We only do explicit fetches inside the FIPS module */ EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR); return 0; @@ -205,7 +205,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) /* TODO(3.0): Remove legacy code below */ legacy: -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if (type) { if (impl != NULL) { if (!ENGINE_init(impl)) { @@ -257,10 +257,10 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) } } } -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) skip_to_init: #endif -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * TODO(3.0): Temporarily no support for EVP_DigestSign* inside FIPS module * or when using providers. @@ -452,7 +452,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) /* copied EVP_MD_CTX should free the copied EVP_PKEY_CTX */ EVP_MD_CTX_clear_flags(out, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */ if (in->pctx != NULL) { out->pctx = EVP_PKEY_CTX_dup(in->pctx); @@ -468,7 +468,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) /* TODO(3.0): Remove legacy code below */ legacy: -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) /* Make sure it's safe to copy a digest context using an ENGINE */ if (in->engine && !ENGINE_init(in->engine)) { EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB); @@ -509,7 +509,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) out->update = in->update; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */ if (in->pctx) { out->pctx = EVP_PKEY_CTX_dup(in->pctx); @@ -724,7 +724,7 @@ EVP_MD *evp_md_new(void) * provider based, we know that none of its code depends on legacy * NIDs or any functionality that use them. */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.x) get rid of the need for legacy NIDs */ static void set_legacy_nid(const char *name, void *vlegacy_nid) { @@ -764,7 +764,7 @@ static void *evp_md_from_dispatch(int name_id, return NULL; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.x) get rid of the need for legacy NIDs */ md->type = NID_undef; evp_names_do_all(prov, name_id, set_legacy_nid, &md->type); diff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c index 39c53b55..05be2190 100644 --- a/crypto/evp/e_aes.c +++ b/crypto/evp/e_aes.c @@ -71,7 +71,7 @@ typedef struct { const unsigned char iv[16]); } EVP_AES_XTS_CTX; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE static const int allow_insecure_decrypt = 0; #else static const int allow_insecure_decrypt = 1; @@ -2901,7 +2901,7 @@ static int aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, return rv; } -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* * See SP800-38D (GCM) Section 8 "Uniqueness requirement on IVS and keys" * @@ -2923,7 +2923,7 @@ static int aes_gcm_iv_generate(EVP_AES_GCM_CTX *gctx, int offset) return 0; return 1; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t len) @@ -2937,7 +2937,7 @@ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, if (gctx->tls_aad_len >= 0) return aes_gcm_tls_cipher(ctx, out, in, len); -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* * FIPS requires generation of AES-GCM IV's inside the FIPS module. * The IV can still be set externally (the security policy will state that @@ -2954,7 +2954,7 @@ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, #else if (!gctx->iv_set) return -1; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ if (in) { if (out == NULL) { diff --git a/crypto/evp/evp_cnf.c b/crypto/evp/evp_cnf.c index 7cfa0a27..27815553 100644 --- a/crypto/evp/evp_cnf.c +++ b/crypto/evp/evp_cnf.c @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2012-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,9 +15,10 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) + /* Algorithm configuration module. */ -/* TODO(3.0): the config module functions should be passed a library context */ static int alg_module_init(CONF_IMODULE *md, const CONF *cnf) { int i; @@ -44,14 +45,17 @@ static int alg_module_init(CONF_IMODULE *md, const CONF *cnf) } /* * fips_mode is deprecated and should not be used in new - * configurations. Old configurations are likely to ONLY - * have this, so we assume that no default properties have - * been set before this. + * configurations. */ - if (m > 0) - EVP_set_default_properties(NULL, "fips=yes"); + if (!EVP_default_properties_enable_fips(cnf->libctx, m > 0)) { + EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_SET_DEFAULT_PROPERTY_FAILURE); + return 0; + } } else if (strcmp(oval->name, "default_properties") == 0) { - EVP_set_default_properties(NULL, oval->value); + if (!EVP_set_default_properties(cnf->libctx, oval->value)) { + EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_SET_DEFAULT_PROPERTY_FAILURE); + return 0; + } } else { EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_UNKNOWN_OPTION); ERR_add_error_data(4, "name=", oval->name, diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index f6d7e87f..0f7b0a7d 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -51,7 +51,7 @@ int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx) OPENSSL_cleanse(ctx->cipher_data, ctx->cipher->ctx_size); } OPENSSL_free(ctx->cipher_data); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(ctx->engine); #endif memset(ctx, 0, sizeof(*ctx)); @@ -81,7 +81,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv, int enc) { -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE *tmpimpl = NULL; #endif const EVP_CIPHER *tmpcipher; @@ -106,7 +106,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, /* TODO(3.0): Legacy work around code below. Remove this */ -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) /* * Whether it's nice or not, "Inits" can be used on "Final"'d contexts so * this context may already have an ENGINE! Try to avoid releasing the @@ -127,7 +127,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, * If there are engines involved then we should use legacy handling for now. */ if (ctx->engine != NULL -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) || tmpimpl != NULL #endif || impl != NULL) { @@ -321,7 +321,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, cipher = ctx->cipher; if (cipher->prov == NULL) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* We only do explicit fetches inside the FIPS module */ EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR); return 0; @@ -404,7 +404,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ctx->encrypt = enc; ctx->flags = flags; } -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if (impl != NULL) { if (!ENGINE_init(impl)) { EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR); @@ -460,7 +460,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, } } } -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) skip_to_init: #endif if (ctx->cipher == NULL) @@ -1340,7 +1340,7 @@ int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key) if (ctx->cipher->flags & EVP_CIPH_RAND_KEY) return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key); -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return 0; #else { @@ -1351,7 +1351,7 @@ int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key) return 0; return 1; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ } int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) @@ -1390,7 +1390,7 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) /* TODO(3.0): Remove legacy code below */ legacy: -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) /* Make sure it's safe to copy a cipher context using an ENGINE */ if (in->engine && !ENGINE_init(in->engine)) { EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, ERR_R_ENGINE_LIB); @@ -1440,7 +1440,7 @@ EVP_CIPHER *evp_cipher_new(void) * provider based, we know that none of its code depends on legacy * NIDs or any functionality that use them. */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.x) get rid of the need for legacy NIDs */ static void set_legacy_nid(const char *name, void *vlegacy_nid) { @@ -1478,7 +1478,7 @@ static void *evp_cipher_from_dispatch(const int name_id, return NULL; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.x) get rid of the need for legacy NIDs */ cipher->nid = NID_undef; evp_names_do_all(prov, name_id, set_legacy_nid, &cipher->nid); diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index 3f2b814f..0908b1ca 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -114,6 +114,7 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NO_KEYMGMT_PRESENT), "no keymgmt present"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NO_KEY_SET), "no key set"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NO_OPERATION_SET), "no operation set"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NULL_MAC_PKEY_CTX), "null mac pkey ctx"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_ONLY_ONESHOT_SUPPORTED), "only oneshot supported"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE), @@ -132,6 +133,8 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PRIVATE_KEY_ENCODE_ERROR), "private key encode error"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PUBLIC_KEY_NOT_RSA), "public key not rsa"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_SET_DEFAULT_PROPERTY_FAILURE), + "set default property failure"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_TOO_MANY_RECORDS), "too many records"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_UNKNOWN_CIPHER), "unknown cipher"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_UNKNOWN_DIGEST), "unknown digest"}, diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c index ca06b578..be5ab111 100644 --- a/crypto/evp/evp_fetch.c +++ b/crypto/evp/evp_fetch.c @@ -301,7 +301,7 @@ void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, if (ret == NULL) { int code = EVP_R_FETCH_FAILED; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE ERR_raise(ERR_LIB_EVP, code); #else ERR_raise_data(ERR_LIB_EVP, code, @@ -339,7 +339,7 @@ void *evp_generic_fetch_by_number(OPENSSL_CTX *libctx, int operation_id, if (ret == NULL) { int code = EVP_R_FETCH_FAILED; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE ERR_raise(ERR_LIB_EVP, code); #else { @@ -367,10 +367,42 @@ int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq) if (store != NULL) return ossl_method_store_set_global_properties(store, propq); - EVPerr(EVP_F_EVP_SET_DEFAULT_PROPERTIES, ERR_R_INTERNAL_ERROR); + EVPerr(0, ERR_R_INTERNAL_ERROR); return 0; } + +static int evp_default_properties_merge(OPENSSL_CTX *libctx, const char *propq) +{ + OSSL_METHOD_STORE *store = get_evp_method_store(libctx); + + if (store != NULL) + return ossl_method_store_merge_global_properties(store, propq); + EVPerr(0, ERR_R_INTERNAL_ERROR); + return 0; +} + +static int evp_default_property_is_enabled(OPENSSL_CTX *libctx, + const char *prop_name) +{ + OSSL_METHOD_STORE *store = get_evp_method_store(libctx); + + return ossl_method_store_global_property_is_enabled(store, prop_name); +} + +int EVP_default_properties_is_fips_enabled(OPENSSL_CTX *libctx) +{ + return evp_default_property_is_enabled(libctx, "fips"); +} + +int EVP_default_properties_enable_fips(OPENSSL_CTX *libctx, int enable) +{ + const char *query = (enable != 0) ? "fips=yes" : "-fips"; + + return evp_default_properties_merge(libctx, query); +} + + struct do_all_data_st { void (*user_fn)(void *method, void *arg); void *user_arg; diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index d5f758fb..22948510 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -18,7 +18,7 @@ #include "internal/provider.h" #include "evp_local.h" -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type) { int ret = -1; /* Assume the worst */ @@ -206,7 +206,7 @@ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) } return i; } -#endif /* !defined(FIPS_MODE) */ +#endif /* !defined(FIPS_MODULE) */ /* Convert the various cipher NIDs and dummies to a proper OID NID */ int EVP_CIPHER_type(const EVP_CIPHER *ctx) @@ -258,7 +258,7 @@ int EVP_CIPHER_type(const EVP_CIPHER *ctx) return NID_des_cfb64; default: -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return NID_undef; #else { @@ -548,7 +548,7 @@ const char *EVP_CIPHER_name(const EVP_CIPHER *cipher) { if (cipher->prov != NULL) return evp_first_name(cipher->prov, cipher->name_id); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE return OBJ_nid2sn(EVP_CIPHER_nid(cipher)); #else return NULL; @@ -589,7 +589,7 @@ const char *EVP_MD_name(const EVP_MD *md) { if (md->prov != NULL) return evp_first_name(md->prov, md->name_id); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE return OBJ_nid2sn(EVP_MD_nid(md)); #else return NULL; @@ -844,7 +844,7 @@ EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) return ctx->pctx; } -#if !defined(FIPS_MODE) +#if !defined(FIPS_MODULE) /* TODO(3.0): EVP_DigestSign* not yet supported in FIPS module */ void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) { @@ -864,7 +864,7 @@ void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); } } -#endif /* !defined(FIPS_MODE) */ +#endif /* !defined(FIPS_MODULE) */ void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) { diff --git a/crypto/evp/evp_local.h b/crypto/evp/evp_local.h index 4c822aa7..de7d69a2 100644 --- a/crypto/evp/evp_local.h +++ b/crypto/evp/evp_local.h @@ -86,8 +86,6 @@ struct evp_keymgmt_st { OSSL_OP_keymgmt_gen_set_template_fn *gen_set_template; OSSL_OP_keymgmt_gen_set_params_fn *gen_set_params; OSSL_OP_keymgmt_gen_settable_params_fn *gen_settable_params; - OSSL_OP_keymgmt_gen_get_params_fn *gen_get_params; - OSSL_OP_keymgmt_gen_gettable_params_fn *gen_gettable_params; OSSL_OP_keymgmt_gen_fn *gen; OSSL_OP_keymgmt_gen_cleanup_fn *gen_cleanup; diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index 8b2c0772..26d7e1ce 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -264,6 +264,7 @@ int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) return ret ? 1 : 0; err: + evp_pkey_ctx_free_old_ops(ctx); ctx->operation = EVP_PKEY_OP_UNDEFINED; return 0; @@ -275,7 +276,7 @@ int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) */ ERR_pop_to_mark(); -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return 0; #else if (ctx->pmeth == NULL || ctx->pmeth->derive == NULL) { @@ -323,7 +324,7 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) return ctx->op.kex.exchange->set_peer(ctx->op.kex.exchprovctx, provkey); legacy: -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return ret; #else /* diff --git a/crypto/evp/keymgmt_lib.c b/crypto/evp/keymgmt_lib.c index 3493ceb3..54805d74 100644 --- a/crypto/evp/keymgmt_lib.c +++ b/crypto/evp/keymgmt_lib.c @@ -346,10 +346,19 @@ int evp_keymgmt_util_copy(EVP_PKEY *to, EVP_PKEY *from, int selection) if (from == NULL || from->keydata == NULL) return 0; + /* + * If |to| is unassigned, ensure it gets the same KEYMGMT as |from|, + * Note that the final setting of KEYMGMT is done further down, with + * EVP_PKEY_set_type_by_keymgmt(); we don't want to do that prematurely. + */ + if (to_keymgmt == NULL) + to_keymgmt = from->keymgmt; + if (to_keymgmt == from->keymgmt && to_keymgmt->copy != NULL) { /* Make sure there's somewhere to copy to */ if (to_keydata == NULL - && (to_keydata = evp_keymgmt_newdata(to_keymgmt)) == NULL) { + && ((to_keydata = alloc_keydata = evp_keymgmt_newdata(to_keymgmt)) + == NULL)) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); return 0; } @@ -375,10 +384,11 @@ int evp_keymgmt_util_copy(EVP_PKEY *to, EVP_PKEY *from, int selection) } /* - * In this case to_keydata was previously unallocated, try_import() + * In case to_keydata was previously unallocated, try_import() * may have created it for us. */ - to_keydata = import_data.keydata; + if (to_keydata == NULL) + to_keydata = alloc_keydata = import_data.keydata; } else { ERR_raise(ERR_LIB_EVP, EVP_R_DIFFERENT_KEY_TYPES); return 0; diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c index 172dd21a..b75d02f1 100644 --- a/crypto/evp/keymgmt_meth.c +++ b/crypto/evp/keymgmt_meth.c @@ -39,7 +39,7 @@ static void *keymgmt_from_dispatch(int name_id, { EVP_KEYMGMT *keymgmt = NULL; int setparamfncnt = 0, getparamfncnt = 0; - int setgenparamfncnt = 0, getgenparamfncnt = 0; + int setgenparamfncnt = 0; int importfncnt = 0, exportfncnt = 0; if ((keymgmt = keymgmt_new()) == NULL) { @@ -77,20 +77,6 @@ static void *keymgmt_from_dispatch(int name_id, OSSL_get_OP_keymgmt_gen_settable_params(fns); } break; - case OSSL_FUNC_KEYMGMT_GEN_GET_PARAMS: - if (keymgmt->gen_get_params == NULL) { - getgenparamfncnt++; - keymgmt->gen_get_params = - OSSL_get_OP_keymgmt_gen_get_params(fns); - } - break; - case OSSL_FUNC_KEYMGMT_GEN_GETTABLE_PARAMS: - if (keymgmt->gen_gettable_params == NULL) { - getgenparamfncnt++; - keymgmt->gen_gettable_params = - OSSL_get_OP_keymgmt_gen_gettable_params(fns); - } - break; case OSSL_FUNC_KEYMGMT_GEN: if (keymgmt->gen == NULL) keymgmt->gen = OSSL_get_OP_keymgmt_gen(fns); @@ -186,7 +172,6 @@ static void *keymgmt_from_dispatch(int name_id, || (getparamfncnt != 0 && getparamfncnt != 2) || (setparamfncnt != 0 && setparamfncnt != 2) || (setgenparamfncnt != 0 && setgenparamfncnt != 2) - || (getgenparamfncnt != 0 && getgenparamfncnt != 2) || (importfncnt != 0 && importfncnt != 2) || (exportfncnt != 0 && exportfncnt != 2) || (keymgmt->gen != NULL @@ -342,23 +327,6 @@ const OSSL_PARAM *evp_keymgmt_gen_settable_params(const EVP_KEYMGMT *keymgmt) return keymgmt->gen_settable_params(provctx); } -int evp_keymgmt_gen_get_params(const EVP_KEYMGMT *keymgmt, void *genctx, - OSSL_PARAM params[]) -{ - if (keymgmt->gen_get_params == NULL) - return 0; - return keymgmt->gen_get_params(genctx, params); -} - -const OSSL_PARAM *evp_keymgmt_gen_gettable_params(const EVP_KEYMGMT *keymgmt) -{ - void *provctx = ossl_provider_ctx(EVP_KEYMGMT_provider(keymgmt)); - - if (keymgmt->gen_gettable_params == NULL) - return NULL; - return keymgmt->gen_gettable_params(provctx); -} - void *evp_keymgmt_gen(const EVP_KEYMGMT *keymgmt, void *genctx, OSSL_CALLBACK *cb, void *cbarg) { diff --git a/crypto/evp/m_sigver.c b/crypto/evp/m_sigver.c index 5f2e27ed..44e7cab1 100644 --- a/crypto/evp/m_sigver.c +++ b/crypto/evp/m_sigver.c @@ -16,7 +16,7 @@ #include "internal/provider.h" #include "evp_local.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static int update(EVP_MD_CTX *ctx, const void *data, size_t datalen) { @@ -71,6 +71,9 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, locpctx = ctx->pctx; evp_pkey_ctx_free_old_ops(locpctx); + if (props == NULL) + props = locpctx->propquery; + /* * TODO when we stop falling back to legacy, this and the ERR_pop_to_mark() * calls can be removed. @@ -142,7 +145,7 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, locpctx->operation = ver ? EVP_PKEY_OP_VERIFYCTX : EVP_PKEY_OP_SIGNCTX; locpctx->op.sig.sigprovctx - = signature->newctx(ossl_provider_ctx(signature->prov)); + = signature->newctx(ossl_provider_ctx(signature->prov), props); if (locpctx->op.sig.sigprovctx == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); goto err; @@ -182,14 +185,14 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, goto err; } ret = signature->digest_verify_init(locpctx->op.sig.sigprovctx, - mdname, props, provkey); + mdname, provkey); } else { if (signature->digest_sign_init == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); goto err; } ret = signature->digest_sign_init(locpctx->op.sig.sigprovctx, - mdname, props, provkey); + mdname, provkey); } return ret ? 1 : 0; @@ -317,11 +320,13 @@ int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) data, dsize); legacy: - /* do_sigver_init() checked that |digest_custom| is non-NULL */ - if (pctx->flag_call_digest_custom - && !ctx->pctx->pmeth->digest_custom(ctx->pctx, ctx)) - return 0; - pctx->flag_call_digest_custom = 0; + if (pctx != NULL) { + /* do_sigver_init() checked that |digest_custom| is non-NULL */ + if (pctx->flag_call_digest_custom + && !ctx->pctx->pmeth->digest_custom(ctx->pctx, ctx)) + return 0; + pctx->flag_call_digest_custom = 0; + } return EVP_DigestUpdate(ctx, data, dsize); } @@ -345,16 +350,18 @@ int EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t dsize) data, dsize); legacy: - /* do_sigver_init() checked that |digest_custom| is non-NULL */ - if (pctx->flag_call_digest_custom - && !ctx->pctx->pmeth->digest_custom(ctx->pctx, ctx)) - return 0; - pctx->flag_call_digest_custom = 0; + if (pctx != NULL) { + /* do_sigver_init() checked that |digest_custom| is non-NULL */ + if (pctx->flag_call_digest_custom + && !ctx->pctx->pmeth->digest_custom(ctx->pctx, ctx)) + return 0; + pctx->flag_call_digest_custom = 0; + } return EVP_DigestUpdate(ctx, data, dsize); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) { @@ -550,4 +557,4 @@ int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret, return -1; return EVP_DigestVerifyFinal(ctx, sigret, siglen); } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 11d6babb..9eb9f493 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,7 @@ #include "internal/evp.h" #include "internal/provider.h" #include "evp_local.h" +DEFINE_STACK_OF(X509_ATTRIBUTE) #include "crypto/ec.h" @@ -46,7 +48,7 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len, EVP_KEYMGMT *keymgmt); static void evp_pkey_free_it(EVP_PKEY *key); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* The type of parameters selected in key parameter functions */ # define SELECT_PARAMETERS OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS @@ -229,9 +231,11 @@ static int evp_pkey_cmp_any(const EVP_PKEY *a, const EVP_PKEY *b, * us to compare types using legacy NIDs. */ if ((a->type != EVP_PKEY_NONE - && !EVP_KEYMGMT_is_a(b->keymgmt, OBJ_nid2sn(a->type))) + && (b->keymgmt == NULL + || !EVP_KEYMGMT_is_a(b->keymgmt, OBJ_nid2sn(a->type)))) || (b->type != EVP_PKEY_NONE - && !EVP_KEYMGMT_is_a(a->keymgmt, OBJ_nid2sn(b->type)))) + && (a->keymgmt == NULL + || !EVP_KEYMGMT_is_a(a->keymgmt, OBJ_nid2sn(b->type))))) return -1; /* not the same key type */ /* @@ -317,78 +321,213 @@ int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) return -2; } -EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, - const unsigned char *priv, - size_t len) -{ - EVP_PKEY *ret = EVP_PKEY_new(); - if (ret == NULL - || !pkey_set_type(ret, e, type, NULL, -1, NULL)) { +static EVP_PKEY *new_raw_key_int(OPENSSL_CTX *libctx, + const char *strtype, + const char *propq, + int nidtype, + ENGINE *e, + const unsigned char *key, + size_t len, + int key_is_priv) +{ + EVP_PKEY *pkey = NULL; + EVP_PKEY_CTX *ctx = NULL; + const EVP_PKEY_ASN1_METHOD *ameth = NULL; + int result = 0; + +# ifndef OPENSSL_NO_ENGINE + /* Check if there is an Engine for this type */ + if (e == NULL) { + ENGINE *tmpe = NULL; + + if (strtype != NULL) + ameth = EVP_PKEY_asn1_find_str(&tmpe, strtype, -1); + else if (nidtype != EVP_PKEY_NONE) + ameth = EVP_PKEY_asn1_find(&tmpe, nidtype); + + /* If tmpe is NULL then no engine is claiming to support this type */ + if (tmpe == NULL) + ameth = NULL; + + ENGINE_finish(tmpe); + } +# endif + + if (e == NULL && ameth == NULL) { + /* + * No engine is claiming to support this type, so lets see if we have + * a provider. + */ + ctx = EVP_PKEY_CTX_new_from_name(libctx, + strtype != NULL ? strtype + : OBJ_nid2sn(nidtype), + propq); + if (ctx == NULL) { + EVPerr(0, ERR_R_MALLOC_FAILURE); + goto err; + } + /* May fail if no provider available */ + ERR_set_mark(); + if (EVP_PKEY_key_fromdata_init(ctx) == 1) { + OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; + + ERR_clear_last_mark(); + params[0] = OSSL_PARAM_construct_octet_string( + key_is_priv ? OSSL_PKEY_PARAM_PRIV_KEY + : OSSL_PKEY_PARAM_PUB_KEY, + (void *)key, len); + + if (EVP_PKEY_fromdata(ctx, &pkey, params) != 1) { + EVPerr(0, EVP_R_KEY_SETUP_FAILED); + goto err; + } + + EVP_PKEY_CTX_free(ctx); + + return pkey; + } + ERR_pop_to_mark(); + /* else not supported so fallback to legacy */ + } + + /* Legacy code path */ + + pkey = EVP_PKEY_new(); + if (pkey == NULL) { + EVPerr(0, ERR_R_MALLOC_FAILURE); + goto err; + } + + if (!pkey_set_type(pkey, e, nidtype, strtype, -1, NULL)) { /* EVPerr already called */ goto err; } - if (ret->ameth->set_priv_key == NULL) { - EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PRIVATE_KEY, - EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + if (!ossl_assert(pkey->ameth != NULL)) goto err; + + if (key_is_priv) { + if (pkey->ameth->set_priv_key == NULL) { + EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + goto err; + } + + if (!pkey->ameth->set_priv_key(pkey, key, len)) { + EVPerr(0, EVP_R_KEY_SETUP_FAILED); + goto err; + } + } else { + if (pkey->ameth->set_pub_key == NULL) { + EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + goto err; + } + + if (!pkey->ameth->set_pub_key(pkey, key, len)) { + EVPerr(0, EVP_R_KEY_SETUP_FAILED); + goto err; + } } - if (!ret->ameth->set_priv_key(ret, priv, len)) { - EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PRIVATE_KEY, EVP_R_KEY_SETUP_FAILED); - goto err; - } - - return ret; - + result = 1; err: - EVP_PKEY_free(ret); - return NULL; + if (!result) { + EVP_PKEY_free(pkey); + pkey = NULL; + } + EVP_PKEY_CTX_free(ctx); + return pkey; +} + +EVP_PKEY *EVP_PKEY_new_raw_private_key_with_libctx(OPENSSL_CTX *libctx, + const char *keytype, + const char *propq, + const unsigned char *priv, + size_t len) +{ + return new_raw_key_int(libctx, keytype, propq, EVP_PKEY_NONE, NULL, priv, + len, 1); +} + +EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, + const unsigned char *priv, + size_t len) +{ + return new_raw_key_int(NULL, NULL, NULL, type, e, priv, len, 1); +} + +EVP_PKEY *EVP_PKEY_new_raw_public_key_with_libctx(OPENSSL_CTX *libctx, + const char *keytype, + const char *propq, + const unsigned char *pub, + size_t len) +{ + return new_raw_key_int(libctx, keytype, propq, EVP_PKEY_NONE, NULL, pub, + len, 0); } EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, const unsigned char *pub, size_t len) { - EVP_PKEY *ret = EVP_PKEY_new(); + return new_raw_key_int(NULL, NULL, NULL, type, e, pub, len, 0); +} - if (ret == NULL - || !pkey_set_type(ret, e, type, NULL, -1, NULL)) { - /* EVPerr already called */ - goto err; +struct raw_key_details_st +{ + unsigned char **key; + size_t *len; + int selection; +}; + +static OSSL_CALLBACK get_raw_key_details; +static int get_raw_key_details(const OSSL_PARAM params[], void *arg) +{ + const OSSL_PARAM *p = NULL; + struct raw_key_details_st *raw_key = arg; + + if (raw_key->selection == OSSL_KEYMGMT_SELECT_PRIVATE_KEY) { + if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY)) + != NULL) + return OSSL_PARAM_get_octet_string(p, (void **)raw_key->key, + SIZE_MAX, raw_key->len); + } else if (raw_key->selection == OSSL_KEYMGMT_SELECT_PUBLIC_KEY) { + if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY)) + != NULL) + return OSSL_PARAM_get_octet_string(p, (void **)raw_key->key, + SIZE_MAX, raw_key->len); } - if (ret->ameth->set_pub_key == NULL) { - EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PUBLIC_KEY, - EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); - goto err; - } - - if (!ret->ameth->set_pub_key(ret, pub, len)) { - EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PUBLIC_KEY, EVP_R_KEY_SETUP_FAILED); - goto err; - } - - return ret; - - err: - EVP_PKEY_free(ret); - return NULL; + return 0; } int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, size_t *len) { - /* TODO(3.0) Do we need to do anything about provider side keys? */ - if (pkey->ameth->get_priv_key == NULL) { - EVPerr(EVP_F_EVP_PKEY_GET_RAW_PRIVATE_KEY, - EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + if (pkey->keymgmt != NULL) { + struct raw_key_details_st raw_key; + + raw_key.key = priv == NULL ? NULL : &priv; + raw_key.len = len; + raw_key.selection = OSSL_KEYMGMT_SELECT_PRIVATE_KEY; + + return evp_keymgmt_export(pkey->keymgmt, pkey->keydata, + OSSL_KEYMGMT_SELECT_PRIVATE_KEY, + get_raw_key_details, &raw_key); + } + + if (pkey->ameth == NULL) { + EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + return 0; + } + + if (pkey->ameth->get_priv_key == NULL) { + EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return 0; } if (!pkey->ameth->get_priv_key(pkey, priv, len)) { - EVPerr(EVP_F_EVP_PKEY_GET_RAW_PRIVATE_KEY, EVP_R_GET_RAW_KEY_FAILED); + EVPerr(0, EVP_R_GET_RAW_KEY_FAILED); return 0; } @@ -398,7 +537,23 @@ int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, size_t *len) { - /* TODO(3.0) Do we need to do anything about provider side keys? */ + if (pkey->keymgmt != NULL) { + struct raw_key_details_st raw_key; + + raw_key.key = pub == NULL ? NULL : &pub; + raw_key.len = len; + raw_key.selection = OSSL_KEYMGMT_SELECT_PUBLIC_KEY; + + return evp_keymgmt_export(pkey->keymgmt, pkey->keydata, + OSSL_KEYMGMT_SELECT_PUBLIC_KEY, + get_raw_key_details, &raw_key); + } + + if (pkey->ameth == NULL) { + EVPerr(0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + return 0; + } + if (pkey->ameth->get_pub_key == NULL) { EVPerr(EVP_F_EVP_PKEY_GET_RAW_PUBLIC_KEY, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); @@ -655,9 +810,9 @@ DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey) return ret; } # endif /* OPENSSL_NO_DSA */ -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # ifndef OPENSSL_NO_EC int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) { @@ -751,7 +906,7 @@ int EVP_PKEY_base_id(const EVP_PKEY *pkey) int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (pkey->keymgmt == NULL) { /* * These hard coded cases are pure hackery to get around the fact @@ -1063,9 +1218,9 @@ size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt) return rv; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ -/*- All methods below can also be used in FIPS_MODE */ +/*- All methods below can also be used in FIPS_MODULE */ EVP_PKEY *EVP_PKEY_new(void) { @@ -1084,7 +1239,7 @@ EVP_PKEY *EVP_PKEY_new(void) EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); goto err; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, ret, &ret->ex_data)) { EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); goto err; @@ -1114,7 +1269,7 @@ EVP_PKEY *EVP_PKEY_new(void) static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len, EVP_KEYMGMT *keymgmt) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE const EVP_PKEY_ASN1_METHOD *ameth = NULL; ENGINE **eptr = (e == NULL) ? &e : NULL; #endif @@ -1132,13 +1287,13 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, if (pkey != NULL) { int free_it = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE free_it = free_it || pkey->pkey.ptr != NULL; #endif free_it = free_it || pkey->keydata != NULL; if (free_it) evp_pkey_free_it(pkey); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * If key type matches and a method exists then this lookup has * succeeded once so just indicate success. @@ -1156,7 +1311,7 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, # endif #endif } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (str != NULL) ameth = EVP_PKEY_asn1_find_str(eptr, str, len); else if (type != EVP_PKEY_NONE) @@ -1171,7 +1326,7 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, { int check = 1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE check = check && ameth == NULL; #endif check = check && keymgmt == NULL; @@ -1191,7 +1346,7 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, pkey->save_type = type; pkey->type = type; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * If the internal "origin" key is provider side, don't save |ameth|. * The main reason is that |ameth| is one factor to detect that the @@ -1209,16 +1364,18 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, * to the |save_type| field, because |type| is supposed to be set * to EVP_PKEY_NONE in that case. */ - if (keymgmt != NULL) - pkey->save_type = ameth->pkey_id; - else if (pkey->ameth != NULL) - pkey->type = ameth->pkey_id; + if (ameth != NULL) { + if (keymgmt != NULL) + pkey->save_type = ameth->pkey_id; + else if (pkey->ameth != NULL) + pkey->type = ameth->pkey_id; + } #endif } return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static void find_ameth(const char *name, void *data) { const char **str = data; @@ -1243,7 +1400,7 @@ static void find_ameth(const char *name, void *data) int EVP_PKEY_set_type_by_keymgmt(EVP_PKEY *pkey, EVP_KEYMGMT *keymgmt) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # define EVP_PKEY_TYPE_STR str[0] # define EVP_PKEY_TYPE_STRLEN (str[0] == NULL ? -1 : (int)strlen(str[0])) /* @@ -1282,7 +1439,7 @@ int EVP_PKEY_up_ref(EVP_PKEY *pkey) return ((i > 1) ? 1 : 0); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE void evp_pkey_free_legacy(EVP_PKEY *x) { if (x->ameth != NULL) { @@ -1298,14 +1455,14 @@ void evp_pkey_free_legacy(EVP_PKEY *x) # endif x->type = EVP_PKEY_NONE; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ static void evp_pkey_free_it(EVP_PKEY *x) { /* internal function; x is never NULL */ evp_keymgmt_util_clear_operation_cache(x); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE evp_pkey_free_legacy(x); #endif @@ -1330,11 +1487,11 @@ void EVP_PKEY_free(EVP_PKEY *x) return; REF_ASSERT_ISNT(i < 0); evp_pkey_free_it(x); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EVP_PKEY, x, &x->ex_data); #endif CRYPTO_THREAD_lock_free(x->lock); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); #endif OPENSSL_free(x); @@ -1346,7 +1503,7 @@ int EVP_PKEY_size(const EVP_PKEY *pkey) if (pkey != NULL) { size = pkey->cache.size; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (pkey->ameth != NULL && pkey->ameth->pkey_size != NULL) size = pkey->ameth->pkey_size(pkey); #endif @@ -1368,14 +1525,14 @@ void *evp_pkey_export_to_provider(EVP_PKEY *pk, OPENSSL_CTX *libctx, /* No key data => nothing to export */ check = 1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE check = check && pk->pkey.ptr == NULL; #endif check = check && pk->keydata == NULL; if (check) return NULL; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (pk->pkey.ptr != NULL) { /* * If the legacy key doesn't have an dirty counter or export function, @@ -1407,7 +1564,7 @@ void *evp_pkey_export_to_provider(EVP_PKEY *pk, OPENSSL_CTX *libctx, if (tmp_keymgmt == NULL) goto end; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (pk->pkey.ptr != NULL) { size_t i = 0; @@ -1479,7 +1636,7 @@ void *evp_pkey_export_to_provider(EVP_PKEY *pk, OPENSSL_CTX *libctx, pk->dirty_cnt_copy = pk->ameth->dirty_cnt(pk); goto end; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ keydata = evp_keymgmt_util_export_to_provider(pk, tmp_keymgmt); @@ -1499,7 +1656,7 @@ void *evp_pkey_export_to_provider(EVP_PKEY *pk, OPENSSL_CTX *libctx, return keydata; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int evp_pkey_downgrade(EVP_PKEY *pk) { EVP_KEYMGMT *keymgmt = pk->keymgmt; @@ -1605,7 +1762,7 @@ int evp_pkey_downgrade(EVP_PKEY *pk) evp_keymgmt_util_cache_keyinfo(pk); return 0; /* No downgrade, but at least the key is restored */ } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ const OSSL_PARAM *EVP_PKEY_gettable_params(EVP_PKEY *pkey) { diff --git a/crypto/evp/pkey_mac.c b/crypto/evp/pkey_mac.c index bfd8cd63..3503aac6 100644 --- a/crypto/evp/pkey_mac.c +++ b/crypto/evp/pkey_mac.c @@ -308,11 +308,14 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) OSSL_PARAM params[3]; size_t params_n = 0; char *ciphname = (char *)OBJ_nid2sn(EVP_CIPHER_nid(p2)); -#ifndef OPENSSL_NO_ENGINE - char *engineid = (char *)ENGINE_get_id(ctx->engine); - params[params_n++] = - OSSL_PARAM_construct_utf8_string("engine", engineid, 0); +#ifndef OPENSSL_NO_ENGINE + if (ctx->engine != NULL) { + char *engid = (char *)ENGINE_get_id(ctx->engine); + + params[params_n++] = + OSSL_PARAM_construct_utf8_string("engine", engid, 0); + } #endif params[params_n++] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER, @@ -458,13 +461,14 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) size_t params_n = 0; char *mdname = (char *)OBJ_nid2sn(EVP_MD_nid(hctx->raw_data.md)); -#ifndef OPENSSL_NO_ENGINE - char *engineid = ctx->engine == NULL - ? NULL : (char *)ENGINE_get_id(ctx->engine); - if (engineid != NULL) +#ifndef OPENSSL_NO_ENGINE + if (ctx->engine != NULL) { + char *engid = (char *)ENGINE_get_id(ctx->engine); + params[params_n++] = - OSSL_PARAM_construct_utf8_string("engine", engineid, 0); + OSSL_PARAM_construct_utf8_string("engine", engid, 0); + } #endif params[params_n++] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST, @@ -493,13 +497,24 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) } static int pkey_mac_ctrl_str(EVP_PKEY_CTX *ctx, - const char *type, const char *value) + const char *type, const char *value) { MAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx); - const EVP_MAC *mac = EVP_MAC_CTX_mac(hctx->ctx); + const EVP_MAC *mac; OSSL_PARAM params[2]; int ok = 0; + if (hctx == NULL) { + EVPerr(0, EVP_R_NULL_MAC_PKEY_CTX); + return 0; + } + if (hctx->ctx == NULL) { + /* This actually means the fetch failed during the init call */ + EVPerr(0, EVP_R_FETCH_FAILED); + return 0; + } + mac = EVP_MAC_CTX_mac(hctx->ctx); + /* * Translation of some control names that are equivalent to a single * parameter name. @@ -520,12 +535,6 @@ static int pkey_mac_ctrl_str(EVP_PKEY_CTX *ctx, return 0; params[1] = OSSL_PARAM_construct_end(); - if (hctx->ctx == NULL) { - /* This actually means the fetch failed during the init call */ - EVPerr(0, EVP_R_FETCH_FAILED); - return 0; - } - ok = EVP_MAC_CTX_set_params(hctx->ctx, params); OPENSSL_free(params[0].data); return ok; diff --git a/crypto/evp/pmeth_check.c b/crypto/evp/pmeth_check.c index 587e8ae1..b99d5b1a 100644 --- a/crypto/evp/pmeth_check.c +++ b/crypto/evp/pmeth_check.c @@ -38,7 +38,7 @@ int EVP_PKEY_public_check(EVP_PKEY_CTX *ctx) if (pkey->type == EVP_PKEY_NONE) goto not_supported; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* legacy */ /* call customized public key check function first */ if (ctx->pmeth->public_check != NULL) @@ -76,7 +76,7 @@ int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx) if (pkey->type == EVP_PKEY_NONE) goto not_supported; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* legacy */ /* call customized param check function first */ if (ctx->pmeth->param_check != NULL) @@ -156,7 +156,7 @@ int EVP_PKEY_check(EVP_PKEY_CTX *ctx) if (pkey->type == EVP_PKEY_NONE) goto not_supported; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* legacy */ /* call customized check function first */ if (ctx->pmeth->check != NULL) diff --git a/crypto/evp/pmeth_fn.c b/crypto/evp/pmeth_fn.c index 4d8d3e91..8bc59c40 100644 --- a/crypto/evp/pmeth_fn.c +++ b/crypto/evp/pmeth_fn.c @@ -126,11 +126,8 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation) goto err; } - if (ret <= 0) { - cipher->freectx(ctx->op.ciph.ciphprovctx); - ctx->op.ciph.ciphprovctx = NULL; + if (ret <= 0) goto err; - } return 1; legacy: @@ -162,8 +159,10 @@ static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation) } err: - if (ret <= 0) + if (ret <= 0) { + evp_pkey_ctx_free_old_ops(ctx); ctx->operation = EVP_PKEY_OP_UNDEFINED; + } return ret; } diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index 0d6a8220..fb861d24 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -20,7 +20,7 @@ #include "crypto/evp.h" #include "evp_local.h" -#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_EC) +#if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_EC) # define TMP_SM2_HACK #endif @@ -69,7 +69,7 @@ static int gen_init(EVP_PKEY_CTX *ctx, int operation) goto end; legacy: -#ifdef FIPS_MODE +#ifdef FIPS_MODULE goto not_supported; #else if (ctx->pmeth == NULL @@ -93,8 +93,10 @@ static int gen_init(EVP_PKEY_CTX *ctx, int operation) #endif end: - if (ret <= 0) + if (ret <= 0 && ctx != NULL) { + evp_pkey_ctx_free_old_ops(ctx); ctx->operation = EVP_PKEY_OP_UNDEFINED; + } return ret; not_supported: @@ -189,7 +191,7 @@ int EVP_PKEY_gen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) ossl_callback_to_pkey_gencb, ctx) != NULL); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* In case |*ppkey| was originally a legacy key */ if (ret) evp_pkey_free_legacy(*ppkey); @@ -210,8 +212,9 @@ int EVP_PKEY_gen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) { char curve_name[OSSL_MAX_NAME_SIZE] = ""; - if (EVP_PKEY_CTX_get_ec_paramgen_curve_name(ctx, curve_name, - sizeof(curve_name)) < 1 + if (!EVP_PKEY_get_utf8_string_param(*ppkey, OSSL_PKEY_PARAM_EC_NAME, + curve_name, sizeof(curve_name), + NULL) || strcmp(curve_name, "SM2") != 0) goto end; } @@ -223,7 +226,7 @@ int EVP_PKEY_gen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) goto end; legacy: -#ifdef FIPS_MODE +#ifdef FIPS_MODULE goto not_supported; #else if (ctx->pkey && !evp_pkey_downgrade(ctx->pkey)) @@ -256,7 +259,7 @@ int EVP_PKEY_gen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey) ERR_raise(ERR_LIB_EVP, EVP_R_OPERATON_NOT_INITIALIZED); ret = -1; goto end; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE not_accessible: ERR_raise(ERR_LIB_EVP, EVP_R_INACCESSIBLE_DOMAIN_PARAMETERS); ret = -1; @@ -319,7 +322,7 @@ int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx) return ctx->keygen_info[idx]; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, int keylen) @@ -340,9 +343,9 @@ EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, return mac_key; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ -/*- All methods below can also be used in FIPS_MODE */ +/*- All methods below can also be used in FIPS_MODULE */ static int fromdata_init(EVP_PKEY_CTX *ctx, int operation) { diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 2b99b52c..eca51781 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -30,7 +30,7 @@ #include "internal/provider.h" #include "evp_local.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE typedef const EVP_PKEY_METHOD *(*pmeth_fn)(void); typedef int sk_cmp_fn_type(const char *const *a, const char *const *b); @@ -135,7 +135,7 @@ EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags) pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC; return pmeth; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx, EVP_PKEY *pkey, ENGINE *e, @@ -165,7 +165,7 @@ static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx, keytype = evp_first_name(pkey->keymgmt->prov, pkey->keymgmt->name_id); goto common; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* TODO(3.0) Legacy code should be removed when all is provider based */ /* BEGIN legacy */ if (id == -1) { @@ -221,7 +221,7 @@ static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx, return NULL; } /* END legacy */ -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ common: /* * If there's no engine and there's a name, we try fetching a provider @@ -237,7 +237,7 @@ static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx, ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { EVP_KEYMGMT_free(keymgmt); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(e); #endif EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE); @@ -265,7 +265,7 @@ static EVP_PKEY_CTX *int_ctx_new(OPENSSL_CTX *libctx, return ret; } -/*- All methods below can also be used in FIPS_MODE */ +/*- All methods below can also be used in FIPS_MODULE */ EVP_PKEY_CTX *EVP_PKEY_CTX_new_from_name(OPENSSL_CTX *libctx, const char *name, @@ -296,7 +296,7 @@ void evp_pkey_ctx_free_old_ops(EVP_PKEY_CTX *ctx) ctx->op.kex.exchange = NULL; } /* TODO(3.0): add dependancies and uncomment this when available for fips mode */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE else if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx)) { if (ctx->op.ciph.ciphprovctx != NULL && ctx->op.ciph.cipher != NULL) ctx->op.ciph.cipher->freectx(ctx->op.ciph.ciphprovctx); @@ -322,13 +322,13 @@ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) EVP_PKEY_free(ctx->pkey); EVP_PKEY_free(ctx->peerkey); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(ctx->engine); #endif OPENSSL_free(ctx); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth) @@ -592,7 +592,7 @@ int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) return 0; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) { if (EVP_PKEY_CTX_IS_DERIVE_OP(ctx) @@ -613,12 +613,6 @@ int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) && ctx->op.ciph.cipher->get_ctx_params != NULL) return ctx->op.ciph.cipher->get_ctx_params(ctx->op.ciph.ciphprovctx, params); - if (EVP_PKEY_CTX_IS_GEN_OP(ctx) - && ctx->op.keymgmt.genctx != NULL - && ctx->keymgmt != NULL - && ctx->keymgmt->gen_get_params != NULL) - return evp_keymgmt_gen_get_params(ctx->keymgmt, ctx->op.keymgmt.genctx, - params); return 0; } @@ -632,12 +626,10 @@ const OSSL_PARAM *EVP_PKEY_CTX_gettable_params(EVP_PKEY_CTX *ctx) && ctx->op.sig.signature != NULL && ctx->op.sig.signature->gettable_ctx_params != NULL) return ctx->op.sig.signature->gettable_ctx_params(); - if (EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) && ctx->op.ciph.cipher != NULL && ctx->op.ciph.cipher->gettable_ctx_params != NULL) return ctx->op.ciph.cipher->gettable_ctx_params(); - return NULL; } @@ -656,8 +648,7 @@ const OSSL_PARAM *EVP_PKEY_CTX_settable_params(EVP_PKEY_CTX *ctx) && ctx->op.ciph.cipher->settable_ctx_params != NULL) return ctx->op.ciph.cipher->settable_ctx_params(); if (EVP_PKEY_CTX_IS_GEN_OP(ctx) - && ctx->keymgmt != NULL - && ctx->keymgmt->gen_settable_params != NULL) + && ctx->keymgmt != NULL) return evp_keymgmt_gen_settable_params(ctx->keymgmt); return NULL; @@ -670,7 +661,7 @@ const OSSL_PARAM *EVP_PKEY_CTX_settable_params(EVP_PKEY_CTX *ctx) * * In particular they return -2 if any of the params is not supported. * - * They are not available in FIPS_MODE as they depend on + * They are not available in FIPS_MODULE as they depend on * - EVP_PKEY_CTX_{get,set}_params() * - EVP_PKEY_CTX_{gettable,settable}_params() * @@ -1026,6 +1017,12 @@ static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name, name = OSSL_PKEY_PARAM_RSA_E; else if (strcmp(name, "rsa_keygen_primes") == 0) name = OSSL_PKEY_PARAM_RSA_PRIMES; + else if (strcmp(name, "rsa_pss_keygen_md") == 0) + name = OSSL_PKEY_PARAM_RSA_DIGEST; + else if (strcmp(name, "rsa_pss_keygen_mgf1_md") == 0) + name = OSSL_PKEY_PARAM_RSA_MGF1_DIGEST; + else if (strcmp(name, "rsa_pss_keygen_saltlen") == 0) + name = OSSL_PKEY_PARAM_RSA_PSS_SALTLEN; # ifndef OPENSSL_NO_DSA else if (strcmp(name, "dsa_paramgen_bits") == 0) name = OSSL_PKEY_PARAM_FFC_PBITS; @@ -1075,7 +1072,8 @@ static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name, if (!OSSL_PARAM_allocate_from_text(¶ms[0], settable, name, value, strlen(value), &exists)) { if (!exists) { - ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); + ERR_raise_data(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED, + "name=%s,value=%s", name, value); return -2; } return 0; @@ -1592,4 +1590,4 @@ void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD *pmeth, *pdigest_custom = pmeth->digest_custom; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index d845ac12..595a93e6 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -417,7 +417,8 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) /* No more legacy from here down to legacy: */ ctx->op.sig.signature = signature; - ctx->op.sig.sigprovctx = signature->newctx(ossl_provider_ctx(signature->prov)); + ctx->op.sig.sigprovctx = + signature->newctx(ossl_provider_ctx(signature->prov), ctx->propquery); if (ctx->op.sig.sigprovctx == NULL) { /* The provider key can stay in the cache */ EVPerr(0, EVP_R_INITIALIZATION_ERROR); @@ -503,6 +504,7 @@ static int evp_pkey_signature_init(EVP_PKEY_CTX *ctx, int operation) return ret; err: + evp_pkey_ctx_free_old_ops(ctx); ctx->operation = EVP_PKEY_OP_UNDEFINED; return ret; } diff --git a/crypto/ex_data.c b/crypto/ex_data.c index d672b464..6200d055 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -10,6 +10,8 @@ #include "crypto/cryptlib.h" #include "internal/thread_once.h" +DEFINE_STACK_OF(void) + int do_ex_data_init(OPENSSL_CTX *ctx) { OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(ctx); diff --git a/crypto/ffc/ffc_backend.c b/crypto/ffc/ffc_backend.c index d9b3e2e8..1cfa427d 100644 --- a/crypto/ffc/ffc_backend.c +++ b/crypto/ffc/ffc_backend.c @@ -63,11 +63,8 @@ int ffc_params_fromdata(FFC_PARAMS *ffc, const OSSL_PARAM params[]) ffc->pcounter = i; } prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_COFACTOR); - if (prm != NULL) { - if (!OSSL_PARAM_get_BN(prm, &j)) - goto err; - j = NULL; - } + if (prm != NULL && !OSSL_PARAM_get_BN(prm, &j)) + goto err; prm = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H); if (prm != NULL) { if (!OSSL_PARAM_get_int(prm, &i)) diff --git a/crypto/ffc/ffc_params.c b/crypto/ffc/ffc_params.c index 63a8bb73..efd7dc89 100644 --- a/crypto/ffc/ffc_params.c +++ b/crypto/ffc/ffc_params.c @@ -12,7 +12,7 @@ #include "internal/ffc.h" #include "internal/param_build_set.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # include /* ffc_params_print */ #endif @@ -231,7 +231,7 @@ int ffc_params_todata(const FFC_PARAMS *ffc, OSSL_PARAM_BLD *bld, return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int ffc_params_print(BIO *bp, const FFC_PARAMS *ffc, int indent) { if (!ASN1_bn_print(bp, "prime P:", ffc->p, NULL, indent)) @@ -270,4 +270,4 @@ int ffc_params_print(BIO *bp, const FFC_PARAMS *ffc, int indent) err: return 0; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ diff --git a/crypto/ffc/ffc_params_generate.c b/crypto/ffc/ffc_params_generate.c index 6d9b9243..1d8d80c9 100644 --- a/crypto/ffc/ffc_params_generate.c +++ b/crypto/ffc/ffc_params_generate.c @@ -772,7 +772,7 @@ int ffc_params_FIPS186_2_gen_verify(OPENSSL_CTX *libctx, FFC_PARAMS *params, EVP_MD *evpmd_fetch = NULL; *res = 0; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* * FIPS 186-4 states that validation can only be done for this pair. * (Even though the original spec allowed L = 512 + 64*j (j = 0.. 8)) diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c index b49baec4..6c1a70e4 100644 --- a/crypto/hmac/hmac.c +++ b/crypto/hmac/hmac.c @@ -55,6 +55,8 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, j = EVP_MD_block_size(md); if (!ossl_assert(j <= (int)sizeof(keytmp))) return 0; + if (j < 0) + return 0; if (j < len) { if (!EVP_DigestInit_ex(ctx->md_ctx, md, impl) || !EVP_DigestUpdate(ctx->md_ctx, key, len) diff --git a/crypto/http/http_client.c b/crypto/http/http_client.c index 4c123f81..64f877ab 100644 --- a/crypto/http/http_client.c +++ b/crypto/http/http_client.c @@ -25,6 +25,8 @@ #include "http_local.h" +DEFINE_STACK_OF(CONF_VALUE) + #define HTTP_PREFIX "HTTP/" #define HTTP_VERSION_PATT "1." /* allow 1.x */ #define HTTP_VERSION_STR_LEN 3 @@ -220,7 +222,7 @@ static int OSSL_HTTP_REQ_CTX_content(OSSL_HTTP_REQ_CTX *rctx, && BIO_write(rctx->mem, req, req_len) == (int)req_len; } -BIO *HTTP_asn1_item2bio(const ASN1_ITEM *it, ASN1_VALUE *val) +BIO *HTTP_asn1_item2bio(const ASN1_ITEM *it, const ASN1_VALUE *val) { BIO *res; @@ -1067,7 +1069,7 @@ ASN1_VALUE *OSSL_HTTP_post_asn1(const char *server, const char *port, OSSL_HTTP_bio_cb_t bio_update_fn, void *arg, const STACK_OF(CONF_VALUE) *headers, const char *content_type, - ASN1_VALUE *req, const ASN1_ITEM *req_it, + const ASN1_VALUE *req, const ASN1_ITEM *req_it, int maxline, unsigned long max_resp_len, int timeout, const char *expected_ct, const ASN1_ITEM *rsp_it) diff --git a/crypto/http/http_local.h b/crypto/http/http_local.h index 64b475b8..729d24e4 100644 --- a/crypto/http/http_local.h +++ b/crypto/http/http_local.h @@ -27,7 +27,7 @@ typedef OCSP_REQ_CTX OSSL_HTTP_REQ_CTX; # define OSSL_HTTP_REQ_CTX_get0_mem_bio OCSP_REQ_CTX_get0_mem_bio /* undoc'd */ # define OSSL_HTTP_REQ_CTX_set_max_response_length OCSP_set_max_response_length -BIO *HTTP_asn1_item2bio(const ASN1_ITEM *it, ASN1_VALUE *val); +BIO *HTTP_asn1_item2bio(const ASN1_ITEM *it, const ASN1_VALUE *val); OSSL_HTTP_REQ_CTX *HTTP_REQ_CTX_new(BIO *wbio, BIO *rbio, int use_http_proxy, const char *server, const char *port, const char *path, diff --git a/crypto/include/internal/pem_int.h b/crypto/include/internal/pem_int.h new file mode 100644 index 00000000..c8f90528 --- /dev/null +++ b/crypto/include/internal/pem_int.h @@ -0,0 +1,23 @@ +/* + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PEM_INT_H +# define HEADER_PEM_INT_H + +# include + +/* Found in crypto/pem/pvkfmt.c */ +int ossl_do_blob_header(const unsigned char **in, unsigned int length, + unsigned int *pmagic, unsigned int *pbitlen, + int *pisdss, int *pispub); +int ossl_do_PVK_header(const unsigned char **in, unsigned int length, + int skip_magic, + unsigned int *psaltlen, unsigned int *pkeylen); + +#endif diff --git a/crypto/initthread.c b/crypto/initthread.c index 6f15cda6..a97cf359 100644 --- a/crypto/initthread.c +++ b/crypto/initthread.c @@ -13,7 +13,7 @@ #include "prov/providercommon.h" #include "internal/thread_once.h" -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* * Thread aware code may want to be told about thread stop events. We register * to hear about those thread stop events when we see a new thread has started. @@ -37,7 +37,7 @@ struct thread_event_handler_st { THREAD_EVENT_HANDLER *next; }; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE DEFINE_SPECIAL_STACK_OF(THREAD_EVENT_HANDLER_PTR, THREAD_EVENT_HANDLER *) typedef struct global_tevent_register_st GLOBAL_TEVENT_REGISTER; @@ -77,7 +77,7 @@ static GLOBAL_TEVENT_REGISTER *get_global_tevent_register(void) } #endif -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static int init_thread_push_handlers(THREAD_EVENT_HANDLER **hands); static void init_thread_remove_handlers(THREAD_EVENT_HANDLER **handsin); static void init_thread_destructor(void *hands); @@ -101,7 +101,7 @@ init_get_thread_local(CRYPTO_THREAD_LOCAL *local, int alloc, int keep) return NULL; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!init_thread_push_handlers(hands)) { CRYPTO_THREAD_set_local(local, NULL); OPENSSL_free(hands); @@ -116,7 +116,7 @@ init_get_thread_local(CRYPTO_THREAD_LOCAL *local, int alloc, int keep) return hands; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * Since per-thread-specific-data destructors are not universally * available, i.e. not on Windows, only below CRYPTO_THREAD_LOCAL key @@ -292,7 +292,7 @@ void ossl_ctx_thread_stop(void *arg) init_thread_stop(arg, hands); OPENSSL_free(hands); } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ static void init_thread_stop(void *arg, THREAD_EVENT_HANDLER **hands) @@ -328,7 +328,7 @@ int ossl_init_thread_start(const void *index, void *arg, { THREAD_EVENT_HANDLER **hands; THREAD_EVENT_HANDLER *hand; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE OPENSSL_CTX *ctx = arg; /* @@ -353,14 +353,14 @@ int ossl_init_thread_start(const void *index, void *arg, if (hands == NULL) return 0; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE if (*hands == NULL) { /* * We've not yet registered any handlers for this thread. We need to get * libcrypto to tell us about later thread stop events. c_thread_start * is a callback to libcrypto defined in fipsprov.c */ - if (!c_thread_start(FIPS_get_provider(ctx), ossl_ctx_thread_stop)) + if (!c_thread_start(FIPS_get_core_handle(ctx), ossl_ctx_thread_stop)) return 0; } #endif @@ -378,7 +378,7 @@ int ossl_init_thread_start(const void *index, void *arg, return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static int init_thread_deregister(void *index, int all) { GLOBAL_TEVENT_REGISTER *gtr; diff --git a/crypto/mem.c b/crypto/mem.c index 1368bd73..d682a368 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -23,7 +23,7 @@ static CRYPTO_malloc_fn malloc_impl = CRYPTO_malloc; static CRYPTO_realloc_fn realloc_impl = CRYPTO_realloc; static CRYPTO_free_fn free_impl = CRYPTO_free; -#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODULE) # include "internal/tsan_assist.h" static TSAN_QUALIFIER int malloc_count; @@ -75,7 +75,7 @@ void CRYPTO_get_mem_functions(CRYPTO_malloc_fn *malloc_fn, *free_fn = free_impl; } -#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODULE) void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount) { if (mcount != NULL) diff --git a/crypto/modes/siv128.c b/crypto/modes/siv128.c index 71214103..f45e7e2f 100644 --- a/crypto/modes/siv128.c +++ b/crypto/modes/siv128.c @@ -1,7 +1,7 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/o_fips.c b/crypto/o_fips.c deleted file mode 100644 index ac768e5a..00000000 --- a/crypto/o_fips.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the Apache License 2.0 (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include "internal/cryptlib.h" - -int FIPS_mode(void) -{ - /* This version of the library does not support FIPS mode. */ - return 0; -} - -int FIPS_mode_set(int r) -{ - if (r == 0) - return 1; - CRYPTOerr(CRYPTO_F_FIPS_MODE_SET, CRYPTO_R_FIPS_MODE_NOT_SUPPORTED); - return 0; -} diff --git a/crypto/ocsp/ocsp_cl.c b/crypto/ocsp/ocsp_cl.c index ec657900..95b16dce 100644 --- a/crypto/ocsp/ocsp_cl.c +++ b/crypto/ocsp/ocsp_cl.c @@ -18,6 +18,10 @@ #include #include "ocsp_local.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(OCSP_ONEREQ) +DEFINE_STACK_OF(OCSP_SINGLERESP) + /* * Utility functions related to sending OCSP requests and extracting relevant * information from the response. diff --git a/crypto/ocsp/ocsp_ext.c b/crypto/ocsp/ocsp_ext.c index c2b61bd4..77e67840 100644 --- a/crypto/ocsp/ocsp_ext.c +++ b/crypto/ocsp/ocsp_ext.c @@ -16,6 +16,9 @@ #include #include +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF(ACCESS_DESCRIPTION) + /* Standard wrapper functions for extensions */ /* OCSP request extensions */ diff --git a/crypto/ocsp/ocsp_prn.c b/crypto/ocsp/ocsp_prn.c index 6d527dfc..c782a8e5 100644 --- a/crypto/ocsp/ocsp_prn.c +++ b/crypto/ocsp/ocsp_prn.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,10 @@ #include "internal/cryptlib.h" #include +DEFINE_STACK_OF(OCSP_ONEREQ) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(OCSP_SINGLERESP) + static int ocsp_certid_print(BIO *bp, OCSP_CERTID *a, int indent) { BIO_printf(bp, "%*sCertificate ID:\n", indent, ""); diff --git a/crypto/ocsp/ocsp_srv.c b/crypto/ocsp/ocsp_srv.c index b9253b36..3cfe3649 100644 --- a/crypto/ocsp/ocsp_srv.c +++ b/crypto/ocsp/ocsp_srv.c @@ -16,6 +16,10 @@ #include #include "ocsp_local.h" +DEFINE_STACK_OF(OCSP_ONEREQ) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(OCSP_SINGLERESP) + /* * Utility functions related to sending OCSP responses and extracting * relevant information from the request. diff --git a/crypto/ocsp/ocsp_vfy.c b/crypto/ocsp/ocsp_vfy.c index c7a22a1f..0dccb24e 100644 --- a/crypto/ocsp/ocsp_vfy.c +++ b/crypto/ocsp/ocsp_vfy.c @@ -12,6 +12,10 @@ #include #include +DEFINE_STACK_OF(OCSP_ONEREQ) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(OCSP_SINGLERESP) + static int ocsp_find_signer(X509 **psigner, OCSP_BASICRESP *bs, STACK_OF(X509) *certs, unsigned long flags); static X509 *ocsp_find_signer_sk(STACK_OF(X509) *certs, OCSP_RESPID *id); diff --git a/crypto/ocsp/v3_ocsp.c b/crypto/ocsp/v3_ocsp.c index 9648ba94..15013219 100644 --- a/crypto/ocsp/v3_ocsp.c +++ b/crypto/ocsp/v3_ocsp.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,6 +16,8 @@ # include # include "../x509/ext_dat.h" +DEFINE_STACK_OF(ACCESS_DESCRIPTION) + /* * OCSP extensions and a couple of CRL entry extensions */ diff --git a/crypto/packet.c b/crypto/packet.c index 661b59e8..6db97a54 100644 --- a/crypto/packet.c +++ b/crypto/packet.c @@ -265,7 +265,10 @@ static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose) && !put_value(&buf[sub->packet_len], packlen, sub->lenbytes)) return 0; - } else if (pkt->endfirst && sub->parent != NULL) { + } else if (pkt->endfirst && sub->parent != NULL + && (packlen != 0 + || (sub->flags + & WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH) == 0)) { size_t tmplen = packlen; size_t numlenbytes = 1; diff --git a/crypto/param_build.c b/crypto/param_build.c index c4624ec3..76522cd3 100644 --- a/crypto/param_build.c +++ b/crypto/param_build.c @@ -125,6 +125,8 @@ static void free_all_params(OSSL_PARAM_BLD *bld) void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld) { + if (bld == NULL) + return; free_all_params(bld); sk_OSSL_PARAM_BLD_DEF_free(bld->params); OPENSSL_free(bld); @@ -361,14 +363,12 @@ OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld) if (s == NULL) { CRYPTOerr(CRYPTO_F_OSSL_PARAM_BLD_TO_PARAM, CRYPTO_R_SECURE_MALLOC_FAILURE); - OPENSSL_free(bld); return NULL; } } params = OPENSSL_malloc(total); if (params == NULL) { CRYPTOerr(CRYPTO_F_OSSL_PARAM_BLD_TO_PARAM, ERR_R_MALLOC_FAILURE); - OPENSSL_free(bld); OPENSSL_secure_free(s); return NULL; } diff --git a/crypto/params.c b/crypto/params.c index 32161d05..06ae1bc4 100644 --- a/crypto/params.c +++ b/crypto/params.c @@ -780,7 +780,7 @@ static int get_string_internal(const OSSL_PARAM *p, void **val, size_t max_len, { size_t sz; - if (val == NULL || p == NULL || p->data_type != type) + if ((val == NULL && used_len == NULL) || p == NULL || p->data_type != type) return 0; sz = p->data_size; @@ -793,6 +793,9 @@ static int get_string_internal(const OSSL_PARAM *p, void **val, size_t max_len, if (p->data == NULL) return 0; + if (val == NULL) + return 1; + if (*val == NULL) { char *const q = OPENSSL_malloc(sz); diff --git a/crypto/pem/pem_info.c b/crypto/pem/pem_info.c index 90162d7d..f6a5dedc 100644 --- a/crypto/pem/pem_info.c +++ b/crypto/pem/pem_info.c @@ -23,6 +23,8 @@ #include #include +DEFINE_STACK_OF(X509_INFO) + #ifndef OPENSSL_NO_STDIO STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c index e059328a..c170f60b 100644 --- a/crypto/pem/pem_lib.c +++ b/crypto/pem/pem_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -806,7 +806,7 @@ static int get_header_and_data(BIO *bp, BIO **header, BIO **data, char *name, { BIO *tmp = *header; char *linebuf, *p; - int len, line, ret = 0, end = 0; + int len, line, ret = 0, end = 0, prev_partial_line_read = 0, partial_line_read = 0; /* 0 if not seen (yet), 1 if reading header, 2 if finished header */ enum header_status got_header = MAYBE_HEADER; unsigned int flags_mask; @@ -824,10 +824,18 @@ static int get_header_and_data(BIO *bp, BIO **header, BIO **data, char *name, flags_mask = ~0u; len = BIO_gets(bp, linebuf, LINESIZE); if (len <= 0) { - PEMerr(PEM_F_GET_HEADER_AND_DATA, PEM_R_SHORT_HEADER); + PEMerr(PEM_F_GET_HEADER_AND_DATA, PEM_R_BAD_END_LINE); goto err; } + /* + * Check if line has been read completely or if only part of the line + * has been read. Keep the previous value to ignore newlines that + * appear due to reading a line up until the char before the newline. + */ + prev_partial_line_read = partial_line_read; + partial_line_read = len == LINESIZE-1 && linebuf[LINESIZE-2] != '\n'; + if (got_header == MAYBE_HEADER) { if (memchr(linebuf, ':', len) != NULL) got_header = IN_HEADER; @@ -838,13 +846,19 @@ static int get_header_and_data(BIO *bp, BIO **header, BIO **data, char *name, /* Check for end of header. */ if (linebuf[0] == '\n') { - if (got_header == POST_HEADER) { - /* Another blank line is an error. */ - PEMerr(PEM_F_GET_HEADER_AND_DATA, PEM_R_BAD_END_LINE); - goto err; + /* + * If previous line has been read only partially this newline is a + * regular newline at the end of a line and not an empty line. + */ + if (!prev_partial_line_read) { + if (got_header == POST_HEADER) { + /* Another blank line is an error. */ + PEMerr(PEM_F_GET_HEADER_AND_DATA, PEM_R_BAD_END_LINE); + goto err; + } + got_header = POST_HEADER; + tmp = *data; } - got_header = POST_HEADER; - tmp = *data; continue; } diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index a1e8403e..ee9b6764 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -39,8 +39,8 @@ EVP_PKEY *PEM_read_bio_PrivateKey_ex(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, if ((ui_method = UI_UTIL_wrap_read_pem_callback(cb, 0)) == NULL) return NULL; - if ((ctx = ossl_store_attach_pem_bio(bp, ui_method, u, libctx, - propq)) == NULL) + if ((ctx = OSSL_STORE_attach(bp, libctx, "file", propq, ui_method, u, + NULL, NULL)) == NULL) goto err; #ifndef OPENSSL_NO_SECURE_HEAP { @@ -56,13 +56,14 @@ EVP_PKEY *PEM_read_bio_PrivateKey_ex(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, break; } OSSL_STORE_INFO_free(info); + info = NULL; } if (ret != NULL && x != NULL) *x = ret; err: - ossl_store_detach_pem_bio(ctx); + OSSL_STORE_close(ctx); UI_destroy_method(ui_method); OSSL_STORE_INFO_free(info); return ret; @@ -105,7 +106,8 @@ EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x) OSSL_STORE_CTX *ctx = NULL; OSSL_STORE_INFO *info = NULL; - if ((ctx = ossl_store_attach_pem_bio(bp, UI_null(), NULL, NULL, NULL)) == NULL) + if ((ctx = OSSL_STORE_attach(bp, NULL, "file", NULL, UI_null(), NULL, + NULL, NULL)) == NULL) goto err; while (!OSSL_STORE_eof(ctx) && (info = OSSL_STORE_load(ctx)) != NULL) { @@ -114,13 +116,14 @@ EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x) break; } OSSL_STORE_INFO_free(info); + info = NULL; } if (ret != NULL && x != NULL) *x = ret; err: - ossl_store_detach_pem_bio(ctx); + OSSL_STORE_close(ctx); OSSL_STORE_INFO_free(info); return ret; } @@ -198,7 +201,8 @@ DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u) if ((ui_method = UI_UTIL_wrap_read_pem_callback(cb, 0)) == NULL) return NULL; - if ((ctx = ossl_store_attach_pem_bio(bp, ui_method, u, NULL, NULL)) == NULL) + if ((ctx = OSSL_STORE_attach(bp, NULL, "file", NULL, ui_method, u, + NULL, NULL)) == NULL) goto err; while (!OSSL_STORE_eof(ctx) && (info = OSSL_STORE_load(ctx)) != NULL) { @@ -211,13 +215,14 @@ DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u) } } OSSL_STORE_INFO_free(info); + info = NULL; } if (ret != NULL && x != NULL) *x = ret; err: - ossl_store_detach_pem_bio(ctx); + OSSL_STORE_close(ctx); UI_destroy_method(ui_method); OSSL_STORE_INFO_free(info); return ret; diff --git a/crypto/pem/pvkfmt.c b/crypto/pem/pvkfmt.c index 6896cc4e..e2f57028 100644 --- a/crypto/pem/pvkfmt.c +++ b/crypto/pem/pvkfmt.c @@ -20,6 +20,7 @@ #include "internal/cryptlib.h" #include +#include "internal/pem_int.h" #include #include #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) @@ -89,9 +90,9 @@ static EVP_PKEY *b2i_rsa(const unsigned char **in, static EVP_PKEY *b2i_dss(const unsigned char **in, unsigned int bitlen, int ispub); -static int do_blob_header(const unsigned char **in, unsigned int length, - unsigned int *pmagic, unsigned int *pbitlen, - int *pisdss, int *pispub) +int ossl_do_blob_header(const unsigned char **in, unsigned int length, + unsigned int *pmagic, unsigned int *pbitlen, + int *pisdss, int *pispub) { const unsigned char *p = *in; if (length < 16) @@ -99,13 +100,13 @@ static int do_blob_header(const unsigned char **in, unsigned int length, /* bType */ if (*p == MS_PUBLICKEYBLOB) { if (*pispub == 0) { - PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PRIVATE_KEY_BLOB); + PEMerr(PEM_F_OSSL_DO_BLOB_HEADER, PEM_R_EXPECTING_PRIVATE_KEY_BLOB); return 0; } *pispub = 1; } else if (*p == MS_PRIVATEKEYBLOB) { if (*pispub == 1) { - PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PUBLIC_KEY_BLOB); + PEMerr(PEM_F_OSSL_DO_BLOB_HEADER, PEM_R_EXPECTING_PUBLIC_KEY_BLOB); return 0; } *pispub = 0; @@ -114,7 +115,7 @@ static int do_blob_header(const unsigned char **in, unsigned int length, p++; /* Version */ if (*p++ != 0x2) { - PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_VERSION_NUMBER); + PEMerr(PEM_F_OSSL_DO_BLOB_HEADER, PEM_R_BAD_VERSION_NUMBER); return 0; } /* Ignore reserved, aiKeyAlg */ @@ -129,7 +130,7 @@ static int do_blob_header(const unsigned char **in, unsigned int length, /* fall thru */ case MS_RSA1MAGIC: if (*pispub == 0) { - PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PRIVATE_KEY_BLOB); + PEMerr(PEM_F_OSSL_DO_BLOB_HEADER, PEM_R_EXPECTING_PRIVATE_KEY_BLOB); return 0; } break; @@ -139,13 +140,13 @@ static int do_blob_header(const unsigned char **in, unsigned int length, /* fall thru */ case MS_RSA2MAGIC: if (*pispub == 1) { - PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PUBLIC_KEY_BLOB); + PEMerr(PEM_F_OSSL_DO_BLOB_HEADER, PEM_R_EXPECTING_PUBLIC_KEY_BLOB); return 0; } break; default: - PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_MAGIC_NUMBER); + PEMerr(PEM_F_OSSL_DO_BLOB_HEADER, PEM_R_BAD_MAGIC_NUMBER); return -1; } *in = p; @@ -191,7 +192,7 @@ static EVP_PKEY *do_b2i(const unsigned char **in, unsigned int length, const unsigned char *p = *in; unsigned int bitlen, magic; int isdss; - if (do_blob_header(&p, length, &magic, &bitlen, &isdss, &ispub) <= 0) { + if (ossl_do_blob_header(&p, length, &magic, &bitlen, &isdss, &ispub) <= 0) { PEMerr(PEM_F_DO_B2I, PEM_R_KEYBLOB_HEADER_PARSE_ERROR); return NULL; } @@ -218,7 +219,7 @@ static EVP_PKEY *do_b2i_bio(BIO *in, int ispub) return NULL; } p = hdr_buf; - if (do_blob_header(&p, 16, &magic, &bitlen, &isdss, &ispub) <= 0) + if (ossl_do_blob_header(&p, 16, &magic, &bitlen, &isdss, &ispub) <= 0) return NULL; length = blob_length(bitlen, isdss, ispub); @@ -617,26 +618,26 @@ int i2b_PublicKey_bio(BIO *out, const EVP_PKEY *pk) # ifndef OPENSSL_NO_RC4 -static int do_PVK_header(const unsigned char **in, unsigned int length, - int skip_magic, - unsigned int *psaltlen, unsigned int *pkeylen) +int ossl_do_PVK_header(const unsigned char **in, unsigned int length, + int skip_magic, + unsigned int *psaltlen, unsigned int *pkeylen) { const unsigned char *p = *in; unsigned int pvk_magic, is_encrypted; if (skip_magic) { if (length < 20) { - PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT); + PEMerr(PEM_F_OSSL_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT); return 0; } } else { if (length < 24) { - PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT); + PEMerr(PEM_F_OSSL_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT); return 0; } pvk_magic = read_ledword(&p); if (pvk_magic != MS_PVKMAGIC) { - PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_BAD_MAGIC_NUMBER); + PEMerr(PEM_F_OSSL_DO_PVK_HEADER, PEM_R_BAD_MAGIC_NUMBER); return 0; } } @@ -653,7 +654,7 @@ static int do_PVK_header(const unsigned char **in, unsigned int length, return 0; if (is_encrypted && *psaltlen == 0) { - PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_INCONSISTENT_HEADER); + PEMerr(PEM_F_OSSL_DO_PVK_HEADER, PEM_R_INCONSISTENT_HEADER); return 0; } @@ -766,7 +767,7 @@ EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u) } p = pvk_hdr; - if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen)) + if (!ossl_do_PVK_header(&p, 24, 0, &saltlen, &keylen)) return 0; buflen = (int)keylen + saltlen; buf = OPENSSL_malloc(buflen); @@ -882,9 +883,9 @@ int i2b_PVK_bio(BIO *out, const EVP_PKEY *pk, int enclevel, wrlen = BIO_write(out, tmp, outlen); OPENSSL_free(tmp); if (wrlen == outlen) { - PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE); return outlen; } + PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE); return -1; } diff --git a/crypto/perlasm/s390x.pm b/crypto/perlasm/s390x.pm index b2fea801..dbf48426 100644 --- a/crypto/perlasm/s390x.pm +++ b/crypto/perlasm/s390x.pm @@ -1,7 +1,7 @@ #!/usr/bin/env perl -# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/crypto/perlasm/x86_64-support.pl b/crypto/perlasm/x86_64-support.pl index 66aeaeda..0bacb718 100644 --- a/crypto/perlasm/x86_64-support.pl +++ b/crypto/perlasm/x86_64-support.pl @@ -1,7 +1,7 @@ #! /usr/bin/env perl # Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/crypto/pkcs12/p12_crt.c b/crypto/pkcs12/p12_crt.c index 0e8b419d..f75b2437 100644 --- a/crypto/pkcs12/p12_crt.c +++ b/crypto/pkcs12/p12_crt.c @@ -12,6 +12,10 @@ #include #include "p12_local.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(PKCS7) +DEFINE_STACK_OF(PKCS12_SAFEBAG) + static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, PKCS12_SAFEBAG *bag); diff --git a/crypto/pkcs12/p12_kiss.c b/crypto/pkcs12/p12_kiss.c index a9a3ff54..88925f76 100644 --- a/crypto/pkcs12/p12_kiss.c +++ b/crypto/pkcs12/p12_kiss.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,6 +11,10 @@ #include "internal/cryptlib.h" #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(PKCS7) +DEFINE_STACK_OF(PKCS12_SAFEBAG) + /* Simplified PKCS#12 routines */ static int parse_pk12(PKCS12 *p12, const char *pass, int passlen, diff --git a/crypto/pkcs12/p12_npas.c b/crypto/pkcs12/p12_npas.c index 7c916d46..a83d745b 100644 --- a/crypto/pkcs12/p12_npas.c +++ b/crypto/pkcs12/p12_npas.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,9 @@ #include #include "p12_local.h" +DEFINE_STACK_OF(PKCS7) +DEFINE_STACK_OF(PKCS12_SAFEBAG) + /* PKCS#12 password change routine */ static int newpass_p12(PKCS12 *p12, const char *oldpass, const char *newpass); diff --git a/crypto/pkcs7/pk7_attr.c b/crypto/pkcs7/pk7_attr.c index e7bc808c..926a02a3 100644 --- a/crypto/pkcs7/pk7_attr.c +++ b/crypto/pkcs7/pk7_attr.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,8 @@ #include #include +DEFINE_STACK_OF(X509_ALGOR) + int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap) { diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c index 2cf62b62..3e206524 100644 --- a/crypto/pkcs7/pk7_doit.c +++ b/crypto/pkcs7/pk7_doit.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,11 @@ #include #include +DEFINE_STACK_OF(X509_ALGOR) +DEFINE_STACK_OF(X509_ATTRIBUTE) +DEFINE_STACK_OF(PKCS7_RECIP_INFO) +DEFINE_STACK_OF(PKCS7_SIGNER_INFO) + static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, void *value); static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid); diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c index ca039656..32e2ffc8 100644 --- a/crypto/pkcs7/pk7_lib.c +++ b/crypto/pkcs7/pk7_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,12 @@ #include "crypto/asn1.h" #include "crypto/evp.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(X509_ALGOR) +DEFINE_STACK_OF(PKCS7_RECIP_INFO) +DEFINE_STACK_OF(PKCS7_SIGNER_INFO) + long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg) { int nid; diff --git a/crypto/pkcs7/pk7_smime.c b/crypto/pkcs7/pk7_smime.c index 43ad266a..385b4af4 100644 --- a/crypto/pkcs7/pk7_smime.c +++ b/crypto/pkcs7/pk7_smime.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,9 +14,13 @@ #include #include - #define BUFFERSIZE 4096 +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_ATTRIBUTE) +DEFINE_STACK_OF(X509_ALGOR) +DEFINE_STACK_OF(PKCS7_SIGNER_INFO) + static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si); PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, diff --git a/crypto/ppccap.c b/crypto/ppccap.c index 0b2cc78d..4989e432 100644 --- a/crypto/ppccap.c +++ b/crypto/ppccap.c @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -87,7 +87,7 @@ void sha512_block_data_order(void *ctx, const void *inp, size_t len) * TODO(3.0): Temporarily disabled some assembler that hasn't been brought into * the FIPS module yet. */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # ifndef OPENSSL_NO_CHACHA void ChaCha20_ctr32_int(unsigned char *out, const unsigned char *inp, size_t len, const unsigned int key[8], @@ -145,7 +145,7 @@ int poly1305_init(void *ctx, const unsigned char key[16], void *func[2]) return 1; } # endif -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ #ifdef ECP_NISTZ256_ASM void ecp_nistz256_mul_mont(unsigned long res[4], const unsigned long a[4], diff --git a/crypto/property/build.info b/crypto/property/build.info index bfa1f060..56f26760 100644 --- a/crypto/property/build.info +++ b/crypto/property/build.info @@ -2,3 +2,4 @@ LIBS=../../libcrypto $COMMON=property_string.c property_parse.c property.c defn_cache.c SOURCE[../../libcrypto]=$COMMON property_err.c SOURCE[../../providers/libfips.a]=$COMMON +SOURCE[../../providers/liblegacy.a]=$COMMON diff --git a/crypto/property/property.c b/crypto/property/property.c index 0e31b8fa..ef39057c 100644 --- a/crypto/property/property.c +++ b/crypto/property/property.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use @@ -305,7 +305,7 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid, int ret = 0; int j, best = -1, score, optional; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL); #endif @@ -362,10 +362,51 @@ fin: return ret; } -int ossl_method_store_set_global_properties(OSSL_METHOD_STORE *store, - const char *prop_query) { +int ossl_method_store_global_property_is_enabled(OSSL_METHOD_STORE *store, + const char *prop_name) +{ int ret = 0; + if (store == NULL) + return 0; + + ossl_property_read_lock(store); + ret = ossl_property_is_enabled(store->ctx, prop_name, + store->global_properties); + ossl_property_unlock(store); + return ret; +} + +int ossl_method_store_set_global_properties(OSSL_METHOD_STORE *store, + const char *prop_query) +{ + int ret = 0; + + if (store == NULL) + return 1; + + ossl_property_write_lock(store); + ossl_method_cache_flush_all(store); + + ossl_property_free(store->global_properties); + store->global_properties = NULL; + + if (prop_query == NULL) { + ossl_property_unlock(store); + return 1; + } + store->global_properties = ossl_parse_query(store->ctx, prop_query); + ret = store->global_properties != NULL; + ossl_property_unlock(store); + return ret; +} + +int ossl_method_store_merge_global_properties(OSSL_METHOD_STORE *store, + const char *prop_query) +{ + int ret = 0; + OSSL_PROPERTY_LIST *prop = NULL, *global; + if (store == NULL) return 1; @@ -374,15 +415,31 @@ int ossl_method_store_set_global_properties(OSSL_METHOD_STORE *store, if (prop_query == NULL) { ossl_property_free(store->global_properties); store->global_properties = NULL; - ossl_property_unlock(store); - return 1; + goto success; } - store->global_properties = ossl_parse_query(store->ctx, prop_query); - ret = store->global_properties != NULL; + prop = ossl_parse_query(store->ctx, prop_query); + if (prop == NULL) + goto end; + + if (store->global_properties == NULL) { + store->global_properties = prop; + prop = NULL; + goto success; + } + global = ossl_property_merge(prop, store->global_properties); + if (global == NULL) + goto end; + ossl_property_free(store->global_properties); + store->global_properties = global; + success: + ret = 1; + end: ossl_property_unlock(store); + ossl_property_free(prop); return ret; } + static void impl_cache_flush_alg(ossl_uintmax_t idx, ALGORITHM *alg) { lh_QUERY_doall(alg->cache, &impl_cache_free); diff --git a/crypto/property/property_parse.c b/crypto/property/property_parse.c index eee76abc..21f78c02 100644 --- a/crypto/property/property_parse.c +++ b/crypto/property/property_parse.c @@ -453,6 +453,35 @@ int ossl_property_has_optional(const OSSL_PROPERTY_LIST *query) return query->has_optional ? 1 : 0; } +int ossl_property_is_enabled(OPENSSL_CTX *ctx, const char *property_name, + const OSSL_PROPERTY_LIST *prop_list) +{ + int i; + OSSL_PROPERTY_IDX name_id; + const PROPERTY_DEFINITION *prop = NULL; + + if (prop_list == NULL) + return 0; + + if (!parse_name(ctx, &property_name, 0, &name_id)) + return 0; + + prop = prop_list->properties; + for (i = 0; i < prop_list->n; ++i) { + if (prop[i].name_idx == name_id) { + /* Do a separate check for override as it does not set type */ + if (prop[i].optional || prop[i].oper == PROPERTY_OVERRIDE) + return 0; + return (prop[i].type == PROPERTY_TYPE_STRING + && ((prop[i].oper == PROPERTY_OPER_EQ + && prop[i].v.str_val == ossl_property_true) + || (prop[i].oper == PROPERTY_OPER_NE + && prop[i].v.str_val != ossl_property_true))); + } + } + return 0; +} + /* * Compare a query against a definition. * Return the number of clauses matched or -1 if a mandatory clause is false. diff --git a/crypto/provider_conf.c b/crypto/provider_conf.c index 1dd5b1d1..ce09fae7 100644 --- a/crypto/provider_conf.c +++ b/crypto/provider_conf.c @@ -14,9 +14,11 @@ #include #include "internal/provider.h" +DEFINE_STACK_OF(OSSL_PROVIDER) +DEFINE_STACK_OF(CONF_VALUE) + /* PROVIDER config module */ -DEFINE_STACK_OF(OSSL_PROVIDER) static STACK_OF(OSSL_PROVIDER) *activated_providers = NULL; static const char *skip_dot(const char *name) diff --git a/crypto/provider_core.c b/crypto/provider_core.c index f1118a20..662576cd 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -19,7 +19,7 @@ #include "internal/provider.h" #include "internal/refcount.h" #include "provider_local.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # include #endif @@ -54,7 +54,7 @@ struct ossl_provider_st { STACK_OF(INFOPAIR) *parameters; OPENSSL_CTX *libctx; /* The library context this instance is in */ struct provider_store_st *store; /* The store this instance belongs to */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * In the FIPS module inner provider, this isn't needed, since the * error upcalls are always direct calls to the outer provider. @@ -140,7 +140,7 @@ static void *provider_store_new(OPENSSL_CTX *ctx) } prov->libctx = ctx; prov->store = store; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE prov->error_lib = ERR_get_next_error_library(); #endif if(p->is_fallback) @@ -176,7 +176,7 @@ OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name, OSSL_PROVIDER tmpl = { 0, }; int i; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * Make sure any providers are loaded from config before we try to find * them. @@ -264,7 +264,7 @@ OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name, } else { prov->libctx = libctx; prov->store = store; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE prov->error_lib = ERR_get_next_error_library(); #endif } @@ -303,13 +303,13 @@ void ossl_provider_free(OSSL_PROVIDER *prov) * When that happens, the provider is inactivated. */ if (ref < 2 && prov->flag_initialized) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE ossl_init_thread_deregister(prov); #endif if (prov->teardown != NULL) prov->teardown(prov->provctx); #ifndef OPENSSL_NO_ERR -# ifndef FIPS_MODE +# ifndef FIPS_MODULE if (prov->error_strings != NULL) { ERR_unload_strings(prov->error_lib, prov->error_strings); OPENSSL_free(prov->error_strings); @@ -325,7 +325,7 @@ void ossl_provider_free(OSSL_PROVIDER *prov) * the store. All we have to do here is clean it out. */ if (ref == 0) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE DSO_free(prov->module); #endif OPENSSL_free(prov->name); @@ -418,8 +418,9 @@ int OSSL_PROVIDER_set_default_search_path(OPENSSL_CTX *libctx, const char *path) static int provider_activate(OSSL_PROVIDER *prov) { const OSSL_DISPATCH *provider_dispatch = NULL; + void *tmp_provctx = NULL; /* safety measure */ #ifndef OPENSSL_NO_ERR -# ifndef FIPS_MODE +# ifndef FIPS_MODULE OSSL_provider_get_reason_strings_fn *p_get_reason_strings = NULL; # endif #endif @@ -432,7 +433,7 @@ static int provider_activate(OSSL_PROVIDER *prov) * a loadable module. */ if (prov->init_function == NULL) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return 0; #else if (prov->module == NULL) { @@ -487,16 +488,17 @@ static int provider_activate(OSSL_PROVIDER *prov) /* Call the initialise function for the provider. */ if (prov->init_function == NULL - || !prov->init_function(prov, core_dispatch, &provider_dispatch, - &prov->provctx)) { + || !prov->init_function((OSSL_CORE_HANDLE *)prov, core_dispatch, + &provider_dispatch, &tmp_provctx)) { ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_INIT_FAIL, NULL, "name=%s", prov->name); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE DSO_free(prov->module); prov->module = NULL; #endif return 0; } + prov->provctx = tmp_provctx; for (; provider_dispatch->function_id != 0; provider_dispatch++) { switch (provider_dispatch->function_id) { @@ -517,7 +519,7 @@ static int provider_activate(OSSL_PROVIDER *prov) OSSL_get_provider_query_operation(provider_dispatch); break; #ifndef OPENSSL_NO_ERR -# ifndef FIPS_MODE +# ifndef FIPS_MODULE case OSSL_FUNC_PROVIDER_GET_REASON_STRINGS: p_get_reason_strings = OSSL_get_provider_get_reason_strings(provider_dispatch); @@ -528,7 +530,7 @@ static int provider_activate(OSSL_PROVIDER *prov) } #ifndef OPENSSL_NO_ERR -# ifndef FIPS_MODE +# ifndef FIPS_MODULE if (p_get_reason_strings != NULL) { const OSSL_ITEM *reasonstrings = p_get_reason_strings(prov->provctx); size_t cnt, cnt2; @@ -671,7 +673,7 @@ int ossl_provider_forall_loaded(OPENSSL_CTX *ctx, int ret = 1; struct provider_store_st *store = get_provider_store(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * Make sure any providers are loaded from config before we try to use * them. @@ -730,7 +732,7 @@ const DSO *ossl_provider_dso(const OSSL_PROVIDER *prov) const char *ossl_provider_module_name(const OSSL_PROVIDER *prov) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return NULL; #else return DSO_get_filename(prov->module); @@ -739,7 +741,7 @@ const char *ossl_provider_module_name(const OSSL_PROVIDER *prov) const char *ossl_provider_module_path(const OSSL_PROVIDER *prov) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return NULL; #else /* FIXME: Ensure it's a full path */ @@ -807,7 +809,7 @@ static OSSL_core_gettable_params_fn core_gettable_params; static OSSL_core_get_params_fn core_get_params; static OSSL_core_thread_start_fn core_thread_start; static OSSL_core_get_library_context_fn core_get_libctx; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static OSSL_core_new_error_fn core_new_error; static OSSL_core_set_error_debug_fn core_set_error_debug; static OSSL_core_vset_error_fn core_vset_error; @@ -816,22 +818,27 @@ static OSSL_core_clear_last_error_mark_fn core_clear_last_error_mark; static OSSL_core_pop_error_to_mark_fn core_pop_error_to_mark; #endif -static const OSSL_PARAM *core_gettable_params(const OSSL_PROVIDER *prov) +static const OSSL_PARAM *core_gettable_params(const OSSL_CORE_HANDLE *handle) { return param_types; } -static int core_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) +static int core_get_params(const OSSL_CORE_HANDLE *handle, OSSL_PARAM params[]) { int i; OSSL_PARAM *p; + /* + * We created this object originally and we know it is actually an + * OSSL_PROVIDER *, so the cast is safe + */ + OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle; if ((p = OSSL_PARAM_locate(params, "openssl-version")) != NULL) OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR); if ((p = OSSL_PARAM_locate(params, "provider-name")) != NULL) OSSL_PARAM_set_utf8_ptr(p, prov->name); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if ((p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_MODULE_FILENAME)) != NULL) OSSL_PARAM_set_utf8_ptr(p, ossl_provider_module_path(prov)); #endif @@ -848,14 +855,26 @@ static int core_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) return 1; } -static OPENSSL_CTX *core_get_libctx(const OSSL_PROVIDER *prov) +static OPENSSL_CORE_CTX *core_get_libctx(const OSSL_CORE_HANDLE *handle) { - return ossl_provider_library_context(prov); + /* + * We created this object originally and we know it is actually an + * OSSL_PROVIDER *, so the cast is safe + */ + OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle; + + return (OPENSSL_CORE_CTX *)ossl_provider_library_context(prov); } -static int core_thread_start(const OSSL_PROVIDER *prov, +static int core_thread_start(const OSSL_CORE_HANDLE *handle, OSSL_thread_stop_handler_fn handfn) { + /* + * We created this object originally and we know it is actually an + * OSSL_PROVIDER *, so the cast is safe + */ + OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle; + return ossl_init_thread_start(prov, prov->provctx, handfn); } @@ -864,28 +883,34 @@ static int core_thread_start(const OSSL_PROVIDER *prov, * needed there, since the FIPS module upcalls are always the outer provider * ones. */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* - * TODO(3.0) These error functions should use |prov| to select the proper + * TODO(3.0) These error functions should use |handle| to select the proper * library context to report in the correct error stack, at least if error * stacks become tied to the library context. * We cannot currently do that since there's no support for it in the * ERR subsystem. */ -static void core_new_error(const OSSL_PROVIDER *prov) +static void core_new_error(const OSSL_CORE_HANDLE *handle) { ERR_new(); } -static void core_set_error_debug(const OSSL_PROVIDER *prov, +static void core_set_error_debug(const OSSL_CORE_HANDLE *handle, const char *file, int line, const char *func) { ERR_set_debug(file, line, func); } -static void core_vset_error(const OSSL_PROVIDER *prov, +static void core_vset_error(const OSSL_CORE_HANDLE *handle, uint32_t reason, const char *fmt, va_list args) { + /* + * We created this object originally and we know it is actually an + * OSSL_PROVIDER *, so the cast is safe + */ + OSSL_PROVIDER *prov = (OSSL_PROVIDER *)handle; + /* * If the uppermost 8 bits are non-zero, it's an OpenSSL library * error and will be treated as such. Otherwise, it's a new style @@ -898,21 +923,21 @@ static void core_vset_error(const OSSL_PROVIDER *prov, } } -static int core_set_error_mark(const OSSL_PROVIDER *prov) +static int core_set_error_mark(const OSSL_CORE_HANDLE *handle) { return ERR_set_mark(); } -static int core_clear_last_error_mark(const OSSL_PROVIDER *prov) +static int core_clear_last_error_mark(const OSSL_CORE_HANDLE *handle) { return ERR_clear_last_mark(); } -static int core_pop_error_to_mark(const OSSL_PROVIDER *prov) +static int core_pop_error_to_mark(const OSSL_CORE_HANDLE *handle) { return ERR_pop_to_mark(); } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ /* * Functions provided by the core. Blank line separates "families" of related @@ -923,7 +948,7 @@ static const OSSL_DISPATCH core_dispatch_[] = { { OSSL_FUNC_CORE_GET_PARAMS, (void (*)(void))core_get_params }, { OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT, (void (*)(void))core_get_libctx }, { OSSL_FUNC_CORE_THREAD_START, (void (*)(void))core_thread_start }, -#ifndef FIPS_MODE +#ifndef FIPS_MODULE { OSSL_FUNC_CORE_NEW_ERROR, (void (*)(void))core_new_error }, { OSSL_FUNC_CORE_SET_ERROR_DEBUG, (void (*)(void))core_set_error_debug }, { OSSL_FUNC_CORE_VSET_ERROR, (void (*)(void))core_vset_error }, @@ -934,6 +959,7 @@ static const OSSL_DISPATCH core_dispatch_[] = { { OSSL_FUNC_BIO_NEW_FILE, (void (*)(void))BIO_new_file }, { OSSL_FUNC_BIO_NEW_MEMBUF, (void (*)(void))BIO_new_mem_buf }, { OSSL_FUNC_BIO_READ_EX, (void (*)(void))BIO_read_ex }, + { OSSL_FUNC_BIO_WRITE_EX, (void (*)(void))BIO_write_ex }, { OSSL_FUNC_BIO_FREE, (void (*)(void))BIO_free }, { OSSL_FUNC_BIO_VPRINTF, (void (*)(void))BIO_vprintf }, { OSSL_FUNC_BIO_VSNPRINTF, (void (*)(void))BIO_vsnprintf }, diff --git a/crypto/provider_predefined.c b/crypto/provider_predefined.c index 42fc5db9..d1c3a6e0 100644 --- a/crypto/provider_predefined.c +++ b/crypto/provider_predefined.c @@ -17,7 +17,7 @@ OSSL_provider_init_fn fips_intern_provider_init; OSSL_provider_init_fn ossl_legacy_provider_init; #endif const struct predefined_providers_st predefined_providers[] = { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE { "fips", fips_intern_provider_init, 1 }, #else { "default", ossl_default_provider_init, 1 }, diff --git a/crypto/rand/drbg_ctr.c b/crypto/rand/drbg_ctr.c index 063e3bb1..050ae496 100644 --- a/crypto/rand/drbg_ctr.c +++ b/crypto/rand/drbg_ctr.c @@ -480,7 +480,7 @@ int drbg_ctr_init(RAND_DRBG *drbg) drbg->max_perslen = DRBG_MAX_LENGTH; drbg->max_adinlen = DRBG_MAX_LENGTH; } else { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE RANDerr(RAND_F_DRBG_CTR_INIT, RAND_R_DERIVATION_FUNCTION_MANDATORY_FOR_FIPS); return 0; diff --git a/crypto/rand/drbg_lib.c b/crypto/rand/drbg_lib.c index c3f3b4eb..cda13595 100644 --- a/crypto/rand/drbg_lib.c +++ b/crypto/rand/drbg_lib.c @@ -161,7 +161,7 @@ static void *drbg_ossl_ctx_new(OPENSSL_CTX *libctx) if (dgbl == NULL) return NULL; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * We need to ensure that base libcrypto thread handling has been * initialised. @@ -468,7 +468,7 @@ static RAND_DRBG *rand_drbg_new(OPENSSL_CTX *ctx, drbg->parent = parent; if (parent == NULL) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE drbg->get_entropy = rand_crngt_get_entropy; drbg->cleanup_entropy = rand_crngt_cleanup_entropy; #else @@ -552,7 +552,7 @@ void RAND_DRBG_free(RAND_DRBG *drbg) drbg->meth->uninstantiate(drbg); rand_pool_free(drbg->adin_pool); CRYPTO_THREAD_lock_free(drbg->lock); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RAND_DRBG, drbg, &drbg->ex_data); #endif @@ -1143,7 +1143,7 @@ int rand_drbg_enable_locking(RAND_DRBG *drbg) return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * Get and set the EXDATA */ @@ -1287,7 +1287,7 @@ static int drbg_add(const void *buf, int num, double randomness) buflen = (size_t)num; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* * NIST SP-800-90A mandates that entropy *shall not* be provided * by the consuming application. By setting the randomness to zero, @@ -1458,7 +1458,7 @@ RAND_METHOD rand_meth = { RAND_METHOD *RAND_OpenSSL(void) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE return &rand_meth; #else return NULL; diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 2e21ddfc..a5eb0bc7 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -17,7 +17,7 @@ #include "rand_local.h" #include "e_os.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # ifndef OPENSSL_NO_ENGINE /* non-NULL if default_RAND_meth is ENGINE-provided */ static ENGINE *funct_ref; @@ -28,7 +28,7 @@ static const RAND_METHOD *default_RAND_meth; static CRYPTO_ONCE rand_init = CRYPTO_ONCE_STATIC_INIT; static int rand_inited = 0; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ #ifdef OPENSSL_RAND_SEED_RDTSC /* @@ -238,7 +238,7 @@ void rand_drbg_cleanup_additional_data(RAND_POOL *pool, unsigned char *out) rand_pool_reattach(pool, out); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE DEFINE_RUN_ONCE_STATIC(do_rand_init) { # ifndef OPENSSL_NO_ENGINE @@ -354,7 +354,7 @@ int RAND_poll(void) return ret; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ /* * Allocate memory and initialize a new random pool @@ -753,7 +753,7 @@ int rand_pool_add_end(RAND_POOL *pool, size_t len, size_t entropy) return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int RAND_set_rand_method(const RAND_METHOD *meth) { if (!RUN_ONCE(&rand_init, do_rand_init)) @@ -772,7 +772,7 @@ int RAND_set_rand_method(const RAND_METHOD *meth) const RAND_METHOD *RAND_get_rand_method(void) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return NULL; #else const RAND_METHOD *tmp_meth = NULL; @@ -804,7 +804,7 @@ const RAND_METHOD *RAND_get_rand_method(void) #endif } -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) int RAND_set_rand_engine(ENGINE *engine) { const RAND_METHOD *tmp_meth = NULL; @@ -899,7 +899,7 @@ int RAND_bytes(unsigned char *buf, int num) return RAND_bytes_ex(NULL, buf, num); } -#if !defined(OPENSSL_NO_DEPRECATED_1_1_0) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_DEPRECATED_1_1_0) && !defined(FIPS_MODULE) int RAND_pseudo_bytes(unsigned char *buf, int num) { const RAND_METHOD *meth = RAND_get_rand_method(); diff --git a/crypto/rand/rand_local.h b/crypto/rand/rand_local.h index 5152bf80..76e50fa2 100644 --- a/crypto/rand/rand_local.h +++ b/crypto/rand/rand_local.h @@ -310,7 +310,7 @@ struct rand_drbg_st { size_t seedlen; DRBG_STATUS state; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* Application data, mainly used in the KATs. */ CRYPTO_EX_DATA ex_data; #endif diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c index bef4af8d..081ffca9 100644 --- a/crypto/rand/rand_unix.c +++ b/crypto/rand/rand_unix.c @@ -27,12 +27,12 @@ # include # endif #endif -#if defined(__FreeBSD__) && !defined(OPENSSL_SYS_UEFI) +#if (defined(__FreeBSD__) || defined(__NetBSD__)) && !defined(OPENSSL_SYS_UEFI) # include # include # include #endif -#if defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(__OpenBSD__) # include #endif @@ -227,10 +227,12 @@ static ssize_t sysctl_random(char *buf, size_t buflen) * when the sysctl returns long and we want to request something not a * multiple of longs, which should never be the case. */ +#if defined(__FreeBSD__) if (!ossl_assert(buflen % sizeof(long) == 0)) { errno = EINVAL; return -1; } +#endif /* * On NetBSD before 4.0 KERN_ARND was an alias for KERN_URND, and only @@ -248,7 +250,7 @@ static ssize_t sysctl_random(char *buf, size_t buflen) mib[1] = KERN_ARND; do { - len = buflen; + len = buflen > 256 ? 256 : buflen; if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) return done > 0 ? done : -1; done += len; @@ -349,7 +351,7 @@ static ssize_t syscall_random(void *buf, size_t buflen) if (getentropy != NULL) return getentropy(buf, buflen) == 0 ? (ssize_t)buflen : -1; -# elif !defined(FIPS_MODE) +# elif !defined(FIPS_MODULE) union { void *p; int (*f)(void *buffer, size_t length); @@ -392,7 +394,7 @@ static int keep_random_devices_open = 1; # if defined(__linux) && defined(DEVRANDOM_WAIT) static void *shm_addr; -# if !defined(FIPS_MODE) +# if !defined(FIPS_MODULE) static void cleanup_shm(void) { shmdt(shm_addr); @@ -463,7 +465,7 @@ static int wait_random_seeded(void) * If this call fails, it isn't a big problem. */ shm_addr = shmat(shm_id, NULL, SHM_RDONLY); -# ifndef FIPS_MODE +# ifndef FIPS_MODULE /* TODO 3.0: The FIPS provider doesn't have OPENSSL_atexit */ if (shm_addr != (void *)-1) OPENSSL_atexit(&cleanup_shm); diff --git a/crypto/rand/rand_vxworks.c b/crypto/rand/rand_vxworks.c index 8a891d2f..427d50d2 100644 --- a/crypto/rand/rand_vxworks.c +++ b/crypto/rand/rand_vxworks.c @@ -1,7 +1,7 @@ /* * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/rand/rand_win.c b/crypto/rand/rand_win.c index 213a7425..89f9d6f1 100644 --- a/crypto/rand/rand_win.c +++ b/crypto/rand/rand_win.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -163,7 +163,7 @@ int rand_pool_add_additional_data(RAND_POOL *pool) return rand_pool_add(pool, (unsigned char *)&data, sizeof(data), 0); } -# if !defined(OPENSSL_NO_DEPRECATED_1_1_0) && !defined(FIPS_MODE) +# if !defined(OPENSSL_NO_DEPRECATED_1_1_0) && !defined(FIPS_MODULE) int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam) { RAND_poll(); diff --git a/crypto/rsa/build.info b/crypto/rsa/build.info index 970c4935..984ad775 100644 --- a/crypto/rsa/build.info +++ b/crypto/rsa/build.info @@ -3,7 +3,7 @@ LIBS=../../libcrypto $COMMON=rsa_ossl.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_pk1.c \ rsa_none.c rsa_oaep.c rsa_chk.c rsa_pss.c rsa_x931.c rsa_crpt.c \ rsa_x931g.c rsa_sp800_56b_gen.c rsa_sp800_56b_check.c rsa_backend.c \ - rsa_mp_names.c + rsa_mp_names.c rsa_schemes.c SOURCE[../../libcrypto]=$COMMON\ rsa_saos.c rsa_err.c rsa_asn1.c rsa_ameth.c rsa_prn.c \ diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index f6af743f..2e52c906 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -37,7 +37,7 @@ static int rsa_param_encode(const EVP_PKEY *pkey, *pstr = NULL; /* If RSA it's just NULL type */ - if (pkey->ameth->pkey_id != EVP_PKEY_RSA_PSS) { + if (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK) != RSA_FLAG_TYPE_RSASSAPSS) { *pstrtype = V_ASN1_NULL; return 1; } @@ -190,6 +190,20 @@ static int rsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) RSA_free(rsa); return 0; } + + RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK); + switch (pkey->ameth->pkey_id) { + case EVP_PKEY_RSA: + RSA_set_flags(rsa, RSA_FLAG_TYPE_RSA); + break; + case EVP_PKEY_RSA_PSS: + RSA_set_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS); + break; + default: + /* Leave the type bits zero */ + break; + } + EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa); return 1; } @@ -1072,18 +1086,23 @@ static size_t rsa_pkey_dirty_cnt(const EVP_PKEY *pkey) return pkey->pkey.rsa->dirty_cnt; } -DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM) - -static int rsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata, - EVP_KEYMGMT *to_keymgmt, OPENSSL_CTX *libctx, - const char *propq) +/* + * For the moment, we trust the call path, where keys going through + * rsa_pkey_export_to() match a KEYMGMT for the "RSA" keytype, while + * keys going through rsa_pss_pkey_export_to() match a KEYMGMT for the + * "RSA-PSS" keytype. + * TODO(3.0) Investigate whether we should simply continue to trust the + * call path, or if we should strengthen this function by checking that + * |rsa_type| matches the RSA key subtype. The latter requires ensuring + * that the type flag for the RSA key is properly set by other functions + * in this file. + */ +static int rsa_int_export_to(const EVP_PKEY *from, int rsa_type, + void *to_keydata, EVP_KEYMGMT *to_keymgmt, + OPENSSL_CTX *libctx, const char *propq) { RSA *rsa = from->pkey.rsa; OSSL_PARAM_BLD *tmpl = OSSL_PARAM_BLD_new(); - const BIGNUM *n = RSA_get0_n(rsa), *e = RSA_get0_e(rsa); - const BIGNUM *d = RSA_get0_d(rsa); - STACK_OF(BIGNUM_const) *primes = NULL, *exps = NULL, *coeffs = NULL; - int numprimes = 0, numexps = 0, numcoeffs = 0; OSSL_PARAM *params = NULL; int selection = 0; int rv = 0; @@ -1098,65 +1117,32 @@ static int rsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata, goto err; /* Public parameters must always be present */ - if (n == NULL || e == NULL) + if (RSA_get0_n(rsa) == NULL || RSA_get0_e(rsa) == NULL) goto err; - /* |e| and |n| are always present */ - if (!OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_RSA_E, e)) - goto err; - if (!OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_RSA_N, n)) + if (!rsa_todata(rsa, tmpl, NULL)) goto err; + selection |= OSSL_KEYMGMT_SELECT_PUBLIC_KEY; - - if (d != NULL) { - int i; - - /* Get all the primes and CRT params */ - if ((primes = sk_BIGNUM_const_new_null()) == NULL - || (exps = sk_BIGNUM_const_new_null()) == NULL - || (coeffs = sk_BIGNUM_const_new_null()) == NULL) - goto err; - - if (!rsa_get0_all_params(rsa, primes, exps, coeffs)) - goto err; - - numprimes = sk_BIGNUM_const_num(primes); - numexps = sk_BIGNUM_const_num(exps); - numcoeffs = sk_BIGNUM_const_num(coeffs); - - /* - * It's permisssible to have zero primes, i.e. no CRT params. - * Otherwise, there must be at least two, as many exponents, - * and one coefficient less. - */ - if (numprimes != 0 - && (numprimes < 2 || numexps < 2 || numcoeffs < 1)) - goto err; - - if (!OSSL_PARAM_BLD_push_BN(tmpl, OSSL_PKEY_PARAM_RSA_D, d)) - goto err; + if (RSA_get0_d(rsa) != NULL) selection |= OSSL_KEYMGMT_SELECT_PRIVATE_KEY; - for (i = 0; i < numprimes && rsa_mp_factor_names[i] != NULL; i++) { - const BIGNUM *num = sk_BIGNUM_const_value(primes, i); + if (rsa->pss != NULL) { + const EVP_MD *md = NULL, *mgf1md = NULL; + int md_nid, mgf1md_nid, saltlen; + RSA_PSS_PARAMS_30 pss_params; - if (!OSSL_PARAM_BLD_push_BN(tmpl, rsa_mp_factor_names[i], num)) - goto err; - } - - for (i = 0; i < numexps && rsa_mp_exp_names[i] != NULL; i++) { - const BIGNUM *num = sk_BIGNUM_const_value(exps, i); - - if (!OSSL_PARAM_BLD_push_BN(tmpl, rsa_mp_exp_names[i], num)) - goto err; - } - - for (i = 0; i < numcoeffs && rsa_mp_coeff_names[i] != NULL; i++) { - const BIGNUM *num = sk_BIGNUM_const_value(coeffs, i); - - if (!OSSL_PARAM_BLD_push_BN(tmpl, rsa_mp_coeff_names[i], num)) - goto err; - } + if (!rsa_pss_get_param(rsa->pss, &md, &mgf1md, &saltlen)) + goto err; + md_nid = EVP_MD_type(md); + mgf1md_nid = EVP_MD_type(mgf1md); + if (!rsa_pss_params_30_set_defaults(&pss_params) + || !rsa_pss_params_30_set_hashalg(&pss_params, md_nid) + || !rsa_pss_params_30_set_maskgenhashalg(&pss_params, mgf1md_nid) + || !rsa_pss_params_30_set_saltlen(&pss_params, saltlen) + || !rsa_pss_params_30_todata(&pss_params, propq, tmpl, NULL)) + goto err; + selection |= OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS; } if ((params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) @@ -1166,31 +1152,104 @@ static int rsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata, rv = evp_keymgmt_import(to_keymgmt, to_keydata, selection, params); err: - sk_BIGNUM_const_free(primes); - sk_BIGNUM_const_free(exps); - sk_BIGNUM_const_free(coeffs); OSSL_PARAM_BLD_free_params(params); OSSL_PARAM_BLD_free(tmpl); return rv; } -static int rsa_pkey_import_from(const OSSL_PARAM params[], void *vpctx) +static int rsa_int_import_from(const OSSL_PARAM params[], void *vpctx, + int rsa_type) { EVP_PKEY_CTX *pctx = vpctx; EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(pctx); RSA *rsa = rsa_new_with_ctx(pctx->libctx); + RSA_PSS_PARAMS_30 rsa_pss_params = { 0, }; + int ok = 0; if (rsa == NULL) { ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); return 0; } - if (!rsa_fromdata(rsa, params) - || !EVP_PKEY_assign_RSA(pkey, rsa)) { - RSA_free(rsa); - return 0; + RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK); + RSA_set_flags(rsa, rsa_type); + + if (!rsa_pss_params_30_fromdata(&rsa_pss_params, params, pctx->libctx)) + goto err; + + switch (rsa_type) { + case RSA_FLAG_TYPE_RSA: + /* + * Were PSS parameters filled in? + * In that case, something's wrong + */ + if (!rsa_pss_params_30_is_unrestricted(&rsa_pss_params)) + goto err; + break; + case RSA_FLAG_TYPE_RSASSAPSS: + /* + * Were PSS parameters filled in? In that case, create the old + * RSA_PSS_PARAMS structure. Otherwise, this is an unrestricted key. + */ + if (!rsa_pss_params_30_is_unrestricted(&rsa_pss_params)) { + /* Create the older RSA_PSS_PARAMS from RSA_PSS_PARAMS_30 data */ + int mdnid = rsa_pss_params_30_hashalg(&rsa_pss_params); + int mgf1mdnid = rsa_pss_params_30_maskgenhashalg(&rsa_pss_params); + int saltlen = rsa_pss_params_30_saltlen(&rsa_pss_params); + const EVP_MD *md = EVP_get_digestbynid(mdnid); + const EVP_MD *mgf1md = EVP_get_digestbynid(mgf1mdnid); + + if ((rsa->pss = rsa_pss_params_create(md, mgf1md, saltlen)) == NULL) + goto err; + } + break; + default: + /* RSA key sub-types we don't know how to handle yet */ + goto err; } - return 1; + + if (!rsa_fromdata(rsa, params)) + goto err; + + switch (rsa_type) { + case RSA_FLAG_TYPE_RSA: + ok = EVP_PKEY_assign_RSA(pkey, rsa); + break; + case RSA_FLAG_TYPE_RSASSAPSS: + ok = EVP_PKEY_assign(pkey, EVP_PKEY_RSA_PSS, rsa); + break; + } + + err: + if (!ok) + RSA_free(rsa); + return ok; +} + +static int rsa_pkey_export_to(const EVP_PKEY *from, void *to_keydata, + EVP_KEYMGMT *to_keymgmt, OPENSSL_CTX *libctx, + const char *propq) +{ + return rsa_int_export_to(from, RSA_FLAG_TYPE_RSA, to_keydata, + to_keymgmt, libctx, propq); +} + +static int rsa_pss_pkey_export_to(const EVP_PKEY *from, void *to_keydata, + EVP_KEYMGMT *to_keymgmt, OPENSSL_CTX *libctx, + const char *propq) +{ + return rsa_int_export_to(from, RSA_FLAG_TYPE_RSASSAPSS, to_keydata, + to_keymgmt, libctx, propq); +} + +static int rsa_pkey_import_from(const OSSL_PARAM params[], void *vpctx) +{ + return rsa_int_import_from(params, vpctx, RSA_FLAG_TYPE_RSA); +} + +static int rsa_pss_pkey_import_from(const OSSL_PARAM params[], void *vpctx) +{ + return rsa_int_import_from(params, vpctx, RSA_FLAG_TYPE_RSASSAPSS); } const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[2] = { @@ -1277,6 +1336,6 @@ const EVP_PKEY_ASN1_METHOD rsa_pss_asn1_meth = { 0, 0, 0, 0, rsa_pkey_dirty_cnt, - rsa_pkey_export_to, - rsa_pkey_import_from + rsa_pss_pkey_export_to, + rsa_pss_pkey_import_from }; diff --git a/crypto/rsa/rsa_backend.c b/crypto/rsa/rsa_backend.c index 57a539c0..7497a857 100644 --- a/crypto/rsa/rsa_backend.c +++ b/crypto/rsa/rsa_backend.c @@ -7,10 +7,16 @@ * https://www.openssl.org/source/license.html */ +#include #include #include +#include +#include "internal/sizes.h" +#include "internal/param_build_set.h" #include "crypto/rsa.h" +#include "e_os.h" /* strcasecmp for Windows() */ + /* * The intention with the "backend" source file is to offer backend support * for legacy backends (EVP_PKEY_ASN1_METHOD and EVP_PKEY_METHOD) and provider @@ -97,3 +103,188 @@ int rsa_fromdata(RSA *rsa, const OSSL_PARAM params[]) return 0; } +DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM) + +int rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]) +{ + int ret = 0; + const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL; + STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null(); + STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null(); + STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null(); + + if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL) + goto err; + + RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d); + rsa_get0_all_params(rsa, factors, exps, coeffs); + + /* Check private key data integrity */ + if (rsa_d != NULL) { + int numprimes = sk_BIGNUM_const_num(factors); + int numexps = sk_BIGNUM_const_num(exps); + int numcoeffs = sk_BIGNUM_const_num(coeffs); + + /* + * It's permisssible to have zero primes, i.e. no CRT params. + * Otherwise, there must be at least two, as many exponents, + * and one coefficient less. + */ + if (numprimes != 0 + && (numprimes < 2 || numexps < 2 || numcoeffs < 1)) + goto err; + } + + if (!ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_N, rsa_n) + || !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_E, rsa_e) + || !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_D, rsa_d) + || !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_factor_names, + factors) + || !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_exp_names, + exps) + || !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_coeff_names, + coeffs)) + goto err; + ret = 1; + err: + sk_BIGNUM_const_free(factors); + sk_BIGNUM_const_free(exps); + sk_BIGNUM_const_free(coeffs); + return ret; +} + +int rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30 *pss, const char *propq, + OSSL_PARAM_BLD *bld, OSSL_PARAM params[]) +{ + if (!rsa_pss_params_30_is_unrestricted(pss)) { + int hashalg_nid = rsa_pss_params_30_hashalg(pss); + int maskgenalg_nid = rsa_pss_params_30_maskgenalg(pss); + int maskgenhashalg_nid = rsa_pss_params_30_maskgenhashalg(pss); + int saltlen = rsa_pss_params_30_saltlen(pss); + int default_hashalg_nid = rsa_pss_params_30_hashalg(NULL); + int default_maskgenalg_nid = rsa_pss_params_30_maskgenalg(NULL); + int default_maskgenhashalg_nid = rsa_pss_params_30_maskgenhashalg(NULL); + const char *mdname = + (hashalg_nid == default_hashalg_nid + ? NULL : rsa_oaeppss_nid2name(hashalg_nid)); + const char *mgfname = + (maskgenalg_nid == default_maskgenalg_nid + ? NULL : rsa_oaeppss_nid2name(maskgenalg_nid)); + const char *mgf1mdname = + (maskgenhashalg_nid == default_maskgenhashalg_nid + ? NULL : rsa_oaeppss_nid2name(maskgenhashalg_nid)); + const char *key_md = OSSL_PKEY_PARAM_RSA_DIGEST; + const char *key_mgf = OSSL_PKEY_PARAM_RSA_MASKGENFUNC; + const char *key_mgf1_md = OSSL_PKEY_PARAM_RSA_MGF1_DIGEST; + const char *key_saltlen = OSSL_PKEY_PARAM_RSA_PSS_SALTLEN; + + /* + * To ensure that the key isn't seen as unrestricted by the recipient, + * we make sure that at least one PSS-related parameter is passed, even + * if it has a default value; saltlen. + */ + if ((mdname != NULL + && !ossl_param_build_set_utf8_string(bld, params, key_md, mdname)) + || (mgfname != NULL + && !ossl_param_build_set_utf8_string(bld, params, + key_mgf, mgfname)) + || (mgf1mdname != NULL + && !ossl_param_build_set_utf8_string(bld, params, + key_mgf1_md, mgf1mdname)) + || (!ossl_param_build_set_int(bld, params, key_saltlen, saltlen))) + return 0; + } + return 1; +} + +int rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30 *pss_params, + const OSSL_PARAM params[], OPENSSL_CTX *libctx) +{ + const OSSL_PARAM *param_md, *param_mgf, *param_mgf1md, *param_saltlen; + EVP_MD *md = NULL, *mgf1md = NULL; + int saltlen; + int ret = 0; + + if (pss_params == NULL) + return 0; + + param_md = + OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_DIGEST); + param_mgf = + OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_MASKGENFUNC); + param_mgf1md = + OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_MGF1_DIGEST); + param_saltlen = + OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_PSS_SALTLEN); + + /* + * If we get any of the parameters, we know we have at least some + * restrictions, so we start by setting default values, and let each + * parameter override their specific restriction data. + */ + if (param_md != NULL || param_mgf != NULL || param_mgf1md != NULL + || param_saltlen != NULL) + if (!rsa_pss_params_30_set_defaults(pss_params)) + return 0; + + if (param_mgf != NULL) { + int default_maskgenalg_nid = rsa_pss_params_30_maskgenalg(NULL); + const char *mgfname = NULL; + + if (param_mgf->data_type == OSSL_PARAM_UTF8_STRING) + mgfname = param_mgf->data; + else if (!OSSL_PARAM_get_utf8_ptr(param_mgf, &mgfname)) + return 0; + + /* TODO Revisit this if / when a new MGF algorithm appears */ + if (strcasecmp(param_mgf->data, + rsa_mgf_nid2name(default_maskgenalg_nid)) != 0) + return 0; + } + + /* + * We're only interested in the NIDs that correspond to the MDs, so the + * exact propquery is unimportant in the EVP_MD_fetch() calls below. + */ + + if (param_md != NULL) { + const char *mdname = NULL; + + if (param_md->data_type == OSSL_PARAM_UTF8_STRING) + mdname = param_md->data; + else if (!OSSL_PARAM_get_utf8_ptr(param_mgf, &mdname)) + goto err; + + if ((md = EVP_MD_fetch(libctx, mdname, NULL)) == NULL + || !rsa_pss_params_30_set_hashalg(pss_params, + rsa_oaeppss_md2nid(md))) + goto err; + } + + if (param_mgf1md != NULL) { + const char *mgf1mdname = NULL; + + if (param_mgf1md->data_type == OSSL_PARAM_UTF8_STRING) + mgf1mdname = param_mgf1md->data; + else if (!OSSL_PARAM_get_utf8_ptr(param_mgf, &mgf1mdname)) + goto err; + + if ((mgf1md = EVP_MD_fetch(libctx, mgf1mdname, NULL)) == NULL + || !rsa_pss_params_30_set_maskgenhashalg(pss_params, + rsa_oaeppss_md2nid(mgf1md))) + goto err; + } + + if (param_saltlen != NULL) { + if (!OSSL_PARAM_get_int(param_saltlen, &saltlen) + || !rsa_pss_params_30_set_saltlen(pss_params, saltlen)) + goto err; + } + + ret = 1; + + err: + EVP_MD_free(md); + EVP_MD_free(mgf1md); + return ret; +} diff --git a/crypto/rsa/rsa_chk.c b/crypto/rsa/rsa_chk.c index 6ba0010c..4b5ee52b 100644 --- a/crypto/rsa/rsa_chk.c +++ b/crypto/rsa/rsa_chk.c @@ -12,7 +12,7 @@ #include "crypto/rsa.h" #include "rsa_local.h" -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static int rsa_validate_keypair_multiprime(const RSA *key, BN_GENCB *cb) { BIGNUM *i, *j, *k, *l, *m; @@ -222,7 +222,7 @@ static int rsa_validate_keypair_multiprime(const RSA *key, BN_GENCB *cb) BN_CTX_free(ctx); return ret; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ int rsa_validate_public(const RSA *key) { @@ -236,7 +236,7 @@ int rsa_validate_private(const RSA *key) int rsa_validate_pairwise(const RSA *key) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return rsa_sp800_56b_check_keypair(key, NULL, -1, RSA_bits(key)); #else return rsa_validate_keypair_multiprime(key, NULL); @@ -250,11 +250,11 @@ int RSA_check_key(const RSA *key) int RSA_check_key_ex(const RSA *key, BN_GENCB *cb) { -#ifdef FIPS_MODE +#ifdef FIPS_MODULE return rsa_validate_public(key) && rsa_validate_private(key) && rsa_validate_pairwise(key); #else return rsa_validate_keypair_multiprime(key, cb); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ } diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c index 16d365c2..d8da0873 100644 --- a/crypto/rsa/rsa_gen.c +++ b/crypto/rsa/rsa_gen.c @@ -43,7 +43,7 @@ int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e_value, BN_GENCB *cb) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* multi-prime is only supported with the builtin key generation */ if (rsa->meth->rsa_multi_prime_keygen != NULL) { return rsa->meth->rsa_multi_prime_keygen(rsa, bits, primes, @@ -60,7 +60,7 @@ int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, else return 0; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ return rsa_keygen(NULL, rsa, bits, primes, e_value, cb, 0); } @@ -68,7 +68,7 @@ static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes, BIGNUM *e_value, BN_GENCB *cb, int pairwise_test) { int ok = -1; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE if (primes != 2) return 0; ok = rsa_sp800_56b_generate_key(rsa, bits, e_value, cb); @@ -401,7 +401,7 @@ static int rsa_keygen(OPENSSL_CTX *libctx, RSA *rsa, int bits, int primes, } BN_CTX_end(ctx); BN_CTX_free(ctx); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ if (pairwise_test && ok > 0) { OSSL_CALLBACK *stcb = NULL; @@ -457,7 +457,7 @@ static int rsa_keygen_pairwise_test(RSA *rsa, OSSL_CALLBACK *cb, void *cbarg) if (ciphertxt_len <= 0) goto err; if (ciphertxt_len == plaintxt_len - && memcmp(decoded, plaintxt, plaintxt_len) == 0) + && memcmp(ciphertxt, plaintxt, plaintxt_len) == 0) goto err; OSSL_SELF_TEST_oncorrupt_byte(st, ciphertxt); diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c index f657c8a8..896783f1 100644 --- a/crypto/rsa/rsa_lib.c +++ b/crypto/rsa/rsa_lib.c @@ -23,7 +23,7 @@ static RSA *rsa_new_intern(ENGINE *engine, OPENSSL_CTX *libctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE RSA *RSA_new(void) { return rsa_new_intern(NULL, NULL); @@ -84,7 +84,7 @@ static RSA *rsa_new_intern(ENGINE *engine, OPENSSL_CTX *libctx) ret->libctx = libctx; ret->meth = RSA_get_default_method(); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW; if (engine) { if (!ENGINE_init(engine)) { @@ -105,7 +105,7 @@ static RSA *rsa_new_intern(ENGINE *engine, OPENSSL_CTX *libctx) #endif ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data)) { goto err; } @@ -138,11 +138,11 @@ void RSA_free(RSA *r) if (r->meth != NULL && r->meth->finish != NULL) r->meth->finish(r); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) ENGINE_finish(r->engine); #endif -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); #endif @@ -156,8 +156,7 @@ void RSA_free(RSA *r) BN_clear_free(r->dmp1); BN_clear_free(r->dmq1); BN_clear_free(r->iqmp); - /* TODO(3.0): Support PSS in FIPS_MODE */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE RSA_PSS_PARAMS_free(r->pss); sk_RSA_PRIME_INFO_pop_free(r->prime_infos, rsa_multip_info_free); #endif @@ -179,7 +178,12 @@ int RSA_up_ref(RSA *r) return i > 1 ? 1 : 0; } -#ifndef FIPS_MODE +OPENSSL_CTX *rsa_get0_libctx(RSA *r) +{ + return r->libctx; +} + +#ifndef FIPS_MODULE int RSA_set_ex_data(RSA *r, int idx, void *arg) { return CRYPTO_set_ex_data(&r->ex_data, idx, arg); @@ -333,7 +337,7 @@ int RSA_security_bits(const RSA *rsa) { int bits = BN_num_bits(rsa->n); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (rsa->version == RSA_ASN1_VERSION_MULTI) { /* This ought to mean that we have private key at hand. */ int ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos); @@ -427,7 +431,7 @@ int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * Is it better to export RSA_PRIME_INFO structure * and related functions to let user pass a triplet? @@ -517,7 +521,7 @@ void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) *q = r->q; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int RSA_get_multi_prime_extra_count(const RSA *r) { int pnum; @@ -561,7 +565,7 @@ void RSA_get0_crt_params(const RSA *r, *iqmp = r->iqmp; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[], const BIGNUM *coeffs[]) { @@ -631,7 +635,17 @@ const BIGNUM *RSA_get0_iqmp(const RSA *r) const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r) { +#ifdef FIPS_MODULE + return NULL; +#else return r->pss; +#endif +} + +/* Internal */ +RSA_PSS_PARAMS_30 *rsa_get0_pss_params_30(RSA *r) +{ + return &r->pss_params; } void RSA_clear_flags(RSA *r, int flags) @@ -655,7 +669,7 @@ int RSA_get_version(RSA *r) return r->version; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE ENGINE *RSA_get0_engine(const RSA *r) { return r->engine; @@ -678,7 +692,7 @@ int rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes, const STACK_OF(BIGNUM) *exps, const STACK_OF(BIGNUM) *coeffs) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE STACK_OF(RSA_PRIME_INFO) *prime_infos, *old_infos = NULL; #endif int pnum; @@ -699,12 +713,12 @@ int rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes, sk_BIGNUM_value(coeffs, 0))) return 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE old_infos = r->prime_infos; #endif if (pnum > 2) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int i; prime_infos = sk_RSA_PRIME_INFO_new_reserve(NULL, pnum); @@ -746,7 +760,7 @@ int rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes, #endif } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (old_infos != NULL) { /* * This is hard to deal with, since the old infos could @@ -762,7 +776,7 @@ int rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes, r->dirty_cnt++; return 1; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE err: /* r, d, t should not be freed */ sk_RSA_PRIME_INFO_pop_free(prime_infos, rsa_multip_info_free_ex); @@ -776,7 +790,7 @@ int rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes, STACK_OF(BIGNUM_const) *exps, STACK_OF(BIGNUM_const) *coeffs) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE RSA_PRIME_INFO *pinfo; int i, pnum; #endif @@ -794,7 +808,7 @@ int rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes, sk_BIGNUM_const_push(exps, RSA_get0_dmq1(r)); sk_BIGNUM_const_push(coeffs, RSA_get0_iqmp(r)); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE pnum = RSA_get_multi_prime_extra_count(r); for (i = 0; i < pnum; i++) { pinfo = sk_RSA_PRIME_INFO_value(r->prime_infos, i); @@ -807,7 +821,7 @@ int rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes, return 1; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad_mode) { OSSL_PARAM pad_params[2], *p = pad_params; @@ -986,47 +1000,16 @@ int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD **md) return 1; } -int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) -{ - const char *name; - - if (ctx == NULL - || (!EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) - && !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx))) { - ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); - /* Uses the same return values as EVP_PKEY_CTX_ctrl */ - return -2; - } - - /* If key type not RSA return error */ - if (ctx->pmeth != NULL - && ctx->pmeth->pkey_id != EVP_PKEY_RSA - && ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS) - return -1; - - /* TODO(3.0): Remove this eventually when no more legacy */ - if ((EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) - && ctx->op.ciph.ciphprovctx == NULL) - || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) - && ctx->op.sig.sigprovctx == NULL)) - return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, - EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, - EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)md); - - name = (md == NULL) ? "" : EVP_MD_name(md); - - return EVP_PKEY_CTX_set_rsa_mgf1_md_name(ctx, name, NULL); -} - -int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname, - const char *mdprops) +static int int_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, + /* For EVP_PKEY_CTX_ctrl() */ + int keytype, int optype, int cmd, + const EVP_MD *md, + /* For EVP_PKEY_CTX_set_params() */ + const char *mdname, const char *mdprops) { OSSL_PARAM rsa_params[3], *p = rsa_params; - if (ctx == NULL - || mdname == NULL - || (!EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) - && !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx))) { + if (ctx == NULL || (ctx->operation & optype) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; @@ -1034,10 +1017,26 @@ int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname, /* If key type not RSA return error */ if (ctx->pmeth != NULL - && ctx->pmeth->pkey_id != EVP_PKEY_RSA - && ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS) + && (keytype == -1 + ? (ctx->pmeth->pkey_id != EVP_PKEY_RSA + && ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS) + : ctx->pmeth->pkey_id != keytype)) return -1; + /* TODO(3.0): Remove this eventually when no more legacy */ + if (cmd != -1) { + if ((EVP_PKEY_CTX_IS_ASYM_CIPHER_OP(ctx) + && ctx->op.ciph.ciphprovctx == NULL) + || (EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) + && ctx->op.sig.sigprovctx == NULL) + || (EVP_PKEY_CTX_IS_GEN_OP(ctx) + && ctx->op.keymgmt.genctx == NULL)) + return EVP_PKEY_CTX_ctrl(ctx, keytype, optype, cmd, 0, (void *)md); + + mdname = (md == NULL) ? "" : EVP_MD_name(md); + } + + *p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_MGF1_DIGEST, /* * Cast away the const. This is @@ -1058,6 +1057,36 @@ int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname, return EVP_PKEY_CTX_set_params(ctx, rsa_params); } +int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) +{ + return int_set_rsa_mgf1_md(ctx, -1, + EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, + EVP_PKEY_CTRL_RSA_MGF1_MD, md, NULL, NULL); +} + +int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname, + const char *mdprops) +{ + return int_set_rsa_mgf1_md(ctx, -1, + EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, + -1, NULL, mdname, mdprops); +} + +int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) +{ + return int_set_rsa_mgf1_md(ctx, EVP_PKEY_RSA_PSS, + EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_RSA_MGF1_MD, + md, NULL, NULL); +} + +int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name(EVP_PKEY_CTX *ctx, + const char *mdname) +{ + return int_set_rsa_mgf1_md(ctx, EVP_PKEY_RSA_PSS, + EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_TYPE_SIG, + -1, NULL, mdname, NULL); +} + int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, char *name, size_t namelen) { @@ -1196,11 +1225,12 @@ int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, unsigned char **label) return (int)labellen; } -int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen) +static int int_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen, + int keytype, int optype) { OSSL_PARAM pad_params[2], *p = pad_params; - if (ctx == NULL) { + if (ctx == NULL || (ctx->operation & optype) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); /* Uses the same return values as EVP_PKEY_CTX_ctrl */ return -2; @@ -1208,14 +1238,19 @@ int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen) /* If key type not RSA or RSA-PSS return error */ if (ctx->pmeth != NULL - && ctx->pmeth->pkey_id != EVP_PKEY_RSA - && ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS) + && (keytype == -1 + ? (ctx->pmeth->pkey_id != EVP_PKEY_RSA + && ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS) + : ctx->pmeth->pkey_id != keytype)) return -1; /* TODO(3.0): Remove this eventually when no more legacy */ - if (!EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) - || ctx->op.sig.sigprovctx == NULL) - return EVP_PKEY_CTX_ctrl(ctx, -1, -1, EVP_PKEY_CTRL_RSA_PSS_SALTLEN, + if ((EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx) + && ctx->op.sig.sigprovctx == NULL) + || (EVP_PKEY_CTX_IS_GEN_OP(ctx) + && ctx->op.keymgmt.genctx == NULL)) + return EVP_PKEY_CTX_ctrl(ctx, keytype, optype, + EVP_PKEY_CTRL_RSA_PSS_SALTLEN, saltlen, NULL); *p++ = @@ -1225,6 +1260,17 @@ int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen) return EVP_PKEY_CTX_set_params(ctx, pad_params); } +int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen) +{ + return int_set_rsa_pss_saltlen(ctx, saltlen, -1, EVP_PKEY_OP_TYPE_SIG); +} + +int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, int saltlen) +{ + return int_set_rsa_pss_saltlen(ctx, saltlen, EVP_PKEY_RSA_PSS, + EVP_PKEY_OP_KEYGEN); +} + int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen) { OSSL_PARAM pad_params[2], *p = pad_params; diff --git a/crypto/rsa/rsa_local.h b/crypto/rsa/rsa_local.h index a5e4b6fd..f94fc79c 100644 --- a/crypto/rsa/rsa_local.h +++ b/crypto/rsa/rsa_local.h @@ -12,6 +12,7 @@ #include #include "internal/refcount.h" +#include "crypto/rsa.h" #define RSA_MAX_PRIME_NUM 5 #define RSA_MIN_MODULUS_BITS 512 @@ -50,9 +51,19 @@ struct rsa_st { BIGNUM *dmp1; BIGNUM *dmq1; BIGNUM *iqmp; - /* If a PSS only key this contains the parameter restrictions */ + + /* + * If a PSS only key this contains the parameter restrictions. + * There are two structures for the same thing, used in different cases. + */ + /* This is used uniquely by OpenSSL provider implementations. */ + RSA_PSS_PARAMS_30 pss_params; +#ifndef FIPS_MODULE + /* This is used uniquely by rsa_ameth.c and rsa_pmeth.c. */ RSA_PSS_PARAMS *pss; -#ifndef FIPS_MODE +#endif + +#ifndef FIPS_MODULE /* for multi-prime RSA, defined in RFC 8017 */ STACK_OF(RSA_PRIME_INFO) *prime_infos; /* Be careful using this if the RSA structure is shared */ diff --git a/crypto/rsa/rsa_mp_names.c b/crypto/rsa/rsa_mp_names.c index e69321a4..15b1b9e0 100644 --- a/crypto/rsa/rsa_mp_names.c +++ b/crypto/rsa/rsa_mp_names.c @@ -23,7 +23,7 @@ const char *rsa_mp_factor_names[] = { OSSL_PKEY_PARAM_RSA_FACTOR1, OSSL_PKEY_PARAM_RSA_FACTOR2, -#ifndef FIPS_MODE +#ifndef FIPS_MODULE OSSL_PKEY_PARAM_RSA_FACTOR3, OSSL_PKEY_PARAM_RSA_FACTOR4, OSSL_PKEY_PARAM_RSA_FACTOR5, @@ -43,7 +43,7 @@ const char *rsa_mp_factor_names[] = { const char *rsa_mp_exp_names[] = { OSSL_PKEY_PARAM_RSA_EXPONENT1, OSSL_PKEY_PARAM_RSA_EXPONENT2, -#ifndef FIPS_MODE +#ifndef FIPS_MODULE OSSL_PKEY_PARAM_RSA_EXPONENT3, OSSL_PKEY_PARAM_RSA_EXPONENT4, OSSL_PKEY_PARAM_RSA_EXPONENT5, @@ -63,7 +63,7 @@ const char *rsa_mp_exp_names[] = { const char *rsa_mp_coeff_names[] = { OSSL_PKEY_PARAM_RSA_COEFFICIENT1, OSSL_PKEY_PARAM_RSA_COEFFICIENT2, -#ifndef FIPS_MODE +#ifndef FIPS_MODULE OSSL_PKEY_PARAM_RSA_COEFFICIENT3, OSSL_PKEY_PARAM_RSA_COEFFICIENT4, OSSL_PKEY_PARAM_RSA_COEFFICIENT5, diff --git a/crypto/rsa/rsa_oaep.c b/crypto/rsa/rsa_oaep.c index 9fac1b84..cc673367 100644 --- a/crypto/rsa/rsa_oaep.c +++ b/crypto/rsa/rsa_oaep.c @@ -61,7 +61,7 @@ int rsa_padding_add_PKCS1_OAEP_mgf1_with_libctx(OPENSSL_CTX *libctx, unsigned char seedmask[EVP_MAX_MD_SIZE]; int mdlen, dbmask_len = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (md == NULL) md = EVP_sha1(); #else @@ -165,7 +165,7 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, int mdlen; if (md == NULL) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE md = EVP_sha1(); #else RSAerr(0, ERR_R_PASSED_NULL_PARAMETER); @@ -296,7 +296,7 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, to[i] = constant_time_select_8(mask, db[i + mdlen + 1], to[i]); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * To avoid chosen ciphertext attacks, the error message should not * reveal which kind of decoding error happened. diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c index bed9dd5e..b757da7f 100644 --- a/crypto/rsa/rsa_ossl.c +++ b/crypto/rsa/rsa_ossl.c @@ -113,7 +113,7 @@ static int rsa_ossl_public_encrypt(int flen, const unsigned char *from, from, flen, NULL, 0, NULL, NULL); break; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE case RSA_SSLV23_PADDING: i = rsa_padding_add_SSLv23_with_libctx(rsa->libctx, buf, num, from, flen); @@ -486,7 +486,7 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, case RSA_PKCS1_OAEP_PADDING: r = RSA_padding_check_PKCS1_OAEP(to, num, buf, j, num, NULL, 0); break; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE case RSA_SSLV23_PADDING: r = RSA_padding_check_SSLv23(to, num, buf, j, num); break; @@ -498,7 +498,7 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE); goto err; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * This trick doesn't work in the FIPS provider because libcrypto manages * the error stack. Instead we opt not to put an error on the stack at all @@ -617,7 +617,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) { BIGNUM *r1, *m1, *vrfy; int ret = 0, smooth = 0; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE BIGNUM *r2, *m[RSA_MAX_PRIME_NUM - 2]; int i, ex_primes = 0; RSA_PRIME_INFO *pinfo; @@ -626,7 +626,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) BN_CTX_start(ctx); r1 = BN_CTX_get(ctx); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE r2 = BN_CTX_get(ctx); #endif m1 = BN_CTX_get(ctx); @@ -634,7 +634,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) if (vrfy == NULL) goto err; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (rsa->version == RSA_ASN1_VERSION_MULTI && ((ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0 || ex_primes > RSA_MAX_PRIME_NUM - 2)) @@ -660,7 +660,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) BN_free(factor); goto err; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE for (i = 0; i < ex_primes; i++) { pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i); BN_with_flags(factor, pinfo->r, BN_FLG_CONSTTIME); @@ -676,7 +676,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) BN_free(factor); smooth = (rsa->meth->bn_mod_exp == BN_mod_exp_mont) -#ifndef FIPS_MODE +#ifndef FIPS_MODULE && (ex_primes == 0) #endif && (BN_num_bits(rsa->q) == BN_num_bits(rsa->p)); @@ -784,7 +784,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) BN_free(dmp1); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * calculate m_i in multi-prime case * @@ -878,7 +878,7 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) if (!BN_add(r0, r1, m1)) goto err; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* add m_i to m in multi-prime case */ if (ex_primes > 0) { BIGNUM *pr2 = BN_new(); @@ -997,7 +997,7 @@ static int rsa_ossl_init(RSA *rsa) static int rsa_ossl_finish(RSA *rsa) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int i; RSA_PRIME_INFO *pinfo; diff --git a/crypto/rsa/rsa_pk1.c b/crypto/rsa/rsa_pk1.c index 2db8ff34..087071f5 100644 --- a/crypto/rsa/rsa_pk1.c +++ b/crypto/rsa/rsa_pk1.c @@ -259,7 +259,7 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, } OPENSSL_clear_free(em, num); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * This trick doesn't work in the FIPS provider because libcrypto manages * the error stack. Instead we opt not to put an error on the stack at all diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c index 2ac44fdd..aca046fd 100644 --- a/crypto/rsa/rsa_pmeth.c +++ b/crypto/rsa/rsa_pmeth.c @@ -376,6 +376,8 @@ static int check_padding_md(const EVP_MD *md, int padding) case NID_sha256: case NID_sha384: case NID_sha512: + case NID_sha512_224: + case NID_sha512_256: case NID_md5: case NID_md5_sha1: case NID_md2: diff --git a/crypto/rsa/rsa_pss.c b/crypto/rsa/rsa_pss.c index 365e77f5..8a9ac659 100644 --- a/crypto/rsa/rsa_pss.c +++ b/crypto/rsa/rsa_pss.c @@ -250,6 +250,142 @@ int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, } +/* + * The defaults for PSS restrictions are defined in RFC 8017, A.2.3 RSASSA-PSS + * (https://tools.ietf.org/html/rfc8017#appendix-A.2.3): + * + * If the default values of the hashAlgorithm, maskGenAlgorithm, and + * trailerField fields of RSASSA-PSS-params are used, then the algorithm + * identifier will have the following value: + * + * rSASSA-PSS-Default-Identifier RSASSA-AlgorithmIdentifier ::= { + * algorithm id-RSASSA-PSS, + * parameters RSASSA-PSS-params : { + * hashAlgorithm sha1, + * maskGenAlgorithm mgf1SHA1, + * saltLength 20, + * trailerField trailerFieldBC + * } + * } + * + * RSASSA-AlgorithmIdentifier ::= AlgorithmIdentifier { + * {PKCS1Algorithms} + * } + */ +static const RSA_PSS_PARAMS_30 default_RSASSA_PSS_params = { + NID_sha1, /* default hashAlgorithm */ + { + NID_mgf1, /* default maskGenAlgorithm */ + NID_sha1 /* default MGF1 hash */ + }, + 20, /* default saltLength */ + 1 /* default trailerField (0xBC) */ +}; + +int rsa_pss_params_30_set_defaults(RSA_PSS_PARAMS_30 *rsa_pss_params) +{ + if (rsa_pss_params == NULL) + return 0; + *rsa_pss_params = default_RSASSA_PSS_params; + return 1; +} + +int rsa_pss_params_30_is_unrestricted(const RSA_PSS_PARAMS_30 *rsa_pss_params) +{ + static RSA_PSS_PARAMS_30 pss_params_cmp = { 0, }; + + return rsa_pss_params == NULL + || memcmp(rsa_pss_params, &pss_params_cmp, + sizeof(*rsa_pss_params)) == 0; +} + +int rsa_pss_params_30_copy(RSA_PSS_PARAMS_30 *to, + const RSA_PSS_PARAMS_30 *from) +{ + memcpy(to, from, sizeof(*to)); + return 1; +} + +int rsa_pss_params_30_set_hashalg(RSA_PSS_PARAMS_30 *rsa_pss_params, + int hashalg_nid) +{ + if (rsa_pss_params == NULL) + return 0; + rsa_pss_params->hash_algorithm_nid = hashalg_nid; + return 1; +} + +int rsa_pss_params_30_set_maskgenalg(RSA_PSS_PARAMS_30 *rsa_pss_params, + int maskgenalg_nid) +{ + if (rsa_pss_params == NULL) + return 0; + rsa_pss_params->mask_gen.algorithm_nid = maskgenalg_nid; + return 1; +} + +int rsa_pss_params_30_set_maskgenhashalg(RSA_PSS_PARAMS_30 *rsa_pss_params, + int maskgenhashalg_nid) +{ + if (rsa_pss_params == NULL) + return 0; + rsa_pss_params->mask_gen.hash_algorithm_nid = maskgenhashalg_nid; + return 1; +} + +int rsa_pss_params_30_set_saltlen(RSA_PSS_PARAMS_30 *rsa_pss_params, + int saltlen) +{ + if (rsa_pss_params == NULL) + return 0; + rsa_pss_params->salt_len = saltlen; + return 1; +} + +int rsa_pss_params_30_set_trailerfield(RSA_PSS_PARAMS_30 *rsa_pss_params, + int trailerfield) +{ + if (rsa_pss_params == NULL) + return 0; + rsa_pss_params->trailer_field = trailerfield; + return 1; +} + +int rsa_pss_params_30_hashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params) +{ + if (rsa_pss_params == NULL) + return default_RSASSA_PSS_params.hash_algorithm_nid; + return rsa_pss_params->hash_algorithm_nid; +} + +int rsa_pss_params_30_maskgenalg(const RSA_PSS_PARAMS_30 *rsa_pss_params) +{ + if (rsa_pss_params == NULL) + return default_RSASSA_PSS_params.mask_gen.algorithm_nid; + return rsa_pss_params->mask_gen.algorithm_nid; +} + +int rsa_pss_params_30_maskgenhashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params) +{ + if (rsa_pss_params == NULL) + return default_RSASSA_PSS_params.hash_algorithm_nid; + return rsa_pss_params->mask_gen.hash_algorithm_nid; +} + +int rsa_pss_params_30_saltlen(const RSA_PSS_PARAMS_30 *rsa_pss_params) +{ + if (rsa_pss_params == NULL) + return default_RSASSA_PSS_params.salt_len; + return rsa_pss_params->salt_len; +} + +int rsa_pss_params_30_trailerfield(const RSA_PSS_PARAMS_30 *rsa_pss_params) +{ + if (rsa_pss_params == NULL) + return default_RSASSA_PSS_params.trailer_field; + return rsa_pss_params->trailer_field; +} + #if defined(_MSC_VER) # pragma optimize("",on) #endif diff --git a/crypto/rsa/rsa_schemes.c b/crypto/rsa/rsa_schemes.c new file mode 100644 index 00000000..7a54296a --- /dev/null +++ b/crypto/rsa/rsa_schemes.c @@ -0,0 +1,86 @@ +/* + * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include +#include +#include +#include "internal/nelem.h" +#include "crypto/rsa.h" + +static int meth2nid(const void *meth, + int (*meth_is_a)(const void *meth, const char *name), + const OSSL_ITEM *items, size_t items_n) +{ + size_t i; + + if (meth != NULL) + for (i = 0; i < items_n; i++) + if (meth_is_a(meth, items[i].ptr)) + return (int)items[i].id; + return NID_undef; +} + +static const char *nid2name(int meth, const OSSL_ITEM *items, size_t items_n) +{ + size_t i; + + for (i = 0; i < items_n; i++) + if (meth == (int)items[i].id) + return items[i].ptr; + return NULL; +} + +/* + * The list of permitted hash functions are taken from + * https://tools.ietf.org/html/rfc8017#appendix-A.2.1: + * + * OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= { + * { OID id-sha1 PARAMETERS NULL }| + * { OID id-sha224 PARAMETERS NULL }| + * { OID id-sha256 PARAMETERS NULL }| + * { OID id-sha384 PARAMETERS NULL }| + * { OID id-sha512 PARAMETERS NULL }| + * { OID id-sha512-224 PARAMETERS NULL }| + * { OID id-sha512-256 PARAMETERS NULL }, + * ... -- Allows for future expansion -- + * } + */ +static const OSSL_ITEM oaeppss_name_nid_map[] = { + { NID_sha1, OSSL_DIGEST_NAME_SHA1 }, + { NID_sha224, OSSL_DIGEST_NAME_SHA2_224 }, + { NID_sha256, OSSL_DIGEST_NAME_SHA2_256 }, + { NID_sha384, OSSL_DIGEST_NAME_SHA2_384 }, + { NID_sha512, OSSL_DIGEST_NAME_SHA2_512 }, + { NID_sha512_224, OSSL_DIGEST_NAME_SHA2_512_224 }, + { NID_sha512_256, OSSL_DIGEST_NAME_SHA2_512_256 }, +}; + +static int md_is_a(const void *md, const char *name) +{ + return EVP_MD_is_a(md, name); +} + +int rsa_oaeppss_md2nid(const EVP_MD *md) +{ + return meth2nid(md, md_is_a, + oaeppss_name_nid_map, OSSL_NELEM(oaeppss_name_nid_map)); +} + +const char *rsa_oaeppss_nid2name(int md) +{ + return nid2name(md, oaeppss_name_nid_map, OSSL_NELEM(oaeppss_name_nid_map)); +} + +const char *rsa_mgf_nid2name(int mgf) +{ + if (mgf == NID_mgf1) + return SN_mgf1; + return NULL; +} diff --git a/crypto/rsa/rsa_sign.c b/crypto/rsa/rsa_sign.c index eeaa2d9a..f10c9bf5 100644 --- a/crypto/rsa/rsa_sign.c +++ b/crypto/rsa/rsa_sign.c @@ -87,7 +87,7 @@ static const unsigned char digestinfo_##name##_der[] = { \ ASN1_OCTET_STRING, sz \ }; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # ifndef OPENSSL_NO_MD2 ENCODE_DIGESTINFO_MD(md2, 0x02, MD2_DIGEST_LENGTH) # endif @@ -117,7 +117,7 @@ static const unsigned char digestinfo_ripemd160_der[] = { ASN1_OCTET_STRING, RIPEMD160_DIGEST_LENGTH }; # endif -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ /* SHA-1 (1 3 14 3 2 26) */ static const unsigned char digestinfo_sha1_der[] = { @@ -147,7 +147,7 @@ ENCODE_DIGESTINFO_SHA(sha3_512, 0x0a, SHA512_DIGEST_LENGTH) const unsigned char *rsa_digestinfo_encoding(int md_nid, size_t *len) { switch (md_nid) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # ifndef OPENSSL_NO_MDC2 MD_CASE(mdc2) # endif @@ -163,7 +163,7 @@ const unsigned char *rsa_digestinfo_encoding(int md_nid, size_t *len) # ifndef OPENSSL_NO_RMD160 MD_CASE(ripemd160) # endif -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ MD_CASE(sha1) MD_CASE(sha224) MD_CASE(sha256) @@ -187,7 +187,7 @@ const unsigned char *rsa_digestinfo_encoding(int md_nid, size_t *len) static int digest_sz_from_nid(int nid) { switch (nid) { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE # ifndef OPENSSL_NO_MDC2 MD_NID_CASE(mdc2, MDC2_DIGEST_LENGTH) # endif @@ -203,7 +203,7 @@ static int digest_sz_from_nid(int nid) # ifndef OPENSSL_NO_RMD160 MD_NID_CASE(ripemd160, RIPEMD160_DIGEST_LENGTH) # endif -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ MD_NID_CASE(sha1, SHA_DIGEST_LENGTH) MD_NID_CASE(sha224, SHA224_DIGEST_LENGTH) MD_NID_CASE(sha256, SHA256_DIGEST_LENGTH) @@ -272,10 +272,10 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len, unsigned char *tmps = NULL; const unsigned char *encoded = NULL; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (rsa->meth->rsa_sign != NULL) return rsa->meth->rsa_sign(type, m, m_len, sigret, siglen, rsa); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ /* Compute the encoded digest. */ if (type == NID_md5_sha1) { @@ -348,7 +348,7 @@ int int_rsa_verify(int type, const unsigned char *m, unsigned int m_len, goto err; decrypt_len = len; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (type == NID_md5_sha1) { /* * NID_md5_sha1 corresponds to the MD5/SHA1 combination in TLS 1.1 and @@ -395,7 +395,7 @@ int int_rsa_verify(int type, const unsigned char *m, unsigned int m_len, } } } else -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ { /* * If recovering the digest, extract a digest-sized output from the end diff --git a/crypto/rsa/rsa_sp800_56b_check.c b/crypto/rsa/rsa_sp800_56b_check.c index 2abd6db1..7cf6241d 100644 --- a/crypto/rsa/rsa_sp800_56b_check.c +++ b/crypto/rsa/rsa_sp800_56b_check.c @@ -2,7 +2,7 @@ * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2018-2019, Oracle and/or its affiliates. All rights reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -238,7 +238,7 @@ int rsa_get_lcm(BN_CTX *ctx, const BIGNUM *p, const BIGNUM *q, int rsa_sp800_56b_check_public(const RSA *rsa) { int ret = 0, status; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE int nbits; #endif BN_CTX *ctx = NULL; @@ -247,7 +247,7 @@ int rsa_sp800_56b_check_public(const RSA *rsa) if (rsa->n == NULL || rsa->e == NULL) return 0; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* * (Step a): modulus must be 2048 or 3072 (caveat from SP800-56Br1) * NOTE: changed to allow keys >= 2048 diff --git a/crypto/rsa/rsa_sp800_56b_gen.c b/crypto/rsa/rsa_sp800_56b_gen.c index 6c30a967..c4c7c08e 100644 --- a/crypto/rsa/rsa_sp800_56b_gen.c +++ b/crypto/rsa/rsa_sp800_56b_gen.c @@ -2,7 +2,7 @@ * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2018-2019, Oracle and/or its affiliates. All rights reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/self_test_core.c b/crypto/self_test_core.c index bee3161e..1a6f828c 100644 --- a/crypto/self_test_core.c +++ b/crypto/self_test_core.c @@ -55,7 +55,7 @@ static SELF_TEST_CB *get_self_test_callback(OPENSSL_CTX *libctx) &self_test_set_callback_method); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE void OSSL_SELF_TEST_set_callback(OPENSSL_CTX *libctx, OSSL_CALLBACK *cb, void *cbarg) { @@ -66,7 +66,7 @@ void OSSL_SELF_TEST_set_callback(OPENSSL_CTX *libctx, OSSL_CALLBACK *cb, stcb->cbarg = cbarg; } } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ void OSSL_SELF_TEST_get_callback(OPENSSL_CTX *libctx, OSSL_CALLBACK **cb, void **cbarg) diff --git a/crypto/serializer/serializer_pkey.c b/crypto/serializer/serializer_pkey.c index 3750ea3d..a3b854e5 100644 --- a/crypto/serializer/serializer_pkey.c +++ b/crypto/serializer/serializer_pkey.c @@ -255,7 +255,7 @@ static int serializer_write_cb(const OSSL_PARAM params[], void *arg) OSSL_SERIALIZER_CTX *ctx = write_data->ctx; BIO *out = write_data->out; - return ctx->ser->serialize_data(ctx->serctx, params, out, + return ctx->ser->serialize_data(ctx->serctx, params, (OSSL_CORE_BIO *)out, serializer_passphrase_out_cb, ctx); } @@ -291,7 +291,8 @@ static int serializer_EVP_PKEY_to_bio(OSSL_SERIALIZER_CTX *ctx, BIO *out) &serializer_write_cb, &write_data); } - return ctx->ser->serialize_object(ctx->serctx, keydata, out, + return ctx->ser->serialize_object(ctx->serctx, keydata, + (OSSL_CORE_BIO *)out, serializer_passphrase_out_cb, ctx); } diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c index 6c50d064..f0ed6da6 100644 --- a/crypto/srp/srp_vfy.c +++ b/crypto/srp/srp_vfy.c @@ -25,6 +25,10 @@ # define SRP_RANDOM_SALT_LEN 20 # define MAX_LEN 2500 +DEFINE_STACK_OF(SRP_user_pwd) +DEFINE_STACK_OF(SRP_gN_cache) +DEFINE_STACK_OF(SRP_gN) + /* * Note that SRP uses its own variant of base 64 encoding. A different base64 * alphabet is used and no padding '=' characters are added. Instead we pad to diff --git a/crypto/store/loader_file.c b/crypto/store/loader_file.c index 9b7f8fb8..320c527a 100644 --- a/crypto/store/loader_file.c +++ b/crypto/store/loader_file.c @@ -18,6 +18,7 @@ #include #include #include +#include "internal/pem_int.h" #include /* For the PKCS8 stuff o.O */ #include /* For d2i_RSAPrivateKey */ #include @@ -32,6 +33,8 @@ #include "crypto/evp.h" #include "store_local.h" +DEFINE_STACK_OF(X509) + #ifdef _WIN32 # define stat _stat #endif @@ -46,7 +49,8 @@ */ static char *file_get_pass(const UI_METHOD *ui_method, char *pass, - size_t maxsize, const char *prompt_info, void *data) + size_t maxsize, const char *desc, const char *info, + void *data) { UI *ui = UI_new(); char *prompt = NULL; @@ -60,8 +64,7 @@ static char *file_get_pass(const UI_METHOD *ui_method, char *pass, UI_set_method(ui, ui_method); UI_add_user_data(ui, data); - if ((prompt = UI_construct_prompt(ui, "pass phrase", - prompt_info)) == NULL) { + if ((prompt = UI_construct_prompt(ui, desc, info)) == NULL) { OSSL_STOREerr(OSSL_STORE_F_FILE_GET_PASS, ERR_R_MALLOC_FAILURE); pass = NULL; } else if (!UI_add_input_string(ui, prompt, UI_INPUT_FLAG_DEFAULT_PWD, @@ -92,18 +95,20 @@ static char *file_get_pass(const UI_METHOD *ui_method, char *pass, struct pem_pass_data { const UI_METHOD *ui_method; void *data; + const char *prompt_desc; const char *prompt_info; }; static int file_fill_pem_pass_data(struct pem_pass_data *pass_data, - const char *prompt_info, + const char *desc, const char *info, const UI_METHOD *ui_method, void *ui_data) { if (pass_data == NULL) return 0; pass_data->ui_method = ui_method; pass_data->data = ui_data; - pass_data->prompt_info = prompt_info; + pass_data->prompt_desc = desc; + pass_data->prompt_info = info; return 1; } @@ -112,7 +117,8 @@ static int file_get_pem_pass(char *buf, int num, int w, void *data) { struct pem_pass_data *pass_data = data; char *pass = file_get_pass(pass_data->ui_method, buf, num, - pass_data->prompt_info, pass_data->data); + pass_data->prompt_desc, pass_data->prompt_info, + pass_data->data); return pass == NULL ? 0 : strlen(pass); } @@ -166,7 +172,7 @@ typedef OSSL_STORE_INFO *(*file_try_decode_fn)(const char *pem_name, size_t len, void **handler_ctx, int *matchcount, const UI_METHOD *ui_method, - void *ui_data, + void *ui_data, const char *uri, OPENSSL_CTX *libctx, const char *propq); /* @@ -203,7 +209,8 @@ static OSSL_STORE_INFO *try_decode_PKCS12(const char *pem_name, size_t len, void **pctx, int *matchcount, const UI_METHOD *ui_method, - void *ui_data, OPENSSL_CTX *libctx, + void *ui_data, const char *uri, + OPENSSL_CTX *libctx, const char *propq) { OSSL_STORE_INFO *store_info = NULL; @@ -232,7 +239,7 @@ static OSSL_STORE_INFO *try_decode_PKCS12(const char *pem_name, pass = ""; } else { if ((pass = file_get_pass(ui_method, tpass, PEM_BUFSIZE, - "PKCS12 import password", + "PKCS12 import pass phrase", uri, ui_data)) == NULL) { OSSL_STOREerr(OSSL_STORE_F_TRY_DECODE_PKCS12, OSSL_STORE_R_PASSPHRASE_CALLBACK_ERROR); @@ -271,6 +278,7 @@ static OSSL_STORE_INFO *try_decode_PKCS12(const char *pem_name, (void)sk_X509_shift(chain); } } + sk_X509_free(chain); if (!ok) { OSSL_STORE_INFO_free(osi_ca); OSSL_STORE_INFO_free(osi_cert); @@ -333,6 +341,7 @@ static OSSL_STORE_INFO *try_decode_PKCS8Encrypted(const char *pem_name, int *matchcount, const UI_METHOD *ui_method, void *ui_data, + const char *uri, OPENSSL_CTX *libctx, const char *propq) { @@ -364,7 +373,8 @@ static OSSL_STORE_INFO *try_decode_PKCS8Encrypted(const char *pem_name, } if ((pass = file_get_pass(ui_method, kbuf, PEM_BUFSIZE, - "PKCS8 decrypt password", ui_data)) == NULL) { + "PKCS8 decrypt pass phrase", uri, + ui_data)) == NULL) { OSSL_STOREerr(OSSL_STORE_F_TRY_DECODE_PKCS8ENCRYPTED, OSSL_STORE_R_BAD_PASSWORD_READ); goto nop8; @@ -410,7 +420,8 @@ static OSSL_STORE_INFO *try_decode_PrivateKey(const char *pem_name, size_t len, void **pctx, int *matchcount, const UI_METHOD *ui_method, - void *ui_data, OPENSSL_CTX *libctx, + void *ui_data, const char *uri, + OPENSSL_CTX *libctx, const char *propq) { OSSL_STORE_INFO *store_info = NULL; @@ -489,7 +500,8 @@ static OSSL_STORE_INFO *try_decode_PUBKEY(const char *pem_name, size_t len, void **pctx, int *matchcount, const UI_METHOD *ui_method, - void *ui_data, OPENSSL_CTX *libctx, + void *ui_data, const char *uri, + OPENSSL_CTX *libctx, const char *propq) { OSSL_STORE_INFO *store_info = NULL; @@ -524,7 +536,8 @@ static OSSL_STORE_INFO *try_decode_params(const char *pem_name, size_t len, void **pctx, int *matchcount, const UI_METHOD *ui_method, - void *ui_data, OPENSSL_CTX *libctx, + void *ui_data, const char *uri, + OPENSSL_CTX *libctx, const char *propq) { OSSL_STORE_INFO *store_info = NULL; @@ -609,6 +622,7 @@ static OSSL_STORE_INFO *try_decode_X509Certificate(const char *pem_name, int *matchcount, const UI_METHOD *ui_method, void *ui_data, + const char *uri, OPENSSL_CTX *libctx, const char *propq) { @@ -660,7 +674,8 @@ static OSSL_STORE_INFO *try_decode_X509CRL(const char *pem_name, size_t len, void **pctx, int *matchcount, const UI_METHOD *ui_method, - void *ui_data, OPENSSL_CTX *libctx, + void *ui_data, const char *uri, + OPENSSL_CTX *libctx, const char *propq) { OSSL_STORE_INFO *store_info = NULL; @@ -709,6 +724,7 @@ static const FILE_HANDLER *file_handlers[] = { */ struct ossl_store_loader_ctx_st { + char *uri; /* The URI we currently try to load */ enum { is_raw = 0, is_pem, @@ -716,6 +732,7 @@ struct ossl_store_loader_ctx_st { } type; int errcnt; #define FILE_FLAG_SECMEM (1<<0) +#define FILE_FLAG_ATTACHED (1<<1) unsigned int flags; union { struct { /* Used with is_raw and is_pem */ @@ -731,7 +748,6 @@ struct ossl_store_loader_ctx_st { struct { /* Used with is_dir */ OPENSSL_DIR_CTX *ctx; int end_reached; - char *uri; /* * When a search expression is given, these are filled in. @@ -759,9 +775,11 @@ struct ossl_store_loader_ctx_st { static void OSSL_STORE_LOADER_CTX_free(OSSL_STORE_LOADER_CTX *ctx) { - if (ctx->type == is_dir) { - OPENSSL_free(ctx->_.dir.uri); - } else { + if (ctx == NULL) + return; + + OPENSSL_free(ctx->uri); + if (ctx->type != is_dir) { if (ctx->_.file.last_handler != NULL) { ctx->_.file.last_handler->destroy_ctx(&ctx->_.file.last_handler_ctx); ctx->_.file.last_handler_ctx = NULL; @@ -772,6 +790,23 @@ static void OSSL_STORE_LOADER_CTX_free(OSSL_STORE_LOADER_CTX *ctx) OPENSSL_free(ctx); } +static int file_find_type(OSSL_STORE_LOADER_CTX *ctx) +{ + BIO *buff = NULL; + char peekbuf[4096] = { 0, }; + + if ((buff = BIO_new(BIO_f_buffer())) == NULL) + return 0; + + ctx->_.file.file = BIO_push(buff, ctx->_.file.file); + if (BIO_buffer_peek(ctx->_.file.file, peekbuf, sizeof(peekbuf) - 1) > 0) { + peekbuf[sizeof(peekbuf) - 1] = '\0'; + if (strstr(peekbuf, "-----BEGIN ") != NULL) + ctx->type = is_pem; + } + return 1; +} + static OSSL_STORE_LOADER_CTX *file_open(const OSSL_STORE_LOADER *loader, const char *uri, const UI_METHOD *ui_method, @@ -863,19 +898,14 @@ static OSSL_STORE_LOADER_CTX *file_open(const OSSL_STORE_LOADER *loader, OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN, ERR_R_MALLOC_FAILURE); return NULL; } + ctx->uri = OPENSSL_strdup(uri); + if (ctx->uri == NULL) { + OSSL_STOREerr(OSSL_STORE_F_FILE_OPEN, ERR_R_MALLOC_FAILURE); + goto err; + } if (S_ISDIR(st.st_mode)) { - /* - * Try to copy everything, even if we know that some of them must be - * NULL for the moment. This prevents errors in the future, when more - * components may be used. - */ - ctx->_.dir.uri = OPENSSL_strdup(uri); ctx->type = is_dir; - - if (ctx->_.dir.uri == NULL) - goto err; - ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, path); ctx->_.dir.last_errno = errno; if (ctx->_.dir.last_entry == NULL) { @@ -889,22 +919,10 @@ static OSSL_STORE_LOADER_CTX *file_open(const OSSL_STORE_LOADER *loader, } ctx->_.dir.end_reached = 1; } - } else { - BIO *buff = NULL; - char peekbuf[4096] = { 0, }; - - if ((buff = BIO_new(BIO_f_buffer())) == NULL - || (ctx->_.file.file = BIO_new_file(path, "rb")) == NULL) { - BIO_free_all(buff); - goto err; - } - - ctx->_.file.file = BIO_push(buff, ctx->_.file.file); - if (BIO_buffer_peek(ctx->_.file.file, peekbuf, sizeof(peekbuf) - 1) > 0) { - peekbuf[sizeof(peekbuf) - 1] = '\0'; - if (strstr(peekbuf, "-----BEGIN ") != NULL) - ctx->type = is_pem; - } + } else if ((ctx->_.file.file = BIO_new_file(path, "rb")) == NULL + || !file_find_type(ctx)) { + BIO_free_all(ctx->_.file.file); + goto err; } return ctx; @@ -913,6 +931,34 @@ static OSSL_STORE_LOADER_CTX *file_open(const OSSL_STORE_LOADER *loader, return NULL; } +static OSSL_STORE_LOADER_CTX *file_attach(const OSSL_STORE_LOADER *loader, + BIO *bp, OPENSSL_CTX *libctx, + const char *propq, + const UI_METHOD *ui_method, + void *ui_data) +{ + OSSL_STORE_LOADER_CTX *ctx; + + if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL + || (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL)) { + OSSL_STOREerr(OSSL_STORE_F_FILE_ATTACH, ERR_R_MALLOC_FAILURE); + OSSL_STORE_LOADER_CTX_free(ctx); + return NULL; + } + + ctx->libctx = libctx; + ctx->flags |= FILE_FLAG_ATTACHED; + ctx->_.file.file = bp; + if (!file_find_type(ctx)) { + /* Safety measure */ + ctx->_.file.file = NULL; + OSSL_STORE_LOADER_CTX_free(ctx); + ctx = NULL; + } + + return ctx; +} + static int file_ctrl(OSSL_STORE_LOADER_CTX *ctx, int cmd, va_list args) { int ret = 1; @@ -982,36 +1028,6 @@ static int file_find(OSSL_STORE_LOADER_CTX *ctx, return 0; } -/* Internal function to decode an already opened PEM file */ -OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp, - OPENSSL_CTX *libctx, - const char *propq) -{ - OSSL_STORE_LOADER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); - - if (ctx == NULL) { - OSSL_STOREerr(OSSL_STORE_F_OSSL_STORE_FILE_ATTACH_PEM_BIO_INT, - ERR_R_MALLOC_FAILURE); - return NULL; - } - - ctx->_.file.file = bp; - ctx->type = is_pem; - - ctx->libctx = libctx; - if (propq != NULL) { - ctx->propq = OPENSSL_strdup(propq); - if (ctx->propq == NULL) { - OSSL_STOREerr(OSSL_STORE_F_OSSL_STORE_FILE_ATTACH_PEM_BIO_INT, - ERR_R_MALLOC_FAILURE); - OPENSSL_free(ctx); - return NULL; - } - } - - return ctx; -} - static OSSL_STORE_INFO *file_load_try_decode(OSSL_STORE_LOADER_CTX *ctx, const char *pem_name, const char *pem_header, @@ -1046,7 +1062,8 @@ static OSSL_STORE_INFO *file_load_try_decode(OSSL_STORE_LOADER_CTX *ctx, OSSL_STORE_INFO *tmp_result = handler->try_decode(pem_name, pem_header, data, len, &tmp_handler_ctx, &try_matchcount, - ui_method, ui_data, ctx->libctx, ctx->propq); + ui_method, ui_data, ctx->uri, + ctx->libctx, ctx->propq); if (try_matchcount > 0) { @@ -1113,7 +1130,7 @@ static OSSL_STORE_INFO *file_load_try_repeat(OSSL_STORE_LOADER_CTX *ctx, ctx->_.file.last_handler->try_decode(NULL, NULL, NULL, 0, &ctx->_.file.last_handler_ctx, &try_matchcount, - ui_method, ui_data, + ui_method, ui_data, ctx->uri, ctx->libctx, ctx->propq); if (result == NULL) { @@ -1134,8 +1151,8 @@ static void pem_free_flag(void *pem_data, int secure, size_t num) } static int file_read_pem(BIO *bp, char **pem_name, char **pem_header, unsigned char **data, long *len, - const UI_METHOD *ui_method, - void *ui_data, int secure) + const UI_METHOD *ui_method, void *ui_data, + const char *uri, int secure) { int i = secure ? PEM_read_bio_ex(bp, pem_name, pem_header, data, len, @@ -1156,7 +1173,8 @@ static int file_read_pem(BIO *bp, char **pem_name, char **pem_header, struct pem_pass_data pass_data; if (!PEM_get_EVP_CIPHER_INFO(*pem_header, &cipher) - || !file_fill_pem_pass_data(&pass_data, "PEM", ui_method, ui_data) + || !file_fill_pem_pass_data(&pass_data, "PEM pass phrase", uri, + ui_method, ui_data) || !PEM_do_header(&cipher, *data, len, file_get_pem_pass, &pass_data)) { return 0; @@ -1165,6 +1183,84 @@ static int file_read_pem(BIO *bp, char **pem_name, char **pem_header, return 1; } +static OSSL_STORE_INFO *file_try_read_msblob(BIO *bp, int *matchcount) +{ +#ifdef OPENSSL_NO_DSA + return NULL; +#else + OSSL_STORE_INFO *result = NULL; + int ispub = -1; + + { + unsigned int magic = 0, bitlen = 0; + int isdss = 0; + unsigned char peekbuf[16] = { 0, }; + const unsigned char *p = peekbuf; + + if (BIO_buffer_peek(bp, peekbuf, sizeof(peekbuf)) <= 0) + return 0; + if (!ossl_do_blob_header(&p, sizeof(peekbuf), &magic, &bitlen, + &isdss, &ispub)) + return 0; + } + + (*matchcount)++; + + { + EVP_PKEY *tmp = ispub + ? b2i_PublicKey_bio(bp) + : b2i_PrivateKey_bio(bp); + + if (tmp == NULL + || (result = OSSL_STORE_INFO_new_PKEY(tmp)) == NULL) { + EVP_PKEY_free(tmp); + return 0; + } + } + + return result; +#endif +} + +static OSSL_STORE_INFO *file_try_read_PVK(BIO *bp, const UI_METHOD *ui_method, + void *ui_data, const char *uri, + int *matchcount) +{ +#if defined(OPENSSL_NO_DSA) || defined(OPENSSL_NO_RC4) + return NULL; +#else + OSSL_STORE_INFO *result = NULL; + + { + unsigned int saltlen = 0, keylen = 0; + unsigned char peekbuf[24] = { 0, }; + const unsigned char *p = peekbuf; + + if (BIO_buffer_peek(bp, peekbuf, sizeof(peekbuf)) <= 0) + return 0; + if (!ossl_do_PVK_header(&p, sizeof(peekbuf), 0, &saltlen, &keylen)) + return 0; + } + + (*matchcount)++; + + { + EVP_PKEY *tmp = NULL; + struct pem_pass_data pass_data; + + if (!file_fill_pem_pass_data(&pass_data, "PVK pass phrase", uri, + ui_method, ui_data) + || (tmp = b2i_PVK_bio(bp, file_get_pem_pass, &pass_data)) == NULL + || (result = OSSL_STORE_INFO_new_PKEY(tmp)) == NULL) { + EVP_PKEY_free(tmp); + return 0; + } + } + + return result; +#endif +} + static int file_read_asn1(BIO *bp, unsigned char **data, long *len) { BUF_MEM *mem = NULL; @@ -1199,8 +1295,8 @@ static int file_name_to_uri(OSSL_STORE_LOADER_CTX *ctx, const char *name, assert(name != NULL); assert(data != NULL); { - const char *pathsep = ends_with_dirsep(ctx->_.dir.uri) ? "" : "/"; - long calculated_length = strlen(ctx->_.dir.uri) + strlen(pathsep) + const char *pathsep = ends_with_dirsep(ctx->uri) ? "" : "/"; + long calculated_length = strlen(ctx->uri) + strlen(pathsep) + strlen(name) + 1 /* \0 */; *data = OPENSSL_zalloc(calculated_length); @@ -1209,7 +1305,7 @@ static int file_name_to_uri(OSSL_STORE_LOADER_CTX *ctx, const char *name, return 0; } - OPENSSL_strlcat(*data, ctx->_.dir.uri, calculated_length); + OPENSSL_strlcat(*data, ctx->uri, calculated_length); OPENSSL_strlcat(*data, pathsep, calculated_length); OPENSSL_strlcat(*data, name, calculated_length); } @@ -1316,8 +1412,7 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx, * only cares that it isn't NULL. Therefore, we can safely give * it our URI here. */ - ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, - ctx->_.dir.uri); + ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, ctx->uri); ctx->_.dir.last_errno = errno; if (ctx->_.dir.last_entry == NULL && ctx->_.dir.last_errno == 0) ctx->_.dir.end_reached = 1; @@ -1349,12 +1444,19 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx, matchcount = -1; if (ctx->type == is_pem) { if (!file_read_pem(ctx->_.file.file, &pem_name, &pem_header, - &data, &len, ui_method, ui_data, + &data, &len, ui_method, ui_data, ctx->uri, (ctx->flags & FILE_FLAG_SECMEM) != 0)) { ctx->errcnt++; goto endloop; } } else { + if ((result = file_try_read_msblob(ctx->_.file.file, + &matchcount)) != NULL + || (result = file_try_read_PVK(ctx->_.file.file, + ui_method, ui_data, ctx->uri, + &matchcount)) != NULL) + goto endloop; + if (!file_read_asn1(ctx->_.file.file, &data, &len)) { ctx->errcnt++; goto endloop; @@ -1433,17 +1535,25 @@ static int file_eof(OSSL_STORE_LOADER_CTX *ctx) static int file_close(OSSL_STORE_LOADER_CTX *ctx) { - if (ctx->type == is_dir) { - OPENSSL_DIR_end(&ctx->_.dir.ctx); + if ((ctx->flags & FILE_FLAG_ATTACHED) == 0) { + if (ctx->type == is_dir) + OPENSSL_DIR_end(&ctx->_.dir.ctx); + else + BIO_free_all(ctx->_.file.file); } else { - BIO_free_all(ctx->_.file.file); - } - OSSL_STORE_LOADER_CTX_free(ctx); - return 1; -} + /* + * Because file_attach() called file_find_type(), we know that a + * BIO_f_buffer() has been pushed on top of the regular BIO. + */ + BIO *buff = ctx->_.file.file; -int ossl_store_file_detach_pem_bio_int(OSSL_STORE_LOADER_CTX *ctx) -{ + /* Detach buff */ + (void)BIO_pop(ctx->_.file.file); + /* Safety measure */ + ctx->_.file.file = NULL; + + BIO_free(buff); + } OSSL_STORE_LOADER_CTX_free(ctx); return 1; } @@ -1453,6 +1563,7 @@ static OSSL_STORE_LOADER file_loader = "file", NULL, file_open, + file_attach, file_ctrl, file_expect, file_find, diff --git a/crypto/store/store_err.c b/crypto/store/store_err.c index aa8ab4f9..3abb50bb 100644 --- a/crypto/store/store_err.c +++ b/crypto/store/store_err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy diff --git a/crypto/store/store_lib.c b/crypto/store/store_lib.c index 5bcd17b1..e1fc5918 100644 --- a/crypto/store/store_lib.c +++ b/crypto/store/store_lib.c @@ -231,6 +231,8 @@ int OSSL_STORE_close(OSSL_STORE_CTX *ctx) { int loader_ret; + if (ctx == NULL) + return 1; OSSL_TRACE1(STORE, "Closing %p\n", (void *)ctx->loader_ctx); loader_ret = ctx->loader->close(ctx->loader_ctx); @@ -651,47 +653,33 @@ char *ossl_store_info_get0_EMBEDDED_pem_name(OSSL_STORE_INFO *info) return NULL; } -OSSL_STORE_CTX *ossl_store_attach_pem_bio(BIO *bp, const UI_METHOD *ui_method, - void *ui_data, OPENSSL_CTX *libctx, - const char *propq) +OSSL_STORE_CTX *OSSL_STORE_attach(BIO *bp, OPENSSL_CTX *libctx, + const char *scheme, const char *propq, + const UI_METHOD *ui_method, void *ui_data, + OSSL_STORE_post_process_info_fn post_process, + void *post_process_data) { OSSL_STORE_CTX *ctx = NULL; const OSSL_STORE_LOADER *loader = NULL; OSSL_STORE_LOADER_CTX *loader_ctx = NULL; - if ((loader = ossl_store_get0_loader_int("file")) == NULL - || ((loader_ctx = ossl_store_file_attach_pem_bio_int(bp, libctx, - propq)) == NULL)) - goto done; + if ((loader = + ossl_store_get0_loader_int(scheme != NULL ? scheme : "file")) == NULL + || (loader_ctx = loader->attach(loader, bp, libctx, propq, + ui_method, ui_data)) == NULL) + return NULL; + if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL) { - OSSL_STOREerr(OSSL_STORE_F_OSSL_STORE_ATTACH_PEM_BIO, - ERR_R_MALLOC_FAILURE); - goto done; + OSSL_STOREerr(OSSL_STORE_F_OSSL_STORE_ATTACH, ERR_R_MALLOC_FAILURE); + return NULL; } ctx->loader = loader; ctx->loader_ctx = loader_ctx; - loader_ctx = NULL; ctx->ui_method = ui_method; ctx->ui_data = ui_data; - ctx->post_process = NULL; - ctx->post_process_data = NULL; + ctx->post_process = post_process; + ctx->post_process_data = post_process_data; - done: - if (loader_ctx != NULL) - /* - * We ignore a returned error because we will return NULL anyway in - * this case, so if something goes wrong when closing, that'll simply - * just add another entry on the error stack. - */ - (void)loader->close(loader_ctx); return ctx; } - -int ossl_store_detach_pem_bio(OSSL_STORE_CTX *ctx) -{ - int loader_ret = ossl_store_file_detach_pem_bio_int(ctx->loader_ctx); - - OPENSSL_free(ctx); - return loader_ret; -} diff --git a/crypto/store/store_local.h b/crypto/store/store_local.h index 7c864190..31e04d13 100644 --- a/crypto/store/store_local.h +++ b/crypto/store/store_local.h @@ -102,6 +102,7 @@ struct ossl_store_loader_st { const char *scheme; ENGINE *engine; OSSL_STORE_open_fn open; + OSSL_STORE_attach_fn attach; OSSL_STORE_ctrl_fn ctrl; OSSL_STORE_expect_fn expect; OSSL_STORE_find_fn find; @@ -122,13 +123,3 @@ void ossl_store_destroy_loaders_int(void); int ossl_store_init_once(void); int ossl_store_file_loader_init(void); - -/*- - * 'file' scheme stuff - * ------------------- - */ - -OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp, - OPENSSL_CTX *libctx, - const char *propq); -int ossl_store_file_detach_pem_bio_int(OSSL_STORE_LOADER_CTX *ctx); diff --git a/crypto/store/store_register.c b/crypto/store/store_register.c index 399ec8c6..12efb3e8 100644 --- a/crypto/store/store_register.c +++ b/crypto/store/store_register.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -71,6 +71,13 @@ int OSSL_STORE_LOADER_set_open(OSSL_STORE_LOADER *loader, return 1; } +int OSSL_STORE_LOADER_set_attach(OSSL_STORE_LOADER *loader, + OSSL_STORE_attach_fn attach_function) +{ + loader->attach = attach_function; + return 1; +} + int OSSL_STORE_LOADER_set_ctrl(OSSL_STORE_LOADER *loader, OSSL_STORE_ctrl_fn ctrl_function) { diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c index 762da60a..8b60251e 100644 --- a/crypto/threads_pthread.c +++ b/crypto/threads_pthread.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -190,7 +190,7 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock) return 1; } -# ifndef FIPS_MODE +# ifndef FIPS_MODULE /* TODO(3.0): No fork protection in FIPS module yet! */ # ifdef OPENSSL_SYS_UNIX @@ -211,7 +211,7 @@ int openssl_init_fork_handlers(void) # endif return 0; } -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ int openssl_get_fork_id(void) { diff --git a/crypto/ts/ts_conf.c b/crypto/ts/ts_conf.c index 4117ccdd..9044920e 100644 --- a/crypto/ts/ts_conf.c +++ b/crypto/ts/ts_conf.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,10 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_INFO) +DEFINE_STACK_OF(CONF_VALUE) + /* Macro definitions for the configuration file. */ #define BASE_SECTION "tsa" #define ENV_DEFAULT_TSA "default_tsa" diff --git a/crypto/ts/ts_req_utils.c b/crypto/ts/ts_req_utils.c index 8b950979..2d14ed11 100644 --- a/crypto/ts/ts_req_utils.c +++ b/crypto/ts/ts_req_utils.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include #include "ts_local.h" +DEFINE_STACK_OF(X509_EXTENSION) + int TS_REQ_set_version(TS_REQ *a, long version) { return ASN1_INTEGER_set(a->version, version); diff --git a/crypto/ts/ts_rsp_print.c b/crypto/ts/ts_rsp_print.c index 8593e2d9..b5374e0f 100644 --- a/crypto/ts/ts_rsp_print.c +++ b/crypto/ts/ts_rsp_print.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,9 @@ #include #include "ts_local.h" +DEFINE_STACK_OF(ASN1_UTF8STRING) +DEFINE_STACK_OF(CONF_VALUE) + struct status_map_st { int bit; const char *text; diff --git a/crypto/ts/ts_rsp_sign.c b/crypto/ts/ts_rsp_sign.c index ed0979e5..33f2b511 100644 --- a/crypto/ts/ts_rsp_sign.c +++ b/crypto/ts/ts_rsp_sign.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,12 @@ #include "ts_local.h" #include "crypto/ess.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(ASN1_UTF8STRING) +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF_CONST(EVP_MD) + static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *, void *); static int def_time_cb(struct TS_resp_ctx *, void *, long *sec, long *usec); static int def_extension_cb(struct TS_resp_ctx *, X509_EXTENSION *, void *); @@ -51,6 +57,7 @@ static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *ctx, void *data) TSerr(TS_F_DEF_SERIAL_CB, ERR_R_MALLOC_FAILURE); TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION, "Error during serial number generation."); + ASN1_INTEGER_free(serial); return NULL; } diff --git a/crypto/ts/ts_rsp_utils.c b/crypto/ts/ts_rsp_utils.c index 6017e8d1..86e1a9d4 100644 --- a/crypto/ts/ts_rsp_utils.c +++ b/crypto/ts/ts_rsp_utils.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include #include "ts_local.h" +DEFINE_STACK_OF(X509_EXTENSION) + int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info) { TS_STATUS_INFO *new_status_info; diff --git a/crypto/ts/ts_rsp_verify.c b/crypto/ts/ts_rsp_verify.c index 1f20fb9c..b872f75b 100644 --- a/crypto/ts/ts_rsp_verify.c +++ b/crypto/ts/ts_rsp_verify.c @@ -15,6 +15,13 @@ #include "ts_local.h" #include "crypto/ess.h" +DEFINE_STACK_OF(PKCS7_SIGNER_INFO) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(ESS_CERT_ID) +DEFINE_STACK_OF(ESS_CERT_ID_V2) +DEFINE_STACK_OF(ASN1_UTF8STRING) +DEFINE_STACK_OF(GENERAL_NAME) + static int ts_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer, STACK_OF(X509) **chain); static int ts_check_signing_certs(PKCS7_SIGNER_INFO *si, diff --git a/crypto/ts/ts_verify_ctx.c b/crypto/ts/ts_verify_ctx.c index 3c834013..2c95fd1f 100644 --- a/crypto/ts/ts_verify_ctx.c +++ b/crypto/ts/ts_verify_ctx.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -12,6 +12,8 @@ #include #include "ts_local.h" +DEFINE_STACK_OF(X509) + TS_VERIFY_CTX *TS_VERIFY_CTX_new(void) { TS_VERIFY_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c index 97a75eab..85bf8c1f 100644 --- a/crypto/ui/ui_lib.c +++ b/crypto/ui/ui_lib.c @@ -15,6 +15,8 @@ #include #include "ui_local.h" +DEFINE_STACK_OF(UI_STRING) + UI *UI_new(void) { return UI_new_method(NULL); diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c index 4479d6ad..43b175e2 100644 --- a/crypto/x509/by_dir.c +++ b/crypto/x509/by_dir.c @@ -22,6 +22,8 @@ #include "crypto/x509.h" #include "x509_local.h" +DEFINE_STACK_OF(X509_OBJECT) + struct lookup_dir_hashes_st { unsigned long hash; int suffix; diff --git a/crypto/x509/by_file.c b/crypto/x509/by_file.c index 93a1af87..f9e1e73f 100644 --- a/crypto/x509/by_file.c +++ b/crypto/x509/by_file.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,8 @@ #include #include "x509_local.h" +DEFINE_STACK_OF(X509_INFO) + static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, char **ret); static X509_LOOKUP_METHOD x509_file_lookup = { diff --git a/crypto/x509/by_store.c b/crypto/x509/by_store.c index 8a8c50b6..7141c1bd 100644 --- a/crypto/x509/by_store.c +++ b/crypto/x509/by_store.c @@ -12,6 +12,8 @@ #include "crypto/x509.h" #include "x509_local.h" +DEFINE_STACK_OF_STRING() + /* Generic object loader, given expected type and criterion */ static int cache_objects(X509_LOOKUP *lctx, const char *uri, const OSSL_STORE_SEARCH *criterion, diff --git a/crypto/x509/pcy_cache.c b/crypto/x509/pcy_cache.c index e65931e4..61423bf2 100644 --- a/crypto/x509/pcy_cache.c +++ b/crypto/x509/pcy_cache.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include "pcy_local.h" +DEFINE_STACK_OF(POLICYINFO) + static int policy_data_cmp(const X509_POLICY_DATA *const *a, const X509_POLICY_DATA *const *b); static int policy_cache_set_int(long *out, ASN1_INTEGER *value); diff --git a/crypto/x509/pcy_data.c b/crypto/x509/pcy_data.c index cc3fc201..966b0b2e 100644 --- a/crypto/x509/pcy_data.c +++ b/crypto/x509/pcy_data.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,6 +13,9 @@ #include "pcy_local.h" +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF(POLICYQUALINFO) + /* Policy Node routines */ void policy_data_free(X509_POLICY_DATA *data) diff --git a/crypto/x509/pcy_lib.c b/crypto/x509/pcy_lib.c index c4740a0a..23baa2db 100644 --- a/crypto/x509/pcy_lib.c +++ b/crypto/x509/pcy_lib.c @@ -13,6 +13,8 @@ #include "pcy_local.h" +DEFINE_STACK_OF(X509_POLICY_NODE) + /* accessor functions */ /* X509_POLICY_TREE stuff */ diff --git a/crypto/x509/pcy_map.c b/crypto/x509/pcy_map.c index 258792be..0dec6245 100644 --- a/crypto/x509/pcy_map.c +++ b/crypto/x509/pcy_map.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,9 @@ #include "pcy_local.h" +DEFINE_STACK_OF(POLICY_MAPPING) +DEFINE_STACK_OF(ASN1_OBJECT) + /* * Set policy mapping entries in cache. Note: this modifies the passed * POLICY_MAPPINGS structure diff --git a/crypto/x509/pcy_node.c b/crypto/x509/pcy_node.c index fc06a31c..baa4fa8d 100644 --- a/crypto/x509/pcy_node.c +++ b/crypto/x509/pcy_node.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,9 @@ #include "pcy_local.h" +DEFINE_STACK_OF(X509_POLICY_NODE) +DEFINE_STACK_OF(ASN1_OBJECT) + static int node_cmp(const X509_POLICY_NODE *const *a, const X509_POLICY_NODE *const *b) { diff --git a/crypto/x509/pcy_tree.c b/crypto/x509/pcy_tree.c index fa11e5e4..30879197 100644 --- a/crypto/x509/pcy_tree.c +++ b/crypto/x509/pcy_tree.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,10 @@ #include "pcy_local.h" +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_POLICY_NODE) + static void expected_print(BIO *channel, X509_POLICY_LEVEL *lev, X509_POLICY_NODE *node, int indent) diff --git a/crypto/x509/t_crl.c b/crypto/x509/t_crl.c index 33b871eb..0824bb6d 100644 --- a/crypto/x509/t_crl.c +++ b/crypto/x509/t_crl.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,8 @@ #include #include +DEFINE_STACK_OF(X509_REVOKED) + #ifndef OPENSSL_NO_STDIO int X509_CRL_print_fp(FILE *fp, X509_CRL *x) { diff --git a/crypto/x509/t_req.c b/crypto/x509/t_req.c index 8af6510b..e1ee12de 100644 --- a/crypto/x509/t_req.c +++ b/crypto/x509/t_req.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,8 @@ #include #include +DEFINE_STACK_OF(X509_EXTENSION) + #ifndef OPENSSL_NO_STDIO int X509_REQ_print_fp(FILE *fp, X509_REQ *x) { diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index 5e953954..75d688c5 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -17,6 +17,9 @@ #include "crypto/asn1.h" #include "crypto/x509.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(ASN1_OBJECT) + #ifndef OPENSSL_NO_STDIO int X509_print_fp(FILE *fp, X509 *x) { @@ -449,17 +452,46 @@ int X509_STORE_CTX_print_verify_cb(int ok, X509_STORE_CTX *ctx) { if (ok == 0 && ctx != NULL) { int cert_error = X509_STORE_CTX_get_error(ctx); - int depth = X509_STORE_CTX_get_error_depth(ctx); - X509 *cert = X509_STORE_CTX_get_current_cert(ctx); BIO *bio = BIO_new(BIO_s_mem()); /* may be NULL */ - BIO_printf(bio, "%s at depth=%d error=%d (%s)\n", + BIO_printf(bio, "%s at depth = %d error = %d (%s)\n", X509_STORE_CTX_get0_parent_ctx(ctx) != NULL - ? "CRL path validation" : "certificate verification", - depth, cert_error, - X509_verify_cert_error_string(cert_error)); - BIO_printf(bio, "failure for:\n"); - x509_print_ex_brief(bio, cert, X509_FLAG_NO_EXTENSIONS); + ? "CRL path validation" + : "Certificate verification", + X509_STORE_CTX_get_error_depth(ctx), + cert_error, X509_verify_cert_error_string(cert_error)); + { + X509_STORE *ts = X509_STORE_CTX_get0_store(ctx); + X509_VERIFY_PARAM *vpm = X509_STORE_get0_param(ts); + char *str; + int idx = 0; + + switch (cert_error) { + case X509_V_ERR_HOSTNAME_MISMATCH: + BIO_printf(bio, "Expected hostname(s) = "); + while ((str = X509_VERIFY_PARAM_get0_host(vpm, idx++)) != NULL) + BIO_printf(bio, "%s%s", idx == 1 ? "" : ", ", str); + BIO_printf(bio, "\n"); + break; + case X509_V_ERR_EMAIL_MISMATCH: + str = X509_VERIFY_PARAM_get0_email(vpm); + if (str != NULL) + BIO_printf(bio, "Expected email address = %s\n", str); + break; + case X509_V_ERR_IP_ADDRESS_MISMATCH: + str = X509_VERIFY_PARAM_get1_ip_asc(vpm); + if (str != NULL) + BIO_printf(bio, "Expected IP address = %s\n", str); + OPENSSL_free(str); + break; + default: + break; + } + } + + BIO_printf(bio, "Failure for:\n"); + x509_print_ex_brief(bio, X509_STORE_CTX_get_current_cert(ctx), + X509_FLAG_NO_EXTENSIONS); if (cert_error == X509_V_ERR_CERT_UNTRUSTED || cert_error == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT || cert_error == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN @@ -467,9 +499,9 @@ int X509_STORE_CTX_print_verify_cb(int ok, X509_STORE_CTX *ctx) || cert_error == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY || cert_error == X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER || cert_error == X509_V_ERR_STORE_LOOKUP) { - BIO_printf(bio, "non-trusted certs:\n"); + BIO_printf(bio, "Non-trusted certs:\n"); print_certs(bio, X509_STORE_CTX_get0_untrusted(ctx)); - BIO_printf(bio, "certs in trust store:\n"); + BIO_printf(bio, "Certs in trust store:\n"); print_store_certs(bio, X509_STORE_CTX_get0_store(ctx)); } X509err(0, X509_R_CERTIFICATE_VERIFICATION_FAILED); diff --git a/crypto/x509/v3_addr.c b/crypto/x509/v3_addr.c index 766c5bc1..9e2b9d48 100644 --- a/crypto/x509/v3_addr.c +++ b/crypto/x509/v3_addr.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -25,6 +25,11 @@ #ifndef OPENSSL_NO_RFC3779 +DEFINE_STACK_OF(IPAddressOrRange) +DEFINE_STACK_OF(IPAddressFamily) +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(X509) + /* * OpenSSL ASN.1 template translation of RFC 3779 2.2.3. */ @@ -139,6 +144,7 @@ static int i2r_address(BIO *out, return 0; BIO_printf(out, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); break; + /* TODO possibly combine with ipaddr_to_asc() */ case IANA_AFI_IPV6: if (!addr_expand(addr, bs, 16, fill)) return 0; diff --git a/crypto/x509/v3_admis.c b/crypto/x509/v3_admis.c index 104b58f2..2fbb11bd 100644 --- a/crypto/x509/v3_admis.c +++ b/crypto/x509/v3_admis.c @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,6 +20,10 @@ #include "v3_admis.h" #include "ext_dat.h" +DEFINE_STACK_OF(ADMISSIONS) +DEFINE_STACK_OF(PROFESSION_INFO) +DEFINE_STACK_OF(ASN1_STRING) +DEFINE_STACK_OF(ASN1_OBJECT) ASN1_SEQUENCE(NAMING_AUTHORITY) = { ASN1_OPT(NAMING_AUTHORITY, namingAuthorityId, ASN1_OBJECT), diff --git a/crypto/x509/v3_akey.c b/crypto/x509/v3_akey.c index 4898869b..a40963d9 100644 --- a/crypto/x509/v3_akey.c +++ b/crypto/x509/v3_akey.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,9 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(GENERAL_NAME) + static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) diff --git a/crypto/x509/v3_alt.c b/crypto/x509/v3_alt.c index a910d5d7..5fece4f9 100644 --- a/crypto/x509/v3_alt.c +++ b/crypto/x509/v3_alt.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -11,8 +11,12 @@ #include "internal/cryptlib.h" #include #include +#include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(GENERAL_NAME) + static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); @@ -78,9 +82,8 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret) { - unsigned char *p; - char oline[256], htmp[5]; - int i; + char othername[300]; + char oline[256], *tmp; switch (gen->type) { case GEN_OTHERNAME: @@ -121,7 +124,26 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, return NULL; break; default: - if (!X509V3_add_value("othername", "", &ret)) + if (OBJ_obj2txt(oline, sizeof(oline), gen->d.otherName->type_id, 0) > 0) + BIO_snprintf(othername, sizeof(othername), "othername: %s:", + oline); + else + strncpy(othername, "othername:", sizeof(othername)); + + /* check if the value is something printable */ + if (gen->d.otherName->value->type == V_ASN1_IA5STRING) { + if (X509V3_add_value_uchar(othername, + gen->d.otherName->value->value.ia5string->data, + &ret)) + return ret; + } + if (gen->d.otherName->value->type == V_ASN1_UTF8STRING) { + if (X509V3_add_value_uchar(othername, + gen->d.otherName->value->value.utf8string->data, + &ret)) + return ret; + } + if (!X509V3_add_value(othername, "", &ret)) return NULL; break; } @@ -159,26 +181,10 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, break; case GEN_IPADD: - p = gen->d.ip->data; - if (gen->d.ip->length == 4) - BIO_snprintf(oline, sizeof(oline), "%d.%d.%d.%d", - p[0], p[1], p[2], p[3]); - else if (gen->d.ip->length == 16) { - oline[0] = 0; - for (i = 0; i < 8; i++) { - BIO_snprintf(htmp, sizeof(htmp), "%X", p[0] << 8 | p[1]); - p += 2; - strcat(oline, htmp); - if (i != 7) - strcat(oline, ":"); - } - } else { - if (!X509V3_add_value("IP Address", "", &ret)) - return NULL; - break; - } - if (!X509V3_add_value("IP Address", oline, &ret)) - return NULL; + tmp = ipaddr_to_asc(gen->d.ip->data, gen->d.ip->length); + if (tmp == NULL || !X509V3_add_value("IP Address", tmp, &ret)) + ret = NULL; + OPENSSL_free(tmp); break; case GEN_RID: @@ -192,8 +198,8 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen) { - unsigned char *p; - int i, nid; + char *tmp; + int nid; switch (gen->type) { case GEN_OTHERNAME: @@ -264,19 +270,11 @@ int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen) break; case GEN_IPADD: - p = gen->d.ip->data; - if (gen->d.ip->length == 4) - BIO_printf(out, "IP Address:%d.%d.%d.%d", p[0], p[1], p[2], p[3]); - else if (gen->d.ip->length == 16) { - BIO_printf(out, "IP Address"); - for (i = 0; i < 8; i++) { - BIO_printf(out, ":%X", p[0] << 8 | p[1]); - p += 2; - } - } else { - BIO_printf(out, "IP Address:"); - break; - } + tmp = ipaddr_to_asc(gen->d.ip->data, gen->d.ip->length); + if (tmp == NULL) + return 0; + BIO_printf(out, "IP Address:%s", tmp); + OPENSSL_free(tmp); break; case GEN_RID: diff --git a/crypto/x509/v3_asid.c b/crypto/x509/v3_asid.c index 6cb5cd55..0ff37073 100644 --- a/crypto/x509/v3_asid.c +++ b/crypto/x509/v3_asid.c @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -55,6 +55,10 @@ IMPLEMENT_ASN1_FUNCTIONS(ASIdOrRange) IMPLEMENT_ASN1_FUNCTIONS(ASIdentifierChoice) IMPLEMENT_ASN1_FUNCTIONS(ASIdentifiers) +DEFINE_STACK_OF(ASIdOrRange) +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(X509) + /* * i2r method for an ASIdentifierChoice. */ diff --git a/crypto/x509/v3_bcons.c b/crypto/x509/v3_bcons.c index 02e30022..6ab4aaf6 100644 --- a/crypto/x509/v3_bcons.c +++ b/crypto/x509/v3_bcons.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,8 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) + static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) diff --git a/crypto/x509/v3_bitst.c b/crypto/x509/v3_bitst.c index 81cdcfb6..ec8fdc55 100644 --- a/crypto/x509/v3_bitst.c +++ b/crypto/x509/v3_bitst.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,6 +13,8 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) + static BIT_STRING_BITNAME ns_cert_type_table[] = { {0, "SSL Client", "client"}, {1, "SSL Server", "server"}, diff --git a/crypto/x509/v3_conf.c b/crypto/x509/v3_conf.c index 47b1cfc9..bbe67dc3 100644 --- a/crypto/x509/v3_conf.c +++ b/crypto/x509/v3_conf.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,9 @@ #include "crypto/x509.h" #include +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(X509_EXTENSION) + static int v3_check_critical(const char **value); static int v3_check_generic(const char **value); static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, diff --git a/crypto/x509/v3_cpols.c b/crypto/x509/v3_cpols.c index 470088c9..abbf5fbe 100644 --- a/crypto/x509/v3_cpols.c +++ b/crypto/x509/v3_cpols.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,11 @@ #include "pcy_local.h" #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(POLICYINFO) +DEFINE_STACK_OF(POLICYQUALINFO) +DEFINE_STACK_OF(ASN1_INTEGER) + /* Certificate policies extension support: this one is a bit complex... */ static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, diff --git a/crypto/x509/v3_crld.c b/crypto/x509/v3_crld.c index b23a9619..21a1bfcd 100644 --- a/crypto/x509/v3_crld.c +++ b/crypto/x509/v3_crld.c @@ -17,6 +17,11 @@ #include "crypto/x509.h" #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(DIST_POINT) +DEFINE_STACK_OF(X509_NAME_ENTRY) + static void *v2i_crld(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, diff --git a/crypto/x509/v3_extku.c b/crypto/x509/v3_extku.c index 8d0dfcf3..ed51b60f 100644 --- a/crypto/x509/v3_extku.c +++ b/crypto/x509/v3_extku.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,9 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF(CONF_VALUE) + static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); diff --git a/crypto/x509/v3_info.c b/crypto/x509/v3_info.c index c50cfd1f..489daa71 100644 --- a/crypto/x509/v3_info.c +++ b/crypto/x509/v3_info.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,9 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(ACCESS_DESCRIPTION) +DEFINE_STACK_OF(CONF_VALUE) + static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method, AUTHORITY_INFO_ACCESS *ainfo, STACK_OF(CONF_VALUE) diff --git a/crypto/x509/v3_ist.c b/crypto/x509/v3_ist.c index 6db4f199..ceb127f6 100644 --- a/crypto/x509/v3_ist.c +++ b/crypto/x509/v3_ist.c @@ -15,6 +15,8 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) + /* * Issuer Sign Tool (1.2.643.100.112) The name of the tool used to signs the subject (ASN1_SEQUENCE) * This extention is required to obtain the status of a qualified certificate at Russian Federation. diff --git a/crypto/x509/v3_lib.c b/crypto/x509/v3_lib.c index 71ba7a32..b1e32bb4 100644 --- a/crypto/x509/v3_lib.c +++ b/crypto/x509/v3_lib.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -16,6 +16,9 @@ #include "ext_dat.h" +DEFINE_STACK_OF(X509V3_EXT_METHOD) +DEFINE_STACK_OF(X509_EXTENSION) + static STACK_OF(X509V3_EXT_METHOD) *ext_list = NULL; static int ext_cmp(const X509V3_EXT_METHOD *const *a, diff --git a/crypto/x509/v3_ncons.c b/crypto/x509/v3_ncons.c index d6a286c0..d7b82b77 100644 --- a/crypto/x509/v3_ncons.c +++ b/crypto/x509/v3_ncons.c @@ -19,6 +19,10 @@ #include "crypto/x509.h" #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(GENERAL_SUBTREE) + static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); @@ -188,26 +192,17 @@ static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method, static int print_nc_ipadd(BIO *bp, ASN1_OCTET_STRING *ip) { - int i, len; - unsigned char *p; - p = ip->data; - len = ip->length; - BIO_puts(bp, "IP:"); - if (len == 8) { - BIO_printf(bp, "%d.%d.%d.%d/%d.%d.%d.%d", - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - } else if (len == 32) { - for (i = 0; i < 16; i++) { - BIO_printf(bp, "%X", p[0] << 8 | p[1]); - p += 2; - if (i == 7) - BIO_puts(bp, "/"); - else if (i != 15) - BIO_puts(bp, ":"); - } - } else - BIO_printf(bp, "IP Address:"); - return 1; + /* ip->length should be 8 or 32 and len1 == len2 == 4 or len1 == len2 == 16 */ + int len1 = ip->length >= 16 ? 16 : ip->length >= 4 ? 4 : ip->length; + int len2 = ip->length - len1; + char *ip1 = ipaddr_to_asc(ip->data, len1); + char *ip2 = ipaddr_to_asc(ip->data + len1, len2); + int ret = ret = ip1 != NULL && ip2 != NULL + && BIO_printf(bp, "IP:%s/%s", ip1, ip2) > 0; + + OPENSSL_free(ip1); + OPENSSL_free(ip2); + return ret; } #define NAME_CHECK_MAX (1 << 20) diff --git a/crypto/x509/v3_pci.c b/crypto/x509/v3_pci.c index fb5f35a5..30711149 100644 --- a/crypto/x509/v3_pci.c +++ b/crypto/x509/v3_pci.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -49,6 +49,8 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) + static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *ext, BIO *out, int indent); static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method, diff --git a/crypto/x509/v3_pcons.c b/crypto/x509/v3_pcons.c index 33c08cfd..e7bb7e95 100644 --- a/crypto/x509/v3_pcons.c +++ b/crypto/x509/v3_pcons.c @@ -1,5 +1,5 @@ /* - * Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2003-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,8 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) + static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *bcons, STACK_OF(CONF_VALUE) *extlist); diff --git a/crypto/x509/v3_pmaps.c b/crypto/x509/v3_pmaps.c index 2b478402..d54384da 100644 --- a/crypto/x509/v3_pmaps.c +++ b/crypto/x509/v3_pmaps.c @@ -1,5 +1,5 @@ /* - * Copyright 2003-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2003-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,9 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(POLICY_MAPPING) +DEFINE_STACK_OF(CONF_VALUE) + static void *v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); static STACK_OF(CONF_VALUE) *i2v_POLICY_MAPPINGS(const X509V3_EXT_METHOD diff --git a/crypto/x509/v3_prn.c b/crypto/x509/v3_prn.c index 2ef76c1b..aa902204 100644 --- a/crypto/x509/v3_prn.c +++ b/crypto/x509/v3_prn.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,9 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(X509_EXTENSION) + /* Extension printing routines */ static int unknown_ext_print(BIO *out, const unsigned char *ext, int extlen, diff --git a/crypto/x509/v3_purp.c b/crypto/x509/v3_purp.c index 687d0653..b3401035 100644 --- a/crypto/x509/v3_purp.c +++ b/crypto/x509/v3_purp.c @@ -15,6 +15,11 @@ #include "crypto/x509.h" #include "internal/tsan_assist.h" +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(DIST_POINT) +DEFINE_STACK_OF(X509_PURPOSE) +DEFINE_STACK_OF(ASN1_OBJECT) + static int check_ssl_ca(const X509 *x); static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, int ca); diff --git a/crypto/x509/v3_sxnet.c b/crypto/x509/v3_sxnet.c index 072b8efe..d9007375 100644 --- a/crypto/x509/v3_sxnet.c +++ b/crypto/x509/v3_sxnet.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,9 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(SXNETID) +DEFINE_STACK_OF(CONF_VALUE) + /* Support for Thawte strong extranet extension */ #define SXNET_TEST diff --git a/crypto/x509/v3_tlsf.c b/crypto/x509/v3_tlsf.c index 28e83bb2..e494e4e8 100644 --- a/crypto/x509/v3_tlsf.c +++ b/crypto/x509/v3_tlsf.c @@ -1,5 +1,5 @@ /* - * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,6 +15,9 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(ASN1_INTEGER) +DEFINE_STACK_OF(CONF_VALUE) + static STACK_OF(CONF_VALUE) *i2v_TLS_FEATURE(const X509V3_EXT_METHOD *method, TLS_FEATURE *tls_feature, STACK_OF(CONF_VALUE) *ext_list); @@ -88,7 +91,7 @@ static TLS_FEATURE *v2i_TLS_FEATURE(const X509V3_EXT_METHOD *method, { TLS_FEATURE *tlsf; char *extval, *endptr; - ASN1_INTEGER *ai; + ASN1_INTEGER *ai = NULL; CONF_VALUE *val; int i; size_t j; @@ -127,10 +130,13 @@ static TLS_FEATURE *v2i_TLS_FEATURE(const X509V3_EXT_METHOD *method, X509V3err(X509V3_F_V2I_TLS_FEATURE, ERR_R_MALLOC_FAILURE); goto err; } + /* So it doesn't get purged if an error occurs next time around */ + ai = NULL; } return tlsf; err: sk_ASN1_INTEGER_pop_free(tlsf, ASN1_INTEGER_free); + ASN1_INTEGER_free(ai); return NULL; } diff --git a/crypto/x509/v3_utl.c b/crypto/x509/v3_utl.c index c7f54aa0..aefb5897 100644 --- a/crypto/x509/v3_utl.c +++ b/crypto/x509/v3_utl.c @@ -20,12 +20,19 @@ #include #include "ext_dat.h" +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(ACCESS_DESCRIPTION) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF_STRING() + static char *strip_spaces(char *name); static int sk_strcmp(const char *const *a, const char *const *b); static STACK_OF(OPENSSL_STRING) *get_email(const X509_NAME *name, GENERAL_NAMES *gens); static void str_free(OPENSSL_STRING str); -static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, const ASN1_IA5STRING *email); +static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, + const ASN1_IA5STRING *email); static int ipv4_from_asc(unsigned char *v4, const char *in); static int ipv6_from_asc(unsigned char *v6, const char *in); @@ -172,6 +179,7 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, const char *value) ASN1_INTEGER *aint; int isneg, ishex; int ret; + if (value == NULL) { X509V3err(X509V3_F_S2I_ASN1_INTEGER, X509V3_R_INVALID_NULL_VALUE); return NULL; @@ -184,14 +192,16 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, const char *value) if (value[0] == '-') { value++; isneg = 1; - } else + } else { isneg = 0; + } if (value[0] == '0' && ((value[1] == 'x') || (value[1] == 'X'))) { value += 2; ishex = 1; - } else + } else { ishex = 0; + } if (ishex) ret = BN_hex2bn(&bn, value); @@ -291,6 +301,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line) STACK_OF(CONF_VALUE) *values = NULL; char *linebuf; int state; + /* We are going to modify the line so copy it first */ linebuf = OPENSSL_strdup(line); if (linebuf == NULL) { @@ -376,6 +387,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line) static char *strip_spaces(char *name) { char *p, *q; + /* Skip over leading spaces */ p = name; while (*p && ossl_isspace(*p)) @@ -401,6 +413,7 @@ int v3_name_cmp(const char *name, const char *cmp) { int len, ret; char c; + len = strlen(cmp); if ((ret = strncmp(name, cmp, len))) return ret; @@ -496,9 +509,11 @@ static void str_free(OPENSSL_STRING str) OPENSSL_free(str); } -static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, const ASN1_IA5STRING *email) +static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, + const ASN1_IA5STRING *email) { char *emtmp; + /* First some sanity checks */ if (email->type != V_ASN1_IA5STRING) return 1; @@ -513,7 +528,7 @@ static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, const ASN1_IA5STRING *email return 1; emtmp = OPENSSL_strdup((char *)email->data); if (emtmp == NULL || !sk_OPENSSL_STRING_push(*sk, emtmp)) { - OPENSSL_free(emtmp); /* free on push failure */ + OPENSSL_free(emtmp); /* free on push failure */ X509_email_free(*sk); *sk = NULL; return 0; @@ -570,9 +585,10 @@ static int equal_nocase(const unsigned char *pattern, size_t pattern_len, skip_prefix(&pattern, &pattern_len, subject_len, flags); if (pattern_len != subject_len) return 0; - while (pattern_len) { + while (pattern_len != 0) { unsigned char l = *pattern; unsigned char r = *subject; + /* The pattern must not contain NUL characters. */ if (l == 0) return 0; @@ -611,6 +627,7 @@ static int equal_email(const unsigned char *a, size_t a_len, unsigned int unused_flags) { size_t i = a_len; + if (a_len != b_len) return 0; /* @@ -698,6 +715,7 @@ static const unsigned char *valid_star(const unsigned char *p, size_t len, size_t i; int state = LABEL_START; int dots = 0; + for (i = 0; i < len; ++i) { /* * Locate first and only legal wildcard, either at the start @@ -739,8 +757,9 @@ static const unsigned char *valid_star(const unsigned char *p, size_t len, if ((state & LABEL_START) != 0) return NULL; state |= LABEL_HYPHEN; - } else + } else { return NULL; + } } /* @@ -856,6 +875,7 @@ static int do_x509_check(X509 *x, const char *chk, size_t chklen, for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { GENERAL_NAME *gen; ASN1_STRING *cstr; + gen = sk_GENERAL_NAME_value(gens, i); if (gen->type != check_type) continue; @@ -955,6 +975,29 @@ int X509_check_ip_asc(X509 *x, const char *ipasc, unsigned int flags) return do_x509_check(x, (char *)ipout, iplen, flags, GEN_IPADD, NULL); } +char *ipaddr_to_asc(unsigned char *p, int len) +{ + char buf[40], *out; + + switch (len) { + case 4: /* IPv4 */ + BIO_snprintf(buf, sizeof(buf), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); + break; + /* TODO possibly combine with static i2r_address() in v3_addr.c */ + case 16: /* IPv6 */ + for (out = buf; out < buf + 8 * 3; out += 3) { + BIO_snprintf(out, 3 + 1, "%X:", p[0] << 8 | p[1]); + p += 2; + } + out[-1] = '\0'; + break; + default: + BIO_snprintf(buf, sizeof(buf), "", len); + break; + } + return OPENSSL_strdup(buf); +} + /* * Convert IP addresses both IPv4 and IPv6 into an OCTET STRING compatible * with RFC3280. @@ -1044,6 +1087,7 @@ int a2i_ipadd(unsigned char *ipout, const char *ipasc) static int ipv4_from_asc(unsigned char *v4, const char *in) { int a0, a1, a2, a3; + if (sscanf(in, "%d.%d.%d.%d", &a0, &a1, &a2, &a3) != 4) return 0; if ((a0 < 0) || (a0 > 255) || (a1 < 0) || (a1 > 255) @@ -1070,6 +1114,7 @@ typedef struct { static int ipv6_from_asc(unsigned char *v6, const char *in) { IPV6_STAT v6stat; + v6stat.total = 0; v6stat.zero_pos = -1; v6stat.zero_cnt = 0; @@ -1092,21 +1137,19 @@ static int ipv6_from_asc(unsigned char *v6, const char *in) if (v6stat.total == 16) return 0; /* More than three zeroes is an error */ - if (v6stat.zero_cnt > 3) + if (v6stat.zero_cnt > 3) { return 0; /* Can only have three zeroes if nothing else present */ - else if (v6stat.zero_cnt == 3) { + } else if (v6stat.zero_cnt == 3) { if (v6stat.total > 0) return 0; - } - /* Can only have two zeroes if at start or end */ - else if (v6stat.zero_cnt == 2) { + } else if (v6stat.zero_cnt == 2) { + /* Can only have two zeroes if at start or end */ if ((v6stat.zero_pos != 0) && (v6stat.zero_pos != v6stat.total)) return 0; - } else + } else { /* Can only have one zero if *not* start or end */ - { if ((v6stat.zero_pos == 0) || (v6stat.zero_pos == v6stat.total)) return 0; @@ -1125,8 +1168,9 @@ static int ipv6_from_asc(unsigned char *v6, const char *in) memcpy(v6 + v6stat.zero_pos + 16 - v6stat.total, v6stat.tmp + v6stat.zero_pos, v6stat.total - v6stat.zero_pos); - } else + } else { memcpy(v6, v6stat.tmp, 16); + } return 1; } @@ -1134,6 +1178,7 @@ static int ipv6_from_asc(unsigned char *v6, const char *in) static int ipv6_cb(const char *elem, int len, void *usr) { IPV6_STAT *s = usr; + /* Error if 16 bytes written */ if (s->total == 16) return 0; @@ -1197,6 +1242,7 @@ int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, CONF_VALUE *v; int i, mval, spec_char, plus_char; char *p, *type; + if (!nm) return 0; @@ -1211,7 +1257,7 @@ int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, spec_char = ((*p == ':') || (*p == ',') || (*p == '.')); #else spec_char = ((*p == os_toascii[':']) || (*p == os_toascii[',']) - || (*p == os_toascii['.'])); + || (*p == os_toascii['.'])); #endif if (spec_char) { p++; @@ -1228,8 +1274,9 @@ int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, if (plus_char) { mval = -1; type++; - } else + } else { mval = 0; + } if (!X509_NAME_add_entry_by_txt(nm, type, chtype, (unsigned char *)v->value, -1, -1, mval)) diff --git a/crypto/x509/x509_att.c b/crypto/x509/x509_att.c index c8b2d0f8..ce003615 100644 --- a/crypto/x509/x509_att.c +++ b/crypto/x509/x509_att.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,9 @@ #include #include "x509_local.h" +DEFINE_STACK_OF(X509_ATTRIBUTE) +DEFINE_STACK_OF(ASN1_TYPE) + int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x) { return sk_X509_ATTRIBUTE_num(x); diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c index 654b7b5a..05615c1e 100644 --- a/crypto/x509/x509_cmp.c +++ b/crypto/x509/x509_cmp.c @@ -16,6 +16,8 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(X509) + int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b) { int i; diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c index 64791f24..421f26ba 100644 --- a/crypto/x509/x509_lu.c +++ b/crypto/x509/x509_lu.c @@ -15,6 +15,11 @@ #include #include "x509_local.h" +DEFINE_STACK_OF(X509_LOOKUP) +DEFINE_STACK_OF(X509_OBJECT) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(X509) + X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method) { X509_LOOKUP *ret = OPENSSL_zalloc(sizeof(*ret)); diff --git a/crypto/x509/x509_obj.c b/crypto/x509/x509_obj.c index 9d8f48d2..c1e893bf 100644 --- a/crypto/x509/x509_obj.c +++ b/crypto/x509/x509_obj.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(X509_NAME_ENTRY) + /* * Limit to ensure we don't overflow: much greater than * anything encountered in practice. diff --git a/crypto/x509/x509_r2x.c b/crypto/x509/x509_r2x.c index a03ba249..a284bf72 100644 --- a/crypto/x509/x509_r2x.c +++ b/crypto/x509/x509_r2x.c @@ -17,6 +17,8 @@ #include #include +DEFINE_STACK_OF(X509_ATTRIBUTE) + X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) { X509 *ret = NULL; diff --git a/crypto/x509/x509_trs.c b/crypto/x509/x509_trs.c index 10718c34..ebd45b68 100644 --- a/crypto/x509/x509_trs.c +++ b/crypto/x509/x509_trs.c @@ -12,6 +12,9 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(X509_TRUST) +DEFINE_STACK_OF(ASN1_OBJECT) + static int tr_cmp(const X509_TRUST *const *a, const X509_TRUST *const *b); static void trtable_free(X509_TRUST *p); diff --git a/crypto/x509/x509_v3.c b/crypto/x509/x509_v3.c index 715c3594..f0596672 100644 --- a/crypto/x509/x509_v3.c +++ b/crypto/x509/x509_v3.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,8 @@ #include #include "x509_local.h" +DEFINE_STACK_OF(X509_EXTENSION) + int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x) { if (x == NULL) diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index 99479444..fb046918 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -25,6 +25,13 @@ #include "crypto/x509.h" #include "x509_local.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_REVOKED) +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(X509_CRL) +DEFINE_STACK_OF(DIST_POINT) +DEFINE_STACK_OF_STRING() + /* CRL score values */ /* No unhandled critical extensions */ @@ -3251,6 +3258,7 @@ static int build_chain(X509_STORE_CTX *ctx) if (ss < 0) { X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR); ctx->error = X509_V_ERR_UNSPECIFIED; + sk_X509_free(sktmp); return 0; } diff --git a/crypto/x509/x509_vpm.c b/crypto/x509/x509_vpm.c index f6555dd2..f87dfd07 100644 --- a/crypto/x509/x509_vpm.c +++ b/crypto/x509/x509_vpm.c @@ -18,6 +18,10 @@ #include "x509_local.h" +DEFINE_STACK_OF(ASN1_OBJECT) +DEFINE_STACK_OF(X509_VERIFY_PARAM) +DEFINE_STACK_OF_STRING() + /* X509_VERIFY_PARAM functions */ #define SET_HOST 0 @@ -142,14 +146,14 @@ void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param) /* Macro to test if a field should be copied from src to dest */ #define test_x509_verify_param_copy(field, def) \ - (to_overwrite || \ - ((src->field != def) && (to_default || (dest->field == def)))) + (to_overwrite \ + || ((src->field != def) && (to_default || (dest->field == def)))) /* Macro to test and copy a field if necessary */ #define x509_verify_param_copy(field, def) \ - if (test_x509_verify_param_copy(field, def)) \ - dest->field = src->field + if (test_x509_verify_param_copy(field, def)) \ + dest->field = src->field; int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *dest, const X509_VERIFY_PARAM *src) @@ -239,14 +243,16 @@ int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, static int int_x509_param_set1(char **pdest, size_t *pdestlen, const char *src, size_t srclen) { - void *tmp; + char *tmp; if (src) { if (srclen == 0) srclen = strlen(src); - tmp = OPENSSL_memdup(src, srclen); + tmp = OPENSSL_malloc(srclen + 1); if (tmp == NULL) return 0; + memcpy(tmp, src, srclen); + tmp[srclen] = '\0'; /* enforce NUL termination */ } else { tmp = NULL; srclen = 0; @@ -375,6 +381,11 @@ int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, return 1; } +char *X509_VERIFY_PARAM_get0_host(X509_VERIFY_PARAM *param, int idx) +{ + return sk_OPENSSL_STRING_value(param->hosts, idx); +} + int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, const char *name, size_t namelen) { @@ -421,6 +432,11 @@ void X509_VERIFY_PARAM_move_peername(X509_VERIFY_PARAM *to, from->peername = NULL; } +char *X509_VERIFY_PARAM_get0_email(X509_VERIFY_PARAM *param) +{ + return param->email; +} + int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, const char *email, size_t emaillen) { @@ -428,6 +444,24 @@ int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, email, emaillen); } +static unsigned char +*int_X509_VERIFY_PARAM_get0_ip(X509_VERIFY_PARAM *param, size_t *plen) +{ + if (param == NULL || param->ip == NULL) + return NULL; + if (plen != NULL) + *plen = param->iplen; + return param->ip; +} + +char *X509_VERIFY_PARAM_get1_ip_asc(X509_VERIFY_PARAM *param) +{ + size_t iplen; + unsigned char *ip = int_X509_VERIFY_PARAM_get0_ip(param, &iplen); + + return ip == NULL ? NULL : ipaddr_to_asc(ip, iplen); +} + int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, const unsigned char *ip, size_t iplen) { diff --git a/crypto/x509/x509cset.c b/crypto/x509/x509cset.c index 22143da6..d5b37780 100644 --- a/crypto/x509/x509cset.c +++ b/crypto/x509/x509cset.c @@ -16,6 +16,8 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(X509_REVOKED) + int X509_CRL_set_version(X509_CRL *x, long version) { if (x == NULL) diff --git a/crypto/x509/x509name.c b/crypto/x509/x509name.c index b00e5f5b..7e2704fb 100644 --- a/crypto/x509/x509name.c +++ b/crypto/x509/x509name.c @@ -16,6 +16,8 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(X509_NAME_ENTRY) + int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, char *buf, int len) { diff --git a/crypto/x509/x_attrib.c b/crypto/x509/x_attrib.c index b3023411..fca6df50 100644 --- a/crypto/x509/x_attrib.c +++ b/crypto/x509/x_attrib.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include #include "x509_local.h" +DEFINE_STACK_OF(ASN1_TYPE) + /*- * X509_ATTRIBUTE: this has the following form: * diff --git a/crypto/x509/x_crl.c b/crypto/x509/x_crl.c index 0f53be71..0d3e1fed 100644 --- a/crypto/x509/x_crl.c +++ b/crypto/x509/x_crl.c @@ -15,6 +15,11 @@ #include #include "x509_local.h" +DEFINE_STACK_OF(GENERAL_NAME) +DEFINE_STACK_OF(GENERAL_NAMES) +DEFINE_STACK_OF(X509_REVOKED) +DEFINE_STACK_OF(X509_EXTENSION) + static int X509_REVOKED_cmp(const X509_REVOKED *const *a, const X509_REVOKED *const *b); static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); diff --git a/crypto/x509/x_name.c b/crypto/x509/x_name.c index 692bd656..2db9aa34 100644 --- a/crypto/x509/x_name.c +++ b/crypto/x509/x_name.c @@ -16,6 +16,9 @@ #include "crypto/asn1.h" #include "x509_local.h" +DEFINE_STACK_OF(X509_NAME_ENTRY) +DEFINE_STACK_OF(ASN1_VALUE) + /* * Maximum length of X509_NAME: much larger than anything we should * ever see in practice. diff --git a/crypto/x509/x_req.c b/crypto/x509/x_req.c index 21215b47..10b82df5 100644 --- a/crypto/x509/x_req.c +++ b/crypto/x509/x_req.c @@ -13,6 +13,8 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(X509_ATTRIBUTE) + /*- * X509_REQ_INFO is handled in an unusual way to get round * invalid encodings. Some broken certificate requests don't diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c index e9317dc1..8a216c49 100644 --- a/crypto/x509/x_x509.c +++ b/crypto/x509/x_x509.c @@ -15,6 +15,10 @@ #include #include "crypto/x509.h" +#ifndef OPENSSL_NO_RFC3779 +DEFINE_STACK_OF(IPAddressFamily) +#endif + ASN1_SEQUENCE_enc(X509_CINF, enc, 0) = { ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0), ASN1_EMBED(X509_CINF, serialNumber, ASN1_INTEGER), diff --git a/crypto/x509/x_x509a.c b/crypto/x509/x_x509a.c index 18d09e30..f0dc9d65 100644 --- a/crypto/x509/x_x509a.c +++ b/crypto/x509/x_x509a.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include #include "crypto/x509.h" +DEFINE_STACK_OF(ASN1_OBJECT) + /* * X509_CERT_AUX routines. These are used to encode additional user * modifiable data about a certificate. This data is appended to the X509 diff --git a/dev/release-aux/README.md b/dev/release-aux/README.md index 9d05ae5f..01c5a207 100644 --- a/dev/release-aux/README.md +++ b/dev/release-aux/README.md @@ -1,30 +1,30 @@ Auxilliary files for dev/release.sh =================================== -- release-state-fn.sh +- release-state-fn.sh - This is the main version and state update logic... you could say - that it's the innermost engine for the release mechanism. It - tries to be agnostic of versioning schemes, and relies on - release-version-fn.sh to supply necessary functions that are - specific for versioning schemes. - -- release-version-fn.sh + This is the main version and state update logic... you could say + that it's the innermost engine for the release mechanism. It + tries to be agnostic of versioning schemes, and relies on + release-version-fn.sh to supply necessary functions that are + specific for versioning schemes. - Supplies functions that are specific to versioning schemes: - - get_version() gets the version data from appropriate files. +- release-version-fn.sh - set_version() writes the version data to appropriate files. + Supplies functions that are specific to versioning schemes: - fixup_version() updates the version data, given a first argument - that instructs it what update to do. - -- openssl-announce-pre-release.tmpl and openssl-announce-release.tmpl + get_version() gets the version data from appropriate files. - Templates for announcements - -- fixup-*-release.pl and fixup-*-postrelease.pl + set_version() writes the version data to appropriate files. - Fixup scripts for specific files, to be done for the release - commit and for the post-release commit. + fixup_version() updates the version data, given a first argument + that instructs it what update to do. + +- openssl-announce-pre-release.tmpl and openssl-announce-release.tmpl + + Templates for announcements + +- fixup-*-release.pl and fixup-*-postrelease.pl + + Fixup scripts for specific files, to be done for the release + commit and for the post-release commit. diff --git a/dev/release-aux/fixup-CHANGES.md-postrelease.pl b/dev/release-aux/fixup-CHANGES.md-postrelease.pl index 6592635d..0fb2e913 100644 --- a/dev/release-aux/fixup-CHANGES.md-postrelease.pl +++ b/dev/release-aux/fixup-CHANGES.md-postrelease.pl @@ -18,11 +18,11 @@ if (/^### Changes between (\S+) and (\S+) \[xx XXX xxxx\]/ # If this is a pre-release, we do nothing if ($RELEASE !~ /^\d+\.\d+\.\d+-(?:alpha|beta)/) { $_ = <<_____ -### Changes between $v2 and $RELEASE_TEXT [xx XXX xxxx] ### +### Changes between $v2 and $RELEASE_TEXT [xx XXX xxxx] * -### Changes between $v1 and $v2 [$PREV_RELEASE_DATE] ### +### Changes between $v1 and $v2 [$PREV_RELEASE_DATE] _____ } } diff --git a/dev/release-aux/fixup-NEWS.md-postrelease.pl b/dev/release-aux/fixup-NEWS.md-postrelease.pl index b1d47264..ff41ab29 100644 --- a/dev/release-aux/fixup-NEWS.md-postrelease.pl +++ b/dev/release-aux/fixup-NEWS.md-postrelease.pl @@ -18,11 +18,11 @@ if (/^### Major changes between OpenSSL (\S+) and OpenSSL (\S+) \[under developm # If this is a pre-release, we do nothing if ($RELEASE !~ /^\d+\.\d+\.\d+-(?:alpha|beta)/) { $_ = <<_____ -### Major changes between OpenSSL $v2 and OpenSSL $RELEASE_TEXT [under development] ### +### Major changes between OpenSSL $v2 and OpenSSL $RELEASE_TEXT [under development] * -### Major changes between OpenSSL $v1 and OpenSSL $v2 [$PREV_RELEASE_DATE] ### +### Major changes between OpenSSL $v1 and OpenSSL $v2 [$PREV_RELEASE_DATE] _____ } } diff --git a/dev/release.sh b/dev/release.sh index c7f19fe1..7f7042fb 100755 --- a/dev/release.sh +++ b/dev/release.sh @@ -24,6 +24,7 @@ Usage: release.sh [ options ... ] where '{major}' and '{minor}' are the major and minor version numbers. +--reviewer= The reviewer of the commits. --local-user= For the purpose of signing tags and tar files, use this key (default: use the default e-mail address’ key). @@ -65,6 +66,7 @@ do_manual=false tagkey=' -s' gpgkey= +reviewers= upload_address=upload@dev.openssl.org @@ -73,6 +75,7 @@ TEMP=$(getopt -l 'alpha,next-beta,beta,final' \ -l 'no-upload,no-update' \ -l 'verbose,debug' \ -l 'local-user:' \ + -l 'reviewer:' \ -l 'force' \ -l 'help,manual' \ -n release.sh -- - "$@") @@ -122,6 +125,11 @@ while true; do gpgkey=" -u $1" shift ;; + --reviewer ) + reviewers="$reviewers $1=$2" + shift + shift + ;; --force ) force=true shift @@ -311,6 +319,9 @@ if [ -n "$(git status --porcelain)" ]; then $VERBOSE "== Committing updates" git add -u git commit $git_quiet -m 'make update' + if [ -n "$reviewers" ]; then + addrev --nopr $reviewers + fi fi # Write the version information we updated @@ -339,6 +350,9 @@ done $VERBOSE "== Comitting updates and tagging" git add -u git commit $git_quiet -m "Prepare for release of $release_text" +if [ -n "$reviewers" ]; then + addrev --nopr $reviewers +fi echo "Tagging release with tag $tag. You may need to enter a pass phrase" git tag$tagkey "$tag" -m "OpenSSL $release release tag" @@ -436,6 +450,9 @@ done $VERBOSE "== Comitting updates" git add -u git commit $git_quiet -m "Prepare for $release_text" +if [ -n "$reviewers" ]; then + addrev --nopr $reviewers +fi if $do_branch; then $VERBOSE "== Going back to the main branch $current_branch" @@ -460,6 +477,9 @@ if $do_branch; then $VERBOSE "== Comitting updates" git add -u git commit $git_quiet -m "Prepare for $release_text" + if [ -n "$reviewers" ]; then + addrev --nopr $reviewers + fi fi # Done ############################################################### @@ -543,6 +563,7 @@ B<--beta> | B<--final> | B<--branch> | B<--local-user>=I | +B<--reviewer>=I | B<--no-upload> | B<--no-update> | B<--verbose> | @@ -619,6 +640,14 @@ Use I as the local user for C and for signing with C. If not given, then the default e-mail address' key is used. +=item B<--reviewer>=I + +Add I to the set of reviewers for the commits performed by this script. +Multiple reviewers are allowed. + +If no reviewer is given, you will have to run C manually, which +means retagging a release commit manually as well. + =item B<--force> Force execution. Precisely, the check that the current branch is C diff --git a/doc/build.info b/doc/build.info index 47728fed..83da34ee 100644 --- a/doc/build.info +++ b/doc/build.info @@ -56,7 +56,6 @@ DEPEND[$manfile]=$podfile GENERATE[$manfile]=$podfile _____ $OUT .= << "_____" if $podinfile; -DEPEND[$podfile]=$podinfile ../configdata.pm GENERATE[$podfile]=$podinfile _____ } diff --git a/doc/internal/man3/ossl_cmp_msg_protect.pod b/doc/internal/man3/ossl_cmp_msg_protect.pod index a931d3ca..bf859cdb 100644 --- a/doc/internal/man3/ossl_cmp_msg_protect.pod +++ b/doc/internal/man3/ossl_cmp_msg_protect.pod @@ -15,9 +15,9 @@ ossl_cmp_msg_add_extraCerts =head1 DESCRIPTION -ossl_cmp_msg_protect() protects the given message B using an algorithm +ossl_cmp_msg_protect() (re-)protects the given message B using an algorithm depending on the available context information given in the B. -If there is a secretValue it selects PBMAC. Else if there is a clCert +If there is a secretValue it selects PBMAC, else if there is a protection cert it selects Signature and uses B. It also sets the protectionAlg field in the message header accordingly. diff --git a/doc/man1/build.info b/doc/man1/build.info index c48ff0ac..5b0b4eb6 100644 --- a/doc/man1/build.info +++ b/doc/man1/build.info @@ -4,6 +4,7 @@ DEPEND[]= \ openssl-ca.pod \ openssl-ciphers.pod \ openssl-cmds.pod \ + openssl-cmp.pod \ openssl-cms.pod \ openssl-crl2pkcs7.pod \ openssl-crl.pod \ @@ -58,6 +59,7 @@ DEPEND[openssl-asn1parse.pod]=../perlvars.pm DEPEND[openssl-ca.pod]=../perlvars.pm DEPEND[openssl-ciphers.pod]=../perlvars.pm DEPEND[openssl-cmds.pod]=../perlvars.pm +DEPEND[openssl-cmp.pod]=../perlvars.pm DEPEND[openssl-cms.pod]=../perlvars.pm DEPEND[openssl-crl2pkcs7.pod]=../perlvars.pm DEPEND[openssl-crl.pod]=../perlvars.pm @@ -112,6 +114,7 @@ GENERATE[openssl-asn1parse.pod]=openssl-asn1parse.pod.in GENERATE[openssl-ca.pod]=openssl-ca.pod.in GENERATE[openssl-ciphers.pod]=openssl-ciphers.pod.in GENERATE[openssl-cmds.pod]=openssl-cmds.pod.in +GENERATE[openssl-cmp.pod]=openssl-cmp.pod.in GENERATE[openssl-cms.pod]=openssl-cms.pod.in GENERATE[openssl-crl2pkcs7.pod]=openssl-crl2pkcs7.pod.in GENERATE[openssl-crl.pod]=openssl-crl.pod.in diff --git a/doc/man1/openssl-ca.pod.in b/doc/man1/openssl-ca.pod.in index 02026618..35b36afb 100644 --- a/doc/man1/openssl-ca.pod.in +++ b/doc/man1/openssl-ca.pod.in @@ -32,11 +32,11 @@ B B [B<-md> I] [B<-policy> I] [B<-keyfile> I] -[B<-keyform> B|B] +[B<-keyform> B|B|B|B] [B<-key> I] [B<-passin> I] [B<-cert> I] -[B<-certform> B|] +[B<-certform> B|B|B] [B<-selfsign>] [B<-in> I] [B<-inform> B|] @@ -142,18 +142,19 @@ F<.pem> appended. The CA certificate file. -=item B<-certform> B|B +=item B<-certform> B|B|B The format of the data in certificate input files. -The default is PEM. +This option has no effect and is retained for backward compatibility only. =item B<-keyfile> I The private key to sign requests with. -=item B<-keyform> B|B +=item B<-keyform> B|B|B|B -The format of the private key file; the default is B. +The format of the private key input file; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-sigopt> I:I @@ -788,6 +789,11 @@ retained mainly for compatibility reasons. The B<-section> option was added in OpenSSL 3.0.0. +The B<-certform> option has become obsolete in OpenSSL 3.0.0 and has no effect. + +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 SEE ALSO L, diff --git a/doc/man1/openssl-cmp.pod.in b/doc/man1/openssl-cmp.pod.in new file mode 100644 index 00000000..102f99ae --- /dev/null +++ b/doc/man1/openssl-cmp.pod.in @@ -0,0 +1,1165 @@ +=pod +{- OpenSSL::safe::output_do_not_edit_headers(); -} + +=head1 NAME + +openssl-cmp - client for the Certificate Management Protocol (CMP, RFC 4210) + +=head1 SYNOPSIS + +B B +[B<-help>] +[B<-config> I] +[B<-section> I] + +[B<-server> I] +[B<-proxy> I<[http[s]://]address[:port][/path]>] +[B<-no_proxy> I] +[B<-path> I] +[B<-msg_timeout> I] +[B<-total_timeout> I] + +[B<-trusted> I] +[B<-untrusted> I] +[B<-srvcert> I] +[B<-recipient> I] +[B<-expect_sender> I] +[B<-ignore_keyusage>] +[B<-unprotected_errors>] +[B<-extracertsout> I] +[B<-cacertsout> I] + +[B<-ref> I] +[B<-secret> I] +[B<-cert> I] +[B<-key> I] +[B<-keypass> I] +[B<-digest> I] +[B<-mac> I] +[B<-extracerts> I] +[B<-unprotected_requests>] + +[B<-cmd> I] +[B<-infotype> I] +[B<-geninfo> I] + +[B<-newkey> I] +[B<-newkeypass> I] +[B<-subject> I] +[B<-issuer> I] +[B<-days> I] +[B<-reqexts> I] +[B<-sans> I] +[B<-san_nodefault>] +[B<-policies> I] +[B<-policy_oids> I] +[B<-policy_oids_critical>] +[B<-popo> I] +[B<-csr> I] +[B<-out_trusted> I] +[B<-verify_hostname> I] +[B<-verify_ip> I] +[B<-verify_email> I] +[B<-implicit_confirm>] +[B<-disable_confirm>] +[B<-certout> I] + +[B<-oldcert> I] +[B<-revreason> I] + +[B<-certform> I] +[B<-keyform> I] +[B<-certsform> I] +[B<-otherpass> I] +[B<-engine> I] +{- $OpenSSL::safe::opt_provider_synopsis -} + +[B<-tls_used>] +[B<-tls_cert> I] +[B<-tls_key> I] +[B<-tls_keypass> I] +[B<-tls_extra> I] +[B<-tls_trusted> I] +[B<-tls_host> I] + +[B<-batch>] +[B<-repeat> I] +[B<-reqin>] I +[B<-reqin_new_tid>] +[B<-reqout>] I +[B<-rspin>] I +[B<-rspout>] I +[B<-use_mock_srv>] + +[B<-policy> I] +[B<-purpose> I] +[B<-verify_name> I] +[B<-verify_depth> I] +[B<-auth_level> I] +[B<-attime> I] +[B<-ignore_critical>] +[B<-issuer_checks>] +[B<-policy_check>] +[B<-explicit_policy>] +[B<-inhibit_any>] +[B<-inhibit_map>] +[B<-x509_strict>] +[B<-extended_crl>] +[B<-use_deltas>] +[B<-policy_print>] +[B<-check_ss_sig>] +[B<-crl_check>] +[B<-crl_check_all>] +[B<-trusted_first>] +[B<-suiteB_128_only>] +[B<-suiteB_128>] +[B<-suiteB_192>] +[B<-partial_chain>] +[B<-no_alt_chains>] +[B<-no_check_time>] +[B<-allow_proxy_certs>] + +[B<-port> I] +[B<-max_msgs> I] +[B<-srv_ref> I] +[B<-srv_secret> I] +[B<-srv_cert> I] +[B<-srv_key> I] +[B<-srv_keypass> I] +[B<-srv_trusted> I] +[B<-srv_untrusted> I] +[B<-rsp_cert> I] +[B<-rsp_extracerts> I] +[B<-rsp_capubs> I] +[B<-poll_count> I] +[B<-check_after> I] +[B<-grant_implicitconf>] +[B<-pkistatus> I] +[B<-failure> I] +[B<-failurebits> I] +[B<-statusstring> I] +[B<-send_error>] +[B<-send_unprotected>] +[B<-send_unprot_err>] +[B<-accept_unprotected>] +[B<-accept_unprot_err>] +[B<-accept_raverified>] + +=head1 DESCRIPTION + +The B command is a client implementation for the Certificate +Management Protocol (CMP) as defined in RFC4210. +It can be used to request certificates from a CA server, +update their certificates, +request certificates to be revoked, and perform other CMP requests. + +=head1 OPTIONS + +=over 4 + +=item B<-help> + +Display a summary of all options + +=item B<-config> I + +Configuration file to use. +An empty string C<""> means none. +Default filename is from the environment variable C. + +=item B<-section> I + +Section(s) to use within config file defining CMP options. +An empty string C<""> means no specific section. +Default is C. +Multiple section names may be given, separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "..."). +Contents of sections named later may override contents of sections named before. +In any case, as usual, the C<[default]> section and finally the unnamed +section (as far as present) can provide per-option fallback values. + +=back + + +=head2 Generic message options + +=over 4 + +=item B<-cmd> I + +CMP command to execute. +Currently implemented commands are: + +=over 8 + +=item ir E - Initialization Request + +=item cr E - Certificate Request + +=item p10cr - PKCS#10 Certification Request (for legacy support) + +=item kur EE- Key Update Request + +=item rr E - Revocation Request + +=item genm - General Message + +=back + +B requests initialization of an End Entity into a PKI hierarchy by means of +issuance of a first certificate. + +B requests issuance of an additional certificate for an End Entity already +initialized to the PKI hierarchy. + +B requests issuance of an additional certificate similarly to B +but uses PKCS#10 CSR format. + +B requests (key) update for an existing, given certificate. + +B requests revocation of an existing, given certificate. + +B requests information using a General Message, where optionally +included Bs may be used to state which info is of interest. +Upon receipt of the General Response, information about all received +ITAV Bs is printed to stdout. + +=item B<-infotype> I + +Set InfoType name to use for requesting specific info in B, +e.g., C. + +=item B<-geninfo> I + +generalInfo integer values to place in request PKIHeader with given OID, +e.g., C<1.2.3:int:987>. + +=back + + +=head2 Certificate request options + +=over 4 + +=item B<-newkey> I + +The file containing the private or public key for the certificate requested +in Initialization Request (IR), Certification Request(CR), or +Key Update Request (KUR). +Default is the public key in the PKCS#10 CSR given with the B<-csr> option, +if any, or else the current client key, if given. + +=item B<-newkeypass> I + +Pass phrase source for the key given with the B<-newkey> option. +If not given here, the password will be prompted for if needed. + +For more information about the format of B see the +B section in L. + +=item B<-subject> I + +X509 Distinguished Name (DN) of subject to use in the requested certificate +template. +For KUR, it defaults to the subject DN of the reference certificate +(see B<-oldcert>). +This default is used for IR and CR only if no SANs are set. + +The argument must be formatted as I, +characters may be escaped by C<\>E(backslash), no spaces are skipped. + +In case B<-cert> is not set, for instance when using MSG_MAC_ALG, +the subject DN is also used as sender of the PKI message. + +=item B<-issuer> I + +X509 issuer Distinguished Name (DN) of the CA server +to place in the requested certificate template in IR/CR/KUR. + +The argument must be formatted as I, +characters may be escaped by C<\>E(backslash), no spaces are skipped. + +If neither B<-srvcert> nor B<-recipient> is available, +the name given in this option is also set as the recipient of the CMP message. + +=item B<-days> I + +Number of days the new certificate is requested to be valid for, counting from +the current time of the host. +Also triggers the explicit request that the +validity period starts from the current time (as seen by the host). + +=item B<-reqexts> I + +Name of section in OpenSSL config file defining certificate request extensions. + +=item B<-sans> I + +One or more IP addresses, DNS names, or URIs separated by commas or whitespace +(where in the latter case the whole argument must be enclosed in "...") +to add as Subject Alternative Name(s) (SAN) certificate request extension. +If the special element "critical" is given the SANs are flagged as critical. +Cannot be used if any Subject Alternative Name extension is set via B<-reqexts>. + +=item B<-san_nodefault> + +When Subject Alternative Names are not given via B<-sans> +nor defined via B<-reqexts>, +they are copied by default from the reference certificate (see B<-oldcert>). +This can be disabled by giving the B<-san_nodefault> option. + +=item B<-policies> I + +Name of section in OpenSSL config file defining policies to be set +as certificate request extension. +This option cannot be used together with B<-policy_oids>. + +=item B<-policy_oids> I + +One or more OID(s), separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "...") +to add as certificate policies request extension. +This option cannot be used together with B<-policies>. + +=item B<-policy_oids_critical> + +Flag the policies given with B<-policy_oids> as critical. + +=item B<-popo> I + +Proof-of-Possession (POPO) method to use for IR/CR/KUR; values: C<-1>..<2> where +C<-1> = NONE, C<0> = RAVERIFIED, C<1> = SIGNATURE (default), C<2> = KEYENC. + +Note that a signature-based POPO can only be produced if a private key +is provided via the B<-newkey> or B<-key> options. + +=item B<-csr> I + +CSR in PKCS#10 format to use in legacy P10CR messages. + +=item B<-out_trusted> I + +Trusted certificate(s) to use for verifying the newly enrolled certificate. + +Multiple filenames may be given, separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "..."). +Each source may contain multiple certificates. + +=item B<-verify_hostname> I + +When verification of the newly enrolled certificate is enabled (with the +B<-out_trusted> option), check if any DNS Subject Alternative Name (or if no +DNS SAN is included, the Common Name in the subject) equals the given B. + +=item B<-verify_ip> I + +When verification of the newly enrolled certificate is enabled (with the +B<-out_trusted> option), check if there is +an IP address Subject Alternative Name matching the given IP address. + +=item B<-verify_email> I + +When verification of the newly enrolled certificate is enabled (with the +B<-out_trusted> option), check if there is +an email address Subject Alternative Name matching the given email address. + +=item B<-implicit_confirm> + +Request implicit confirmation of newly enrolled certificates. + +=item B<-disable_confirm> + +Do not send certificate confirmation message for newly enrolled certificate +without requesting implicit confirmation +to cope with broken servers not supporting implicit confirmation correctly. +B This leads to behavior violating RFC 4210. + +=item B<-certout> I + +The file where the newly enrolled certificate should be saved. + +=back + + +=head2 Certificate revocation options + +=over 4 + +=item B<-oldcert> I + +The certificate to be updated (i.e., renewed or re-keyed) in Key Update Request +(KUR) messages or to be revoked in Revocation Request (RR) messages. +It must be given for RR, while for KUR it defaults to B<-cert>. + +The reference certificate determined in this way, if any, is also used for +deriving default subject DN and Subject Alternative Names for IR, CR, and KUR. +Its issuer, if any, is used as default recipient in the CMP message header +if neither B<-srvcert>, B<-recipient>, nor B<-issuer> is available. + +=item B<-revreason> I + +Set CRLReason to be included in revocation request (RR); values: C<0>..C<10> +or C<-1> for none (which is the default). + +Reason numbers defined in RFC 5280 are: + + CRLReason ::= ENUMERATED { + unspecified (0), + keyCompromise (1), + cACompromise (2), + affiliationChanged (3), + superseded (4), + cessationOfOperation (5), + certificateHold (6), + -- value 7 is not used + removeFromCRL (8), + privilegeWithdrawn (9), + aACompromise (10) + } + +=back + + +=head2 Message transfer options + +=over 4 + +=item B<-server> I<[http[s]://]address[:port]> + +The IP address or DNS hostname and optionally port (defaulting to 80 or 443) +of the CMP server to connect to using HTTP(S) transport. +The optional "http://" or "https://" prefix is ignored. + +=item B<-proxy> I<[http[s]://]address[:port][/path]> + +The HTTP(S) proxy server to use for reaching the CMP server unless B +applies, see below. +The optional "http://" or "https://" prefix and any trailing path are ignored. +Defaults to the environment variable C if set, else C +in case no TLS is used, otherwise C if set, else C. + +=item B<-no_proxy> I +List of IP addresses and/or DNS names of servers +not to use an HTTP(S) proxy for, separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "..."). +Default is from the environment variable C if set, else C. + +=item B<-path> I + +HTTP path at the CMP server (aka CMP alias) to use for POST requests. +Defaults to "/". + +=item B<-msg_timeout> I + +Number of seconds (or 0 for infinite) a CMP request-response message round trip +is allowed to take before a timeout error is returned. +Default is 120. + +=item B<-total_timeout> I + +Maximum number seconds an overall enrollment transaction may take, +including attempts polling for certificates on C PKIStatus. +Default is 0 (infinite). + +=back + + +=head2 Server authentication options + +=over 4 + +=item B<-trusted> I + +When verifying signature-based protection of CMP response messages, +these are the CA certificate(s) to trust while checking certificate chains +during CMP server authentication. +This option gives more flexibility than the B<-srvcert> option because +it does not pin down the expected CMP server by allowing only one certificate. + +Multiple filenames may be given, separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "..."). +Each source may contain multiple certificates. + +=item B<-untrusted> I + +Non-trusted intermediate certificate(s) that may be useful +for constructing the TLS client certificate chain (if TLS is enabled) and +for building certificate chains while verifying the CMP server certificate +(when checking signature-based CMP message protection) +and while verifying the newly enrolled certificate. +These may get added to the extraCerts field sent in requests as far as needed. + +Multiple filenames may be given, separated by commas and/or whitespace. +Each file may contain multiple certificates. + +=item B<-srvcert> I + +The specific CMP server certificate to use and directly trust (even if it is +expired) when verifying signature-based protection of CMP response messages. +May be set alternatively to the B<-trusted> option +if the certificate is available and only this one shall be accepted. + +If set, the issuer of the certificate is also used as the recipient of the CMP +request and as the expected sender of the CMP response, +overriding any potential B<-recipient> option. + +=item B<-recipient> I + +This option may be used to explicitly set the Distinguished Name (DN) +of the CMP message recipient, i.e., the CMP server (usually a CA or RA entity). + +The argument must be formatted as I, +characters may be escaped by C<\>E(backslash), no spaces are skipped. + +If a CMP server certificate is given with the B<-srvcert> option, its subject +name is taken as the recipient name and the B<-recipient> option is ignored. +If neither of the two are given, the recipient of the PKI message is +determined in the following order: from the B<-issuer> option if present, +the issuer of old cert given with the B<-oldcert> option if present, +the issuer of the client certificate (B<-cert> option) if present. + +The recipient field in the header of CMP messagese is mandatory. +If none of the options that enable the derivation of the recipient name are +given, no suitable value for the recipient in the PKIHeader is available. +As a last resort it is set to NULL-DN. + +When a response is received, its sender must match the recipient of the request. + +=item B<-expect_sender> I + +Distinguished Name (DN) of the expected sender of CMP response messages when +MSG_SIG_ALG is used for protection. +This can be used to ensure that only a particular entity is accepted +as the CMP server, and attackers are not able to use arbitrary certificates +of a trusted PKI hierarchy to fraudulently pose as a CMP server. +Note that this option gives slightly more freedom than B<-srvcert>, +which pins down the server to a particular certificate, +while B<-expect_sender> I will continue to match after updates of the +server cert. + +The argument must be formatted as I, +characters may be escaped by C<\>E(backslash), no spaces are skipped. + +If not given, the subject DN of B<-srvcert>, if provided, will be used. + +=item B<-ignore_keyusage> + +Ignore key usage restrictions in CMP signer certificates when verifying +signature-based protection of incoming CMP messages, +else C must be allowed for signer certificate. + +=item B<-unprotected_errors> + +Accept missing or invalid protection of negative responses from the server. +This applies to the following message types and contents: + +=over 4 + +=item * error messages + +=item * negative certificate responses (IP/CP/KUP) + +=item * negative revocation responses (RP) + +=item * negative PKIConf messages + +=back + +B This setting leads to unspecified behavior and it is meant +exclusively to allow interoperability with server implementations violating +RFC 4210, e.g.: + +=over 4 + +=item * section 5.1.3.1 allows exceptions from protecting only for special +cases: +"There MAY be cases in which the PKIProtection BIT STRING is deliberately not +used to protect a message [...] because other protection, external to PKIX, will +be applied instead." + +=item * section 5.3.21 is clear on ErrMsgContent: "The CA MUST always sign it +with a signature key." + +=item * appendix D.4 shows PKIConf message having protection + +=back + +=item B<-extracertsout> I + +The file where to save any extra certificates received in the extraCerts field +of response messages. + +=item B<-cacertsout> I + +The file where to save any CA certificates received in the caPubs field of +Initializiation Response (IP) messages. + +=back + + +=head2 Client authentication options + +=over 4 + +=item B<-ref> I + +Reference number/string/value to use as fallback senderKID; this is required +if no sender name can be determined from the B<-cert> or <-subject> options and +is typically used when authenticating with pre-shared key (password-based MAC). + +=item B<-secret> I + +Source of secret value to use for creating PBM-based protection of outgoing +messages and for verifying any PBM-based protection of incoming messages. +PBM stands for Password-Based Message Authentication Code. +This takes precedence over the B<-cert> option. + +For more information about the format of B see the +B section in L. + +=item B<-cert> I + +The client's current certificate. +Requires the corresponding key to be given with B<-key>. +The subject of this certificate will be used as the "sender" field +of outgoing CMP messages, while B<-subjectName> may provide a fallback value. +When using signature-based message protection, this "protection certificate" +will be included first in the extraCerts field of outgoing messages. +In Initialization Request (IR) messages this can be used for authenticating +using an external entity certificate as defined in appendix E.7 of RFC 4210. +For Key Update Request (KUR) messages this is also used as +the certificate to be updated if the B<-oldcert> option is not given. +If the file includes further certs, they are appended to the untrusted certs. +These may get added to the extraCerts field sent in requests as far as needed. + +=item B<-key> I + +The corresponding private key file for the client's current certificate given in +the B<-cert> option. +This will be used for signature-based message protection unless +the B<-secret> option indicating PBM or B<-unprotected_requests> is given. + +=item B<-keypass> I + +Pass phrase source for the private key given with the B<-key> option. +Also used for B<-cert> and B<-oldcert> in case it is an encrypted PKCS#12 file. +If not given here, the password will be prompted for if needed. + +For more information about the format of B see the +B section in L. + +=item B<-digest> I + +Specifies name of supported digest to use in RFC 4210's MSG_SIG_ALG +and as the one-way function (OWF) in MSG_MAC_ALG. +If applicable, this is used for message protection and +Proof-of-Possession (POPO) signatures. +To see the list of supported digests, use B. +Defaults to C. + +=item B<-mac> I + +Specifies the name of the MAC algorithm in MSG_MAC_ALG. +To get the names of supported MAC algorithms use B +and possibly combine such a name with the name of a supported digest algorithm, +e.g., hmacWithSHA256. +Defaults to C as per RFC 4210. + +=item B<-extracerts> I + +Certificates to append in the extraCerts field when sending messages. + +Multiple filenames or URLs may be given, separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "..."). +Each source may contain multiple certificates. + +=item B<-unprotected_requests> + +Send messages without CMP-level protection. + +=back + + +=head2 Credentials format options + +=over 4 + +=item B<-certform> I + +File format to use when saving a certificate to a file. +Default value is PEM. + +=item B<-keyform> I + +Format to assume when reading key files. +Default value is PEM. + +=item B<-certsform> I + +Format to try first when reading multiple certificates from file(s). +Default value is PEM. + +=item B<-otherpass> I + +Pass phrase source for certificate given with the B<-trusted>, B<-untrusted>, +B<-out_trusted>, B<-extracerts>, B<-tls_extra>, or B<-tls_trusted> options. +If not given here, the password will be prompted for if needed. + +For more information about the format of B see the +B section in L. + +=item B<-engine> I + +Specifying a crypto engine B will lead to obtaining a functional +reference to the specified engine, initializing it if needed. +The engine will be used for all algorithms supported for keys +prefixed by C. +Engines may be defined in the OpenSSL config file as usual in an engine section. + +Options specifying keys, like B<-key>, B<-newkey>, B<-tls_key> can prefix +C to engine-specific identifiers for security tokens objects held by +the engine. + The following example utilizes the RFC 7512 PKCS #11 URI scheme +as supported, e.g., by libp11: +C<-key engine:pkcs11:object=my-private-key;type=private;pin-value=1234> + +{- $OpenSSL::safe::opt_provider_item -} + +=back + + +=head2 TLS options + +=over 4 + +=item B<-tls_used> + +Enable using TLS (even when other TLS_related options are not set) +when connecting to CMP server. + +=item B<-tls_cert> I + +Client's TLS certificate. +If the file includes further certificates, +they are used for constructing the client cert chain provided to the TLS server. + +=item B<-tls_key> I + +Private key for the client's TLS certificate. + +=item B<-tls_keypass> I + +Pass phrase source for client's private TLS key B. +Also used for B<-tls_cert> in case it is an encrypted PKCS#12 file. +If not given here, the password will be prompted for if needed. + +For more information about the format of B see the +B section in L. + +=item B<-tls_extra> I + +Extra certificates to provide to TLS server during TLS handshake + +=item B<-tls_trusted> I + +Trusted certificate(s) to use for verifying the TLS server certificate. +This implies hostname validation. + +Multiple filenames may be given, separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "..."). +Each source may contain multiple certificates. + +=item B<-tls_host> I + +Address to be checked during hostname validation. +This may be a DNS name or an IP address. +If not given it defaults to the B<-server> address. + +=back + + +=head2 Client-side debugging options + +=over 4 + +=item B<-batch> + +Do not interactively prompt for input, for instance when a password is needed. +This can be useful for batch processing and testing. + +=item B<-repeat> I + +Invoke the command the given number of times with the same parameters. +Default is one invocation. + +=item B<-reqin> I + +Take sequence of CMP requests from file(s). +Multiple filenames may be given, separated by commas and/or whitespace +(where in the latter case the whole argument must be enclosed in "..."). +As many files are read as needed for a complete transaction. + +=item B<-reqin_new_tid> + +Use a fresh transactionID for CMP request messages read using B<-reqin>, +which requires re-protecting them as far as they were protected before. +This may be needed in case the sequence of requests is reused +and the CMP server complains that the transaction ID has already been used. + +=item B<-reqout> I + +Save sequence of CMP requests to file(s). +Multiple filenames may be given, separated by commas and/or whitespace. +As many files are written as needed to store the complete transaction. + +=item B<-rspin> I + +Process sequence of CMP responses provided in file(s), skipping server. +Multiple filenames may be given, separated by commas and/or whitespace. +As many files are read as needed for the complete transaction. + +=item B<-rspout> I + +Save sequence of CMP responses to file(s). +Multiple filenames may be given, separated by commas and/or whitespace. +As many files are written as needed to store the complete transaction. + +=item B<-use_mock_srv> + +Use the internal mock server for testing the client. +This works at API level, bypassing HTTP transport. + +=back + + +=head2 Certificate verification options, for both CMP and TLS + +=over 4 + +=item B<-policy>, B<-purpose>, B<-verify_name>, B<-verify_depth>, +B<-attime>, +B<-ignore_critical>, B<-issuer_checks>, +B<-policy_check>, +B<-explicit_policy>, B<-inhibit_any>, B<-inhibit_map>, +B<-x509_strict>, B<-extended_crl>, B<-use_deltas>, +B<-policy_print>, B<-check_ss_sig>, B<-crl_check>, B<-crl_check_all>, +B<-trusted_first>, +B<-suiteB_128_only>, B<-suiteB_128>, B<-suiteB_192>, +B<-partial_chain>, B<-no_alt_chains>, B<-no_check_time>, +B<-auth_level>, +B<-allow_proxy_certs> + +Set various options of certificate chain verification. +See L for details. + +=back + + +=head2 Mock server options, for testing purposes only + +=over 4 + +=item B<-port> I + +Act as CMP HTTP server mock-up listening on the given port. + +=item B<-max_msgs> I + +Maximum number of CMP (request) messages the CMP HTTP server mock-up +should handle, which must be non-negative. +The default value is 0, which means that no limit is imposed. +In any case the server terminates on internal errors, but not when it +detects a CMP-level error that it can successfully answer with an error message. + +=item B<-srv_ref> I + +Reference value to use as senderKID of server in case no B<-srv_cert> is given. + +=item B<-srv_secret> I + +Password source for server authentication with a pre-shared key (secret). + +=item B<-srv_cert> I + +Certificate of the server. + +=item B<-srv_key> I + +Private key used by the server for signing messages. + +=item B<-srv_keypass> I + +Server private key (and cert) file pass phrase source. + +=item B<-srv_trusted> I + +Trusted certificates for client authentication. + +=item B<-srv_untrusted> I + +Intermediate CA certs that may be useful when verifying client certificates. + +=item B<-rsp_cert> I + +Certificate to be returned as mock enrollment result. + +=item B<-rsp_extracerts> I + +Extra certificates to be included in mock certification responses. + +=item B<-rsp_capubs> I + +CA certificates to be included in mock Initialization Response (IP) message. + +=item B<-poll_count> I + +Number of times the client must poll before receiving a certificate. + +=item B<-check_after> I + +The checkAfter value (number of seconds to wait) to include in poll response. + + +=item B<-grant_implicitconf> + +Grant implicit confirmation of newly enrolled certificate. + +=item B<-pkistatus> I + +PKIStatus to be included in server response. +Valid range is 0 (accepted) .. 6 (keyUpdateWarning). + +=item B<-failure> I + +A single failure info bit number to be included in server response. +Valid range is 0 (badAlg) .. 26 (duplicateCertReq). + +=item B<-failurebits> I +Number representing failure bits to be included in server response. +Valid range is 0 .. 2^27 - 1. + +=item B<-statusstring> I + +Text to be included as status string in server response. + +=item B<-send_error> + +Force server to reply with error message. + +=item B<-send_unprotected> + +Send response messages without CMP-level protection. + +=item B<-send_unprot_err> + +In case of negative responses, server shall send unprotected error messages, +certificate responses (IP/CP/KUP), and revocation responses (RP). +WARNING: This setting leads to behavior violating RFC 4210. + +=item B<-accept_unprotected> + +Accept missing or invalid protection of requests. + +=item B<-accept_unprot_err> + +Accept unprotected error messages from client. + +=item B<-accept_raverified> + +Accept RAVERIFED as proof-of-possession (POPO). + +=back + + +=head1 NOTES + +When setting up CMP configurations and experimenting with enrollment options +typically various errors occur until the configuration is correct and complete. +When the CMP server reports an error the client will by default +check the protection of the CMP response message. +Yet some CMP services tend not to protect negative responses. +In this case the client will reject them, and thus their contents are not shown +although they usually contain hints that would be helpful for diagnostics. +For assisting in such cases the CMP client offers a workaround via the +B<-unprotected_errors> option, which allows accepting such negative messages. + + +=head1 EXAMPLES + +=head2 Simple examples using the default OpenSSL configuration file + +This CMP client implementation comes with demonstrative CMP sections +in the example configuration file F, +which can be used to interact conveniently with the Insta Demo CA. + +In order to enroll an initial certificate from that CA it is sufficient +to issue the following shell commands. + + cd /path/to/openssl + export OPENSSL_CONF=openssl.cnf + wget 'http://pki.certificate.fi:8080/install-ca-cert.html/ca-certificate.crt\ + ?ca-id=632&download-certificate=1' -O insta.ca.crt + openssl genrsa -out insta.priv.pem + openssl cmp -section insta + +This should produce the file F containing a new certificate +for the private key held in F. +It can be viewed using, e.g., + + openssl x509 -noout -text -in insta.cert.pem + +In case the network setup requires using an HTTP proxy it may be given as usual +via the environment variable B or via the B option or +the CMP command-line argument B<-proxy>, for example + + -proxy http://192.168.1.1:8080 + +In the Insta Demo CA scenario both clients and the server may use the pre-shared +secret "insta" and the reference value "3078" to authenticate to each other. + +Alternatively, CMP messages may be protected in signature-based manner, +where the trust anchor in this case is F +and the client may use any certificate already obtained from that CA, +as specified in the B<[signature]> section of the example configuration. +This can be used in combination with the B<[insta]> section simply by + + openssl cmp -section insta,signature + +By default the CMP IR message type is used, yet CR works equally here. +This may be specified directly at the command line: + + openssl cmp -section insta -cmd cr + +or by referencing in addition the B<[cr]> section of the example configuration: + + openssl cmp -section insta,cr + +In order to update the enrolled certificate one may call + + openssl cmp -section insta,kur + +using with PBM-based protection or + + openssl cmp -section insta,kur,signature + +using signature-based protection. + +In a similar way any previously enrolled certificate may be revoked by + + openssl cmp -section insta,rr -trusted insta.ca.crt + +or + + openssl cmp -section insta,rr,signature + +Many more options can be used in the configuration file +and/or on the command line. + + +=head2 Certificate enrollment + +The following examples at first do not make use of a configuration file. +They assume that a CMP server can be contacted on the local TCP port 80 +and accepts requests under the alias "/pkix/". + +For enrolling its very first certificate the client generates a first client key +and sends an initial request message to the local CMP server +using a pre-shared secret key for mutual authentication. +In this example the client does not have the CA certificate yet, +so we specify the name of the CA with the B<-recipient> option +and save any CA certificates that we may receive in the C file. + +In below command line usage examples the C<\> at line ends is just used +for formatting; each of the command invocations should be on a single line. + + openssl genrsa -out cl_key.pem + openssl cmp -cmd ir -server 127.0.0.1:80 -path pkix/ \ + -ref 1234 -secret pass:1234-5678-1234-5678 \ + -recipient "/CN=CMPserver" \ + -newkey cl_key.pem -subject "/CN=MyName" \ + -cacertsout capubs.pem -certout cl_cert.pem + + +=head2 Certificate update + +Then, when the client certificate and its related key pair needs to be updated, +the client can send a key update request taking the certs in C +as trusted for authenticating the server and using the previous cert and key +for its own authentication. +Then it can start using the new cert and key. + + openssl genrsa -out cl_key_new.pem + openssl cmp -cmd kur -server 127.0.0.1:80 -path pkix/ \ + -trusted capubs.pem \ + -cert cl_cert.pem -key cl_key.pem \ + -newkey cl_key_new.pem -certout cl_cert.pem + cp cl_key_new.pem cl_key.pem + +This command sequence can be repated as often as needed. + + +=head2 Requesting information from CMP server + +Requesting "all relevant information" with an empty General Message. +This prints information about all received ITAV Bs to stdout. + + openssl cmp -cmd genm -server 127.0.0.1 -path pkix/ \ + -ref 1234 -secret pass:1234-5678-1234-5678 \ + -recipient "/CN=CMPserver" + + +=head2 Using a custom configuration file + +For CMP client invocations, in particular for certificate enrollment, +usually many parameters need to be set, which is tedious and error-prone to do +on the command line. +Therefore the client offers the possibility to read +options from sections of the OpenSSL config file, usually called B. +The values found there can still be extended and even overridden by any +subsequently loaded sections and on the command line. + +After including in the configuration file the following sections: + + [cmp] + server = 127.0.0.1 + path = pkix/ + trusted = capubs.pem + cert = cl_cert.pem + key = cl_key.pem + newkey = cl_key.pem + certout = cl_cert.pem + + [cmp-init] + recipient = "/CN=CMPserver" + trusted = + cert = + key = + ref = 1234 + secret = pass:1234-5678-1234-567 + subject = "/CN=MyName" + cacertsout = capubs.pem + +the above enrollment invocations reduce to + + openssl cmp -section cmp,cmp-init + openssl cmp -cmd kur -newkey cl_key_new.pem + +and the above genm call reduces to + + openssl cmp -section cmp,cmp-init -cmd genm + +=head1 SEE ALSO + +L, L, L, +L, L, L + +=head1 COPYRIGHT + +Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the OpenSSL license (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/man1/openssl-cms.pod.in b/doc/man1/openssl-cms.pod.in index 15dd7799..375d3587 100644 --- a/doc/man1/openssl-cms.pod.in +++ b/doc/man1/openssl-cms.pod.in @@ -36,7 +36,7 @@ B B [B<-inform> B|B|B] [B<-outform> B|B|B] [B<-rctform> B|B|B] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B|B] [B<-stream>] [B<-indef>] [B<-noindef>] @@ -82,7 +82,7 @@ B B {- $OpenSSL::safe::opt_r_synopsis -} {- $OpenSSL::safe::opt_engine_synopsis -} {- $OpenSSL::safe::opt_provider_synopsis -} -[I ...] +[I ...] =for openssl ifdef des-wrap engine @@ -107,7 +107,7 @@ Print out a usage message. Encrypt mail for the given recipient certificates. Input file is the message to be encrypted. The output file is the encrypted mail in MIME format. The -actual CMS type is EnvelopedData. +actual CMS type is B. Note that no revocation check is done for the recipient cert, so if that key has been compromised, others may be able to decrypt the text. @@ -235,9 +235,10 @@ The output format of the CMS structure (if one is being written); the default is B. See L for details. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B|B The format of the private key file; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-rctform> B|B|B @@ -370,7 +371,7 @@ the MIME type multipart/signed is used. Allows additional certificates to be specified. When signing these will be included with the message. When verifying these will be searched for -the signers certificates. The certificates should be in PEM format. +the signers certificates. =item B<-certsout> I @@ -493,7 +494,7 @@ Any verification errors cause the command to exit. {- $OpenSSL::safe::opt_provider_item -} -=item I ... +=item I ... One or more certificates of message recipients: used when encrypting a message. @@ -766,6 +767,9 @@ was added in OpenSSL 1.0.2. The -no_alt_chains option was added in OpenSSL 1.0.2b. +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-crl.pod.in b/doc/man1/openssl-crl.pod.in index 409f0b60..19e72f1b 100644 --- a/doc/man1/openssl-crl.pod.in +++ b/doc/man1/openssl-crl.pod.in @@ -12,7 +12,7 @@ B B [B<-inform> B|B] [B<-outform> B|B] [B<-key> I] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B] [B<-text>] [B<-in> I] [B<-out> I] @@ -45,19 +45,24 @@ This command processes CRL files in DER or PEM format. Print out a usage message. -=item B<-inform> B|B, B<-outform> B|B +=item B<-inform> B|B -The input and output formats of the CRL; the default is B. +The CRL input format. +This option has no effect and is retained for backward compatibility only. + +=item B<-outform> B|B + +The CRL output format; the default is B. See L for details. =item B<-key> I The private key to be used to sign the CRL. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B -The format of the private key file; the default is B. -See L for details. +The format of the private key file. +This option has no effect and is retained for backward compatibility only. =item B<-in> I @@ -136,7 +141,7 @@ Convert a CRL file from PEM to DER: Output the text form of a DER encoded certificate: - openssl crl -in crl.der -inform DER -text -noout + openssl crl -in crl.der -text -noout =head1 BUGS @@ -151,6 +156,11 @@ L, L, L +=head1 HISTORY + +The B<-inform> and B<-keyform> options have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-dgst.pod.in b/doc/man1/openssl-dgst.pod.in index 84bd133f..22c07a5a 100644 --- a/doc/man1/openssl-dgst.pod.in +++ b/doc/man1/openssl-dgst.pod.in @@ -103,6 +103,7 @@ command instead for this. =item B<-keyform> B|B|B|B The format of the key to sign with; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-sigopt> I:I @@ -247,6 +248,9 @@ L The default digest was changed from MD5 to SHA256 in OpenSSL 1.1.0. The FIPS-related options were removed in OpenSSL 1.1.0. +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-dhparam.pod.in b/doc/man1/openssl-dhparam.pod.in index bb401494..91883fb8 100644 --- a/doc/man1/openssl-dhparam.pod.in +++ b/doc/man1/openssl-dhparam.pod.in @@ -30,9 +30,6 @@ B =head1 DESCRIPTION -This command has been deprecated. -The L command should be used instead. - This command is used to manipulate DH parameter files. =head1 OPTIONS @@ -62,6 +59,8 @@ as the input filename. =item B<-dsaparam> +This option is deprecated. + If this option is used, DSA rather than DH parameters are read or created; they are converted to DH format. Otherwise, "strong" primes (such that (p-1)/2 is also prime) will be used for DH parameter generation. @@ -136,7 +135,7 @@ L =head1 HISTORY -This command was deprecated in OpenSSL 3.0. +The B<-dsaparam> option was deprecated in OpenSSL 3.0. =head1 COPYRIGHT diff --git a/doc/man1/openssl-dsa.pod.in b/doc/man1/openssl-dsa.pod.in index a0352343..f3d1a942 100644 --- a/doc/man1/openssl-dsa.pod.in +++ b/doc/man1/openssl-dsa.pod.in @@ -43,9 +43,6 @@ B B =head1 DESCRIPTION -This command has been deprecated. -The L command should be used instead. - This command processes DSA keys. They can be converted between various forms and their components printed out. B This command uses the traditional SSLeay compatible format for private key encryption: newer @@ -162,10 +159,6 @@ L, L, L -=head1 HISTORY - -This command was deprecated in OpenSSL 3.0. - =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-dsaparam.pod.in b/doc/man1/openssl-dsaparam.pod.in index d9775dd0..27bd6517 100644 --- a/doc/man1/openssl-dsaparam.pod.in +++ b/doc/man1/openssl-dsaparam.pod.in @@ -25,9 +25,6 @@ B =head1 DESCRIPTION -This command has been deprecated. -The L command should be used instead. - This command is used to manipulate or generate DSA parameter files. DSA parameter generation can be a slow process and as a result the same set of @@ -107,10 +104,6 @@ L, L, L -=head1 HISTORY - -This command was deprecated in OpenSSL 3.0. - =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-ec.pod.in b/doc/man1/openssl-ec.pod.in index f493a537..c1e92ef5 100644 --- a/doc/man1/openssl-ec.pod.in +++ b/doc/man1/openssl-ec.pod.in @@ -13,7 +13,7 @@ openssl-ec - EC key processing B B [B<-help>] -[B<-inform> B|B] +[B<-inform> B|B|B|B] [B<-outform> B|B] [B<-in> I] [B<-passin> I] @@ -38,9 +38,6 @@ B B =head1 DESCRIPTION -This command has been deprecated. -The L command should be used instead. - The L command processes EC keys. They can be converted between various forms and their components printed out. B OpenSSL uses the private key format specified in 'SEC 1: Elliptic Curve Cryptography' @@ -55,9 +52,15 @@ PKCS#8 private key format use the L command. Print out a usage message. -=item B<-inform> B|B, B<-outform> B|B +=item B<-inform> B|B|B|B -The input and formats; the default is B. +The key input format; the default is B. +The only value with effect is B; all others have become obsolete. +See L for details. + +=item B<-outform> B|B + +The key output formats; the default is B. See L for details. Private keys are an SEC1 private key or PKCS#8 format. @@ -183,10 +186,6 @@ L, L, L -=head1 HISTORY - -This command was deprecated in OpenSSL 3.0. - =head1 COPYRIGHT Copyright 2003-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-ecparam.pod.in b/doc/man1/openssl-ecparam.pod.in index a42fa35e..ff4d97ea 100644 --- a/doc/man1/openssl-ecparam.pod.in +++ b/doc/man1/openssl-ecparam.pod.in @@ -32,10 +32,6 @@ B =head1 DESCRIPTION -This command has been deprecated. -The L and L commands -should be used instead. - This command is used to manipulate or generate EC parameter files. OpenSSL is currently not able to generate new groups and therefore @@ -172,10 +168,6 @@ L, L, L -=head1 HISTORY - -This command was deprecated in OpenSSL 3.0. - =head1 COPYRIGHT Copyright 2003-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-fipsinstall.pod.in b/doc/man1/openssl-fipsinstall.pod.in index 74b23341..1d1cdea7 100644 --- a/doc/man1/openssl-fipsinstall.pod.in +++ b/doc/man1/openssl-fipsinstall.pod.in @@ -168,7 +168,7 @@ L Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man1/openssl-gendsa.pod.in b/doc/man1/openssl-gendsa.pod.in index 0d908e0d..aca9bb51 100644 --- a/doc/man1/openssl-gendsa.pod.in +++ b/doc/man1/openssl-gendsa.pod.in @@ -33,9 +33,6 @@ B B =head1 DESCRIPTION -This command has been deprecated. -The L command should be used instead. - This command generates a DSA private key from a DSA parameter file (which will be typically generated by the L command). @@ -95,10 +92,6 @@ L, L, L -=head1 HISTORY - -This command was deprecated in OpenSSL 3.0. - =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-kdf.pod.in b/doc/man1/openssl-kdf.pod.in index 4c0825c9..9c585325 100644 --- a/doc/man1/openssl-kdf.pod.in +++ b/doc/man1/openssl-kdf.pod.in @@ -167,7 +167,7 @@ Added in OpenSSL 3.0 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man1/openssl-mac.pod.in b/doc/man1/openssl-mac.pod.in index 2157c75c..4c9cc3bc 100644 --- a/doc/man1/openssl-mac.pod.in +++ b/doc/man1/openssl-mac.pod.in @@ -158,7 +158,7 @@ L Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man1/openssl-ocsp.pod.in b/doc/man1/openssl-ocsp.pod.in index e227f50e..a738ddbd 100644 --- a/doc/man1/openssl-ocsp.pod.in +++ b/doc/man1/openssl-ocsp.pod.in @@ -103,8 +103,8 @@ specify output filename, default is standard output. =item B<-issuer> I This specifies the current issuer certificate. This option can be used -multiple times. The certificate specified in I must be in -PEM format. This option B come before any B<-cert> options. +multiple times. +This option B come before any B<-cert> options. =item B<-cert> I diff --git a/doc/man1/openssl-pkey.pod.in b/doc/man1/openssl-pkey.pod.in index a678bd75..de1bef95 100644 --- a/doc/man1/openssl-pkey.pod.in +++ b/doc/man1/openssl-pkey.pod.in @@ -13,7 +13,7 @@ openssl-pkey - public or private key processing command B B [B<-help>] -[B<-inform> B|B] +[B<-inform> B|B|B|B] [B<-outform> B|B] [B<-in> I] [B<-passin> I] @@ -48,9 +48,15 @@ converted between various forms and their components printed out. Print out a usage message. -=item B<-inform> B|B, B<-outform> B|B +=item B<-inform> B|B|B|B -The input and formats; the default is B. +The key input format; the default is B. +The only value with effect is B; all others have become obsolete. +See L for details. + +=item B<-outform> B|B + +The key output formats; the default is B. See L for details. =item B<-in> I diff --git a/doc/man1/openssl-pkeyutl.pod.in b/doc/man1/openssl-pkeyutl.pod.in index 0a65f6ac..d823f0b8 100644 --- a/doc/man1/openssl-pkeyutl.pod.in +++ b/doc/man1/openssl-pkeyutl.pod.in @@ -15,10 +15,10 @@ B B [B<-out> I] [B<-sigfile> I] [B<-inkey> I] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B|B] [B<-passin> I] [B<-peerkey> I] -[B<-peerform> B|B|B] +[B<-peerform> B|B|B|B] [B<-pubin>] [B<-certin>] [B<-rev>] @@ -89,9 +89,10 @@ Signature file, required for B<-verify> operations only The input key file, by default it should be a private key. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B|B The key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-passin> I @@ -103,9 +104,10 @@ see L. The peer key file, used by key derivation (agreement) operations. -=item B<-peerform> B|B|B +=item B<-peerform> B|B|B|B The peer key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-pubin> @@ -402,6 +404,10 @@ L L, L, +=head1 HISTORY + +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. =head1 COPYRIGHT diff --git a/doc/man1/openssl-rehash.pod.in b/doc/man1/openssl-rehash.pod.in index c98f89eb..380ad6dd 100644 --- a/doc/man1/openssl-rehash.pod.in +++ b/doc/man1/openssl-rehash.pod.in @@ -2,7 +2,7 @@ {- OpenSSL::safe::output_do_not_edit_headers(); -} =for comment -Original text by James Westby, contributed under the OpenSSL license. +Original text by James Westby. =head1 NAME diff --git a/doc/man1/openssl-req.pod.in b/doc/man1/openssl-req.pod.in index 397bf552..ab6b3d78 100644 --- a/doc/man1/openssl-req.pod.in +++ b/doc/man1/openssl-req.pod.in @@ -25,7 +25,7 @@ B B [B<-pkeyopt> I:I] [B<-nodes>] [B<-key> I] -[B<-keyform> B|B] +[B<-keyform> B|B|B|B] [B<-keyout> I] [B<-keygen_engine> I] [B<-I>] @@ -186,9 +186,10 @@ See L for more details. This specifies the file to read the private key from. It also accepts PKCS#8 format private keys for PEM format files. -=item B<-keyform> B|B +=item B<-keyform> B|B|B|B The format of the private key; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-keyout> I @@ -691,6 +692,9 @@ L The B<-section> option was added in OpenSSL 3.0.0. +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-rsa.pod.in b/doc/man1/openssl-rsa.pod.in index 59929eaf..b2477b2b 100644 --- a/doc/man1/openssl-rsa.pod.in +++ b/doc/man1/openssl-rsa.pod.in @@ -13,7 +13,7 @@ openssl-rsa - RSA key processing command B B [B<-help>] -[B<-inform> B|B] +[B<-inform> B|B|B|B] [B<-outform> B|B] [B<-in> I] [B<-passin> I] @@ -46,9 +46,6 @@ B B =head1 DESCRIPTION -This command has been deprecated. -The L command should be used instead. - This command processes RSA keys. They can be converted between various forms and their components printed out. B this command uses the traditional SSLeay compatible format for private key encryption: newer @@ -64,9 +61,15 @@ L command. Print out a usage message. -=item B<-inform> B|B, B<-outform> B|B +=item B<-inform> B|B|B|B -The input and formats; the default is B. +The key input format; the default is B. +The only value with effect is B; all others have become obsolete. +See L for details. + +=item B<-outform> B|B + +The key output format; the default is B. See L for details. =item B<-inform> B|B @@ -184,10 +187,6 @@ L, L, L -=head1 HISTORY - -This command was deprecated in OpenSSL 3.0. - =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-rsautl.pod.in b/doc/man1/openssl-rsautl.pod.in index 2461db53..5383fe21 100644 --- a/doc/man1/openssl-rsautl.pod.in +++ b/doc/man1/openssl-rsautl.pod.in @@ -14,7 +14,7 @@ B B [B<-rev>] [B<-out> I] [B<-inkey> I] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B|B] [B<-pubin>] [B<-certin>] [B<-sign>] @@ -76,9 +76,10 @@ default. The input key file, by default it should be an RSA private key. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B|B The key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-pubin> @@ -237,6 +238,9 @@ L This command was deprecated in OpenSSL 3.0. +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-s_client.pod.in b/doc/man1/openssl-s_client.pod.in index 42cff1f5..4d6b54a5 100644 --- a/doc/man1/openssl-s_client.pod.in +++ b/doc/man1/openssl-s_client.pod.in @@ -29,14 +29,14 @@ B B [B<-verifyCApath> I] [B<-verifyCAstore> I] [B<-cert> I] -[B<-certform> B|B] +[B<-certform> B|B|B] [B<-cert_chain> I] [B<-build_chain>] [B<-CRL> I] [B<-CRLform> B|B] [B<-crl_download>] [B<-key> I] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B|B] [B<-pass> I] [B<-chainCAfile> I] [B<-chainCApath> I] @@ -240,10 +240,10 @@ The default is not to use a certificate. The chain for the client certificate may be specified using B<-cert_chain>. -=item B<-certform> B|B +=item B<-certform> B|B|B The client certificate file format to use; the default is B. -see L. +This option has no effect and is retained for backward compatibility only. =item B<-cert_chain> @@ -273,9 +273,10 @@ Download CRL from distribution points in the certificate. The client private key file to use. If not specified then the certificate file will be used to read also the key. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B|B The key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-pass> I @@ -850,7 +851,7 @@ for an appropriate page. If a certificate is specified on the command line using the B<-cert> option it will not be used unless the server specifically requests -a client certificate. Therefor merely including a client certificate +a client certificate. Therefore merely including a client certificate on the command line is no guarantee that the certificate works. If there are problems verifying a server certificate then the @@ -894,6 +895,11 @@ L The B<-no_alt_chains> option was added in OpenSSL 1.1.0. The B<-name> option was added in OpenSSL 1.1.1. +The B<-certform> option has become obsolete in OpenSSL 3.0.0 and has no effect. + +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-s_server.pod.in b/doc/man1/openssl-s_server.pod.in index fb8df539..8e5da51c 100644 --- a/doc/man1/openssl-s_server.pod.in +++ b/doc/man1/openssl-s_server.pod.in @@ -20,19 +20,19 @@ B B [B<-Verify> I] [B<-cert> I] [B<-cert2> I] -[B<-certform> B|B] +[B<-certform> B|B|B] [B<-cert_chain> I] [B<-build_chain>] [B<-serverinfo> I] [B<-key> I] [B<-key2> I] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B|B] [B<-pass> I] [B<-dcert> I] -[B<-dcertform> B|B] +[B<-dcertform> B|B|B] [B<-dcert_chain> I] [B<-dkey> I] -[B<-dkeyform> B|B|B] +[B<-dkeyform> B|B|B|B] [B<-dpass> I] [B<-nbio_test>] [B<-crlf>] @@ -46,6 +46,7 @@ B B [B<-www>] [B<-WWW>] [B<-http_server_binmode>] +[B<-no_ca_names>] [B<-servername>] [B<-servername_fatal>] [B<-tlsextdebug>] @@ -219,10 +220,10 @@ certificate and some require a certificate with a certain public key type: for example the DSS cipher suites require a certificate containing a DSS (DSA) key. If not specified then the filename F will be used. -=item B<-certform> B|B +=item B<-certform> B|B|B -The server certificate file format; the default is B. -See L for details. +The server certificate file format. +This option has no effect and is retained for backward compatibility only. =item B<-cert_chain> @@ -247,9 +248,10 @@ ServerHello extension will be returned. The private key to use. If not specified then the certificate file will be used. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B|B The key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-pass> I @@ -275,14 +277,15 @@ A file containing untrusted certificates to use when attempting to build the server certificate chain when a certificate specified via the B<-dcert> option is in use. -=item B<-dcertform> B|B +=item B<-dcertform> B|B|B -The format of the additional certificate file; the default is B. -See L. +The format of the additional certificate file. +This option has no effect and is retained for backward compatibility only. -=item B<-dkeyform> B|B|B +=item B<-dkeyform> B|B|B|B The format of the additional private key; the default is B. +The only value with effect is B; all others have become obsolete. See L. =item B<-dpass> I @@ -411,6 +414,12 @@ Neither of these options can be used in conjunction with B<-early_data>. When acting as web-server (using option B<-WWW> or B<-HTTP>) open files requested by the client in binary mode. +=item B<-no_ca_names> + +Disable TLS Extension CA Names. You may want to disable it for security reasons +or for compatibility with some Windows TLS implementations crashing when this +extension is larger than 1024 bytes. + =item B<-id_prefix> I Generate SSL/TLS session IDs prefixed by I. This is mostly useful @@ -815,6 +824,12 @@ The -no_alt_chains option was added in OpenSSL 1.1.0. The -allow-no-dhe-kex and -prioritize_chacha options were added in OpenSSL 1.1.1. +All B<-keyform> and B<-dkeyform> values except B +have become obsolete in OpenSSL 3.0.0 and have no effect. + +The B<-certform> and B<-dcertform> options have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-s_time.pod.in b/doc/man1/openssl-s_time.pod.in index dd4029d4..0f9f0555 100644 --- a/doc/man1/openssl-s_time.pod.in +++ b/doc/man1/openssl-s_time.pod.in @@ -164,7 +164,7 @@ send an HTTP request for an appropriate page. If a certificate is specified on the command line using the B<-cert> option it will not be used unless the server specifically requests -a client certificate. Therefor merely including a client certificate +a client certificate. Therefore merely including a client certificate on the command line is no guarantee that the certificate works. =head1 BUGS diff --git a/doc/man1/openssl-smime.pod.in b/doc/man1/openssl-smime.pod.in index 13a0e4a4..4dce01a4 100644 --- a/doc/man1/openssl-smime.pod.in +++ b/doc/man1/openssl-smime.pod.in @@ -32,7 +32,7 @@ B B [B<-recip> I< file>] [B<-inform> B|B|B] [B<-outform> B|B|B] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B|B] [B<-passin> I] [B<-inkey> I] [B<-out> I] @@ -50,7 +50,7 @@ B B {- $OpenSSL::safe::opt_r_synopsis -} {- $OpenSSL::safe::opt_v_synopsis -} {- $OpenSSL::safe::opt_provider_synopsis -} -I ... +I ... =for openssl ifdef engine @@ -125,9 +125,10 @@ The output format of the PKCS#7 (S/MIME) structure (if one is being written); the default is B. See L for details. -=item B<-keyform> B|B +=item B<-keyform> B|B|B|B The key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-stream>, B<-indef>, B<-noindef> @@ -235,7 +236,7 @@ option is present B is used instead. Allows additional certificates to be specified. When signing these will be included with the message. When verifying these will be searched for -the signers certificates. The certificates should be in PEM format. +the signers certificates. =item B<-signer> I @@ -291,7 +292,7 @@ Any verification errors cause the command to exit. {- $OpenSSL::safe::opt_provider_item -} -=item I ... +=item I ... One or more certificates of message recipients, used when encrypting a message. @@ -479,6 +480,9 @@ added in OpenSSL 1.0.0 The -no_alt_chains option was added in OpenSSL 1.1.0. +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-spkac.pod.in b/doc/man1/openssl-spkac.pod.in index 72e4788f..ca7d097d 100644 --- a/doc/man1/openssl-spkac.pod.in +++ b/doc/man1/openssl-spkac.pod.in @@ -16,7 +16,7 @@ B B [B<-in> I] [B<-out> I] [B<-key> I] -[B<-keyform> B|B|B] +[B<-keyform> B|B|B|B] [B<-passin> I] [B<-challenge> I] [B<-pubkey>] @@ -59,9 +59,10 @@ Create an SPKAC file using the private key in I. The B<-in>, B<-noout>, B<-spksect> and B<-verify> options are ignored if present. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B|B The key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-passin> I @@ -148,6 +149,11 @@ to be used in a "replay attack". L, L +=head1 HISTORY + +All B<-keyform> values except B have become obsolete in OpenSSL 3.0.0 +and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl-verify.pod.in b/doc/man1/openssl-verify.pod.in index e4e394fa..7271efe8 100644 --- a/doc/man1/openssl-verify.pod.in +++ b/doc/man1/openssl-verify.pod.in @@ -99,7 +99,6 @@ with a B<->. One or more certificates to verify. If no certificates are given, this command will attempt to read a certificate from standard input. -Certificates must be in PEM format. If a certificate chain has multiple problems, this program tries to display all of them. diff --git a/doc/man1/openssl-x509.pod.in b/doc/man1/openssl-x509.pod.in index b8fd2a40..918c91b3 100644 --- a/doc/man1/openssl-x509.pod.in +++ b/doc/man1/openssl-x509.pod.in @@ -11,9 +11,9 @@ B B [B<-help>] [B<-inform> B|B] [B<-outform> B|B] -[B<-keyform> B|B|B] -[B<-CAform> B|B] -[B<-CAkeyform> B|B|B] +[B<-keyform> B|B|B|B] +[B<-CAform> B|B|B] +[B<-CAkeyform> B|B|B|B] [B<-in> I] [B<-out> I] [B<-serial>] @@ -100,13 +100,18 @@ various sections. Print out a usage message. -=item B<-inform> B|B, B<-outform> B|B +=item B<-inform> B|B -The input and formats; the default is B. +The CSR input format; the default is B. See L for details. -The input is normally an X.509 certificate, but this can change if other -options such as B<-req> are used. +The input is normally an X.509 certificate file of any format, +but this can change if other options such as B<-req> are used. + +B<-outform> B|B + +The output format; the default is B. +See L for details. =item B<-in> I @@ -355,8 +360,7 @@ can thus behave like a "mini CA". =item B<-signkey> I This option causes the input file to be self signed using the supplied -private key or engine. The private key's format is specified with the -B<-keyform> option. +private key or engine. It sets the issuer name to the subject name (i.e., makes it self-issued) and changes the public key to the supplied value (unless overridden by @@ -392,14 +396,21 @@ certificate is being created from another certificate (for example with the B<-signkey> or the B<-CA> options). Normally all extensions are retained. -=item B<-keyform> B|B|B +=item B<-keyform> B|B|B|B The key format; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. -=item B<-CAform> B|B, B<-CAkeyform> B|B|B +=item B<-CAform> B|B|B, -The format for the CA certificate and key; the default is B. +The format for the CA certificate. +This option has no effect and is retained for backward compatibility. + +=item B<-CAkeyform> B|B|B|B + +The format for the CA key; the default is B. +The only value with effect is B; all others have become obsolete. See L for details. =item B<-days> I @@ -502,8 +513,6 @@ self-signed, for instance when the key cannot be used for signing, such as DH. It can also be used in conjunction with b<-new> and B<-subj> to directly generate a certificate containing any desired public key. -The format of the key file can be specified using the B<-keyform> option. - =item B<-subj> I When a certificate is created set its subject name to the given value. @@ -821,6 +830,11 @@ of the distinguished name. In OpenSSL 1.0.0 and later it is based on a canonical version of the DN using SHA1. This means that any directories using the old form must have their links rebuilt using L or similar. +All B<-keyform> and B<-CAkeyform> values except B +have become obsolete in OpenSSL 3.0.0 and have no effect. + +The B<-CAform> option has become obsolete in OpenSSL 3.0.0 and has no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man1/openssl.pod b/doc/man1/openssl.pod index 9bac3cd4..7170a984 100644 --- a/doc/man1/openssl.pod +++ b/doc/man1/openssl.pod @@ -525,7 +525,12 @@ parameters start with a minus sign: =head2 Format Options Several OpenSSL commands can take input or generate output in a variety -of formats. The list of acceptable formats, and the default, is +of formats. +Since OpenSSL 3.0 keys, single certificates, and CRLs can be read from +files in any of the B, B, or B formats, +while specifying their input format is no more needed. + +The list of acceptable formats, and the default, is described in each command documentation. The list of formats is described below. Both uppercase and lowercase are accepted. @@ -618,6 +623,8 @@ The format of the input or output streams. =item B<-keyform> I Format of a private key input source. +The only value with effect is B; all others have become obsolete. +See L for details. =item B<-CRLform> I @@ -789,12 +796,6 @@ OpenSSL command to generate an alternative chain. =over 4 -=item B<-xchain_build> - -Specify whether the application should build the certificate chain to be -provided to the server for the extra certificates via the B<-xkey>, -B<-xcert>, and B<-xchain> options. - =item B<-xkey> I, B<-xcert> I, B<-xchain> Specify an extra certificate, private key and certificate chain. These behave @@ -802,21 +803,21 @@ in the same manner as the B<-cert>, B<-key> and B<-cert_chain> options. When specified, the callback returning the first valid chain will be in use by the client. -=item B<-xcertform> B|B, B<-xkeyform> B|B - -The input format for the extra certificate and key, respectively. -See L for details. - =item B<-xchain_build> Specify whether the application should build the certificate chain to be provided to the server for the extra certificates via the B<-xkey>, B<-xcert>, and B<-xchain> options. -=item B<-xcertform> B|B, B<-xkeyform> B|B +=item B<-xcertform> B|B|B -The input format for the extra certificate and key, respectively. -See L for details. +The input format for the extra certificate. +This option has no effect and is retained for backward compatibility only. + +=item B<-xkeyform> B|B|B + +The input format for the extra key. +This option has no effect and is retained for backward compatibility only. =back @@ -1124,7 +1125,7 @@ values larger than 127, as described in B. Escapes some characters by surrounding the entire string with quotation marks, C<">. -Without this option, individual special characters are preceeded with +Without this option, individual special characters are preceded with a backslash character, C<\>. =item B @@ -1403,6 +1404,9 @@ manual pages. The B<-issuer_checks> option is deprecated as of OpenSSL 1.1.0 and is silently ignored. +The B<-xcertform> and B<-xkeyform> options +are obsolete since OpenSSL 3.0.0 and have no effect. + =head1 COPYRIGHT Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man3/ASN1_INTEGER_new.pod b/doc/man3/ASN1_INTEGER_new.pod new file mode 100644 index 00000000..4722f880 --- /dev/null +++ b/doc/man3/ASN1_INTEGER_new.pod @@ -0,0 +1,44 @@ +=pod + +=head1 NAME + +ASN1_INTEGER_new, ASN1_INTEGER_free - ASN1_INTEGER allocation functions + +=head1 SYNOPSIS + +=for openssl generic + + #include + + ASN1_INTEGER *ASN1_INTEGER_new(void); + void ASN1_INTEGER_free(ASN1_INTEGER *a); + +=head1 DESCRIPTION + +ASN1_INTEGER_new() returns an allocated B structure. + +ASN1_INTEGER_free() frees up a single B object. + +B structure representing the ASN.1 INTEGER type + +=head1 RETURN VALUES + +ASN1_INTEGER_new() return a valid B structure or NULL +if an error occurred. + +ASN1_INTEGER_free() does not return a value. + +=head1 SEE ALSO + +L + +=head1 COPYRIGHT + +Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/man3/CMS_EnvelopedData_create.pod b/doc/man3/CMS_EnvelopedData_create.pod new file mode 100644 index 00000000..625daa80 --- /dev/null +++ b/doc/man3/CMS_EnvelopedData_create.pod @@ -0,0 +1,52 @@ +=pod + +=head1 NAME + +CMS_EnvelopedData_create - Create CMS envelope + +=head1 SYNOPSIS + + #include + + CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher); + +=head1 DESCRIPTION + +CMS_EnvelopedData_create() creates a B structure with +a type B. B is the symmetric cipher to use. + +The algorithm passed in the B parameter must support ASN1 encoding of +its parameters. + +The recipients can be added later using L or +L. + +The B structure needs to be finalized using L +and then freed using L. + +=head1 NOTES + +Although CMS_EnvelopedData_create() allocates a new B +structure it is usually not used in applications. The wrappers +L and L are often used instead. + +=head1 RETURN VALUES + +If the allocation fails, CMS_EnvelopedData_create() returns NULL and sets +an error code that can be obtained by L. +Otherwise it returns a pointer to the newly allocated structure. + +=head1 SEE ALSO + +L, L, L, L + +=head1 COPYRIGHT + +Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/man3/DEFINE_STACK_OF.pod b/doc/man3/DEFINE_STACK_OF.pod index 4dd3de84..9088dc04 100644 --- a/doc/man3/DEFINE_STACK_OF.pod +++ b/doc/man3/DEFINE_STACK_OF.pod @@ -64,27 +64,31 @@ functions that wrap around the utility B API. In the description here, B> is used as a placeholder for any of the OpenSSL datatypes, such as B. -STACK_OF() returns the name for a stack of the specified B>. -DEFINE_STACK_OF() creates set of functions for a stack of B>. This -will mean that type B> is stored in each stack, the type is referenced by +The STACK_OF() macro returns the name for a stack of the specified B>. +This is an opaque pointer to a structure declaration. +This can be used in every header file that references the stack. +There are several B macros that create static inline functions +for all of the functions described on this page. +This should normally be used in one source file, and the stack manipulation +is wrapped with application-specific functions. + +DEFINE_STACK_OF() creates set of functions for a stack of B> elements. +The type is referenced by B(B>) and each function name begins with B_>. -For example: - - TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); - DEFINE_STACK_OF_CONST() is identical to DEFINE_STACK_OF() except -each element is constant. For example: +each element is constant. + /* DEFINE_STACK_OF(TYPE) */ + TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); + /* DEFINE_STACK_OF_CONST(TYPE) */ const TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); -DEFINE_SPECIAL_STACK_OF() defines a stack of B> but -each function uses B in the function name. For example: +DEFINE_SPECIAL_STACK_OF() and DEFINE_SPECIAL_STACK_OF_CONST() are similar +except B is used in the function names: + /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */ TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx); - -DEFINE_SPECIAL_STACK_OF_CONST() is similar except that each element is -constant: - + /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */ const TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx); B_num>() returns the number of elements in I or -1 if I is @@ -266,7 +270,7 @@ B_reserve>() and B_new_reserve>() were added in OpenSSL =head1 COPYRIGHT -Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/DH_size.pod b/doc/man3/DH_size.pod index 98452524..099c1bad 100644 --- a/doc/man3/DH_size.pod +++ b/doc/man3/DH_size.pod @@ -9,39 +9,39 @@ security bits #include + int DH_bits(const DH *dh); + Deprecated since OpenSSL 3.0, can be hidden entirely by defining B with a suitable version value, see L: int DH_size(const DH *dh); - int DH_bits(const DH *dh); - int DH_security_bits(const DH *dh); =head1 DESCRIPTION -All of the functions described on this page are deprecated. -Applications should instead use L, -L and L. +DH_bits() returns the number of significant bits. + +B and Bp> must not be B. + +The remaining functions described on this page are deprecated. +Applications should instead use L and +L. DH_size() returns the Diffie-Hellman prime size in bytes. It can be used to determine how much memory must be allocated for the shared secret computed by L. -DH_bits() returns the number of significant bits. - -B and Bp> must not be B. - DH_security_bits() returns the number of security bits of the given B key. See L. =head1 RETURN VALUES -DH_size() returns the prime size of Diffie-Hellman in bytes. - DH_bits() returns the number of bits in the key. +DH_size() returns the prime size of Diffie-Hellman in bytes. + DH_security_bits() returns the number of security bits. =head1 SEE ALSO @@ -52,7 +52,7 @@ L =head1 HISTORY -All of these functions were deprecated in OpenSSL 3.0. +The DH_size() and DH_security_bits() functions were deprecated in OpenSSL 3.0. The DH_bits() function was added in OpenSSL 1.1.0. diff --git a/doc/man3/DSA_size.pod b/doc/man3/DSA_size.pod index 2d74eea3..404f1bb2 100644 --- a/doc/man3/DSA_size.pod +++ b/doc/man3/DSA_size.pod @@ -8,19 +8,24 @@ DSA_size, DSA_bits, DSA_security_bits - get DSA signature size, key bits or secu #include + int DSA_bits(const DSA *dsa); + Deprecated since OpenSSL 3.0, can be hidden entirely by defining B with a suitable version value, see L: int DSA_size(const DSA *dsa); - int DSA_bits(const DSA *dsa); + int DSA_security_bits(const DSA *dsa); =head1 DESCRIPTION -All of the functions described on this page are deprecated. -Applications should instead use L, -L and L. +DSA_bits() returns the number of bits in key B: this is the number +of bits in the B

parameter. + +The remaining functions described on this page are deprecated. +Applications should instead use L and +L. DSA_size() returns the maximum size of an ASN.1 encoded DSA signature for key B in bytes. It can be used to determine how much memory must @@ -28,18 +33,15 @@ be allocated for a DSA signature. Bq> must not be B. -DSA_bits() returns the number of bits in key B: this is the number -of bits in the B

parameter. - DSA_security_bits() returns the number of security bits of the given B key. See L. =head1 RETURN VALUES -DSA_size() returns the signature size in bytes. - DSA_bits() returns the number of bits in the key. +DSA_size() returns the signature size in bytes. + =head1 SEE ALSO L, @@ -49,7 +51,7 @@ L, L =head1 HISTORY -All of these functions were deprecated in OpenSSL 3.0. +The DSA_size() and DSA_security_bits() functions were deprecated in OpenSSL 3.0. =head1 COPYRIGHT diff --git a/doc/man3/EC_POINT_add.pod b/doc/man3/EC_POINT_add.pod index 9b71d71f..3ac567f8 100644 --- a/doc/man3/EC_POINT_add.pod +++ b/doc/man3/EC_POINT_add.pod @@ -18,13 +18,15 @@ EC_POINT_add, EC_POINT_dbl, EC_POINT_invert, EC_POINT_is_at_infinity, EC_POINT_i int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx); int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx); - int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, size_t num, - const EC_POINT *p[], const BIGNUM *m[], BN_CTX *ctx); int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); int EC_GROUP_have_precompute_mult(const EC_GROUP *group); + Deprecated since OpenSSL 3.0: + + int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, size_t num, + const EC_POINT *p[], const BIGNUM *m[], BN_CTX *ctx); =head1 DESCRIPTION @@ -43,12 +45,14 @@ The functions EC_POINT_make_affine and EC_POINTs_make_affine force the internal co-ordinate system. In the case of EC_POINTs_make_affine the value B provides the number of points in the array B to be forced. -EC_POINT_mul is a convenient interface to EC_POINTs_mul: it calculates the value generator * B + B * B and stores the result in B. +EC_POINT_mul calculates the value generator * B + B * B and stores the result in B. The value B may be NULL in which case the result is just B * B (variable point multiplication). Alternatively, both B and B may be NULL, and B non-NULL, in which case the result is just generator * B (fixed point multiplication). When performing a single fixed or variable point multiplication, the underlying implementation uses a constant time algorithm, when the input scalar (either B or B) is in the range [0, ec_group_order). +Although deprecated in OpenSSL 3.0 and should no longer be used, EC_POINTs_mul calculates the value generator * B + B * B + ... + B * B. As for EC_POINT_mul the value B may be NULL or B may be zero. When performing a fixed point multiplication (B is non-NULL and B is 0) or a variable point multiplication (B is NULL and B is 1), the underlying implementation uses a constant time algorithm, when the input scalar (either B or B) is in the range [0, ec_group_order). +Modern versions should instead use EC_POINT_mul(), combined (if needed) with EC_POINT_add() in such rare circumstances. The function EC_GROUP_precompute_mult stores multiples of the generator for faster point multiplication, whilst EC_GROUP_have_precompute_mult tests whether precomputation has already been done. See L for information @@ -74,6 +78,10 @@ L, L, L, L, L, L, L +=head1 HISTORY + +EC_POINTs_mul() was deprecated in OpenSSL 3.0. + =head1 COPYRIGHT Copyright 2013-2018 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man3/EVP_DigestInit.pod b/doc/man3/EVP_DigestInit.pod index 6c0f136b..370b685b 100644 --- a/doc/man3/EVP_DigestInit.pod +++ b/doc/man3/EVP_DigestInit.pod @@ -226,7 +226,7 @@ EVP_DigestInit_ex() can be called to initialize a new digest operation. =item EVP_DigestFinalXOF() Interfaces to extendable-output functions, XOFs, such as SHAKE128 and SHAKE256. -It retrieves the digest value from I and places it in I-sized md. +It retrieves the digest value from I and places it in I-sized I. After calling this function no additional calls to EVP_DigestUpdate() can be made, but EVP_DigestInit_ex() can be called to initialize a new operation. diff --git a/doc/man3/EVP_PKEY_fromdata.pod b/doc/man3/EVP_PKEY_fromdata.pod index a1c1ed37..52610938 100644 --- a/doc/man3/EVP_PKEY_fromdata.pod +++ b/doc/man3/EVP_PKEY_fromdata.pod @@ -94,16 +94,16 @@ TODO Write a set of cookbook documents and link to them. * and secure application is expected to use BIGNUMs, and to build * this array dynamically. */ - const unsigned long rsa_n = 0xbc747fc5; - const unsigned long rsa_e = 0x10001; - const unsigned long rsa_d = 0x7b133399; - const OSSL_PARAM[] = { + unsigned long rsa_n = 0xbc747fc5; + unsigned long rsa_e = 0x10001; + unsigned long rsa_d = 0x7b133399; + OSSL_PARAM params[] = { OSSL_PARAM_ulong("n", &rsa_n), OSSL_PARAM_ulong("e", &rsa_e), OSSL_PARAM_ulong("d", &rsa_d), OSSL_PARAM_END }; - + int main() { EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL); diff --git a/doc/man3/EVP_PKEY_new.pod b/doc/man3/EVP_PKEY_new.pod index b3bbe63a..3efab956 100644 --- a/doc/man3/EVP_PKEY_new.pod +++ b/doc/man3/EVP_PKEY_new.pod @@ -5,7 +5,9 @@ EVP_PKEY_new, EVP_PKEY_up_ref, EVP_PKEY_free, +EVP_PKEY_new_raw_private_key_with_libctx, EVP_PKEY_new_raw_private_key, +EVP_PKEY_new_raw_public_key_with_libctx, EVP_PKEY_new_raw_public_key, EVP_PKEY_new_CMAC_key, EVP_PKEY_new_mac_key, @@ -21,8 +23,18 @@ EVP_PKEY_get_raw_public_key int EVP_PKEY_up_ref(EVP_PKEY *key); void EVP_PKEY_free(EVP_PKEY *key); + EVP_PKEY *EVP_PKEY_new_raw_private_key_with_libctx(OPENSSL_CTX *libctx, + const char *keytype, + const char *propq, + const unsigned char *key, + size_t keylen); EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, const unsigned char *key, size_t keylen); + EVP_PKEY *EVP_PKEY_new_raw_public_key_with_libctx(OPENSSL_CTX *libctx, + const char *keytype, + const char *propq, + const unsigned char *key, + size_t keylen); EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, const unsigned char *key, size_t keylen); EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, @@ -46,16 +58,34 @@ EVP_PKEY_up_ref() increments the reference count of B. EVP_PKEY_free() decrements the reference count of B and, if the reference count is zero, frees it up. If B is NULL, nothing is done. -EVP_PKEY_new_raw_private_key() allocates a new B. If B is non-NULL -then the new B structure is associated with the engine B. The -B argument indicates what kind of key this is. The value should be a NID -for a public key algorithm that supports raw private keys, i.e. one of -B, B, B, B, -B, B or B. B points to the -raw private key data for this B which should be of length B. -The length should be appropriate for the type of the key. The public key data -will be automatically derived from the given private key data (if appropriate -for the algorithm type). +EVP_PKEY_new_raw_private_key_with_libctx() allocates a new B. Unless +an engine should be used for the key type, a provider for the key is found using +the library context I and the property query string I. The +I argument indicates what kind of key this is. The value should be a +string for a public key algorithm that supports raw private keys, i.e one of +"POLY1305", "SIPHASH", "X25519", "ED25519", "X448" or "ED448". Note that you may +also use "HMAC" which is not a public key algorithm but is treated as such by +some OpenSSL APIs. You are encouraged to use the EVP_MAC APIs instead for HMAC +(see L). I points to the raw private key data for this +B which should be of length I. The length should be +appropriate for the type of the key. The public key data will be automatically +derived from the given private key data (if appropriate for the algorithm type). + +EVP_PKEY_new_raw_private_key() does the same as +EVP_PKEY_new_raw_private_key_with_libctx() except that the default library +context and default property query are used instead. If B is non-NULL then +the new B structure is associated with the engine B. The B +argument indicates what kind of key this is. The value should be a NID for a +public key algorithm that supports raw private keys, i.e. one of +B, B, B, +B, B or B. As for +EVP_PKEY_new_raw_private_key_with_libctx() you may also use B. + +EVP_PKEY_new_raw_public_key_with_libctx() works in the same way as +EVP_PKEY_new_raw_private_key_with_libctx() except that B points to the raw +public key data. The B structure will be initialised without any +private key information. Algorithm types that support raw public keys are +"X25519", "ED25519", "X448" or "ED448". EVP_PKEY_new_raw_public_key() works in the same way as EVP_PKEY_new_raw_private_key() except that B points to the raw public key @@ -127,6 +157,9 @@ EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(), EVP_PKEY_new_CMAC_key(), EVP_PKEY_new_raw_private_key() and EVP_PKEY_get_raw_public_key() functions were added in OpenSSL 1.1.1. +The EVP_PKEY_new_raw_private_key_with_libctx and +EVP_PKEY_new_raw_public_key_with_libctx functions were added in OpenSSL 3.0. + =head1 COPYRIGHT Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man3/EVP_set_default_properties.pod b/doc/man3/EVP_set_default_properties.pod index 6231fde6..9135742b 100644 --- a/doc/man3/EVP_set_default_properties.pod +++ b/doc/man3/EVP_set_default_properties.pod @@ -2,7 +2,8 @@ =head1 NAME -EVP_set_default_properties +EVP_set_default_properties, EVP_default_properties_enable_fips, +EVP_default_properties_is_fips_enabled - Set default properties for future algorithm fetches =head1 SYNOPSIS @@ -10,6 +11,8 @@ EVP_set_default_properties #include int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq); + int EVP_default_properties_enable_fips(OPENSSL_CTX *libctx, int enable); + int EVP_default_properties_is_fips_enabled(OPENSSL_CTX *libctx); =head1 DESCRIPTION @@ -27,10 +30,22 @@ given with I (NULL signifies the default library context). Any previous default property for the specified library context will be dropped. +EVP_default_properties_enable_fips() sets the 'fips=yes' to be a default property +if I is non zero, otherwise it clears 'fips' from the default property +query for the given I. It merges the fips default property query with any +existing query strings that have been set via EVP_set_default_properties(). + +EVP_default_properties_is_fips_enabled() indicates if 'fips=yes' is a default +property for the given I. + =head1 RETURN VALUES -EVP_set_default_properties() returns 1 on success, or 0 on failure. -The latter adds an error on the error stack. +EVP_set_default_properties() and EVP_default_properties_enable_fips() return 1 +on success, or 0 on failure. An error is placed on the the error stack if a +failure occurs. + +EVP_default_properties_is_fips_enabled() returns 1 if the 'fips=yes' default +property is set for the given I, otherwise it returns 0. =head1 SEE ALSO @@ -42,7 +57,7 @@ The functions described here were added in OpenSSL 3.0. =head1 COPYRIGHT -Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/OSSL_CMP_CTX_new.pod b/doc/man3/OSSL_CMP_CTX_new.pod index 354965b7..c8eacfc3 100644 --- a/doc/man3/OSSL_CMP_CTX_new.pod +++ b/doc/man3/OSSL_CMP_CTX_new.pod @@ -28,7 +28,7 @@ OSSL_CMP_CTX_set0_trustedStore, OSSL_CMP_CTX_get0_trustedStore, OSSL_CMP_CTX_set1_untrusted_certs, OSSL_CMP_CTX_get0_untrusted_certs, -OSSL_CMP_CTX_set1_clCert, +OSSL_CMP_CTX_set1_cert, OSSL_CMP_CTX_set1_pkey, OSSL_CMP_CTX_set1_referenceValue, OSSL_CMP_CTX_set1_secretValue, @@ -102,7 +102,7 @@ OSSL_CMP_CTX_set1_senderNonce STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted_certs(const OSSL_CMP_CTX *ctx); /* client authentication: */ - int OSSL_CMP_CTX_set1_clCert(OSSL_CMP_CTX *ctx, X509 *cert); + int OSSL_CMP_CTX_set1_cert(OSSL_CMP_CTX *ctx, X509 *cert); int OSSL_CMP_CTX_set1_pkey(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey); int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx, const unsigned char *ref, int len); @@ -226,18 +226,18 @@ The following options can be set: =item B - The digest algorithm NID to be used in RFC 4210's MSG_SIG_ALG, - if applicable used for message protection and Proof-of-Possession. + The NID of the digest algorithm to be used in RFC 4210's MSG_SIG_ALG + for signature-based message protection and Proof-of-Possession (POPO). Default is SHA256. - OSSL_CMP_OPT_OWF_ALGNID - The digest algorithm NID to be used as one-way function (OWF) - in RFC 4210's MSG_MAC_ALG, if applicable used for message protection. +=item B + The NID of the digest algorithm to be used as one-way function (OWF) + in RFC 4210's MSG_MAC_ALG for PBM-based message protection. Default is SHA256. - OSSL_CMP_OPT_MAC_ALGNID - The MAC algorithm NID to be used in RFC 4210's MSG_MAC_ALG, - if applicable used for message protection. +=item B + The NID of the MAC algorithm to be used in RFC 4210's MSG_MAC_ALG + for PBM-based message protection. Default is HMAC-SHA1 as per RFC 4210. =item B @@ -403,26 +403,26 @@ parameter the entry is cleared. OSSL_CMP_CTX_get0_trustedStore() returns a pointer to the certificate store containing trusted root CA certificates, which may be empty if unset. -OSSL_CMP_CTX_set1_untrusted_certs() takes over a list of certificates containing -non-trusted intermediate certs used for path construction in authentication -of the CMP server and potentially others (TLS server, newly enrolled cert). +OSSL_CMP_CTX_set1_untrusted_certs() sets up a list of non-trusted certificates +of intermediate CAs that may be useful for path construction when authenticating +the CMP server and when verifying newly enrolled certificates. The reference counts of those certificates handled successfully are increased. OSSL_CMP_CTX_get0_untrusted_certs(OSSL_CMP_CTX *ctx) returns a pointer to the -list of untrusted certs, which my be empty if unset. +list of untrusted certs, which may be empty if unset. -OSSL_CMP_CTX_set1_clCert() sets the client certificate in the given B. -The public key of this B must correspond to +OSSL_CMP_CTX_set1_cert() sets the certificate used for CMP message protection. +The public key of this B must correspond to the private key set via B. When using signature-based protection of CMP request messages this "protection certificate" will be included first in the extraCerts field. -The subject of this B will be used as the "sender" field +The subject of this B will be used as the "sender" field of outgoing CMP messages, with the fallback being the B set via B. The B argument may be NULL to clear the entry. -OSSL_CMP_CTX_set1_pkey() sets the private key corresponding to -the client certificate B set via B. +OSSL_CMP_CTX_set1_pkey() sets the private key corresponding to the +protecting certificate B set via B. This key is used create signature-based protection (protectionAlg = MSG_SIG_ALG) of outgoing messages unless a PBM secret has been set via B. @@ -438,11 +438,11 @@ PBM-based protection takes precedence over signature-based protection. OSSL_CMP_CTX_set1_referenceValue() sets the given referenceValue B with length B in the given B or clears it if the B argument is NULL. According to RFC 4210 section 5.1.1, if no value for the "sender" field in -CMP message headers can be determined (i.e., no B and no B -is given) then the "sender" field will contain the NULL-DN +CMP message headers can be determined (i.e., no protecting certificate B +and no B is given) then the "sender" field will contain the NULL-DN and the senderKID field of the CMP message header must be set. When signature-based protection is used the senderKID will be set to -the subjectKeyIdentifier of the as far as present. +the subjectKeyIdentifier of the protecting B as far as present. If not present or when PBM-based protection is used the B value is taken as the fallback value for the senderKID. @@ -451,7 +451,7 @@ PKIHeader of a request message, i.e. the X509 name of the (CA) server. Setting is overruled by subject of B if set. If neither B nor recipient are set, the recipient of the PKI message is determined in the following order: issuer, issuer of old cert (oldCert), -issuer of client cert (B), else NULL-DN. +issuer of protecting certificate (B), else NULL-DN. When a response is received, its sender must match the recipient of the request. OSSL_CMP_CTX_push0_geninfo_ITAV() adds B to the stack in the B to be @@ -481,7 +481,7 @@ the CertTemplate structure when requesting a new cert. For Key Update Requests see B. This default is used for Initialization Requests (IR) and Certification Requests (CR) only if no SANs are set. The B is also used as the "sender" field for outgoing CMP messages -if no B has been set (e.g., in case requests are protected using PBM). +if no B has been set (e.g., in case requests are protected using PBM). OSSL_CMP_CTX_push1_subjectAltName() adds the given X509 name to the list of alternate names on the certificate template request. This cannot be used if @@ -507,7 +507,7 @@ to the X509_EXTENSIONS of the requested certificate template. OSSL_CMP_CTX_set1_oldCert() sets the old certificate to be updated in Key Update Requests (KUR) or to be revoked in Revocation Requests (RR). -It must be given for RR, else it defaults to B. +It must be given for RR, else it defaults to the protecting B. The B determined in this way, if any, is also used for deriving default subject DN and Subject Alternative Names for IR, CR, and KUR. Its issuer, if any, is used as default recipient in the CMP message header. @@ -608,53 +608,57 @@ All other functions return 1 on success, 0 on error. =head1 EXAMPLES -The following code does an Initialization Request: +The following code omits error handling. - cmp_ctx = OSSL_CMP_CTX_new(); - OSSL_CMP_CTX_set1_server(cmp_ctx, address); - OSSL_CMP_CTX_set1_referenceValue(cmp_ctx, ref, ref_len); - OSSL_CMP_CTX_set1_secretValue(cmp_ctx, sec, sec_len); - OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1); - OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert); - - initialClCert = OSSL_CMP_exec_IR_ses(cmp_ctx); - -The following code does an Initialization Request using an -external identity certificate (RFC 4210, Appendix E.7): - - cmp_ctx = OSSL_CMP_CTX_new(); - OSSL_CMP_CTX_set1_server(cmp_ctx, sname); - OSSL_CMP_CTX_set1_clCert(cmp_ctx, cl_cert); - OSSL_CMP_CTX_set1_pkey(cmp_ctx, pkey); - OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1); - OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert); - - initialClCert = OSSL_CMP_exec_IR_ses(cmp_ctx); - -Here externalCert is an X509 certificate granted to the EE by another CA -which is trusted by the current CA the code will connect to. - - -The following code does a Key Update Request: - - cmp_ctx = OSSL_CMP_CTX_new(); - OSSL_CMP_CTX_set1_server(cmp_ctx, url); - OSSL_CMP_CTX_set1_pkey(cmp_ctx, pkey); - OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1); - OSSL_CMP_CTX_set1_clCert(cmp_ctx, cl_cert); - OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert); - - updatedClCert = OSSL_CMP_exec_KUR_ses(cmp_ctx); - -The following code (which omits error handling) sends a General Message -including, as an example, the id-it-signKeyPairTypes OID and prints info on -the General Response contents. +Set up a CMP client context for sending requests and verifying responses: cmp_ctx = OSSL_CMP_CTX_new(); - OSSL_CMP_CTX_set1_server(cmp_ctx, sname); + OSSL_CMP_CTX_set1_server(cmp_ctx, name_or_address); + OSSL_CMP_CTX_set1_serverPort(cmp_ctx, port_string); + OSSL_CMP_CTX_set1_serverPath(cmp_ctx, path_or_alias); + OSSL_CMP_CTX_set0_trustedStore(cmp_ctx, ts); + +Set up client credentials for password-based protection (PBM): + OSSL_CMP_CTX_set1_referenceValue(cmp_ctx, ref, ref_len); OSSL_CMP_CTX_set1_secretValue(cmp_ctx, sec, sec_len); +Set up the details for certificate requests: + + OSSL_CMP_CTX_set1_subjectName(cmp_ctx, name); + OSSL_CMP_CTX_set0_newPkey(cmp_ctx, 1, initialKey); + +Perform an Initialization Request transaction: + + initialCert = OSSL_CMP_exec_IR_ses(cmp_ctx); + +Reset the transaction state of the CMP context and the credentials: + + OSSL_CMP_CTX_reinit(cmp_ctx); + OSSL_CMP_CTX_set1_referenceValue(cmp_ctx, NULL, 0); + OSSL_CMP_CTX_set1_secretValue(cmp_ctx, NULL, 0); + +Perform a Certification Request transaction, making use of the new credentials: + + OSSL_CMP_CTX_set1_cert(cmp_ctx, initialCert); + OSSL_CMP_CTX_set1_pkey(cmp_ctx, initialKey); + OSSL_CMP_CTX_set0_newPkey(cmp_ctx, 1, curentKey); + currentCert = OSSL_CMP_exec_CR_ses(cmp_ctx); + +Perform a Key Update Request, signed using the cert (and key) to be updated: + + OSSL_CMP_CTX_reinit(cmp_ctx); + OSSL_CMP_CTX_set1_cert(cmp_ctx, currentCert); + OSSL_CMP_CTX_set1_pkey(cmp_ctx, currentKey); + OSSL_CMP_CTX_set0_newPkey(cmp_ctx, 1, updatedKey); + currentCert = OSSL_CMP_exec_KUR_ses(cmp_ctx); + currentKey = updatedKey; + +Perform a General Message transaction including, as an example, +the id-it-signKeyPairTypes OID and prints info on the General Response contents: + + OSSL_CMP_CTX_reinit(cmp_ctx); + ASN1_OBJECT *type = OBJ_txt2obj("1.3.6.1.5.5.7.4.2", 1); OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new(type, NULL); OSSL_CMP_CTX_push0_genm_ITAV(cmp_ctx, itav); diff --git a/doc/man3/OSSL_CMP_MSG_get0_header.pod b/doc/man3/OSSL_CMP_MSG_get0_header.pod index bd51eb55..3ab76c14 100644 --- a/doc/man3/OSSL_CMP_MSG_get0_header.pod +++ b/doc/man3/OSSL_CMP_MSG_get0_header.pod @@ -3,6 +3,7 @@ =head1 NAME OSSL_CMP_MSG_get0_header, +OSSL_CMP_MSG_update_transactionID, d2i_OSSL_CMP_MSG_bio, i2d_OSSL_CMP_MSG_bio - function(s) manipulating CMP messages @@ -12,17 +13,22 @@ i2d_OSSL_CMP_MSG_bio #include OSSL_CMP_PKIHEADER *OSSL_CMP_MSG_get0_header(const OSSL_CMP_MSG *msg); + int OSSL_CMP_MSG_update_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg); OSSL_CMP_MSG *d2i_OSSL_CMP_MSG_bio(BIO *bio, OSSL_CMP_MSG **msg); int i2d_OSSL_CMP_MSG_bio(BIO *bio, const OSSL_CMP_MSG *msg); =head1 DESCRIPTION -OSSL_CMP_MSG_get0_header returns the header of the given CMP message. +OSSL_CMP_MSG_get0_header() returns the header of the given CMP message. -d2i_OSSL_CMP_MSG_bio parses an ASN.1-encoded OSSL_CMP_MSG from the BIO I. +OSSL_CMP_MSG_update_transactionID() updates the transactionID field +in the header of the given message according to the CMP_CTX. +This requires re-protecting the message (if it was protected). + +d2i_OSSL_CMP_MSG_bio() parses an ASN.1-encoded OSSL_CMP_MSG from the BIO I. It assigns a pointer to the new structure to I<*msg> if I is not NULL. -i2d_OSSL_CMP_MSG_bio writes the OSSL_CMP_MSG I in ASN.1 encoding +i2d_OSSL_CMP_MSG_bio() writes the OSSL_CMP_MSG I in ASN.1 encoding to BIO I. =head1 NOTES @@ -36,7 +42,8 @@ or NULL if the respective entry does not exist and on error. d2i_OSSL_CMP_MSG_bio() returns the parsed message or NULL on error. -i2d_OSSL_CMP_MSG_bio() returns 1 on success or 0 on error. +i2d_OSSL_CMP_MSG_bio() and OSSL_CMP_MSG_update_transactionID() +return 1 on success, 0 on error. =head1 HISTORY diff --git a/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod b/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod index f8c58dfc..b760db19 100644 --- a/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod +++ b/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod @@ -17,16 +17,18 @@ OSSL_CRMF_MSG_get_certReqId OSSL_CRMF_CERTTEMPLATE *OSSL_CRMF_MSG_get0_tmpl(const OSSL_CRMF_MSG *crm); ASN1_INTEGER - *OSSL_CRMF_CERTTEMPLATE_get0_serialNumber(OSSL_CRMF_CERTTEMPLATE *tmpl); - X509_NAME *OSSL_CRMF_CERTTEMPLATE_get0_issuer(OSSL_CRMF_CERTTEMPLATE *tmpl); + *OSSL_CRMF_CERTTEMPLATE_get0_serialNumber(const OSSL_CRMF_CERTTEMPLATE *tmpl); + X509_NAME + *OSSL_CRMF_CERTTEMPLATE_get0_issuer(const OSSL_CRMF_CERTTEMPLATE *tmpl); ASN1_INTEGER *OSSL_CRMF_CERTID_get0_serialNumber(const OSSL_CRMF_CERTID *cid); const X509_NAME *OSSL_CRMF_CERTID_get0_issuer(const OSSL_CRMF_CERTID *cid); - X509 *OSSL_CRMF_ENCRYPTEDVALUE_get1_encCert(OSSL_CRMF_ENCRYPTEDVALUE *ecert, - EVP_PKEY *pkey); + X509 + *OSSL_CRMF_ENCRYPTEDVALUE_get1_encCert(const OSSL_CRMF_ENCRYPTEDVALUE *ecert, + EVP_PKEY *pkey); - int OSSL_CRMF_MSG_get_certReqId(OSSL_CRMF_MSG *crm); + int OSSL_CRMF_MSG_get_certReqId(const OSSL_CRMF_MSG *crm); =head1 DESCRIPTION diff --git a/doc/man3/OSSL_HTTP_transfer.pod b/doc/man3/OSSL_HTTP_transfer.pod index 632f48db..e0adb2a1 100644 --- a/doc/man3/OSSL_HTTP_transfer.pod +++ b/doc/man3/OSSL_HTTP_transfer.pod @@ -38,7 +38,7 @@ OSSL_HTTP_parse_url OSSL_HTTP_bio_cb_t bio_update_fn, void *arg, const STACK_OF(CONF_VALUE) *headers, const char *content_type, - ASN1_VALUE *req, const ASN1_ITEM *req_it, + const ASN1_VALUE *req, const ASN1_ITEM *req_it, int maxline, unsigned long max_resp_len, int timeout, const char *expected_ct, const ASN1_ITEM *rsp_it); diff --git a/doc/man3/OSSL_PARAM_int.pod b/doc/man3/OSSL_PARAM_int.pod index 91269068..09215184 100644 --- a/doc/man3/OSSL_PARAM_int.pod +++ b/doc/man3/OSSL_PARAM_int.pod @@ -233,7 +233,9 @@ OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter pointed to by B

. The OCTETs are either stored into B<*val> with a length limit of B or, in the case when B<*val> is B, memory is allocated and -B is ignored. +B is ignored. B<*used_len> is populated with the number of OCTETs +stored. If B is NULL then the OCTETS are not stored, but B<*used_len> is +still populated. If memory is allocated by this function, it must be freed by the caller. OSSL_PARAM_set_octet_string() sets an OCTET string from the parameter diff --git a/doc/man3/OSSL_STORE_LOADER.pod b/doc/man3/OSSL_STORE_LOADER.pod index 101857d5..ad9544eb 100644 --- a/doc/man3/OSSL_STORE_LOADER.pod +++ b/doc/man3/OSSL_STORE_LOADER.pod @@ -4,12 +4,14 @@ OSSL_STORE_LOADER, OSSL_STORE_LOADER_CTX, OSSL_STORE_LOADER_new, OSSL_STORE_LOADER_get0_engine, OSSL_STORE_LOADER_get0_scheme, -OSSL_STORE_LOADER_set_open, OSSL_STORE_LOADER_set_ctrl, -OSSL_STORE_LOADER_set_expect, OSSL_STORE_LOADER_set_find, -OSSL_STORE_LOADER_set_load, OSSL_STORE_LOADER_set_eof, -OSSL_STORE_LOADER_set_error, OSSL_STORE_LOADER_set_close, +OSSL_STORE_LOADER_set_open, OSSL_STORE_LOADER_set_attach, +OSSL_STORE_LOADER_set_ctrl, OSSL_STORE_LOADER_set_expect, +OSSL_STORE_LOADER_set_find, OSSL_STORE_LOADER_set_load, +OSSL_STORE_LOADER_set_eof, OSSL_STORE_LOADER_set_error, +OSSL_STORE_LOADER_set_close, OSSL_STORE_LOADER_free, OSSL_STORE_register_loader, -OSSL_STORE_unregister_loader, OSSL_STORE_open_fn, OSSL_STORE_ctrl_fn, +OSSL_STORE_unregister_loader, +OSSL_STORE_open_fn, OSSL_STORE_attach_fn, OSSL_STORE_ctrl_fn, OSSL_STORE_expect_fn, OSSL_STORE_find_fn, OSSL_STORE_load_fn, OSSL_STORE_eof_fn, OSSL_STORE_error_fn, OSSL_STORE_close_fn - Types and functions to manipulate, register and @@ -35,6 +37,16 @@ unregister STORE loaders for different URI schemes void *ui_data); int OSSL_STORE_LOADER_set_open(OSSL_STORE_LOADER *store_loader, OSSL_STORE_open_fn store_open_function); + typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_attach_fn)(const OSSL_STORE_LOADER + *loader, + BIO *bio, + OPENSSL_CTX *libctx, + const char *propq, + const UI_METHOD + *ui_method, + void *ui_data); + int OSSL_STORE_LOADER_set_attach(OSSL_STORE_LOADER *loader, + OSSL_STORE_attach_fn attach_function); typedef int (*OSSL_STORE_ctrl_fn)(OSSL_STORE_LOADER_CTX *ctx, int cmd, va_list args); int OSSL_STORE_LOADER_set_ctrl(OSSL_STORE_LOADER *store_loader, @@ -99,6 +111,10 @@ initialized, to create a private data store (B, see above), and to return it. If something goes wrong, this function is expected to return NULL. +=item B + +This function takes a B, otherwise works like B. + =item B This function takes a B pointer, a command number @@ -189,6 +205,9 @@ OSSL_STORE_LOADER_get0_scheme() returns the scheme of the B. OSSL_STORE_LOADER_set_open() sets the opener function for the B. +OSSL_STORE_LOADER_set_attach() sets the attacher function for the +B. + OSSL_STORE_LOADER_set_ctrl() sets the control function for the B. @@ -254,7 +273,7 @@ were added in OpenSSL 1.1.1. =head1 COPYRIGHT -Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/OSSL_STORE_attach.pod b/doc/man3/OSSL_STORE_attach.pod new file mode 100644 index 00000000..7df28049 --- /dev/null +++ b/doc/man3/OSSL_STORE_attach.pod @@ -0,0 +1,45 @@ +=pod + +=head1 NAME + +OSSL_STORE_attach - Functions to read objects from a BIO + +=head1 SYNOPSIS + + #include + + OSSL_STORE_CTX *OSSL_STORE_attach(BIO *bio, OPENSSL_CTX *libctx, + const char *scheme, const char *propq, + const UI_METHOD *ui_method, void *ui_data, + OSSL_STORE_post_process_info_fn post_process, + void *post_process_data); + +=head1 DESCRIPTION + +OSSL_STORE_attach() works like L, except it takes a B +I instead of a I, along with a I to determine what loader +should be used to process the data. + +=head1 RETURN VALUES + +OSSL_STORE_attach() returns a pointer to a B on success, or +NULL on failure. + +=head1 SEE ALSO + +L, L + +=head1 HISTORY + +OSSL_STORE_attach() was added in OpenSSL 3.0. + +=head1 COPYRIGHT + +Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/man3/RSA_size.pod b/doc/man3/RSA_size.pod index b2a7c967..a23f51ab 100644 --- a/doc/man3/RSA_size.pod +++ b/doc/man3/RSA_size.pod @@ -8,19 +8,23 @@ RSA_size, RSA_bits, RSA_security_bits - get RSA modulus size or security bits #include + int RSA_bits(const RSA *rsa); + Deprecated since OpenSSL 3.0, can be hidden entirely by defining B with a suitable version value, see L: int RSA_size(const RSA *rsa); - int RSA_bits(const RSA *rsa); - int RSA_security_bits(const RSA *rsa) =head1 DESCRIPTION -All of the functions described on this page are deprecated. +RSA_bits() returns the number of significant bits. + +B and Bn> must not be B. + +The remaining functions described on this page are deprecated. Applications should instead use L, L and L. @@ -28,18 +32,14 @@ RSA_size() returns the RSA modulus size in bytes. It can be used to determine how much memory must be allocated for an RSA encrypted value. -RSA_bits() returns the number of significant bits. - -B and Bn> must not be B. - RSA_security_bits() returns the number of security bits of the given B key. See L. =head1 RETURN VALUES -RSA_size() returns the size of modulus in bytes. +RSA_bits() returns the number of bits in the key. -DSA_bits() returns the number of bits in the key. +RSA_size() returns the size of modulus in bytes. RSA_security_bits() returns the number of security bits. @@ -49,7 +49,7 @@ L =head1 HISTORY -All of these functions were deprecated in OpenSSL 3.0. +The RSA_size() and RSA_security_bits() functions were deprecated in OpenSSL 3.0. The RSA_bits() function was added in OpenSSL 1.1.0. diff --git a/doc/man3/SSL_CONF_cmd.pod b/doc/man3/SSL_CONF_cmd.pod index 73c50da8..b0604493 100644 --- a/doc/man3/SSL_CONF_cmd.pod +++ b/doc/man3/SSL_CONF_cmd.pod @@ -507,6 +507,10 @@ B: use extended master secret extension, enabled by default. Inverse of B: that is, B<-ExtendedMasterSecret> is the same as setting B. +B: use CA names extension, enabled by +default. Inverse of B: that is, +B<-CANames> is the same as setting B. + =item B The B argument is a comma separated list of flags to set. diff --git a/doc/man3/SSL_CTX_config.pod b/doc/man3/SSL_CTX_config.pod index 7aba58f8..8ddb4a97 100644 --- a/doc/man3/SSL_CTX_config.pod +++ b/doc/man3/SSL_CTX_config.pod @@ -80,7 +80,7 @@ The SSL_CTX_config() and SSL_config() functions were added in OpenSSL 1.1.0. =head1 COPYRIGHT -Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/SSL_CTX_set_num_tickets.pod b/doc/man3/SSL_CTX_set_num_tickets.pod index 84afe4ae..aa673bd8 100644 --- a/doc/man3/SSL_CTX_set_num_tickets.pod +++ b/doc/man3/SSL_CTX_set_num_tickets.pod @@ -5,7 +5,8 @@ SSL_set_num_tickets, SSL_get_num_tickets, SSL_CTX_set_num_tickets, -SSL_CTX_get_num_tickets +SSL_CTX_get_num_tickets, +SSL_new_session_ticket - control the number of TLSv1.3 session tickets that are issued =head1 SYNOPSIS @@ -16,6 +17,7 @@ SSL_CTX_get_num_tickets size_t SSL_get_num_tickets(SSL *s); int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets); size_t SSL_CTX_get_num_tickets(SSL_CTX *ctx); + int SSL_new_session_ticket(SSL *s); =head1 DESCRIPTION @@ -40,14 +42,29 @@ handshake then SSL_set_num_tickets() can be called again prior to calling SSL_verify_client_post_handshake() to update the number of tickets that will be sent. +To issue tickets after other events (such as application-layer changes), +SSL_new_session_ticket() is used by a server application to request that a new +ticket be sent when it is safe to do so. New tickets are only allowed to be +sent in this manner after the initial handshake has completed, and only for TLS +1.3 connections. The ticket generation and transmission are delayed until the +server is starting a new write operation, so that it is bundled with other +application data being written and properly aligned to a record boundary. +SSL_new_session_ticket() can be called more than once to request additional +tickets be sent; all such requests are queued and written together when it is +safe to do so. Note that a successful return from SSL_new_session_ticket() +indicates only that the request to send a ticket was processed, not that the +ticket itself was sent. To be notified when the ticket itself is sent, a +new-session callback can be registered with L that +will be invoked as the ticket or tickets are generated. + SSL_CTX_get_num_tickets() and SSL_get_num_tickets() return the number of tickets set by a previous call to SSL_CTX_set_num_tickets() or SSL_set_num_tickets(), or 2 if no such call has been made. =head1 RETURN VALUES -SSL_CTX_set_num_tickets() and SSL_set_num_tickets() return 1 on success or 0 on -failure. +SSL_CTX_set_num_tickets(), SSL_set_num_tickets(), and +SSL_new_session_ticket() return 1 on success or 0 on failure. SSL_CTX_get_num_tickets() and SSL_get_num_tickets() return the number of tickets that have been previously set. @@ -58,11 +75,13 @@ L =head1 HISTORY -These functions were added in OpenSSL 1.1.1. +SSL_new_session_ticket() was added in OpenSSL 3.0.0. +SSL_set_num_tickets(), SSL_get_num_tickets(), SSL_CTX_set_num_tickets(), and +SSL_CTX_get_num_tickets() were added in OpenSSL 1.1.1. =head1 COPYRIGHT -Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/SSL_CTX_set_options.pod b/doc/man3/SSL_CTX_set_options.pod index dd89125d..39cb2ec3 100644 --- a/doc/man3/SSL_CTX_set_options.pod +++ b/doc/man3/SSL_CTX_set_options.pod @@ -67,6 +67,12 @@ The following B options are available: Don't prefer ECDHE-ECDSA ciphers when the client appears to be Safari on OS X. OS X 10.8..10.8.3 has broken support for ECDHE-ECDSA ciphers. +=item SSL_OP_DISABLE_TLSEXT_CA_NAMES + +Disable TLS Extension CA Names. You may want to disable it for security reasons +or for compatibility with some Windows TLS implementations crashing when this +extension is larger than 1024 bytes. + =item SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS Disables a countermeasure against a SSL 3.0/TLS 1.0 protocol @@ -378,7 +384,7 @@ The B option was added in OpenSSL 3.0. =head1 COPYRIGHT -Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/SSL_CTX_set_tlsext_servername_callback.pod b/doc/man3/SSL_CTX_set_tlsext_servername_callback.pod index 374f575b..0c271b1f 100644 --- a/doc/man3/SSL_CTX_set_tlsext_servername_callback.pod +++ b/doc/man3/SSL_CTX_set_tlsext_servername_callback.pod @@ -88,7 +88,7 @@ Otherwise it returns NULL. =item On the client, during or after the handshake and a TLSv1.2 (or below) resumption occurred -If the session from the orignal handshake had a servername accepted by the +If the session from the original handshake had a servername accepted by the server then it will return that servername. Otherwise it returns the servername set via SSL_set_tlsext_host_name() or NULL @@ -157,12 +157,12 @@ corner cases. This has been fixed from OpenSSL 1.1.1e. Prior to 1.1.1e, when the client requested a servername in an initial TLSv1.2 handshake, the server accepted it, and then the client successfully resumed but -set a different explict servername in the second handshake then when called by +set a different explicit servername in the second handshake then when called by the client it returned the servername from the second handshake. This has now been changed to return the servername requested in the original handshake. Also prior to 1.1.1e, if the client sent a servername in the first handshake but -the server did not accept it, and then a second handshake occured where TLSv1.2 +the server did not accept it, and then a second handshake occurred where TLSv1.2 resumption was successful then when called by the server it returned the servername requested in the original handshake. This has now been changed to NULL. diff --git a/doc/man3/SSL_set_async_callback.pod b/doc/man3/SSL_set_async_callback.pod index 3fa05dff..5a0bd2bf 100644 --- a/doc/man3/SSL_set_async_callback.pod +++ b/doc/man3/SSL_set_async_callback.pod @@ -121,9 +121,9 @@ SSL_get_async_status() were first added to OpenSSL 3.0. =head1 COPYRIGHT -Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man3/SSL_shutdown.pod b/doc/man3/SSL_shutdown.pod index 608cd719..25191130 100644 --- a/doc/man3/SSL_shutdown.pod +++ b/doc/man3/SSL_shutdown.pod @@ -75,6 +75,16 @@ state but not actually send the close_notify alert messages, see L. When "quiet shutdown" is enabled, SSL_shutdown() will always succeed and return 1. +Note that this is not standard compliant behaviour. +It should only be done when the peer has a way to make sure all +data has been received and doesn't wait for the close_notify alert +message, otherwise an unexpected EOF will be reported. + +There are implementations that do not send the required close_notify alert. +If there is a need to communicate with such an implementation, and it's clear +that all data has been received, do not wait for the peer's close_notify alert. +Waiting for the close_notify alert when the peer just closes the connection will +result in an error being generated. =head2 First to close the connection @@ -124,8 +134,10 @@ The following return values can occur: The shutdown is not yet finished: the close_notify was sent but the peer did not send it back yet. Call SSL_read() to do a bidirectional shutdown. -The output of L may be misleading, as an -erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred. + +Unlike most other function, returning 0 does not indicate an error. +L should not get called, it may misleadingly +indicate an error even though no error occurred. =item Z<>1 @@ -153,7 +165,7 @@ L, L =head1 COPYRIGHT -Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/X509_STORE_CTX_get_error.pod b/doc/man3/X509_STORE_CTX_get_error.pod index 0c0d01b8..ce69e4da 100644 --- a/doc/man3/X509_STORE_CTX_get_error.pod +++ b/doc/man3/X509_STORE_CTX_get_error.pod @@ -327,7 +327,7 @@ Unhandled critical CRL extension. Invalid non-CA certificate has CA markings. -=item B +=item B Proxy path length constraint exceeded. @@ -340,7 +340,7 @@ certificates. Proxy certificates not allowed unless the B<-allow_proxy_certs> option is used. -=item B +=item B See RFC 3779 for details. @@ -415,7 +415,7 @@ recognized by the OCSP responder. The issuer certificate does not have a public key. -=item B +=item B The issuer's public key is not of the type required by the signature in the subject's certificate. diff --git a/doc/man3/X509_VERIFY_PARAM_set_flags.pod b/doc/man3/X509_VERIFY_PARAM_set_flags.pod index 27e0a739..f34020cb 100644 --- a/doc/man3/X509_VERIFY_PARAM_set_flags.pod +++ b/doc/man3/X509_VERIFY_PARAM_set_flags.pod @@ -10,11 +10,13 @@ X509_VERIFY_PARAM_get_depth, X509_VERIFY_PARAM_set_auth_level, X509_VERIFY_PARAM_get_auth_level, X509_VERIFY_PARAM_set_time, X509_VERIFY_PARAM_get_time, X509_VERIFY_PARAM_add0_policy, X509_VERIFY_PARAM_set1_policies, +X509_VERIFY_PARAM_get0_host, X509_VERIFY_PARAM_set1_host, X509_VERIFY_PARAM_add1_host, X509_VERIFY_PARAM_set_hostflags, X509_VERIFY_PARAM_get_hostflags, X509_VERIFY_PARAM_get0_peername, -X509_VERIFY_PARAM_set1_email, X509_VERIFY_PARAM_set1_ip, +X509_VERIFY_PARAM_get0_email, X509_VERIFY_PARAM_set1_email, +X509_VERIFY_PARAM_set1_ip, X509_VERIFY_PARAM_get1_ip_asc, X509_VERIFY_PARAM_set1_ip_asc - X509 verification parameters @@ -50,6 +52,7 @@ X509_VERIFY_PARAM_set1_ip_asc int auth_level); int X509_VERIFY_PARAM_get_auth_level(const X509_VERIFY_PARAM *param); + char *X509_VERIFY_PARAM_get0_host(X509_VERIFY_PARAM *param, int n); int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, const char *name, size_t namelen); int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, @@ -58,8 +61,10 @@ X509_VERIFY_PARAM_set1_ip_asc unsigned int flags); unsigned int X509_VERIFY_PARAM_get_hostflags(const X509_VERIFY_PARAM *param); char *X509_VERIFY_PARAM_get0_peername(const X509_VERIFY_PARAM *param); + char *X509_VERIFY_PARAM_get0_email(X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, const char *email, size_t emaillen); + char *X509_VERIFY_PARAM_get1_ip_asc(X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, const unsigned char *ip, size_t iplen); int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, const char *ipasc); @@ -128,6 +133,11 @@ Security level 1 requires at least 80-bit-equivalent security and is broadly interoperable, though it will, for example, reject MD5 signatures or RSA keys shorter than 1024 bits. +X509_VERIFY_PARAM_get0_host() returns the Bth expected DNS hostname that has +been set using X509_VERIFY_PARAM_set1_host() or X509_VERIFY_PARAM_add1_host(). +To obtain all names start with B = 0 and increment B as long as no NULL +pointer is returned. + X509_VERIFY_PARAM_set1_host() sets the expected DNS hostname to B clearing any previously specified hostname. If B is NULL, or empty the list of hostnames is cleared, and @@ -177,12 +187,17 @@ string is allocated by the library and is no longer valid once the associated B argument is freed. Applications must not free the return value. +X509_VERIFY_PARAM_get0_email() returns the expected RFC822 email address. + X509_VERIFY_PARAM_set1_email() sets the expected RFC822 email address to B. If B is NUL-terminated, B may be zero, otherwise B must be set to the length of B. When an email address is specified, certificate verification automatically invokes L. +X509_VERIFY_PARAM_get1_ip_asc() returns the expected IP address as a string. +The caller is responsible for freeing it. + X509_VERIFY_PARAM_set1_ip() sets the expected IP address to B. The B argument is in binary format, in network byte-order and B must be set to 4 for IPv4 and 16 for IPv6. When an IP @@ -205,6 +220,10 @@ X509_VERIFY_PARAM_set1_email(), X509_VERIFY_PARAM_set1_ip() and X509_VERIFY_PARAM_set1_ip_asc() return 1 for success and 0 for failure. +X509_VERIFY_PARAM_get0_host(), X509_VERIFY_PARAM_get0_email(), and +X509_VERIFY_PARAM_get1_ip_asc(), return the string pointers pecified above +or NULL if the respective value has not been set or on error. + X509_VERIFY_PARAM_get_flags() returns the current verification flags. X509_VERIFY_PARAM_get_hostflags() returns any current host flags. @@ -374,6 +393,9 @@ and has no effect. The X509_VERIFY_PARAM_get_hostflags() function was added in OpenSSL 1.1.0i. +The X509_VERIFY_PARAM_get0_host(), X509_VERIFY_PARAM_get0_email(), +and X509_VERIFY_PARAM_get1_ip_asc() functions were added in OpenSSL 3.0. + =head1 COPYRIGHT Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved. diff --git a/doc/man3/X509_load_http.pod b/doc/man3/X509_load_http.pod index d30253d5..483597b5 100644 --- a/doc/man3/X509_load_http.pod +++ b/doc/man3/X509_load_http.pod @@ -24,7 +24,7 @@ X509_load_http() and X509_CRL_load_http() loads a certificate or a CRL, respectively, in ASN.1 format using HTTP from the given B. If B is given and B is NULL then this BIO is used instead of an -interal one for connecting, writing the request, and reading the response. +internal one for connecting, writing the request, and reading the response. If both B and B are given (which may be memory BIOs, for instance) then no explicit connection is attempted, B is used for writing the request, and B for reading the response. @@ -36,7 +36,7 @@ while a value < 0 immediately leads to a timeout condition. X509_http_nbio() and X509_CRL_http_nbio() are macros for backward compatibility that have the same effect as the functions above but with infinite timeout -and without the possiblity to specify custom BIOs. +and without the possibility to specify custom BIOs. =head1 RETURN VALUES diff --git a/doc/man3/s2i_ASN1_IA5STRING.pod b/doc/man3/s2i_ASN1_IA5STRING.pod index 08fa984a..e59a8560 100644 --- a/doc/man3/s2i_ASN1_IA5STRING.pod +++ b/doc/man3/s2i_ASN1_IA5STRING.pod @@ -32,7 +32,7 @@ i2s_ASN1_ENUMERATED_TABLE, =head1 DESCRIPTION These functions convert OpenSSL objects to and from their ASN.1/string -representation. This function is used for B extentions. +representation. This function is used for B extensions. =head1 NOTES diff --git a/doc/man7/EVP_KDF-KRB5KDF.pod b/doc/man7/EVP_KDF-KRB5KDF.pod index c75340ac..071cb4e8 100644 --- a/doc/man7/EVP_KDF-KRB5KDF.pod +++ b/doc/man7/EVP_KDF-KRB5KDF.pod @@ -110,7 +110,7 @@ This functionality was added to OpenSSL 3.0. Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man7/EVP_KDF-SSHKDF.pod b/doc/man7/EVP_KDF-SSHKDF.pod index 1f7f3a55..e91858c0 100644 --- a/doc/man7/EVP_KDF-SSHKDF.pod +++ b/doc/man7/EVP_KDF-SSHKDF.pod @@ -148,9 +148,9 @@ L =head1 COPYRIGHT -Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man7/EVP_PKEY-X25519.pod b/doc/man7/EVP_PKEY-X25519.pod index dd3e68f1..58f7525f 100644 --- a/doc/man7/EVP_PKEY-X25519.pod +++ b/doc/man7/EVP_PKEY-X25519.pod @@ -9,12 +9,18 @@ EVP_KEYMGMT-X25519, EVP_KEYMGMT-X448, EVP_KEYMGMT-ED25519, EVP_KEYMGMT-ED448 =head1 DESCRIPTION The B, B, B and B keytypes are -implemented in OpenSSL's default provider. +implemented in OpenSSL's default and FIPS providers. These implementations +support the associated key, containing the public key I and the +private key I. + +In the FIPS provider they are non-approved algorithms and do not have the +"fips=yes" property set. =head2 Common X25519, X448, ED25519 and ED448 parameters -The following Import/Export types are available for the built-in X25519, X448, -ED25519 and X448 algorithms: +In addition to the common parameters that all keytypes should support (see +L), the implementation of these keytypes +support the following. =over 4 diff --git a/doc/man7/provider-base.pod b/doc/man7/provider-base.pod index a52c718e..aefaa408 100644 --- a/doc/man7/provider-base.pod +++ b/doc/man7/provider-base.pod @@ -16,15 +16,15 @@ provider-base */ /* Functions offered by libcrypto to the providers */ - const OSSL_ITEM *core_gettable_params(const OSSL_PROVIDER *prov); - int core_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]); - int core_thread_start(const OSSL_PROVIDER *prov, + const OSSL_ITEM *core_gettable_params(const OSSL_CORE_HANDLE *handle); + int core_get_params(const OSSL_CORE_HANDLE *handle, OSSL_PARAM params[]); + int core_thread_start(const OSSL_CORE_HANDLE *handle, OSSL_thread_stop_handler_fn handfn); - OPENSSL_CTX *core_get_library_context(const OSSL_PROVIDER *prov); - void core_new_error(const OSSL_PROVIDER *prov); - void core_set_error_debug(const OSSL_PROVIDER *prov, + OPENSSL_CORE_CTX *core_get_library_context(const OSSL_CORE_HANDLE *handle); + void core_new_error(const OSSL_CORE_HANDLE *handle); + void core_set_error_debug(const OSSL_CORE_HANDLE *handle, const char *file, int line, const char *func); - void core_vset_error(const OSSL_PROVIDER *prov, + void core_vset_error(const OSSL_CORE_HANDLE *handle, uint32_t reason, const char *fmt, va_list args); /* @@ -52,7 +52,19 @@ provider-base const char *file, int line); int CRYPTO_secure_allocated(const void *ptr); void OPENSSL_cleanse(void *ptr, size_t len); - unsigned char *OPENSSL_hexstr2buf(const char *str, long *len); + + OSSL_CORE_BIO * BIO_new_file(const char *filename, const char *mode) + OSSL_CORE_BIO * BIO_new_membuf(const void *buf, int len) + int BIO_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len, + size_t *bytes_read)) + int BIO_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len, + size_t *written) + int BIO_free(OSSL_CORE_BIO *bio)) + int BIO_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list args) + int BIO_vsnprintf(char *buf, size_t n, const char *fmt, va_list args) + + void self_test_cb(OPENSSL_CORE_CTX *ctx, OSSL_CALLBACK **cb, void **cbarg) + /* Functions offered by the provider to libcrypto */ void provider_teardown(void *provctx); @@ -76,8 +88,8 @@ function pointer from a B element named B. For example, the "function" core_gettable_params() has these: - typedef OSSL_ITEM * - (OSSL_core_gettable_params_fn)(const OSSL_PROVIDER *prov); + typedef OSSL_PARAM * + (OSSL_core_gettable_params_fn)(const OSSL_CORE_HANDLE *handle); static ossl_inline OSSL_NAME_core_gettable_params_fn OSSL_get_core_gettable_params(const OSSL_DISPATCH *opf); @@ -114,7 +126,6 @@ provider): BIO_free OSSL_FUNC_BIO_FREE BIO_vprintf OSSL_FUNC_BIO_VPRINTF OPENSSL_cleanse OSSL_FUNC_OPENSSL_CLEANSE - OPENSSL_hexstr2buf OSSL_FUNC_OPENSSL_HEXSTR2BUF OSSL_SELF_TEST_set_callback OSSL_FUNC_SELF_TEST_CB For I<*out> (the B array passed from the provider to @@ -131,20 +142,20 @@ F): core_gettable_params() returns a constant array of descriptor B, for parameters that core_get_params() can handle. -core_get_params() retrieves I parameters from the core. +core_get_params() retrieves parameters from the core for the given I. See L below for a description of currently known parameters. =for comment core_thread_start() TBA -core_get_library_context() retrieves the library context in which the -B object I is stored. +core_get_library_context() retrieves the library context in which the library +object for the current provider is stored, accessible through the I. This may sometimes be useful if the provider wishes to store a reference to its context in the same library context. core_new_error(), core_set_error_debug() and core_set_error() are building blocks for reporting an error back to the core, with -reference to the provider object I. +reference to the I. =over 4 @@ -188,7 +199,10 @@ BIO_new_file(), BIO_new_mem_buf(), BIO_read_ex(), BIO_free(), BIO_vprintf(), OPENSSL_cleanse(), and OPENSSL_hexstr2buf() correspond exactly to the public functions with the same name. As a matter of fact, the pointers in the B array are -direct pointers to those public functions. +direct pointers to those public functions. Note that the BIO functions take an +B type rather than the standard B type. This is to ensure +that a provider does not mix BIOs from the core with BIOs used on the provider +side (the two are not compatible). OSSL_SELF_TEST_set_callback() is used to set an optional callback that can be passed into a provider. This may be ignored by a provider. @@ -327,7 +341,7 @@ operation C. /* Provider context */ struct prov_ctx_st { - OSSL_PROVIDER *prov; + OSSL_CORE_HANDLE *handle; } /* operation context for the algorithm FOO */ @@ -343,7 +357,7 @@ operation C. if (fooctx != NULL) fooctx->provctx = provctx; else - c_put_error(provctx->prov, E_MALLOC, __FILE__, __LINE__); + c_put_error(provctx->handle, E_MALLOC, __FILE__, __LINE__); return fooctx; } @@ -419,7 +433,7 @@ operation C. { 0, NULL } }; - int OSSL_provider_init(const OSSL_PROVIDER *provider, + int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) @@ -440,9 +454,10 @@ operation C. * ALEA IACTA EST, if the core retrieves the reason table * regardless, that string will be displayed, otherwise not. */ - c_put_error(provider, E_MALLOC, __FILE__, __LINE__); + c_put_error(handle, E_MALLOC, __FILE__, __LINE__); return 0; } + pctx->handle = handle; return 1; } diff --git a/doc/man7/provider-keymgmt.pod b/doc/man7/provider-keymgmt.pod index 0669585b..4202a77b 100644 --- a/doc/man7/provider-keymgmt.pod +++ b/doc/man7/provider-keymgmt.pod @@ -22,8 +22,6 @@ provider-keymgmt - The KEYMGMT library E-E provider functions int OP_keymgmt_gen_set_template(void *genctx, void *template); int OP_keymgmt_gen_set_params(void *genctx, const OSSL_PARAM params[]); const OSSL_PARAM *OP_keymgmt_gen_settable_params(void *provctx); - int OP_keymgmt_gen_get_params(void *genctx, const OSSL_PARAM params[]); - const OSSL_PARAM *OP_keymgmt_gen_gettable_params(void *provctx); void *OP_keymgmt_gen(void *genctx, OSSL_CALLBACK *cb, void *cbarg); void OP_keymgmt_gen_cleanup(void *genctx); @@ -93,8 +91,6 @@ macros in L, as follows: OP_keymgmt_gen_set_template OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE OP_keymgmt_gen_set_params OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS OP_keymgmt_gen_settable_params OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS - OP_keymgmt_gen_get_params OSSL_FUNC_KEYMGMT_GEN_GET_PARAMS - OP_keymgmt_gen_gettable_params OSSL_FUNC_KEYMGMT_GEN_GETTABLE_PARAMS OP_keymgmt_gen OSSL_FUNC_KEYMGMT_GEN OP_keymgmt_gen_cleanup OSSL_FUNC_KEYMGMT_GEN_CLEANUP @@ -213,7 +209,6 @@ OP_keymgmt_free() should free the passed I. OP_keymgmt_gen_init(), OP_keymgmt_gen_set_template(), OP_keymgmt_gen_set_params(), OP_keymgmt_gen_settable_params(), -OP_keymgmt_gen_get_params(), OP_keymgmt_gen_gettable_params(), OP_keymgmt_gen() and OP_keymgmt_gen_cleanup() work together as a more elaborate context based key object constructor. @@ -235,13 +230,6 @@ OP_keymgmt_gen_settable_params() should return a constant array of descriptor B, for parameters that OP_keymgmt_gen_set_params() can handle. -OP_keymgmt_gen_get_params() should extract information data associated -with the key object generation context I. - -OP_keymgmt_gen_gettable_params() should return a constant array of -descriptor B, for parameters that OP_keymgmt_gen_get_params() -can handle. - OP_keymgmt_gen() should perform the key object generation itself, and return the result. The callback I should be called at regular intervals with indications on how the key object generation diff --git a/doc/man7/provider-serializer.pod b/doc/man7/provider-serializer.pod index dfc80312..ad3b5fdd 100644 --- a/doc/man7/provider-serializer.pod +++ b/doc/man7/provider-serializer.pod @@ -28,10 +28,10 @@ Future development will also include deserializing functions. /* Functions to serialize object data */ int OP_serializer_serialize_data(void *ctx, const OSSL_PARAM *data, - BIO *out, + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg); - int OP_serializer_serialize_object(void *ctx, void *obj, BIO *out, + int OP_serializer_serialize_object(void *ctx, void *obj, OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg); @@ -39,11 +39,11 @@ Future development will also include deserializing functions. The SERIALIZER is a generic method to serialize any set of object data in L array form, or any provider side object into -serialized form, and write it to the given BIO. If the caller wants +serialized form, and write it to the given OSSL_CORE_BIO. If the caller wants to get the serialized stream to memory, it should provide a L. -The serializer doesn't need to know more about the B pointer than +The serializer doesn't need to know more about the B pointer than being able to pass it to the appropriate BIO upcalls (see L). @@ -71,7 +71,7 @@ For example, the "function" OP_serializer_serialize_data() has these: typedef int (OSSL_OP_serializer_serialize_data_fn)(void *provctx, const OSSL_PARAM params[], - BIO *out); + OSSL_CORE_BIO *out); static ossl_inline OSSL_OP_serializer_serialize_data_fn OSSL_get_OP_serializer_serialize_data(const OSSL_DISPATCH *opf); @@ -180,11 +180,11 @@ by OP_serializer_set_ctx_params() and OP_serializer_settable_ctx_params(). OP_serializer_serialize_data() should take an array of B, I, and if it contains the data necessary for the object type that the implementation handles, it should output the object in -serialized form to the B. +serialized form to the B. OP_serializer_serialize_object() should take a pointer to an object that it knows intimately, and output that object in serialized form to -the B. The caller I ensure that this function is called +the B. The caller I ensure that this function is called with a pointer that the provider of this function is familiar with. It is not suitable to use with object pointers coming from other providers. diff --git a/doc/man7/provider-signature.pod b/doc/man7/provider-signature.pod index 9396b4a8..45d97e66 100644 --- a/doc/man7/provider-signature.pod +++ b/doc/man7/provider-signature.pod @@ -253,7 +253,7 @@ although this may be ignored by providers. OP_signature_digest_sign_update() provides data to be signed in the I parameter which should be of length I. A previously initialised signature context is passed in the I parameter. This function may be called -multiple times to cummulatively add data to be signed. +multiple times to cumulatively add data to be signed. OP_signature_digest_sign_final() finalises a signature operation previously started through OP_signature_digest_sign_init() and @@ -288,7 +288,7 @@ although this may be ignored by providers. OP_signature_digest_verify_update() provides data to be verified in the I parameter which should be of length I. A previously initialised verification context is passed in the I parameter. This function may be -called multiple times to cummulatively add data to be verified. +called multiple times to cumulatively add data to be verified. OP_signature_digest_verify_final() finalises a verification operation previously started through OP_signature_digest_verify_init() and @@ -347,7 +347,7 @@ By default it retries until a signature is calculated. Setting the value to 0 causes the sign operation to retry, otherwise the sign operation is only tried once and returns whether or not it was successful. -Known answer tests can be performed if the random generator is overriden to +Known answer tests can be performed if the random generator is overridden to supply known values that either pass or fail. =back diff --git a/doc/man7/provider.pod b/doc/man7/provider.pod index f7f6bbe9..581c33b9 100644 --- a/doc/man7/provider.pod +++ b/doc/man7/provider.pod @@ -42,16 +42,15 @@ If it's built-in, the initialization function may have any name. The initialization function must have the following signature: - int NAME(const OSSL_PROVIDER *provider, + int NAME(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx); -I is the OpenSSL library object for the provider, and works +I is the OpenSSL library object for the provider, and works as a handle for everything the OpenSSL libraries need to know about the provider. -For the provider itself, it may hold some interesting information, -and is also passed to some of the functions given in the dispatch -array I. +For the provider itself, it is passed to some of the functions given in the +dispatch array I. I is a dispatch array of base functions offered by the OpenSSL libraries, and the available functions are further described in @@ -288,6 +287,13 @@ Should it be needed (if other providers are loaded and offer implementations of the same algorithms), the property "provider=legacy" can be used as a search criterion for these implementations. +=head2 Null provider + +The null provider is built in as part of the F library. It contains +no algorithms in it at all. When fetching algorithms the default provider will +be automatically loaded if no other provider has been explicitly loaded. To +prevent that from happening you can explicitly load the null provider. + =head1 EXAMPLES =head2 Fetching diff --git a/engines/e_capi.c b/engines/e_capi.c index 74b79e31..4ac55902 100644 --- a/engines/e_capi.c +++ b/engines/e_capi.c @@ -1,5 +1,5 @@ /* - * Copyright 2008-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -31,6 +31,9 @@ # include # include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_NAME) + /* * This module uses several "new" interfaces, among which is * CertGetCertificateContextProperty. CERT_KEY_PROV_INFO_PROP_ID is diff --git a/fuzz/README.md b/fuzz/README.md index eca15886..c8dbf454 100644 --- a/fuzz/README.md +++ b/fuzz/README.md @@ -1,7 +1,10 @@ -# I Can Haz Fuzz? +Fuzzing OpenSSL +=============== + +OpenSSL can use either LibFuzzer or AFL to do fuzzing. LibFuzzer -========= +--------- How to fuzz OpenSSL with [libfuzzer](http://llvm.org/docs/LibFuzzer.html), starting from a vanilla+OpenSSH server Ubuntu install. @@ -68,7 +71,7 @@ prebuilt fuzzer library. This is represented as `$PATH_TO_LIBFUZZER_DIR` below. --debug AFL -=== +--- This is an alternative to using LibFuzzer. @@ -92,7 +95,7 @@ Run one of the fuzzers: Where $FUZZER is one of the executables in `fuzz/`. Reproducing issues -================== +------------------ If a fuzzer generates a reproducible error, you can reproduce the problem using the fuzz/*-test binaries and the file generated by the fuzzer. They binaries @@ -108,7 +111,7 @@ To reproduce the crash you can run: fuzz/$FUZZER-test $file Random numbers -============== +-------------- The client and server fuzzer normally generate random numbers as part of the TLS connection setup. This results in the coverage of the fuzzing corpus changing @@ -127,16 +130,17 @@ the same client hello with the same random number in it, and so the server, as emulated by the file, can be generated for that client hello. Coverage changes -================ +---------------- Since the corpus depends on the default behaviour of the client and the server, changes in what they send by default will have an impact on the coverage. The corpus will need to be updated in that case. Updating the corpus -=================== +------------------- The client and server corpus is generated with multiple config options: + - The options as documented above - Without enable-ec_nistp_64_gcc_128 and without --debug - With no-asm @@ -147,7 +151,7 @@ The libfuzzer merge option is used to add the additional coverage from each config to the minimal set. Minimizing the corpus -===================== +--------------------- When you have gathered corpus data from more than one fuzzer run or for any other reason want to to minimize the data diff --git a/fuzz/asn1.c b/fuzz/asn1.c index 520bcae5..e9abbb34 100644 --- a/fuzz/asn1.c +++ b/fuzz/asn1.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/fuzz/client.c b/fuzz/client.c index 45198977..01bd70a4 100644 --- a/fuzz/client.c +++ b/fuzz/client.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ #include "rand.inc" +DEFINE_STACK_OF(SSL_COMP) + /* unused, to avoid warning. */ static int idx; diff --git a/fuzz/cmp.c b/fuzz/cmp.c index 0088dd94..6883a286 100644 --- a/fuzz/cmp.c +++ b/fuzz/cmp.c @@ -18,6 +18,8 @@ #include "fuzzer.h" #include "rand.inc" +DEFINE_STACK_OF(OSSL_CMP_ITAV) + int FuzzerInitialize(int *argc, char ***argv) { OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); diff --git a/fuzz/server.c b/fuzz/server.c index 335f1f16..f00029b0 100644 --- a/fuzz/server.c +++ b/fuzz/server.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,8 @@ #include "rand.inc" +DEFINE_STACK_OF(SSL_COMP) + static const uint8_t kCertificateDER[] = { 0x30, 0x82, 0x02, 0xff, 0x30, 0x82, 0x01, 0xe7, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00, 0xb1, 0x84, 0xee, 0x34, 0x99, 0x98, 0x76, 0xfb, diff --git a/include/crypto/ecx.h b/include/crypto/ecx.h index 5ee6b8ce..54ce5f2b 100644 --- a/include/crypto/ecx.h +++ b/include/crypto/ecx.h @@ -61,6 +61,7 @@ typedef enum { : EVP_PKEY_ED448))) struct ecx_key_st { + OPENSSL_CTX *libctx; unsigned int haspubkey:1; unsigned char pubkey[MAX_KEYLEN]; unsigned char *privkey; @@ -73,7 +74,7 @@ struct ecx_key_st { typedef struct ecx_key_st ECX_KEY; size_t ecx_key_length(ECX_KEY_TYPE type); -ECX_KEY *ecx_key_new(ECX_KEY_TYPE type, int haspubkey); +ECX_KEY *ecx_key_new(OPENSSL_CTX *libctx, ECX_KEY_TYPE type, int haspubkey); unsigned char *ecx_key_allocate_privkey(ECX_KEY *key); void ecx_key_free(ECX_KEY *key); int ecx_key_up_ref(ECX_KEY *key); @@ -109,6 +110,7 @@ void X448_public_from_private(uint8_t out_public_value[56], const uint8_t private_key[56]); /* Backend support */ +int ecx_public_from_private(ECX_KEY *key); int ecx_key_fromdata(ECX_KEY *ecx, const OSSL_PARAM params[], int include_private); diff --git a/include/crypto/evp.h b/include/crypto/evp.h index 4528af95..ee4b6221 100644 --- a/include/crypto/evp.h +++ b/include/crypto/evp.h @@ -526,7 +526,7 @@ struct evp_pkey_st { int type; int save_type; -# ifndef FIPS_MODE +# ifndef FIPS_MODULE /* * Legacy key "origin" is composed of a pointer to an EVP_PKEY_ASN1_METHOD, * a pointer to a low level key and possibly a pointer to an engine. @@ -557,7 +557,7 @@ struct evp_pkey_st { CRYPTO_RWLOCK *lock; STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ int save_parameters; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE CRYPTO_EX_DATA ex_data; #endif @@ -633,7 +633,7 @@ void evp_app_cleanup_int(void); void *evp_pkey_export_to_provider(EVP_PKEY *pk, OPENSSL_CTX *libctx, EVP_KEYMGMT **keymgmt, const char *propquery); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int evp_pkey_downgrade(EVP_PKEY *pk); void evp_pkey_free_legacy(EVP_PKEY *x); #endif @@ -678,10 +678,6 @@ int evp_keymgmt_gen_set_params(const EVP_KEYMGMT *keymgmt, void *genctx, const OSSL_PARAM params[]); const OSSL_PARAM * evp_keymgmt_gen_settable_params(const EVP_KEYMGMT *keymgmt); -int evp_keymgmt_gen_get_params(const EVP_KEYMGMT *keymgmt, void *genctx, - OSSL_PARAM params[]); -const OSSL_PARAM * -evp_keymgmt_gen_gettable_params(const EVP_KEYMGMT *keymgmt); void *evp_keymgmt_gen(const EVP_KEYMGMT *keymgmt, void *genctx, OSSL_CALLBACK *cb, void *cbarg); void evp_keymgmt_gen_cleanup(const EVP_KEYMGMT *keymgmt, void *genctx); @@ -723,7 +719,7 @@ void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags); const EVP_CIPHER *evp_get_cipherbyname_ex(OPENSSL_CTX *libctx, const char *name); const EVP_MD *evp_get_digestbyname_ex(OPENSSL_CTX *libctx, const char *name); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * Internal helpers for stricter EVP_PKEY_CTX_{set,get}_params(). * @@ -731,7 +727,7 @@ const EVP_MD *evp_get_digestbyname_ex(OPENSSL_CTX *libctx, const char *name); * * In particular they return -2 if any of the params is not supported. * - * They are not available in FIPS_MODE as they depend on + * They are not available in FIPS_MODULE as they depend on * - EVP_PKEY_CTX_{get,set}_params() * - EVP_PKEY_CTX_{gettable,settable}_params() * @@ -741,4 +737,4 @@ int evp_pkey_ctx_get_params_strict(EVP_PKEY_CTX *ctx, OSSL_PARAM *params); EVP_PKEY *evp_pkcs82pkey_int(const PKCS8_PRIV_KEY_INFO *p8, OPENSSL_CTX *libctx, const char *propq); -#endif /* !defined(FIPS_MODE) */ +#endif /* !defined(FIPS_MODULE) */ diff --git a/include/crypto/rsa.h b/include/crypto/rsa.h index 7ce1fdb3..6f32ec42 100644 --- a/include/crypto/rsa.h +++ b/include/crypto/rsa.h @@ -13,7 +13,43 @@ #include #include +typedef struct rsa_pss_params_30_st { + int hash_algorithm_nid; + struct { + int algorithm_nid; /* Currently always NID_mgf1 */ + int hash_algorithm_nid; + } mask_gen; + unsigned int salt_len; + unsigned int trailer_field; +} RSA_PSS_PARAMS_30; + +RSA_PSS_PARAMS_30 *rsa_get0_pss_params_30(RSA *r); +int rsa_pss_params_30_set_defaults(RSA_PSS_PARAMS_30 *rsa_pss_params); +int rsa_pss_params_30_copy(RSA_PSS_PARAMS_30 *to, + const RSA_PSS_PARAMS_30 *from); +int rsa_pss_params_30_is_unrestricted(const RSA_PSS_PARAMS_30 *rsa_pss_params); +int rsa_pss_params_30_set_hashalg(RSA_PSS_PARAMS_30 *rsa_pss_params, + int hashalg_nid); +int rsa_pss_params_30_set_maskgenalg(RSA_PSS_PARAMS_30 *rsa_pss_params, + int maskgenalg_nid); +int rsa_pss_params_30_set_maskgenhashalg(RSA_PSS_PARAMS_30 *rsa_pss_params, + int maskgenhashalg_nid); +int rsa_pss_params_30_set_saltlen(RSA_PSS_PARAMS_30 *rsa_pss_params, + int saltlen); +int rsa_pss_params_30_set_trailerfield(RSA_PSS_PARAMS_30 *rsa_pss_params, + int trailerfield); +int rsa_pss_params_30_hashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params); +int rsa_pss_params_30_maskgenalg(const RSA_PSS_PARAMS_30 *rsa_pss_params); +int rsa_pss_params_30_maskgenhashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params); +int rsa_pss_params_30_saltlen(const RSA_PSS_PARAMS_30 *rsa_pss_params); +int rsa_pss_params_30_trailerfield(const RSA_PSS_PARAMS_30 *rsa_pss_params); + +const char *rsa_mgf_nid2name(int mgf); +int rsa_oaeppss_md2nid(const EVP_MD *md); +const char *rsa_oaeppss_nid2name(int md); + RSA *rsa_new_with_ctx(OPENSSL_CTX *libctx); +OPENSSL_CTX *rsa_get0_libctx(RSA *r); int rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes, const STACK_OF(BIGNUM) *exps, @@ -21,7 +57,13 @@ int rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes, int rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes, STACK_OF(BIGNUM_const) *exps, STACK_OF(BIGNUM_const) *coeffs); + +int rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]); int rsa_fromdata(RSA *rsa, const OSSL_PARAM params[]); +int rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30 *pss, const char *propq, + OSSL_PARAM_BLD *bld, OSSL_PARAM params[]); +int rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30 *pss_params, + const OSSL_PARAM params[], OPENSSL_CTX *libctx); int rsa_padding_check_PKCS1_type_2_TLS(OPENSSL_CTX *ctx, unsigned char *to, size_t tlen, const unsigned char *from, diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h index 615cd21a..b479b58a 100644 --- a/include/internal/cryptlib.h +++ b/include/internal/cryptlib.h @@ -157,7 +157,8 @@ typedef struct ossl_ex_data_global_st { # define OPENSSL_CTX_FIPS_PROV_INDEX 9 # define OPENSSL_CTX_SERIALIZER_STORE_INDEX 10 # define OPENSSL_CTX_SELF_TEST_CB_INDEX 11 -# define OPENSSL_CTX_MAX_INDEXES 12 +# define OPENSSL_CTX_BIO_PROV_INDEX 12 +# define OPENSSL_CTX_MAX_INDEXES 13 typedef struct openssl_ctx_method { void *(*new_func)(OPENSSL_CTX *ctx); @@ -238,5 +239,6 @@ static ossl_inline void ossl_sleep(unsigned long millis) char *sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text, const char *sep, size_t max_len); +char *ipaddr_to_asc(unsigned char *p, int len); #endif diff --git a/include/internal/ffc.h b/include/internal/ffc.h index 8a948066..e4c4dce8 100644 --- a/include/internal/ffc.h +++ b/include/internal/ffc.h @@ -118,9 +118,9 @@ void ffc_params_get_validate_params(const FFC_PARAMS *params, int ffc_params_copy(FFC_PARAMS *dst, const FFC_PARAMS *src); int ffc_params_cmp(const FFC_PARAMS *a, const FFC_PARAMS *b, int ignore_q); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE int ffc_params_print(BIO *bp, const FFC_PARAMS *ffc, int indent); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ int ffc_params_FIPS186_4_generate(OPENSSL_CTX *libctx, FFC_PARAMS *params, diff --git a/include/internal/property.h b/include/internal/property.h index 5e23daba..2b2332b2 100644 --- a/include/internal/property.h +++ b/include/internal/property.h @@ -26,6 +26,8 @@ OSSL_PROPERTY_LIST *ossl_parse_query(OPENSSL_CTX *ctx, const char *s); /* Property checker of query vs definition */ int ossl_property_match_count(const OSSL_PROPERTY_LIST *query, const OSSL_PROPERTY_LIST *defn); +int ossl_property_is_enabled(OPENSSL_CTX *ctx, const char *property_name, + const OSSL_PROPERTY_LIST *prop_list); /* Free a parsed property list */ void ossl_property_free(OSSL_PROPERTY_LIST *p); @@ -43,6 +45,10 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid, const char *prop_query, void **result); int ossl_method_store_set_global_properties(OSSL_METHOD_STORE *store, const char *prop_query); +int ossl_method_store_merge_global_properties(OSSL_METHOD_STORE *store, + const char *prop_query); +int ossl_method_store_global_property_is_enabled(OSSL_METHOD_STORE *store, + const char *prop_name); /* property query cache functions */ int ossl_method_store_cache_get(OSSL_METHOD_STORE *store, int nid, diff --git a/include/internal/sockets.h b/include/internal/sockets.h index e7708516..6d17363d 100644 --- a/include/internal/sockets.h +++ b/include/internal/sockets.h @@ -154,9 +154,9 @@ struct servent *PASCAL getservbyname(const char *, const char *); /* also in apps/include/apps.h */ # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE) -# define openssl_fdset(a,b) FD_SET((unsigned int)a, b) +# define openssl_fdset(a, b) FD_SET((unsigned int)(a), b) # else -# define openssl_fdset(a,b) FD_SET(a, b) +# define openssl_fdset(a, b) FD_SET(a, b) # endif #endif diff --git a/include/internal/thread_once.h b/include/internal/thread_once.h index 177974f0..cbc9cc1e 100644 --- a/include/internal/thread_once.h +++ b/include/internal/thread_once.h @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -15,7 +15,7 @@ * OPENSSL_CTX object. In this way data will get cleaned up correctly when the * module gets unloaded. */ -#if !defined(FIPS_MODE) || defined(ALLOW_RUN_ONCE_IN_FIPS) +#if !defined(FIPS_MODULE) || defined(ALLOW_RUN_ONCE_IN_FIPS) /* * DEFINE_RUN_ONCE: Define an initialiser function that should be run exactly * once. It takes no arguments and returns and int result (1 for success or @@ -143,4 +143,4 @@ # define RUN_ONCE_ALT(once, initalt, init) \ (CRYPTO_THREAD_run_once(once, initalt##_ossl_) ? init##_ossl_ret_ : 0) -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ diff --git a/include/openssl/asn1.h b/include/openssl/asn1.h index f5878127..c9917492 100644 --- a/include/openssl/asn1.h +++ b/include/openssl/asn1.h @@ -119,8 +119,9 @@ extern "C" { # define SMIME_OLDMIME 0x400 # define SMIME_CRLFEOL 0x800 # define SMIME_STREAM 0x1000 - struct X509_algor_st; -DEFINE_STACK_OF(X509_ALGOR) + +/* Stacks for types not otherwise defined in this header */ +DEFINE_OR_DECLARE_STACK_OF(X509_ALGOR) # define ASN1_STRING_FLAG_BITS_LEFT 0x08/* Set if 0x07 has bits left value */ /* @@ -187,15 +188,15 @@ typedef struct ASN1_ENCODING_st { (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) # define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) -typedef struct asn1_string_table_st { +struct asn1_string_table_st { int nid; long minsize; long maxsize; unsigned long mask; unsigned long flags; -} ASN1_STRING_TABLE; +}; -DEFINE_STACK_OF(ASN1_STRING_TABLE) +DEFINE_OR_DECLARE_STACK_OF(ASN1_STRING_TABLE) /* size limits: this stuff is taken straight from RFC2459 */ @@ -419,13 +420,8 @@ typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); ASN1_STRFLGS_DUMP_UNKNOWN | \ ASN1_STRFLGS_DUMP_DER) -DEFINE_STACK_OF(ASN1_INTEGER) -DEFINE_STACK_OF(ASN1_GENERALSTRING) - -DEFINE_STACK_OF(ASN1_UTF8STRING) - -typedef struct asn1_type_st { +struct asn1_type_st { int type; union { char *ptr; @@ -454,9 +450,9 @@ typedef struct asn1_type_st { ASN1_STRING *sequence; ASN1_VALUE *asn1_value; } value; -} ASN1_TYPE; +}; -DEFINE_STACK_OF(ASN1_TYPE) +DEFINE_OR_DECLARE_STACK_OF(ASN1_TYPE) typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY; @@ -510,8 +506,9 @@ int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b); ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t); void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t); +DEFINE_OR_DECLARE_STACK_OF(ASN1_OBJECT) + DECLARE_ASN1_FUNCTIONS(ASN1_OBJECT) -DEFINE_STACK_OF(ASN1_OBJECT) ASN1_STRING *ASN1_STRING_new(void); void ASN1_STRING_free(ASN1_STRING *a); @@ -545,6 +542,8 @@ int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl); int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value, BIT_STRING_BITNAME *tbl); +DEFINE_OR_DECLARE_STACK_OF(ASN1_INTEGER) + DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length); @@ -578,6 +577,8 @@ int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len); +DEFINE_OR_DECLARE_STACK_OF(ASN1_UTF8STRING) + DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) @@ -587,6 +588,8 @@ DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) int UTF8_getc(const unsigned char *str, int len, unsigned long *val); int UTF8_putc(unsigned char *str, int len, unsigned long value); +DEFINE_OR_DECLARE_STACK_OF(ASN1_GENERALSTRING) + DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) diff --git a/include/openssl/asn1t.h b/include/openssl/asn1t.h index 837fd427..286db9e2 100644 --- a/include/openssl/asn1t.h +++ b/include/openssl/asn1t.h @@ -880,7 +880,7 @@ DECLARE_ASN1_ITEM(LONG) DECLARE_ASN1_ITEM(ZLONG) # endif -DEFINE_STACK_OF(ASN1_VALUE) +DEFINE_OR_DECLARE_STACK_OF(ASN1_VALUE) /* Functions used internally by the ASN1 code */ diff --git a/include/openssl/bio.h b/include/openssl/bio.h index edc9fbd6..19f9311c 100644 --- a/include/openssl/bio.h +++ b/include/openssl/bio.h @@ -61,6 +61,7 @@ extern "C" { # ifndef OPENSSL_NO_SCTP # define BIO_TYPE_DGRAM_SCTP (24|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) # endif +# define BIO_TYPE_CORE_TO_PROV (25|BIO_TYPE_FILTER) #define BIO_TYPE_START 128 @@ -286,7 +287,7 @@ int BIO_method_type(const BIO *b); typedef int BIO_info_cb(BIO *, int, int); typedef BIO_info_cb bio_info_cb; /* backward compatibility */ -DEFINE_STACK_OF(BIO) +DEFINE_OR_DECLARE_STACK_OF(BIO) /* Prefix and suffix callback in ASN1 BIO */ typedef int asn1_ps_func (BIO *b, unsigned char **pbuf, int *plen, diff --git a/include/openssl/cmp.h b/include/openssl/cmp.h index 6a5da278..e06fba9b 100644 --- a/include/openssl/cmp.h +++ b/include/openssl/cmp.h @@ -210,21 +210,21 @@ typedef struct ossl_cmp_msg_st OSSL_CMP_MSG; DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_MSG) DECLARE_ASN1_ENCODE_FUNCTIONS(OSSL_CMP_MSG, OSSL_CMP_MSG, OSSL_CMP_MSG) typedef struct ossl_cmp_certstatus_st OSSL_CMP_CERTSTATUS; -DEFINE_STACK_OF(OSSL_CMP_CERTSTATUS) +DEFINE_OR_DECLARE_STACK_OF(OSSL_CMP_CERTSTATUS) typedef struct ossl_cmp_itav_st OSSL_CMP_ITAV; DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_ITAV) -DEFINE_STACK_OF(OSSL_CMP_ITAV) +DEFINE_OR_DECLARE_STACK_OF(OSSL_CMP_ITAV) typedef struct ossl_cmp_revrepcontent_st OSSL_CMP_REVREPCONTENT; typedef struct ossl_cmp_pkisi_st OSSL_CMP_PKISI; DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKISI) DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI) -DEFINE_STACK_OF(OSSL_CMP_PKISI) +DEFINE_OR_DECLARE_STACK_OF(OSSL_CMP_PKISI) typedef struct ossl_cmp_certrepmessage_st OSSL_CMP_CERTREPMESSAGE; -DEFINE_STACK_OF(OSSL_CMP_CERTREPMESSAGE) +DEFINE_OR_DECLARE_STACK_OF(OSSL_CMP_CERTREPMESSAGE) typedef struct ossl_cmp_pollrep_st OSSL_CMP_POLLREP; typedef STACK_OF(OSSL_CMP_POLLREP) OSSL_CMP_POLLREPCONTENT; typedef struct ossl_cmp_certresponse_st OSSL_CMP_CERTRESPONSE; -DEFINE_STACK_OF(OSSL_CMP_CERTRESPONSE) +DEFINE_OR_DECLARE_STACK_OF(OSSL_CMP_CERTRESPONSE) typedef STACK_OF(ASN1_UTF8STRING) OSSL_CMP_PKIFREETEXT; /* @@ -294,7 +294,7 @@ X509_STORE *OSSL_CMP_CTX_get0_trustedStore(const OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_set1_untrusted_certs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *certs); STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted_certs(const OSSL_CMP_CTX *ctx); /* client authentication: */ -int OSSL_CMP_CTX_set1_clCert(OSSL_CMP_CTX *ctx, X509 *cert); +int OSSL_CMP_CTX_set1_cert(OSSL_CMP_CTX *ctx, X509 *cert); int OSSL_CMP_CTX_set1_pkey(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey); int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx, const unsigned char *ref, int len); @@ -310,7 +310,8 @@ int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey); EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv); int OSSL_CMP_CTX_set1_issuer(OSSL_CMP_CTX *ctx, const X509_NAME *name); int OSSL_CMP_CTX_set1_subjectName(OSSL_CMP_CTX *ctx, const X509_NAME *name); -int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx, const GENERAL_NAME *name); +int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx, + const GENERAL_NAME *name); int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts); int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx); int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo); @@ -346,11 +347,13 @@ OSSL_CMP_PKISI * OSSL_CMP_STATUSINFO_new(int status, int fail_info, const char *text); /* from cmp_hdr.c */ -ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_transactionID(const OSSL_CMP_PKIHEADER *hdr); +ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_transactionID(const + OSSL_CMP_PKIHEADER *hdr); ASN1_OCTET_STRING *OSSL_CMP_HDR_get0_recipNonce(const OSSL_CMP_PKIHEADER *hdr); /* from cmp_msg.c */ OSSL_CMP_PKIHEADER *OSSL_CMP_MSG_get0_header(const OSSL_CMP_MSG *msg); +int OSSL_CMP_MSG_update_transactionID(OSSL_CMP_CTX *ctx, OSSL_CMP_MSG *msg); OSSL_CMP_MSG *d2i_OSSL_CMP_MSG_bio(BIO *bio, OSSL_CMP_MSG **msg); int i2d_OSSL_CMP_MSG_bio(BIO *bio, const OSSL_CMP_MSG *msg); @@ -387,7 +390,7 @@ typedef void (*OSSL_CMP_SRV_error_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, const OSSL_CMP_MSG *req, const OSSL_CMP_PKISI *statusInfo, const ASN1_INTEGER *errorCode, - const OSSL_CMP_PKIFREETEXT *errorDetails); + const OSSL_CMP_PKIFREETEXT *errDetails); typedef int (*OSSL_CMP_SRV_certConf_cb_t)(OSSL_CMP_SRV_CTX *srv_ctx, const OSSL_CMP_MSG *req, int certReqId, @@ -418,10 +421,10 @@ X509 *OSSL_CMP_exec_IR_ses(OSSL_CMP_CTX *ctx); X509 *OSSL_CMP_exec_CR_ses(OSSL_CMP_CTX *ctx); X509 *OSSL_CMP_exec_P10CR_ses(OSSL_CMP_CTX *ctx); X509 *OSSL_CMP_exec_KUR_ses(OSSL_CMP_CTX *ctx); -# define OSSL_CMP_IR OSSL_CMP_PKIBODY_IR -# define OSSL_CMP_CR OSSL_CMP_PKIBODY_CR -# define OSSL_CMP_P10CR OSSL_CMP_PKIBODY_P10CR -# define OSSL_CMP_KUR OSSL_CMP_PKIBODY_KUR +# define OSSL_CMP_IR OSSL_CMP_PKIBODY_IR +# define OSSL_CMP_CR OSSL_CMP_PKIBODY_CR +# define OSSL_CMP_P10CR OSSL_CMP_PKIBODY_P10CR +# define OSSL_CMP_KUR OSSL_CMP_PKIBODY_KUR int OSSL_CMP_try_certreq(OSSL_CMP_CTX *ctx, int req_type, int *checkAfter); int OSSL_CMP_certConf_cb(OSSL_CMP_CTX *ctx, X509 *cert, int fail_info, const char **text); diff --git a/include/openssl/cms.h b/include/openssl/cms.h index c7e5abcf..a0f4b6a0 100644 --- a/include/openssl/cms.h +++ b/include/openssl/cms.h @@ -36,10 +36,11 @@ typedef struct CMS_Receipt_st CMS_Receipt; typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey; typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute; -DEFINE_STACK_OF(CMS_SignerInfo) -DEFINE_STACK_OF(CMS_RecipientEncryptedKey) -DEFINE_STACK_OF(CMS_RecipientInfo) -DEFINE_STACK_OF(CMS_RevocationInfoChoice) +DEFINE_OR_DECLARE_STACK_OF(CMS_SignerInfo) +DEFINE_OR_DECLARE_STACK_OF(CMS_RecipientEncryptedKey) +DEFINE_OR_DECLARE_STACK_OF(CMS_RecipientInfo) +DEFINE_OR_DECLARE_STACK_OF(CMS_RevocationInfoChoice) + DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo) DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest) DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo) diff --git a/include/openssl/conf.h b/include/openssl/conf.h index d15d4787..24cdcbb1 100644 --- a/include/openssl/conf.h +++ b/include/openssl/conf.h @@ -33,7 +33,8 @@ typedef struct { char *value; } CONF_VALUE; -DEFINE_STACK_OF(CONF_VALUE) +DEFINE_OR_DECLARE_STACK_OF(CONF_VALUE) + DEFINE_LHASH_OF(CONF_VALUE); struct conf_st; @@ -58,8 +59,8 @@ struct conf_method_st { typedef struct conf_imodule_st CONF_IMODULE; typedef struct conf_module_st CONF_MODULE; -DEFINE_STACK_OF(CONF_MODULE) -DEFINE_STACK_OF(CONF_IMODULE) +STACK_OF(CONF_MODULE); +STACK_OF(CONF_IMODULE); /* DSO module function typedefs */ typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf); diff --git a/include/openssl/core.h b/include/openssl/core.h index 2d653dd6..5eb992a5 100644 --- a/include/openssl/core.h +++ b/include/openssl/core.h @@ -25,6 +25,11 @@ extern "C" { * to communicate data between them. */ +/* Opaque handles to be used with core upcall functions from providers */ +typedef struct ossl_core_handle_st OSSL_CORE_HANDLE; +typedef struct openssl_core_ctx_st OPENSSL_CORE_CTX; +typedef struct ossl_core_bio_st OSSL_CORE_BIO; + /* * Dispatch table element. function_id numbers are defined further down, * see macros with '_FUNC' in their names. @@ -171,7 +176,7 @@ typedef void (*OSSL_thread_stop_handler_fn)(void *arg); * module, that module is not an OpenSSL provider module. */ /*- - * |provider| pointer to opaque type OSSL_PROVIDER. This can be used + * |handle| pointer to opaque type OSSL_CORE_HANDLE. This can be used * together with some functions passed via |in| to query data. * |in| is the array of functions that the Core passes to the provider. * |out| will be the array of base functions that the provider passes @@ -180,7 +185,7 @@ typedef void (*OSSL_thread_stop_handler_fn)(void *arg); * provider needs it. This value is passed to other provider * functions, notably other context constructors. */ -typedef int (OSSL_provider_init_fn)(const OSSL_PROVIDER *provider, +typedef int (OSSL_provider_init_fn)(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx); diff --git a/include/openssl/core_names.h b/include/openssl/core_names.h index 4bc151c1..1bd12248 100644 --- a/include/openssl/core_names.h +++ b/include/openssl/core_names.h @@ -94,6 +94,8 @@ extern "C" { #define OSSL_DIGEST_NAME_SHA2_256 "SHA2-256" #define OSSL_DIGEST_NAME_SHA2_384 "SHA2-384" #define OSSL_DIGEST_NAME_SHA2_512 "SHA2-512" +#define OSSL_DIGEST_NAME_SHA2_512_224 "SHA2-512/224" +#define OSSL_DIGEST_NAME_SHA2_512_256 "SHA2-512/256" #define OSSL_DIGEST_NAME_MD2 "MD2" #define OSSL_DIGEST_NAME_MD4 "MD4" #define OSSL_DIGEST_NAME_MDC2 "MDC2" @@ -180,6 +182,7 @@ extern "C" { #define OSSL_PKEY_PARAM_DIGEST OSSL_ALG_PARAM_DIGEST #define OSSL_PKEY_PARAM_PROPERTIES OSSL_ALG_PARAM_PROPERTIES #define OSSL_PKEY_PARAM_DIGEST_SIZE "digest-size" +#define OSSL_PKEY_PARAM_MASKGENFUNC "mgf" #define OSSL_PKEY_PARAM_MGF1_DIGEST "mgf1-digest" #define OSSL_PKEY_PARAM_MGF1_PROPERTIES "mgf1-properties" @@ -269,8 +272,12 @@ extern "C" { /* Key generation parameters */ -#define OSSL_PKEY_PARAM_RSA_BITS OSSL_PKEY_PARAM_BITS -#define OSSL_PKEY_PARAM_RSA_PRIMES "primes" +#define OSSL_PKEY_PARAM_RSA_BITS OSSL_PKEY_PARAM_BITS +#define OSSL_PKEY_PARAM_RSA_PRIMES "primes" +#define OSSL_PKEY_PARAM_RSA_DIGEST OSSL_PKEY_PARAM_DIGEST +#define OSSL_PKEY_PARAM_RSA_MASKGENFUNC OSSL_PKEY_PARAM_MASKGENFUNC +#define OSSL_PKEY_PARAM_RSA_MGF1_DIGEST OSSL_PKEY_PARAM_MGF1_DIGEST +#define OSSL_PKEY_PARAM_RSA_PSS_SALTLEN "saltlen" /* Key generation parameters */ #define OSSL_PKEY_PARAM_FFC_TYPE "type" @@ -308,7 +315,7 @@ extern "C" { #define OSSL_SIGNATURE_PARAM_PAD_MODE OSSL_PKEY_PARAM_PAD_MODE #define OSSL_SIGNATURE_PARAM_DIGEST OSSL_PKEY_PARAM_DIGEST #define OSSL_SIGNATURE_PARAM_PROPERTIES OSSL_PKEY_PARAM_PROPERTIES -#define OSSL_SIGNATURE_PARAM_PSS_SALTLEN "pss-saltlen" +#define OSSL_SIGNATURE_PARAM_PSS_SALTLEN "saltlen" #define OSSL_SIGNATURE_PARAM_MGF1_DIGEST OSSL_PKEY_PARAM_MGF1_DIGEST #define OSSL_SIGNATURE_PARAM_MGF1_PROPERTIES \ OSSL_PKEY_PARAM_MGF1_PROPERTIES diff --git a/include/openssl/core_numbers.h b/include/openssl/core_numbers.h index aaf281b1..f7025d1c 100644 --- a/include/openssl/core_numbers.h +++ b/include/openssl/core_numbers.h @@ -12,7 +12,6 @@ # include # include -# include # ifdef __cplusplus extern "C" { @@ -60,33 +59,33 @@ extern "C" { /* Functions provided by the Core to the provider, reserved numbers 1-1023 */ # define OSSL_FUNC_CORE_GETTABLE_PARAMS 1 OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, - core_gettable_params,(const OSSL_PROVIDER *prov)) + core_gettable_params,(const OSSL_CORE_HANDLE *prov)) # define OSSL_FUNC_CORE_GET_PARAMS 2 -OSSL_CORE_MAKE_FUNC(int,core_get_params,(const OSSL_PROVIDER *prov, +OSSL_CORE_MAKE_FUNC(int,core_get_params,(const OSSL_CORE_HANDLE *prov, OSSL_PARAM params[])) # define OSSL_FUNC_CORE_THREAD_START 3 -OSSL_CORE_MAKE_FUNC(int,core_thread_start,(const OSSL_PROVIDER *prov, +OSSL_CORE_MAKE_FUNC(int,core_thread_start,(const OSSL_CORE_HANDLE *prov, OSSL_thread_stop_handler_fn handfn)) # define OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT 4 -OSSL_CORE_MAKE_FUNC(OPENSSL_CTX *,core_get_library_context, - (const OSSL_PROVIDER *prov)) +OSSL_CORE_MAKE_FUNC(OPENSSL_CORE_CTX *,core_get_library_context, + (const OSSL_CORE_HANDLE *prov)) # define OSSL_FUNC_CORE_NEW_ERROR 5 -OSSL_CORE_MAKE_FUNC(void,core_new_error,(const OSSL_PROVIDER *prov)) +OSSL_CORE_MAKE_FUNC(void,core_new_error,(const OSSL_CORE_HANDLE *prov)) # define OSSL_FUNC_CORE_SET_ERROR_DEBUG 6 OSSL_CORE_MAKE_FUNC(void,core_set_error_debug, - (const OSSL_PROVIDER *prov, + (const OSSL_CORE_HANDLE *prov, const char *file, int line, const char *func)) # define OSSL_FUNC_CORE_VSET_ERROR 7 OSSL_CORE_MAKE_FUNC(void,core_vset_error, - (const OSSL_PROVIDER *prov, + (const OSSL_CORE_HANDLE *prov, uint32_t reason, const char *fmt, va_list args)) # define OSSL_FUNC_CORE_SET_ERROR_MARK 8 -OSSL_CORE_MAKE_FUNC(int, core_set_error_mark, (const OSSL_PROVIDER *prov)) +OSSL_CORE_MAKE_FUNC(int, core_set_error_mark, (const OSSL_CORE_HANDLE *prov)) # define OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK 9 OSSL_CORE_MAKE_FUNC(int, core_clear_last_error_mark, - (const OSSL_PROVIDER *prov)) + (const OSSL_CORE_HANDLE *prov)) # define OSSL_FUNC_CORE_POP_ERROR_TO_MARK 10 -OSSL_CORE_MAKE_FUNC(int, core_pop_error_to_mark, (const OSSL_PROVIDER *prov)) +OSSL_CORE_MAKE_FUNC(int, core_pop_error_to_mark, (const OSSL_CORE_HANDLE *prov)) /* Memory allocation, freeing, clearing. */ #define OSSL_FUNC_CRYPTO_MALLOC 20 @@ -132,22 +131,26 @@ OSSL_CORE_MAKE_FUNC(void, #define OSSL_FUNC_BIO_NEW_FILE 40 #define OSSL_FUNC_BIO_NEW_MEMBUF 41 #define OSSL_FUNC_BIO_READ_EX 42 -#define OSSL_FUNC_BIO_FREE 43 -#define OSSL_FUNC_BIO_VPRINTF 44 -#define OSSL_FUNC_BIO_VSNPRINTF 45 +#define OSSL_FUNC_BIO_WRITE_EX 43 +#define OSSL_FUNC_BIO_FREE 44 +#define OSSL_FUNC_BIO_VPRINTF 45 +#define OSSL_FUNC_BIO_VSNPRINTF 46 -OSSL_CORE_MAKE_FUNC(BIO *, BIO_new_file, (const char *filename, const char *mode)) -OSSL_CORE_MAKE_FUNC(BIO *, BIO_new_membuf, (const void *buf, int len)) -OSSL_CORE_MAKE_FUNC(int, BIO_read_ex, (BIO *bio, void *data, size_t data_len, - size_t *bytes_read)) -OSSL_CORE_MAKE_FUNC(int, BIO_free, (BIO *bio)) -OSSL_CORE_MAKE_FUNC(int, BIO_vprintf, (BIO *bio, const char *format, +OSSL_CORE_MAKE_FUNC(OSSL_CORE_BIO *, BIO_new_file, (const char *filename, + const char *mode)) +OSSL_CORE_MAKE_FUNC(OSSL_CORE_BIO *, BIO_new_membuf, (const void *buf, int len)) +OSSL_CORE_MAKE_FUNC(int, BIO_read_ex, (OSSL_CORE_BIO *bio, void *data, + size_t data_len, size_t *bytes_read)) +OSSL_CORE_MAKE_FUNC(int, BIO_write_ex, (OSSL_CORE_BIO *bio, const void *data, + size_t data_len, size_t *written)) +OSSL_CORE_MAKE_FUNC(int, BIO_free, (OSSL_CORE_BIO *bio)) +OSSL_CORE_MAKE_FUNC(int, BIO_vprintf, (OSSL_CORE_BIO *bio, const char *format, va_list args)) OSSL_CORE_MAKE_FUNC(int, BIO_vsnprintf, (char *buf, size_t n, const char *fmt, va_list args)) #define OSSL_FUNC_SELF_TEST_CB 100 -OSSL_CORE_MAKE_FUNC(void, self_test_cb, (OPENSSL_CTX *ctx, OSSL_CALLBACK **cb, +OSSL_CORE_MAKE_FUNC(void, self_test_cb, (OPENSSL_CORE_CTX *ctx, OSSL_CALLBACK **cb, void **cbarg)) /* Functions provided by the provider to the Core, reserved numbers 1024-1535 */ @@ -161,7 +164,7 @@ OSSL_CORE_MAKE_FUNC(int,provider_get_params,(void *provctx, OSSL_PARAM params[])) # define OSSL_FUNC_PROVIDER_QUERY_OPERATION 1027 OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation, - (void *provctx, int operation_id, const int *no_store)) + (void *provctx, int operation_id, int *no_store)) # define OSSL_FUNC_PROVIDER_GET_REASON_STRINGS 1028 OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings, (void *provctx)) @@ -392,10 +395,8 @@ OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_new, (void *provctx)) # define OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE 3 # define OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS 4 # define OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS 5 -# define OSSL_FUNC_KEYMGMT_GEN_GET_PARAMS 6 -# define OSSL_FUNC_KEYMGMT_GEN_GETTABLE_PARAMS 7 -# define OSSL_FUNC_KEYMGMT_GEN 8 -# define OSSL_FUNC_KEYMGMT_GEN_CLEANUP 9 +# define OSSL_FUNC_KEYMGMT_GEN 6 +# define OSSL_FUNC_KEYMGMT_GEN_CLEANUP 7 OSSL_CORE_MAKE_FUNC(void *, OP_keymgmt_gen_init, (void *provctx, int selection)) OSSL_CORE_MAKE_FUNC(int, OP_keymgmt_gen_set_template, @@ -526,7 +527,8 @@ OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_keyexch_gettable_ctx_params, # define OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS 24 # define OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS 25 -OSSL_CORE_MAKE_FUNC(void *, OP_signature_newctx, (void *provctx)) +OSSL_CORE_MAKE_FUNC(void *, OP_signature_newctx, (void *provctx, + const char *propq)) OSSL_CORE_MAKE_FUNC(int, OP_signature_sign_init, (void *ctx, void *provkey)) OSSL_CORE_MAKE_FUNC(int, OP_signature_sign, (void *ctx, unsigned char *sig, size_t *siglen, size_t sigsize, @@ -547,8 +549,7 @@ OSSL_CORE_MAKE_FUNC(int, OP_signature_verify_recover, (void *ctx, const unsigned char *sig, size_t siglen)) OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign_init, - (void *ctx, const char *mdname, const char *props, - void *provkey)) + (void *ctx, const char *mdname, void *provkey)) OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign_update, (void *ctx, const unsigned char *data, size_t datalen)) OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign_final, @@ -558,8 +559,7 @@ OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_sign, (void *ctx, unsigned char *sigret, size_t *siglen, size_t sigsize, const unsigned char *tbs, size_t tbslen)) OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_verify_init, - (void *ctx, const char *mdname, const char *props, - void *provkey)) + (void *ctx, const char *mdname, void *provkey)) OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_verify_update, (void *ctx, const unsigned char *data, size_t datalen)) OSSL_CORE_MAKE_FUNC(int, OP_signature_digest_verify_final, @@ -640,10 +640,10 @@ OSSL_CORE_MAKE_FUNC(const OSSL_PARAM *, OP_serializer_settable_ctx_params, (void)) OSSL_CORE_MAKE_FUNC(int, OP_serializer_serialize_data, - (void *ctx, const OSSL_PARAM[], BIO *out, + (void *ctx, const OSSL_PARAM[], OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)) OSSL_CORE_MAKE_FUNC(int, OP_serializer_serialize_object, - (void *ctx, void *obj, BIO *out, + (void *ctx, void *obj, OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg)) # ifdef __cplusplus diff --git a/include/openssl/crmf.h b/include/openssl/crmf.h index 02ed3af7..28eb6825 100644 --- a/include/openssl/crmf.h +++ b/include/openssl/crmf.h @@ -43,7 +43,7 @@ typedef struct ossl_crmf_encryptedvalue_st OSSL_CRMF_ENCRYPTEDVALUE; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCRYPTEDVALUE) typedef struct ossl_crmf_msg_st OSSL_CRMF_MSG; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_MSG) -DEFINE_STACK_OF(OSSL_CRMF_MSG) +DEFINE_OR_DECLARE_STACK_OF(OSSL_CRMF_MSG) typedef struct ossl_crmf_attributetypeandvalue_st OSSL_CRMF_ATTRIBUTETYPEANDVALUE; typedef struct ossl_crmf_pbmparameter_st OSSL_CRMF_PBMPARAMETER; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PBMPARAMETER) @@ -51,7 +51,7 @@ typedef struct ossl_crmf_poposigningkey_st OSSL_CRMF_POPOSIGNINGKEY; typedef struct ossl_crmf_certrequest_st OSSL_CRMF_CERTREQUEST; typedef struct ossl_crmf_certid_st OSSL_CRMF_CERTID; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_CERTID) -DEFINE_STACK_OF(OSSL_CRMF_CERTID) +DEFINE_OR_DECLARE_STACK_OF(OSSL_CRMF_CERTID) typedef struct ossl_crmf_pkipublicationinfo_st OSSL_CRMF_PKIPUBLICATIONINFO; DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PKIPUBLICATIONINFO) diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h index e20d17b5..3cca316c 100644 --- a/include/openssl/crypto.h +++ b/include/openssl/crypto.h @@ -169,7 +169,8 @@ struct crypto_ex_data_st { OPENSSL_CTX *ctx; STACK_OF(void) *sk; }; -DEFINE_STACK_OF(void) + +DEFINE_OR_DECLARE_STACK_OF(void) /* * Per class, we have a STACK of function pointers. @@ -376,9 +377,6 @@ ossl_noreturn void OPENSSL_die(const char *assertion, const char *file, int line int OPENSSL_isservice(void); -int FIPS_mode(void); -int FIPS_mode_set(int r); - void OPENSSL_init(void); # ifdef OPENSSL_SYS_UNIX void OPENSSL_fork_prepare(void); diff --git a/include/openssl/ct.h b/include/openssl/ct.h index c3447004..280f7cee 100644 --- a/include/openssl/ct.h +++ b/include/openssl/ct.h @@ -34,6 +34,9 @@ extern "C" { /* All hashes are SHA256 in v1 of Certificate Transparency */ # define CT_V1_HASHLEN SHA256_DIGEST_LENGTH +DEFINE_OR_DECLARE_STACK_OF(SCT) +DEFINE_OR_DECLARE_STACK_OF(CTLOG) + typedef enum { CT_LOG_ENTRY_TYPE_NOT_SET = -1, CT_LOG_ENTRY_TYPE_X509 = 0, @@ -61,9 +64,6 @@ typedef enum { SCT_VALIDATION_STATUS_UNKNOWN_VERSION } sct_validation_status_t; -DEFINE_STACK_OF(SCT) -DEFINE_STACK_OF(CTLOG) - /****************************************** * CT policy evaluation context functions * ******************************************/ diff --git a/include/openssl/dh.h b/include/openssl/dh.h index 437d3032..4907bc65 100644 --- a/include/openssl/dh.h +++ b/include/openssl/dh.h @@ -146,7 +146,7 @@ DEPRECATEDIN_3_0(DH *DH_new_method(ENGINE *engine)) DH *DH_new(void); void DH_free(DH *dh); int DH_up_ref(DH *dh); -DEPRECATEDIN_3_0(int DH_bits(const DH *dh)) +int DH_bits(const DH *dh); DEPRECATEDIN_3_0(int DH_size(const DH *dh)) DEPRECATEDIN_3_0(int DH_security_bits(const DH *dh)) # ifndef OPENSSL_NO_DEPRECATED_3_0 diff --git a/include/openssl/dsa.h b/include/openssl/dsa.h index 92be4760..a7d32eee 100644 --- a/include/openssl/dsa.h +++ b/include/openssl/dsa.h @@ -114,7 +114,7 @@ void DSA_free(DSA *r); /* "up" the DSA object's reference count */ int DSA_up_ref(DSA *r); DEPRECATEDIN_3_0(int DSA_size(const DSA *)) -DEPRECATEDIN_3_0(int DSA_bits(const DSA *d)) +int DSA_bits(const DSA *d); DEPRECATEDIN_3_0(int DSA_security_bits(const DSA *d)) /* next 4 return -1 on error */ DEPRECATEDIN_3_0(int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, diff --git a/include/openssl/ec.h b/include/openssl/ec.h index 09c3e291..703fc1cd 100644 --- a/include/openssl/ec.h +++ b/include/openssl/ec.h @@ -775,9 +775,10 @@ int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, * \param ctx BN_CTX object (optional) * \return 1 on success and 0 if an error occurred */ -int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, - size_t num, const EC_POINT *p[], const BIGNUM *m[], - BN_CTX *ctx); +DEPRECATEDIN_3_0(int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, + const BIGNUM *n, size_t num, + const EC_POINT *p[], const BIGNUM *m[], + BN_CTX *ctx)) /** Computes r = generator * n + q * m * \param group underlying EC_GROUP object diff --git a/include/openssl/ecerr.h b/include/openssl/ecerr.h index cf845fbb..49adc7c6 100644 --- a/include/openssl/ecerr.h +++ b/include/openssl/ecerr.h @@ -170,6 +170,7 @@ int ERR_load_EC_strings(void); # define EC_F_EC_POINT_IS_AT_INFINITY 0 # define EC_F_EC_POINT_IS_ON_CURVE 0 # define EC_F_EC_POINT_MAKE_AFFINE 0 +# define EC_F_EC_POINT_MUL 0 # define EC_F_EC_POINT_NEW 0 # define EC_F_EC_POINT_OCT2POINT 0 # define EC_F_EC_POINT_POINT2BUF 0 diff --git a/include/openssl/ess.h b/include/openssl/ess.h index c20bf820..17962473 100644 --- a/include/openssl/ess.h +++ b/include/openssl/ess.h @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,16 +19,17 @@ extern "C" { # include # include + typedef struct ESS_issuer_serial ESS_ISSUER_SERIAL; typedef struct ESS_cert_id ESS_CERT_ID; typedef struct ESS_signing_cert ESS_SIGNING_CERT; -DEFINE_STACK_OF(ESS_CERT_ID) +DEFINE_OR_DECLARE_STACK_OF(ESS_CERT_ID) typedef struct ESS_signing_cert_v2_st ESS_SIGNING_CERT_V2; typedef struct ESS_cert_id_v2_st ESS_CERT_ID_V2; -DEFINE_STACK_OF(ESS_CERT_ID_V2) +DEFINE_OR_DECLARE_STACK_OF(ESS_CERT_ID_V2) DECLARE_ASN1_ALLOC_FUNCTIONS(ESS_ISSUER_SERIAL) DECLARE_ASN1_ENCODE_FUNCTIONS_only(ESS_ISSUER_SERIAL, ESS_ISSUER_SERIAL) diff --git a/include/openssl/evp.h b/include/openssl/evp.h index f534b1e7..c4ab7f0f 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -78,6 +78,8 @@ extern "C" { #endif int EVP_set_default_properties(OPENSSL_CTX *libctx, const char *propq); +int EVP_default_properties_is_fips_enabled(OPENSSL_CTX *libctx); +int EVP_default_properties_enable_fips(OPENSSL_CTX *libctx, int enable); # define EVP_PKEY_MO_SIGN 0x0001 # define EVP_PKEY_MO_VERIFY 0x0002 @@ -435,7 +437,7 @@ typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass, # ifndef OPENSSL_NO_RSA # define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ - (rsa)) + (rsa)) # endif # ifndef OPENSSL_NO_DSA @@ -1517,9 +1519,19 @@ void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen); EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, int keylen); +EVP_PKEY *EVP_PKEY_new_raw_private_key_with_libctx(OPENSSL_CTX *libctx, + const char *keytype, + const char *propq, + const unsigned char *priv, + size_t len); EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, const unsigned char *priv, size_t len); +EVP_PKEY *EVP_PKEY_new_raw_public_key_with_libctx(OPENSSL_CTX *libctx, + const char *keytype, + const char *propq, + const unsigned char *pub, + size_t len); EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, const unsigned char *pub, size_t len); diff --git a/include/openssl/evperr.h b/include/openssl/evperr.h index 9290cfff..a18b30e4 100644 --- a/include/openssl/evperr.h +++ b/include/openssl/evperr.h @@ -10,6 +10,7 @@ #ifndef OPENSSL_EVPERR_H # define OPENSSL_EVPERR_H +# pragma once # include # include @@ -223,6 +224,7 @@ int ERR_load_EVP_strings(void); # define EVP_R_NO_KEYMGMT_PRESENT 196 # define EVP_R_NO_KEY_SET 154 # define EVP_R_NO_OPERATION_SET 149 +# define EVP_R_NULL_MAC_PKEY_CTX 208 # define EVP_R_ONLY_ONESHOT_SUPPORTED 177 # define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 150 # define EVP_R_OPERATON_NOT_INITIALIZED 151 @@ -233,6 +235,7 @@ int ERR_load_EVP_strings(void); # define EVP_R_PRIVATE_KEY_DECODE_ERROR 145 # define EVP_R_PRIVATE_KEY_ENCODE_ERROR 146 # define EVP_R_PUBLIC_KEY_NOT_RSA 106 +# define EVP_R_SET_DEFAULT_PROPERTY_FAILURE 209 # define EVP_R_TOO_MANY_RECORDS 183 # define EVP_R_UNKNOWN_CIPHER 160 # define EVP_R_UNKNOWN_DIGEST 161 diff --git a/include/openssl/http.h b/include/openssl/http.h index 4dff0088..45c8f11d 100644 --- a/include/openssl/http.h +++ b/include/openssl/http.h @@ -56,7 +56,7 @@ ASN1_VALUE *OSSL_HTTP_post_asn1(const char *server, const char *port, OSSL_HTTP_bio_cb_t bio_update_fn, void *arg, const STACK_OF(CONF_VALUE) *headers, const char *content_type, - ASN1_VALUE *req, const ASN1_ITEM *req_it, + const ASN1_VALUE *req, const ASN1_ITEM *req_it, int maxline, unsigned long max_resp_len, int timeout, const char *expected_ct, const ASN1_ITEM *rsp_it); diff --git a/include/openssl/ocsp.h b/include/openssl/ocsp.h index b9f55c01..d5ccff0e 100644 --- a/include/openssl/ocsp.h +++ b/include/openssl/ocsp.h @@ -103,17 +103,14 @@ extern "C" { # define OCSP_NOTIME 0x800 typedef struct ocsp_cert_id_st OCSP_CERTID; - -DEFINE_STACK_OF(OCSP_CERTID) - typedef struct ocsp_one_request_st OCSP_ONEREQ; - -DEFINE_STACK_OF(OCSP_ONEREQ) - typedef struct ocsp_req_info_st OCSP_REQINFO; typedef struct ocsp_signature_st OCSP_SIGNATURE; typedef struct ocsp_request_st OCSP_REQUEST; +DEFINE_OR_DECLARE_STACK_OF(OCSP_CERTID) +DEFINE_OR_DECLARE_STACK_OF(OCSP_ONEREQ) + # define OCSP_RESPONSE_STATUS_SUCCESSFUL 0 # define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 # define OCSP_RESPONSE_STATUS_INTERNALERROR 2 @@ -126,7 +123,7 @@ typedef struct ocsp_resp_bytes_st OCSP_RESPBYTES; # define V_OCSP_RESPID_NAME 0 # define V_OCSP_RESPID_KEY 1 -DEFINE_STACK_OF(OCSP_RESPID) +DEFINE_OR_DECLARE_STACK_OF(OCSP_RESPID) typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO; @@ -137,7 +134,7 @@ typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO; typedef struct ocsp_cert_status_st OCSP_CERTSTATUS; typedef struct ocsp_single_response_st OCSP_SINGLERESP; -DEFINE_STACK_OF(OCSP_SINGLERESP) +DEFINE_OR_DECLARE_STACK_OF(OCSP_SINGLERESP) typedef struct ocsp_response_data_st OCSP_RESPDATA; diff --git a/include/openssl/opensslv.h.in b/include/openssl/opensslv.h.in index ffd2bfff..3f47a2ac 100644 --- a/include/openssl/opensslv.h.in +++ b/include/openssl/opensslv.h.in @@ -1,7 +1,7 @@ /* * {- join("\n * ", @autowarntext) -} * - * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -91,9 +91,9 @@ extern "C" { /* Synthesize OPENSSL_VERSION_NUMBER with the layout 0xMNN00PPSL */ # ifdef OPENSSL_VERSION_PRE_RELEASE -# define _OPENSSL_VERSION_PRE_RELEASE 0x0 +# define _OPENSSL_VERSION_PRE_RELEASE 0x0L # else -# define _OPENSSL_VERSION_PRE_RELEASE 0xf +# define _OPENSSL_VERSION_PRE_RELEASE 0xfL # endif # define OPENSSL_VERSION_NUMBER \ ( (OPENSSL_VERSION_MAJOR<<28) \ diff --git a/include/openssl/pkcs12.h b/include/openssl/pkcs12.h index 51d6e8a4..abf124f2 100644 --- a/include/openssl/pkcs12.h +++ b/include/openssl/pkcs12.h @@ -1,5 +1,5 @@ /* - * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -52,7 +52,7 @@ typedef struct PKCS12_st PKCS12; typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG; -DEFINE_STACK_OF(PKCS12_SAFEBAG) +DEFINE_OR_DECLARE_STACK_OF(PKCS12_SAFEBAG) typedef struct pkcs12_bag_st PKCS12_BAGS; diff --git a/include/openssl/pkcs7.h b/include/openssl/pkcs7.h index 7c079a2e..0e1c5003 100644 --- a/include/openssl/pkcs7.h +++ b/include/openssl/pkcs7.h @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -28,6 +28,7 @@ extern "C" { #endif + /*- Encryption_ID DES-CBC Digest_ID MD5 @@ -51,8 +52,7 @@ typedef struct pkcs7_signer_info_st { /* The private key to sign with */ EVP_PKEY *pkey; } PKCS7_SIGNER_INFO; - -DEFINE_STACK_OF(PKCS7_SIGNER_INFO) +DEFINE_OR_DECLARE_STACK_OF(PKCS7_SIGNER_INFO) typedef struct pkcs7_recip_info_st { ASN1_INTEGER *version; /* version 0 */ @@ -61,8 +61,8 @@ typedef struct pkcs7_recip_info_st { ASN1_OCTET_STRING *enc_key; X509 *cert; /* get the pub-key from this */ } PKCS7_RECIP_INFO; +DEFINE_OR_DECLARE_STACK_OF(PKCS7_RECIP_INFO) -DEFINE_STACK_OF(PKCS7_RECIP_INFO) typedef struct pkcs7_signed_st { ASN1_INTEGER *version; /* version 1 */ @@ -148,8 +148,8 @@ typedef struct pkcs7_st { ASN1_TYPE *other; } d; } PKCS7; +DEFINE_OR_DECLARE_STACK_OF(PKCS7) -DEFINE_STACK_OF(PKCS7) # define PKCS7_OP_SET_DETACHED_SIGNATURE 1 # define PKCS7_OP_GET_DETACHED_SIGNATURE 2 diff --git a/include/openssl/rsa.h b/include/openssl/rsa.h index ee4c5212..45040e68 100644 --- a/include/openssl/rsa.h +++ b/include/openssl/rsa.h @@ -100,6 +100,24 @@ extern "C" { # define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME # endif +/*- + * New with 3.0: use part of the flags to denote exact type of RSA key, + * some of which are limited to specific signature and encryption schemes. + * These different types share the same RSA structure, but indicate the + * use of certain fields in that structure. + * Currently known are: + * RSA - this is the "normal" unlimited RSA structure (typenum 0) + * RSASSA-PSS - indicates that the PSS parameters are used. + * RSAES-OAEP - no specific field used for the moment, but OAEP padding + * is expected. (currently unused) + * + * 4 bits allow for 16 types + */ +# define RSA_FLAG_TYPE_MASK 0xF000 +# define RSA_FLAG_TYPE_RSA 0x0000 +# define RSA_FLAG_TYPE_RSASSAPSS 0x1000 +# define RSA_FLAG_TYPE_RSAESOAEP 0x2000 + int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad_mode); int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX *ctx, int *pad_mode); @@ -109,6 +127,7 @@ int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen); int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX *ctx, int bits); int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp); int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX *ctx, int primes); +int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, int saltlen); /* Salt length matches digest */ # define RSA_PSS_SALTLEN_DIGEST -1 @@ -119,21 +138,15 @@ int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX *ctx, int primes); /* Old compatible max salt length for sign only */ # define RSA_PSS_SALTLEN_MAX_SIGN -2 -# define EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(ctx, len) \ - EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \ - EVP_PKEY_CTRL_RSA_PSS_SALTLEN, len, NULL) - int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, const char *mdname, const char *mdprops); int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD **md); int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX *ctx, char *name, size_t namelen); - - -# define EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(ctx, md) \ - EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \ - EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md)) +int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); +int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name(EVP_PKEY_CTX *ctx, + const char *mdname); int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); int EVP_PKEY_CTX_set_rsa_oaep_md_name(EVP_PKEY_CTX *ctx, const char *mdname, diff --git a/include/openssl/safestack.h b/include/openssl/safestack.h index b8de23cf..c94ce78c 100644 --- a/include/openssl/safestack.h +++ b/include/openssl/safestack.h @@ -1,5 +1,5 @@ /* - * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -132,11 +132,11 @@ extern "C" { return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \ } -# define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2) # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t) +# define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t) +# define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2) # define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \ SKM_DEFINE_STACK_OF(t1, const t2, t2) -# define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t) /*- * Strings are special: normally an lhash entry will point to a single @@ -155,6 +155,28 @@ extern "C" { typedef char *OPENSSL_STRING; typedef const char *OPENSSL_CSTRING; +# define DEFINE_STACK_OF_STRING() \ + DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char) +# define DEFINE_STACK_OF_CSTRING() \ + DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char) + +/* + * If we're building OpenSSL, or we have no-deprecated configured, + * then we don't define the inline functions (see |SKM_DEFINE_STACK_OF|, + * above), we just declare the stack datatypes. Otherwise, for compatibility + * and to not remove the API's, we define the functions. We have the + * trailing semicolon so that uses of this never need it. + */ +#if defined(OPENSSL_BUILDING_OPENSSL) || defined(OPENSSL_NO_DEPRECATED_3_0) +# define DEFINE_OR_DECLARE_STACK_OF(s) STACK_OF(s); +# define DEFINE_OR_DECLARE_STACK_OF_STRING() STACK_OF(OPENSSL_STRING); +# define DEFINE_OR_DECLARE_STACK_OF_CSTRING() STACK_OF(OPENSSL_CSTRING); +#else +# define DEFINE_OR_DECLARE_STACK_OF(s) DEFINE_STACK_OF(s) +# define DEFINE_OR_DECLARE_STACK_OF_STRING() DEFINE_STACK_OF_STRING() +# define DEFINE_OR_DECLARE_STACK_OF_CSTRING() DEFINE_STACK_OF_CSTRING() +#endif + /*- * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned @@ -162,15 +184,17 @@ typedef const char *OPENSSL_CSTRING; * chars. So, we have to implement STRING specially for STACK_OF. This is * dealt with in the autogenerated macros below. */ -DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char) -DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char) +DEFINE_OR_DECLARE_STACK_OF_STRING() +DEFINE_OR_DECLARE_STACK_OF_CSTRING() +#if !defined(OPENSSL_NO_DEPRECATED_3_0) /* - * Similarly, we sometimes use a block of characters, NOT nul-terminated. + * This is not used by OpenSSL. A block of bytes, NOT nul-terminated. * These should also be distinguished from "normal" stacks. */ typedef void *OPENSSL_BLOCK; DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void) +#endif /* * If called without higher optimization (min. -xO3) the Oracle Developer diff --git a/include/openssl/self_test.h b/include/openssl/self_test.h index bfc459e0..ff6e1b8e 100644 --- a/include/openssl/self_test.h +++ b/include/openssl/self_test.h @@ -1,7 +1,7 @@ /* * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/include/openssl/srp.h b/include/openssl/srp.h index 56d294b7..5c8f5368 100644 --- a/include/openssl/srp.h +++ b/include/openssl/srp.h @@ -37,9 +37,7 @@ typedef struct SRP_gN_cache_st { char *b64_bn; BIGNUM *bn; } SRP_gN_cache; - - -DEFINE_STACK_OF(SRP_gN_cache) +DEFINE_OR_DECLARE_STACK_OF(SRP_gN_cache) typedef struct SRP_user_pwd_st { /* Owned by us. */ @@ -52,6 +50,7 @@ typedef struct SRP_user_pwd_st { /* Owned by us. */ char *info; } SRP_user_pwd; +DEFINE_OR_DECLARE_STACK_OF(SRP_user_pwd) SRP_user_pwd *SRP_user_pwd_new(void); void SRP_user_pwd_free(SRP_user_pwd *user_pwd); @@ -60,8 +59,6 @@ void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g, const BIGNUM * int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id, const char *info); int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v); -DEFINE_STACK_OF(SRP_user_pwd) - typedef struct SRP_VBASE_st { STACK_OF(SRP_user_pwd) *users_pwd; STACK_OF(SRP_gN_cache) *gN_cache; @@ -79,8 +76,7 @@ typedef struct SRP_gN_st { const BIGNUM *g; const BIGNUM *N; } SRP_gN; - -DEFINE_STACK_OF(SRP_gN) +DEFINE_OR_DECLARE_STACK_OF(SRP_gN) SRP_VBASE *SRP_VBASE_new(char *seed_key); void SRP_VBASE_free(SRP_VBASE *vb); diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h index 348f24f8..3572f74d 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h @@ -239,8 +239,8 @@ typedef struct srtp_protection_profile_st { const char *name; unsigned long id; } SRTP_PROTECTION_PROFILE; +DEFINE_OR_DECLARE_STACK_OF(SRTP_PROTECTION_PROFILE) -DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE) typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data, int len, void *arg); @@ -332,9 +332,10 @@ typedef int (*SSL_async_callback_fn)(SSL *s, void *arg); /* * Reserved value (until OpenSSL 3.0.0) 0x00000080U * Reserved value (until OpenSSL 3.0.0) 0x00000100U - * Reserved value (until OpenSSL 3.0.0) 0x00000200U */ +# define SSL_OP_DISABLE_TLSEXT_CA_NAMES 0x00000200U + /* In TLSv1.3 allow a non-(ec)dhe based kex_mode */ # define SSL_OP_ALLOW_NO_DHE_KEX 0x00000400U @@ -980,8 +981,8 @@ extern "C" { * These need to be after the above set of includes due to a compiler bug * in VisualStudio 2015 */ -DEFINE_STACK_OF_CONST(SSL_CIPHER) -DEFINE_STACK_OF(SSL_COMP) +DEFINE_OR_DECLARE_STACK_OF(SSL_CIPHER) +DEFINE_OR_DECLARE_STACK_OF(SSL_COMP) /* compatibility */ # define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)(arg))) @@ -1418,7 +1419,7 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION) # define SSL_get1_groups(s, glist) \ SSL_ctrl(s,SSL_CTRL_GET_GROUPS,0,(int*)(glist)) # define SSL_CTX_set1_groups(ctx, glist, glistlen) \ - SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist)) + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(int *)(glist)) # define SSL_CTX_set1_groups_list(ctx, s) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(s)) # define SSL_set1_groups(s, glist, glistlen) \ @@ -1961,6 +1962,7 @@ int SSL_get_key_update_type(const SSL *s); int SSL_renegotiate(SSL *s); int SSL_renegotiate_abbreviated(SSL *s); __owur int SSL_renegotiate_pending(const SSL *s); +int SSL_new_session_ticket(SSL *s); int SSL_shutdown(SSL *s); __owur int SSL_verify_client_post_handshake(SSL *s); void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val); diff --git a/include/openssl/store.h b/include/openssl/store.h index 7b2561c2..ffea2df1 100644 --- a/include/openssl/store.h +++ b/include/openssl/store.h @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -102,6 +102,24 @@ int OSSL_STORE_error(OSSL_STORE_CTX *ctx); */ int OSSL_STORE_close(OSSL_STORE_CTX *ctx); +/* + * Attach to a BIO. This works like OSSL_STORE_open() except it takes a + * BIO instead of a uri, along with a scheme to use when reading. + * The given UI method will be used any time the loader needs extra input, + * for example when a password or pin is needed, and will be passed the + * same user data every time it's needed in this context. + * + * Returns a context reference which represents the channel to communicate + * through. + * + * Note that this function is considered unsafe, all depending on what the + * BIO actually reads. + */ +OSSL_STORE_CTX *OSSL_STORE_attach(BIO *bio, OPENSSL_CTX *libctx, + const char *scheme, const char *propq, + const UI_METHOD *ui_method, void *ui_data, + OSSL_STORE_post_process_info_fn post_process, + void *post_process_data); /*- * Extracting OpenSSL types from and creating new OSSL_STORE_INFOs @@ -228,6 +246,16 @@ typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_open_fn)(const OSSL_STORE_LOADER void *ui_data); int OSSL_STORE_LOADER_set_open(OSSL_STORE_LOADER *loader, OSSL_STORE_open_fn open_function); +typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_attach_fn)(const OSSL_STORE_LOADER + *loader, + BIO *bio, + OPENSSL_CTX *libctx, + const char *propq, + const UI_METHOD + *ui_method, + void *ui_data); +int OSSL_STORE_LOADER_set_attach(OSSL_STORE_LOADER *loader, + OSSL_STORE_attach_fn attach_function); typedef int (*OSSL_STORE_ctrl_fn)(OSSL_STORE_LOADER_CTX *ctx, int cmd, va_list args); int OSSL_STORE_LOADER_set_ctrl(OSSL_STORE_LOADER *loader, diff --git a/include/openssl/storeerr.h b/include/openssl/storeerr.h index db279382..ed8f7988 100644 --- a/include/openssl/storeerr.h +++ b/include/openssl/storeerr.h @@ -8,8 +8,8 @@ * https://www.openssl.org/source/license.html */ -#ifndef OPENSSL_STOREERR_H -# define OPENSSL_STOREERR_H +#ifndef OPENSSL_OSSL_STOREERR_H +# define OPENSSL_OSSL_STOREERR_H # pragma once # include @@ -25,6 +25,7 @@ int ERR_load_OSSL_STORE_strings(void); * OSSL_STORE function codes. */ # ifndef OPENSSL_NO_DEPRECATED_3_0 +# define OSSL_STORE_F_FILE_ATTACH 0 # define OSSL_STORE_F_FILE_CTRL 0 # define OSSL_STORE_F_FILE_FIND 0 # define OSSL_STORE_F_FILE_GET_PASS 0 @@ -32,9 +33,8 @@ int ERR_load_OSSL_STORE_strings(void); # define OSSL_STORE_F_FILE_LOAD_TRY_DECODE 0 # define OSSL_STORE_F_FILE_NAME_TO_URI 0 # define OSSL_STORE_F_FILE_OPEN 0 -# define OSSL_STORE_F_OSSL_STORE_ATTACH_PEM_BIO 0 +# define OSSL_STORE_F_OSSL_STORE_ATTACH 0 # define OSSL_STORE_F_OSSL_STORE_EXPECT 0 -# define OSSL_STORE_F_OSSL_STORE_FILE_ATTACH_PEM_BIO_INT 0 # define OSSL_STORE_F_OSSL_STORE_FIND 0 # define OSSL_STORE_F_OSSL_STORE_GET0_LOADER_INT 0 # define OSSL_STORE_F_OSSL_STORE_INFO_GET1_CERT 0 diff --git a/include/openssl/ts.h b/include/openssl/ts.h index 1229838d..48cea0f5 100644 --- a/include/openssl/ts.h +++ b/include/openssl/ts.h @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -264,8 +264,6 @@ typedef int (*TS_extension_cb) (struct TS_resp_ctx *, X509_EXTENSION *, typedef struct TS_resp_ctx TS_RESP_CTX; -DEFINE_STACK_OF_CONST(EVP_MD) - /* Creates a response context that can be used for generating responses. */ TS_RESP_CTX *TS_RESP_CTX_new(void); void TS_RESP_CTX_free(TS_RESP_CTX *ctx); diff --git a/include/openssl/types.h b/include/openssl/types.h index 2b1d0820..27f90a7b 100644 --- a/include/openssl/types.h +++ b/include/openssl/types.h @@ -60,7 +60,9 @@ typedef int ASN1_BOOLEAN; typedef int ASN1_NULL; # endif +typedef struct asn1_type_st ASN1_TYPE; typedef struct asn1_object_st ASN1_OBJECT; +typedef struct asn1_string_table_st ASN1_STRING_TABLE; typedef struct ASN1_ITEM_st ASN1_ITEM; typedef struct asn1_pctx_st ASN1_PCTX; diff --git a/include/openssl/ui.h b/include/openssl/ui.h index 254ec6c2..fa55d92a 100644 --- a/include/openssl/ui.h +++ b/include/openssl/ui.h @@ -283,7 +283,8 @@ const UI_METHOD *UI_null(void); * about a string or a prompt, including test data for a verification prompt. */ typedef struct ui_string_st UI_STRING; -DEFINE_STACK_OF(UI_STRING) + +DEFINE_OR_DECLARE_STACK_OF(UI_STRING) /* * The different types of strings that are currently supported. This is only diff --git a/include/openssl/x509.h b/include/openssl/x509.h index c54a91b6..d709c53c 100644 --- a/include/openssl/x509.h +++ b/include/openssl/x509.h @@ -40,6 +40,11 @@ extern "C" { #endif +/* Needed stacks for types defined in other headers */ +DEFINE_OR_DECLARE_STACK_OF(X509_NAME) +DEFINE_OR_DECLARE_STACK_OF(X509) +DEFINE_OR_DECLARE_STACK_OF(X509_REVOKED) +DEFINE_OR_DECLARE_STACK_OF(X509_CRL) /* Flags for X509_get_signature_info() */ /* Signature info is valid */ @@ -77,33 +82,21 @@ typedef struct X509_val_st { typedef struct X509_sig_st X509_SIG; typedef struct X509_name_entry_st X509_NAME_ENTRY; +DEFINE_OR_DECLARE_STACK_OF(X509_NAME_ENTRY) -DEFINE_STACK_OF(X509_NAME_ENTRY) - -DEFINE_STACK_OF(X509_NAME) # define X509_EX_V_NETSCAPE_HACK 0x8000 # define X509_EX_V_INIT 0x0001 typedef struct X509_extension_st X509_EXTENSION; - +DEFINE_OR_DECLARE_STACK_OF(X509_EXTENSION) typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; - -DEFINE_STACK_OF(X509_EXTENSION) - typedef struct x509_attributes_st X509_ATTRIBUTE; - -DEFINE_STACK_OF(X509_ATTRIBUTE) - +DEFINE_OR_DECLARE_STACK_OF(X509_ATTRIBUTE) typedef struct X509_req_info_st X509_REQ_INFO; - typedef struct X509_req_st X509_REQ; - typedef struct x509_cert_aux_st X509_CERT_AUX; - typedef struct x509_cinf_st X509_CINF; -DEFINE_STACK_OF(X509) - /* This is used for a table of trust checking functions */ typedef struct x509_trust_st { @@ -114,8 +107,8 @@ typedef struct x509_trust_st { int arg1; void *arg2; } X509_TRUST; +DEFINE_OR_DECLARE_STACK_OF(X509_TRUST) -DEFINE_STACK_OF(X509_TRUST) /* standard trust ids */ @@ -227,12 +220,8 @@ DEFINE_STACK_OF(X509_TRUST) XN_FLAG_FN_LN | \ XN_FLAG_FN_ALIGN) -DEFINE_STACK_OF(X509_REVOKED) - typedef struct X509_crl_info_st X509_CRL_INFO; -DEFINE_STACK_OF(X509_CRL) - typedef struct private_key_st { int version; /* The PKCS#8 data types */ @@ -256,8 +245,7 @@ typedef struct X509_info_st { int enc_len; char *enc_data; } X509_INFO; - -DEFINE_STACK_OF(X509_INFO) +DEFINE_OR_DECLARE_STACK_OF(X509_INFO) /* * The next 2 structures and their 8 routines are used to manipulate Netscape's diff --git a/include/openssl/x509_vfy.h b/include/openssl/x509_vfy.h index 5822eab5..92aed083 100644 --- a/include/openssl/x509_vfy.h +++ b/include/openssl/x509_vfy.h @@ -60,9 +60,9 @@ typedef enum { #define X509_LU_FAIL 0 #endif -DEFINE_STACK_OF(X509_LOOKUP) -DEFINE_STACK_OF(X509_OBJECT) -DEFINE_STACK_OF(X509_VERIFY_PARAM) +DEFINE_OR_DECLARE_STACK_OF(X509_LOOKUP) +DEFINE_OR_DECLARE_STACK_OF(X509_OBJECT) +DEFINE_OR_DECLARE_STACK_OF(X509_VERIFY_PARAM) int X509_STORE_set_depth(X509_STORE *store, int depth); @@ -585,6 +585,7 @@ int X509_VERIFY_PARAM_set_inh_flags(X509_VERIFY_PARAM *param, uint32_t flags); uint32_t X509_VERIFY_PARAM_get_inh_flags(const X509_VERIFY_PARAM *param); +char *X509_VERIFY_PARAM_get0_host(X509_VERIFY_PARAM *param, int idx); int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, const char *name, size_t namelen); int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, @@ -594,8 +595,10 @@ void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, unsigned int X509_VERIFY_PARAM_get_hostflags(const X509_VERIFY_PARAM *param); char *X509_VERIFY_PARAM_get0_peername(const X509_VERIFY_PARAM *param); void X509_VERIFY_PARAM_move_peername(X509_VERIFY_PARAM *, X509_VERIFY_PARAM *); +char *X509_VERIFY_PARAM_get0_email(X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, const char *email, size_t emaillen); +char *X509_VERIFY_PARAM_get1_ip_asc(X509_VERIFY_PARAM *param); int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, const unsigned char *ip, size_t iplen); int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, diff --git a/include/openssl/x509v3.h b/include/openssl/x509v3.h index 6f4743d1..e7d36638 100644 --- a/include/openssl/x509v3.h +++ b/include/openssl/x509v3.h @@ -97,7 +97,7 @@ struct v3_ext_ctx { typedef struct v3_ext_method X509V3_EXT_METHOD; -DEFINE_STACK_OF(X509V3_EXT_METHOD) +DEFINE_OR_DECLARE_STACK_OF(X509V3_EXT_METHOD) /* ext_flags values */ # define X509V3_EXT_DYNAMIC 0x1 @@ -163,17 +163,15 @@ typedef struct ACCESS_DESCRIPTION_st { GENERAL_NAME *location; } ACCESS_DESCRIPTION; +DEFINE_OR_DECLARE_STACK_OF(ACCESS_DESCRIPTION) +DEFINE_OR_DECLARE_STACK_OF(GENERAL_NAME) + typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; - typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; - typedef STACK_OF(ASN1_INTEGER) TLS_FEATURE; - -DEFINE_STACK_OF(GENERAL_NAME) typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; -DEFINE_STACK_OF(GENERAL_NAMES) -DEFINE_STACK_OF(ACCESS_DESCRIPTION) +DEFINE_OR_DECLARE_STACK_OF(GENERAL_NAMES) typedef struct DIST_POINT_NAME_st { int type; @@ -206,9 +204,9 @@ struct DIST_POINT_st { int dp_reasons; }; -typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; +DEFINE_OR_DECLARE_STACK_OF(DIST_POINT) -DEFINE_STACK_OF(DIST_POINT) +typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; struct AUTHORITY_KEYID_st { ASN1_OCTET_STRING *keyid; @@ -223,7 +221,7 @@ typedef struct SXNET_ID_st { ASN1_OCTET_STRING *user; } SXNETID; -DEFINE_STACK_OF(SXNETID) +DEFINE_OR_DECLARE_STACK_OF(SXNETID) typedef struct SXNET_st { ASN1_INTEGER *version; @@ -256,23 +254,23 @@ typedef struct POLICYQUALINFO_st { } d; } POLICYQUALINFO; -DEFINE_STACK_OF(POLICYQUALINFO) +DEFINE_OR_DECLARE_STACK_OF(POLICYQUALINFO) typedef struct POLICYINFO_st { ASN1_OBJECT *policyid; STACK_OF(POLICYQUALINFO) *qualifiers; } POLICYINFO; -typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; +DEFINE_OR_DECLARE_STACK_OF(POLICYINFO) -DEFINE_STACK_OF(POLICYINFO) +typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; typedef struct POLICY_MAPPING_st { ASN1_OBJECT *issuerDomainPolicy; ASN1_OBJECT *subjectDomainPolicy; } POLICY_MAPPING; -DEFINE_STACK_OF(POLICY_MAPPING) +DEFINE_OR_DECLARE_STACK_OF(POLICY_MAPPING) typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; @@ -282,7 +280,7 @@ typedef struct GENERAL_SUBTREE_st { ASN1_INTEGER *maximum; } GENERAL_SUBTREE; -DEFINE_STACK_OF(GENERAL_SUBTREE) +DEFINE_OR_DECLARE_STACK_OF(GENERAL_SUBTREE) struct NAME_CONSTRAINTS_st { STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; @@ -422,6 +420,8 @@ typedef struct x509_purpose_st { void *usr_data; } X509_PURPOSE; +DEFINE_OR_DECLARE_STACK_OF(X509_PURPOSE) + # define X509_PURPOSE_SSL_CLIENT 1 # define X509_PURPOSE_SSL_SERVER 2 # define X509_PURPOSE_NS_SSL_SERVER 3 @@ -458,8 +458,6 @@ typedef struct x509_purpose_st { # define X509V3_ADD_DELETE 5L # define X509V3_ADD_SILENT 0x10 -DEFINE_STACK_OF(X509_PURPOSE) - DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) DECLARE_ASN1_FUNCTIONS(SXNET) @@ -736,7 +734,7 @@ int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, unsigned long chtype); void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent); -DEFINE_STACK_OF(X509_POLICY_NODE) +DEFINE_OR_DECLARE_STACK_OF(X509_POLICY_NODE) #ifndef OPENSSL_NO_RFC3779 typedef struct ASRange_st { @@ -754,8 +752,9 @@ typedef struct ASIdOrRange_st { } u; } ASIdOrRange; +DEFINE_OR_DECLARE_STACK_OF(ASIdOrRange) + typedef STACK_OF(ASIdOrRange) ASIdOrRanges; -DEFINE_STACK_OF(ASIdOrRange) # define ASIdentifierChoice_inherit 0 # define ASIdentifierChoice_asIdsOrRanges 1 @@ -792,8 +791,9 @@ typedef struct IPAddressOrRange_st { } u; } IPAddressOrRange; +DEFINE_OR_DECLARE_STACK_OF(IPAddressOrRange) + typedef STACK_OF(IPAddressOrRange) IPAddressOrRanges; -DEFINE_STACK_OF(IPAddressOrRange) # define IPAddressChoice_inherit 0 # define IPAddressChoice_addressesOrRanges 1 @@ -811,8 +811,9 @@ typedef struct IPAddressFamily_st { IPAddressChoice *ipAddressChoice; } IPAddressFamily; +DEFINE_OR_DECLARE_STACK_OF(IPAddressFamily) + typedef STACK_OF(IPAddressFamily) IPAddrBlocks; -DEFINE_STACK_OF(IPAddressFamily) DECLARE_ASN1_FUNCTIONS(IPAddressRange) DECLARE_ASN1_FUNCTIONS(IPAddressOrRange) @@ -884,7 +885,7 @@ int X509v3_addr_validate_resource_set(STACK_OF(X509) *chain, #endif /* OPENSSL_NO_RFC3779 */ -DEFINE_STACK_OF(ASN1_STRING) +DEFINE_OR_DECLARE_STACK_OF(ASN1_STRING) /* * Admission Syntax @@ -897,8 +898,8 @@ DECLARE_ASN1_FUNCTIONS(NAMING_AUTHORITY) DECLARE_ASN1_FUNCTIONS(PROFESSION_INFO) DECLARE_ASN1_FUNCTIONS(ADMISSIONS) DECLARE_ASN1_FUNCTIONS(ADMISSION_SYNTAX) -DEFINE_STACK_OF(ADMISSIONS) -DEFINE_STACK_OF(PROFESSION_INFO) +DEFINE_OR_DECLARE_STACK_OF(PROFESSION_INFO) +DEFINE_OR_DECLARE_STACK_OF(ADMISSIONS) typedef STACK_OF(PROFESSION_INFO) PROFESSION_INFOS; const ASN1_OBJECT *NAMING_AUTHORITY_get0_authorityId( diff --git a/providers/build.info b/providers/build.info index 45faecf6..b7eef405 100644 --- a/providers/build.info +++ b/providers/build.info @@ -21,11 +21,11 @@ # libfips.a Contains all things needed to support # FIPS implementations, such as code from # crypto/ and object files that contain -# FIPS-specific code. FIPS_MODE is defined +# FIPS-specific code. FIPS_MODULE is defined # for this library. The FIPS module uses # this. # libnonfips.a Corresponds to libfips.a, but built with -# FIPS_MODE undefined. The default and legacy +# FIPS_MODULE undefined. The default and legacy # providers use this. SUBDIRS=common implementations @@ -50,7 +50,7 @@ INCLUDE[$LIBIMPLEMENTATIONS]=.. $COMMON_INCLUDES INCLUDE[$LIBLEGACY]=.. $COMMON_INCLUDES INCLUDE[$LIBNONFIPS]=$COMMON_INCLUDES INCLUDE[$LIBFIPS]=.. $COMMON_INCLUDES -DEFINE[$LIBFIPS]=FIPS_MODE +DEFINE[$LIBFIPS]=FIPS_MODULE # Weak dependencies to provide library order information. # We make it weak so they aren't both used always; what is @@ -101,7 +101,7 @@ SUBDIRS=fips $FIPSGOAL=fips DEPEND[$FIPSGOAL]=$LIBIMPLEMENTATIONS $LIBFIPS INCLUDE[$FIPSGOAL]=../include -DEFINE[$FIPSGOAL]=FIPS_MODE +DEFINE[$FIPSGOAL]=FIPS_MODULE IF[{- defined $target{shared_defflag} -}] SOURCE[$FIPSGOAL]=fips.ld GENERATE[fips.ld]=../util/providers.num @@ -149,7 +149,7 @@ IF[{- !$disabled{legacy} -}] # Common things that are valid no matter what form the Legacy provider # takes. SOURCE[$LEGACYGOAL]=legacyprov.c - INCLUDE[$LEGACYGOAL]=../include implementations/include + INCLUDE[$LEGACYGOAL]=../include implementations/include common/include ENDIF # diff --git a/providers/common/bio_prov.c b/providers/common/bio_prov.c index 7b440043..2bfd14b5 100644 --- a/providers/common/bio_prov.c +++ b/providers/common/bio_prov.c @@ -7,12 +7,15 @@ * https://www.openssl.org/source/license.html */ +#include #include +#include "internal/cryptlib.h" #include "prov/bio.h" static OSSL_BIO_new_file_fn *c_bio_new_file = NULL; static OSSL_BIO_new_membuf_fn *c_bio_new_membuf = NULL; static OSSL_BIO_read_ex_fn *c_bio_read_ex = NULL; +static OSSL_BIO_write_ex_fn *c_bio_write_ex = NULL; static OSSL_BIO_free_fn *c_bio_free = NULL; static OSSL_BIO_vprintf_fn *c_bio_vprintf = NULL; @@ -32,6 +35,10 @@ int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns) if (c_bio_read_ex == NULL) c_bio_read_ex = OSSL_get_BIO_read_ex(fns); break; + case OSSL_FUNC_BIO_WRITE_EX: + if (c_bio_write_ex == NULL) + c_bio_write_ex = OSSL_get_BIO_write_ex(fns); + break; case OSSL_FUNC_BIO_FREE: if (c_bio_free == NULL) c_bio_free = OSSL_get_BIO_free(fns); @@ -46,21 +53,21 @@ int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns) return 1; } -BIO *ossl_prov_bio_new_file(const char *filename, const char *mode) +OSSL_CORE_BIO *ossl_prov_bio_new_file(const char *filename, const char *mode) { if (c_bio_new_file == NULL) return NULL; return c_bio_new_file(filename, mode); } -BIO *ossl_prov_bio_new_membuf(const char *filename, int len) +OSSL_CORE_BIO *ossl_prov_bio_new_membuf(const char *filename, int len) { if (c_bio_new_membuf == NULL) return NULL; return c_bio_new_membuf(filename, len); } -int ossl_prov_bio_read_ex(BIO *bio, void *data, size_t data_len, +int ossl_prov_bio_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len, size_t *bytes_read) { if (c_bio_read_ex == NULL) @@ -68,21 +75,29 @@ int ossl_prov_bio_read_ex(BIO *bio, void *data, size_t data_len, return c_bio_read_ex(bio, data, data_len, bytes_read); } -int ossl_prov_bio_free(BIO *bio) +int ossl_prov_bio_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len, + size_t *written) +{ + if (c_bio_write_ex == NULL) + return 0; + return c_bio_write_ex(bio, data, data_len, written); +} + +int ossl_prov_bio_free(OSSL_CORE_BIO *bio) { if (c_bio_free == NULL) return 0; return c_bio_free(bio); } -int ossl_prov_bio_vprintf(BIO *bio, const char *format, va_list ap) +int ossl_prov_bio_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list ap) { if (c_bio_vprintf == NULL) return -1; return c_bio_vprintf(bio, format, ap); } -int ossl_prov_bio_printf(BIO *bio, const char *format, ...) +int ossl_prov_bio_printf(OSSL_CORE_BIO *bio, const char *format, ...) { va_list ap; int ret; @@ -94,3 +109,90 @@ int ossl_prov_bio_printf(BIO *bio, const char *format, ...) return ret; } +#ifndef FIPS_MODULE + +/* No direct BIO support in the FIPS module */ + +static int bio_core_read_ex(BIO *bio, char *data, size_t data_len, + size_t *bytes_read) +{ + return ossl_prov_bio_read_ex(BIO_get_data(bio), data, data_len, bytes_read); +} + +static int bio_core_write_ex(BIO *bio, const char *data, size_t data_len, + size_t *written) +{ + return ossl_prov_bio_write_ex(BIO_get_data(bio), data, data_len, written); +} + +static long bio_core_ctrl(BIO *bio, int cmd, long num, void *ptr) +{ + /* We don't support this */ + assert(0); + return 0; +} + +static int bio_core_gets(BIO *bio, char *buf, int size) +{ + /* We don't support this */ + assert(0); + return -1; +} + +static int bio_core_puts(BIO *bio, const char *str) +{ + /* We don't support this */ + assert(0); + return -1; +} + +static int bio_core_new(BIO *bio) +{ + BIO_set_init(bio, 1); + + return 1; +} + +static int bio_core_free(BIO *bio) +{ + BIO_set_init(bio, 0); + + return 1; +} + +BIO_METHOD *bio_prov_init_bio_method(void) +{ + BIO_METHOD *corebiometh = NULL; + + corebiometh = BIO_meth_new(BIO_TYPE_CORE_TO_PROV, "BIO to Core filter"); + if (corebiometh == NULL + || !BIO_meth_set_write_ex(corebiometh, bio_core_write_ex) + || !BIO_meth_set_read_ex(corebiometh, bio_core_read_ex) + || !BIO_meth_set_puts(corebiometh, bio_core_puts) + || !BIO_meth_set_gets(corebiometh, bio_core_gets) + || !BIO_meth_set_ctrl(corebiometh, bio_core_ctrl) + || !BIO_meth_set_create(corebiometh, bio_core_new) + || !BIO_meth_set_destroy(corebiometh, bio_core_free)) { + BIO_meth_free(corebiometh); + return NULL; + } + + return corebiometh; +} + +BIO *bio_new_from_core_bio(PROV_CTX *provctx, OSSL_CORE_BIO *corebio) +{ + BIO *outbio; + BIO_METHOD *corebiometh = PROV_CTX_get0_core_bio_method(provctx); + + if (corebiometh == NULL) + return NULL; + + outbio = BIO_new(corebiometh); + if (outbio != NULL) + BIO_set_data(outbio, corebio); + + return outbio; +} + +#endif diff --git a/providers/common/build.info b/providers/common/build.info index b6495d34..c49b0902 100644 --- a/providers/common/build.info +++ b/providers/common/build.info @@ -1,6 +1,6 @@ SUBDIRS=der -SOURCE[../libcommon.a]=provider_err.c bio_prov.c +SOURCE[../libcommon.a]=provider_err.c bio_prov.c provider_ctx.c $FIPSCOMMON=provider_util.c SOURCE[../libnonfips.a]=$FIPSCOMMON nid_to_name.c SOURCE[../libfips.a]=$FIPSCOMMON diff --git a/providers/common/der/DIGESTS.asn1 b/providers/common/der/DIGESTS.asn1 new file mode 100644 index 00000000..afed3721 --- /dev/null +++ b/providers/common/der/DIGESTS.asn1 @@ -0,0 +1,19 @@ +-- ------------------------------------------------------------------- +-- Taken from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration + +id-sha256 OBJECT IDENTIFIER ::= { hashAlgs 1 } +id-sha384 OBJECT IDENTIFIER ::= { hashAlgs 2 } +id-sha512 OBJECT IDENTIFIER ::= { hashAlgs 3 } +id-sha224 OBJECT IDENTIFIER ::= { hashAlgs 4 } +id-sha512-224 OBJECT IDENTIFIER ::= { hashAlgs 5 } +id-sha512-256 OBJECT IDENTIFIER ::= { hashAlgs 6 } +id-sha3-224 OBJECT IDENTIFIER ::= { hashAlgs 7 } +id-sha3-256 OBJECT IDENTIFIER ::= { hashAlgs 8 } +id-sha3-384 OBJECT IDENTIFIER ::= { hashAlgs 9 } +id-sha3-512 OBJECT IDENTIFIER ::= { hashAlgs 10 } +id-shake128 OBJECT IDENTIFIER ::= { hashAlgs 11 } +id-shake256 OBJECT IDENTIFIER ::= { hashAlgs 12 } +id-shake128-len OBJECT IDENTIFIER ::= { hashAlgs 17 } +id-shake256-len OBJECT IDENTIFIER ::= { hashAlgs 18 } +id-KMACWithSHAKE128 OBJECT IDENTIFIER ::={hashAlgs 19} +id-KMACWithSHAKE256 OBJECT IDENTIFIER ::={ hashAlgs 20} diff --git a/providers/common/der/NIST.asn1 b/providers/common/der/NIST.asn1 new file mode 100644 index 00000000..3e438484 --- /dev/null +++ b/providers/common/der/NIST.asn1 @@ -0,0 +1,8 @@ +-- ------------------------------------------------------------------- +-- Taken from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration + +-- Copies of common OIDs used by other ASN.1 files. +csor OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 } +nistAlgorithms OBJECT IDENTIFIER ::= { csor nistAlgorithm(4) } +hashAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 2 } +sigAlgs OBJECT IDENTIFIER ::= { nistAlgorithms 3 } diff --git a/providers/common/der/RSA.asn1 b/providers/common/der/RSA.asn1 index 7bce6360..d0c54d71 100644 --- a/providers/common/der/RSA.asn1 +++ b/providers/common/der/RSA.asn1 @@ -80,9 +80,18 @@ id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } -- ------------------------------------------------------------------- -- Taken from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration -sigAlgs OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 4 3 } - id-rsassa-pkcs1-v1_5-with-sha3-224 OBJECT IDENTIFIER ::= { sigAlgs 13 } id-rsassa-pkcs1-v1_5-with-sha3-256 OBJECT IDENTIFIER ::= { sigAlgs 14 } id-rsassa-pkcs1-v1_5-with-sha3-384 OBJECT IDENTIFIER ::= { sigAlgs 15 } id-rsassa-pkcs1-v1_5-with-sha3-512 OBJECT IDENTIFIER ::= { sigAlgs 16 } + + +-- ------------------------------------------------------------------- +-- These OID's exist in the codebase but may need to be deprecated at some point. +-- mdc2 and md5_sha1 have been omitted as they do not look like valid entries. + +md4WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 3 } + +ripemd160WithRSAEncryption OBJECT IDENTIFIER ::= { + iso(1) identified-organization(3) teletrust(36) algorithm(3) signatureAlgorithm(3) rsaSignature(1) 2 +} diff --git a/providers/common/der/build.info b/providers/common/der/build.info index eda763ea..837fe73f 100644 --- a/providers/common/der/build.info +++ b/providers/common/der/build.info @@ -1,4 +1,4 @@ -$FIPSABLE=der_rsa.c der_dsa.c der_ec.c +$FIPSABLE=der_rsa.c der_dsa.c der_ec.c der_digests.c SOURCE[../../libfips.a]=$FIPSABLE SOURCE[../../libnonfips.a]=$FIPSABLE @@ -6,7 +6,7 @@ SOURCE[../../libnonfips.a]=$FIPSABLE GENERATE[der_rsa.c]=der_rsa.c.in DEPEND[der_rsa.c]=oids_to_c.pm -DEPEND[der_rsa.o]=../include/prov/der_rsa.h +DEPEND[der_rsa.o]=../include/prov/der_rsa.h ../include/prov/der_digests.h GENERATE[../include/prov/der_rsa.h]=der_rsa.h.in DEPEND[../include/prov/der_rsa.h]=oids_to_c.pm @@ -23,3 +23,10 @@ DEPEND[der_ec.c]=oids_to_c.pm DEPEND[der_ec.o]=../include/prov/der_ec.h GENERATE[../include/prov/der_ec.h]=der_ec.h.in DEPEND[../include/prov/der_ec.h]=oids_to_c.pm + +GENERATE[der_digests.c]=der_digests.c.in +DEPEND[der_digests.c]=oids_to_c.pm + +DEPEND[der_digests.o]=../include/prov/der_digests.h +GENERATE[../include/prov/der_digests.h]=der_digests.h.in +DEPEND[../include/prov/der_digests.h]=oids_to_c.pm diff --git a/providers/common/der/der_digests.c.in b/providers/common/der/der_digests.c.in new file mode 100644 index 00000000..433c1074 --- /dev/null +++ b/providers/common/der/der_digests.c.in @@ -0,0 +1,18 @@ +/* + * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "prov/der_digests.h" + +/* Well known OIDs precompiled */ +{- + $OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1', + 'providers/common/der/DIGESTS.asn1', + { dir => $config{sourcedir}, + filter => \&oids_to_c::filter_to_C }); +-} diff --git a/providers/common/der/der_digests.h.in b/providers/common/der/der_digests.h.in new file mode 100644 index 00000000..91fbe1f7 --- /dev/null +++ b/providers/common/der/der_digests.h.in @@ -0,0 +1,18 @@ +/* + * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "internal/der.h" + +/* Well known OIDs precompiled */ +{- + $OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1', + 'providers/common/der/DIGESTS.asn1', + { dir => $config{sourcedir}, + filter => \&oids_to_c::filter_to_H }); +-} diff --git a/providers/common/der/der_rsa.c.in b/providers/common/der/der_rsa.c.in index fb936d29..30e945cf 100644 --- a/providers/common/der/der_rsa.c.in +++ b/providers/common/der/der_rsa.c.in @@ -9,25 +9,381 @@ #include #include +#include "internal/cryptlib.h" #include "prov/der_rsa.h" +#include "prov/der_digests.h" /* Well known OIDs precompiled */ {- - $OUT = oids_to_c::process_leaves('providers/common/der/RSA.asn1', + $OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1', + 'providers/common/der/DIGESTS.asn1', + 'providers/common/der/RSA.asn1', { dir => $config{sourcedir}, filter => \&oids_to_c::filter_to_C }); -} -int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa) +/* More complex pre-compiled sequences. TODO(3.0) refactor? */ +/*- + * From https://tools.ietf.org/html/rfc8017#appendix-A.2.1 + * + * OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= { + * { OID id-sha1 PARAMETERS NULL }| + * { OID id-sha224 PARAMETERS NULL }| + * { OID id-sha256 PARAMETERS NULL }| + * { OID id-sha384 PARAMETERS NULL }| + * { OID id-sha512 PARAMETERS NULL }| + * { OID id-sha512-224 PARAMETERS NULL }| + * { OID id-sha512-256 PARAMETERS NULL }, + * ... -- Allows for future expansion -- + * } + */ +#define DER_V_NULL DER_P_NULL, 0 +#define DER_SZ_NULL 2 + +/* + * The names for the hash function AlgorithmIdentifiers are borrowed and + * expanded from https://tools.ietf.org/html/rfc4055#section-2.1 + * + * sha1Identifier AlgorithmIdentifier ::= { id-sha1, NULL } + * sha224Identifier AlgorithmIdentifier ::= { id-sha224, NULL } + * sha256Identifier AlgorithmIdentifier ::= { id-sha256, NULL } + * sha384Identifier AlgorithmIdentifier ::= { id-sha384, NULL } + * sha512Identifier AlgorithmIdentifier ::= { id-sha512, NULL } + */ +/* + * NOTE: Some of the arrays aren't used other than inside sizeof(), which + * clang complains about (-Wno-unneeded-internal-declaration). To get + * around that, we make them non-static, and declare them an extra time to + * avoid compilers complaining about definitions without declarations. + */ +#if 0 /* Currently unused */ +#define DER_AID_V_sha1Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_sha1 + DER_SZ_NULL, \ + DER_OID_V_id_sha1, \ + DER_V_NULL +extern const unsigned char der_aid_sha1Identifier[]; +const unsigned char der_aid_sha1Identifier[] = { + DER_AID_V_sha1Identifier +}; +#define DER_AID_SZ_sha1Identifier sizeof(der_aid_sha1Identifier) +#endif + +#define DER_AID_V_sha224Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_sha224 + DER_SZ_NULL, \ + DER_OID_V_id_sha224, \ + DER_V_NULL +extern const unsigned char der_aid_sha224Identifier[]; +const unsigned char der_aid_sha224Identifier[] = { + DER_AID_V_sha224Identifier +}; +#define DER_AID_SZ_sha224Identifier sizeof(der_aid_sha224Identifier) + +#define DER_AID_V_sha256Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_sha256 + DER_SZ_NULL, \ + DER_OID_V_id_sha256, \ + DER_V_NULL +extern const unsigned char der_aid_sha256Identifier[]; +const unsigned char der_aid_sha256Identifier[] = { + DER_AID_V_sha256Identifier +}; +#define DER_AID_SZ_sha256Identifier sizeof(der_aid_sha256Identifier) + +#define DER_AID_V_sha384Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_sha384 + DER_SZ_NULL, \ + DER_OID_V_id_sha384, \ + DER_V_NULL +extern const unsigned char der_aid_sha384Identifier[]; +const unsigned char der_aid_sha384Identifier[] = { + DER_AID_V_sha384Identifier +}; +#define DER_AID_SZ_sha384Identifier sizeof(der_aid_sha384Identifier) + +#define DER_AID_V_sha512Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_sha512 + DER_SZ_NULL, \ + DER_OID_V_id_sha512, \ + DER_V_NULL +extern const unsigned char der_aid_sha512Identifier[]; +const unsigned char der_aid_sha512Identifier[] = { + DER_AID_V_sha512Identifier +}; +#define DER_AID_SZ_sha512Identifier sizeof(der_aid_sha512Identifier) + +#define DER_AID_V_sha512_224Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_sha512_224 + DER_SZ_NULL, \ + DER_OID_V_id_sha512_224, \ + DER_V_NULL +extern const unsigned char der_aid_sha512_224Identifier[]; +const unsigned char der_aid_sha512_224Identifier[] = { + DER_AID_V_sha512_224Identifier +}; +#define DER_AID_SZ_sha512_224Identifier sizeof(der_aid_sha512_224Identifier) + +#define DER_AID_V_sha512_256Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_sha512_256 + DER_SZ_NULL, \ + DER_OID_V_id_sha512_256, \ + DER_V_NULL +extern const unsigned char der_aid_sha512_256Identifier[]; +const unsigned char der_aid_sha512_256Identifier[] = { + DER_AID_V_sha512_256Identifier +}; +#define DER_AID_SZ_sha512_256Identifier sizeof(der_aid_sha512_256Identifier) + +/*- + * From https://tools.ietf.org/html/rfc8017#appendix-A.2.1 + * + * HashAlgorithm ::= AlgorithmIdentifier { + * {OAEP-PSSDigestAlgorithms} + * } + * + * ... + * + * PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= { + * { OID id-mgf1 PARAMETERS HashAlgorithm }, + * ... -- Allows for future expansion -- + * } + */ + +/* + * The names for the MGF1 AlgorithmIdentifiers are borrowed and expanded + * from https://tools.ietf.org/html/rfc4055#section-2.1 + * + * mgf1SHA1Identifier AlgorithmIdentifier ::= + * { id-mgf1, sha1Identifier } + * mgf1SHA224Identifier AlgorithmIdentifier ::= + * { id-mgf1, sha224Identifier } + * mgf1SHA256Identifier AlgorithmIdentifier ::= + * { id-mgf1, sha256Identifier } + * mgf1SHA384Identifier AlgorithmIdentifier ::= + * { id-mgf1, sha384Identifier } + * mgf1SHA512Identifier AlgorithmIdentifier ::= + * { id-mgf1, sha512Identifier } + */ +#if 0 /* Currently unused */ +#define DER_AID_V_mgf1SHA1Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha1Identifier, \ + DER_OID_V_id_mgf1, \ + DER_AID_V_sha1Identifier +static const unsigned char der_aid_mgf1SHA1Identifier[] = { + DER_AID_V_mgf1SHA1Identifier +}; +#define DER_AID_SZ_mgf1SHA1Identifier sizeof(der_aid_mgf1SHA1Identifier) +#endif + +#define DER_AID_V_mgf1SHA224Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha224Identifier, \ + DER_OID_V_id_mgf1, \ + DER_AID_V_sha224Identifier +static const unsigned char der_aid_mgf1SHA224Identifier[] = { + DER_AID_V_mgf1SHA224Identifier +}; +#define DER_AID_SZ_mgf1SHA224Identifier sizeof(der_aid_mgf1SHA224Identifier) + +#define DER_AID_V_mgf1SHA256Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha256Identifier, \ + DER_OID_V_id_mgf1, \ + DER_AID_V_sha256Identifier +static const unsigned char der_aid_mgf1SHA256Identifier[] = { + DER_AID_V_mgf1SHA256Identifier +}; +#define DER_AID_SZ_mgf1SHA256Identifier sizeof(der_aid_mgf1SHA256Identifier) + +#define DER_AID_V_mgf1SHA384Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha384Identifier, \ + DER_OID_V_id_mgf1, \ + DER_AID_V_sha384Identifier +static const unsigned char der_aid_mgf1SHA384Identifier[] = { + DER_AID_V_mgf1SHA384Identifier +}; +#define DER_AID_SZ_mgf1SHA384Identifier sizeof(der_aid_mgf1SHA384Identifier) + +#define DER_AID_V_mgf1SHA512Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha512Identifier, \ + DER_OID_V_id_mgf1, \ + DER_AID_V_sha512Identifier +static const unsigned char der_aid_mgf1SHA512Identifier[] = { + DER_AID_V_mgf1SHA512Identifier +}; +#define DER_AID_SZ_mgf1SHA512Identifier sizeof(der_aid_mgf1SHA512Identifier) + +#define DER_AID_V_mgf1SHA512_224Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha512_224Identifier, \ + DER_OID_V_id_mgf1, \ + DER_AID_V_sha512_224Identifier +static const unsigned char der_aid_mgf1SHA512_224Identifier[] = { + DER_AID_V_mgf1SHA512_224Identifier +}; +#define DER_AID_SZ_mgf1SHA512_224Identifier sizeof(der_aid_mgf1SHA512_224Identifier) + +#define DER_AID_V_mgf1SHA512_256Identifier \ + DER_P_SEQUENCE|DER_F_CONSTRUCTED, \ + DER_OID_SZ_id_mgf1 + DER_AID_SZ_sha512_256Identifier, \ + DER_OID_V_id_mgf1, \ + DER_AID_V_sha512_256Identifier +static const unsigned char der_aid_mgf1SHA512_256Identifier[] = { + DER_AID_V_mgf1SHA512_256Identifier +}; +#define DER_AID_SZ_mgf1SHA512_256Identifier sizeof(der_aid_mgf1SHA512_256Identifier) + + +#define MGF1_SHA_CASE(bits, var) \ + case NID_sha##bits: \ + var = der_aid_mgf1SHA##bits##Identifier; \ + var##_sz = sizeof(der_aid_mgf1SHA##bits##Identifier); \ + break; + +/*- + * The name is borrowed from https://tools.ietf.org/html/rfc8017#appendix-A.2.1 + * + * MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} } + */ +static int DER_w_MaskGenAlgorithm(WPACKET *pkt, int tag, + const RSA_PSS_PARAMS_30 *pss) { + if (pss != NULL && rsa_pss_params_30_maskgenalg(pss) == NID_mgf1) { + int maskgenhashalg_nid = rsa_pss_params_30_maskgenhashalg(pss); + const unsigned char *maskgenalg = NULL; + size_t maskgenalg_sz = 0; + + switch (maskgenhashalg_nid) { + case NID_sha1: + break; + MGF1_SHA_CASE(224, maskgenalg); + MGF1_SHA_CASE(256, maskgenalg); + MGF1_SHA_CASE(384, maskgenalg); + MGF1_SHA_CASE(512, maskgenalg); + MGF1_SHA_CASE(512_224, maskgenalg); + MGF1_SHA_CASE(512_256, maskgenalg); + default: + return 0; + } + + /* If there is none (or it was the default), we write nothing */ + if (maskgenalg == NULL) + return 1; + + return DER_w_precompiled(pkt, tag, maskgenalg, maskgenalg_sz); + } + return 0; +} + +#define OAEP_PSS_MD_CASE(name, var) \ + case NID_##name: \ + var = der_oid_id_##name; \ + var##_sz = sizeof(der_oid_id_##name); \ + break; + +int DER_w_RSASSA_PSS_params(WPACKET *pkt, int tag, const RSA_PSS_PARAMS_30 *pss) +{ + int hashalg_nid, default_hashalg_nid; + int saltlen, default_saltlen; + int trailerfield, default_trailerfield; + const unsigned char *hashalg = NULL; + size_t hashalg_sz = 0; + + /* + * For an unrestricted key, this function should not have been called; + * the caller must be in control, because unrestricted keys are permitted + * in some situations (when encoding the public key in a SubjectKeyInfo, + * for example) while not in others, and this function doesn't know the + * intent. Therefore, we assert that here, the PSS parameters must show + * that the key is restricted. + */ + if (!ossl_assert(pss != NULL && !rsa_pss_params_30_is_unrestricted(pss))) + return 0; + + hashalg_nid = rsa_pss_params_30_hashalg(pss); + saltlen = rsa_pss_params_30_saltlen(pss); + trailerfield = rsa_pss_params_30_trailerfield(pss); + + /* Getting default values */ + default_hashalg_nid = rsa_pss_params_30_hashalg(NULL); + default_saltlen = rsa_pss_params_30_saltlen(NULL); + default_trailerfield = rsa_pss_params_30_trailerfield(NULL); + + /* + * From https://tools.ietf.org/html/rfc8017#appendix-A.2.1: + * + * OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= { + * { OID id-sha1 PARAMETERS NULL }| + * { OID id-sha224 PARAMETERS NULL }| + * { OID id-sha256 PARAMETERS NULL }| + * { OID id-sha384 PARAMETERS NULL }| + * { OID id-sha512 PARAMETERS NULL }| + * { OID id-sha512-224 PARAMETERS NULL }| + * { OID id-sha512-256 PARAMETERS NULL }, + * ... -- Allows for future expansion -- + * } + */ + switch (hashalg_nid) { + OAEP_PSS_MD_CASE(sha1, hashalg); + OAEP_PSS_MD_CASE(sha224, hashalg); + OAEP_PSS_MD_CASE(sha256, hashalg); + OAEP_PSS_MD_CASE(sha384, hashalg); + OAEP_PSS_MD_CASE(sha512, hashalg); + OAEP_PSS_MD_CASE(sha512_224, hashalg); + OAEP_PSS_MD_CASE(sha512_256, hashalg); + default: + return 0; + } + return DER_w_begin_sequence(pkt, tag) - /* No parameters (yet?) */ - && DER_w_precompiled(pkt, -1, der_oid_rsaEncryption, - sizeof(der_oid_rsaEncryption)) + && (trailerfield == default_trailerfield + || DER_w_ulong(pkt, 3, trailerfield)) + && (saltlen == default_saltlen || DER_w_ulong(pkt, 2, saltlen)) + && DER_w_MaskGenAlgorithm(pkt, 1, pss) + && (hashalg_nid == default_hashalg_nid + || DER_w_precompiled(pkt, 0, hashalg, hashalg_sz)) && DER_w_end_sequence(pkt, tag); } -/* Aliases so we can have a uniform MD_CASE */ +/* Aliases so we can have a uniform RSA_CASE */ +#define der_oid_rsassaPss der_oid_id_RSASSA_PSS + +#define RSA_CASE(name, var) \ + var##_nid = NID_##name; \ + var##_oid = der_oid_##name; \ + var##_oid_sz = sizeof(der_oid_##name); \ + break; + +int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa) +{ + int rsa_nid = NID_undef; + const unsigned char *rsa_oid = NULL; + size_t rsa_oid_sz = 0; + RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa); + + switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) { + case RSA_FLAG_TYPE_RSA: + RSA_CASE(rsaEncryption, rsa); + case RSA_FLAG_TYPE_RSASSAPSS: + RSA_CASE(rsassaPss, rsa); + } + + if (rsa_oid == NULL) + return 0; + + return DER_w_begin_sequence(pkt, tag) + && (rsa_nid != NID_rsassaPss + || rsa_pss_params_30_is_unrestricted(pss_params) + || DER_w_RSASSA_PSS_params(pkt, -1, pss_params)) + && DER_w_precompiled(pkt, -1, rsa_oid, rsa_oid_sz) + && DER_w_end_sequence(pkt, tag); +} + +/* Aliases so we can have a uniform MD_with_RSA_CASE */ #define der_oid_sha3_224WithRSAEncryption \ der_oid_id_rsassa_pkcs1_v1_5_with_sha3_224 #define der_oid_sha3_256WithRSAEncryption \ @@ -37,10 +393,10 @@ int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa) #define der_oid_sha3_512WithRSAEncryption \ der_oid_id_rsassa_pkcs1_v1_5_with_sha3_512 -#define MD_CASE(name) \ +#define MD_with_RSA_CASE(name, var) \ case NID_##name: \ - precompiled = der_oid_##name##WithRSAEncryption; \ - precompiled_sz = sizeof(der_oid_##name##WithRSAEncryption); \ + var = der_oid_##name##WithRSAEncryption; \ + var##_sz = sizeof(der_oid_##name##WithRSAEncryption); \ break; int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag, @@ -50,19 +406,24 @@ int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag, size_t precompiled_sz = 0; switch (mdnid) { -#ifndef FIPS_MODE - MD_CASE(md2); - MD_CASE(md5); +#ifndef FIPS_MODULE + MD_with_RSA_CASE(md2, precompiled); + MD_with_RSA_CASE(md5, precompiled); + MD_with_RSA_CASE(md4, precompiled); + MD_with_RSA_CASE(ripemd160, precompiled); +/* TODO(3.0) Decide what to do about mdc2 and md5_sha1 */ #endif - MD_CASE(sha1); - MD_CASE(sha224); - MD_CASE(sha256); - MD_CASE(sha384); - MD_CASE(sha512); - MD_CASE(sha3_224); - MD_CASE(sha3_256); - MD_CASE(sha3_384); - MD_CASE(sha3_512); + MD_with_RSA_CASE(sha1, precompiled); + MD_with_RSA_CASE(sha224, precompiled); + MD_with_RSA_CASE(sha256, precompiled); + MD_with_RSA_CASE(sha384, precompiled); + MD_with_RSA_CASE(sha512, precompiled); + MD_with_RSA_CASE(sha512_224, precompiled); + MD_with_RSA_CASE(sha512_256, precompiled); + MD_with_RSA_CASE(sha3_224, precompiled); + MD_with_RSA_CASE(sha3_256, precompiled); + MD_with_RSA_CASE(sha3_384, precompiled); + MD_with_RSA_CASE(sha3_512, precompiled); default: return 0; } diff --git a/providers/common/der/der_rsa.h.in b/providers/common/der/der_rsa.h.in index 3f7cc0e0..53f62278 100644 --- a/providers/common/der/der_rsa.h.in +++ b/providers/common/der/der_rsa.h.in @@ -7,15 +7,20 @@ * https://www.openssl.org/source/license.html */ +#include "crypto/rsa.h" #include "internal/der.h" /* Well known OIDs precompiled */ {- - $OUT = oids_to_c::process_leaves('providers/common/der/RSA.asn1', + $OUT = oids_to_c::process_leaves('providers/common/der/NIST.asn1', + 'providers/common/der/DIGESTS.asn1', + 'providers/common/der/RSA.asn1', { dir => $config{sourcedir}, filter => \&oids_to_c::filter_to_H }); -} +int DER_w_RSASSA_PSS_params(WPACKET *pkt, int tag, + const RSA_PSS_PARAMS_30 *pss); int DER_w_algorithmIdentifier_RSA(WPACKET *pkt, int tag, RSA *rsa); int DER_w_algorithmIdentifier_RSA_with(WPACKET *pkt, int tag, RSA *rsa, int mdnid); diff --git a/providers/common/include/prov/bio.h b/providers/common/include/prov/bio.h index 63f9d4ec..732dc06f 100644 --- a/providers/common/include/prov/bio.h +++ b/providers/common/include/prov/bio.h @@ -10,13 +10,19 @@ #include #include #include +#include "prov/provider_ctx.h" int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns); -BIO *ossl_prov_bio_new_file(const char *filename, const char *mode); -BIO *ossl_prov_bio_new_membuf(const char *filename, int len); -int ossl_prov_bio_read_ex(BIO *bio, void *data, size_t data_len, +OSSL_CORE_BIO *ossl_prov_bio_new_file(const char *filename, const char *mode); +OSSL_CORE_BIO *ossl_prov_bio_new_membuf(const char *filename, int len); +int ossl_prov_bio_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len, size_t *bytes_read); -int ossl_prov_bio_free(BIO *bio); -int ossl_prov_bio_vprintf(BIO *bio, const char *format, va_list ap); -int ossl_prov_bio_printf(BIO *bio, const char *format, ...); +int ossl_prov_bio_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len, + size_t *written); +int ossl_prov_bio_free(OSSL_CORE_BIO *bio); +int ossl_prov_bio_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list ap); +int ossl_prov_bio_printf(OSSL_CORE_BIO *bio, const char *format, ...); + +BIO_METHOD *bio_prov_init_bio_method(void); +BIO *bio_new_from_core_bio(PROV_CTX *provctx, OSSL_CORE_BIO *corebio); diff --git a/providers/common/include/prov/provider_ctx.h b/providers/common/include/prov/provider_ctx.h index 365667d1..a252143e 100644 --- a/providers/common/include/prov/provider_ctx.h +++ b/providers/common/include/prov/provider_ctx.h @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,8 +7,34 @@ * https://www.openssl.org/source/license.html */ +#ifndef OSSL_PROV_PROVIDER_CTX_H +# define OSSL_PROV_PROVIDER_CTX_H + +# include +# include +# include +# include + +typedef struct prov_ctx_st { + const OSSL_CORE_HANDLE *handle; + OPENSSL_CTX *libctx; /* For all provider modules */ + BIO_METHOD *corebiometh; +} PROV_CTX; + /* * To be used anywhere the library context needs to be passed, such as to * fetching functions. */ -#define PROV_LIBRARY_CONTEXT_OF(provctx) (provctx) +# define PROV_LIBRARY_CONTEXT_OF(provctx) \ + PROV_CTX_get0_library_context((provctx)) + +PROV_CTX *PROV_CTX_new(void); +void PROV_CTX_free(PROV_CTX *ctx); +void PROV_CTX_set0_library_context(PROV_CTX *ctx, OPENSSL_CTX *libctx); +void PROV_CTX_set0_handle(PROV_CTX *ctx, const OSSL_CORE_HANDLE *handle); +void PROV_CTX_set0_core_bio_method(PROV_CTX *ctx, BIO_METHOD *corebiometh); +OPENSSL_CTX *PROV_CTX_get0_library_context(PROV_CTX *ctx); +const OSSL_CORE_HANDLE *PROV_CTX_get0_handle(PROV_CTX *ctx); +BIO_METHOD *PROV_CTX_get0_core_bio_method(PROV_CTX *ctx); + +#endif diff --git a/providers/common/include/prov/providercommon.h b/providers/common/include/prov/providercommon.h index 5123f78e..07c5a67f 100644 --- a/providers/common/include/prov/providercommon.h +++ b/providers/common/include/prov/providercommon.h @@ -9,7 +9,7 @@ #include -const OSSL_PROVIDER *FIPS_get_provider(OPENSSL_CTX *ctx); +const OSSL_CORE_HANDLE *FIPS_get_core_handle(OPENSSL_CTX *ctx); const char *ossl_prov_util_nid_to_name(int nid); diff --git a/providers/common/include/prov/providercommonerr.h b/providers/common/include/prov/providercommonerr.h index 5b3bcbb6..87bea503 100644 --- a/providers/common/include/prov/providercommonerr.h +++ b/providers/common/include/prov/providercommonerr.h @@ -10,6 +10,7 @@ #ifndef OPENSSL_PROVERR_H # define OPENSSL_PROVERR_H +# pragma once # include # include @@ -89,6 +90,7 @@ int ERR_load_PROV_strings(void); # define PROV_R_INVALID_PSS_SALTLEN 169 # define PROV_R_INVALID_SALT_LENGTH 112 # define PROV_R_INVALID_SEED_LENGTH 154 +# define PROV_R_INVALID_SIGNATURE_SIZE 179 # define PROV_R_INVALID_TAG 110 # define PROV_R_INVALID_TAGLEN 118 # define PROV_R_INVALID_X931_DIGEST 170 @@ -110,6 +112,7 @@ int ERR_load_PROV_strings(void); # define PROV_R_NOT_XOF_OR_INVALID_LENGTH 113 # define PROV_R_NO_KEY_SET 114 # define PROV_R_NO_PARAMETERS_SET 177 +# define PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 178 # define PROV_R_OUTPUT_BUFFER_TOO_SMALL 106 # define PROV_R_PSS_SALTLEN_TOO_SMALL 172 # define PROV_R_READ_KEY 159 diff --git a/providers/common/provider_ctx.c b/providers/common/provider_ctx.c new file mode 100644 index 00000000..04cca1f2 --- /dev/null +++ b/providers/common/provider_ctx.c @@ -0,0 +1,61 @@ +/* + * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include "prov/provider_ctx.h" +#include "prov/bio.h" + +PROV_CTX *PROV_CTX_new(void) +{ + return OPENSSL_zalloc(sizeof(PROV_CTX)); +} + +void PROV_CTX_free(PROV_CTX *ctx) +{ + OPENSSL_free(ctx); +} + +void PROV_CTX_set0_library_context(PROV_CTX *ctx, OPENSSL_CTX *libctx) +{ + if (ctx != NULL) + ctx->libctx = libctx; +} + +void PROV_CTX_set0_handle(PROV_CTX *ctx, const OSSL_CORE_HANDLE *handle) +{ + if (ctx != NULL) + ctx->handle = handle; +} + +void PROV_CTX_set0_core_bio_method(PROV_CTX *ctx, BIO_METHOD *corebiometh) +{ + if (ctx != NULL) + ctx->corebiometh = corebiometh; +} + +OPENSSL_CTX *PROV_CTX_get0_library_context(PROV_CTX *ctx) +{ + if (ctx == NULL) + return NULL; + return ctx->libctx; +} + +const OSSL_CORE_HANDLE *PROV_CTX_get0_handle(PROV_CTX *ctx) +{ + if (ctx == NULL) + return NULL; + return ctx->handle; +} + +BIO_METHOD *PROV_CTX_get0_core_bio_method(PROV_CTX *ctx) +{ + if (ctx == NULL) + return NULL; + return ctx->corebiometh; +} diff --git a/providers/common/provider_err.c b/providers/common/provider_err.c index 1018fa31..f79cdb0e 100644 --- a/providers/common/provider_err.c +++ b/providers/common/provider_err.c @@ -75,6 +75,8 @@ static const ERR_STRING_DATA PROV_str_reasons[] = { "invalid salt length"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_SEED_LENGTH), "invalid seed length"}, + {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_SIGNATURE_SIZE), + "invalid signature size"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_TAG), "invalid tag"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_TAGLEN), "invalid taglen"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_INVALID_X931_DIGEST), @@ -101,6 +103,8 @@ static const ERR_STRING_DATA PROV_str_reasons[] = { "not xof or invalid length"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_NO_KEY_SET), "no key set"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_NO_PARAMETERS_SET), "no parameters set"}, + {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE), + "operation not supported for this keytype"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_OUTPUT_BUFFER_TOO_SMALL), "output buffer too small"}, {ERR_PACK(ERR_LIB_PROV, 0, PROV_R_PSS_SALTLEN_TOO_SMALL), diff --git a/providers/common/provider_util.c b/providers/common/provider_util.c index a409d717..270609e9 100644 --- a/providers/common/provider_util.c +++ b/providers/common/provider_util.c @@ -46,7 +46,7 @@ static int load_common(const OSSL_PARAM params[], const char **propquery, *engine = NULL; /* TODO legacy stuff, to be removed */ /* Inside the FIPS module, we don't support legacy ciphers */ -#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE) +#if !defined(FIPS_MODULE) && !defined(OPENSSL_NO_ENGINE) p = OSSL_PARAM_locate_const(params, "engine"); if (p != NULL) { if (p->data_type != OSSL_PARAM_UTF8_STRING) @@ -80,7 +80,7 @@ int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc, ERR_set_mark(); pc->cipher = pc->alloc_cipher = EVP_CIPHER_fetch(ctx, p->data, propquery); /* TODO legacy stuff, to be removed */ -#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy ciphers */ +#ifndef FIPS_MODULE /* Inside the FIPS module, we don't support legacy ciphers */ if (pc->cipher == NULL) pc->cipher = EVP_get_cipherbyname(p->data); #endif @@ -140,7 +140,7 @@ int ossl_prov_digest_load_from_params(PROV_DIGEST *pd, ERR_set_mark(); pd->md = pd->alloc_md = EVP_MD_fetch(ctx, p->data, propquery); /* TODO legacy stuff, to be removed */ -#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy digests */ +#ifndef FIPS_MODULE /* Inside the FIPS module, we don't support legacy digests */ if (pd->md == NULL) pd->md = EVP_get_digestbyname(p->data); #endif @@ -231,7 +231,7 @@ int ossl_prov_macctx_load_from_params(EVP_MAC_CTX **macctx, *mp++ = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_PROPERTIES, (char *)properties, 0); -#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) if ((p = OSSL_PARAM_locate_const(params, "engine")) != NULL) { if (p->data_type != OSSL_PARAM_UTF8_STRING) return 0; diff --git a/providers/defltprov.c b/providers/defltprov.c index f26654ab..4b15a21c 100644 --- a/providers/defltprov.c +++ b/providers/defltprov.c @@ -15,11 +15,20 @@ #include #include #include "prov/bio.h" +#include "prov/provider_ctx.h" #include "prov/providercommon.h" #include "prov/implementations.h" #include "prov/provider_util.h" #include "internal/nelem.h" +/* + * Forward declarations to ensure that interface functions are correctly + * defined. + */ +static OSSL_provider_gettable_params_fn deflt_gettable_params; +static OSSL_provider_get_params_fn deflt_get_params; +static OSSL_provider_query_operation_fn deflt_query; + #define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK } #define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL) @@ -35,12 +44,12 @@ static const OSSL_PARAM deflt_param_types[] = { OSSL_PARAM_END }; -static const OSSL_PARAM *deflt_gettable_params(const OSSL_PROVIDER *prov) +static const OSSL_PARAM *deflt_gettable_params(void *provctx) { return deflt_param_types; } -static int deflt_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) +static int deflt_get_params(void *provctx, OSSL_PARAM params[]) { OSSL_PARAM *p; @@ -354,6 +363,7 @@ static const OSSL_ALGORITHM deflt_keymgmt[] = { { "DSA:dsaEncryption", "provider=default", dsa_keymgmt_functions }, #endif { "RSA:rsaEncryption", "provider=default", rsa_keymgmt_functions }, + { "RSA-PSS:RSASSA-PSS", "provider=default", rsapss_keymgmt_functions }, #ifndef OPENSSL_NO_EC { "EC:id-ecPublicKey", "provider=default", ec_keymgmt_functions }, { "X25519", "provider=default", x25519_keymgmt_functions }, @@ -382,6 +392,18 @@ static const OSSL_ALGORITHM deflt_serializer[] = { rsa_priv_pem_serializer_functions }, { "RSA", "provider=default,fips=yes,format=pem,type=public", rsa_pub_pem_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=text,type=private", + rsa_priv_text_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=text,type=public", + rsa_pub_text_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=der,type=private", + rsa_priv_der_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=der,type=public", + rsa_pub_der_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=pem,type=private", + rsa_priv_pem_serializer_functions }, + { "RSA-PSS", "provider=default,fips=yes,format=pem,type=public", + rsa_pub_pem_serializer_functions }, #ifndef OPENSSL_NO_DH { "DH", "provider=default,fips=yes,format=text,type=private", @@ -500,8 +522,7 @@ static const OSSL_ALGORITHM deflt_serializer[] = { { NULL, NULL, NULL } }; -static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov, - int operation_id, +static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id, int *no_cache) { *no_cache = 0; @@ -529,8 +550,15 @@ static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov, return NULL; } +static void deflt_teardown(void *provctx) +{ + BIO_meth_free(PROV_CTX_get0_core_bio_method(provctx)); + PROV_CTX_free(provctx); +} + /* Functions we provide to the core */ static const OSSL_DISPATCH deflt_dispatch_table[] = { + { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown }, { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params }, { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params }, { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query }, @@ -539,12 +567,13 @@ static const OSSL_DISPATCH deflt_dispatch_table[] = { OSSL_provider_init_fn ossl_default_provider_init; -int ossl_default_provider_init(const OSSL_PROVIDER *provider, +int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) { OSSL_core_get_library_context_fn *c_get_libctx = NULL; + BIO_METHOD *corebiometh; if (!ossl_prov_bio_from_dispatch(in)) return 0; @@ -568,13 +597,25 @@ int ossl_default_provider_init(const OSSL_PROVIDER *provider, if (c_get_libctx == NULL) return 0; - *out = deflt_dispatch_table; - /* * We want to make sure that all calls from this provider that requires * a library context use the same context as the one used to call our - * functions. We do that by passing it along as the provider context. + * functions. We do that by passing it along in the provider context. + * + * This only works for built-in providers. Most providers should + * create their own library context. */ - *provctx = c_get_libctx(provider); + if ((*provctx = PROV_CTX_new()) == NULL + || (corebiometh = bio_prov_init_bio_method()) == NULL) { + PROV_CTX_free(*provctx); + *provctx = NULL; + return 0; + } + PROV_CTX_set0_library_context(*provctx, (OPENSSL_CTX *)c_get_libctx(handle)); + PROV_CTX_set0_handle(*provctx, handle); + PROV_CTX_set0_core_bio_method(*provctx, corebiometh); + + *out = deflt_dispatch_table; + return 1; } diff --git a/providers/fips/fipsprov.c b/providers/fips/fipsprov.c index 98cccbf3..1c4f3fdf 100644 --- a/providers/fips/fipsprov.c +++ b/providers/fips/fipsprov.c @@ -34,6 +34,15 @@ #include "prov/provider_util.h" #include "self_test.h" +/* + * Forward declarations to ensure that interface functions are correctly + * defined. + */ +static OSSL_provider_teardown_fn fips_teardown; +static OSSL_provider_gettable_params_fn fips_gettable_params; +static OSSL_provider_get_params_fn fips_get_params; +static OSSL_provider_query_operation_fn fips_query; + #define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=fips,fips=yes", FUNC }, CHECK } #define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL) @@ -72,7 +81,7 @@ static OSSL_CRYPTO_secure_allocated_fn *c_CRYPTO_secure_allocated; static OSSL_BIO_vsnprintf_fn *c_BIO_vsnprintf; typedef struct fips_global_st { - const OSSL_PROVIDER *prov; + const OSSL_CORE_HANDLE *handle; } FIPS_GLOBAL; static void *fips_prov_ossl_ctx_new(OPENSSL_CTX *libctx) @@ -127,9 +136,8 @@ static OSSL_PARAM core_params[] = }; /* TODO(3.0): To be removed */ -static int dummy_evp_call(void *provctx) +static int dummy_evp_call(OPENSSL_CTX *libctx) { - OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx); EVP_MD_CTX *ctx = EVP_MD_CTX_new(); EVP_MD *sha256 = EVP_MD_fetch(libctx, "SHA256", NULL); EVP_KDF *kdf = EVP_KDF_fetch(libctx, OSSL_KDF_NAME_PBKDF2, NULL); @@ -208,12 +216,12 @@ static int dummy_evp_call(void *provctx) return ret; } -static const OSSL_PARAM *fips_gettable_params(const OSSL_PROVIDER *prov) +static const OSSL_PARAM *fips_gettable_params(void *provctx) { return fips_param_types; } -static int fips_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) +static int fips_get_params(void *provctx, OSSL_PARAM params[]) { OSSL_PARAM *p; @@ -233,7 +241,7 @@ static int fips_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) /* FIPS specific version of the function of the same name in provlib.c */ const char *ossl_prov_util_nid_to_name(int nid) { - /* We don't have OBJ_nid2n() in FIPS_MODE so we have an explicit list */ + /* We don't have OBJ_nid2n() in FIPS_MODULE so we have an explicit list */ switch (nid) { /* Digests */ @@ -469,6 +477,7 @@ static const OSSL_ALGORITHM fips_keymgmt[] = { { "DSA", "provider=fips,fips=yes", dsa_keymgmt_functions }, #endif { "RSA:rsaEncryption", "provider=fips,fips=yes", rsa_keymgmt_functions }, + { "RSA-PSS:RSASSA-PSS", "provider=default", rsapss_keymgmt_functions }, #ifndef OPENSSL_NO_EC { "EC:id-ecPublicKey", "provider=fips,fips=yes", ec_keymgmt_functions }, { "X25519", "provider=fips,fips=no", x25519_keymgmt_functions }, @@ -479,9 +488,8 @@ static const OSSL_ALGORITHM fips_keymgmt[] = { { NULL, NULL, NULL } }; -static const OSSL_ALGORITHM *fips_query(OSSL_PROVIDER *prov, - int operation_id, - int *no_cache) +static const OSSL_ALGORITHM *fips_query(void *provctx, int operation_id, + int *no_cache) { *no_cache = 0; switch (operation_id) { @@ -506,13 +514,24 @@ static const OSSL_ALGORITHM *fips_query(OSSL_PROVIDER *prov, return NULL; } +static void fips_teardown(void *provctx) +{ + OPENSSL_CTX_free(PROV_LIBRARY_CONTEXT_OF(provctx)); + PROV_CTX_free(provctx); +} + +static void fips_intern_teardown(void *provctx) +{ + /* + * We know that the library context is the same as for the outer provider, + * so no need to destroy it here. + */ + PROV_CTX_free(provctx); +} + /* Functions we provide to the core */ static const OSSL_DISPATCH fips_dispatch_table[] = { - /* - * To release our resources we just need to free the OPENSSL_CTX so we just - * use OPENSSL_CTX_free directly as our teardown function - */ - { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))OPENSSL_CTX_free }, + { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))fips_teardown }, { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))fips_gettable_params }, { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))fips_get_params }, { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query }, @@ -521,18 +540,19 @@ static const OSSL_DISPATCH fips_dispatch_table[] = { /* Functions we provide to ourself */ static const OSSL_DISPATCH intern_dispatch_table[] = { + { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))fips_intern_teardown }, { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query }, { 0, NULL } }; -int OSSL_provider_init(const OSSL_PROVIDER *provider, +int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) { FIPS_GLOBAL *fgbl; - OPENSSL_CTX *ctx; + OPENSSL_CTX *libctx = NULL; OSSL_self_test_cb_fn *stcbfn = NULL; OSSL_core_get_library_context_fn *c_get_libctx = NULL; @@ -627,7 +647,7 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider, } if (stcbfn != NULL && c_get_libctx != NULL) { - stcbfn(c_get_libctx(provider), &selftest_params.cb, + stcbfn(c_get_libctx(handle), &selftest_params.cb, &selftest_params.cb_arg); } else { @@ -635,39 +655,47 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider, selftest_params.cb_arg = NULL; } - if (!c_get_params(provider, core_params)) + if (!c_get_params(handle, core_params)) return 0; /* Create a context. */ - if ((ctx = OPENSSL_CTX_new()) == NULL) - return 0; - if ((fgbl = openssl_ctx_get_data(ctx, OPENSSL_CTX_FIPS_PROV_INDEX, - &fips_prov_ossl_ctx_method)) == NULL) { - OPENSSL_CTX_free(ctx); - return 0; + if ((*provctx = PROV_CTX_new()) == NULL + || (libctx = OPENSSL_CTX_new()) == NULL) { + /* + * We free libctx separately here and only here because it hasn't + * been attached to *provctx. All other error paths below rely + * solely on fips_teardown. + */ + OPENSSL_CTX_free(libctx); + goto err; } + PROV_CTX_set0_library_context(*provctx, libctx); + PROV_CTX_set0_handle(*provctx, handle); - fgbl->prov = provider; + if ((fgbl = openssl_ctx_get_data(libctx, OPENSSL_CTX_FIPS_PROV_INDEX, + &fips_prov_ossl_ctx_method)) == NULL) + goto err; - selftest_params.libctx = PROV_LIBRARY_CONTEXT_OF(ctx); - if (!SELF_TEST_post(&selftest_params, 0)) { - OPENSSL_CTX_free(ctx); - return 0; - } + fgbl->handle = handle; + + selftest_params.libctx = libctx; + if (!SELF_TEST_post(&selftest_params, 0)) + goto err; /* * TODO(3.0): Remove me. This is just a dummy call to demonstrate making * EVP calls from within the FIPS module. */ - if (!dummy_evp_call(ctx)) { - OPENSSL_CTX_free(ctx); - return 0; - } + if (!dummy_evp_call(libctx)) + goto err; *out = fips_dispatch_table; - *provctx = ctx; return 1; + err: + fips_teardown(*provctx); + *provctx = NULL; + return 0; } /* @@ -678,7 +706,7 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider, * that was used in the EVP call that initiated this recursive call. */ OSSL_provider_init_fn fips_intern_provider_init; -int fips_intern_provider_init(const OSSL_PROVIDER *provider, +int fips_intern_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) @@ -698,14 +726,15 @@ int fips_intern_provider_init(const OSSL_PROVIDER *provider, if (c_get_libctx == NULL) return 0; - *provctx = c_get_libctx(provider); - - /* - * Safety measure... we should get the library context that was - * created up in OSSL_provider_init(). - */ - if (*provctx == NULL) + if ((*provctx = PROV_CTX_new()) == NULL) return 0; + /* + * Using the parent library context only works because we are a built-in + * internal provider. This is not something that most providers would be + * able to do. + */ + PROV_CTX_set0_library_context(*provctx, (OPENSSL_CTX *)c_get_libctx(handle)); + PROV_CTX_set0_handle(*provctx, handle); *out = intern_dispatch_table; return 1; @@ -750,15 +779,23 @@ int ERR_pop_to_mark(void) return c_pop_error_to_mark(NULL); } -const OSSL_PROVIDER *FIPS_get_provider(OPENSSL_CTX *ctx) +/* + * This must take a library context, since it's called from the depths + * of crypto/initthread.c code, where it's (correctly) assumed that the + * passed caller argument is an OPENSSL_CTX pointer (since the same routine + * is also called from other parts of libcrypto, which all pass around a + * OPENSSL_CTX pointer) + */ +const OSSL_CORE_HANDLE *FIPS_get_core_handle(OPENSSL_CTX *libctx) { - FIPS_GLOBAL *fgbl = openssl_ctx_get_data(ctx, OPENSSL_CTX_FIPS_PROV_INDEX, + FIPS_GLOBAL *fgbl = openssl_ctx_get_data(libctx, + OPENSSL_CTX_FIPS_PROV_INDEX, &fips_prov_ossl_ctx_method); if (fgbl == NULL) return NULL; - return fgbl->prov; + return fgbl->handle; } void *CRYPTO_malloc(size_t num, const char *file, int line) diff --git a/providers/fips/self_test.c b/providers/fips/self_test.c index ccc01bd3..b767e8f3 100644 --- a/providers/fips/self_test.c +++ b/providers/fips/self_test.c @@ -1,7 +1,7 @@ /* * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -130,7 +130,7 @@ DEP_FINI_ATTRIBUTE void cleanup(void) * the result matches the expected value. * Return 1 if verified, or 0 if it fails. */ -static int verify_integrity(BIO *bio, OSSL_BIO_read_ex_fn read_ex_cb, +static int verify_integrity(OSSL_CORE_BIO *bio, OSSL_BIO_read_ex_fn read_ex_cb, unsigned char *expected, size_t expected_len, OPENSSL_CTX *libctx, OSSL_SELF_TEST *ev, const char *event_type) @@ -188,7 +188,7 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test) int ok = 0; int kats_already_passed = 0; long checksum_len; - BIO *bio_module = NULL, *bio_indicator = NULL; + OSSL_CORE_BIO *bio_module = NULL, *bio_indicator = NULL; unsigned char *module_checksum = NULL; unsigned char *indicator_checksum = NULL; int loclstate; diff --git a/providers/fips/self_test.h b/providers/fips/self_test.h index 7367e96a..ad693aa9 100644 --- a/providers/fips/self_test.h +++ b/providers/fips/self_test.h @@ -1,7 +1,7 @@ /* * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/providers/fips/self_test_data.inc b/providers/fips/self_test_data.inc index 43de2aa3..431e5246 100644 --- a/providers/fips/self_test_data.inc +++ b/providers/fips/self_test_data.inc @@ -1,7 +1,7 @@ /* * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/providers/fips/self_test_kats.c b/providers/fips/self_test_kats.c index f02dbcd8..5ef4474a 100644 --- a/providers/fips/self_test_kats.c +++ b/providers/fips/self_test_kats.c @@ -1,7 +1,7 @@ /* * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/providers/implementations/asymciphers/rsa_enc.c b/providers/implementations/asymciphers/rsa_enc.c index f9f75850..dde63852 100644 --- a/providers/implementations/asymciphers/rsa_enc.c +++ b/providers/implementations/asymciphers/rsa_enc.c @@ -89,7 +89,16 @@ static int rsa_init(void *vprsactx, void *vrsa) return 0; RSA_free(prsactx->rsa); prsactx->rsa = vrsa; - prsactx->pad_mode = RSA_PKCS1_PADDING; + + switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) { + case RSA_FLAG_TYPE_RSA: + prsactx->pad_mode = RSA_PKCS1_PADDING; + break; + default: + ERR_raise(ERR_LIB_PROV, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + return 0; + } + return 1; } diff --git a/providers/implementations/ciphers/cipher_aes_ocb.c b/providers/implementations/ciphers/cipher_aes_ocb.c index 8d7f8956..859f3524 100644 --- a/providers/implementations/ciphers/cipher_aes_ocb.c +++ b/providers/implementations/ciphers/cipher_aes_ocb.c @@ -153,7 +153,7 @@ static int aes_ocb_block_update_internal(PROV_AES_OCB_CTX *ctx, size_t nextblocks; size_t outlint = 0; - if (bufsz != 0) + if (*bufsz != 0) nextblocks = fillblock(buf, bufsz, AES_BLOCK_SIZE, &in, &inl); else nextblocks = inl & ~(AES_BLOCK_SIZE-1); diff --git a/providers/implementations/ciphers/cipher_aes_xts_fips.c b/providers/implementations/ciphers/cipher_aes_xts_fips.c index 7c8f40ac..b294bdec 100644 --- a/providers/implementations/ciphers/cipher_aes_xts_fips.c +++ b/providers/implementations/ciphers/cipher_aes_xts_fips.c @@ -16,8 +16,8 @@ #include "cipher_aes_xts.h" -#ifdef FIPS_MODE +#ifdef FIPS_MODULE const int allow_insecure_decrypt = 0; #else const int allow_insecure_decrypt = 1; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ diff --git a/providers/implementations/ciphers/cipher_cast5.c b/providers/implementations/ciphers/cipher_cast5.c index a9da32e7..566583d1 100644 --- a/providers/implementations/ciphers/cipher_cast5.c +++ b/providers/implementations/ciphers/cipher_cast5.c @@ -49,7 +49,7 @@ static void *cast5_dupctx(void *ctx) IMPLEMENT_var_keylen_cipher(cast5, CAST, ecb, ECB, CAST5_FLAGS, 128, 64, 0, block) /* cast5128cbc_functions */ IMPLEMENT_var_keylen_cipher(cast5, CAST, cbc, CBC, CAST5_FLAGS, 128, 64, 64, block) -/* cast564ofb64_functions */ -IMPLEMENT_var_keylen_cipher(cast5, CAST, ofb64, OFB, CAST5_FLAGS, 64, 8, 64, stream) -/* cast564cfb64_functions */ -IMPLEMENT_var_keylen_cipher(cast5, CAST, cfb64, CFB, CAST5_FLAGS, 64, 8, 64, stream) +/* cast5128ofb64_functions */ +IMPLEMENT_var_keylen_cipher(cast5, CAST, ofb64, OFB, CAST5_FLAGS, 128, 8, 64, stream) +/* cast5128cfb64_functions */ +IMPLEMENT_var_keylen_cipher(cast5, CAST, cfb64, CFB, CAST5_FLAGS, 128, 8, 64, stream) diff --git a/providers/implementations/ciphers/cipher_des_hw.c b/providers/implementations/ciphers/cipher_des_hw.c index 7181c229..f52bade4 100644 --- a/providers/implementations/ciphers/cipher_des_hw.c +++ b/providers/implementations/ciphers/cipher_des_hw.c @@ -65,7 +65,13 @@ static int cipher_hw_des_ecb_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out, static int cipher_hw_des_cbc_cipher(PROV_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t len) { - DES_key_schedule *key = &(((PROV_DES_CTX *)ctx)->dks.ks); + PROV_DES_CTX *dctx = (PROV_DES_CTX *)ctx; + DES_key_schedule *key = &(dctx->dks.ks); + + if (dctx->dstream.cbc != NULL) { + (*dctx->dstream.cbc) (in, out, len, key, ctx->iv); + return 1; + } while (len >= MAXCHUNK) { DES_ncbc_encrypt(in, out, MAXCHUNK, key, (DES_cblock *)ctx->iv, diff --git a/providers/implementations/exchange/ecdh_exch.c b/providers/implementations/exchange/ecdh_exch.c index 7293e0b9..ae0720d9 100644 --- a/providers/implementations/exchange/ecdh_exch.c +++ b/providers/implementations/exchange/ecdh_exch.c @@ -458,7 +458,7 @@ int ecdh_plain_derive(void *vpecdhctx, unsigned char *secret, return ret; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE static ossl_inline int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret, size_t *psecretlen, size_t outlen) @@ -498,7 +498,7 @@ int ecdh_X9_63_kdf_derive(void *vpecdhctx, unsigned char *secret, OPENSSL_secure_clear_free(stmp, stmplen); return ret; } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ static int ecdh_derive(void *vpecdhctx, unsigned char *secret, @@ -509,11 +509,11 @@ int ecdh_derive(void *vpecdhctx, unsigned char *secret, switch (pecdhctx->kdf_type) { case PROV_ECDH_KDF_NONE: return ecdh_plain_derive(vpecdhctx, secret, psecretlen, outlen); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE case PROV_ECDH_KDF_X9_63: return ecdh_X9_63_kdf_derive(vpecdhctx, secret, psecretlen, outlen); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ default: break; } diff --git a/providers/implementations/include/prov/implementations.h b/providers/implementations/include/prov/implementations.h index 9b5017a1..0589a6e9 100644 --- a/providers/implementations/include/prov/implementations.h +++ b/providers/implementations/include/prov/implementations.h @@ -148,8 +148,8 @@ extern const OSSL_DISPATCH idea128cfb64_functions[]; #ifndef OPENSSL_NO_CAST extern const OSSL_DISPATCH cast5128ecb_functions[]; extern const OSSL_DISPATCH cast5128cbc_functions[]; -extern const OSSL_DISPATCH cast564ofb64_functions[]; -extern const OSSL_DISPATCH cast564cfb64_functions[]; +extern const OSSL_DISPATCH cast5128ofb64_functions[]; +extern const OSSL_DISPATCH cast5128cfb64_functions[]; #endif /* OPENSSL_NO_CAST */ #ifndef OPENSSL_NO_SEED extern const OSSL_DISPATCH seed128ecb_functions[]; @@ -181,7 +181,7 @@ extern const OSSL_DISPATCH rc2128ofb128_functions[]; #ifndef OPENSSL_NO_DES extern const OSSL_DISPATCH tdes_ede3_ecb_functions[]; extern const OSSL_DISPATCH tdes_ede3_cbc_functions[]; -# ifndef FIPS_MODE +# ifndef FIPS_MODULE extern const OSSL_DISPATCH tdes_ede3_ofb_functions[]; extern const OSSL_DISPATCH tdes_ede3_cfb_functions[]; extern const OSSL_DISPATCH tdes_ede3_cfb8_functions[]; @@ -201,7 +201,7 @@ extern const OSSL_DISPATCH des_ofb64_functions[]; extern const OSSL_DISPATCH des_cfb64_functions[]; extern const OSSL_DISPATCH des_cfb1_functions[]; extern const OSSL_DISPATCH des_cfb8_functions[]; -# endif /* FIPS_MODE */ +# endif /* FIPS_MODULE */ #endif /* OPENSSL_NO_DES */ #ifndef OPENSSL_NO_RC4 @@ -257,6 +257,7 @@ extern const OSSL_DISPATCH kdf_krb5kdf_functions[]; extern const OSSL_DISPATCH dh_keymgmt_functions[]; extern const OSSL_DISPATCH dsa_keymgmt_functions[]; extern const OSSL_DISPATCH rsa_keymgmt_functions[]; +extern const OSSL_DISPATCH rsapss_keymgmt_functions[]; extern const OSSL_DISPATCH x25519_keymgmt_functions[]; extern const OSSL_DISPATCH x448_keymgmt_functions[]; extern const OSSL_DISPATCH ed25519_keymgmt_functions[]; diff --git a/providers/implementations/kdfs/krb5kdf.c b/providers/implementations/kdfs/krb5kdf.c index 59711eef..0a97b8e3 100644 --- a/providers/implementations/kdfs/krb5kdf.c +++ b/providers/implementations/kdfs/krb5kdf.c @@ -1,7 +1,7 @@ /* * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/providers/implementations/kdfs/pbkdf2_fips.c b/providers/implementations/kdfs/pbkdf2_fips.c index d33782b2..be60be1f 100644 --- a/providers/implementations/kdfs/pbkdf2_fips.c +++ b/providers/implementations/kdfs/pbkdf2_fips.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,8 +13,8 @@ * For backwards compatibility reasons, * Extra checks are done by default in fips mode only. */ -#ifdef FIPS_MODE +#ifdef FIPS_MODULE const int kdf_pbkdf2_default_checks = 1; #else const int kdf_pbkdf2_default_checks = 0; -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ diff --git a/providers/implementations/kdfs/sshkdf.c b/providers/implementations/kdfs/sshkdf.c index 508fb635..4ba9a164 100644 --- a/providers/implementations/kdfs/sshkdf.c +++ b/providers/implementations/kdfs/sshkdf.c @@ -1,7 +1,7 @@ /* - * Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/providers/implementations/keymgmt/dh_kmgmt.c b/providers/implementations/keymgmt/dh_kmgmt.c index f09654c0..a551a72d 100644 --- a/providers/implementations/keymgmt/dh_kmgmt.c +++ b/providers/implementations/keymgmt/dh_kmgmt.c @@ -322,6 +322,8 @@ static int dh_validate_public(DH *dh) const BIGNUM *pub_key = NULL; DH_get0_key(dh, &pub_key, NULL); + if (pub_key == NULL) + return 0; return DH_check_pub_key_ex(dh, pub_key); } @@ -331,6 +333,8 @@ static int dh_validate_private(DH *dh) const BIGNUM *priv_key = NULL; DH_get0_key(dh, NULL, &priv_key); + if (priv_key == NULL) + return 0; return dh_check_priv_key(dh, priv_key, &status);; } diff --git a/providers/implementations/keymgmt/dsa_kmgmt.c b/providers/implementations/keymgmt/dsa_kmgmt.c index 12610352..de54b9a3 100644 --- a/providers/implementations/keymgmt/dsa_kmgmt.c +++ b/providers/implementations/keymgmt/dsa_kmgmt.c @@ -312,6 +312,8 @@ static int dsa_validate_public(DSA *dsa) const BIGNUM *pub_key = NULL; DSA_get0_key(dsa, &pub_key, NULL); + if (pub_key == NULL) + return 0; return dsa_check_pub_key(dsa, pub_key, &status); } @@ -321,6 +323,8 @@ static int dsa_validate_private(DSA *dsa) const BIGNUM *priv_key = NULL; DSA_get0_key(dsa, NULL, &priv_key); + if (priv_key == NULL) + return 0; return dsa_check_priv_key(dsa, priv_key, &status); } diff --git a/providers/implementations/keymgmt/ec_kmgmt.c b/providers/implementations/keymgmt/ec_kmgmt.c index 9466b4fd..a48b2795 100644 --- a/providers/implementations/keymgmt/ec_kmgmt.c +++ b/providers/implementations/keymgmt/ec_kmgmt.c @@ -31,8 +31,6 @@ static OSSL_OP_keymgmt_gen_init_fn ec_gen_init; static OSSL_OP_keymgmt_gen_set_template_fn ec_gen_set_template; static OSSL_OP_keymgmt_gen_set_params_fn ec_gen_set_params; static OSSL_OP_keymgmt_gen_settable_params_fn ec_gen_settable_params; -static OSSL_OP_keymgmt_gen_get_params_fn ec_gen_get_params; -static OSSL_OP_keymgmt_gen_gettable_params_fn ec_gen_gettable_params; static OSSL_OP_keymgmt_gen_fn ec_gen; static OSSL_OP_keymgmt_gen_cleanup_fn ec_gen_cleanup; static OSSL_OP_keymgmt_free_fn ec_freedata; @@ -679,39 +677,6 @@ static const OSSL_PARAM *ec_gen_settable_params(void *provctx) return settable; } -static int ec_gen_get_params(void *genctx, OSSL_PARAM params[]) -{ - struct ec_gen_ctx *gctx = genctx; - OSSL_PARAM *p; - - if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_EC_NAME)) != NULL) { - int nid = EC_GROUP_get_curve_name(gctx->gen_group); - int ret = 0; - const char *curve_name = ec_curve_nid2name(nid); - - switch (p->data_type) { - case OSSL_PARAM_UTF8_STRING: - ret = OSSL_PARAM_set_utf8_string(p, curve_name); - break; - case OSSL_PARAM_UTF8_PTR: - ret = OSSL_PARAM_set_utf8_ptr(p, curve_name); - break; - } - return ret; - } - return 1; -} - -static const OSSL_PARAM *ec_gen_gettable_params(void *provctx) -{ - static OSSL_PARAM gettable[] = { - { OSSL_PKEY_PARAM_EC_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0, 0 }, - OSSL_PARAM_END - }; - - return gettable; -} - static int ec_gen_assign_group(EC_KEY *ec, EC_GROUP *group) { if (group == NULL) { @@ -767,9 +732,6 @@ const OSSL_DISPATCH ec_keymgmt_functions[] = { { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))ec_gen_set_params }, { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, (void (*)(void))ec_gen_settable_params }, - { OSSL_FUNC_KEYMGMT_GEN_GET_PARAMS, (void (*)(void))ec_gen_get_params }, - { OSSL_FUNC_KEYMGMT_GEN_GETTABLE_PARAMS, - (void (*)(void))ec_gen_gettable_params }, { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))ec_gen }, { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))ec_gen_cleanup }, { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))ec_freedata }, diff --git a/providers/implementations/keymgmt/ecx_kmgmt.c b/providers/implementations/keymgmt/ecx_kmgmt.c index 2ba8f53e..e2b613e5 100644 --- a/providers/implementations/keymgmt/ecx_kmgmt.c +++ b/providers/implementations/keymgmt/ecx_kmgmt.c @@ -47,6 +47,7 @@ static OSSL_OP_keymgmt_gettable_params_fn x448_gettable_params; static OSSL_OP_keymgmt_gettable_params_fn ed25519_gettable_params; static OSSL_OP_keymgmt_gettable_params_fn ed448_gettable_params; static OSSL_OP_keymgmt_has_fn ecx_has; +static OSSL_OP_keymgmt_match_fn ecx_match; static OSSL_OP_keymgmt_import_fn ecx_import; static OSSL_OP_keymgmt_import_types_fn ecx_imexport_types; static OSSL_OP_keymgmt_export_fn ecx_export; @@ -68,22 +69,22 @@ static void *s390x_ecd_keygen448(struct ecx_gen_ctx *gctx); static void *x25519_new_key(void *provctx) { - return ecx_key_new(ECX_KEY_TYPE_X25519, 0); + return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_X25519, 0); } static void *x448_new_key(void *provctx) { - return ecx_key_new(ECX_KEY_TYPE_X448, 0); + return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_X448, 0); } static void *ed25519_new_key(void *provctx) { - return ecx_key_new(ECX_KEY_TYPE_ED25519, 0); + return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_ED25519, 0); } static void *ed448_new_key(void *provctx) { - return ecx_key_new(ECX_KEY_TYPE_ED448, 0); + return ecx_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), ECX_KEY_TYPE_ED448, 0); } static int ecx_has(void *keydata, int selection) @@ -104,6 +105,36 @@ static int ecx_has(void *keydata, int selection) return ok; } +static int ecx_match(const void *keydata1, const void *keydata2, int selection) +{ + const ECX_KEY *key1 = keydata1; + const ECX_KEY *key2 = keydata2; + int ok = 1; + + if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) + ok = ok && key1->type == key2->type; + if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { + if ((key1->privkey == NULL && key2->privkey != NULL) + || (key1->privkey != NULL && key2->privkey == NULL) + || key1->type != key2->type) + ok = 0; + else + ok = ok && (key1->privkey == NULL /* implies key2->privkey == NULL */ + || CRYPTO_memcmp(key1->privkey, key2->privkey, + key1->keylen) == 0); + } + if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) { + if (key1->haspubkey != key2->haspubkey + || key1->type != key2->type) + ok = 0; + else + ok = ok && (key1->haspubkey == 0 /* implies key2->haspubkey == 0 */ + || CRYPTO_memcmp(key1->pubkey, key2->pubkey, + key1->keylen) == 0); + } + return ok; +} + static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[]) { ECX_KEY *key = keydata; @@ -113,12 +144,11 @@ static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[]) if (key == NULL) return 0; - if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0) + if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0) return 0; include_private = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0); - if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) - ok = ok && ecx_key_fromdata(key, params, include_private); + ok = ok && ecx_key_fromdata(key, params, include_private); return ok; } @@ -162,10 +192,6 @@ static int ecx_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, && !key_to_params(key, tmpl, NULL)) goto err; - if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0 - && !key_to_params(key, tmpl, NULL)) - goto err; - params = OSSL_PARAM_BLD_to_param(tmpl); if (params == NULL) goto err; @@ -326,7 +352,7 @@ static void *ecx_gen(struct ecx_gen_ctx *gctx) if (gctx == NULL) return NULL; - if ((key = ecx_key_new(gctx->type, 0)) == NULL) { + if ((key = ecx_key_new(gctx->libctx, gctx->type, 0)) == NULL) { ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); return NULL; } @@ -425,6 +451,7 @@ static void ecx_gen_cleanup(void *genctx) { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))alg##_get_params }, \ { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))alg##_gettable_params }, \ { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))ecx_has }, \ + { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))ecx_match }, \ { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ecx_import }, \ { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))ecx_imexport_types }, \ { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))ecx_export }, \ @@ -450,7 +477,7 @@ static void *s390x_ecx_keygen25519(struct ecx_gen_ctx *gctx) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X25519, 1); + ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_X25519, 1); unsigned char *privkey = NULL, *pubkey; if (key == NULL) { @@ -490,7 +517,7 @@ static void *s390x_ecx_keygen448(struct ecx_gen_ctx *gctx) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_X448, 1); + ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_X448, 1); unsigned char *privkey = NULL, *pubkey; if (key == NULL) { @@ -533,7 +560,7 @@ static void *s390x_ecd_keygen25519(struct ecx_gen_ctx *gctx) 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, }; unsigned char x_dst[32], buff[SHA512_DIGEST_LENGTH]; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED25519, 1); + ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_ED25519, 1); unsigned char *privkey = NULL, *pubkey; unsigned int sz; EVP_MD *sha = NULL; @@ -595,7 +622,7 @@ static void *s390x_ecd_keygen448(struct ecx_gen_ctx *gctx) 0x24, 0xbc, 0xb6, 0x6e, 0x71, 0x46, 0x3f, 0x69, 0x00 }; unsigned char x_dst[57], buff[114]; - ECX_KEY *key = ecx_key_new(ECX_KEY_TYPE_ED448, 1); + ECX_KEY *key = ecx_key_new(gctx->libctx, ECX_KEY_TYPE_ED448, 1); unsigned char *privkey = NULL, *pubkey; EVP_MD_CTX *hashctx = NULL; EVP_MD *shake = NULL; diff --git a/providers/implementations/keymgmt/rsa_kmgmt.c b/providers/implementations/keymgmt/rsa_kmgmt.c index f117d990..53982e7d 100644 --- a/providers/implementations/keymgmt/rsa_kmgmt.c +++ b/providers/implementations/keymgmt/rsa_kmgmt.c @@ -20,9 +20,12 @@ #include "internal/param_build_set.h" static OSSL_OP_keymgmt_new_fn rsa_newdata; +static OSSL_OP_keymgmt_new_fn rsapss_newdata; static OSSL_OP_keymgmt_gen_init_fn rsa_gen_init; +static OSSL_OP_keymgmt_gen_init_fn rsapss_gen_init; static OSSL_OP_keymgmt_gen_set_params_fn rsa_gen_set_params; static OSSL_OP_keymgmt_gen_settable_params_fn rsa_gen_settable_params; +static OSSL_OP_keymgmt_gen_settable_params_fn rsapss_gen_settable_params; static OSSL_OP_keymgmt_gen_fn rsa_gen; static OSSL_OP_keymgmt_gen_cleanup_fn rsa_gen_cleanup; static OSSL_OP_keymgmt_free_fn rsa_freedata; @@ -35,51 +38,53 @@ static OSSL_OP_keymgmt_import_fn rsa_import; static OSSL_OP_keymgmt_import_types_fn rsa_import_types; static OSSL_OP_keymgmt_export_fn rsa_export; static OSSL_OP_keymgmt_export_types_fn rsa_export_types; +static OSSL_OP_keymgmt_query_operation_name_fn rsapss_query_operation_name; #define RSA_DEFAULT_MD "SHA256" -#define RSA_POSSIBLE_SELECTIONS \ +#define RSA_PSS_DEFAULT_MD OSSL_DIGEST_NAME_SHA1 +#define RSA_POSSIBLE_SELECTIONS \ (OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) DEFINE_STACK_OF(BIGNUM) DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM) -static int key_to_params(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]) +static int pss_params_fromdata(RSA_PSS_PARAMS_30 *pss_params, + const OSSL_PARAM params[], int rsa_type, + OPENSSL_CTX *libctx) { - int ret = 0; - const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL; - STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null(); - STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null(); - STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null(); + if (!rsa_pss_params_30_fromdata(pss_params, params, libctx)) + return 0; - if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL) - goto err; + /* If not a PSS type RSA, sending us PSS parameters is wrong */ + if (rsa_type != RSA_FLAG_TYPE_RSASSAPSS + && !rsa_pss_params_30_is_unrestricted(pss_params)) + return 0; - RSA_get0_key(rsa, &rsa_n, &rsa_e, &rsa_d); - rsa_get0_all_params(rsa, factors, exps, coeffs); - - if (!ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_N, rsa_n) - || !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_E, rsa_e) - || !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_RSA_D, rsa_d) - || !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_factor_names, - factors) - || !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_exp_names, - exps) - || !ossl_param_build_set_multi_key_bn(bld, params, rsa_mp_coeff_names, - coeffs)) - goto err; - ret = 1; - err: - sk_BIGNUM_const_free(factors); - sk_BIGNUM_const_free(exps); - sk_BIGNUM_const_free(coeffs); - return ret; + return 1; } static void *rsa_newdata(void *provctx) { OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx); + RSA *rsa = rsa_new_with_ctx(libctx); - return rsa_new_with_ctx(libctx); + if (rsa != NULL) { + RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK); + RSA_set_flags(rsa, RSA_FLAG_TYPE_RSA); + } + return rsa; +} + +static void *rsapss_newdata(void *provctx) +{ + OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx); + RSA *rsa = rsa_new_with_ctx(libctx); + + if (rsa != NULL) { + RSA_clear_flags(rsa, RSA_FLAG_TYPE_MASK); + RSA_set_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS); + } + return rsa; } static void rsa_freedata(void *keydata) @@ -97,7 +102,8 @@ static int rsa_has(void *keydata, int selection) ok = 1; if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0) - ok = ok && 0; /* This will change with PSS and OAEP */ + /* This will change with OAEP */ + ok = ok && (RSA_test_flags(rsa, RSA_FLAG_TYPE_RSASSAPSS) != 0); if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) ok = ok && (RSA_get0_e(rsa) != NULL); if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) @@ -126,13 +132,22 @@ static int rsa_match(const void *keydata1, const void *keydata2, int selection) static int rsa_import(void *keydata, int selection, const OSSL_PARAM params[]) { RSA *rsa = keydata; + int rsa_type; int ok = 1; if (rsa == NULL) return 0; - /* TODO(3.0) PSS and OAEP should bring on parameters */ + if ((selection & RSA_POSSIBLE_SELECTIONS) == 0) + return 0; + rsa_type = RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK); + + /* TODO(3.0) OAEP should bring on parameters as well */ + + if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0) + ok = ok && pss_params_fromdata(rsa_get0_pss_params_30(rsa), params, + rsa_type, rsa_get0_libctx(rsa)); if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) ok = ok && rsa_fromdata(rsa, params); @@ -143,6 +158,7 @@ static int rsa_export(void *keydata, int selection, OSSL_CALLBACK *param_callback, void *cbarg) { RSA *rsa = keydata; + const RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa); OSSL_PARAM_BLD *tmpl; OSSL_PARAM *params = NULL; int ok = 1; @@ -150,14 +166,17 @@ static int rsa_export(void *keydata, int selection, if (rsa == NULL) return 0; - /* TODO(3.0) PSS and OAEP should bring on parameters */ + /* TODO(3.0) OAEP should bring on parameters */ tmpl = OSSL_PARAM_BLD_new(); if (tmpl == NULL) return 0; + if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0) + ok = ok && (rsa_pss_params_30_is_unrestricted(pss_params) + || rsa_pss_params_30_todata(pss_params, NULL, tmpl, NULL)); if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) - ok = ok && key_to_params(rsa, tmpl, NULL); + ok = ok && rsa_todata(rsa, tmpl, NULL); if (!ok || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) @@ -170,7 +189,7 @@ err: return ok; } -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* In fips mode there are no multi-primes. */ # define RSA_KEY_MP_TYPES() \ OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0), \ @@ -259,6 +278,8 @@ static const OSSL_PARAM *rsa_export_types(int selection) static int rsa_get_params(void *key, OSSL_PARAM params[]) { RSA *rsa = key; + const RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa); + int rsa_type = RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK); OSSL_PARAM *p; if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL @@ -271,32 +292,36 @@ static int rsa_get_params(void *key, OSSL_PARAM params[]) && !OSSL_PARAM_set_int(p, RSA_size(rsa))) return 0; -# if 0 /* TODO(3.0): PSS support pending */ - if ((p = OSSL_PARAM_locate(params, - OSSL_PKEY_PARAM_MANDATORY_DIGEST)) != NULL - && RSA_get0_pss_params(rsa) != NULL) { - const EVP_MD *md, *mgf1md; - int min_saltlen; - - if (!rsa_pss_get_param(RSA_get0_pss_params(rsa), - &md, &mgf1md, &min_saltlen)) { - ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); - return 0; - } - if (!OSSL_PARAM_set_utf8_string(p, EVP_MD_name(md))) - return 0; - } -#endif + /* + * For RSA-PSS keys, we ignore the default digest request + * TODO(3.0) with RSA-OAEP keys, this may need to be amended + */ if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL -/* TODO(3.0): PSS support pending */ -#if 0 - && RSA_get0_pss_params(rsa) == NULL -#endif - ) { + && rsa_type != RSA_FLAG_TYPE_RSASSAPSS) { if (!OSSL_PARAM_set_utf8_string(p, RSA_DEFAULT_MD)) return 0; } - return key_to_params(rsa, NULL, params); + + /* + * For non-RSA-PSS keys, we ignore the mandatory digest request + * TODO(3.0) with RSA-OAEP keys, this may need to be amended + */ + if ((p = OSSL_PARAM_locate(params, + OSSL_PKEY_PARAM_MANDATORY_DIGEST)) != NULL + && rsa_type == RSA_FLAG_TYPE_RSASSAPSS) { + const char *mdname = RSA_PSS_DEFAULT_MD; + + if (!rsa_pss_params_30_is_unrestricted(pss_params)) { + mdname = + rsa_oaeppss_nid2name(rsa_pss_params_30_hashalg(pss_params)); + + if (mdname == NULL || !OSSL_PARAM_set_utf8_string(p, mdname)) + return 0; + } + } + return (rsa_type != RSA_FLAG_TYPE_RSASSAPSS + || rsa_pss_params_30_todata(pss_params, NULL, NULL, params)) + && rsa_todata(rsa, NULL, params); } static const OSSL_PARAM rsa_params[] = { @@ -337,10 +362,15 @@ static int rsa_validate(void *keydata, int selection) struct rsa_gen_ctx { OPENSSL_CTX *libctx; + int rsa_type; + size_t nbits; BIGNUM *pub_exp; size_t primes; + /* For PSS */ + RSA_PSS_PARAMS_30 pss_params; + /* For generation callback */ OSSL_CALLBACK *cb; void *cbarg; @@ -357,7 +387,7 @@ static int rsa_gencb(int p, int n, BN_GENCB *cb) return gctx->cb(params, gctx->cbarg); } -static void *rsa_gen_init(void *provctx, int selection) +static void *gen_init(void *provctx, int selection, int rsa_type) { OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx); struct rsa_gen_ctx *gctx = NULL; @@ -370,15 +400,32 @@ static void *rsa_gen_init(void *provctx, int selection) if ((gctx->pub_exp = BN_new()) == NULL || !BN_set_word(gctx->pub_exp, RSA_F4)) { BN_free(gctx->pub_exp); + OPENSSL_free(gctx); gctx = NULL; } else { gctx->nbits = 2048; gctx->primes = RSA_DEFAULT_PRIME_NUM; } + gctx->rsa_type = rsa_type; } return gctx; } +static void *rsa_gen_init(void *provctx, int selection) +{ + return gen_init(provctx, selection, RSA_FLAG_TYPE_RSA); +} + +static void *rsapss_gen_init(void *provctx, int selection) +{ + return gen_init(provctx, selection, RSA_FLAG_TYPE_RSASSAPSS); +} + +/* + * This function is common for all RSA sub-types, to detect possible + * misuse, such as PSS parameters being passed when a plain RSA key + * is generated. + */ static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[]) { struct rsa_gen_ctx *gctx = genctx; @@ -393,15 +440,44 @@ static int rsa_gen_set_params(void *genctx, const OSSL_PARAM params[]) if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E)) != NULL && !OSSL_PARAM_get_BN(p, &gctx->pub_exp)) return 0; + /* Only attempt to get PSS parameters when generating an RSA-PSS key */ + if (gctx->rsa_type == RSA_FLAG_TYPE_RSASSAPSS + && !pss_params_fromdata(&gctx->pss_params, params, gctx->rsa_type, + gctx->libctx)) + return 0; return 1; } +#define rsa_gen_basic \ + OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_BITS, NULL), \ + OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, NULL), \ + OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0) + +/* + * The following must be kept in sync with rsa_pss_params_30_fromdata() + * in crypto/rsa/rsa_backend.c + */ +#define rsa_gen_pss \ + OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_DIGEST, NULL, 0), \ + OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MASKGENFUNC, NULL, 0), \ + OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_RSA_MGF1_DIGEST, NULL, 0), \ + OSSL_PARAM_int(OSSL_PKEY_PARAM_RSA_PSS_SALTLEN, NULL) + static const OSSL_PARAM *rsa_gen_settable_params(void *provctx) { static OSSL_PARAM settable[] = { - OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_BITS, NULL), - OSSL_PARAM_size_t(OSSL_PKEY_PARAM_RSA_PRIMES, NULL), - OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0), + rsa_gen_basic, + OSSL_PARAM_END + }; + + return settable; +} + +static const OSSL_PARAM *rsapss_gen_settable_params(void *provctx) +{ + static OSSL_PARAM settable[] = { + rsa_gen_basic, + rsa_gen_pss, OSSL_PARAM_END }; @@ -411,11 +487,28 @@ static const OSSL_PARAM *rsa_gen_settable_params(void *provctx) static void *rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg) { struct rsa_gen_ctx *gctx = genctx; - RSA *rsa = NULL; + RSA *rsa = NULL, *rsa_tmp = NULL; BN_GENCB *gencb = NULL; + switch (gctx->rsa_type) { + case RSA_FLAG_TYPE_RSA: + /* For plain RSA keys, PSS parameters must not be set */ + if (!rsa_pss_params_30_is_unrestricted(&gctx->pss_params)) + goto err; + break; + case RSA_FLAG_TYPE_RSASSAPSS: + /* + * For plain RSA-PSS keys, PSS parameters may be set but don't have + * to, so not check. + */ + break; + default: + /* Unsupported RSA key sub-type... */ + return NULL; + } + if (gctx == NULL - || (rsa = rsa_new_with_ctx(gctx->libctx)) == NULL) + || (rsa_tmp = rsa_new_with_ctx(gctx->libctx)) == NULL) return NULL; gctx->cb = osslcb; @@ -424,14 +517,23 @@ static void *rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg) if (gencb != NULL) BN_GENCB_set(gencb, rsa_gencb, genctx); - if (!RSA_generate_multi_prime_key(rsa, (int)gctx->nbits, (int)gctx->primes, - gctx->pub_exp, gencb)) { - RSA_free(rsa); - rsa = NULL; - } + if (!RSA_generate_multi_prime_key(rsa_tmp, + (int)gctx->nbits, (int)gctx->primes, + gctx->pub_exp, gencb)) + goto err; + if (!rsa_pss_params_30_copy(rsa_get0_pss_params_30(rsa_tmp), + &gctx->pss_params)) + goto err; + + RSA_clear_flags(rsa_tmp, RSA_FLAG_TYPE_MASK); + RSA_set_flags(rsa_tmp, gctx->rsa_type); + + rsa = rsa_tmp; + rsa_tmp = NULL; + err: BN_GENCB_free(gencb); - + RSA_free(rsa_tmp); return rsa; } @@ -446,6 +548,12 @@ static void rsa_gen_cleanup(void *genctx) OPENSSL_free(gctx); } +/* For any RSA key, we use the "RSA" algorithms regardless of sub-type. */ +static const char *rsapss_query_operation_name(int operation_id) +{ + return "RSA"; +} + const OSSL_DISPATCH rsa_keymgmt_functions[] = { { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsa_newdata }, { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))rsa_gen_init }, @@ -467,3 +575,25 @@ const OSSL_DISPATCH rsa_keymgmt_functions[] = { { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))rsa_export_types }, { 0, NULL } }; + +const OSSL_DISPATCH rsapss_keymgmt_functions[] = { + { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))rsapss_newdata }, + { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))rsapss_gen_init }, + { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))rsa_gen_set_params }, + { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, + (void (*)(void))rsapss_gen_settable_params }, + { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))rsa_gen }, + { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))rsa_gen_cleanup }, + { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))rsa_freedata }, + { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))rsa_get_params }, + { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))rsa_gettable_params }, + { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))rsa_has }, + { OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))rsa_validate }, + { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))rsa_import }, + { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))rsa_import_types }, + { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))rsa_export }, + { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))rsa_export_types }, + { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, + (void (*)(void))rsapss_query_operation_name }, + { 0, NULL } +}; diff --git a/providers/implementations/macs/kmac_prov.c b/providers/implementations/macs/kmac_prov.c index 6feaba76..da465965 100644 --- a/providers/implementations/macs/kmac_prov.c +++ b/providers/implementations/macs/kmac_prov.c @@ -1,5 +1,5 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -250,6 +250,8 @@ static int kmac_init(void *vmacctx) return 0; block_len = EVP_MD_block_size(ossl_prov_digest_md(&kctx->digest)); + if (block_len < 0) + return 0; /* Set default custom string if it is not already set */ if (kctx->custom_len == 0) { diff --git a/providers/implementations/serializers/build.info b/providers/implementations/serializers/build.info index 097bdcac..ffafbe38 100644 --- a/providers/implementations/serializers/build.info +++ b/providers/implementations/serializers/build.info @@ -10,7 +10,10 @@ $ECX_GOAL=../../libimplementations.a $EC_GOAL=../../libimplementations.a SOURCE[$SERIALIZER_GOAL]=serializer_common.c + SOURCE[$RSA_GOAL]=serializer_rsa.c serializer_rsa_priv.c serializer_rsa_pub.c +DEPEND[serializer_rsa.o]=../../common/include/prov/der_rsa.h + IF[{- !$disabled{"dh"} || !$disabled{"dsa"} -}] SOURCE[$FFC_GOAL]=serializer_ffc_params.c ENDIF diff --git a/providers/implementations/serializers/serializer_common.c b/providers/implementations/serializers/serializer_common.c index 2dbbe6b3..75c1ddc2 100644 --- a/providers/implementations/serializers/serializer_common.c +++ b/providers/implementations/serializers/serializer_common.c @@ -178,7 +178,7 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label, } if (BN_is_zero(bn)) - return ossl_prov_bio_printf(out, "%s%s0\n", label, post_label_spc); + return BIO_printf(out, "%s%s0\n", label, post_label_spc); if (BN_num_bytes(bn) <= BN_BYTES) { BN_ULONG *words = bn_get_words(bn); @@ -186,10 +186,8 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label, if (BN_is_negative(bn)) neg = "-"; - return ossl_prov_bio_printf(out, - "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n", - label, post_label_spc, neg, words[0], - neg, words[0]); + return BIO_printf(out, "%s%s%s" BN_FMTu " (%s0x" BN_FMTx ")\n", + label, post_label_spc, neg, words[0], neg, words[0]); } hex_str = BN_bn2hex(bn); @@ -198,18 +196,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label, ++p; neg = " (Negative)"; } - if (ossl_prov_bio_printf(out, "%s%s\n", label, neg) <= 0) + if (BIO_printf(out, "%s%s\n", label, neg) <= 0) goto err; /* Keep track of how many bytes we have printed out so far */ bytes = 0; - if (ossl_prov_bio_printf(out, "%s", spaces) <= 0) + if (BIO_printf(out, "%s", spaces) <= 0) goto err; /* Add a leading 00 if the top bit is set */ if (*p >= '8') { - if (ossl_prov_bio_printf(out, "%02x", 0) <= 0) + if (BIO_printf(out, "%02x", 0) <= 0) goto err; ++bytes; use_sep = 1; @@ -217,18 +215,18 @@ int ossl_prov_print_labeled_bignum(BIO *out, const char *label, while (*p != '\0') { /* Do a newline after every 15 hex bytes + add the space indent */ if ((bytes % 15) == 0 && bytes > 0) { - if (ossl_prov_bio_printf(out, ":\n%s", spaces) <= 0) + if (BIO_printf(out, ":\n%s", spaces) <= 0) goto err; use_sep = 0; /* The first byte on the next line doesnt have a : */ } - if (ossl_prov_bio_printf(out, "%s%c%c", use_sep ? ":" : "", - ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0) + if (BIO_printf(out, "%s%c%c", use_sep ? ":" : "", + ossl_tolower(p[0]), ossl_tolower(p[1])) <= 0) goto err; ++bytes; p += 2; use_sep = 1; } - if (ossl_prov_bio_printf(out, "\n") <= 0) + if (BIO_printf(out, "\n") <= 0) goto err; ret = 1; err: @@ -244,22 +242,22 @@ int ossl_prov_print_labeled_buf(BIO *out, const char *label, { size_t i; - if (ossl_prov_bio_printf(out, "%s\n", label) <= 0) + if (BIO_printf(out, "%s\n", label) <= 0) return 0; for (i = 0; i < buflen; i++) { if ((i % LABELED_BUF_PRINT_WIDTH) == 0) { - if (i > 0 && ossl_prov_bio_printf(out, "\n") <= 0) + if (i > 0 && BIO_printf(out, "\n") <= 0) return 0; - if (ossl_prov_bio_printf(out, " ") <= 0) + if (BIO_printf(out, " ") <= 0) return 0; } - if (ossl_prov_bio_printf(out, "%02x%s", buf[i], + if (BIO_printf(out, "%02x%s", buf[i], (i == buflen - 1) ? "" : ":") <= 0) return 0; } - if (ossl_prov_bio_printf(out, "\n") <= 0) + if (BIO_printf(out, "\n") <= 0) return 0; return 1; diff --git a/providers/implementations/serializers/serializer_dh.c b/providers/implementations/serializers/serializer_dh.c index 2b616b2e..df92017b 100644 --- a/providers/implementations/serializers/serializer_dh.c +++ b/providers/implementations/serializers/serializer_dh.c @@ -70,7 +70,7 @@ int ossl_prov_print_dh(BIO *out, DH *dh, enum dh_print_type type) if (p == NULL) goto null_err; - if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p)) + if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p)) <= 0) goto err; if (priv_key != NULL diff --git a/providers/implementations/serializers/serializer_dh_param.c b/providers/implementations/serializers/serializer_dh_param.c index 5e061785..4acf5cae 100644 --- a/providers/implementations/serializers/serializer_dh_param.c +++ b/providers/implementations/serializers/serializer_dh_param.c @@ -21,6 +21,7 @@ #include "prov/bio.h" #include "prov/implementations.h" #include "prov/providercommonerr.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn dh_param_newctx; @@ -48,7 +49,8 @@ static void dh_param_freectx(void *ctx) } /* Public key : DER */ -static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new(); @@ -69,14 +71,23 @@ static int dh_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_param_der(void *ctx, void *dh, BIO *out, +static int dh_param_der(void *ctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return i2d_DHparams_bio(out, dh); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + ret = i2d_DHparams_bio(out, dh); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new(); @@ -97,13 +108,23 @@ static int dh_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_param_pem(void *ctx, void *dh, BIO *out, +static int dh_param_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return PEM_write_bio_DHparams(out, dh); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = PEM_write_bio_DHparams(out, dh); + BIO_free(out); + + return ret; } -static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new(); @@ -124,10 +145,19 @@ static int dh_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_param_print(void *ctx, void *dh, BIO *out, +static int dh_param_print(void *ctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_dh(out, dh, dh_print_params); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_dh(out, dh, dh_print_params); + BIO_free(out); + + return ret; } const OSSL_DISPATCH dh_param_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_dh_priv.c b/providers/implementations/serializers/serializer_dh_priv.c index 99d529b0..c37eb402 100644 --- a/providers/implementations/serializers/serializer_dh_priv.c +++ b/providers/implementations/serializers/serializer_dh_priv.c @@ -22,6 +22,7 @@ #include #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn dh_priv_newctx; @@ -117,7 +118,8 @@ static int dh_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } /* Private key : DER */ -static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dh_priv_ctx_st *ctx = vctx; @@ -138,11 +140,15 @@ static int dh_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_priv_der(void *vctx, void *dh, BIO *out, +static int dh_priv_der(void *vctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dh_priv_ctx_st *ctx = vctx; int ret; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; @@ -151,12 +157,14 @@ static int dh_priv_der(void *vctx, void *dh, BIO *out, ossl_prov_prepare_dh_params, ossl_prov_dh_priv_to_der, &ctx->sc); + BIO_free(out); return ret; } /* Private key : PEM */ -static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dh_priv_ctx_st *ctx = vctx; @@ -177,11 +185,15 @@ static int dh_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_pem_priv(void *vctx, void *dh, BIO *out, +static int dh_pem_priv(void *vctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dh_priv_ctx_st *ctx = vctx; int ret; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; @@ -190,6 +202,7 @@ static int dh_pem_priv(void *vctx, void *dh, BIO *out, ossl_prov_prepare_dh_params, ossl_prov_dh_priv_to_der, &ctx->sc); + BIO_free(out); return ret; } @@ -206,7 +219,8 @@ static void dh_print_freectx(void *ctx) { } -static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dh_priv_ctx_st *ctx = vctx; @@ -227,10 +241,19 @@ static int dh_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_priv_print(void *ctx, void *dh, BIO *out, +static int dh_priv_print(void *ctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_dh(out, dh, dh_print_priv); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_dh(out, dh, dh_print_priv); + BIO_free(out); + + return ret; } const OSSL_DISPATCH dh_priv_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_dh_pub.c b/providers/implementations/serializers/serializer_dh_pub.c index b787f7c0..d1b60d87 100644 --- a/providers/implementations/serializers/serializer_dh_pub.c +++ b/providers/implementations/serializers/serializer_dh_pub.c @@ -21,6 +21,7 @@ #include #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn dh_pub_newctx; @@ -48,7 +49,8 @@ static void dh_pub_freectx(void *ctx) } /* Public key : DER */ -static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new(); @@ -69,17 +71,27 @@ static int dh_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_pub_der(void *ctx, void *dh, BIO *out, +static int dh_pub_der(void *ctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH, - ossl_prov_prepare_dh_params, - ossl_prov_dh_pub_to_der); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_der_from_obj(out, dh, EVP_PKEY_DH, + ossl_prov_prepare_dh_params, + ossl_prov_dh_pub_to_der); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, - OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) +static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new(); OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free(); @@ -99,17 +111,26 @@ static int dh_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_pub_pem(void *ctx, void *dh, BIO *out, +static int dh_pub_pem(void *ctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH, - ossl_prov_prepare_dh_params, - ossl_prov_dh_pub_to_der); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_pem_from_obj(out, dh, EVP_PKEY_DH, + ossl_prov_prepare_dh_params, + ossl_prov_dh_pub_to_der); + BIO_free(out); + + return ret; } -static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, - OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) +static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dh_new = ossl_prov_get_keymgmt_dh_new(); OSSL_OP_keymgmt_free_fn *dh_free = ossl_prov_get_keymgmt_dh_free(); @@ -129,10 +150,19 @@ static int dh_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dh_pub_print(void *ctx, void *dh, BIO *out, +static int dh_pub_print(void *ctx, void *dh, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_dh(out, dh, dh_print_pub); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_dh(out, dh, dh_print_pub); + BIO_free(out); + + return ret; } const OSSL_DISPATCH dh_pub_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_dsa.c b/providers/implementations/serializers/serializer_dsa.c index 7ee0bc73..dea7a18e 100644 --- a/providers/implementations/serializers/serializer_dsa.c +++ b/providers/implementations/serializers/serializer_dsa.c @@ -73,8 +73,7 @@ int ossl_prov_print_dsa(BIO *out, DSA *dsa, enum dsa_print_type type) if (p == NULL) goto null_err; - if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, - BN_num_bits(p)) <= 0) + if (BIO_printf(out, "%s: (%d bit)\n", type_label, BN_num_bits(p)) <= 0) goto err; if (priv_key != NULL && !ossl_prov_print_labeled_bignum(out, "priv:", priv_key)) diff --git a/providers/implementations/serializers/serializer_dsa_param.c b/providers/implementations/serializers/serializer_dsa_param.c index 720c3903..23a6d1d2 100644 --- a/providers/implementations/serializers/serializer_dsa_param.c +++ b/providers/implementations/serializers/serializer_dsa_param.c @@ -21,6 +21,7 @@ #include "prov/bio.h" #include "prov/implementations.h" #include "prov/providercommonerr.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn dsa_param_newctx; @@ -48,7 +49,8 @@ static void dsa_param_freectx(void *ctx) } /* Public key : DER */ -static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new(); @@ -69,14 +71,24 @@ static int dsa_param_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_param_der(void *ctx, void *dsa, BIO *out, +static int dsa_param_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return i2d_DSAparams_bio(out, dsa); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = i2d_DSAparams_bio(out, dsa); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new(); @@ -97,13 +109,23 @@ static int dsa_param_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_param_pem(void *ctx, void *dsa, BIO *out, +static int dsa_param_pem(void *ctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return PEM_write_bio_DSAparams(out, dsa); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = PEM_write_bio_DSAparams(out, dsa); + BIO_free(out); + + return ret; } -static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new(); @@ -124,10 +146,19 @@ static int dsa_param_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_param_print(void *ctx, void *dsa, BIO *out, +static int dsa_param_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_dsa(out, dsa, dsa_print_params); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_dsa(out, dsa, dsa_print_params); + BIO_free(out); + + return ret; } const OSSL_DISPATCH dsa_param_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_dsa_priv.c b/providers/implementations/serializers/serializer_dsa_priv.c index 7fdc1567..cb913614 100644 --- a/providers/implementations/serializers/serializer_dsa_priv.c +++ b/providers/implementations/serializers/serializer_dsa_priv.c @@ -22,6 +22,7 @@ #include #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn dsa_priv_newctx; @@ -117,7 +118,8 @@ static int dsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } /* Private key : DER */ -static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dsa_priv_ctx_st *ctx = vctx; @@ -138,22 +140,31 @@ static int dsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_priv_der(void *vctx, void *dsa, BIO *out, +static int dsa_priv_der(void *vctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dsa_priv_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; - return ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA, - ossl_prov_prepare_dsa_params, - ossl_prov_dsa_priv_to_der, - &ctx->sc); + ret = ossl_prov_write_priv_der_from_obj(out, dsa, EVP_PKEY_DSA, + ossl_prov_prepare_dsa_params, + ossl_prov_dsa_priv_to_der, + &ctx->sc); + BIO_free(out); + + return ret; } /* Private key : PEM */ -static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dsa_priv_ctx_st *ctx = vctx; @@ -174,18 +185,26 @@ static int dsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_pem_priv(void *vctx, void *dsa, BIO *out, +static int dsa_pem_priv(void *vctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dsa_priv_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; - return ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA, - ossl_prov_prepare_dsa_params, - ossl_prov_dsa_priv_to_der, - &ctx->sc); + ret = ossl_prov_write_priv_pem_from_obj(out, dsa, EVP_PKEY_DSA, + ossl_prov_prepare_dsa_params, + ossl_prov_dsa_priv_to_der, + &ctx->sc); + BIO_free(out); + + return ret; } /* @@ -201,7 +220,7 @@ static void dsa_print_freectx(void *ctx) } static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[], - BIO *out, + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct dsa_priv_ctx_st *ctx = vctx; @@ -222,10 +241,19 @@ static int dsa_priv_print_data(void *vctx, const OSSL_PARAM params[], return ok; } -static int dsa_priv_print(void *ctx, void *dsa, BIO *out, +static int dsa_priv_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_dsa(out, dsa, dsa_print_priv); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_dsa(out, dsa, dsa_print_priv); + BIO_free(out); + + return ret; } const OSSL_DISPATCH dsa_priv_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_dsa_pub.c b/providers/implementations/serializers/serializer_dsa_pub.c index 46e5c716..5c5e61f1 100644 --- a/providers/implementations/serializers/serializer_dsa_pub.c +++ b/providers/implementations/serializers/serializer_dsa_pub.c @@ -21,6 +21,7 @@ #include #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn dsa_pub_newctx; @@ -48,7 +49,8 @@ static void dsa_pub_freectx(void *ctx) } /* Public key : DER */ -static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new(); @@ -69,7 +71,7 @@ static int dsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_pub_der(void *ctx, void *dsa, BIO *out, +static int dsa_pub_der(void *ctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { /* @@ -77,8 +79,13 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out, * in crypto/dsa/dsa_ameth.c */ int save_parameters = 1; + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; - return + if (out == NULL) + return 0; + + ret = save_parameters ? ossl_prov_write_pub_der_from_obj(out, dsa, EVP_PKEY_DSA, ossl_prov_prepare_all_dsa_params, @@ -87,10 +94,14 @@ static int dsa_pub_der(void *ctx, void *dsa, BIO *out, ossl_prov_prepare_dsa_params, ossl_prov_dsa_pub_to_der); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new(); @@ -111,15 +122,26 @@ static int dsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_pub_pem(void *ctx, void *dsa, BIO *out, +static int dsa_pub_pem(void *ctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_write_pub_pem_from_obj(out, dsa, EVP_PKEY_DSA, - ossl_prov_prepare_dsa_params, - ossl_prov_dsa_pub_to_der); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_pem_from_obj(out, dsa, EVP_PKEY_DSA, + ossl_prov_prepare_dsa_params, + ossl_prov_dsa_pub_to_der); + + BIO_free(out); + + return ret; } -static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *dsa_new = ossl_prov_get_keymgmt_dsa_new(); @@ -140,10 +162,19 @@ static int dsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int dsa_pub_print(void *ctx, void *dsa, BIO *out, +static int dsa_pub_print(void *ctx, void *dsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_dsa(out, dsa, 0); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_dsa(out, dsa, 0); + BIO_free(out); + + return ret; } const OSSL_DISPATCH dsa_pub_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_ec.c b/providers/implementations/serializers/serializer_ec.c index 3d455f15..c4ca0c08 100644 --- a/providers/implementations/serializers/serializer_ec.c +++ b/providers/implementations/serializers/serializer_ec.c @@ -31,15 +31,13 @@ static int ossl_prov_print_ec_param(BIO *out, const EC_GROUP *group) if (curve_nid == NID_undef) return 0; - if (ossl_prov_bio_printf(out, "%s: %s\n", "ASN1 OID", - OBJ_nid2sn(curve_nid)) <= 0) + if (BIO_printf(out, "%s: %s\n", "ASN1 OID", OBJ_nid2sn(curve_nid)) <= 0) return 0; /* TODO(3.0): Only named curves are currently supported */ curve_name = EC_curve_nid2nist(curve_nid); return (curve_name == NULL - || ossl_prov_bio_printf(out, "%s: %s\n", "NIST CURVE", - curve_name) > 0); + || BIO_printf(out, "%s: %s\n", "NIST CURVE", curve_name) > 0); } int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type) @@ -86,8 +84,8 @@ int ossl_prov_print_eckey(BIO *out, EC_KEY *eckey, enum ec_print_type type) goto err; } - if (ossl_prov_bio_printf(out, "%s: (%d bit)\n", type_label, - EC_GROUP_order_bits(group)) <= 0) + if (BIO_printf(out, "%s: (%d bit)\n", type_label, + EC_GROUP_order_bits(group)) <= 0) goto err; if (priv != NULL && !ossl_prov_print_labeled_buf(out, "priv:", priv, priv_len)) diff --git a/providers/implementations/serializers/serializer_ec_param.c b/providers/implementations/serializers/serializer_ec_param.c index fdeedb5d..a8297160 100644 --- a/providers/implementations/serializers/serializer_ec_param.c +++ b/providers/implementations/serializers/serializer_ec_param.c @@ -15,6 +15,7 @@ #include "prov/bio.h" #include "prov/implementations.h" #include "prov/providercommonerr.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn ec_param_newctx; @@ -39,8 +40,9 @@ static void ec_param_freectx(void *vctx) } /* Public key : DER */ -static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, - OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) +static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *ec_new; OSSL_OP_keymgmt_free_fn *ec_free; @@ -62,15 +64,25 @@ static int ec_param_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_param_der(void *vctx, void *eckey, BIO *out, +static int ec_param_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey)); + BIO *out = bio_new_from_core_bio(vctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = i2d_ECPKParameters_bio(out, EC_KEY_get0_group(eckey)); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, - OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) +static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *ec_new; OSSL_OP_keymgmt_free_fn *ec_free; @@ -92,14 +104,24 @@ static int ec_param_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_param_pem(void *vctx, void *eckey, BIO *out, +static int ec_param_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey)); + BIO *out = bio_new_from_core_bio(vctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = PEM_write_bio_ECPKParameters(out, EC_KEY_get0_group(eckey)); + BIO_free(out); + + return ret; } -static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, - OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) +static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *ec_new; OSSL_OP_keymgmt_free_fn *ec_free; @@ -121,10 +143,19 @@ static int ec_param_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_param_print(void *vctx, void *eckey, BIO *out, +static int ec_param_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_eckey(out, eckey, ec_print_params); + BIO *out = bio_new_from_core_bio(vctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_eckey(out, eckey, ec_print_params); + BIO_free(out); + + return ret; } const OSSL_DISPATCH ec_param_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_ec_priv.c b/providers/implementations/serializers/serializer_ec_priv.c index 14ff2ae6..4a0e3d8b 100644 --- a/providers/implementations/serializers/serializer_ec_priv.c +++ b/providers/implementations/serializers/serializer_ec_priv.c @@ -16,6 +16,7 @@ #include #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn ec_priv_newctx; @@ -111,8 +112,9 @@ static int ec_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } /* Private key : DER */ -static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, - OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) +static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ec_priv_ctx_st *ctx = vctx; OSSL_OP_keymgmt_new_fn *ec_new; @@ -134,23 +136,32 @@ static int ec_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_priv_der(void *vctx, void *eckey, BIO *out, +static int ec_priv_der(void *vctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ec_priv_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; - return ossl_prov_write_priv_der_from_obj(out, eckey, EVP_PKEY_EC, - ossl_prov_prepare_ec_params, - ossl_prov_ec_priv_to_der, - &ctx->sc); + ret = ossl_prov_write_priv_der_from_obj(out, eckey, EVP_PKEY_EC, + ossl_prov_prepare_ec_params, + ossl_prov_ec_priv_to_der, + &ctx->sc); + BIO_free(out); + + return ret; } /* Private key : PEM */ -static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, - OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) +static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, + OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ec_priv_ctx_st *ctx = vctx; OSSL_OP_keymgmt_new_fn *ec_new; @@ -172,18 +183,26 @@ static int ec_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_pem_priv(void *vctx, void *eckey, BIO *out, +static int ec_pem_priv(void *vctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ec_priv_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; - return ossl_prov_write_priv_pem_from_obj(out, eckey, EVP_PKEY_EC, - ossl_prov_prepare_ec_params, - ossl_prov_ec_priv_to_der, - &ctx->sc); + ret = ossl_prov_write_priv_pem_from_obj(out, eckey, EVP_PKEY_EC, + ossl_prov_prepare_ec_params, + ossl_prov_ec_priv_to_der, + &ctx->sc); + BIO_free(out); + + return ret; } /* @@ -198,7 +217,8 @@ static void ec_print_freectx(void *ctx) { } -static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ec_priv_ctx_st *ctx = vctx; @@ -221,10 +241,19 @@ static int ec_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_priv_print(void *vctx, void *eckey, BIO *out, +static int ec_priv_print(void *ctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_eckey(out, eckey, ec_print_priv); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_eckey(out, eckey, ec_print_priv); + BIO_free(out); + + return ret; } const OSSL_DISPATCH ec_priv_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_ec_pub.c b/providers/implementations/serializers/serializer_ec_pub.c index e9d90f1d..1c145cf3 100644 --- a/providers/implementations/serializers/serializer_ec_pub.c +++ b/providers/implementations/serializers/serializer_ec_pub.c @@ -14,6 +14,7 @@ #include #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn ec_pub_newctx; @@ -41,7 +42,8 @@ static void ec_pub_freectx(void *ctx) } /* Public key : DER */ -static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *ec_new; @@ -64,16 +66,26 @@ static int ec_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_pub_der(void *ctx, void *eckey, BIO *out, +static int ec_pub_der(void *ctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_write_pub_der_from_obj(out, eckey, EVP_PKEY_EC, + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_der_from_obj(out, eckey, EVP_PKEY_EC, ossl_prov_prepare_ec_params, ossl_prov_ec_pub_to_der); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *ec_new; @@ -96,15 +108,25 @@ static int ec_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_pub_pem(void *vctx, void *eckey, BIO *out, +static int ec_pub_pem(void *vctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC, - ossl_prov_prepare_ec_params, - ossl_prov_ec_pub_to_der); + BIO *out = bio_new_from_core_bio(vctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_pem_from_obj(out, eckey, EVP_PKEY_EC, + ossl_prov_prepare_ec_params, + ossl_prov_ec_pub_to_der); + BIO_free(out); + + return ret; } -static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *ec_new; @@ -127,10 +149,19 @@ static int ec_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ec_pub_print(void *vctx, void *eckey, BIO *out, +static int ec_pub_print(void *vctx, void *eckey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_eckey(out, eckey, ec_print_pub); + BIO *out = bio_new_from_core_bio(vctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_eckey(out, eckey, ec_print_pub); + BIO_free(out); + + return ret; } const OSSL_DISPATCH ec_pub_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_ecx.c b/providers/implementations/serializers/serializer_ecx.c index 78b6ec96..a768355a 100644 --- a/providers/implementations/serializers/serializer_ecx.c +++ b/providers/implementations/serializers/serializer_ecx.c @@ -86,7 +86,7 @@ int ossl_prov_print_ecx(BIO *out, ECX_KEY *ecxkey, enum ecx_print_type type) return 0; } - if (ossl_prov_bio_printf(out, "%s:\n", type_label) <= 0) + if (BIO_printf(out, "%s:\n", type_label) <= 0) return 0; if (type == ecx_print_priv && !ossl_prov_print_labeled_buf(out, "priv:", ecxkey->privkey, diff --git a/providers/implementations/serializers/serializer_ecx_priv.c b/providers/implementations/serializers/serializer_ecx_priv.c index c7461094..ea46d6c5 100644 --- a/providers/implementations/serializers/serializer_ecx_priv.c +++ b/providers/implementations/serializers/serializer_ecx_priv.c @@ -16,6 +16,7 @@ #include "crypto/ecx.h" #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn x25519_priv_newctx; @@ -134,7 +135,8 @@ static int ecx_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } /* Private key : DER */ -static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_priv_ctx_st *ctx = vctx; @@ -157,13 +159,17 @@ static int ecx_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out, +static int ecx_priv_der(void *vctx, void *vecxkey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_priv_ctx_st *ctx = vctx; ECX_KEY *ecxkey = vecxkey; int ret; int nid = KEYTYPE2NID(ctx->type); + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; @@ -173,12 +179,14 @@ static int ecx_priv_der(void *vctx, void *vecxkey, BIO *out, NULL, ossl_prov_ecx_priv_to_der, &ctx->sc); + BIO_free(out); return ret; } /* Private key : PEM */ -static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_priv_ctx_st *ctx = vctx; @@ -201,12 +209,16 @@ static int ecx_priv_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out, +static int ecx_priv_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_priv_ctx_st *ctx = vctx; int ret; int nid = KEYTYPE2NID(ctx->type); + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; @@ -216,11 +228,13 @@ static int ecx_priv_pem(void *vctx, void *ecxkey, BIO *out, NULL, ossl_prov_ecx_priv_to_der, &ctx->sc); + BIO_free(out); return ret; } -static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_priv_ctx_st *ctx = vctx; @@ -243,10 +257,20 @@ static int ecx_priv_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ecx_priv_print(void *ctx, void *ecxkey, BIO *out, +static int ecx_priv_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_ecx(out, ecxkey, ecx_print_priv); + struct ecx_priv_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_priv); + BIO_free(out); + + return ret; } #define MAKE_SERIALIZER_FUNCTIONS(alg, type) \ diff --git a/providers/implementations/serializers/serializer_ecx_pub.c b/providers/implementations/serializers/serializer_ecx_pub.c index cd09cd6a..94483f10 100644 --- a/providers/implementations/serializers/serializer_ecx_pub.c +++ b/providers/implementations/serializers/serializer_ecx_pub.c @@ -15,6 +15,7 @@ #include "crypto/ecx.h" #include "prov/bio.h" #include "prov/implementations.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn x25519_pub_newctx; @@ -76,7 +77,8 @@ static void ecx_pub_freectx(void *ctx) } /* Public key : DER */ -static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_pub_ctx_st *ctx = vctx; @@ -99,19 +101,28 @@ static int ecx_pub_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ecx_pub_der(void *vctx, void *ecxkey, BIO *out, +static int ecx_pub_der(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_pub_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; - return ossl_prov_write_pub_der_from_obj(out, ecxkey, - KEYTYPE2NID(ctx->type), - NULL, - ossl_prov_ecx_pub_to_der); + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_der_from_obj(out, ecxkey, + KEYTYPE2NID(ctx->type), + NULL, + ossl_prov_ecx_pub_to_der); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_pub_ctx_st *ctx = vctx; @@ -134,19 +145,27 @@ static int ecx_pub_pem_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ecx_pub_pem(void *vctx, void *ecxkey, BIO *out, +static int ecx_pub_pem(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_pub_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; - return ossl_prov_write_pub_pem_from_obj(out, ecxkey, - KEYTYPE2NID(ctx->type), - NULL, - ossl_prov_ecx_pub_to_der); + if (out == NULL) + return 0; + ret = ossl_prov_write_pub_pem_from_obj(out, ecxkey, + KEYTYPE2NID(ctx->type), + NULL, + ossl_prov_ecx_pub_to_der); + BIO_free(out); + + return ret; } -static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct ecx_pub_ctx_st *ctx = vctx; @@ -169,10 +188,20 @@ static int ecx_pub_print_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int ecx_pub_print(void *ctx, void *ecxkey, BIO *out, +static int ecx_pub_print(void *vctx, void *ecxkey, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_ecx(out, ecxkey, ecx_print_pub); + struct ecx_pub_ctx_st *ctx = vctx; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_ecx(out, ecxkey, ecx_print_pub); + BIO_free(out); + + return ret; } #define MAKE_SERIALIZER_FUNCTIONS(alg, type) \ diff --git a/providers/implementations/serializers/serializer_ffc_params.c b/providers/implementations/serializers/serializer_ffc_params.c index 98c9886c..ad96c4dd 100644 --- a/providers/implementations/serializers/serializer_ffc_params.c +++ b/providers/implementations/serializers/serializer_ffc_params.c @@ -20,7 +20,7 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc) if (name == NULL) goto err; - if (ossl_prov_bio_printf(out, "GROUP: %s\n", name) <= 0) + if (BIO_printf(out, "GROUP: %s\n", name) <= 0) goto err; return 1; #else @@ -46,15 +46,15 @@ int ffc_params_prov_print(BIO *out, const FFC_PARAMS *ffc) goto err; } if (ffc->gindex != -1) { - if (ossl_prov_bio_printf(out, "gindex: %d\n", ffc->gindex) <= 0) + if (BIO_printf(out, "gindex: %d\n", ffc->gindex) <= 0) goto err; } if (ffc->pcounter != -1) { - if (ossl_prov_bio_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0) + if (BIO_printf(out, "pcounter: %d\n", ffc->pcounter) <= 0) goto err; } if (ffc->h != 0) { - if (ossl_prov_bio_printf(out, "h: %d\n", ffc->h) <= 0) + if (BIO_printf(out, "h: %d\n", ffc->h) <= 0) goto err; } return 1; diff --git a/providers/implementations/serializers/serializer_local.h b/providers/implementations/serializers/serializer_local.h index 39fb3ab1..f4aee6fc 100644 --- a/providers/implementations/serializers/serializer_local.h +++ b/providers/implementations/serializers/serializer_local.h @@ -82,6 +82,14 @@ int ossl_prov_prepare_all_dsa_params(const void *dsa, int nid, int ossl_prov_dsa_pub_to_der(const void *dsa, unsigned char **pder); int ossl_prov_dsa_priv_to_der(const void *dsa, unsigned char **pder); +/* + * ossl_prov_prepare_rsa_params() is designed to work with the ossl_prov_write_ + * functions, hence 'void *rsa' rather than 'RSA *rsa'. + */ +int ossl_prov_prepare_rsa_params(const void *rsa, int nid, + void **pstr, int *pstrtype); +int ossl_prov_rsa_type_to_evp(const RSA *rsa); + int ossl_prov_print_labeled_bignum(BIO *out, const char *label, const BIGNUM *bn); int ossl_prov_print_labeled_buf(BIO *out, const char *label, diff --git a/providers/implementations/serializers/serializer_rsa.c b/providers/implementations/serializers/serializer_rsa.c index fa039099..1bca05fb 100644 --- a/providers/implementations/serializers/serializer_rsa.c +++ b/providers/implementations/serializers/serializer_rsa.c @@ -7,8 +7,10 @@ * https://www.openssl.org/source/license.html */ +#include "internal/packet.h" #include "crypto/rsa.h" /* rsa_get0_all_params() */ #include "prov/bio.h" /* ossl_prov_bio_printf() */ +#include "prov/der_rsa.h" /* DER_w_RSASSA_PSS_params() */ #include "prov/implementations.h" /* rsa_keymgmt_functions */ #include "serializer_local.h" @@ -37,6 +39,7 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv) STACK_OF(BIGNUM_const) *factors = sk_BIGNUM_const_new_null(); STACK_OF(BIGNUM_const) *exps = sk_BIGNUM_const_new_null(); STACK_OF(BIGNUM_const) *coeffs = sk_BIGNUM_const_new_null(); + RSA_PSS_PARAMS_30 *pss_params = rsa_get0_pss_params_30(rsa); int ret = 0; if (rsa == NULL || factors == NULL || exps == NULL || coeffs == NULL) @@ -46,15 +49,14 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv) rsa_get0_all_params(rsa, factors, exps, coeffs); if (priv && rsa_d != NULL) { - if (ossl_prov_bio_printf(out, "Private-Key: (%d bit, %d primes)\n", - BN_num_bits(rsa_n), - sk_BIGNUM_const_num(factors)) <= 0) + if (BIO_printf(out, "Private-Key: (%d bit, %d primes)\n", + BN_num_bits(rsa_n), + sk_BIGNUM_const_num(factors)) <= 0) goto err; modulus_label = "modulus:"; exponent_label = "publicExponent:"; } else { - if (ossl_prov_bio_printf(out, "Public-Key: (%d bit)\n", - BN_num_bits(rsa_n)) <= 0) + if (BIO_printf(out, "Public-Key: (%d bit)\n", BN_num_bits(rsa_n)) <= 0) goto err; modulus_label = "Modulus:"; exponent_label = "Exponent:"; @@ -84,18 +86,18 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv) sk_BIGNUM_const_value(coeffs, 0))) goto err; for (i = 2; i < sk_BIGNUM_const_num(factors); i++) { - if (ossl_prov_bio_printf(out, "prime%d:", i + 1) <= 0) + if (BIO_printf(out, "prime%d:", i + 1) <= 0) goto err; if (!ossl_prov_print_labeled_bignum(out, NULL, sk_BIGNUM_const_value(factors, i))) goto err; - if (ossl_prov_bio_printf(out, "exponent%d:", i + 1) <= 0) + if (BIO_printf(out, "exponent%d:", i + 1) <= 0) goto err; if (!ossl_prov_print_labeled_bignum(out, NULL, sk_BIGNUM_const_value(exps, i))) goto err; - if (ossl_prov_bio_printf(out, "coefficient%d:", i + 1) <= 0) + if (BIO_printf(out, "coefficient%d:", i + 1) <= 0) goto err; if (!ossl_prov_print_labeled_bignum(out, NULL, sk_BIGNUM_const_value(coeffs, @@ -103,6 +105,60 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv) goto err; } } + + switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) { + case RSA_FLAG_TYPE_RSA: + if (!rsa_pss_params_30_is_unrestricted(pss_params)) { + if (BIO_printf(out, "(INVALID PSS PARAMETERS)\n") <= 0) + goto err; + } + break; + case RSA_FLAG_TYPE_RSASSAPSS: + if (rsa_pss_params_30_is_unrestricted(pss_params)) { + if (BIO_printf(out, "No PSS parameter restrictions\n") <= 0) + goto err; + } else { + int hashalg_nid = rsa_pss_params_30_hashalg(pss_params); + int maskgenalg_nid = rsa_pss_params_30_maskgenalg(pss_params); + int maskgenhashalg_nid = + rsa_pss_params_30_maskgenhashalg(pss_params); + int saltlen = rsa_pss_params_30_saltlen(pss_params); + int trailerfield = rsa_pss_params_30_trailerfield(pss_params); + + if (BIO_printf(out, "PSS parameter restrictions:\n") <= 0) + goto err; + if (BIO_printf(out, " Hash Algorithm: %s%s\n", + rsa_oaeppss_nid2name(hashalg_nid), + (hashalg_nid == NID_sha1 + ? " (default)" : "")) <= 0) + goto err; + if (BIO_printf(out, " Mask Algorithm: %s with %s%s\n", + rsa_mgf_nid2name(maskgenalg_nid), + rsa_oaeppss_nid2name(maskgenhashalg_nid), + (maskgenalg_nid == NID_mgf1 + && maskgenhashalg_nid == NID_sha1 + ? " (default)" : "")) <= 0) + goto err; + if (BIO_printf(out, " Minimum Salt Length: %d%s\n", + saltlen, + (saltlen == 20 ? " (default)" : "")) <= 0) + goto err; + /* + * TODO(3.0) Should we show the ASN.1 trailerField value, or + * the actual trailerfield byte (i.e. 0xBC for 1)? + * crypto/rsa/rsa_ameth.c isn't very clear on that, as it + * does display 0xBC when the default applies, but the ASN.1 + * trailerField value otherwise... + */ + if (BIO_printf(out, " Trailer Field: 0x%x%s\n", + trailerfield, + (trailerfield == 1 ? " (default)" : "")) + <= 0) + goto err; + } + break; + } + ret = 1; err: sk_BIGNUM_const_free(factors); @@ -110,3 +166,90 @@ int ossl_prov_print_rsa(BIO *out, RSA *rsa, int priv) sk_BIGNUM_const_free(coeffs); return ret; } + +/* + * Helper functions to prepare RSA-PSS params for serialization. We would + * have simply written the whole AlgorithmIdentifier, but existing libcrypto + * functionality doesn't allow that. + */ + +int ossl_prov_prepare_rsa_params(const void *rsa, int nid, + void **pstr, int *pstrtype) +{ + const RSA_PSS_PARAMS_30 *pss = rsa_get0_pss_params_30((RSA *)rsa); + + *pstr = NULL; + + switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) { + case RSA_FLAG_TYPE_RSA: + /* If plain RSA, the parameters shall be NULL */ + *pstrtype = V_ASN1_NULL; + return 1; + case RSA_FLAG_TYPE_RSASSAPSS: + if (rsa_pss_params_30_is_unrestricted(pss)) { + *pstrtype = V_ASN1_UNDEF; + } else { + ASN1_STRING *astr = NULL; + WPACKET pkt; + unsigned char *str = NULL; + size_t str_sz = 0; + int i; + + for (i = 0; i < 2; i++) { + switch (i) { + case 0: + if (!WPACKET_init_null_der(&pkt)) + goto err; + break; + case 1: + if ((str = OPENSSL_malloc(str_sz)) == NULL + || !WPACKET_init_der(&pkt, str, str_sz)) { + goto err; + } + break; + } + if (!DER_w_RSASSA_PSS_params(&pkt, -1, pss) + || !WPACKET_finish(&pkt)) + goto err; + WPACKET_get_total_written(&pkt, &str_sz); + WPACKET_cleanup(&pkt); + + /* + * If no PSS parameters are going to be written, there's no + * point going for another iteration. + * This saves us from getting |str| allocated just to have it + * immediately de-allocated. + */ + if (str_sz == 0) + break; + } + + if ((astr = ASN1_STRING_new()) == NULL) + goto err; + *pstrtype = V_ASN1_SEQUENCE; + ASN1_STRING_set0(astr, str, (int)str_sz); + *pstr = astr; + + return 1; + err: + OPENSSL_free(str); + return 0; + } + } + + /* Currently unsupported RSA key type */ + return 0; +} + +int ossl_prov_rsa_type_to_evp(const RSA *rsa) +{ + switch (RSA_test_flags(rsa, RSA_FLAG_TYPE_MASK)) { + case RSA_FLAG_TYPE_RSA: + return EVP_PKEY_RSA; + case RSA_FLAG_TYPE_RSASSAPSS: + return EVP_PKEY_RSA_PSS; + } + + /* Currently unsupported RSA key type */ + return EVP_PKEY_NONE; +} diff --git a/providers/implementations/serializers/serializer_rsa_priv.c b/providers/implementations/serializers/serializer_rsa_priv.c index dd287cb3..70df51f3 100644 --- a/providers/implementations/serializers/serializer_rsa_priv.c +++ b/providers/implementations/serializers/serializer_rsa_priv.c @@ -15,9 +15,11 @@ #include #include #include +#include "crypto/rsa.h" #include "prov/bio.h" #include "prov/implementations.h" #include "prov/providercommonerr.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn rsa_priv_newctx; @@ -43,34 +45,6 @@ struct rsa_priv_ctx_st { struct pkcs8_encrypt_ctx_st sc; }; -/* Helper functions to prepare RSA-PSS params for serialization */ - -static int prepare_rsa_params(const void *rsa, int nid, - void **pstr, int *pstrtype) -{ - const RSA_PSS_PARAMS *pss = RSA_get0_pss_params(rsa); - *pstr = NULL; - - /* If RSA it's just NULL type */ - if (nid != EVP_PKEY_RSA_PSS) { - *pstrtype = V_ASN1_NULL; - return 1; - } - /* If no PSS parameters we omit parameters entirely */ - if (pss == NULL) { - *pstrtype = V_ASN1_UNDEF; - return 1; - } - /* Encode PSS parameters */ - if (ASN1_item_pack((void *)pss, ASN1_ITEM_rptr(RSA_PSS_PARAMS), - (ASN1_STRING **)pstr) - == NULL) - return 0; - - *pstrtype = V_ASN1_SEQUENCE; - return 1; -} - /* Private key : context */ static void *rsa_priv_newctx(void *provctx) { @@ -140,7 +114,8 @@ static int rsa_priv_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } /* Private key : DER */ -static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct rsa_priv_ctx_st *ctx = vctx; @@ -161,25 +136,32 @@ static int rsa_priv_der_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int rsa_priv_der(void *vctx, void *rsa, BIO *out, +static int rsa_priv_der(void *vctx, void *rsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct rsa_priv_ctx_st *ctx = vctx; int ret; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; - ret = ossl_prov_write_priv_der_from_obj(out, rsa, EVP_PKEY_RSA, - prepare_rsa_params, + ret = ossl_prov_write_priv_der_from_obj(out, rsa, + ossl_prov_rsa_type_to_evp(rsa), + ossl_prov_prepare_rsa_params, (i2d_of_void *)i2d_RSAPrivateKey, &ctx->sc); + BIO_free(out); return ret; } /* Private key : PEM */ -static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, +static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct rsa_priv_ctx_st *ctx = vctx; @@ -200,19 +182,25 @@ static int rsa_pem_priv_data(void *vctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int rsa_pem_priv(void *vctx, void *rsa, BIO *out, +static int rsa_pem_priv(void *vctx, void *rsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct rsa_priv_ctx_st *ctx = vctx; int ret; + BIO *out = bio_new_from_core_bio(ctx->provctx, cout); + + if (out == NULL) + return 0; ctx->sc.cb = cb; ctx->sc.cbarg = cbarg; - ret = ossl_prov_write_priv_pem_from_obj(out, rsa, EVP_PKEY_RSA, - prepare_rsa_params, + ret = ossl_prov_write_priv_pem_from_obj(out, rsa, + ossl_prov_rsa_type_to_evp(rsa), + ossl_prov_prepare_rsa_params, (i2d_of_void *)i2d_RSAPrivateKey, &ctx->sc); + BIO_free(out); return ret; } @@ -230,7 +218,7 @@ static void rsa_print_freectx(void *ctx) } static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[], - BIO *out, + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { struct rsa_priv_ctx_st *ctx = vctx; @@ -251,10 +239,19 @@ static int rsa_priv_print_data(void *vctx, const OSSL_PARAM params[], return ok; } -static int rsa_priv_print(void *ctx, void *rsa, BIO *out, +static int rsa_priv_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_rsa(out, rsa, 1); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_rsa(out, rsa, 1); + BIO_free(out); + + return ret; } const OSSL_DISPATCH rsa_priv_der_serializer_functions[] = { diff --git a/providers/implementations/serializers/serializer_rsa_pub.c b/providers/implementations/serializers/serializer_rsa_pub.c index f901d445..c9e8337d 100644 --- a/providers/implementations/serializers/serializer_rsa_pub.c +++ b/providers/implementations/serializers/serializer_rsa_pub.c @@ -15,6 +15,7 @@ #include "prov/bio.h" #include "prov/implementations.h" #include "prov/providercommonerr.h" +#include "prov/provider_ctx.h" #include "serializer_local.h" static OSSL_OP_serializer_newctx_fn rsa_pub_newctx; @@ -42,7 +43,8 @@ static void rsa_pub_freectx(void *ctx) } /* Public key : DER */ -static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new(); @@ -63,14 +65,27 @@ static int rsa_pub_der_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int rsa_pub_der(void *ctx, void *rsa, BIO *out, +static int rsa_pub_der(void *ctx, void *rsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return i2d_RSA_PUBKEY_bio(out, rsa); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_der_from_obj(out, rsa, + ossl_prov_rsa_type_to_evp(rsa), + ossl_prov_prepare_rsa_params, + (i2d_of_void *)i2d_RSAPublicKey); + BIO_free(out); + + return ret; } /* Public key : PEM */ -static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new(); @@ -91,13 +106,26 @@ static int rsa_pub_pem_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int rsa_pub_pem(void *ctx, void *rsa, BIO *out, +static int rsa_pub_pem(void *ctx, void *rsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return PEM_write_bio_RSA_PUBKEY(out, rsa); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_write_pub_pem_from_obj(out, rsa, + ossl_prov_rsa_type_to_evp(rsa), + ossl_prov_prepare_rsa_params, + (i2d_of_void *)i2d_RSAPublicKey); + BIO_free(out); + + return ret; } -static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, +static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], + OSSL_CORE_BIO *out, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { OSSL_OP_keymgmt_new_fn *rsa_new = ossl_prov_get_keymgmt_rsa_new(); @@ -118,10 +146,19 @@ static int rsa_pub_print_data(void *ctx, const OSSL_PARAM params[], BIO *out, return ok; } -static int rsa_pub_print(void *ctx, void *rsa, BIO *out, +static int rsa_pub_print(void *ctx, void *rsa, OSSL_CORE_BIO *cout, OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg) { - return ossl_prov_print_rsa(out, rsa, 0); + BIO *out = bio_new_from_core_bio(ctx, cout); + int ret; + + if (out == NULL) + return 0; + + ret = ossl_prov_print_rsa(out, rsa, 0); + BIO_free(out); + + return ret; } const OSSL_DISPATCH rsa_pub_der_serializer_functions[] = { diff --git a/providers/implementations/signature/dsa.c b/providers/implementations/signature/dsa.c index f0662d1e..bfab2248 100644 --- a/providers/implementations/signature/dsa.c +++ b/providers/implementations/signature/dsa.c @@ -63,6 +63,7 @@ static OSSL_OP_signature_settable_ctx_md_params_fn dsa_settable_ctx_md_params; typedef struct { OPENSSL_CTX *libctx; + char *propq; DSA *dsa; /* @@ -131,7 +132,7 @@ static int dsa_get_md_nid(const EVP_MD *md) return mdnid; } -static void *dsa_newctx(void *provctx) +static void *dsa_newctx(void *provctx, const char *propq) { PROV_DSA_CTX *pdsactx = OPENSSL_zalloc(sizeof(PROV_DSA_CTX)); @@ -140,12 +141,20 @@ static void *dsa_newctx(void *provctx) pdsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx); pdsactx->flag_allow_md = 1; + if (propq != NULL && (pdsactx->propq = OPENSSL_strdup(propq)) == NULL) { + OPENSSL_free(pdsactx); + pdsactx = NULL; + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); + } return pdsactx; } static int dsa_setup_md(PROV_DSA_CTX *ctx, const char *mdname, const char *mdprops) { + if (mdprops == NULL) + mdprops = ctx->propq; + if (mdname != NULL) { EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops); int md_nid = dsa_get_md_nid(md); @@ -234,7 +243,7 @@ static int dsa_verify(void *vpdsactx, const unsigned char *sig, size_t siglen, } static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname, - const char *props, void *vdsa) + void *vdsa) { PROV_DSA_CTX *pdsactx = (PROV_DSA_CTX *)vpdsactx; @@ -242,7 +251,7 @@ static int dsa_digest_signverify_init(void *vpdsactx, const char *mdname, if (!dsa_signature_init(vpdsactx, vdsa)) return 0; - if (!dsa_setup_md(pdsactx, mdname, props)) + if (!dsa_setup_md(pdsactx, mdname, NULL)) return 0; pdsactx->mdctx = EVP_MD_CTX_new(); diff --git a/providers/implementations/signature/ecdsa.c b/providers/implementations/signature/ecdsa.c index e05830f5..267950d5 100644 --- a/providers/implementations/signature/ecdsa.c +++ b/providers/implementations/signature/ecdsa.c @@ -60,6 +60,7 @@ static OSSL_OP_signature_settable_ctx_md_params_fn ecdsa_settable_ctx_md_params; typedef struct { OPENSSL_CTX *libctx; + char *propq; EC_KEY *ec; char mdname[OSSL_MAX_NAME_SIZE]; @@ -90,7 +91,7 @@ typedef struct { BIGNUM *r; } PROV_ECDSA_CTX; -static void *ecdsa_newctx(void *provctx) +static void *ecdsa_newctx(void *provctx, const char *propq) { PROV_ECDSA_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_ECDSA_CTX)); @@ -98,6 +99,11 @@ static void *ecdsa_newctx(void *provctx) return NULL; ctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx); + if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) { + OPENSSL_free(ctx); + ctx = NULL; + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); + } return ctx; } @@ -203,7 +209,7 @@ static void free_md(PROV_ECDSA_CTX *ctx) } static int ecdsa_digest_signverify_init(void *vctx, const char *mdname, - const char *props, void *ec) + void *ec) { PROV_ECDSA_CTX *ctx = (PROV_ECDSA_CTX *)vctx; int md_nid = NID_undef; @@ -214,7 +220,7 @@ static int ecdsa_digest_signverify_init(void *vctx, const char *mdname, if (!ecdsa_signature_init(vctx, ec)) return 0; - ctx->md = EVP_MD_fetch(ctx->libctx, mdname, props); + ctx->md = EVP_MD_fetch(ctx->libctx, mdname, ctx->propq); if ((md_nid = get_md_nid(ctx->md)) == NID_undef) goto error; diff --git a/providers/implementations/signature/eddsa.c b/providers/implementations/signature/eddsa.c index 1a7bf947..4ecc5266 100644 --- a/providers/implementations/signature/eddsa.c +++ b/providers/implementations/signature/eddsa.c @@ -36,7 +36,7 @@ typedef struct { ECX_KEY *key; } PROV_EDDSA_CTX; -static void *eddsa_newctx(void *provctx) +static void *eddsa_newctx(void *provctx, const char *propq_unused) { PROV_EDDSA_CTX *peddsactx = OPENSSL_zalloc(sizeof(PROV_EDDSA_CTX)); @@ -51,7 +51,7 @@ static void *eddsa_newctx(void *provctx) } static int eddsa_digest_signverify_init(void *vpeddsactx, const char *mdname, - const char *props, void *vedkey) + void *vedkey) { PROV_EDDSA_CTX *peddsactx = (PROV_EDDSA_CTX *)vpeddsactx; ECX_KEY *edkey = (ECX_KEY *)vedkey; diff --git a/providers/implementations/signature/rsa.c b/providers/implementations/signature/rsa.c index 0ea5e0a8..4dc3a898 100644 --- a/providers/implementations/signature/rsa.c +++ b/providers/implementations/signature/rsa.c @@ -31,16 +31,16 @@ #include "prov/der_rsa.h" static OSSL_OP_signature_newctx_fn rsa_newctx; -static OSSL_OP_signature_sign_init_fn rsa_signature_init; -static OSSL_OP_signature_verify_init_fn rsa_signature_init; -static OSSL_OP_signature_verify_recover_init_fn rsa_signature_init; +static OSSL_OP_signature_sign_init_fn rsa_sign_init; +static OSSL_OP_signature_verify_init_fn rsa_verify_init; +static OSSL_OP_signature_verify_recover_init_fn rsa_verify_recover_init; static OSSL_OP_signature_sign_fn rsa_sign; static OSSL_OP_signature_verify_fn rsa_verify; static OSSL_OP_signature_verify_recover_fn rsa_verify_recover; -static OSSL_OP_signature_digest_sign_init_fn rsa_digest_signverify_init; +static OSSL_OP_signature_digest_sign_init_fn rsa_digest_sign_init; static OSSL_OP_signature_digest_sign_update_fn rsa_digest_signverify_update; static OSSL_OP_signature_digest_sign_final_fn rsa_digest_sign_final; -static OSSL_OP_signature_digest_verify_init_fn rsa_digest_signverify_init; +static OSSL_OP_signature_digest_verify_init_fn rsa_digest_verify_init; static OSSL_OP_signature_digest_verify_update_fn rsa_digest_signverify_update; static OSSL_OP_signature_digest_verify_final_fn rsa_digest_verify_final; static OSSL_OP_signature_freectx_fn rsa_freectx; @@ -73,7 +73,9 @@ static OSSL_ITEM padding_item[] = { typedef struct { OPENSSL_CTX *libctx; + char *propq; RSA *rsa; + int operation; /* * Flag to determine if the hash function can be changed (1) or not (0) @@ -129,6 +131,8 @@ static int rsa_get_md_nid(const EVP_MD *md) { NID_sha256, OSSL_DIGEST_NAME_SHA2_256 }, { NID_sha384, OSSL_DIGEST_NAME_SHA2_384 }, { NID_sha512, OSSL_DIGEST_NAME_SHA2_512 }, + { NID_sha512_224, OSSL_DIGEST_NAME_SHA2_512_224 }, + { NID_sha512_256, OSSL_DIGEST_NAME_SHA2_512_256 }, { NID_md5, OSSL_DIGEST_NAME_MD5 }, { NID_md5_sha1, OSSL_DIGEST_NAME_MD5_SHA1 }, { NID_md2, OSSL_DIGEST_NAME_MD2 }, @@ -153,9 +157,6 @@ static int rsa_get_md_nid(const EVP_MD *md) } } - if (mdnid == NID_undef) - ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST); - end: return mdnid; } @@ -177,44 +178,51 @@ static int rsa_check_padding(int mdnid, int padding) return 1; } -static void *rsa_newctx(void *provctx) +static int rsa_check_parameters(EVP_MD *md, PROV_RSA_CTX *prsactx) { - PROV_RSA_CTX *prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX)); + if (prsactx->pad_mode == RSA_PKCS1_PSS_PADDING) { + int max_saltlen; - if (prsactx == NULL) + /* See if minimum salt length exceeds maximum possible */ + max_saltlen = RSA_size(prsactx->rsa) - EVP_MD_size(md); + if ((RSA_bits(prsactx->rsa) & 0x7) == 1) + max_saltlen--; + if (prsactx->min_saltlen > max_saltlen) { + ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_SALT_LENGTH); + return 0; + } + } + return 1; +} + +static void *rsa_newctx(void *provctx, const char *propq) +{ + PROV_RSA_CTX *prsactx = NULL; + char *propq_copy = NULL; + + if ((prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX))) == NULL + || (propq != NULL + && (propq_copy = OPENSSL_strdup(propq)) == NULL)) { + OPENSSL_free(prsactx); + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); return NULL; + } prsactx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx); prsactx->flag_allow_md = 1; + prsactx->propq = propq_copy; return prsactx; } /* True if PSS parameters are restricted */ #define rsa_pss_restricted(prsactx) (prsactx->min_saltlen != -1) -static int rsa_signature_init(void *vprsactx, void *vrsa) -{ - PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx; - - if (prsactx == NULL || vrsa == NULL || !RSA_up_ref(vrsa)) - return 0; - - RSA_free(prsactx->rsa); - prsactx->rsa = vrsa; - if (RSA_get0_pss_params(prsactx->rsa) != NULL) - prsactx->pad_mode = RSA_PKCS1_PSS_PADDING; - else - prsactx->pad_mode = RSA_PKCS1_PADDING; - /* Maximum for sign, auto for verify */ - prsactx->saltlen = RSA_PSS_SALTLEN_AUTO; - prsactx->min_saltlen = -1; - - return 1; -} - static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname, const char *mdprops) { + if (mdprops == NULL) + mdprops = ctx->propq; + if (mdname != NULL) { EVP_MD *md = EVP_MD_fetch(ctx->libctx, mdname, mdprops); int md_nid = rsa_get_md_nid(md); @@ -222,7 +230,14 @@ static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname, if (md == NULL || md_nid == NID_undef - || !rsa_check_padding(md_nid, ctx->pad_mode)) { + || !rsa_check_padding(md_nid, ctx->pad_mode) + || !rsa_check_parameters(md, ctx)) { + if (md == NULL) + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, + "%s could not be fetched", mdname); + if (md_nid == NID_undef) + ERR_raise_data(ERR_LIB_PROV, PROV_R_DIGEST_NOT_ALLOWED, + "digest=%s", mdname); EVP_MD_free(md); return 0; } @@ -256,18 +271,90 @@ static int rsa_setup_md(PROV_RSA_CTX *ctx, const char *mdname, } static int rsa_setup_mgf1_md(PROV_RSA_CTX *ctx, const char *mdname, - const char *props) + const char *mdprops) { + if (mdprops == NULL) + mdprops = ctx->propq; + if (ctx->mgf1_mdname[0] != '\0') EVP_MD_free(ctx->mgf1_md); - if ((ctx->mgf1_md = EVP_MD_fetch(ctx->libctx, mdname, props)) == NULL) + if ((ctx->mgf1_md = EVP_MD_fetch(ctx->libctx, mdname, mdprops)) == NULL) { + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, + "%s could not be fetched", mdname); return 0; + } OPENSSL_strlcpy(ctx->mgf1_mdname, mdname, sizeof(ctx->mgf1_mdname)); return 1; } +static int rsa_signature_init(void *vprsactx, void *vrsa, int operation) +{ + PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx; + + if (prsactx == NULL || vrsa == NULL || !RSA_up_ref(vrsa)) + return 0; + + RSA_free(prsactx->rsa); + prsactx->rsa = vrsa; + prsactx->operation = operation; + + /* Maximum for sign, auto for verify */ + prsactx->saltlen = RSA_PSS_SALTLEN_AUTO; + prsactx->min_saltlen = -1; + + switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) { + case RSA_FLAG_TYPE_RSA: + prsactx->pad_mode = RSA_PKCS1_PADDING; + break; + case RSA_FLAG_TYPE_RSASSAPSS: + prsactx->pad_mode = RSA_PKCS1_PSS_PADDING; + + { + const RSA_PSS_PARAMS_30 *pss = + rsa_get0_pss_params_30(prsactx->rsa); + + if (!rsa_pss_params_30_is_unrestricted(pss)) { + int md_nid = rsa_pss_params_30_hashalg(pss); + int mgf1md_nid = rsa_pss_params_30_maskgenhashalg(pss); + int min_saltlen = rsa_pss_params_30_saltlen(pss); + const char *mdname, *mgf1mdname; + + mdname = rsa_oaeppss_nid2name(md_nid); + mgf1mdname = rsa_oaeppss_nid2name(mgf1md_nid); + prsactx->min_saltlen = min_saltlen; + + if (mdname == NULL) { + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, + "PSS restrictions lack hash algorithm"); + return 0; + } + if (mgf1mdname == NULL) { + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_DIGEST, + "PSS restrictions lack MGF1 hash algorithm"); + return 0; + } + + strncpy(prsactx->mdname, mdname, sizeof(prsactx->mdname)); + strncpy(prsactx->mgf1_mdname, mgf1mdname, + sizeof(prsactx->mgf1_mdname)); + prsactx->saltlen = min_saltlen; + + return rsa_setup_md(prsactx, mdname, prsactx->propq) + && rsa_setup_mgf1_md(prsactx, mgf1mdname, prsactx->propq); + } + } + + break; + default: + ERR_raise(ERR_LIB_RSA, PROV_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); + return 0; + } + + return 1; +} + static int setup_tbuf(PROV_RSA_CTX *ctx) { if (ctx->tbuf != NULL) @@ -287,10 +374,16 @@ static void clean_tbuf(PROV_RSA_CTX *ctx) static void free_tbuf(PROV_RSA_CTX *ctx) { - OPENSSL_clear_free(ctx->tbuf, RSA_size(ctx->rsa)); + clean_tbuf(ctx); + OPENSSL_free(ctx->tbuf); ctx->tbuf = NULL; } +static int rsa_sign_init(void *vprsactx, void *vrsa) +{ + return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_SIGN); +} + static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen, size_t sigsize, const unsigned char *tbs, size_t tbslen) { @@ -304,8 +397,11 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen, return 1; } - if (sigsize < (size_t)rsasize) + if (sigsize < rsasize) { + ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_SIGNATURE_SIZE, + "is %zu, should be at least %zu", sigsize, rsasize); return 0; + } if (mdsize != 0) { if (tbslen != mdsize) { @@ -313,7 +409,7 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen, return 0; } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (EVP_MD_is_a(prsactx->md, OSSL_DIGEST_NAME_MDC2)) { unsigned int sltmp; @@ -336,7 +432,9 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen, switch (prsactx->pad_mode) { case RSA_X931_PADDING: if ((size_t)RSA_size(prsactx->rsa) < tbslen + 1) { - ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SIZE_TOO_SMALL); + ERR_raise_data(ERR_LIB_PROV, PROV_R_KEY_SIZE_TOO_SMALL, + "RSA key size = %d, expected minimum = %d", + RSA_size(prsactx->rsa), tbslen + 1); return 0; } if (!setup_tbuf(prsactx)) { @@ -370,14 +468,24 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen, switch (prsactx->saltlen) { case RSA_PSS_SALTLEN_DIGEST: if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) { - ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL); + ERR_raise_data(ERR_LIB_PROV, + PROV_R_PSS_SALTLEN_TOO_SMALL, + "minimum salt length set to %d, " + "but the digest only gives %d", + prsactx->min_saltlen, + EVP_MD_size(prsactx->md)); return 0; } /* FALLTHRU */ default: if (prsactx->saltlen >= 0 && prsactx->saltlen < prsactx->min_saltlen) { - ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL); + ERR_raise_data(ERR_LIB_PROV, + PROV_R_PSS_SALTLEN_TOO_SMALL, + "minimum salt length set to %d, but the" + "actual salt length is only set to %d", + prsactx->min_saltlen, + prsactx->saltlen); return 0; } break; @@ -407,7 +515,7 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen, prsactx->pad_mode); } -#ifndef FIPS_MODE +#ifndef FIPS_MODULE end: #endif if (ret <= 0) { @@ -419,6 +527,11 @@ static int rsa_sign(void *vprsactx, unsigned char *sig, size_t *siglen, return 1; } +static int rsa_verify_recover_init(void *vprsactx, void *vrsa) +{ + return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_VERIFYRECOVER); +} + static int rsa_verify_recover(void *vprsactx, unsigned char *rout, size_t *routlen, @@ -459,7 +572,9 @@ static int rsa_verify_recover(void *vprsactx, *routlen = ret; if (routsize < (size_t)ret) { - ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); + ERR_raise_data(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL, + "buffer size is %d, should be %d", + routsize, ret); return 0; } memcpy(rout, prsactx->tbuf, ret); @@ -496,6 +611,11 @@ static int rsa_verify_recover(void *vprsactx, return 1; } +static int rsa_verify_init(void *vprsactx, void *vrsa) +{ + return rsa_signature_init(vprsactx, vrsa, EVP_PKEY_OP_VERIFY); +} + static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen) { @@ -520,29 +640,6 @@ static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen, int ret; size_t mdsize; - /* Check PSS restrictions */ - if (rsa_pss_restricted(prsactx)) { - switch (prsactx->saltlen) { - case RSA_PSS_SALTLEN_AUTO: - ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PSS_SALTLEN); - return 0; - case RSA_PSS_SALTLEN_DIGEST: - if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) { - ERR_raise(ERR_LIB_PROV, - PROV_R_PSS_SALTLEN_TOO_SMALL); - return 0; - } - /* FALLTHRU */ - default: - if (prsactx->saltlen >= 0 - && prsactx->saltlen < prsactx->min_saltlen) { - ERR_raise(ERR_LIB_PROV, PROV_R_PSS_SALTLEN_TOO_SMALL); - return 0; - } - break; - } - } - /* * We need to check this for the RSA_verify_PKCS1_PSS_mgf1() * call @@ -596,18 +693,20 @@ static int rsa_verify(void *vprsactx, const unsigned char *sig, size_t siglen, } static int rsa_digest_signverify_init(void *vprsactx, const char *mdname, - const char *props, void *vrsa) + void *vrsa, int operation) { PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx; prsactx->flag_allow_md = 0; - if (!rsa_signature_init(vprsactx, vrsa) - || !rsa_setup_md(prsactx, mdname, props)) + if (!rsa_signature_init(vprsactx, vrsa, operation) + || !rsa_setup_md(prsactx, mdname, NULL)) /* TODO RL */ return 0; prsactx->mdctx = EVP_MD_CTX_new(); - if (prsactx->mdctx == NULL) + if (prsactx->mdctx == NULL) { + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); goto error; + } if (!EVP_DigestInit_ex(prsactx->mdctx, prsactx->md, NULL)) goto error; @@ -622,8 +721,9 @@ static int rsa_digest_signverify_init(void *vprsactx, const char *mdname, return 0; } -int rsa_digest_signverify_update(void *vprsactx, const unsigned char *data, - size_t datalen) +static int rsa_digest_signverify_update(void *vprsactx, + const unsigned char *data, + size_t datalen) { PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx; @@ -633,8 +733,15 @@ int rsa_digest_signverify_update(void *vprsactx, const unsigned char *data, return EVP_DigestUpdate(prsactx->mdctx, data, datalen); } -int rsa_digest_sign_final(void *vprsactx, unsigned char *sig, size_t *siglen, - size_t sigsize) +static int rsa_digest_sign_init(void *vprsactx, const char *mdname, + void *vrsa) +{ + return rsa_digest_signverify_init(vprsactx, mdname, vrsa, + EVP_PKEY_OP_SIGN); +} + +static int rsa_digest_sign_final(void *vprsactx, unsigned char *sig, + size_t *siglen, size_t sigsize) { PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx; unsigned char digest[EVP_MAX_MD_SIZE]; @@ -661,6 +768,12 @@ int rsa_digest_sign_final(void *vprsactx, unsigned char *sig, size_t *siglen, return rsa_sign(vprsactx, sig, siglen, sigsize, digest, (size_t)dlen); } +static int rsa_digest_verify_init(void *vprsactx, const char *mdname, + void *vrsa) +{ + return rsa_digest_signverify_init(vprsactx, mdname, vrsa, + EVP_PKEY_OP_VERIFY); +} int rsa_digest_verify_final(void *vprsactx, const unsigned char *sig, size_t siglen) @@ -695,6 +808,7 @@ static void rsa_freectx(void *vprsactx) EVP_MD_CTX_free(prsactx->mdctx); EVP_MD_free(prsactx->md); EVP_MD_free(prsactx->mgf1_md); + OPENSSL_free(prsactx->propq); free_tbuf(prsactx); OPENSSL_clear_free(prsactx, sizeof(prsactx)); @@ -706,8 +820,10 @@ static void *rsa_dupctx(void *vprsactx) PROV_RSA_CTX *dstctx; dstctx = OPENSSL_zalloc(sizeof(*srcctx)); - if (dstctx == NULL) + if (dstctx == NULL) { + ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); return NULL; + } *dstctx = *srcctx; dstctx->rsa = NULL; @@ -858,11 +974,13 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname))) return 0; - if (propsp != NULL - && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops))) + + if (propsp == NULL) + pmdprops = NULL; + else if (!OSSL_PARAM_get_utf8_string(propsp, + &pmdprops, sizeof(mdprops))) return 0; - /* TODO(3.0) PSS check needs more work */ if (rsa_pss_restricted(prsactx)) { /* TODO(3.0) figure out what to do for prsactx->md == NULL */ if (prsactx->md == NULL || EVP_MD_is_a(prsactx->md, mdname)) @@ -872,13 +990,14 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) } /* non-PSS code follows */ - if (!rsa_setup_md(prsactx, mdname, mdprops)) + if (!rsa_setup_md(prsactx, mdname, pmdprops)) return 0; } p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_PAD_MODE); if (p != NULL) { int pad_mode = 0; + const char *err_extra_text = NULL; switch (p->data_type) { case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */ @@ -910,31 +1029,49 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) * OAEP padding is for asymmetric cipher only so is not compatible * with signature use. */ - ERR_raise_data(ERR_LIB_PROV, - PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE, - "OAEP padding not allowed for signing / verifying"); - return 0; + err_extra_text = "OAEP padding not allowed for signing / verifying"; + goto bad_pad; case RSA_PKCS1_PSS_PADDING: - if (prsactx->mdname[0] == '\0') - rsa_setup_md(prsactx, "SHA1", ""); - goto cont; - case RSA_PKCS1_PADDING: - case RSA_SSLV23_PADDING: - case RSA_NO_PADDING: - case RSA_X931_PADDING: - if (RSA_get0_pss_params(prsactx->rsa) != NULL) { - ERR_raise_data(ERR_LIB_PROV, - PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE, - "X.931 padding not allowed with RSA-PSS"); + if ((prsactx->operation + & (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY)) == 0) { + err_extra_text = + "PSS padding only allowed for sign and verify operations"; + goto bad_pad; + } + if (prsactx->md == NULL + && !rsa_setup_md(prsactx, OSSL_DIGEST_NAME_SHA1, NULL)) { return 0; } - cont: - if (!rsa_check_padding(prsactx->mdnid, pad_mode)) - return 0; break; + case RSA_PKCS1_PADDING: + err_extra_text = "PKCS#1 padding not allowed with RSA-PSS"; + goto cont; + case RSA_SSLV23_PADDING: + err_extra_text = "SSLv3 padding not allowed with RSA-PSS"; + goto cont; + case RSA_NO_PADDING: + err_extra_text = "No padding not allowed with RSA-PSS"; + goto cont; + case RSA_X931_PADDING: + err_extra_text = "X.931 padding not allowed with RSA-PSS"; + cont: + if (RSA_test_flags(prsactx->rsa, + RSA_FLAG_TYPE_MASK) == RSA_FLAG_TYPE_RSA) + break; + /* FALLTHRU */ default: + bad_pad: + if (err_extra_text == NULL) + ERR_raise(ERR_LIB_PROV, + PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE); + else + ERR_raise_data(ERR_LIB_PROV, + PROV_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE, + err_extra_text); return 0; } + if (!rsa_check_padding(prsactx->mdnid, pad_mode)) + return 0; prsactx->pad_mode = pad_mode; } @@ -978,6 +1115,37 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) return 0; } + if (rsa_pss_restricted(prsactx)) { + switch (prsactx->saltlen) { + case RSA_PSS_SALTLEN_AUTO: + if (prsactx->operation == EVP_PKEY_OP_VERIFY) { + ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PSS_SALTLEN); + return 0; + } + break; + case RSA_PSS_SALTLEN_DIGEST: + if (prsactx->min_saltlen > EVP_MD_size(prsactx->md)) { + ERR_raise_data(ERR_LIB_PROV, + PROV_R_PSS_SALTLEN_TOO_SMALL, + "Should be more than %d, but would be " + "set to match digest size (%d)", + prsactx->min_saltlen, + EVP_MD_size(prsactx->md)); + return 0; + } + /* FALLTHRU */ + default: + if (saltlen >= 0 && saltlen < prsactx->min_saltlen) { + ERR_raise_data(ERR_LIB_PROV, + PROV_R_PSS_SALTLEN_TOO_SMALL, + "Should be more than %d, " + "but would be set to %d", + prsactx->min_saltlen, saltlen); + return 0; + } + } + } + prsactx->saltlen = saltlen; } @@ -991,8 +1159,11 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) if (!OSSL_PARAM_get_utf8_string(p, &pmdname, sizeof(mdname))) return 0; - if (propsp != NULL - && !OSSL_PARAM_get_utf8_string(propsp, &pmdprops, sizeof(mdprops))) + + if (propsp == NULL) + pmdprops = NULL; + else if (!OSSL_PARAM_get_utf8_string(propsp, + &pmdprops, sizeof(mdprops))) return 0; if (prsactx->pad_mode != RSA_PKCS1_PSS_PADDING) { @@ -1000,9 +1171,8 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) return 0; } - /* TODO(3.0) PSS check needs more work */ if (rsa_pss_restricted(prsactx)) { - /* TODO(3.0) figure out what to do for prsactx->md == NULL */ + /* TODO(3.0) figure out what to do for prsactx->mgf1_md == NULL */ if (prsactx->mgf1_md == NULL || EVP_MD_is_a(prsactx->mgf1_md, mdname)) return 1; @@ -1011,7 +1181,7 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) } /* non-PSS code follows */ - if (!rsa_setup_mgf1_md(prsactx, mdname, mdprops)) + if (!rsa_setup_mgf1_md(prsactx, mdname, pmdprops)) return 0; } @@ -1081,20 +1251,22 @@ static const OSSL_PARAM *rsa_settable_ctx_md_params(void *vprsactx) const OSSL_DISPATCH rsa_signature_functions[] = { { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))rsa_newctx }, - { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))rsa_signature_init }, + { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))rsa_sign_init }, { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))rsa_sign }, - { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))rsa_signature_init }, + { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))rsa_verify_init }, { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))rsa_verify }, - { OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT, (void (*)(void))rsa_signature_init }, - { OSSL_FUNC_SIGNATURE_VERIFY_RECOVER, (void (*)(void))rsa_verify_recover }, + { OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT, + (void (*)(void))rsa_verify_recover_init }, + { OSSL_FUNC_SIGNATURE_VERIFY_RECOVER, + (void (*)(void))rsa_verify_recover }, { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, - (void (*)(void))rsa_digest_signverify_init }, + (void (*)(void))rsa_digest_sign_init }, { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, (void (*)(void))rsa_digest_signverify_update }, { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL, (void (*)(void))rsa_digest_sign_final }, { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, - (void (*)(void))rsa_digest_signverify_init }, + (void (*)(void))rsa_digest_verify_init }, { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, (void (*)(void))rsa_digest_signverify_update }, { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL, diff --git a/providers/legacyprov.c b/providers/legacyprov.c index c8ebc9c4..886037cf 100644 --- a/providers/legacyprov.c +++ b/providers/legacyprov.c @@ -13,8 +13,17 @@ #include #include #include +#include "prov/provider_ctx.h" #include "prov/implementations.h" +/* + * Forward declarations to ensure that interface functions are correctly + * defined. + */ +static OSSL_provider_gettable_params_fn legacy_gettable_params; +static OSSL_provider_get_params_fn legacy_get_params; +static OSSL_provider_query_operation_fn legacy_query; + #define ALG(NAMES, FUNC) { NAMES, "provider=legacy", FUNC } #ifdef STATIC_LEGACY @@ -27,19 +36,19 @@ static OSSL_core_gettable_params_fn *c_gettable_params = NULL; static OSSL_core_get_params_fn *c_get_params = NULL; /* Parameters we provide to the core */ -static const OSSL_ITEM legacy_param_types[] = { - { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME }, - { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION }, - { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO }, - { 0, NULL } +static const OSSL_PARAM legacy_param_types[] = { + OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0), + OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0), + OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0), + OSSL_PARAM_END }; -static const OSSL_ITEM *legacy_gettable_params(const OSSL_PROVIDER *prov) +static const OSSL_PARAM *legacy_gettable_params(void *provctx) { return legacy_param_types; } -static int legacy_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) +static int legacy_get_params(void *provctx, OSSL_PARAM params[]) { OSSL_PARAM *p; @@ -79,8 +88,8 @@ static const OSSL_ALGORITHM legacy_ciphers[] = { #ifndef OPENSSL_NO_CAST ALG("CAST5-ECB", cast5128ecb_functions), ALG("CAST5-CBC:CAST-CBC:CAST", cast5128cbc_functions), - ALG("CAST5-OFB", cast564ofb64_functions), - ALG("CAST5-CFB", cast564cfb64_functions), + ALG("CAST5-OFB", cast5128ofb64_functions), + ALG("CAST5-CFB", cast5128cfb64_functions), #endif /* OPENSSL_NO_CAST */ #ifndef OPENSSL_NO_BF ALG("BF-ECB", blowfish128ecb_functions), @@ -133,8 +142,7 @@ static const OSSL_ALGORITHM legacy_ciphers[] = { { NULL, NULL, NULL } }; -static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov, - int operation_id, +static const OSSL_ALGORITHM *legacy_query(void *provctx, int operation_id, int *no_cache) { *no_cache = 0; @@ -147,20 +155,28 @@ static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov, return NULL; } +static void legacy_teardown(void *provctx) +{ + OPENSSL_CTX_free(PROV_LIBRARY_CONTEXT_OF(provctx)); + PROV_CTX_free(provctx); +} + /* Functions we provide to the core */ static const OSSL_DISPATCH legacy_dispatch_table[] = { + { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))legacy_teardown }, { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))legacy_gettable_params }, { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))legacy_get_params }, { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))legacy_query }, { 0, NULL } }; -int OSSL_provider_init(const OSSL_PROVIDER *provider, +int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) { OSSL_core_get_library_context_fn *c_get_libctx = NULL; + OPENSSL_CTX *libctx = NULL; for (; in->function_id != 0; in++) { switch (in->function_id) { @@ -182,13 +198,17 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider, if (c_get_libctx == NULL) return 0; + if ((*provctx = PROV_CTX_new()) == NULL + || (libctx = OPENSSL_CTX_new()) == NULL) { + OPENSSL_CTX_free(libctx); + legacy_teardown(*provctx); + *provctx = NULL; + return 0; + } + PROV_CTX_set0_library_context(*provctx, libctx); + PROV_CTX_set0_handle(*provctx, handle); + *out = legacy_dispatch_table; - /* - * We want to make sure that all calls from this provider that requires - * a library context use the same context as the one used to call our - * functions. We do that by passing it along as the provider context. - */ - *provctx = c_get_libctx(provider); return 1; } diff --git a/providers/nullprov.c b/providers/nullprov.c index a1a26811..945ec2fb 100644 --- a/providers/nullprov.c +++ b/providers/nullprov.c @@ -17,10 +17,6 @@ OSSL_provider_init_fn ossl_null_provider_init; -/* Functions provided by the core */ -static OSSL_core_gettable_params_fn *c_gettable_params = NULL; -static OSSL_core_get_params_fn *c_get_params = NULL; - /* Parameters we provide to the core */ static const OSSL_ITEM null_param_types[] = { { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME }, @@ -67,40 +63,14 @@ static const OSSL_DISPATCH null_dispatch_table[] = { { 0, NULL } }; -int ossl_null_provider_init(const OSSL_PROVIDER *provider, +int ossl_null_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) { - OSSL_core_get_library_context_fn *c_get_libctx = NULL; - - for (; in->function_id != 0; in++) { - switch (in->function_id) { - case OSSL_FUNC_CORE_GETTABLE_PARAMS: - c_gettable_params = OSSL_get_core_gettable_params(in); - break; - case OSSL_FUNC_CORE_GET_PARAMS: - c_get_params = OSSL_get_core_get_params(in); - break; - case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT: - c_get_libctx = OSSL_get_core_get_library_context(in); - break; - /* Just ignore anything we don't understand */ - default: - break; - } - } - - if (c_get_libctx == NULL) - return 0; - *out = null_dispatch_table; - /* - * We want to make sure that all calls from this provider that requires - * a library context use the same context as the one used to call our - * functions. We do that by passing it along as the provider context. - */ - *provctx = c_get_libctx(provider); + /* Could be anything - we don't use it */ + *provctx = (void *)handle; return 1; } diff --git a/ssl/bio_ssl.c b/ssl/bio_ssl.c index b44ec3e5..ce8d148c 100644 --- a/ssl/bio_ssl.c +++ b/ssl/bio_ssl.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -284,6 +284,7 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr) ssl_free(b); if (!ssl_new(b)) return 0; + bs = BIO_get_data(b); } BIO_set_shutdown(b, num); ssl = (SSL *)ptr; diff --git a/ssl/d1_srtp.c b/ssl/d1_srtp.c index 6498f84d..66c1b54e 100644 --- a/ssl/d1_srtp.c +++ b/ssl/d1_srtp.c @@ -1,5 +1,5 @@ /* - * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,6 +19,8 @@ #ifndef OPENSSL_NO_SRTP +DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE) + static SRTP_PROTECTION_PROFILE srtp_known_profiles[] = { { "SRTP_AES128_CM_SHA1_80", diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c index d4198917..bceac720 100644 --- a/ssl/record/rec_layer_s3.c +++ b/ssl/record/rec_layer_s3.c @@ -384,10 +384,12 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, size_t len, s->rlayer.wnum = 0; /* - * If we are supposed to be sending a KeyUpdate then go into init unless we - * have writes pending - in which case we should finish doing that first. + * If we are supposed to be sending a KeyUpdate or NewSessionTicket then go + * into init unless we have writes pending - in which case we should finish + * doing that first. */ - if (wb->left == 0 && s->key_update != SSL_KEY_UPDATE_NONE) + if (wb->left == 0 && (s->key_update != SSL_KEY_UPDATE_NONE + || s->ext.extra_tickets_expected > 0)) ossl_statem_set_in_init(s, 1); /* diff --git a/ssl/record/ssl3_buffer.c b/ssl/record/ssl3_buffer.c index 5e2cceee..2c25099e 100644 --- a/ssl/record/ssl3_buffer.c +++ b/ssl/record/ssl3_buffer.c @@ -94,7 +94,7 @@ int ssl3_setup_write_buffer(SSL *s, size_t numwpipes, size_t len) headerlen = SSL3_RT_HEADER_LENGTH; #if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0 - align = (-SSL3_RT_HEADER_LENGTH) & (SSL3_ALIGN_PAYLOAD - 1); + align = SSL3_ALIGN_PAYLOAD - 1; #endif len = ssl_get_max_send_fragment(s) diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c index 0709f59e..70802a45 100644 --- a/ssl/s3_lib.c +++ b/ssl/s3_lib.c @@ -20,6 +20,10 @@ #include #include "internal/cryptlib.h" +DEFINE_STACK_OF(X509_NAME) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF_CONST(SSL_CIPHER) + #define TLS13_NUM_CIPHERS OSSL_NELEM(tls13_ciphers) #define SSL3_NUM_CIPHERS OSSL_NELEM(ssl3_ciphers) #define SSL3_NUM_SCSVS OSSL_NELEM(ssl3_scsvs) diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index b2ef4759..e81542a8 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -25,6 +25,9 @@ #include "ssl_cert_table.h" #include "internal/thread_once.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_NAME) + static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx, int op, int bits, int nid, void *other, void *ex); @@ -869,7 +872,10 @@ int ssl_build_cert_chain(SSL *s, SSL_CTX *ctx, int flags) untrusted = cpk->chain; } - xs_ctx = X509_STORE_CTX_new_with_libctx(s->ctx->libctx, s->ctx->propq); + if (s == NULL) + xs_ctx = X509_STORE_CTX_new_with_libctx(ctx->libctx, ctx->propq); + else + xs_ctx = X509_STORE_CTX_new_with_libctx(s->ctx->libctx, s->ctx->propq); if (xs_ctx == NULL) { SSLerr(SSL_F_SSL_BUILD_CERT_CHAIN, ERR_R_MALLOC_FAILURE); goto err; @@ -1062,19 +1068,20 @@ int ssl_cert_lookup_by_nid(int nid, size_t *pidx) const SSL_CERT_LOOKUP *ssl_cert_lookup_by_pkey(const EVP_PKEY *pk, size_t *pidx) { - int nid = EVP_PKEY_id(pk); - size_t tmpidx; + size_t i; - if (nid == NID_undef) - return NULL; + for (i = 0; i < OSSL_NELEM(ssl_cert_info); i++) { + const SSL_CERT_LOOKUP *tmp_lu = &ssl_cert_info[i]; - if (!ssl_cert_lookup_by_nid(nid, &tmpidx)) - return NULL; + if (EVP_PKEY_is_a(pk, OBJ_nid2sn(tmp_lu->nid)) + || EVP_PKEY_is_a(pk, OBJ_nid2ln(tmp_lu->nid))) { + if (pidx != NULL) + *pidx = i; + return tmp_lu; + } + } - if (pidx != NULL) - *pidx = tmpidx; - - return &ssl_cert_info[tmpidx]; + return NULL; } const SSL_CERT_LOOKUP *ssl_cert_lookup_by_idx(size_t idx) diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c index c7c4dd1d..44225752 100644 --- a/ssl/ssl_ciph.c +++ b/ssl/ssl_ciph.c @@ -22,6 +22,9 @@ #include "internal/thread_once.h" #include "internal/cryptlib.h" +DEFINE_STACK_OF(SSL_COMP) +DEFINE_STACK_OF_CONST(SSL_CIPHER) + #define SSL_ENC_DES_IDX 0 #define SSL_ENC_3DES_IDX 1 #define SSL_ENC_RC4_IDX 2 diff --git a/ssl/ssl_conf.c b/ssl/ssl_conf.c index cccda866..aefe8ad2 100644 --- a/ssl/ssl_conf.c +++ b/ssl/ssl_conf.c @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2012-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,8 @@ #include #include "internal/nelem.h" +DEFINE_STACK_OF(X509_NAME) + /* * structure holding name tables. This is used for permitted elements in lists * such as TLSv1. @@ -381,7 +383,8 @@ static int cmd_Options(SSL_CONF_CTX *cctx, const char *value) SSL_FLAG_TBL("PrioritizeChaCha", SSL_OP_PRIORITIZE_CHACHA), SSL_FLAG_TBL("MiddleboxCompat", SSL_OP_ENABLE_MIDDLEBOX_COMPAT), SSL_FLAG_TBL_INV("AntiReplay", SSL_OP_NO_ANTI_REPLAY), - SSL_FLAG_TBL_INV("ExtendedMasterSecret", SSL_OP_NO_EXTENDED_MASTER_SECRET) + SSL_FLAG_TBL_INV("ExtendedMasterSecret", SSL_OP_NO_EXTENDED_MASTER_SECRET), + SSL_FLAG_TBL_INV("CANames", SSL_OP_DISABLE_TLSEXT_CA_NAMES) }; if (value == NULL) return -3; diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 5f510351..655a0276 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -26,6 +26,14 @@ #include "internal/refcount.h" #include "internal/ktls.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_NAME) +DEFINE_STACK_OF_CONST(SSL_CIPHER) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(OCSP_RESPID) +DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE) +DEFINE_STACK_OF(SCT) + static int ssl_undefined_function_1(SSL *ssl, SSL3_RECORD *r, size_t s, int t) { (void)r; @@ -2361,6 +2369,15 @@ int SSL_renegotiate_pending(const SSL *s) return (s->renegotiate != 0); } +int SSL_new_session_ticket(SSL *s) +{ + if (SSL_in_init(s) || SSL_IS_FIRST_HANDSHAKE(s) || !s->server + || !SSL_IS_TLS13(s)) + return 0; + s->ext.extra_tickets_expected++; + return 1; +} + long SSL_ctrl(SSL *s, int cmd, long larg, void *parg) { long l; diff --git a/ssl/ssl_local.h b/ssl/ssl_local.h index a57c7a82..888503da 100644 --- a/ssl/ssl_local.h +++ b/ssl/ssl_local.h @@ -1548,6 +1548,8 @@ struct ssl_st { /* RFC4507 session ticket expected to be received or sent */ int ticket_expected; + /* TLS 1.3 tickets requested by the application. */ + int extra_tickets_expected; # ifndef OPENSSL_NO_EC size_t ecpointformats_len; /* our list */ diff --git a/ssl/ssl_rsa.c b/ssl/ssl_rsa.c index e0b48870..7a699747 100644 --- a/ssl/ssl_rsa.c +++ b/ssl/ssl_rsa.c @@ -17,6 +17,8 @@ #include #include +DEFINE_STACK_OF(X509) + static int ssl_set_cert(CERT *c, X509 *x509); static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey); diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c index c3779368..8b8c59a9 100644 --- a/ssl/ssl_sess.c +++ b/ssl/ssl_sess.c @@ -16,6 +16,8 @@ #include "ssl_local.h" #include "statem/statem_local.h" +DEFINE_STACK_OF(X509) + static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s); static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s); static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck); diff --git a/ssl/statem/extensions.c b/ssl/statem/extensions.c index 6bd16091..3c023486 100644 --- a/ssl/statem/extensions.c +++ b/ssl/statem/extensions.c @@ -14,6 +14,8 @@ #include "statem_local.h" #include "internal/cryptlib.h" +DEFINE_STACK_OF(X509_NAME) + static int final_renegotiate(SSL *s, unsigned int context, int sent); static int init_server_name(SSL *s, unsigned int context); static int final_server_name(SSL *s, unsigned int context, int sent); diff --git a/ssl/statem/extensions_clnt.c b/ssl/statem/extensions_clnt.c index e983cb18..e3b51729 100644 --- a/ssl/statem/extensions_clnt.c +++ b/ssl/statem/extensions_clnt.c @@ -12,6 +12,10 @@ #include "internal/cryptlib.h" #include "statem_local.h" +DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE) +DEFINE_STACK_OF_CONST(SSL_CIPHER) +DEFINE_STACK_OF(OCSP_RESPID) + EXT_RETURN tls_construct_ctos_renegotiate(SSL *s, WPACKET *pkt, unsigned int context, X509 *x, size_t chainidx) diff --git a/ssl/statem/extensions_srvr.c b/ssl/statem/extensions_srvr.c index c5fa96d6..fc11a1c9 100644 --- a/ssl/statem/extensions_srvr.c +++ b/ssl/statem/extensions_srvr.c @@ -12,6 +12,10 @@ #include "statem_local.h" #include "internal/cryptlib.h" +DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE) +DEFINE_STACK_OF(OCSP_RESPID) +DEFINE_STACK_OF(X509_EXTENSION) + #define COOKIE_STATE_FORMAT_VERSION 0 /* diff --git a/ssl/statem/statem_clnt.c b/ssl/statem/statem_clnt.c index a0050387..3e65f971 100644 --- a/ssl/statem/statem_clnt.c +++ b/ssl/statem/statem_clnt.c @@ -25,6 +25,10 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(SSL_COMP) +DEFINE_STACK_OF_CONST(SSL_CIPHER) + static MSG_PROCESS_RETURN tls_process_as_hello_retry_request(SSL *s, PACKET *pkt); static MSG_PROCESS_RETURN tls_process_encrypted_extensions(SSL *s, PACKET *pkt); diff --git a/ssl/statem/statem_lib.c b/ssl/statem/statem_lib.c index 30e994da..8fd68f81 100644 --- a/ssl/statem/statem_lib.c +++ b/ssl/statem/statem_lib.c @@ -21,6 +21,10 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_NAME) +DEFINE_STACK_OF_CONST(SSL_CIPHER) + /* * Map error codes to TLS/SSL alart types. */ @@ -2338,7 +2342,7 @@ int construct_ca_names(SSL *s, const STACK_OF(X509_NAME) *ca_sk, WPACKET *pkt) return 0; } - if (ca_sk != NULL) { + if ((ca_sk != NULL) && !(s->options & SSL_OP_DISABLE_TLSEXT_CA_NAMES)) { int i; for (i = 0; i < sk_X509_NAME_num(ca_sk); i++) { diff --git a/ssl/statem/statem_srvr.c b/ssl/statem/statem_srvr.c index 1da07cf3..fa402725 100644 --- a/ssl/statem/statem_srvr.c +++ b/ssl/statem/statem_srvr.c @@ -26,6 +26,10 @@ #include #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(SSL_COMP) +DEFINE_STACK_OF_CONST(SSL_CIPHER) + #define TICKET_NONCE_SIZE 8 typedef struct { @@ -437,6 +441,10 @@ static WRITE_TRAN ossl_statem_server13_write_transition(SSL *s) st->hand_state = TLS_ST_SW_CERT_REQ; return WRITE_TRAN_CONTINUE; } + if (s->ext.extra_tickets_expected > 0) { + st->hand_state = TLS_ST_SW_SESSION_TICKET; + return WRITE_TRAN_CONTINUE; + } /* Try to read from the client instead */ return WRITE_TRAN_FINISHED; @@ -527,7 +535,9 @@ static WRITE_TRAN ossl_statem_server13_write_transition(SSL *s) * Following an initial handshake we send the number of tickets we have * been configured for. */ - if (s->hit || s->num_tickets <= s->sent_tickets) { + if (!SSL_IS_FIRST_HANDSHAKE(s) && s->ext.extra_tickets_expected > 0) { + return WRITE_TRAN_CONTINUE; + } else if (s->hit || s->num_tickets <= s->sent_tickets) { /* We've written enough tickets out. */ st->hand_state = TLS_ST_OK; } @@ -723,7 +733,8 @@ WORK_STATE ossl_statem_server_pre_work(SSL *s, WORK_STATE wst) return WORK_FINISHED_CONTINUE; case TLS_ST_SW_SESSION_TICKET: - if (SSL_IS_TLS13(s) && s->sent_tickets == 0) { + if (SSL_IS_TLS13(s) && s->sent_tickets == 0 + && s->ext.extra_tickets_expected == 0) { /* * Actually this is the end of the handshake, but we're going * straight into writing the session ticket out. So we finish off @@ -732,7 +743,8 @@ WORK_STATE ossl_statem_server_pre_work(SSL *s, WORK_STATE wst) * Calls SSLfatal as required. */ return tls_finish_handshake(s, wst, 0, 0); - } if (SSL_IS_DTLS(s)) { + } + if (SSL_IS_DTLS(s)) { /* * We're into the last flight. We don't retransmit the last flight * unless we need to, so we don't use the timer @@ -4157,10 +4169,13 @@ int tls_construct_new_session_ticket(SSL *s, WPACKET *pkt) /* * Increment both |sent_tickets| and |next_ticket_nonce|. |sent_tickets| * gets reset to 0 if we send more tickets following a post-handshake - * auth, but |next_ticket_nonce| does not. + * auth, but |next_ticket_nonce| does not. If we're sending extra + * tickets, decrement the count of pending extra tickets. */ s->sent_tickets++; s->next_ticket_nonce++; + if (s->ext.extra_tickets_expected > 0) + s->ext.extra_tickets_expected--; ssl_update_cache(s, SSL_SESS_CACHE_SERVER); } diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c index 951e2821..0988d972 100644 --- a/ssl/t1_lib.c +++ b/ssl/t1_lib.c @@ -26,6 +26,10 @@ #include "ssl_local.h" #include +DEFINE_STACK_OF_CONST(SSL_CIPHER) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_NAME) + static const SIGALG_LOOKUP *find_sig_alg(SSL *s, X509 *x, EVP_PKEY *pkey); static int tls12_sigalg_allowed(const SSL *s, int op, const SIGALG_LOOKUP *lu); @@ -174,13 +178,13 @@ static const TLS_GROUP_INFO nid_list[] = { {EVP_PKEY_X448, "X448", 224, TLS_GROUP_CURVE_CUSTOM, 0x001E}, /* X448 (30) */ # endif /* OPENSSL_NO_EC */ # ifndef OPENSSL_NO_GOST - {NID_id_tc26_gost_3410_2012_256_paramSetA, "GOST_2012_256", 112, TLS_GROUP_CURVE_PRIME, 0x0022}, /* GC256A (34) */ - {NID_id_tc26_gost_3410_2012_256_paramSetB, "GOST_2012_256", 112, TLS_GROUP_CURVE_PRIME, 0x0023}, /* GC256B (35) */ - {NID_id_tc26_gost_3410_2012_256_paramSetC, "GOST_2012_256", 112, TLS_GROUP_CURVE_PRIME, 0x0024}, /* GC256C (36) */ - {NID_id_tc26_gost_3410_2012_256_paramSetD, "GOST_2012_256", 112, TLS_GROUP_CURVE_PRIME, 0x0025}, /* GC256D (37) */ - {NID_id_tc26_gost_3410_2012_512_paramSetA, "GOST_2012_512", 112, TLS_GROUP_CURVE_PRIME, 0x0026}, /* GC512A (38) */ - {NID_id_tc26_gost_3410_2012_512_paramSetB, "GOST_2012_512", 112, TLS_GROUP_CURVE_PRIME, 0x0027}, /* GC512B (39) */ - {NID_id_tc26_gost_3410_2012_512_paramSetC, "GOST_2012_512", 112, TLS_GROUP_CURVE_PRIME, 0x0028}, /* GC512C (40) */ + {NID_id_tc26_gost_3410_2012_256_paramSetA, "GOST_2012_256", 128, TLS_GROUP_CURVE_PRIME, 0x0022}, /* GC256A (34) */ + {NID_id_tc26_gost_3410_2012_256_paramSetB, "GOST_2012_256", 128, TLS_GROUP_CURVE_PRIME, 0x0023}, /* GC256B (35) */ + {NID_id_tc26_gost_3410_2012_256_paramSetC, "GOST_2012_256", 128, TLS_GROUP_CURVE_PRIME, 0x0024}, /* GC256C (36) */ + {NID_id_tc26_gost_3410_2012_256_paramSetD, "GOST_2012_256", 128, TLS_GROUP_CURVE_PRIME, 0x0025}, /* GC256D (37) */ + {NID_id_tc26_gost_3410_2012_512_paramSetA, "GOST_2012_512", 256, TLS_GROUP_CURVE_PRIME, 0x0026}, /* GC512A (38) */ + {NID_id_tc26_gost_3410_2012_512_paramSetB, "GOST_2012_512", 256, TLS_GROUP_CURVE_PRIME, 0x0027}, /* GC512B (39) */ + {NID_id_tc26_gost_3410_2012_512_paramSetC, "GOST_2012_512", 256, TLS_GROUP_CURVE_PRIME, 0x0028}, /* GC512C (40) */ # endif /* OPENSSL_NO_GOST */ # ifndef OPENSSL_NO_DH /* Security bit values for FFDHE groups are updated as per RFC 7919 */ diff --git a/ssl/tls13_enc.c b/ssl/tls13_enc.c index 0b317f28..19e763d1 100644 --- a/ssl/tls13_enc.c +++ b/ssl/tls13_enc.c @@ -413,11 +413,18 @@ static int derive_secret_key_and_iv(SSL *s, int sending, const EVP_MD *md, uint32_t algenc; ivlen = EVP_CCM_TLS_IV_LEN; - if (s->s3.tmp.new_cipher == NULL) { + if (s->s3.tmp.new_cipher != NULL) { + algenc = s->s3.tmp.new_cipher->algorithm_enc; + } else if (s->session->cipher != NULL) { /* We've not selected a cipher yet - we must be doing early data */ algenc = s->session->cipher->algorithm_enc; + } else if (s->psksession != NULL && s->psksession->cipher != NULL) { + /* We must be doing early data with out-of-band PSK */ + algenc = s->psksession->cipher->algorithm_enc; } else { - algenc = s->s3.tmp.new_cipher->algorithm_enc; + SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DERIVE_SECRET_KEY_AND_IV, + ERR_R_EVP_LIB); + goto err; } if (algenc & (SSL_AES128CCM8 | SSL_AES256CCM8)) taglen = EVP_CCM8_TLS_TAG_LEN; diff --git a/test/README b/test/README index 17dffa0e..9094d9a3 100644 --- a/test/README +++ b/test/README @@ -151,3 +151,7 @@ works fine and can be used in place of: The former produces a more meaningful message on failure than the latter. +Note that the test infrastructure automatically sets up all required environment +variables (such as OPENSSL_MODULES, OPENSSL_CONF etc) for the tests. Individual +tests may choose to override the default settings as required. + diff --git a/test/README.ssltest.md b/test/README.ssltest.md index 6fc73015..6ae10fdc 100644 --- a/test/README.ssltest.md +++ b/test/README.ssltest.md @@ -1,4 +1,5 @@ -# SSL tests +SSL tests +========= SSL testcases are configured in the `ssl-tests` directory. @@ -14,20 +15,19 @@ corresponding to the default configuration. These testcases live in For more details, see `ssl-tests/01-simple.cnf.in` for an example. -## Configuring the test +Configuring the test +-------------------- First, give your test a name. The names do not have to be unique. An example test input looks like this: -``` { name => "test-default", server => { "CipherString" => "DEFAULT" }, client => { "CipherString" => "DEFAULT" }, test => { "ExpectedResult" => "Success" }, } -``` The test section supports the following options @@ -111,19 +111,18 @@ handshake. If this is "empty" the list is expected to be empty otherwise it is a file of certificates whose subject names form the list. -## Configuring the client and server +Configuring the client and server +--------------------------------- The client and server configurations can be any valid `SSL_CTX` configurations. For details, see the manpages for `SSL_CONF_cmd`. Give your configurations as a dictionary of CONF commands, e.g. -``` -server => { - "CipherString" => "DEFAULT", - "MinProtocol" => "TLSv1", -} -``` + server => { + "CipherString" => "DEFAULT", + "MinProtocol" => "TLSv1", + } The following sections may optionally be defined: @@ -146,14 +145,12 @@ The following sections may optionally be defined: Additional handshake settings can be configured in the `extra` section of each client and server: -``` -client => { - "CipherString" => "DEFAULT", - extra => { - "ServerName" => "server2", + client => { + "CipherString" => "DEFAULT", + extra => { + "ServerName" => "server2", + } } -} -``` #### Supported client-side options @@ -202,21 +199,18 @@ automatically. Server certificate verification is requested by default. You can override these options by redefining them: -``` -client => { - "VerifyCAFile" => "/path/to/custom/file" -} -``` + client => { + "VerifyCAFile" => "/path/to/custom/file" + } or by deleting them -``` -client => { - "VerifyCAFile" => undef -} -``` + client => { + "VerifyCAFile" => undef + } -## Adding a test to the test harness +Adding a test to the test harness +--------------------------------- 1. Add a new test configuration to `test/ssl-tests`, following the examples of existing `*.cnf.in` files (for example, `01-simple.cnf.in`). @@ -224,32 +218,26 @@ client => { 2. Generate the generated `*.cnf` test input file. You can do so by running `generate_ssl_tests.pl`: -``` -$ ./config -$ cd test -$ TOP=.. perl -I ../util/perl/ generate_ssl_tests.pl ssl-tests/my.cnf.in \ - > ssl-tests/my.cnf -``` + $ ./config + $ cd test + $ TOP=.. perl -I ../util/perl/ generate_ssl_tests.pl \ + ssl-tests/my.cnf.in default > ssl-tests/my.cnf -where `my.cnf.in` is your test input file. +where `my.cnf.in` is your test input file and `default` is the provider to use. +For all the pre-generated test files you should use the default provider. For example, to generate the test cases in `ssl-tests/01-simple.cnf.in`, do -``` -$ TOP=.. perl -I ../util/perl/ generate_ssl_tests.pl ssl-tests/01-simple.cnf.in > ssl-tests/01-simple.cnf -``` + $ TOP=.. perl -I ../util/perl/ generate_ssl_tests.pl \ + ssl-tests/01-simple.cnf.in default > ssl-tests/01-simple.cnf Alternatively (hackish but simple), you can comment out -``` -unlink glob $tmp_file; -``` + unlink glob $tmp_file; in `test/recipes/80-test_ssl_new.t` and run -``` -$ make TESTS=test_ssl_new test -``` + $ make TESTS=test_ssl_new test This will save the generated output in a `*.tmp` file in the build directory. @@ -257,13 +245,13 @@ This will save the generated output in a `*.tmp` file in the build directory. the test suite has any skip conditions, update those too (see `test/recipes/80-test_ssl_new.t` for details). -## Running the tests with the test harness +Running the tests with the test harness +--------------------------------------- -``` -HARNESS_VERBOSE=yes make TESTS=test_ssl_new test -``` + HARNESS_VERBOSE=yes make TESTS=test_ssl_new test -## Running a test manually +Running a test manually +----------------------- These steps are only needed during development. End users should run `make test` or follow the instructions above to run the SSL test suite. @@ -272,17 +260,13 @@ To run an SSL test manually from the command line, the `TEST_CERTS_DIR` environment variable to point to the location of the certs. E.g., from the root OpenSSL directory, do -``` -$ CTLOG_FILE=test/ct/log_list.cnf TEST_CERTS_DIR=test/certs test/ssl_test \ - test/ssl-tests/01-simple.cnf -``` + $ CTLOG_FILE=test/ct/log_list.cnf TEST_CERTS_DIR=test/certs test/ssl_test \ + test/ssl-tests/01-simple.cnf or for shared builds -``` -$ CTLOG_FILE=test/ct/log_list.cnf TEST_CERTS_DIR=test/certs \ - util/wrap.pl test/ssl_test test/ssl-tests/01-simple.cnf -``` + $ CTLOG_FILE=test/ct/log_list.cnf TEST_CERTS_DIR=test/certs \ + util/wrap.pl test/ssl_test test/ssl-tests/01-simple.cnf Note that the test expectations sometimes depend on the Configure settings. For example, the negotiated protocol depends on the set of available (enabled) diff --git a/test/aesgcmtest.c b/test/aesgcmtest.c index 4a255d50..bacbb8f1 100644 --- a/test/aesgcmtest.c +++ b/test/aesgcmtest.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -116,7 +116,7 @@ static int badkeylen_test(void) return ret; } -#ifdef FIPS_MODE +#ifdef FIPS_MODULE static int ivgen_test(void) { unsigned char iv_gen[16]; @@ -127,14 +127,14 @@ static int ivgen_test(void) return do_encrypt(iv_gen, ct, &ctlen, tag, &taglen) && do_decrypt(iv_gen, ct, ctlen, tag, taglen); } -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ int setup_tests(void) { ADD_TEST(kat_test); ADD_TEST(badkeylen_test); -#ifdef FIPS_MODE +#ifdef FIPS_MODULE ADD_TEST(ivgen_test); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ return 1; } diff --git a/test/bio_memleak_test.c b/test/bio_memleak_test.c index 49ee712a..cafc60e7 100644 --- a/test/bio_memleak_test.c +++ b/test/bio_memleak_test.c @@ -1,7 +1,7 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/test/bn_internal_test.c b/test/bn_internal_test.c index f3e87496..2dda2345 100644 --- a/test/bn_internal_test.c +++ b/test/bn_internal_test.c @@ -1,7 +1,7 @@ /* - * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/test/certs/fake-gp.pem b/test/certs/fake-gp.pem new file mode 100644 index 00000000..c25f1724 --- /dev/null +++ b/test/certs/fake-gp.pem @@ -0,0 +1,36 @@ +-----BEGIN CERTIFICATE----- +MIIGTzCCBTegAwIBAgIEAJiW+zANBgkqhkiG9w0BAQsFADBpMQswCQYDVQQGEwJO +TDEeMBwGA1UECgwVU3RhYXQgZGVyIE5lZGVybGFuZGVuMTowOAYDVQQDDDFTdGFh +dCBkZXIgTmVkZXJsYW5kZW4gT3JnYW5pc2F0aWUgUGVyc29vbiBDQSAtIEczMB4X +DTIwMDQxNjE0MDUyMFoXDTIwMDUxNjE0MDUyMFowbDERMA8GA1UEDAwISHVpc2Fy +dHMxEjAQBgNVBAUTCTAwMDA2NjYwMDEaMBgGA1UEAwwRSGVybWFudXMgQm9lcmhh +dmUxGjAYBgNVBAoMEUhlcm1hbnVzIEJvZXJoYXZlMQswCQYDVQQGEwJOTDCCASIw +DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALs6G9LEt9nOBxjdyjD8nRH3mkDp +oltjjMB9USuY2jHy5TTEzCwQW6ohJuN6s+TbwQYvJns+keJKWB5d2u7EtEuiND1O +4QIkH2j044DYdeomcuZ3Tt56rptA9oJ2OGDvT0/PZOQlFzXcNkf+3Bo40Ppr372X +dam/6eOZ928b+pfTmUDOyMPU40hyJimi+hxnLuPPYhQipIpkpGXtyA9r9qBuXqja +I0Ramdi/+WuBch2NkvjWw36tMO4MREdF2cOxLXtiMMD5404bI68ugH6sJeg3pTWd +9fMzmoD4TH0eR2u5Ayn70fGiYY9xCdLckRas2R4txC4BvUHVYimrhsc/yekCAwEA +AaOCAvowggL2MAkGA1UdEwQCMAAwMQYDVR0lBCowKAYIKwYBBQUHAwEGCCsGAQUF +BwMCBggrBgEFBQcDAwYIKwYBBQUHAwQwHQYDVR0OBBYEFJRP8jB2vCG/hWC52q3r +wU7AIkbQMG0GA1UdIwRmMGShXqRcMFoxKzApBgNVBAMMIlN0YWF0IGRlciBOZWRl +cmxhbmRlbiBSb290IENBIC0gRzMxHjAcBgNVBAoMFVN0YWF0IGRlciBOZWRlcmxh +bmRlbjELMAkGA1UEBhMCTkyCAgPyMDcGCCsGAQUFBwEBBCswKTAnBggrBgEFBQcw +AYYbaHR0cDovL29jc3AudXppLXJlZ2lzdGVyLm5sMFAGA1UdHwRJMEcwRaBDoEGG +P2h0dHA6Ly93d3cudXppLXJlZ2lzdGVyLm5sL2NkcC91emktcmVnaXN0ZXJfem9y +Z3ZlcmxlbmVyX2NhLmNybDCCASoGA1UdIASCASEwggEdMIIBGQYKYIQQAYdrAQIC +AjCCAQkwNAYIKwYBBQUHAgEWKGh0dHBzOi8vd3d3LnV6aS1yZWdpc3Rlci5ubC9j +cHMvY3BzLmh0bWwwgdAGCCsGAQUFBwICMIHDGoHASGV0IHRvZXBhc3NpbmdzZ2Vi +aWVkIHZhbiBkaXQgY2VydGlmaWNhYXQgaXMgYmVwZXJrdCB0b3QgY29tbXVuaWNh +dGllIGJpbm5lbiBoZXQgZG9tZWluIE92ZXJoZWlkIHpvYWxzIGFhbmdlZ2V2ZW4g +aW4gaGV0IFByb2dyYW1tYSB2YW4gRWlzZW4gdmFuIGRlIFBLSSB2b29yIGRlIE92 +ZXJoZWlkLiBaaWUgd3d3LnBraW92ZXJoZWlkLm5sMFUGA1UdEQROMEygSgYDVQUF +oEMWQTIuMTYuNTI4LjEuMTAwMy4xLjMuNS41LjItMS0wMDAwMDA2NjY2LVotMTIz +NDU2NzgtMDEuMDE1LTEyMzQ1Njc4MBgGCCsGAQUFBwEDBAwwCjAIBgYEAI5GAQEw +DQYJKoZIhvcNAQELBQADggEBACqw60ermDQAmqra5eaJS6RC6WPNzm28V1/CaBYd +7TD6s+hdmjrxCXsXjQNBea4+f6Ig1usJOF/G1GR4znfBIWeB73ve5lZ19qwoJf2P +OgajStG2qgWMGPuCbsDQVQDIDWVd99C1/iTq9te3Ljp9A8baWQMcDLGifkzRFnWU +k+toRfZE5K4WmD+8GL7gp1We1egMuBvCO4z3uACcKWK5FKFSvLdhuOXf3jIe9T6+ +xo4RbfzLaF9EjgcGeXdZvDYfu6TZv/ZW6yh3vAtRlxhhymHsA19Bl70k1Im1Xkuy +Um0W+wwXjUcRfiuXarWwbSZxOZZcSFjYQuiQlvUgWSEeiR0= +-----END CERTIFICATE----- diff --git a/test/cipherbytes_test.c b/test/cipherbytes_test.c index 370d033a..cbbfff2a 100644 --- a/test/cipherbytes_test.c +++ b/test/cipherbytes_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ #include "internal/nelem.h" #include "testutil.h" +DEFINE_STACK_OF(SSL_CIPHER) + static SSL_CTX *ctx; static SSL *s; diff --git a/test/cipherlist_test.c b/test/cipherlist_test.c index b950411c..f850d7bb 100644 --- a/test/cipherlist_test.c +++ b/test/cipherlist_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ #include "internal/nelem.h" #include "testutil.h" +DEFINE_STACK_OF_CONST(SSL_CIPHER) + typedef struct cipherlist_test_fixture { const char *test_case_name; SSL_CTX *server; diff --git a/test/ciphername_test.c b/test/ciphername_test.c index c4ec6cad..c82a1648 100644 --- a/test/ciphername_test.c +++ b/test/ciphername_test.c @@ -22,6 +22,8 @@ #include "internal/nelem.h" #include "testutil.h" +DEFINE_STACK_OF(SSL_CIPHER) + typedef struct cipher_id_name { int id; const char *name; diff --git a/test/cmp_client_test.c b/test/cmp_client_test.c index 44d09e04..ab2b9302 100644 --- a/test/cmp_client_test.c +++ b/test/cmp_client_test.c @@ -15,6 +15,9 @@ #ifndef NDEBUG /* tests need mock server, which is available only if !NDEBUG */ +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(OSSL_CMP_ITAV) + static const char *server_key_f; static const char *server_cert_f; static const char *client_key_f; @@ -64,7 +67,7 @@ static CMP_SES_TEST_FIXTURE *set_up(const char *const test_case_name) || !ossl_cmp_mock_srv_set1_certOut(fixture->srv_ctx, client_cert) || (srv_cmp_ctx = OSSL_CMP_SRV_CTX_get0_cmp_ctx(fixture->srv_ctx)) == NULL - || !OSSL_CMP_CTX_set1_clCert(srv_cmp_ctx, server_cert) + || !OSSL_CMP_CTX_set1_cert(srv_cmp_ctx, server_cert) || !OSSL_CMP_CTX_set1_pkey(srv_cmp_ctx, server_key)) goto err; if (!TEST_ptr(fixture->cmp_ctx = ctx = OSSL_CMP_CTX_new()) diff --git a/test/cmp_ctx_test.c b/test/cmp_ctx_test.c index 470ab63b..89805342 100644 --- a/test/cmp_ctx_test.c +++ b/test/cmp_ctx_test.c @@ -13,6 +13,12 @@ #include +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(ASN1_UTF8STRING) +DEFINE_STACK_OF(X509_EXTENSION) +DEFINE_STACK_OF(OSSL_CMP_ITAV) +DEFINE_STACK_OF(POLICYINFO) + typedef struct test_fixture { const char *test_case_name; OSSL_CMP_CTX *ctx; @@ -494,7 +500,11 @@ static X509_STORE *X509_STORE_new_1(void) #define IS_0(x) ((x) == 0) /* for any type */ #define DROP(x) (void)(x) /* dummy free() for non-pointer and function types */ -#define ERR(x) (CMPerr(0, CMP_R_NULL_ARGUMENT), x) +#define RET_IF_NULL_ARG(ctx, ret) \ + if (ctx == NULL) { \ + CMPerr(0, CMP_R_NULL_ARGUMENT); \ + return ret; \ + } #define DEFINE_SET_GET_TEST(OSSL_CMP, CTX, N, M, DUP, FIELD, TYPE) \ DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get##M, DUP, FIELD, \ @@ -519,7 +529,8 @@ static X509_STORE *X509_STORE_new_1(void) #define DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, N, DUP, FIELD, TYPE, DEFAULT) \ static TYPE *OSSL_CMP_CTX_get0_##FIELD(const CMP_CTX *ctx) \ { \ - return ctx == NULL ? ERR(NULL) : (TYPE *)ctx->FIELD; \ + RET_IF_NULL_ARG(ctx, NULL); \ + return (TYPE *)ctx->FIELD; \ } \ DEFINE_SET_GET_TEST_DEFAULT(OSSL_CMP, CTX, N, 0, DUP, FIELD, TYPE, DEFAULT) #define DEFINE_SET_TEST(OSSL_CMP, CTX, N, DUP, FIELD, TYPE) \ @@ -528,7 +539,8 @@ static X509_STORE *X509_STORE_new_1(void) #define DEFINE_SET_SK_TEST(OSSL_CMP, CTX, N, FIELD, TYPE) \ static STACK_OF(TYPE) *OSSL_CMP_CTX_get0_##FIELD(const CMP_CTX *ctx) \ { \ - return ctx == NULL ? ERR(NULL) : ctx->FIELD; \ + RET_IF_NULL_ARG(ctx, NULL); \ + return ctx->FIELD; \ } \ DEFINE_SET_GET_BASE_TEST(OSSL_CMP##_##CTX, set##N, get0, 1, FIELD, \ STACK_OF(TYPE)*, NULL, IS_0, \ @@ -538,9 +550,8 @@ typedef OSSL_HTTP_bio_cb_t OSSL_CMP_http_cb_t; #define DEFINE_SET_CB_TEST(FIELD) \ static OSSL_CMP_##FIELD##_t OSSL_CMP_CTX_get_##FIELD(const CMP_CTX *ctx) \ { \ - if (ctx == NULL) \ - CMPerr(0, CMP_R_NULL_ARGUMENT); \ - return ctx == NULL ? NULL /* cannot use ERR(NULL) here */ : ctx->FIELD;\ + RET_IF_NULL_ARG(ctx, NULL); \ + return ctx->FIELD; \ } \ DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, FIELD, \ OSSL_CMP_##FIELD##_t, NULL, IS_0, \ @@ -557,7 +568,8 @@ typedef OSSL_HTTP_bio_cb_t OSSL_CMP_http_cb_t; #define DEFINE_SET_INT_TEST(FIELD) \ static int OSSL_CMP_CTX_get_##FIELD(const CMP_CTX *ctx) \ { \ - return ctx == NULL ? ERR(-1) : ctx->FIELD; \ + RET_IF_NULL_ARG(ctx, -1); \ + return ctx->FIELD; \ } \ DEFINE_SET_GET_INT_TEST_DEFAULT(OSSL_CMP, CTX, FIELD, IS_0) @@ -581,8 +593,10 @@ typedef OSSL_HTTP_bio_cb_t OSSL_CMP_http_cb_t; \ static char *OSSL_CMP_CTX_get1_##FIELD##_str(const CMP_CTX *ctx) \ { \ - const ASN1_OCTET_STRING *bytes = ctx == NULL ? ERR(NULL) : ctx->FIELD; \ + const ASN1_OCTET_STRING *bytes = NULL; \ \ + RET_IF_NULL_ARG(ctx, NULL); \ + bytes = ctx->FIELD; \ return bytes == NULL ? NULL : \ OPENSSL_strndup((char *)bytes->data, bytes->length); \ } @@ -732,7 +746,7 @@ DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set0, get0, 0, trustedStore, DEFAULT_STORE, X509_STORE_new_1(), X509_STORE_free) DEFINE_SET_GET_SK_X509_TEST(OSSL_CMP, CTX, 1, 0, untrusted_certs) -DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, clCert, X509) +DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, cert, X509) DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 0, pkey, EVP_PKEY) DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, recipient, X509_NAME) @@ -815,7 +829,7 @@ int setup_tests(void) ADD_TEST(test_CTX_set0_get0_trustedStore); ADD_TEST(test_CTX_set1_get0_untrusted_certs); /* client authentication: */ - ADD_TEST(test_CTX_set1_get0_clCert); + ADD_TEST(test_CTX_set1_get0_cert); ADD_TEST(test_CTX_set1_get0_pkey); /* the following two also test ossl_cmp_asn1_octet_string_set1_bytes(): */ ADD_TEST(test_CTX_set1_get1_referenceValue_str); diff --git a/test/cmp_hdr_test.c b/test/cmp_hdr_test.c index 6e78432d..cd30c497 100644 --- a/test/cmp_hdr_test.c +++ b/test/cmp_hdr_test.c @@ -11,6 +11,9 @@ #include "cmp_testlib.h" +DEFINE_STACK_OF(OSSL_CMP_ITAV) +DEFINE_STACK_OF(ASN1_UTF8STRING) + static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH]; typedef struct test_fixture { diff --git a/test/cmp_msg_test.c b/test/cmp_msg_test.c index 6aadd439..ca03dc23 100644 --- a/test/cmp_msg_test.c +++ b/test/cmp_msg_test.c @@ -11,6 +11,8 @@ #include "cmp_testlib.h" +DEFINE_STACK_OF(OSSL_CMP_CERTRESPONSE) + static const char *server_cert_f; static const char *pkcs10_f; @@ -163,7 +165,7 @@ static int test_cmp_create_ir_protection_fails(void) if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, newkey)) || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) /* newkey used by default for signing does not match cert: */ - || !TEST_true(OSSL_CMP_CTX_set1_clCert(fixture->cmp_ctx, cert))) { + || !TEST_true(OSSL_CMP_CTX_set1_cert(fixture->cmp_ctx, cert))) { tear_down(fixture); fixture = NULL; } diff --git a/test/cmp_protect_test.c b/test/cmp_protect_test.c index fc006ac6..1d1e009a 100644 --- a/test/cmp_protect_test.c +++ b/test/cmp_protect_test.c @@ -11,6 +11,8 @@ #include "cmp_testlib.h" +DEFINE_STACK_OF(X509) + static const char *ir_protected_f; static const char *ir_unprotected_f; static const char *ip_PBM_f; @@ -240,7 +242,7 @@ static int test_MSG_protect_with_certificate_and_key(void) OSSL_CMP_MSG_dup(ir_unprotected)) || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) || !TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedkey)) - || !TEST_true(OSSL_CMP_CTX_set1_clCert(fixture->cmp_ctx, cert))) { + || !TEST_true(OSSL_CMP_CTX_set1_cert(fixture->cmp_ctx, cert))) { tear_down(fixture); fixture = NULL; } diff --git a/test/cmp_status_test.c b/test/cmp_status_test.c index 7358f158..bf6699a2 100644 --- a/test/cmp_status_test.c +++ b/test/cmp_status_test.c @@ -11,6 +11,8 @@ #include "cmp_testlib.h" +DEFINE_STACK_OF(ASN1_UTF8STRING) + typedef struct test_fixture { const char *test_case_name; int pkistatus; diff --git a/test/cmp_testlib.c b/test/cmp_testlib.c index bb3351b4..d25ab746 100644 --- a/test/cmp_testlib.c +++ b/test/cmp_testlib.c @@ -12,6 +12,8 @@ #include "cmp_testlib.h" #include /* needed in case config no-deprecated */ +DEFINE_STACK_OF(X509) + EVP_PKEY *load_pem_key(const char *file) { EVP_PKEY *key = NULL; diff --git a/test/cmp_vfy_test.c b/test/cmp_vfy_test.c index 5f43f1e2..c74dd2fa 100644 --- a/test/cmp_vfy_test.c +++ b/test/cmp_vfy_test.c @@ -11,6 +11,7 @@ #include "cmp_testlib.h" #include "../crypto/crmf/crmf_local.h" /* for manipulating POPO signature */ +DEFINE_STACK_OF(OSSL_CRMF_MSG) static const char *server_f; static const char *client_f; diff --git a/test/cmsapitest.c b/test/cmsapitest.c index ad1cbd1c..697daa81 100644 --- a/test/cmsapitest.c +++ b/test/cmsapitest.c @@ -1,7 +1,7 @@ /* * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -16,6 +16,8 @@ #include "testutil.h" +DEFINE_STACK_OF(X509) + static X509 *cert = NULL; static EVP_PKEY *privkey = NULL; diff --git a/test/confdump.c b/test/confdump.c index dbf62446..3750d2cc 100644 --- a/test/confdump.c +++ b/test/confdump.c @@ -1,5 +1,5 @@ /* - * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -14,6 +14,9 @@ #include #include +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF_CSTRING() + static STACK_OF(OPENSSL_CSTRING) *section_names = NULL; static void collect_section_name(CONF_VALUE *v) diff --git a/test/crltest.c b/test/crltest.c index 6a2ef4e9..ff2fadaa 100644 --- a/test/crltest.c +++ b/test/crltest.c @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -17,6 +17,9 @@ #include "testutil.h" +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_CRL) + #define PARAM_TIME 1474934400 /* Sep 27th, 2016 */ static const char *kCRLTestRoot[] = { diff --git a/test/ct_test.c b/test/ct_test.c index bd098c5d..79ffcbf9 100644 --- a/test/ct_test.c +++ b/test/ct_test.c @@ -21,6 +21,9 @@ #include #ifndef OPENSSL_NO_CT + +DEFINE_STACK_OF(SCT) + /* Used when declaring buffers to read text files into */ # define CT_TEST_MAX_FILE_SIZE 8096 diff --git a/test/danetest.c b/test/danetest.c index b0d6ffe5..96b9579f 100644 --- a/test/danetest.c +++ b/test/danetest.c @@ -26,6 +26,8 @@ #include "internal/nelem.h" +DEFINE_STACK_OF(X509) + #define _UC(c) ((unsigned char)(c)) static const char *basedomain; diff --git a/test/drbg_cavs_test.c b/test/drbg_cavs_test.c index 2c0829da..2873417f 100644 --- a/test/drbg_cavs_test.c +++ b/test/drbg_cavs_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -254,7 +254,7 @@ static int test_cavs_kats(const struct drbg_kat *test[], int i) const struct drbg_kat *td = test[i]; int rv = 0; -#ifdef FIPS_MODE +#ifdef FIPS_MODULE /* FIPS mode doesn't support instantiating without a derivation function */ if ((td->flags & USE_DF) == 0) return TEST_skip("instantiating without derivation function " diff --git a/test/drbg_extra_test.c b/test/drbg_extra_test.c index 642f7449..e7c0d77d 100644 --- a/test/drbg_extra_test.c +++ b/test/drbg_extra_test.c @@ -1,7 +1,7 @@ /* * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -75,10 +75,8 @@ static int run_extra_kat(const struct drbg_extra_kat *td) failures++; err: - if (drbg != NULL) { - RAND_DRBG_uninstantiate(drbg); - RAND_DRBG_free(drbg); - } + RAND_DRBG_uninstantiate(drbg); + RAND_DRBG_free(drbg); return failures == 0; } diff --git a/test/drbg_extra_test.h b/test/drbg_extra_test.h index 4c771573..5153dafe 100644 --- a/test/drbg_extra_test.h +++ b/test/drbg_extra_test.h @@ -1,7 +1,7 @@ /* * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/test/drbgtest.c b/test/drbgtest.c index 3354fe16..4eb8f7a2 100644 --- a/test/drbgtest.c +++ b/test/drbgtest.c @@ -111,7 +111,7 @@ typedef struct drbg_selftest_data_st { make_drbg_test_data(nid, 0, pr, p) static DRBG_SELFTEST_DATA drbg_test[] = { -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* FIPS mode doesn't support CTR DRBG without a derivation function */ make_drbg_test_data_no_df (NID_aes_128_ctr, aes_128_no_df, 0), make_drbg_test_data_no_df (NID_aes_192_ctr, aes_192_no_df, 0), @@ -850,7 +850,7 @@ static int test_rand_drbg_reseed(void) /* fill 'randomness' buffer with some arbitrary data */ memset(rand_add_buf, 'r', sizeof(rand_add_buf)); -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* * Test whether all three DRBGs are reseeded by RAND_add(). * The before_reseed time has to be measured here and passed into the @@ -876,7 +876,7 @@ static int test_rand_drbg_reseed(void) if (!TEST_true(test_drbg_reseed(0, master, public, private, 0, 0, 0, 0))) goto error; reset_drbg_hook_ctx(); -#else /* FIPS_MODE */ +#else /* FIPS_MODULE */ /* * In FIPS mode, random data provided by the application via RAND_add() * is not considered a trusted entropy source. It is only treated as @@ -1251,7 +1251,7 @@ static int test_set_defaults(void) && TEST_int_eq(public->flags, RAND_DRBG_FLAG_PUBLIC) /* FIPS mode doesn't support CTR DRBG without a derivation function */ -#ifndef FIPS_MODE +#ifndef FIPS_MODULE /* Change DRBG defaults and change master and check again */ && TEST_true(RAND_DRBG_set_defaults(NID_aes_256_ctr, RAND_DRBG_FLAG_CTR_NO_DF)) @@ -1347,7 +1347,7 @@ static int test_crngt(int n) crngt_case = n % crngt_num_cases; crngt_idx = 0; crngt_get_entropy = &crngt_entropy_cb; -#ifndef FIPS_MODE +#ifndef FIPS_MODULE if (!TEST_true(RAND_DRBG_set_callbacks(drbg, &rand_crngt_get_entropy, &rand_crngt_cleanup_entropy, &rand_drbg_get_nonce, diff --git a/test/dsatest.c b/test/dsatest.c index eac4a17e..c9857d6c 100644 --- a/test/dsatest.c +++ b/test/dsatest.c @@ -155,6 +155,7 @@ static int dsa_keygen_test(void) unsigned char seed_out[32]; char group_out[32]; size_t len = 0; + const OSSL_PARAM *settables = NULL; static const unsigned char seed_data[] = { 0xa6, 0xf5, 0x28, 0x8c, 0x50, 0x77, 0xa5, 0x68, 0x6d, 0x3a, 0xf5, 0xf1, 0xc6, 0x4c, 0xdc, 0x35, @@ -244,6 +245,10 @@ static int dsa_keygen_test(void) goto end; if (!TEST_ptr(pg_ctx = EVP_PKEY_CTX_new_from_name(NULL, "DSA", NULL)) || !TEST_int_gt(EVP_PKEY_paramgen_init(pg_ctx), 0) + || !TEST_ptr_null(EVP_PKEY_CTX_gettable_params(pg_ctx)) + || !TEST_ptr(settables = EVP_PKEY_CTX_settable_params(pg_ctx)) + || !TEST_ptr(OSSL_PARAM_locate_const(settables, + OSSL_PKEY_PARAM_FFC_PBITS)) || !TEST_true(EVP_PKEY_CTX_set_dsa_paramgen_bits(pg_ctx, 2048)) || !TEST_true(EVP_PKEY_CTX_set_dsa_paramgen_q_bits(pg_ctx, 224)) || !TEST_true(EVP_PKEY_CTX_set_dsa_paramgen_seed(pg_ctx, seed_data, diff --git a/test/dtls_mtu_test.c b/test/dtls_mtu_test.c index 33603bae..b0730077 100644 --- a/test/dtls_mtu_test.c +++ b/test/dtls_mtu_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,6 +20,8 @@ /* for SSL_READ_ETM() */ #include "../ssl/ssl_local.h" +DEFINE_STACK_OF(SSL_CIPHER) + static int debug = 0; static unsigned int clnt_psk_callback(SSL *ssl, const char *hint, diff --git a/test/ecdsatest.c b/test/ecdsatest.c index cbe5e62d..f7d6608f 100644 --- a/test/ecdsatest.c +++ b/test/ecdsatest.c @@ -123,10 +123,10 @@ static int x9_62_tests(int n) TEST_info("ECDSA KATs for curve %s", OBJ_nid2sn(nid)); -#ifdef FIPS_MODE +#ifdef FIPS_MODULE if (EC_curve_nid2nist(nid) == NULL) return TEST_skip("skip non approved curves"); -#endif /* FIPS_MODE */ +#endif /* FIPS_MODULE */ if (!TEST_ptr(mctx = EVP_MD_CTX_new()) /* get the message digest */ diff --git a/test/ectest.c b/test/ectest.c index 5c31efe1..bbcd9677 100644 --- a/test/ectest.c +++ b/test/ectest.c @@ -8,6 +8,14 @@ * https://www.openssl.org/source/license.html */ +/* + * We need access to the deprecated EC_POINTs_mul for testing purposes + * when the deprecated calls are not hidden + */ +#ifndef OPENSSL_NO_DEPRECATED_3_0 +# define OPENSSL_SUPPRESS_DEPRECATED +#endif + #include #include "internal/nelem.h" #include "testutil.h" @@ -64,8 +72,10 @@ static int group_order_tests(EC_GROUP *group) goto err; for (i = 1; i <= 2; i++) { +# ifndef OPENSSL_NO_DEPRECATED_3_0 const BIGNUM *scalars[6]; const EC_POINT *points[6]; +# endif if (!TEST_true(BN_set_word(n1, i)) /* @@ -97,11 +107,11 @@ static int group_order_tests(EC_GROUP *group) /* Add P to verify the result. */ || !TEST_true(EC_POINT_add(group, Q, Q, P, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, Q)) - - /* Exercise EC_POINTs_mul, including corner cases. */ || !TEST_false(EC_POINT_is_at_infinity(group, P))) goto err; +# ifndef OPENSSL_NO_DEPRECATED_3_0 + /* Exercise EC_POINTs_mul, including corner cases. */ scalars[0] = scalars[1] = BN_value_one(); points[0] = points[1] = P; @@ -125,6 +135,7 @@ static int group_order_tests(EC_GROUP *group) if (!TEST_true(EC_POINTs_mul(group, P, NULL, 6, points, scalars, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, P))) goto err; +# endif } r = 1; @@ -152,8 +163,10 @@ static int prime_field_tests(void) *P_256 = NULL, *P_384 = NULL, *P_521 = NULL; EC_POINT *P = NULL, *Q = NULL, *R = NULL; BIGNUM *x = NULL, *y = NULL, *z = NULL, *yplusone = NULL; +# ifndef OPENSSL_NO_DEPRECATED_3_0 const EC_POINT *points[4]; const BIGNUM *scalars[4]; +# endif unsigned char buf[100]; size_t len, r = 0; int k; @@ -548,6 +561,9 @@ static int prime_field_tests(void) || !TEST_true(EC_POINT_is_at_infinity(group, R)) /* R = P + 2Q */ || !TEST_false(EC_POINT_is_at_infinity(group, Q))) goto err; + +# ifndef OPENSSL_NO_DEPRECATED_3_0 + TEST_note("combined multiplication ..."); points[0] = Q; points[1] = Q; points[2] = Q; @@ -558,11 +574,10 @@ static int prime_field_tests(void) || !TEST_BN_even(y) || !TEST_true(BN_rshift1(y, y))) goto err; + scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */ scalars[1] = y; - TEST_note("combined multiplication ..."); - /* z is still the group order */ if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) || !TEST_true(EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) @@ -593,10 +608,8 @@ static int prime_field_tests(void) if (!TEST_true(EC_POINTs_mul(group, P, NULL, 4, points, scalars, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, P))) goto err; - +# endif TEST_note(" ok\n"); - - r = 1; err: BN_CTX_free(ctx); @@ -803,8 +816,10 @@ static int char2_curve_test(int n) BIGNUM *x = NULL, *y = NULL, *z = NULL, *cof = NULL, *yplusone = NULL; EC_GROUP *group = NULL, *variable = NULL; EC_POINT *P = NULL, *Q = NULL, *R = NULL; +# ifndef OPENSSL_NO_DEPRECATED_3_0 const EC_POINT *points[3]; const BIGNUM *scalars[3]; +# endif struct c2_curve_test *const test = char2_curve_tests + n; if (!TEST_ptr(ctx = BN_CTX_new()) @@ -888,6 +903,8 @@ static int char2_curve_test(int n) || !TEST_false(EC_POINT_is_at_infinity(group, Q))) goto err; +# ifndef OPENSSL_NO_DEPRECATED_3_0 + TEST_note("combined multiplication ..."); points[0] = Q; points[1] = Q; points[2] = Q; @@ -899,8 +916,6 @@ static int char2_curve_test(int n) scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */ scalars[1] = y; - TEST_note("combined multiplication ..."); - /* z is still the group order */ if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) || !TEST_true(EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) @@ -929,7 +944,8 @@ static int char2_curve_test(int n) if (!TEST_true(EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx)) || !TEST_true(EC_POINT_is_at_infinity(group, P))) - goto err;; + goto err; +# endif } r = 1; diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 115a1331..53d2f3af 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -29,6 +29,8 @@ #include "internal/sizes.h" #include "crypto/evp.h" +static OPENSSL_CTX *testctx = NULL; + /* * kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you * should never use this key anywhere but in an example. @@ -765,7 +767,7 @@ static int test_EVP_PKCS82PKEY(void) } #endif -#if !defined(OPENSSL_NO_SM2) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_SM2) && !defined(FIPS_MODULE) static int test_EVP_SM2_verify(void) { @@ -1005,7 +1007,7 @@ static struct keys_st { #endif }; -static int test_set_get_raw_keys_int(int tst, int pub) +static int test_set_get_raw_keys_int(int tst, int pub, int uselibctx) { int ret = 0; unsigned char buf[80]; @@ -1022,17 +1024,34 @@ static int test_set_get_raw_keys_int(int tst, int pub) if (pub) { inlen = strlen(keys[tst].pub); in = (unsigned char *)keys[tst].pub; - pkey = EVP_PKEY_new_raw_public_key(keys[tst].type, - NULL, - in, - inlen); + if (uselibctx) { + pkey = EVP_PKEY_new_raw_public_key_with_libctx( + testctx, + OBJ_nid2sn(keys[tst].type), + NULL, + in, + inlen); + } else { + pkey = EVP_PKEY_new_raw_public_key(keys[tst].type, + NULL, + in, + inlen); + } } else { inlen = strlen(keys[tst].priv); in = (unsigned char *)keys[tst].priv; - pkey = EVP_PKEY_new_raw_private_key(keys[tst].type, - NULL, - in, - inlen); + if (uselibctx) { + pkey = EVP_PKEY_new_raw_private_key_with_libctx( + testctx, OBJ_nid2sn(keys[tst].type), + NULL, + in, + inlen); + } else { + pkey = EVP_PKEY_new_raw_private_key(keys[tst].type, + NULL, + in, + inlen); + } } if (!TEST_ptr(pkey) @@ -1052,8 +1071,10 @@ static int test_set_get_raw_keys_int(int tst, int pub) static int test_set_get_raw_keys(int tst) { - return test_set_get_raw_keys_int(tst, 0) - && test_set_get_raw_keys_int(tst, 1); + return test_set_get_raw_keys_int(tst, 0, 0) + && test_set_get_raw_keys_int(tst, 0, 1) + && test_set_get_raw_keys_int(tst, 1, 0) + && test_set_get_raw_keys_int(tst, 1, 1); } static int pkey_custom_check(EVP_PKEY *pkey) @@ -1158,6 +1179,29 @@ static int test_EVP_PKEY_check(int i) return ret; } +#ifndef OPENSSL_NO_CMAC +static int test_CMAC_keygen(void) +{ + /* + * This is a legacy method for CMACs, but should still work. + * This verifies that it works without an ENGINE. + */ + EVP_PKEY_CTX *kctx = EVP_PKEY_CTX_new_id(EVP_PKEY_CMAC, NULL); + int ret = 0; + + if (!TEST_true(EVP_PKEY_keygen_init(kctx) > 0) + && !TEST_true(EVP_PKEY_CTX_ctrl(kctx, -1, EVP_PKEY_OP_KEYGEN, + EVP_PKEY_CTRL_CIPHER, + 0, (void *)EVP_aes_256_ecb()) > 0)) + goto done; + ret = 1; + + done: + EVP_PKEY_CTX_free(kctx); + return ret; +} +#endif + static int test_HKDF(void) { EVP_PKEY_CTX *pctx; @@ -1583,6 +1627,11 @@ static int test_keygen_with_empty_template(int n) int setup_tests(void) { + testctx = OPENSSL_CTX_new(); + + if (!TEST_ptr(testctx)) + return 0; + ADD_ALL_TESTS(test_EVP_DigestSignInit, 9); ADD_TEST(test_EVP_DigestVerifyInit); ADD_TEST(test_EVP_Enveloped); @@ -1590,7 +1639,7 @@ int setup_tests(void) #ifndef OPENSSL_NO_EC ADD_TEST(test_EVP_PKCS82PKEY); #endif -#if !defined(OPENSSL_NO_SM2) && !defined(FIPS_MODE) +#if !defined(OPENSSL_NO_SM2) && !defined(FIPS_MODULE) ADD_TEST(test_EVP_SM2); ADD_TEST(test_EVP_SM2_verify); #endif @@ -1604,6 +1653,9 @@ int setup_tests(void) if (!TEST_int_eq(EVP_PKEY_meth_add0(custom_pmeth), 1)) return 0; ADD_ALL_TESTS(test_EVP_PKEY_check, OSSL_NELEM(keycheckdata)); +#ifndef OPENSSL_NO_CMAC + ADD_TEST(test_CMAC_keygen); +#endif ADD_TEST(test_HKDF); #ifndef OPENSSL_NO_EC ADD_TEST(test_X509_PUBKEY_inplace); @@ -1624,3 +1676,8 @@ int setup_tests(void) return 1; } + +void cleanup_tests(void) +{ + OPENSSL_CTX_free(testctx); +} diff --git a/test/evp_pkey_provided_test.c b/test/evp_pkey_provided_test.c index 1ded0d9f..c5ef7241 100644 --- a/test/evp_pkey_provided_test.c +++ b/test/evp_pkey_provided_test.c @@ -130,7 +130,12 @@ static int test_print_key_using_pem(const char *alg, const EVP_PKEY *pk) if (!TEST_ptr(membio)) goto err; - if (!TEST_true(EVP_PKEY_print_private(membio, pk, 0, NULL)) + if (/* Output Encrypted private key in PEM form */ + !TEST_true(PEM_write_bio_PrivateKey(bio_out, pk, EVP_aes_256_cbc(), + (unsigned char *)"pass", 4, + NULL, NULL)) + /* Private key in text form */ + || !TEST_true(EVP_PKEY_print_private(membio, pk, 0, NULL)) || !TEST_true(compare_with_file(alg, PRIV_TEXT, membio)) /* Public key in PEM form */ || !TEST_true(PEM_write_bio_PUBKEY(membio, pk)) @@ -138,11 +143,7 @@ static int test_print_key_using_pem(const char *alg, const EVP_PKEY *pk) /* Unencrypted private key in PEM form */ || !TEST_true(PEM_write_bio_PrivateKey(membio, pk, NULL, NULL, 0, NULL, NULL)) - || !TEST_true(compare_with_file(alg, PRIV_PEM, membio)) - /* Encrypted private key in PEM form */ - || !TEST_true(PEM_write_bio_PrivateKey(bio_out, pk, EVP_aes_256_cbc(), - (unsigned char *)"pass", 4, - NULL, NULL))) + || !TEST_true(compare_with_file(alg, PRIV_PEM, membio))) goto err; ret = 1; @@ -1211,6 +1212,25 @@ static int test_fromdata_dsa_fips186_4(void) return ret; } + +static int test_check_dsa(void) +{ + int ret = 0; + EVP_PKEY_CTX *ctx = NULL; + + if (!TEST_ptr(ctx = EVP_PKEY_CTX_new_from_name(NULL, "DSA", NULL)) + || !TEST_false(EVP_PKEY_check(ctx)) + || !TEST_false(EVP_PKEY_public_check(ctx)) + || !TEST_false(EVP_PKEY_private_check(ctx)) + || !TEST_false(EVP_PKEY_pairwise_check(ctx))) + goto err; + + ret = 1; + err: + EVP_PKEY_CTX_free(ctx); + + return ret; +} #endif /* OPENSSL_NO_DSA */ @@ -1231,6 +1251,7 @@ int setup_tests(void) ADD_TEST(test_fromdata_dh_named_group); #endif #ifndef OPENSSL_NO_DSA + ADD_TEST(test_check_dsa); ADD_TEST(test_fromdata_dsa_fips186_4); #endif #ifndef OPENSSL_NO_EC diff --git a/test/evp_test.c b/test/evp_test.c index 71e47162..6727a007 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -25,6 +25,8 @@ #include "testutil.h" #include "evp_test.h" +DEFINE_STACK_OF_STRING() + #define AAD_NUM 4 typedef struct evp_test_method_st EVP_TEST_METHOD; diff --git a/test/handshake_helper.c b/test/handshake_helper.c index d46db3f2..32aa12c4 100644 --- a/test/handshake_helper.c +++ b/test/handshake_helper.c @@ -26,6 +26,8 @@ #include #endif +DEFINE_STACK_OF(X509_NAME) + HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void) { HANDSHAKE_RESULT *ret; diff --git a/test/http_test.c b/test/http_test.c index 6449c6f6..f0b12a7d 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -15,6 +15,8 @@ #include "testutil.h" +DEFINE_STACK_OF(CONF_VALUE) + static const ASN1_ITEM *x509_it = NULL; static X509 *x509 = NULL; #define SERVER "mock.server" diff --git a/test/insta.priv.pem b/test/insta.priv.pem new file mode 100755 index 00000000..8612994d --- /dev/null +++ b/test/insta.priv.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEAoiNNxo5pwk1lD1em3madbpKz86GSYyGlQtd0ZhIX1tOUFo9l +Fex7n5Osv0A99pKb+7EKqB9Ghg6mJ29kIUUmLACnfZJ/q+U6s9T4zFrYyXweUNJv +QgbA2ojDPyVoRp2T1ekahPh4DpxPWNKfYECDRbrxkHMM3WiIqYFLU8hYvEMGSWRH +HbnS/vG7MTaVDkR8d0zixTOp0fST5c1UUTqppYlThac/BG1kk3hyjIjz5o7lspfX +3s/eAYgT9GhYHL6Uy4o4OqCleR39aVc0dMrrjb7hsmX6ecNwqJOE5AHHOG4Ti6Cb +weSOcdH5PRFzdpao5rlTErsFHlUSTca4mfVeWwIDAQABAoIBAQCUYAZevBjgbP8c +qTPVtsY/WBVB0Qwrl7CqmIy2k7wpJfoRIyx4ga8n+3ZMlredm9EO5ZdA/04EhAdd +czyIjcU+42JjMduQLPgpda4xJLnauLDteYXDQHbgBePXN55TcQTG7skMAm2rwTOD +r0uWQ7Nd7pP9gqu1OmJF7EJI68D4llCU1FrOrliwSDzHWP3p4QmCW3M9PQJ68xw1 +gE7X1QflROGivcFoRgcgeoJDzpxveGvPbEn6Q+05/FMRVxjqWhpxdZ9/SL7iRz1e +45T+P9a8OLgTyErT3Lp/f/vuHA1tlbAYumhSnxXsb+nHi80aDcImOrNQHAp076Ik +bkZ1NpOxAoGBAM3Ulgi2hUPdoAMFtHZF8eBHRzn+4uTfY2s33wObiUJQ8VbGDeJY +ifCfOwLThiAXAqktrs7ItwWDYmzd5xPYGQeWoKcBEoZ+dvaaOe8H7TCMnjB3R3i1 +ACSDHo/3c+NfFOnPJtXL85jeAqGYH50uOtYmYaBVe6xASTBgNvP7snYHAoGBAMmo +ZBQqgIhoqMRapGh6n4OpzH0Nt9ruOTJoteAfbLdAu7X+wAaMuxEaAmZQRDYj0lzX +Ty8DlKSy7vfvXtghxMBEv4+dsYpagXcUOeEZSPfu1c3e253dAov6C0MdREKWBT7P ++NwPBowPy0CP/yBeHaw7d/P7/SYIoPXLGraGl6ANAoGBAMmmce7LUjgw0mjjl+8f +i14cts08x3FO4YnTTOut34VW43oNwuBzuYBBn4CfVpHtuS+hj9cKkTQXib/6jj7E +wZDLo0y6Ijodf9MNOaDSdS/RM9Frqlu5iBA9XR3SYnjpWAXQas2eaGLlblJ+RMqq +1f2j0JVR6j3RJWL9gBj8B9TVAoGBALYZrs4bF1iXEhfGNoL2gIdX1QX0VluIFfR0 +ZBDQr87H0Ppm4qbHfMHTt+kGgKJXNMaL08CDvj4AKxWPfhk0XUS2kDmzUDi8w/5x +MFcaCy+A6Gdw4OcsRfl7QaJIknSCnpf7HCI0G1hthsB1iBCFjMwUI50ap54p2pg6 +4ZOD9PYdAoGAERi5Hlq7+rJeDi3VunKHySqV9mvbOPNclEUmAdKi1yuu3INF1Zgv +Lf432ZI/Ufk2g888ed5ZGE1IMULc2tgSIAMzdX4ZYI4uGFLkHWzSOM6a7NCeZuVt +W+NgUYa2qsqFEd9kqaoDbNry+nPvLM7fWXvBoE4oNkeJhHjOIabBPvw= +-----END RSA PRIVATE KEY----- diff --git a/test/insta_ca.cert.pem b/test/insta_ca.cert.pem new file mode 100755 index 00000000..4b7e31b8 --- /dev/null +++ b/test/insta_ca.cert.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDkDCCAnigAwIBAgIDCZU1MA0GCSqGSIb3DQEBBQUAMDoxCzAJBgNVBAYTAkZJ +MRMwEQYDVQQKEwpJbnN0YSBEZW1vMRYwFAYDVQQDEw1JbnN0YSBEZW1vIENBMB4X +DTA2MDEwMjA4NDgzOFoXDTI1MTIzMTA4NDgzOFowOjELMAkGA1UEBhMCRkkxEzAR +BgNVBAoTCkluc3RhIERlbW8xFjAUBgNVBAMTDUluc3RhIERlbW8gQ0EwggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDF57bSwj+hZnkgLyLtFsoNIN19qBv9 +GIoqFaCiPvw6VQgMXR15t+Z5sdYHdydGp875yJD4wDq2K7cjMoCXALxLeyp6dCY6 +WPC6Hk3QvZtMRuDAz8+0Nb5qaC4+O+7c7j1h/Gs8Jpj+TUuSkmtlCVIGPSWkWaQl +FhLWeUnKRW8bj1CJQguV7igF19kGQKUZ/VZj+n5xIXKHc8njC1ZrS/s0IBFViQkZ +63nTdNPLHQ4Xu8uKrbJbYEK1S4KVNH3L9yA4ut+brqX8n6OulTsKntvMdwNWZdor +KoM15D3lmM7QUGDflJdSQ/qvBVTda+ccrT21sp4hdwwiU01vxQguT26JAgMBAAGj +gZ4wgZswHwYDVR0jBBgwFoAUPHjduMGNV/UFKl5t4FhySvpEJWEwHQYDVR0OBBYE +FDx43bjBjVf1BSpebeBYckr6RCVhMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8E +CDAGAQH/AgEAMDUGCWCGSAGG+EIBDQQoFiZJbnN0YSBEZW1vIENBIC0gb25seSBm +b3IgZGVtbyBwdXJwb3NlczANBgkqhkiG9w0BAQUFAAOCAQEAuVRmRimTxVTZMNXi +3u4bRCq7GxJ4Lonx3mocxYiwBjCYwqn5dPAd4AHrA1HWYCEvIPo52FibpUNNljqH +v7CSoEBg2f4If6cFtwudobqNvf8Z50CAnxlwpPy4k+EbXlh49/uZBtu8+Lc2Ss7L +QaNHHiOeHxYeGX7pTcr6fnXQWAbbn4SLyqniW7ZTqjNJvC79Ym7KowMYzCbmozzv +3xqElA+g/MLFfxn52c/vl/obOVk5eBf3f7V68qKL2IDEip3fyZyoelhfTypq944m +sSJFQjoVzgd7ykgouEwOceOT8YMWWigNsWl/hsVJ03Ri7TxRX4+v8dMEbat+SsTL +AqTTgQ== +-----END CERTIFICATE----- diff --git a/test/ocspapitest.c b/test/ocspapitest.c index 9e8c3062..4ea6c636 100644 --- a/test/ocspapitest.c +++ b/test/ocspapitest.c @@ -18,6 +18,8 @@ #include "testutil.h" +DEFINE_STACK_OF(X509) + static const char *certstr; static const char *privkeystr; diff --git a/test/p_test.c b/test/p_test.c index cecb40ec..5a491234 100644 --- a/test/p_test.c +++ b/test/p_test.c @@ -48,9 +48,9 @@ static const OSSL_PARAM *p_gettable_params(void *_) return p_param_types; } -static int p_get_params(void *vprov, OSSL_PARAM params[]) +static int p_get_params(void *vhand, OSSL_PARAM params[]) { - const OSSL_PROVIDER *prov = vprov; + const OSSL_CORE_HANDLE *hand = vhand; OSSL_PARAM *p = params; int ok = 1; @@ -77,7 +77,7 @@ static int p_get_params(void *vprov, OSSL_PARAM params[]) opensslv = provname = greeting = NULL; - if (c_get_params(prov, counter_request)) { + if (c_get_params(hand, counter_request)) { if (greeting) { strcpy(buf, greeting); } else { @@ -119,7 +119,7 @@ static const OSSL_DISPATCH p_test_table[] = { { 0, NULL } }; -int OSSL_provider_init(const OSSL_PROVIDER *provider, +int OSSL_provider_init(const OSSL_CORE_HANDLE *handle, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out, void **provctx) @@ -139,7 +139,7 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider, } /* Because we use this in get_params, we need to pass it back */ - *provctx = (void *)provider; + *provctx = (void *)handle; *out = p_test_table; return 1; diff --git a/test/param_build_test.c b/test/param_build_test.c index a253f063..d2cf78dc 100644 --- a/test/param_build_test.c +++ b/test/param_build_test.c @@ -205,7 +205,7 @@ static int builder_limit_test(void) for (i = 0; i < n; i++) { names[i][0] = 'A' + (i / 26) - 1; - names[i][0] = 'a' + (i % 26) - 1; + names[i][1] = 'a' + (i % 26) - 1; names[i][2] = '\0'; if (!TEST_true(OSSL_PARAM_BLD_push_int(bld, names[i], 3 * i + 1))) goto err; diff --git a/test/property_test.c b/test/property_test.c index ca407b2b..6f8216ef 100644 --- a/test/property_test.c +++ b/test/property_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use @@ -9,6 +9,7 @@ */ #include +#include #include "testutil.h" #include "internal/nelem.h" #include "internal/property.h" @@ -383,6 +384,35 @@ err: return res; } +static int test_fips_mode(void) +{ + int ret = 0; + OPENSSL_CTX *ctx = NULL; + + if (!TEST_ptr(ctx = OPENSSL_CTX_new())) + goto err; + + ret = TEST_true(EVP_set_default_properties(ctx, "default=yes,fips=yes")) + && TEST_true(EVP_default_properties_is_fips_enabled(ctx)) + && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes")) + && TEST_false(EVP_default_properties_is_fips_enabled(ctx)) + && TEST_true(EVP_set_default_properties(ctx, "fips=no")) + && TEST_false(EVP_default_properties_is_fips_enabled(ctx)) + && TEST_true(EVP_set_default_properties(ctx, "fips!=no")) + && TEST_true(EVP_default_properties_is_fips_enabled(ctx)) + && TEST_true(EVP_set_default_properties(ctx, "fips=no")) + && TEST_false(EVP_default_properties_is_fips_enabled(ctx)) + && TEST_true(EVP_set_default_properties(ctx, "fips=no,default=yes")) + && TEST_true(EVP_default_properties_enable_fips(ctx, 1)) + && TEST_true(EVP_default_properties_is_fips_enabled(ctx)) + && TEST_true(EVP_default_properties_enable_fips(ctx, 0)) + && TEST_false(EVP_default_properties_is_fips_enabled(ctx)); +err: + OPENSSL_CTX_free(ctx); + return ret; +} + + int setup_tests(void) { ADD_TEST(test_property_string); @@ -393,5 +423,6 @@ int setup_tests(void) ADD_TEST(test_register_deregister); ADD_TEST(test_property); ADD_TEST(test_query_cache_stochastic); + ADD_TEST(test_fips_mode); return 1; } diff --git a/test/recipes/03-test_fipsinstall.t b/test/recipes/03-test_fipsinstall.t index b35ddfc7..16ae9556 100644 --- a/test/recipes/03-test_fipsinstall.t +++ b/test/recipes/03-test_fipsinstall.t @@ -27,7 +27,6 @@ plan skip_all => "Test only supported in a fips build" if disabled("fips"); plan tests => 12; my $infile = bldtop_file('providers', platform->dso('fips')); -$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); # fail if no module name ok(!run(app(['openssl', 'fipsinstall', '-out', 'fips.cnf', '-module', diff --git a/test/recipes/03-test_internal_bn.t b/test/recipes/03-test_internal_bn.t index 8aed18ac..3018ccff 100644 --- a/test/recipes/03-test_internal_bn.t +++ b/test/recipes/03-test_internal_bn.t @@ -1,7 +1,7 @@ #! /usr/bin/env perl -# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/test/recipes/03-test_internal_rsa_sp800_56b.t b/test/recipes/03-test_internal_rsa_sp800_56b.t index 2f5e0034..3922f0b2 100644 --- a/test/recipes/03-test_internal_rsa_sp800_56b.t +++ b/test/recipes/03-test_internal_rsa_sp800_56b.t @@ -1,7 +1,7 @@ #! /usr/bin/env perl -# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/test/recipes/04-test_pem.t b/test/recipes/04-test_pem.t index 0e6e4195..b7b28ea7 100644 --- a/test/recipes/04-test_pem.t +++ b/test/recipes/04-test_pem.t @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -28,6 +28,8 @@ my %cert_expected = ( "cert-1023line.pem" => 1, "cert-1024line.pem" => 1, "cert-1025line.pem" => 1, + "cert-254-chars-at-the-end.pem" => 1, + "cert-254-chars-in-the-middle.pem" => 1, "cert-255line.pem" => 1, "cert-256line.pem" => 1, "cert-257line.pem" => 1, @@ -43,6 +45,7 @@ my %cert_expected = ( "cert-misalignedpad.pem" => 0, "cert-onecolumn.pem" => 1, "cert-oneline.pem" => 1, + "cert-oneline-multiple-of-254.pem" => 1, "cert-shortandlongline.pem" => 1, "cert-shortline.pem" => 1, "cert-threecolumn.pem" => 1, diff --git a/test/recipes/04-test_pem_data/cert-254-chars-at-the-end.pem b/test/recipes/04-test_pem_data/cert-254-chars-at-the-end.pem new file mode 100644 index 00000000..0b6a3ba3 --- /dev/null +++ b/test/recipes/04-test_pem_data/cert-254-chars-at-the-end.pem @@ -0,0 +1,6 @@ +-----BEGIN CERTIFICATE----- +MIIEcjCCAyegAwIBAgIUPLgYY73GEwkikNCKRJrcbCR+TbQwDQYJKoZIhvcNAQELBQAwgZUxCzAJBgNVBAYTAkFVMWMwYQYDVQQIDFpUaGUgR3JlYXQgU3RhdGUgb2YgTG9uZy1XaW5kZWQgQ2VydGlmaWNhdGUgRmllbGQgTmFtZXMgV2hlcmVieSB0byBJbmNyZWFzZSB0aGUgT3V0cHV0IFNpemUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA0MDcwMDAwNDJaFw0zMDA0MDUwMDAwNDJaMIGVMQswCQYDVQQGEwJBVTFjMGEGA1UECAxaVGhlIEdyZWF0IFN0YXRlIG9mIExvbmctV2luZGVkIENlcnRpZmljYXRlIEZpZWxkIE5hbWVzIFdoZXJlYnkgdG8gSW5jcmVhc2UgdGhlIE91dHB1dCBTaXplMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggFUMA0GCSqGSIb3DQEBAQUAA4IBQQAwggE8AoIBMwLf +mipKB41NPXrbp/T5eu+fndvZq72N/Tq0vZp2dRoz89NEFC3jYVBjp4pmVwCS9F/fGX1tnVfhb9k/4fqiI/y9lBVzxaHyMG/pt0D2nTS8iaMTM7uBeRvB5rUZlEbU8uvv4GXu3CeP/NnVceXruGbPb4IpjfoUbGLvn5oK35h8a+LNY5f7QRBlAXtUwYrdxVzT+CqQ4wIAuqoIVXgRIweveS1ArbS8hOtsVnu1bUAQVKqORHx8gtbOyiA4heTCEOkwh45YV6KW+uLI1wTeE4E9erlI4RwZ7umbBnQai/hYL//AUfQKQhpGbgfyJrS0UYY7WEP/mcFQh0U2EBTXtAy/e4XPiftViR3+pd+G2TJ/JFofDDzJRrceeo +9tUnMr0pKtU7oB77lSKgsruKKkhn6lLH8CAwEAAaNTMFEwHQYDVR0OBBYEFIkawSiFUdL6G3jw8qg1WQI8Xi4rMB8GA1UdIwQYMBaAFIkawSiFUdL6G3jw8qg1WQI8Xi4rMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggE0AAHe/+71vykcq9BQ5h2X7MpnkE5n0Yn0Xi24uuCpv59JjABmOdaeT6XBQ5UJN8WfidawgzbJ6WiWgjflaMfRfjsdCJRgvdw0gfXXXrsseJMeMYnw1hQTGuB83BKjXBdL6zb45qGf2Fgjm3aNW2NUVM+Q2QfMjo +Kx13hTyDh9l5nOhMv/Rkygcx1Row2WbkvrhxvCLxY0VhL7RuPV8K0ogKicv8VJgQriOUVTTkqBP1xUimKSTaNaZ8KAnC7thxxZHxsNa45a6AouPSzyAOPZQgCJW83OIFxvWsdYU1KvP1wmoi1XC9giSQ/5sLPu/eAYTzmY+Xd6Sq8dF8uyodeI2gFu3AzC28PVKeUriIGfxaqEUn+aXx5W+r8JTE6fQ9mBo9YxJBXG+OTIFgHR27q2dJwqK9c= +-----END CERTIFICATE----- diff --git a/test/recipes/04-test_pem_data/cert-254-chars-in-the-middle.pem b/test/recipes/04-test_pem_data/cert-254-chars-in-the-middle.pem new file mode 100644 index 00000000..cc9076b4 --- /dev/null +++ b/test/recipes/04-test_pem_data/cert-254-chars-in-the-middle.pem @@ -0,0 +1,5 @@ +-----BEGIN CERTIFICATE----- +MIIEcjCCAyegAwIBAgIUPLgYY73GEwkikNCKRJrcbCR+TbQwDQYJKoZIhvcNAQELBQAwgZUxCzAJBgNVBAYTAkFVMWMwYQYDVQQIDFpUaGUgR3JlYXQgU3RhdGUgb2YgTG9uZy1XaW5kZWQgQ2VydGlmaWNhdGUgRmllbGQgTmFtZXMgV2hlcmVieSB0byBJbmNyZWFzZSB0aGUgT +3V0cHV0IFNpemUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA0MDcwMDAwNDJaFw0zMDA0MDUwMDAwNDJaMIGVMQswCQYDVQQGEwJBVTFjMGEGA1UECAxaVGhlIEdyZWF0IFN0YXRlIG9mIExvbmctV2luZGVkIENlcnRpZmljYXRlIEZpZWxkIE5hbWVzIFdoZXJlYnkgdG8gSW5jcmVhc2UgdGhlIE91dHB1dCB +TaXplMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggFUMA0GCSqGSIb3DQEBAQUAA4IBQQAwggE8AoIBMwLfmipKB41NPXrbp/T5eu+fndvZq72N/Tq0vZp2dRoz89NEFC3jYVBjp4pmVwCS9F/fGX1tnVfhb9k/4fqiI/y9lBVzxaHyMG/pt0D2nTS8iaMTM7uBeRvB5rUZlEbU8uvv4GXu3CeP/NnVceXruGbPb4IpjfoUbGLvn5oK35h8a+LNY5f7QRBlAXtUwYrdxVzT+CqQ4wIAuqoIVXgRIweveS1ArbS8hOtsVnu1bUAQVKqORHx8gtbOyiA4heTCEOkwh45YV6KW+uLI1wTeE4E9erlI4RwZ7umbBnQai/hYL//AUfQKQhpGbgfyJrS0UYY7WEP/mcFQh0U2EBTXtAy/e4XPiftViR3+pd+G2TJ/JFofDDzJRrceeo9tUnMr0pKtU7oB77lSKgsruKKkhn6lLH8CAwEAAaNTMFEwHQYDVR0OBBYEFIkawSiFUdL6G3jw8qg1WQI8Xi4rMB8GA1UdIwQYMBaAFIkawSiFUdL6G3jw8qg1WQI8Xi4rMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggE0AAHe/+71vykcq9BQ5h2X7MpnkE5n0Yn0Xi24uuCpv59JjABmOdaeT6XBQ5UJN8WfidawgzbJ6WiWgjflaMfRfjsdCJRgvdw0gfXXXrsseJMeMYnw1hQTGuB83BKjXBdL6zb45qGf2Fgjm3aNW2NUVM+Q2QfMjoKx13hTyDh9l5nOhMv/Rkygcx1Row2WbkvrhxvCLxY0VhL7RuPV8K0ogKicv8VJgQriOUVTTkqBP1xUimKSTaNaZ8KAnC7thxxZHxsNa45a6AouPSzyAOPZQgCJW83OIFxvWsdYU1KvP1wmoi1XC9giSQ/5sLPu/eAYTzmY+Xd6Sq8dF8uyodeI2gFu3AzC28PVKeUriIGfxaqEUn+aXx5W+r8JTE6fQ9mBo9YxJBXG+OTIFgHR27q2dJwqK9c= +-----END CERTIFICATE----- diff --git a/test/recipes/04-test_pem_data/cert-oneline-multiple-of-254.pem b/test/recipes/04-test_pem_data/cert-oneline-multiple-of-254.pem new file mode 100644 index 00000000..e0af8595 --- /dev/null +++ b/test/recipes/04-test_pem_data/cert-oneline-multiple-of-254.pem @@ -0,0 +1,3 @@ +-----BEGIN CERTIFICATE----- +MIIEcjCCAyegAwIBAgIUPLgYY73GEwkikNCKRJrcbCR+TbQwDQYJKoZIhvcNAQELBQAwgZUxCzAJBgNVBAYTAkFVMWMwYQYDVQQIDFpUaGUgR3JlYXQgU3RhdGUgb2YgTG9uZy1XaW5kZWQgQ2VydGlmaWNhdGUgRmllbGQgTmFtZXMgV2hlcmVieSB0byBJbmNyZWFzZSB0aGUgT3V0cHV0IFNpemUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA0MDcwMDAwNDJaFw0zMDA0MDUwMDAwNDJaMIGVMQswCQYDVQQGEwJBVTFjMGEGA1UECAxaVGhlIEdyZWF0IFN0YXRlIG9mIExvbmctV2luZGVkIENlcnRpZmljYXRlIEZpZWxkIE5hbWVzIFdoZXJlYnkgdG8gSW5jcmVhc2UgdGhlIE91dHB1dCBTaXplMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggFUMA0GCSqGSIb3DQEBAQUAA4IBQQAwggE8AoIBMwLfmipKB41NPXrbp/T5eu+fndvZq72N/Tq0vZp2dRoz89NEFC3jYVBjp4pmVwCS9F/fGX1tnVfhb9k/4fqiI/y9lBVzxaHyMG/pt0D2nTS8iaMTM7uBeRvB5rUZlEbU8uvv4GXu3CeP/NnVceXruGbPb4IpjfoUbGLvn5oK35h8a+LNY5f7QRBlAXtUwYrdxVzT+CqQ4wIAuqoIVXgRIweveS1ArbS8hOtsVnu1bUAQVKqORHx8gtbOyiA4heTCEOkwh45YV6KW+uLI1wTeE4E9erlI4RwZ7umbBnQai/hYL//AUfQKQhpGbgfyJrS0UYY7WEP/mcFQh0U2EBTXtAy/e4XPiftViR3+pd+G2TJ/JFofDDzJRrceeo9tUnMr0pKtU7oB77lSKgsruKKkhn6lLH8CAwEAAaNTMFEwHQYDVR0OBBYEFIkawSiFUdL6G3jw8qg1WQI8Xi4rMB8GA1UdIwQYMBaAFIkawSiFUdL6G3jw8qg1WQI8Xi4rMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggE0AAHe/+71vykcq9BQ5h2X7MpnkE5n0Yn0Xi24uuCpv59JjABmOdaeT6XBQ5UJN8WfidawgzbJ6WiWgjflaMfRfjsdCJRgvdw0gfXXXrsseJMeMYnw1hQTGuB83BKjXBdL6zb45qGf2Fgjm3aNW2NUVM+Q2QfMjoKx13hTyDh9l5nOhMv/Rkygcx1Row2WbkvrhxvCLxY0VhL7RuPV8K0ogKicv8VJgQriOUVTTkqBP1xUimKSTaNaZ8KAnC7thxxZHxsNa45a6AouPSzyAOPZQgCJW83OIFxvWsdYU1KvP1wmoi1XC9giSQ/5sLPu/eAYTzmY+Xd6Sq8dF8uyodeI2gFu3AzC28PVKeUriIGfxaqEUn+aXx5W+r8JTE6fQ9mBo9YxJBXG+OTIFgHR27q2dJwqK9c= +-----END CERTIFICATE----- diff --git a/test/recipes/15-test_rsapss.t b/test/recipes/15-test_rsapss.t index 0d7e7bf2..5c834025 100644 --- a/test/recipes/15-test_rsapss.t +++ b/test/recipes/15-test_rsapss.t @@ -16,14 +16,22 @@ use OpenSSL::Test::Utils; setup("test_rsapss"); -plan tests => 5; +plan tests => 7; #using test/testrsa.pem which happens to be a 512 bit RSA ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha1', - '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max', - '-sigopt', 'rsa_mgf1_md:sha512', '-out', 'testrsapss.sig', + '-sigopt', 'rsa_padding_mode:pss', + '-sigopt', 'rsa_pss_saltlen:max', + '-sigopt', 'rsa_mgf1_md:sha512', + '-out', 'testrsapss-restricted.sig', srctop_file('test', 'testrsa.pem')])), - "openssl dgst -sign"); + "openssl dgst -sign [plain RSA key, PSS padding mode, PSS restrictions]"); + +ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha1', + '-sigopt', 'rsa_padding_mode:pss', + '-out', 'testrsapss-unrestricted.sig', + srctop_file('test', 'testrsa.pem')])), + "openssl dgst -sign [plain RSA key, PSS padding mode, no PSS restrictions]"); with({ exit_checker => sub { return shift == 1; } }, sub { ok(run(app(['openssl', 'dgst', '-sign', srctop_file('test', 'testrsa.pem'), '-sha512', @@ -41,8 +49,18 @@ with({ exit_checker => sub { return shift == 1; } }, "openssl dgst -prverify, expect to fail gracefully"); }); -ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'), '-sha1', - '-sigopt', 'rsa_padding_mode:pss', '-sigopt', 'rsa_pss_saltlen:max', - '-sigopt', 'rsa_mgf1_md:sha512', '-signature', 'testrsapss.sig', +ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'), + '-sha1', + '-sigopt', 'rsa_padding_mode:pss', + '-sigopt', 'rsa_pss_saltlen:max', + '-sigopt', 'rsa_mgf1_md:sha512', + '-signature', 'testrsapss-restricted.sig', srctop_file('test', 'testrsa.pem')])), - "openssl dgst -prverify"); + "openssl dgst -prverify [plain RSA key, PSS padding mode, PSS restrictions]"); + +ok(run(app(['openssl', 'dgst', '-prverify', srctop_file('test', 'testrsa.pem'), + '-sha1', + '-sigopt', 'rsa_padding_mode:pss', + '-signature', 'testrsapss-unrestricted.sig', + srctop_file('test', 'testrsa.pem')])), + "openssl dgst -prverify [plain RSA key, PSS padding mode, no PSS restrictions]"); diff --git a/test/recipes/20-test_kdf.t b/test/recipes/20-test_kdf.t index a03f6997..d0ea07ee 100755 --- a/test/recipes/20-test_kdf.t +++ b/test/recipes/20-test_kdf.t @@ -1,7 +1,7 @@ #! /usr/bin/env perl -# Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/test/recipes/20-test_mac.t b/test/recipes/20-test_mac.t index 6a2c094a..e34381c0 100644 --- a/test/recipes/20-test_mac.t +++ b/test/recipes/20-test_mac.t @@ -1,7 +1,7 @@ #! /usr/bin/env perl -# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/test/recipes/25-test_x509.t b/test/recipes/25-test_x509.t index 14584401..427c6b7f 100644 --- a/test/recipes/25-test_x509.t +++ b/test/recipes/25-test_x509.t @@ -16,7 +16,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/; setup("test_x509"); -plan tests => 10; +plan tests => 11; require_ok(srctop_file('test','recipes','tconversion.pl')); @@ -68,4 +68,20 @@ subtest 'x509 -- second x.509 v3 certificate' => sub { subtest 'x509 -- pathlen' => sub { ok(run(test(["v3ext", srctop_file("test/certs", "pathlen.pem")]))); +}; + +subtest 'x500 -- subjectAltName' => sub { + my $fp = srctop_file("test/certs", "fake-gp.pem"); + my $out = "ext.out"; + ok(run(app(["openssl", "x509", "-text", "-in", $fp, "-out", $out]))); + ok(has_doctor_id($out)); + unlink $out; +}; + +sub has_doctor_id { + $_ = shift @_; + open(DATA,$_) or return 0; + $_= join('',); + close(DATA); + return m/2.16.528.1.1003.1.3.5.5.2-1-0000006666-Z-12345678-01.015-12345678/; } diff --git a/test/recipes/30-test_afalg.t b/test/recipes/30-test_afalg.t index 363f4d4c..572a8475 100644 --- a/test/recipes/30-test_afalg.t +++ b/test/recipes/30-test_afalg.t @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -7,7 +7,7 @@ # https://www.openssl.org/source/license.html use strict; -use OpenSSL::Test qw/:DEFAULT bldtop_dir/; +use OpenSSL::Test qw/:DEFAULT/; use OpenSSL::Test::Utils; my $test_name = "test_afalg"; @@ -18,6 +18,4 @@ plan skip_all => "$test_name not supported for this build" plan tests => 1; -$ENV{OPENSSL_ENGINES} = bldtop_dir("engines"); - ok(run(test(["afalgtest"])), "running afalgtest"); diff --git a/test/recipes/30-test_evp.t b/test/recipes/30-test_evp.t index 88eb41e1..5f7585cc 100644 --- a/test/recipes/30-test_evp.t +++ b/test/recipes/30-test_evp.t @@ -80,8 +80,6 @@ plan tests => unless ($no_fips) { my $infile = bldtop_file('providers', platform->dso('fips')); - $ENV{OPENSSL_MODULES} = bldtop_dir("providers"); - $ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers"); ok(run(app(['openssl', 'fipsinstall', '-out', bldtop_file('providers', 'fipsmodule.cnf'), diff --git a/test/recipes/30-test_evp_data/evpaessiv.txt b/test/recipes/30-test_evp_data/evpaessiv.txt index 54199183..e891b214 100644 --- a/test/recipes/30-test_evp_data/evpaessiv.txt +++ b/test/recipes/30-test_evp_data/evpaessiv.txt @@ -1,7 +1,7 @@ # -# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/test/recipes/30-test_evp_data/evppkey.txt b/test/recipes/30-test_evp_data/evppkey.txt index e4b6497b..1d5274f1 100644 --- a/test/recipes/30-test_evp_data/evppkey.txt +++ b/test/recipes/30-test_evp_data/evppkey.txt @@ -142,6 +142,19 @@ Ctrl = digest:SHA1 Input = "0123456789ABCDEF1234" Output = c09d402423cbf233d26cae21f954547bc43fe80fd41360a0336cfdbe9aedad05bef6fd2eaee6cd60089a52482d4809a238149520df3bdde4cb9e23d9307b05c0a6f327052325a29adf2cc95b66523be7024e2a585c3d4db15dfbe146efe0ecdc0402e33fe5d40324ee96c5c3edd374a15cdc0f5d84aa243c0f07e188c6518fbfceae158a9943be398e31097da81b62074f626eff738be6160741d5a26957a482b3251fd85d8df78b98148459de10aa93305dbb4a5230aa1da291a9b0e481918f99b7638d72bb687f97661d304ae145d64a474437a4ef39d7b8059332ddeb07e92bf6e0e3acaf8afedc93795e4511737ec1e7aab6d5bc9466afc950c1c17b48ad +# Truncated digest +Sign = RSA-2048 +Availablein = default +Ctrl = digest:SHA512-224 +Input = "0123456789ABCDEF123456789ABC" +Output = 5f720e9488139bb21e1c2f027fd5ce5993e6d31c5a8faaee833487b3a944d66891178868ace8070cad3ee2ffbe54aa4885a15fd1a7cc5166970fe1fd8c0423e72bd3e3b56fc4a53ed80aaaeca42497f0ec3c62113edc05cd006608f5eef7ce3ad4cba1069f68731dd28a524a1f93fcdc5547112d48d45586dd943ba0d443be9635720d8a61697c54c96627f0d85c5fbeaa3b4af86a65cf2fc3800dd5de34c046985f25d0efc0bb6edccc1d08b3a4fb9c8faffe181c7e68b31e374ad1440a4a664eec9ca0dc53a9d2f5bc7d9940d866f64201bcbc63612754df45727ea24b531d7de83d1bb707444859fa35521320c33bf6f4dbeb6fb56e653adbf7af15843f17 + +Verify = RSA-2048 +Availablein = default +Ctrl = digest:SHA512-224 +Input = "0123456789ABCDEF123456789ABC" +Output = 5f720e9488139bb21e1c2f027fd5ce5993e6d31c5a8faaee833487b3a944d66891178868ace8070cad3ee2ffbe54aa4885a15fd1a7cc5166970fe1fd8c0423e72bd3e3b56fc4a53ed80aaaeca42497f0ec3c62113edc05cd006608f5eef7ce3ad4cba1069f68731dd28a524a1f93fcdc5547112d48d45586dd943ba0d443be9635720d8a61697c54c96627f0d85c5fbeaa3b4af86a65cf2fc3800dd5de34c046985f25d0efc0bb6edccc1d08b3a4fb9c8faffe181c7e68b31e374ad1440a4a664eec9ca0dc53a9d2f5bc7d9940d866f64201bcbc63612754df45727ea24b531d7de83d1bb707444859fa35521320c33bf6f4dbeb6fb56e653adbf7af15843f17 + VerifyRecover = RSA-2048 Availablein = default Ctrl = digest:SHA1 diff --git a/test/recipes/30-test_evp_fetch_prov.t b/test/recipes/30-test_evp_fetch_prov.t index be06716b..a49a66fe 100644 --- a/test/recipes/30-test_evp_fetch_prov.t +++ b/test/recipes/30-test_evp_fetch_prov.t @@ -24,9 +24,6 @@ my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0); my @types = ( "digest", "cipher" ); -$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); -$ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers"); - my @setups = (); my @testdata = ( { config => srctop_file("test", "default.cnf"), diff --git a/test/recipes/70-test_comp.t b/test/recipes/70-test_comp.t index 4a00652c..2ac168c2 100644 --- a/test/recipes/70-test_comp.t +++ b/test/recipes/70-test_comp.t @@ -28,7 +28,6 @@ plan skip_all => "$test_name needs TLSv1.3 or TLSv1.2 enabled" if disabled("tls1_3") && disabled("tls1_2"); $ENV{OPENSSL_ia32cap} = '~0x200000200000000'; -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); use constant { MULTIPLE_COMPRESSIONS => 0, diff --git a/test/recipes/70-test_sslmessages.t b/test/recipes/70-test_sslmessages.t index b90eae57..3f57af62 100644 --- a/test/recipes/70-test_sslmessages.t +++ b/test/recipes/70-test_sslmessages.t @@ -30,7 +30,6 @@ plan skip_all => "$test_name needs TLS enabled" || (!disabled("tls1_3") && disabled("tls1_2")); $ENV{OPENSSL_ia32cap} = '~0x200000200000000'; -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); my $proxy = TLSProxy::Proxy->new( undef, diff --git a/test/recipes/70-test_tls13kexmodes.t b/test/recipes/70-test_tls13kexmodes.t index 2751a3f1..6648376c 100644 --- a/test/recipes/70-test_tls13kexmodes.t +++ b/test/recipes/70-test_tls13kexmodes.t @@ -32,7 +32,6 @@ plan skip_all => "$test_name needs EC enabled" if disabled("ec"); $ENV{OPENSSL_ia32cap} = '~0x200000200000000'; -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); @handmessages = ( diff --git a/test/recipes/70-test_tls13messages.t b/test/recipes/70-test_tls13messages.t index 21fd6f28..3113294f 100644 --- a/test/recipes/70-test_tls13messages.t +++ b/test/recipes/70-test_tls13messages.t @@ -32,8 +32,6 @@ plan skip_all => "$test_name needs EC enabled" if disabled("ec"); $ENV{OPENSSL_ia32cap} = '~0x200000200000000'; -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); - @handmessages = ( [TLSProxy::Message::MT_CLIENT_HELLO, diff --git a/test/recipes/70-test_tls13psk.t b/test/recipes/70-test_tls13psk.t index f20150f6..66582b7d 100644 --- a/test/recipes/70-test_tls13psk.t +++ b/test/recipes/70-test_tls13psk.t @@ -28,7 +28,6 @@ plan skip_all => "$test_name needs TLSv1.3 enabled" if disabled("tls1_3"); $ENV{OPENSSL_ia32cap} = '~0x200000200000000'; -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); my $proxy = TLSProxy::Proxy->new( undef, diff --git a/test/recipes/80-test_ct.t b/test/recipes/80-test_ct.t index 8350467f..33cb7158 100644 --- a/test/recipes/80-test_ct.t +++ b/test/recipes/80-test_ct.t @@ -11,7 +11,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file srctop_dir/; use OpenSSL::Test::Simple; setup("test_ct"); -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); + $ENV{CT_DIR} = srctop_dir("test", "ct"); $ENV{CERTS_DIR} = srctop_dir("test", "certs"); simple_test("test_ct", "ct_test", "ct", "ec"); diff --git a/test/recipes/80-test_ssl_new.t b/test/recipes/80-test_ssl_new.t index 8a26119f..f105a39c 100644 --- a/test/recipes/80-test_ssl_new.t +++ b/test/recipes/80-test_ssl_new.t @@ -26,10 +26,7 @@ use platform; my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0); -$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); -$ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers"); $ENV{TEST_CERTS_DIR} = srctop_dir("test", "certs"); -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); my @conf_srcs = glob(srctop_file("test", "ssl-tests", "*.cnf.in")); map { s/;.*// } @conf_srcs if $^O eq "VMS"; diff --git a/test/recipes/80-test_ssl_old.t b/test/recipes/80-test_ssl_old.t index 42963c36..e01137d5 100644 --- a/test/recipes/80-test_ssl_old.t +++ b/test/recipes/80-test_ssl_old.t @@ -24,10 +24,6 @@ use lib srctop_dir('Configurations'); use lib bldtop_dir('.'); use platform; -$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.cnf"); -$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); -$ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers"); - my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0); my ($no_rsa, $no_dsa, $no_dh, $no_ec, $no_psk, $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2, $no_tls1_3, diff --git a/test/recipes/90-test_bio_memleak.t b/test/recipes/90-test_bio_memleak.t index 93f7f928..f61d2a8d 100644 --- a/test/recipes/90-test_bio_memleak.t +++ b/test/recipes/90-test_bio_memleak.t @@ -1,7 +1,7 @@ #! /usr/bin/env perl -# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/test/recipes/90-test_includes.t b/test/recipes/90-test_includes.t index 301f6c15..add3813a 100644 --- a/test/recipes/90-test_includes.t +++ b/test/recipes/90-test_includes.t @@ -10,6 +10,8 @@ setup("test_includes"); plan skip_all => "test_includes doesn't work without posix-io" if disabled("posix-io"); +delete $ENV{OPENSSL_CONF_INCLUDE}; + plan tests => # The number of tests being performed 5 + ($^O eq "VMS" ? 2 : 0); diff --git a/test/recipes/90-test_sslapi.t b/test/recipes/90-test_sslapi.t index b89b7838..e25ca0ba 100644 --- a/test/recipes/90-test_sslapi.t +++ b/test/recipes/90-test_sslapi.t @@ -30,9 +30,6 @@ plan tests => (undef, my $tmpfilename) = tempfile(); -$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); -$ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers"); - ok(run(test(["sslapitest", srctop_dir("test", "certs"), srctop_file("test", "recipes", "90-test_sslapi_data", "passwd.txt"), $tmpfilename, "default", diff --git a/test/recipes/90-test_sslprovider.t b/test/recipes/90-test_sslprovider.t index 793756bc..1a2a2855 100644 --- a/test/recipes/90-test_sslprovider.t +++ b/test/recipes/90-test_sslprovider.t @@ -23,9 +23,6 @@ plan skip_all => "No TLS/SSL protocols are supported by this OpenSSL build" plan tests => 3; -$ENV{OPENSSL_MODULES} = bldtop_dir("providers"); -$ENV{OPENSSL_CONF_INCLUDE} = bldtop_dir("providers"); - SKIP: { skip "Skipping FIPS installation", 1 if disabled("fips"); diff --git a/test/rsa_sp800_56b_test.c b/test/rsa_sp800_56b_test.c index b9286557..b80df013 100644 --- a/test/rsa_sp800_56b_test.c +++ b/test/rsa_sp800_56b_test.c @@ -1,7 +1,7 @@ /* - * Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/test/run_tests.pl b/test/run_tests.pl index bb917615..b75f7639 100644 --- a/test/run_tests.pl +++ b/test/run_tests.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -27,7 +27,11 @@ my $bldtop = $ENV{BLDTOP} || $ENV{TOP}; my $recipesdir = catdir($srctop, "test", "recipes"); my $libdir = rel2abs(catdir($srctop, "util", "perl")); -$ENV{OPENSSL_CONF} = catdir($srctop, "apps", "openssl.cnf"); +$ENV{OPENSSL_CONF} = rel2abs(catdir($srctop, "apps", "openssl.cnf")); +$ENV{OPENSSL_CONF_INCLUDE} = rel2abs(catdir($bldtop, "providers")); +$ENV{OPENSSL_MODULES} = rel2abs(catdir($bldtop, "providers")); +$ENV{OPENSSL_ENGINES} = rel2abs(catdir($bldtop, "engines")); +$ENV{CTLOG_FILE} = rel2abs(catdir($srctop, "test", "ct", "log_list.cnf")); my %tapargs = ( verbosity => $ENV{HARNESS_VERBOSE} ? 1 : 0, diff --git a/test/ssl-tests/20-cert-select.cnf.in b/test/ssl-tests/20-cert-select.cnf.in index fd3f09d7..79325e71 100644 --- a/test/ssl-tests/20-cert-select.cnf.in +++ b/test/ssl-tests/20-cert-select.cnf.in @@ -599,10 +599,7 @@ my @tests_tls_1_1 = ( ); push @tests, @tests_non_fips unless $fips_mode; - -#TODO(3.0): Re-enable these PSS tests in a $no_deflt_libctx build once we have -# support for it -push @tests, @tests_pss unless $no_deflt_libctx; +push @tests, @tests_pss; push @tests, @tests_tls_1_1 unless disabled("tls1_1") || $no_deflt_libctx; my $server_tls_1_3; diff --git a/test/ssl-tests/30-extended-master-secret.cnf.in b/test/ssl-tests/30-extended-master-secret.cnf.in index 84d3e3cf..281718e6 100644 --- a/test/ssl-tests/30-extended-master-secret.cnf.in +++ b/test/ssl-tests/30-extended-master-secret.cnf.in @@ -1,7 +1,7 @@ # -*- mode: perl; -*- # Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html diff --git a/test/ssl_ctx_test.c b/test/ssl_ctx_test.c index 58ca60a7..e461d725 100644 --- a/test/ssl_ctx_test.c +++ b/test/ssl_ctx_test.c @@ -1,7 +1,7 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/test/ssl_test.c b/test/ssl_test.c index c671feaf..731f5697 100644 --- a/test/ssl_test.c +++ b/test/ssl_test.c @@ -19,6 +19,8 @@ #include "ssl_test_ctx.h" #include "testutil.h" +DEFINE_STACK_OF(X509_NAME) + static CONF *conf = NULL; static OSSL_PROVIDER *defctxnull = NULL, *thisprov = NULL; static OPENSSL_CTX *libctx = NULL; diff --git a/test/ssl_test_ctx.c b/test/ssl_test_ctx.c index 6a3b66bc..aee9773b 100644 --- a/test/ssl_test_ctx.c +++ b/test/ssl_test_ctx.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -20,6 +20,9 @@ # define strcasecmp _stricmp #endif +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_STACK_OF(X509_NAME) + static const int default_app_data_size = 256; /* Default set to be as small as possible to exercise fragmentation. */ static const int default_max_fragment_size = 512; diff --git a/test/sslapitest.c b/test/sslapitest.c index d1635585..c1c288e5 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -37,6 +37,10 @@ #include "internal/ktls.h" #include "../ssl/ssl_local.h" +DEFINE_STACK_OF(OCSP_RESPID) +DEFINE_STACK_OF(X509) +DEFINE_STACK_OF(X509_NAME) + static OPENSSL_CTX *libctx = NULL; static OSSL_PROVIDER *defctxnull = NULL; @@ -655,7 +659,6 @@ end: return testresult; } -#endif /* * Very focused test to exercise a single case in the server-side state @@ -767,6 +770,7 @@ end: return testresult; } +#endif static int execute_test_large_message(const SSL_METHOD *smeth, const SSL_METHOD *cmeth, @@ -1477,7 +1481,7 @@ static SSL_SESSION *get_session_cb(SSL *ssl, const unsigned char *id, int len, } static int execute_test_session(int maxprot, int use_int_cache, - int use_ext_cache) + int use_ext_cache, long s_options) { SSL_CTX *sctx = NULL, *cctx = NULL; SSL *serverssl1 = NULL, *clientssl1 = NULL; @@ -1520,6 +1524,10 @@ static int execute_test_session(int maxprot, int use_int_cache, | SSL_SESS_CACHE_NO_INTERNAL_STORE); } + if (s_options) { + SSL_CTX_set_options(sctx, s_options); + } + if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1, NULL, NULL)) || !TEST_true(create_ssl_connection(serverssl1, clientssl1, @@ -1764,12 +1772,12 @@ static int execute_test_session(int maxprot, int use_int_cache, static int test_session_with_only_int_cache(void) { #ifndef OPENSSL_NO_TLS1_3 - if (!execute_test_session(TLS1_3_VERSION, 1, 0)) + if (!execute_test_session(TLS1_3_VERSION, 1, 0, 0)) return 0; #endif #ifndef OPENSSL_NO_TLS1_2 - return execute_test_session(TLS1_2_VERSION, 1, 0); + return execute_test_session(TLS1_2_VERSION, 1, 0, 0); #else return 1; #endif @@ -1778,12 +1786,12 @@ static int test_session_with_only_int_cache(void) static int test_session_with_only_ext_cache(void) { #ifndef OPENSSL_NO_TLS1_3 - if (!execute_test_session(TLS1_3_VERSION, 0, 1)) + if (!execute_test_session(TLS1_3_VERSION, 0, 1, 0)) return 0; #endif #ifndef OPENSSL_NO_TLS1_2 - return execute_test_session(TLS1_2_VERSION, 0, 1); + return execute_test_session(TLS1_2_VERSION, 0, 1, 0); #else return 1; #endif @@ -1792,17 +1800,32 @@ static int test_session_with_only_ext_cache(void) static int test_session_with_both_cache(void) { #ifndef OPENSSL_NO_TLS1_3 - if (!execute_test_session(TLS1_3_VERSION, 1, 1)) + if (!execute_test_session(TLS1_3_VERSION, 1, 1, 0)) return 0; #endif #ifndef OPENSSL_NO_TLS1_2 - return execute_test_session(TLS1_2_VERSION, 1, 1); + return execute_test_session(TLS1_2_VERSION, 1, 1, 0); #else return 1; #endif } +static int test_session_wo_ca_names(void) +{ +#ifndef OPENSSL_NO_TLS1_3 + if (!execute_test_session(TLS1_3_VERSION, 1, 0, SSL_OP_DISABLE_TLSEXT_CA_NAMES)) + return 0; +#endif + +#ifndef OPENSSL_NO_TLS1_2 + return execute_test_session(TLS1_2_VERSION, 1, 0, SSL_OP_DISABLE_TLSEXT_CA_NAMES); +#else + return 1; +#endif +} + + #ifndef OPENSSL_NO_TLS1_3 static SSL_SESSION *sesscache[6]; static int do_cache; @@ -2089,6 +2112,148 @@ static int test_psk_tickets(void) return testresult; } + +static int test_extra_tickets(int idx) +{ + SSL_CTX *sctx = NULL, *cctx = NULL; + SSL *serverssl = NULL, *clientssl = NULL; + BIO *bretry = BIO_new(bio_s_always_retry()); + BIO *tmp = NULL; + int testresult = 0; + int stateful = 0; + size_t nbytes; + unsigned char c, buf[1]; + + new_called = 0; + do_cache = 1; + + if (idx >= 3) { + idx -= 3; + stateful = 1; + } + + if (!TEST_ptr(bretry) || !setup_ticket_test(stateful, idx, &sctx, &cctx)) + goto end; + SSL_CTX_sess_set_new_cb(sctx, new_session_cb); + /* setup_ticket_test() uses new_cachesession_cb which we don't need. */ + SSL_CTX_sess_set_new_cb(cctx, new_session_cb); + + if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, + &clientssl, NULL, NULL))) + goto end; + + /* + * Note that we have new_session_cb on both sctx and cctx, so new_called is + * incremented by both client and server. + */ + if (!TEST_true(create_ssl_connection(serverssl, clientssl, + SSL_ERROR_NONE)) + /* Check we got the number of tickets we were expecting */ + || !TEST_int_eq(idx * 2, new_called) + || !TEST_true(SSL_new_session_ticket(serverssl)) + || !TEST_true(SSL_new_session_ticket(serverssl)) + || !TEST_int_eq(idx * 2, new_called)) + goto end; + + /* Now try a (real) write to actually send the tickets */ + c = '1'; + if (!TEST_true(SSL_write_ex(serverssl, &c, 1, &nbytes)) + || !TEST_size_t_eq(1, nbytes) + || !TEST_int_eq(idx * 2 + 2, new_called) + || !TEST_true(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes)) + || !TEST_int_eq(idx * 2 + 4, new_called) + || !TEST_int_eq(sizeof(buf), nbytes) + || !TEST_int_eq(c, buf[0]) + || !TEST_false(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes))) + goto end; + + /* Try with only requesting one new ticket, too */ + c = '2'; + new_called = 0; + if (!TEST_true(SSL_new_session_ticket(serverssl)) + || !TEST_true(SSL_write_ex(serverssl, &c, sizeof(c), &nbytes)) + || !TEST_size_t_eq(sizeof(c), nbytes) + || !TEST_int_eq(1, new_called) + || !TEST_true(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes)) + || !TEST_int_eq(2, new_called) + || !TEST_size_t_eq(sizeof(buf), nbytes) + || !TEST_int_eq(c, buf[0])) + goto end; + + /* Do it again but use dummy writes to drive the ticket generation */ + c = '3'; + new_called = 0; + if (!TEST_true(SSL_new_session_ticket(serverssl)) + || !TEST_true(SSL_new_session_ticket(serverssl)) + || !TEST_true(SSL_write_ex(serverssl, &c, 0, &nbytes)) + || !TEST_size_t_eq(0, nbytes) + || !TEST_int_eq(2, new_called) + || !TEST_false(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes)) + || !TEST_int_eq(4, new_called)) + goto end; + + /* + * Use the always-retry BIO to exercise the logic that forces ticket + * generation to wait until a record boundary. + */ + c = '4'; + new_called = 0; + tmp = SSL_get_wbio(serverssl); + if (!TEST_ptr(tmp) || !TEST_true(BIO_up_ref(tmp))) { + tmp = NULL; + goto end; + } + SSL_set0_wbio(serverssl, bretry); + bretry = NULL; + if (!TEST_false(SSL_write_ex(serverssl, &c, 1, &nbytes)) + || !TEST_int_eq(SSL_get_error(serverssl, 0), SSL_ERROR_WANT_WRITE) + || !TEST_size_t_eq(nbytes, 0)) + goto end; + /* Restore a BIO that will let the write succeed */ + SSL_set0_wbio(serverssl, tmp); + tmp = NULL; + /* These calls should just queue the request and not send anything. */ + if (!TEST_true(SSL_new_session_ticket(serverssl)) + || !TEST_true(SSL_new_session_ticket(serverssl)) + || !TEST_int_eq(0, new_called)) + goto end; + /* Re-do the write; still no tickets sent */ + if (!TEST_true(SSL_write_ex(serverssl, &c, 1, &nbytes)) + || !TEST_size_t_eq(1, nbytes) + || !TEST_int_eq(0, new_called) + || !TEST_true(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes)) + || !TEST_int_eq(0, new_called) + || !TEST_int_eq(sizeof(buf), nbytes) + || !TEST_int_eq(c, buf[0]) + || !TEST_false(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes))) + goto end; + /* Now the *next* write should send the tickets */ + c = '5'; + if (!TEST_true(SSL_write_ex(serverssl, &c, 1, &nbytes)) + || !TEST_size_t_eq(1, nbytes) + || !TEST_int_eq(2, new_called) + || !TEST_true(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes)) + || !TEST_int_eq(4, new_called) + || !TEST_int_eq(sizeof(buf), nbytes) + || !TEST_int_eq(c, buf[0]) + || !TEST_false(SSL_read_ex(clientssl, buf, sizeof(buf), &nbytes))) + goto end; + + SSL_shutdown(clientssl); + SSL_shutdown(serverssl); + testresult = 1; + + end: + BIO_free(bretry); + BIO_free(tmp); + SSL_free(serverssl); + SSL_free(clientssl); + SSL_CTX_free(sctx); + SSL_CTX_free(cctx); + clientssl = serverssl = NULL; + sctx = cctx = NULL; + return testresult; +} #endif #define USE_NULL 0 @@ -2590,8 +2755,11 @@ static unsigned int psk_server_cb(SSL *ssl, const char *identity, #define MSG6 "test" #define MSG7 "message." -#define TLS13_AES_256_GCM_SHA384_BYTES ((const unsigned char *)"\x13\x02") #define TLS13_AES_128_GCM_SHA256_BYTES ((const unsigned char *)"\x13\x01") +#define TLS13_AES_256_GCM_SHA384_BYTES ((const unsigned char *)"\x13\x02") +#define TLS13_CHACHA20_POLY1305_SHA256_BYTES ((const unsigned char *)"\x13\x03") +#define TLS13_AES_128_CCM_SHA256_BYTES ((const unsigned char *)"\x13\x04") +#define TLS13_AES_128_CCM_8_SHA256_BYTES ((const unsigned char *)"\x13\05") static SSL_SESSION *create_a_psk(SSL *ssl) @@ -3524,6 +3692,113 @@ static int test_early_data_psk(int idx) return testresult; } +/* + * Test TLSv1.3 PSK can be used to send early_data with all 5 ciphersuites + * idx == 0: Test with TLS1_3_RFC_AES_128_GCM_SHA256 + * idx == 1: Test with TLS1_3_RFC_AES_256_GCM_SHA384 + * idx == 2: Test with TLS1_3_RFC_CHACHA20_POLY1305_SHA256, + * idx == 3: Test with TLS1_3_RFC_AES_128_CCM_SHA256 + * idx == 4: Test with TLS1_3_RFC_AES_128_CCM_8_SHA256 + */ +static int test_early_data_psk_with_all_ciphers(int idx) +{ + SSL_CTX *cctx = NULL, *sctx = NULL; + SSL *clientssl = NULL, *serverssl = NULL; + int testresult = 0; + SSL_SESSION *sess = NULL; + unsigned char buf[20]; + size_t readbytes, written; + const SSL_CIPHER *cipher; + const char *cipher_str[] = { + TLS1_3_RFC_AES_128_GCM_SHA256, + TLS1_3_RFC_AES_256_GCM_SHA384, +# if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) + TLS1_3_RFC_CHACHA20_POLY1305_SHA256, +# else + NULL, +# endif + TLS1_3_RFC_AES_128_CCM_SHA256, + TLS1_3_RFC_AES_128_CCM_8_SHA256 + }; + const unsigned char *cipher_bytes[] = { + TLS13_AES_128_GCM_SHA256_BYTES, + TLS13_AES_256_GCM_SHA384_BYTES, +# if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) + TLS13_CHACHA20_POLY1305_SHA256_BYTES, +# else + NULL, +# endif + TLS13_AES_128_CCM_SHA256_BYTES, + TLS13_AES_128_CCM_8_SHA256_BYTES + }; + + if (cipher_str[idx] == NULL) + return 1; + /* Skip ChaCha20Poly1305 as currently FIPS module does not support it */ + if (idx == 2 && is_fips == 1) + return 1; + + /* We always set this up with a final parameter of "2" for PSK */ + if (!TEST_true(setupearly_data_test(&cctx, &sctx, &clientssl, + &serverssl, &sess, 2))) + goto end; + + if (!TEST_true(SSL_set_ciphersuites(clientssl, cipher_str[idx])) + || !TEST_true(SSL_set_ciphersuites(serverssl, cipher_str[idx]))) + goto end; + + /* + * 'setupearly_data_test' creates only one instance of SSL_SESSION + * and assigns to both client and server with incremented reference + * and the same instance is updated in 'sess'. + * So updating ciphersuite in 'sess' which will get reflected in + * PSK handshake using psk use sess and find sess cb. + */ + cipher = SSL_CIPHER_find(clientssl, cipher_bytes[idx]); + if (!TEST_ptr(cipher) || !TEST_true(SSL_SESSION_set_cipher(sess, cipher))) + goto end; + + SSL_set_connect_state(clientssl); + if (!TEST_true(SSL_write_early_data(clientssl, MSG1, strlen(MSG1), + &written))) + goto end; + + if (!TEST_int_eq(SSL_read_early_data(serverssl, buf, sizeof(buf), + &readbytes), + SSL_READ_EARLY_DATA_SUCCESS) + || !TEST_mem_eq(buf, readbytes, MSG1, strlen(MSG1)) + || !TEST_int_eq(SSL_get_early_data_status(serverssl), + SSL_EARLY_DATA_ACCEPTED) + || !TEST_int_eq(SSL_connect(clientssl), 1) + || !TEST_int_eq(SSL_accept(serverssl), 1)) + goto end; + + /* Send some normal data from client to server */ + if (!TEST_true(SSL_write_ex(clientssl, MSG2, strlen(MSG2), &written)) + || !TEST_size_t_eq(written, strlen(MSG2))) + goto end; + + if (!TEST_true(SSL_read_ex(serverssl, buf, sizeof(buf), &readbytes)) + || !TEST_mem_eq(buf, readbytes, MSG2, strlen(MSG2))) + goto end; + + testresult = 1; + end: + SSL_SESSION_free(sess); + SSL_SESSION_free(clientpsk); + SSL_SESSION_free(serverpsk); + clientpsk = serverpsk = NULL; + if (clientssl != NULL) + SSL_shutdown(clientssl); + if (serverssl != NULL) + SSL_shutdown(serverssl); + SSL_free(serverssl); + SSL_free(clientssl); + SSL_CTX_free(sctx); + SSL_CTX_free(cctx); + return testresult; +} + /* * Test that a server that doesn't try to read early data can handle a * client sending some. @@ -5518,6 +5793,8 @@ static int test_pha_key_update(void) static SRP_VBASE *vbase = NULL; +DEFINE_STACK_OF(SRP_user_pwd) + static int ssl_srp_cb(SSL *s, int *ad, void *arg) { int ret = SSL3_AL_FATAL; @@ -6060,6 +6337,7 @@ static struct { const char *srvrciphers; const char *srvrtls13ciphers; const char *shared; + const char *fipsshared; } shared_ciphers_data[] = { /* * We can't establish a connection (even in TLSv1.1) with these ciphersuites if @@ -6072,14 +6350,29 @@ static struct { NULL, "AES256-SHA:DHE-RSA-AES128-SHA", NULL, + "AES256-SHA", "AES256-SHA" }, +# if !defined(OPENSSL_NO_CHACHA) \ + && !defined(OPENSSL_NO_POLY1305) \ + && !defined(OPENSSL_NO_EC) + { + TLS1_2_VERSION, + "AES128-SHA:ECDHE-RSA-CHACHA20-POLY1305", + NULL, + "AES128-SHA:ECDHE-RSA-CHACHA20-POLY1305", + NULL, + "AES128-SHA:ECDHE-RSA-CHACHA20-POLY1305", + "AES128-SHA" + }, +# endif { TLS1_2_VERSION, "AES128-SHA:DHE-RSA-AES128-SHA:AES256-SHA", NULL, "AES128-SHA:DHE-RSA-AES256-SHA:AES256-SHA", NULL, + "AES128-SHA:AES256-SHA", "AES128-SHA:AES256-SHA" }, { @@ -6088,6 +6381,7 @@ static struct { NULL, "AES128-SHA:DHE-RSA-AES128-SHA", NULL, + "AES128-SHA", "AES128-SHA" }, #endif @@ -6104,7 +6398,8 @@ static struct { "AES256-SHA:AES128-SHA256", NULL, "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:" - "TLS_AES_128_GCM_SHA256:AES256-SHA" + "TLS_AES_128_GCM_SHA256:AES256-SHA", + "TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256:AES256-SHA" }, #endif #ifndef OPENSSL_NO_TLS1_3 @@ -6114,17 +6409,39 @@ static struct { "TLS_AES_256_GCM_SHA384", "AES256-SHA", "TLS_AES_256_GCM_SHA384", + "TLS_AES_256_GCM_SHA384", "TLS_AES_256_GCM_SHA384" }, #endif }; -static int test_ssl_get_shared_ciphers(int tst) +static int int_test_ssl_get_shared_ciphers(int tst, int clnt) { SSL_CTX *cctx = NULL, *sctx = NULL; SSL *clientssl = NULL, *serverssl = NULL; int testresult = 0; char buf[1024]; + OPENSSL_CTX *tmplibctx = OPENSSL_CTX_new(); + + if (!TEST_ptr(tmplibctx)) + goto end; + + /* + * Regardless of whether we're testing with the FIPS provider loaded into + * libctx, we want one peer to always use the full set of ciphersuites + * available. Therefore we use a separate libctx with the default provider + * loaded into it. We run the same tests twice - once with the client side + * having the full set of ciphersuites and once with the server side. + */ + if (clnt) { + cctx = SSL_CTX_new_with_libctx(tmplibctx, NULL, TLS_client_method()); + if (!TEST_ptr(cctx)) + goto end; + } else { + sctx = SSL_CTX_new_with_libctx(tmplibctx, NULL, TLS_server_method()); + if (!TEST_ptr(sctx)) + goto end; + } if (!TEST_true(create_ssl_ctx_pair(libctx, TLS_server_method(), TLS_client_method(), @@ -6153,7 +6470,11 @@ static int test_ssl_get_shared_ciphers(int tst) goto end; if (!TEST_ptr(SSL_get_shared_ciphers(serverssl, buf, sizeof(buf))) - || !TEST_int_eq(strcmp(buf, shared_ciphers_data[tst].shared), 0)) { + || !TEST_int_eq(strcmp(buf, + is_fips + ? shared_ciphers_data[tst].fipsshared + : shared_ciphers_data[tst].shared), + 0)) { TEST_info("Shared ciphers are: %s\n", buf); goto end; } @@ -6165,10 +6486,18 @@ static int test_ssl_get_shared_ciphers(int tst) SSL_free(clientssl); SSL_CTX_free(sctx); SSL_CTX_free(cctx); + OPENSSL_CTX_free(tmplibctx); return testresult; } +static int test_ssl_get_shared_ciphers(int tst) +{ + return int_test_ssl_get_shared_ciphers(tst, 0) + && int_test_ssl_get_shared_ciphers(tst, 1); +} + + static const char *appdata = "Hello World"; static int gen_tick_called, dec_tick_called, tick_key_cb_called; static int tick_key_renew = 0; @@ -7385,10 +7714,12 @@ int setup_tests(void) ADD_TEST(test_session_with_only_int_cache); ADD_TEST(test_session_with_only_ext_cache); ADD_TEST(test_session_with_both_cache); + ADD_TEST(test_session_wo_ca_names); #ifndef OPENSSL_NO_TLS1_3 ADD_ALL_TESTS(test_stateful_tickets, 3); ADD_ALL_TESTS(test_stateless_tickets, 3); ADD_TEST(test_psk_tickets); + ADD_ALL_TESTS(test_extra_tickets, 6); #endif ADD_ALL_TESTS(test_ssl_set_bio, TOTAL_SSL_SET_BIO_TESTS); ADD_TEST(test_ssl_bio_pop_next_bio); @@ -7420,6 +7751,7 @@ int setup_tests(void) ADD_ALL_TESTS(test_early_data_skip_abort, 3); ADD_ALL_TESTS(test_early_data_not_sent, 3); ADD_ALL_TESTS(test_early_data_psk, 8); + ADD_ALL_TESTS(test_early_data_psk_with_all_ciphers, 5); ADD_ALL_TESTS(test_early_data_not_expected, 3); # ifndef OPENSSL_NO_TLS1_2 ADD_ALL_TESTS(test_early_data_tls1_2, 3); diff --git a/test/sslcorrupttest.c b/test/sslcorrupttest.c index 135fe485..476a1758 100644 --- a/test/sslcorrupttest.c +++ b/test/sslcorrupttest.c @@ -11,6 +11,8 @@ #include "ssltestlib.h" #include "testutil.h" +DEFINE_STACK_OF(SSL_CIPHER) + static int docorrupt = 0; static void copy_flags(BIO *bio) diff --git a/test/ssltest_old.c b/test/ssltest_old.c index dca0694e..d45b2786 100644 --- a/test/ssltest_old.c +++ b/test/ssltest_old.c @@ -81,6 +81,9 @@ # include #endif +DEFINE_STACK_OF(SSL_COMP) +DEFINE_STACK_OF_STRING() + static SSL_CTX *s_ctx = NULL; static SSL_CTX *s_ctx2 = NULL; diff --git a/test/testutil/options.c b/test/testutil/options.c index 0b10f7f0..35dfa320 100644 --- a/test/testutil/options.c +++ b/test/testutil/options.c @@ -1,7 +1,7 @@ /* * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/test/testutil/test_options.c b/test/testutil/test_options.c index 99e6d294..51d88039 100644 --- a/test/testutil/test_options.c +++ b/test/testutil/test_options.c @@ -1,7 +1,7 @@ /* - * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/test/v3nametest.c b/test/v3nametest.c index d17ab714..a5fa4822 100644 --- a/test/v3nametest.c +++ b/test/v3nametest.c @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2012-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,6 +19,8 @@ # define strcasecmp _stricmp #endif +DEFINE_STACK_OF(GENERAL_NAME) + static const char *const names[] = { "a", "b", ".", "*", "@", ".a", "a.", ".b", "b.", ".*", "*.", "*@", "@*", "a@", "@a", "b@", "..", diff --git a/test/verify_extra_test.c b/test/verify_extra_test.c index 3dd45627..6cce6260 100644 --- a/test/verify_extra_test.c +++ b/test/verify_extra_test.c @@ -16,6 +16,8 @@ #include #include "testutil.h" +DEFINE_STACK_OF(X509) + static const char *roots_f; static const char *untrusted_f; static const char *bad_f; diff --git a/test/wpackettest.c b/test/wpackettest.c index 08b5f976..b03dfcd2 100644 --- a/test/wpackettest.c +++ b/test/wpackettest.c @@ -360,6 +360,8 @@ static int test_WPACKET_init_der(void) unsigned char testdata[] = { 0x00, 0x01, 0x02, 0x03 }; unsigned char testdata2[259] = { 0x82, 0x01, 0x00 }; size_t written[2]; + size_t size1, size2; + int flags = WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH; int i; /* Test initialising for writing DER */ @@ -370,6 +372,13 @@ static int test_WPACKET_init_der(void) || !TEST_true(WPACKET_memcpy(&pkt, testdata, sizeof(testdata))) || !TEST_true(WPACKET_close(&pkt)) || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xfc)) + /* this sub-packet is empty, and should render zero bytes */ + || (!TEST_true(WPACKET_start_sub_packet(&pkt)) + || !TEST_true(WPACKET_set_flags(&pkt, flags)) + || !TEST_true(WPACKET_get_total_written(&pkt, &size1)) + || !TEST_true(WPACKET_close(&pkt)) + || !TEST_true(WPACKET_get_total_written(&pkt, &size2)) + || !TEST_size_t_eq(size1, size2)) || !TEST_true(WPACKET_finish(&pkt)) || !TEST_true(WPACKET_get_total_written(&pkt, &written[0])) || !TEST_mem_eq(WPACKET_get_curr(&pkt), written[0], simpleder, diff --git a/util/libcrypto.num b/util/libcrypto.num index 7bf2e90d..00e8cbbd 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -144,7 +144,7 @@ IDEA_set_decrypt_key 146 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3 X509_STORE_CTX_set_flags 147 3_0_0 EXIST::FUNCTION: BIO_ADDR_rawmake 148 3_0_0 EXIST::FUNCTION:SOCK EVP_PKEY_asn1_set_ctrl 149 3_0_0 EXIST::FUNCTION: -EC_POINTs_mul 150 3_0_0 EXIST::FUNCTION:EC +EC_POINTs_mul 150 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,EC ASN1_get_object 151 3_0_0 EXIST::FUNCTION: i2d_IPAddressFamily 152 3_0_0 EXIST::FUNCTION:RFC3779 ENGINE_get_ctrl_function 153 3_0_0 EXIST::FUNCTION:ENGINE @@ -490,7 +490,7 @@ X509_CRL_print 499 3_0_0 EXIST::FUNCTION: WHIRLPOOL_Update 500 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,WHIRLPOOL DSA_get_ex_data 501 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,DSA BN_copy 502 3_0_0 EXIST::FUNCTION: -FIPS_mode_set 503 3_0_0 EXIST::FUNCTION: +FIPS_mode_set 503 3_0_0 NOEXIST::FUNCTION: X509_VERIFY_PARAM_add0_policy 504 3_0_0 EXIST::FUNCTION: PKCS7_cert_from_signer_info 505 3_0_0 EXIST::FUNCTION: X509_TRUST_get_trust 506 3_0_0 EXIST::FUNCTION: @@ -2534,7 +2534,7 @@ OPENSSL_strnlen 2587 3_0_0 EXIST::FUNCTION: IDEA_ecb_encrypt 2588 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,IDEA ASN1_STRING_set_default_mask 2589 3_0_0 EXIST::FUNCTION: TS_VERIFY_CTX_add_flags 2590 3_0_0 EXIST::FUNCTION:TS -FIPS_mode 2591 3_0_0 EXIST::FUNCTION: +FIPS_mode 2591 3_0_0 NOEXIST::FUNCTION: d2i_ASN1_UNIVERSALSTRING 2592 3_0_0 EXIST::FUNCTION: NAME_CONSTRAINTS_free 2593 3_0_0 EXIST::FUNCTION: EC_GROUP_get_order 2594 3_0_0 EXIST::FUNCTION:EC @@ -3163,7 +3163,7 @@ ACCESS_DESCRIPTION_free 3228 3_0_0 EXIST::FUNCTION: BN_nist_mod_384 3229 3_0_0 EXIST::FUNCTION: i2d_EC_PUBKEY_fp 3230 3_0_0 EXIST::FUNCTION:EC,STDIO ENGINE_set_default_pkey_meths 3231 3_0_0 EXIST::FUNCTION:ENGINE -DH_bits 3232 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,DH +DH_bits 3232 3_0_0 EXIST::FUNCTION:DH i2d_X509_ALGORS 3233 3_0_0 EXIST::FUNCTION: EVP_camellia_192_cfb1 3234 3_0_0 EXIST::FUNCTION:CAMELLIA TS_RESP_CTX_add_failure_info 3235 3_0_0 EXIST::FUNCTION:TS @@ -4045,7 +4045,7 @@ X509_STORE_unlock 4133 3_0_0 EXIST::FUNCTION: X509_STORE_lock 4134 3_0_0 EXIST::FUNCTION: X509_set_proxy_pathlen 4135 3_0_0 EXIST::FUNCTION: X509_get_proxy_pathlen 4136 3_0_0 EXIST::FUNCTION: -DSA_bits 4137 3_0_0 EXIST::FUNCTION:DEPRECATEDIN_3_0,DSA +DSA_bits 4137 3_0_0 EXIST::FUNCTION:DSA EVP_PKEY_set1_tls_encodedpoint 4138 3_0_0 EXIST::FUNCTION: EVP_PKEY_get1_tls_encodedpoint 4139 3_0_0 EXIST::FUNCTION: ASN1_STRING_get0_data 4140 3_0_0 EXIST::FUNCTION: @@ -4771,7 +4771,7 @@ OSSL_CMP_CTX_set0_trustedStore ? 3_0_0 EXIST::FUNCTION:CMP OSSL_CMP_CTX_get0_trustedStore ? 3_0_0 EXIST::FUNCTION:CMP OSSL_CMP_CTX_set1_untrusted_certs ? 3_0_0 EXIST::FUNCTION:CMP OSSL_CMP_CTX_get0_untrusted_certs ? 3_0_0 EXIST::FUNCTION:CMP -OSSL_CMP_CTX_set1_clCert ? 3_0_0 EXIST::FUNCTION:CMP +OSSL_CMP_CTX_set1_cert ? 3_0_0 EXIST::FUNCTION:CMP OSSL_CMP_CTX_set1_pkey ? 3_0_0 EXIST::FUNCTION:CMP OSSL_CMP_CTX_set1_referenceValue ? 3_0_0 EXIST::FUNCTION:CMP OSSL_CMP_CTX_set1_secretValue ? 3_0_0 EXIST::FUNCTION:CMP @@ -4902,6 +4902,7 @@ i2d_X509_PUBKEY_bio ? 3_0_0 EXIST::FUNCTION: RSA_get0_pss_params ? 3_0_0 EXIST::FUNCTION:RSA X509_cmp_timeframe ? 3_0_0 EXIST::FUNCTION: OSSL_CMP_MSG_get0_header ? 3_0_0 EXIST::FUNCTION:CMP +OSSL_CMP_MSG_update_transactionID ? 3_0_0 EXIST::FUNCTION:CMP BIO_f_prefix ? 3_0_0 EXIST::FUNCTION: EVP_PKEY_CTX_new_from_name ? 3_0_0 EXIST::FUNCTION: EVP_PKEY_CTX_new_from_pkey ? 3_0_0 EXIST::FUNCTION: @@ -5072,6 +5073,9 @@ EVP_PKEY_CTX_set_dh_paramgen_generator ? 3_0_0 EXIST::FUNCTION:DH EVP_PKEY_CTX_set_dh_nid ? 3_0_0 EXIST::FUNCTION:DH EVP_PKEY_CTX_set_dh_rfc5114 ? 3_0_0 EXIST::FUNCTION:DH EVP_PKEY_CTX_set_dhx_rfc5114 ? 3_0_0 EXIST::FUNCTION:DH +X509_VERIFY_PARAM_get0_host ? 3_0_0 EXIST::FUNCTION: +X509_VERIFY_PARAM_get0_email ? 3_0_0 EXIST::FUNCTION: +X509_VERIFY_PARAM_get1_ip_asc ? 3_0_0 EXIST::FUNCTION: X509_verify_ex ? 3_0_0 EXIST::FUNCTION: X509_REQ_verify_ex ? 3_0_0 EXIST::FUNCTION: X509_ALGOR_copy ? 3_0_0 EXIST::FUNCTION: @@ -5079,4 +5083,13 @@ X509_REQ_set0_signature ? 3_0_0 EXIST::FUNCTION: X509_REQ_set1_signature_algo ? 3_0_0 EXIST::FUNCTION: OSSL_PARAM_modified ? 3_0_0 EXIST::FUNCTION: OSSL_PARAM_set_all_unmodified ? 3_0_0 EXIST::FUNCTION: +EVP_default_properties_is_fips_enabled ? 3_0_0 EXIST::FUNCTION: +EVP_default_properties_enable_fips ? 3_0_0 EXIST::FUNCTION: +EVP_PKEY_new_raw_private_key_with_libctx ? 3_0_0 EXIST::FUNCTION: +EVP_PKEY_new_raw_public_key_with_libctx ? 3_0_0 EXIST::FUNCTION: +OSSL_STORE_attach ? 3_0_0 EXIST::FUNCTION: +OSSL_STORE_LOADER_set_attach ? 3_0_0 EXIST::FUNCTION: +EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen ? 3_0_0 EXIST::FUNCTION:RSA +EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md ? 3_0_0 EXIST::FUNCTION:RSA +EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name ? 3_0_0 EXIST::FUNCTION:RSA EVP_chacha20_poly1305_draft ? 3_0_0 EXIST::FUNCTION:CHACHA,POLY1305 diff --git a/util/libssl.num b/util/libssl.num index dec336e1..fc563ef8 100644 --- a/util/libssl.num +++ b/util/libssl.num @@ -513,4 +513,5 @@ SSL_CTX_load_verify_dir ? 3_0_0 EXIST::FUNCTION: SSL_CTX_load_verify_store ? 3_0_0 EXIST::FUNCTION: SSL_CTX_set_tlsext_ticket_key_evp_cb ? 3_0_0 EXIST::FUNCTION: SSL_CTX_new_with_libctx ? 3_0_0 EXIST::FUNCTION: +SSL_new_session_ticket ? 3_0_0 EXIST::FUNCTION: SSL_CTX_set_timeout_tls13 ? 3_0_0 EXIST::FUNCTION: diff --git a/util/markdownlint.rb b/util/markdownlint.rb new file mode 100644 index 00000000..66517484 --- /dev/null +++ b/util/markdownlint.rb @@ -0,0 +1,20 @@ +# markdownlint style rules for OpenSSL +# See https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md + +all + +# Use --- and === for H1 and H2. +rule 'MD003', :style => :setext_with_atx +# Code blocks are indented +rule 'MD046', :style => :indented + +# Bug in mdl, https://github.com/markdownlint/markdownlint/issues/313 +exclude_rule 'MD007' + +exclude_rule 'MD004' # Unordered list style TODO(fix?) +exclude_rule 'MD005' # Inconsistent indentation for list items at the same level +exclude_rule 'MD006' # Consider starting bulleted lists at the beginning of the line +exclude_rule 'MD014' # Dollar signs used before commands without showing output +exclude_rule 'MD024' # Multiple headers with the same content +exclude_rule 'MD025' # Multiple top level headers in the same document +exclude_rule 'MD029' # Ordered list item prefix diff --git a/util/missingcrypto.txt b/util/missingcrypto.txt index a84428d7..3473a869 100644 --- a/util/missingcrypto.txt +++ b/util/missingcrypto.txt @@ -49,9 +49,7 @@ ASN1_IA5STRING_it(3) ASN1_IA5STRING_new(3) ASN1_INTEGER_cmp(3) ASN1_INTEGER_dup(3) -ASN1_INTEGER_free(3) ASN1_INTEGER_it(3) -ASN1_INTEGER_new(3) ASN1_NULL_free(3) ASN1_NULL_it(3) ASN1_NULL_new(3) @@ -314,7 +312,6 @@ CMS_ContentInfo_it(3) CMS_EncryptedData_decrypt(3) CMS_EncryptedData_encrypt(3) CMS_EncryptedData_set1_key(3) -CMS_EnvelopedData_create(3) CMS_ReceiptRequest_it(3) CMS_RecipientEncryptedKey_cert_cmp(3) CMS_RecipientEncryptedKey_get0_id(3) diff --git a/util/missingmacro.txt b/util/missingmacro.txt index ed0f6105..2b02fef5 100644 --- a/util/missingmacro.txt +++ b/util/missingmacro.txt @@ -124,6 +124,11 @@ PKCS7_get_detached(3) PKCS7_is_detached(3) STACK_OF(3) SKM_DEFINE_STACK_OF(3) +DEFINE_OR_DECLARE_STACK_OF(3) +DEFINE_OR_DECLARE_STACK_OF_STRING(3) +DEFINE_OR_DECLARE_STACK_OF_CSTRING(3) +DEFINE_STACK_OF_STRING(3) +DEFINE_STACK_OF_CSTRING(3) U64(3) SSL_set_mtu(3) DTLS_set_link_mtu(3) diff --git a/util/mkrc.pl b/util/mkrc.pl index 8ff35885..d3617663 100755 --- a/util/mkrc.pl +++ b/util/mkrc.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -25,7 +25,7 @@ if ( $filename =~ /openssl/i ) { $vft = "VFT_APP"; } -my $YEAR = [localtime()]->[5] + 1900; +my $YEAR = [gmtime($ENV{SOURCE_DATE_EPOCH} || time())]->[5] + 1900; print <<___; #include diff --git a/util/other.syms b/util/other.syms index 9f44034f..d9934859 100644 --- a/util/other.syms +++ b/util/other.syms @@ -49,6 +49,7 @@ OSSL_STORE_INFO datatype OSSL_STORE_LOADER datatype OSSL_STORE_LOADER_CTX datatype OSSL_STORE_SEARCH datatype +OSSL_STORE_attach_fn datatype OSSL_STORE_close_fn datatype OSSL_STORE_ctrl_fn datatype OSSL_STORE_expect_fn datatype diff --git a/util/perl/OpenSSL/OID.pm b/util/perl/OpenSSL/OID.pm index 0bc34ce5..0b39ef9f 100644 --- a/util/perl/OpenSSL/OID.pm +++ b/util/perl/OpenSSL/OID.pm @@ -304,89 +304,4 @@ sub _pairmap (&@) { map { $block->($_) } _pairs @_; } -######## UNIT TESTING - -use Test::More; - -sub TEST { - # Order is important, so we make it a pairwise list - my @predefined = - ( - 'pkcs' => '1.2.840.113549', - 'pkcs-1' => 'pkcs.1', - ); - - my %good_cases = - ( - ' 1.2.840.113549.1.1 ' => [ 42, 134, 72, 134, 247, 13, 1, 1 ], - 'pkcs.1.1' => [ 42, 134, 72, 134, 247, 13, 1, 1 ], - 'pkcs-1.1' => [ 42, 134, 72, 134, 247, 13, 1, 1 ], - ' { iso (1) 2 840 113549 1 1 } ' => [ 42, 134, 72, 134, 247, 13, 1, 1 ], - '{ pkcs 1 1 } ' => [ 42, 134, 72, 134, 247, 13, 1, 1 ], - '{pkcs-1 1 }' => [ 42, 134, 72, 134, 247, 13, 1, 1 ], - ); - my @bad_cases = - ( - ' { 1.2.840.113549.1.1 } ', - ); - - plan tests => - scalar ( @predefined ) / 2 - + scalar ( keys %good_cases ) - + scalar @bad_cases; - - note 'Predefine a few names OIDs'; - foreach my $pair ( _pairs @predefined ) { - ok( defined eval { register_oid(@$pair) }, - "Registering $pair->[0] => $pair->[1]" ); - } - - note 'Good cases'; - foreach ( keys %good_cases ) { - subtest "Checking '$_'" => sub { - my $oid = shift; - - plan tests => 5; - - my (@l, @e); - - ok( scalar (@l = eval { parse_oid $oid }) > 0, - "Parsing" ); - diag $@ unless @l; - ok( scalar (@e = eval { encode_oid_nums @l }) > 0, - "Encoding via encode_oid_nums()" ); - diag $@ unless @e; - is_deeply(\@e, $good_cases{$oid}, "Checking encoding"); - note "'$oid' => ", join(', ', @e) if @e; - - ok( scalar (@e = eval { encode_oid $oid }) > 0, - "Encoding directly" ); - diag $@ unless @e; - is_deeply(\@e, $good_cases{$oid}, "Checking encoding"); - note "'$oid' => ", join(', ', @e) if @e; - }, - $_; - } - - note 'Bad cases'; - foreach ( @bad_cases ) { - subtest "Checking '$_'" => sub { - my $oid = shift; - - plan tests => 2; - - my (@l, @e); - - ok( scalar (@l = eval { parse_oid $oid }) == 0, - "Parsing '$oid'" ); - note $@ unless @l; - ok( scalar (@e = eval { encode_oid_nums @l }) == 0, - "Encoding '$oid'" ); - note $@ unless @e; - note "'$oid' => ", join(', ', @e) if @e; - }, - $_; - } -} - 1; # End of OpenSSL::OID diff --git a/util/perl/OpenSSL/ParseC.pm b/util/perl/OpenSSL/ParseC.pm index 6d615016..dd1da99f 100644 --- a/util/perl/OpenSSL/ParseC.pm +++ b/util/perl/OpenSSL/ParseC.pm @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -372,6 +372,28 @@ EOF { regexp => qr/DEFINE_STACK_OF_CONST<<<\((.*)\)>>>/, massager => sub { return ("SKM_DEFINE_STACK_OF($1,const $1,$1)"); }, }, + { regexp => qr/DEFINE_STACK_OF_STRING<<<\((.*?)\)>>>/, + massager => sub { + return ("DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)"); + } + }, + { regexp => qr/DEFINE_STACK_OF_CSTRING<<<\((.*?)\)>>>/, + massager => sub { + return ("DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char)"); + } + }, + # DEFINE_OR_DECLARE macro calls must be interpretted as DEFINE macro + # calls, because that's what they look like to the external apps. + # (if that ever changes, we must change the substitutions to STACK_OF) + { regexp => qr/DEFINE_OR_DECLARE_STACK_OF<<<\((.*?)\)>>>/, + massager => sub { return ("DEFINE_STACK_OF($1)"); } + }, + { regexp => qr/DEFINE_OR_DECLARE_STACK_OF_STRING<<<\(\)>>>/, + massager => sub { return ("DEFINE_STACK_OF_STRING()"); }, + }, + { regexp => qr/DEFINE_OR_DECLARE_STACK_OF_CSTRING<<<\(\)>>>/, + massager => sub { return ("DEFINE_STACK_OF_CSTRING()"); }, + }, ##### # ASN1 stuff