Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1880] Support disabling features marked as legacy in OpenSSL 3.0 #1883

Merged
merged 3 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ option(DOWNLOAD_GTEST "Download Googletest" On)
option(DOWNLOAD_SEXP "Use FetchContent to download sexp library" Off)
option(DOWNLOAD_RUBYRNP "Download ruby-rnp and run related tests." On)
# crypto components
function(tristate_feature_auto NAME DESCRIPTION)
set(${NAME} Auto CACHE STRING ${DESCRIPTION})
set_property(CACHE ${NAME} PROPERTY STRINGS ${TRISTATE_VALUES})
endfunction()
set(ENABLE_SM2 Auto CACHE STRING "Enable SM2/SM3/SM4 algorithms support.")
set_property(CACHE ENABLE_SM2 PROPERTY STRINGS ${TRISTATE_VALUES})
set(ENABLE_AEAD Auto CACHE STRING "Enable AEAD ciphers support.")
Expand All @@ -70,6 +74,9 @@ set(ENABLE_BRAINPOOL Auto CACHE STRING "Enable Brainpool curves support.")
set_property(CACHE ENABLE_BRAINPOOL PROPERTY STRINGS ${TRISTATE_VALUES})
set(ENABLE_IDEA Auto CACHE STRING "Enable IDEA algorithm support.")
set_property(CACHE ENABLE_IDEA PROPERTY STRINGS ${TRISTATE_VALUES})
tristate_feature_auto(ENABLE_BLOWFISH "Enable Blowfish cipher support.")
tristate_feature_auto(ENABLE_CAST5 "Enable CAST5 cipher support.")
tristate_feature_auto(ENABLE_RIPEMD160 "Enable RIPEMD-160 hash support.")

set(ENABLE_DOC Auto CACHE STRING "Enable building documentation.")
set_property(CACHE ENABLE_DOC PROPERTY STRINGS ${TRISTATE_VALUES})
Expand Down
14 changes: 10 additions & 4 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ if(CRYPTO_BACKEND_BOTAN)
# base
BIGINT FFI HEX_CODEC PGP_S2K
# symmetric ciphers
BLOCK_CIPHER AES BLOWFISH CAMELLIA CAST_128 DES
BLOCK_CIPHER AES CAMELLIA DES
# cipher modes
MODE_CBC MODE_CFB
# RNG
AUTO_RNG AUTO_SEEDING_RNG HMAC HMAC_DRBG
# hash
CRC24 HASH MD5 SHA1 SHA2_32 SHA2_64 SHA3 RIPEMD_160
CRC24 HASH MD5 SHA1 SHA2_32 SHA2_64 SHA3
# public-key core
DL_GROUP DL_PUBLIC_KEY_FAMILY ECC_GROUP ECC_PUBLIC_KEY_CRYPTO PUBLIC_KEY_CRYPTO
# public-key algs
Expand All @@ -160,6 +160,9 @@ if(CRYPTO_BACKEND_BOTAN)
resolve_feature_state(ENABLE_TWOFISH "TWOFISH")
resolve_feature_state(ENABLE_IDEA "IDEA")
# Botan supports Brainpool curves together with SECP via the ECC_GROUP define
resolve_feature_state(ENABLE_BLOWFISH "BLOWFISH")
resolve_feature_state(ENABLE_CAST5 "CAST_128")
resolve_feature_state(ENABLE_RIPEMD160 "RIPEMD_160")
set(CMAKE_REQUIRED_INCLUDES)
endif()
if(CRYPTO_BACKEND_OPENSSL)
Expand All @@ -168,10 +171,10 @@ if(CRYPTO_BACKEND_OPENSSL)
# symmetric ciphers
AES-128-ECB AES-192-ECB AES-256-ECB AES-128-CBC AES-192-CBC AES-256-CBC
AES-128-OCB AES-192-OCB AES-256-OCB
BF-ECB CAMELLIA-128-ECB CAMELLIA-192-ECB CAMELLIA-256-ECB CAST5-ECB
CAMELLIA-128-ECB CAMELLIA-192-ECB CAMELLIA-256-ECB
DES-EDE3
# hashes
MD5 SHA1 SHA224 SHA256 SHA384 SHA512 SHA3-256 SHA3-512 RIPEMD160
MD5 SHA1 SHA224 SHA256 SHA384 SHA512 SHA3-256 SHA3-512
# curves
PRIME256V1 SECP384R1 SECP521R1 SECP256K1
# public key
Expand All @@ -188,6 +191,9 @@ if(CRYPTO_BACKEND_OPENSSL)

resolve_feature_state(ENABLE_BRAINPOOL "BRAINPOOLP256R1;BRAINPOOLP384R1;BRAINPOOLP512R1")
resolve_feature_state(ENABLE_IDEA "IDEA-ECB;IDEA-CBC")
resolve_feature_state(ENABLE_BLOWFISH "BF-ECB")
resolve_feature_state(ENABLE_CAST5 "CAST5-ECB")
resolve_feature_state(ENABLE_RIPEMD160 "RIPEMD160")
openssl_nope(ENABLE_SM2 "it's on our roadmap, see https://github.com/rnpgp/rnp/issues/1877")
#resolve_feature_state(ENABLE_SM2 "SM2;SM3;SM4-ECB")
openssl_nope(ENABLE_TWOFISH "Twofish isn't and won't be supported by OpenSSL, see https://github.com/openssl/openssl/issues/2046")
Expand Down
3 changes: 3 additions & 0 deletions src/lib/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
#cmakedefine ENABLE_TWOFISH
#cmakedefine ENABLE_BRAINPOOL
#cmakedefine ENABLE_IDEA
#cmakedefine ENABLE_BLOWFISH
#cmakedefine ENABLE_CAST5
#cmakedefine ENABLE_RIPEMD160

/* Macro _GLIBCXX_USE_CXX11_ABI was first introduced with GCC 5.0, which
* we assume to be bundled with a sane implementation of std::regex. */
Expand Down
14 changes: 13 additions & 1 deletion src/lib/crypto/backend_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ backend_version()
}

#if defined(CRYPTO_BACKEND_OPENSSL3)

#if defined(ENABLE_IDEA) || defined(ENABLE_CAST5) || defined(ENABLE_BLOWFISH) || \
defined(ENABLE_RIPEMD160)
#define OPENSSL_LOAD_LEGACY
#endif

typedef struct openssl3_state {
#if defined(OPENSSL_LOAD_LEGACY)
OSSL_PROVIDER *legacy;
#endif
OSSL_PROVIDER *def;
} openssl3_state;

Expand All @@ -132,14 +140,16 @@ backend_init(void **param)
free(state);
return false;
}
/* Load legacy crypto provider */
/* Load legacy crypto provider if needed */
#if defined(OPENSSL_LOAD_LEGACY)
state->legacy = OSSL_PROVIDER_load(NULL, "legacy");
if (!state->legacy) {
RNP_LOG("Failed to load legacy crypto provider: %s", ossl_latest_err());
OSSL_PROVIDER_unload(state->def);
free(state);
return false;
}
#endif
*param = state;
return true;
}
Expand All @@ -152,7 +162,9 @@ backend_finish(void *param)
}
openssl3_state *state = (openssl3_state *) param;
OSSL_PROVIDER_unload(state->def);
#if defined(OPENSSL_LOAD_LEGACY)
OSSL_PROVIDER_unload(state->legacy);
#endif
free(state);
}
#else
Expand Down
12 changes: 12 additions & 0 deletions src/lib/crypto/cipher_botan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ Cipher_Botan::create(pgp_symm_alg_t alg, const std::string &name, bool encrypt)
RNP_LOG("IDEA support has been disabled");
return nullptr;
}
#endif
#if !defined(ENABLE_BLOWFISH)
if (alg == PGP_SA_BLOWFISH) {
RNP_LOG("Blowfish support has been disabled");
return nullptr;
}
#endif
#if !defined(ENABLE_CAST5)
if (alg == PGP_SA_CAST5) {
RNP_LOG("CAST5 support has been disabled");
return nullptr;
}
#endif
auto cipher = Botan::Cipher_Mode::create(
name, encrypt ? Botan::Cipher_Dir::ENCRYPTION : Botan::Cipher_Dir::DECRYPTION);
Expand Down
12 changes: 12 additions & 0 deletions src/lib/crypto/cipher_ossl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ Cipher_OpenSSL::create(pgp_symm_alg_t alg,
RNP_LOG("IDEA support has been disabled");
return nullptr;
}
#endif
#if !defined(ENABLE_BLOWFISH)
if (alg == PGP_SA_BLOWFISH) {
RNP_LOG("Blowfish support has been disabled");
return nullptr;
}
#endif
#if !defined(ENABLE_CAST5)
if (alg == PGP_SA_CAST5) {
RNP_LOG("CAST5 support has been disabled");
return nullptr;
}
#endif
const EVP_CIPHER *cipher = EVP_get_cipherbyname(name.c_str());
if (!cipher) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/symmetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ pgp_sa_to_botan_string(pgp_symm_alg_t alg)
return "TripleDES";
#endif

#if defined(BOTAN_HAS_CAST)
#if defined(BOTAN_HAS_CAST) && defined(ENABLE_CAST5)
case PGP_SA_CAST5:
return "CAST-128";
#endif

#if defined(BOTAN_HAS_BLOWFISH)
#if defined(BOTAN_HAS_BLOWFISH) && defined(ENABLE_BLOWFISH)
case PGP_SA_BLOWFISH:
return "Blowfish";
#endif
Expand Down
8 changes: 7 additions & 1 deletion src/lib/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,12 @@ symm_alg_supported(int alg)
case PGP_SA_IDEA:
#endif
case PGP_SA_TRIPLEDES:
#if defined(ENABLE_CAST5)
case PGP_SA_CAST5:
#endif
#if defined(ENABLE_BLOWFISH)
case PGP_SA_BLOWFISH:
#endif
case PGP_SA_AES_128:
case PGP_SA_AES_192:
case PGP_SA_AES_256:
Expand All @@ -296,7 +300,9 @@ hash_alg_supported(int alg)
switch (alg) {
case PGP_HASH_MD5:
case PGP_HASH_SHA1:
#if defined(ENABLE_RIPEMD160)
case PGP_HASH_RIPEMD:
#endif
case PGP_HASH_SHA256:
case PGP_HASH_SHA384:
case PGP_HASH_SHA512:
Expand Down Expand Up @@ -2902,7 +2908,7 @@ FFI_GUARD
rnp_result_t
rnp_op_sign_signature_set_hash(rnp_op_sign_signature_t sig, const char *hash)
try {
if (!sig) {
if (!sig || !hash) {
return RNP_ERROR_NULL_POINTER;
}
if (!str_to_hash_alg(hash, &sig->signer.halg)) {
Expand Down
Loading