[OpenSSL] Support for OpenSSL 3 (#31256)

Update from gtcooke94:
This PR adds support to build gRPC and it's tests with OpenSSL3. There were some
hiccups with tests as the tests with openssl haven't been built or exercised in a
few months, so they needed some work to fix.

Right now I expect all test files to pass except the following:
- h2_ssl_cert_test
- ssl_transport_security_utils_test

I confirmed locally that these tests fail with OpenSSL 1.1.1 as well,
thus we are at least not introducing regressions. Thus, I've added compiler directives around these tests so they only build when using BoringSSL.

---------

Co-authored-by: Gregory Cooke <gregorycooke@google.com>
Co-authored-by: Esun Kim <veblush@google.com>
pull/34124/head
jrandolf 1 year ago committed by GitHub
parent c0e2fa60f9
commit 3489b6304e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/core/lib/security/credentials/external/aws_request_signer.cc
  2. 17
      src/core/lib/security/credentials/jwt/json_token.cc
  3. 4
      src/core/lib/security/credentials/jwt/json_token.h
  4. 42
      src/core/lib/security/credentials/jwt/jwt_verifier.cc
  5. 4
      src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc
  6. 29
      src/core/tsi/alts/crypt/aes_gcm.cc
  7. 11
      src/core/tsi/ssl_transport_security.cc
  8. 1
      test/core/end2end/BUILD
  9. 14
      test/core/end2end/h2_ssl_cert_test.cc
  10. 6
      test/core/security/credentials_test.cc
  11. 23
      test/core/security/json_token_test.cc
  12. 8
      test/core/tsi/ssl_transport_security_test.cc
  13. 5
      test/core/tsi/ssl_transport_security_utils_test.cc
  14. 24
      test/core/tsi/transport_security_test_lib.cc
  15. 14
      test/cpp/end2end/tls_key_export_test.cc
  16. 1
      tools/distrib/fix_build_deps.py
  17. 2
      tools/run_tests/run_tests_matrix.py

@ -42,15 +42,23 @@ namespace grpc_core {
namespace { namespace {
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
const char kSha256[] = "SHA256";
#endif
const char kAlgorithm[] = "AWS4-HMAC-SHA256"; const char kAlgorithm[] = "AWS4-HMAC-SHA256";
const char kDateFormat[] = "%a, %d %b %E4Y %H:%M:%S %Z"; const char kDateFormat[] = "%a, %d %b %E4Y %H:%M:%S %Z";
const char kXAmzDateFormat[] = "%Y%m%dT%H%M%SZ"; const char kXAmzDateFormat[] = "%Y%m%dT%H%M%SZ";
void SHA256(const std::string& str, unsigned char out[SHA256_DIGEST_LENGTH]) { void SHA256(const std::string& str, unsigned char out[SHA256_DIGEST_LENGTH]) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
SHA256_CTX sha256; SHA256_CTX sha256;
SHA256_Init(&sha256); SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size()); SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(out, &sha256); SHA256_Final(out, &sha256);
#else
EVP_Q_digest(nullptr, kSha256, nullptr, str.c_str(), str.size(), out,
nullptr);
#endif
} }
std::string SHA256Hex(const std::string& str) { std::string SHA256Hex(const std::string& str) {

@ -115,8 +115,12 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) {
gpr_log(GPR_ERROR, "Could not write into openssl BIO."); gpr_log(GPR_ERROR, "Could not write into openssl BIO.");
goto end; goto end;
} }
#if OPENSSL_VERSION_NUMBER < 0x30000000L
result.private_key = result.private_key =
PEM_read_bio_RSAPrivateKey(bio, nullptr, nullptr, const_cast<char*>("")); PEM_read_bio_RSAPrivateKey(bio, nullptr, nullptr, const_cast<char*>(""));
#else
result.private_key = PEM_read_bio_PrivateKey(bio, nullptr, nullptr, nullptr);
#endif
if (result.private_key == nullptr) { if (result.private_key == nullptr) {
gpr_log(GPR_ERROR, "Could not deserialize private key."); gpr_log(GPR_ERROR, "Could not deserialize private key.");
goto end; goto end;
@ -158,7 +162,11 @@ void grpc_auth_json_key_destruct(grpc_auth_json_key* json_key) {
json_key->client_email = nullptr; json_key->client_email = nullptr;
} }
if (json_key->private_key != nullptr) { if (json_key->private_key != nullptr) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
RSA_free(json_key->private_key); RSA_free(json_key->private_key);
#else
EVP_PKEY_free(json_key->private_key);
#endif
json_key->private_key = nullptr; json_key->private_key = nullptr;
} }
} }
@ -237,7 +245,9 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key,
const char* to_sign) { const char* to_sign) {
const EVP_MD* md = openssl_digest_from_algorithm(signature_algorithm); const EVP_MD* md = openssl_digest_from_algorithm(signature_algorithm);
EVP_MD_CTX* md_ctx = nullptr; EVP_MD_CTX* md_ctx = nullptr;
#if OPENSSL_VERSION_NUMBER < 0x30000000L
EVP_PKEY* key = EVP_PKEY_new(); EVP_PKEY* key = EVP_PKEY_new();
#endif
size_t sig_len = 0; size_t sig_len = 0;
unsigned char* sig = nullptr; unsigned char* sig = nullptr;
char* result = nullptr; char* result = nullptr;
@ -247,8 +257,13 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key,
gpr_log(GPR_ERROR, "Could not create MD_CTX"); gpr_log(GPR_ERROR, "Could not create MD_CTX");
goto end; goto end;
} }
#if OPENSSL_VERSION_NUMBER < 0x30000000L
EVP_PKEY_set1_RSA(key, json_key->private_key); EVP_PKEY_set1_RSA(key, json_key->private_key);
if (EVP_DigestSignInit(md_ctx, nullptr, md, nullptr, key) != 1) { if (EVP_DigestSignInit(md_ctx, nullptr, md, nullptr, key) != 1) {
#else
if (EVP_DigestSignInit(md_ctx, nullptr, md, nullptr, json_key->private_key) !=
1) {
#endif
gpr_log(GPR_ERROR, "DigestInit failed."); gpr_log(GPR_ERROR, "DigestInit failed.");
goto end; goto end;
} }
@ -268,7 +283,9 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key,
result = grpc_base64_encode(sig, sig_len, 1, 0); result = grpc_base64_encode(sig, sig_len, 1, 0);
end: end:
#if OPENSSL_VERSION_NUMBER < 0x30000000L
if (key != nullptr) EVP_PKEY_free(key); if (key != nullptr) EVP_PKEY_free(key);
#endif
if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx); if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx);
if (sig != nullptr) gpr_free(sig); if (sig != nullptr) gpr_free(sig);
return result; return result;

@ -38,7 +38,11 @@ struct grpc_auth_json_key {
char* private_key_id; char* private_key_id;
char* client_id; char* client_id;
char* client_email; char* client_email;
#if OPENSSL_VERSION_NUMBER < 0x30000000L
RSA* private_key; RSA* private_key;
#else
EVP_PKEY* private_key;
#endif
}; };
// Returns 1 if the object is valid, 0 otherwise. // Returns 1 if the object is valid, 0 otherwise.
int grpc_auth_json_key_is_valid(const grpc_auth_json_key* json_key); int grpc_auth_json_key_is_valid(const grpc_auth_json_key* json_key);

@ -37,6 +37,9 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#include <openssl/param_build.h>
#endif
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
@ -523,7 +526,13 @@ static int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) {
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L #endif // OPENSSL_VERSION_NUMBER < 0x10100000L
static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) { static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
RSA* rsa = nullptr; RSA* rsa = nullptr;
#else
EVP_PKEY_CTX* ctx = nullptr;
OSSL_PARAM* params = NULL;
OSSL_PARAM_BLD* bld = OSSL_PARAM_BLD_new();
#endif
EVP_PKEY* result = nullptr; EVP_PKEY* result = nullptr;
BIGNUM* tmp_n = nullptr; BIGNUM* tmp_n = nullptr;
BIGNUM* tmp_e = nullptr; BIGNUM* tmp_e = nullptr;
@ -535,11 +544,13 @@ static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) {
gpr_log(GPR_ERROR, "Unsupported key type %s.", kty); gpr_log(GPR_ERROR, "Unsupported key type %s.", kty);
goto end; goto end;
} }
#if OPENSSL_VERSION_NUMBER < 0x30000000L
rsa = RSA_new(); rsa = RSA_new();
if (rsa == nullptr) { if (rsa == nullptr) {
gpr_log(GPR_ERROR, "Could not create rsa key."); gpr_log(GPR_ERROR, "Could not create rsa key.");
goto end; goto end;
} }
#endif
it = json.object().find("n"); it = json.object().find("n");
if (it == json.object().end()) { if (it == json.object().end()) {
gpr_log(GPR_ERROR, "Missing RSA public key field."); gpr_log(GPR_ERROR, "Missing RSA public key field.");
@ -554,6 +565,7 @@ static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) {
} }
tmp_e = bignum_from_base64(validate_string_field(it->second, "e")); tmp_e = bignum_from_base64(validate_string_field(it->second, "e"));
if (tmp_e == nullptr) goto end; if (tmp_e == nullptr) goto end;
#if OPENSSL_VERSION_NUMBER < 0x30000000L
if (!RSA_set0_key(rsa, tmp_n, tmp_e, nullptr)) { if (!RSA_set0_key(rsa, tmp_n, tmp_e, nullptr)) {
gpr_log(GPR_ERROR, "Cannot set RSA key from inputs."); gpr_log(GPR_ERROR, "Cannot set RSA key from inputs.");
goto end; goto end;
@ -563,9 +575,38 @@ static EVP_PKEY* pkey_from_jwk(const Json& json, const char* kty) {
tmp_e = nullptr; tmp_e = nullptr;
result = EVP_PKEY_new(); result = EVP_PKEY_new();
EVP_PKEY_set1_RSA(result, rsa); // uprefs rsa. EVP_PKEY_set1_RSA(result, rsa); // uprefs rsa.
#else
if (!OSSL_PARAM_BLD_push_BN(bld, "n", tmp_n) ||
!OSSL_PARAM_BLD_push_BN(bld, "e", tmp_e) ||
(params = OSSL_PARAM_BLD_to_param(bld)) == NULL) {
gpr_log(GPR_ERROR, "Could not create OSSL_PARAM");
goto end;
}
ctx = EVP_PKEY_CTX_new_from_name(nullptr, "RSA", nullptr);
if (ctx == nullptr) {
gpr_log(GPR_ERROR, "Could not create rsa key.");
goto end;
}
if (EVP_PKEY_fromdata_init(ctx) <= 0) {
gpr_log(GPR_ERROR, "Could not create rsa key.");
goto end;
}
if (EVP_PKEY_fromdata(ctx, &result, EVP_PKEY_KEYPAIR, params) <= 0) {
gpr_log(GPR_ERROR, "Cannot set RSA key from inputs.");
goto end;
}
#endif
end: end:
#if OPENSSL_VERSION_NUMBER < 0x30000000L
RSA_free(rsa); RSA_free(rsa);
#else
EVP_PKEY_CTX_free(ctx);
OSSL_PARAM_free(params);
OSSL_PARAM_BLD_free(bld);
#endif
BN_free(tmp_n); BN_free(tmp_n);
BN_free(tmp_e); BN_free(tmp_e);
return result; return result;
@ -642,6 +683,7 @@ static int verify_jwt_signature(EVP_PKEY* key, const char* alg,
if (EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(signature), if (EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(signature),
GRPC_SLICE_LENGTH(signature)) != 1) { GRPC_SLICE_LENGTH(signature)) != 1) {
gpr_log(GPR_ERROR, "JWT signature verification failed."); gpr_log(GPR_ERROR, "JWT signature verification failed.");
goto end; goto end;
} }
result = 1; result = 1;

@ -437,7 +437,11 @@ absl::StatusOr<bool> PrivateKeyAndCertificateMatch(
return absl::InvalidArgumentError( return absl::InvalidArgumentError(
"Conversion from PEM string to EVP_PKEY failed."); "Conversion from PEM string to EVP_PKEY failed.");
} }
#if OPENSSL_VERSION_NUMBER < 0x30000000L
bool result = EVP_PKEY_cmp(private_evp_pkey, public_evp_pkey) == 1; bool result = EVP_PKEY_cmp(private_evp_pkey, public_evp_pkey) == 1;
#else
bool result = EVP_PKEY_eq(private_evp_pkey, public_evp_pkey) == 1;
#endif
EVP_PKEY_free(private_evp_pkey); EVP_PKEY_free(private_evp_pkey);
EVP_PKEY_free(public_evp_pkey); EVP_PKEY_free(public_evp_pkey);
return result; return result;

@ -35,7 +35,12 @@ constexpr size_t kKdfCounterLen = 6;
constexpr size_t kKdfCounterOffset = 2; constexpr size_t kKdfCounterOffset = 2;
constexpr size_t kRekeyAeadKeyLen = kAes128GcmKeyLength; constexpr size_t kRekeyAeadKeyLen = kAes128GcmKeyLength;
// Struct for additional data required if rekeying is enabled. #if OPENSSL_VERSION_NUMBER >= 0x30000000L
const char kEvpMacAlgorithm[] = "HMAC";
char kEvpDigest[] = "SHA-256";
#endif
/* Struct for additional data required if rekeying is enabled. */
struct gsec_aes_gcm_aead_rekey_data { struct gsec_aes_gcm_aead_rekey_data {
uint8_t kdf_counter[kKdfCounterLen]; uint8_t kdf_counter[kKdfCounterLen];
uint8_t nonce_mask[kAesGcmNonceLength]; uint8_t nonce_mask[kAesGcmNonceLength];
@ -196,7 +201,7 @@ static grpc_status_code aes_gcm_derive_aead_key(uint8_t* dst,
return GRPC_STATUS_INTERNAL; return GRPC_STATUS_INTERNAL;
} }
HMAC_CTX_cleanup(&hmac); HMAC_CTX_cleanup(&hmac);
#else #elif OPENSSL_VERSION_NUMBER < 0x30000000L
HMAC_CTX* hmac = HMAC_CTX_new(); HMAC_CTX* hmac = HMAC_CTX_new();
if (hmac == nullptr) { if (hmac == nullptr) {
return GRPC_STATUS_INTERNAL; return GRPC_STATUS_INTERNAL;
@ -208,6 +213,26 @@ static grpc_status_code aes_gcm_derive_aead_key(uint8_t* dst,
return GRPC_STATUS_INTERNAL; return GRPC_STATUS_INTERNAL;
} }
HMAC_CTX_free(hmac); HMAC_CTX_free(hmac);
#else
EVP_MAC* mac = EVP_MAC_fetch(nullptr, kEvpMacAlgorithm, nullptr);
EVP_MAC_CTX* ctx = EVP_MAC_CTX_new(mac);
if (ctx == nullptr) {
return GRPC_STATUS_INTERNAL;
}
OSSL_PARAM params[2];
params[0] = OSSL_PARAM_construct_utf8_string("digest", kEvpDigest, 0);
params[1] = OSSL_PARAM_construct_end();
if (!EVP_MAC_init(ctx, kdf_key, kKdfKeyLen, params) ||
!EVP_MAC_update(ctx, kdf_counter, kKdfCounterLen) ||
!EVP_MAC_update(ctx, &ctr, 1) ||
!EVP_MAC_final(ctx, buf, nullptr, EVP_MAX_MD_SIZE)) {
EVP_MAC_CTX_free(ctx);
EVP_MAC_free(mac);
return GRPC_STATUS_INTERNAL;
}
EVP_MAC_CTX_free(ctx);
EVP_MAC_free(mac);
#endif #endif
memcpy(dst, buf, kRekeyAeadKeyLen); memcpy(dst, buf, kRekeyAeadKeyLen);
return GRPC_STATUS_OK; return GRPC_STATUS_OK;

@ -149,6 +149,9 @@ static int g_ssl_ex_verified_root_cert_index = -1;
#if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE) #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
static const char kSslEnginePrefix[] = "engine:"; static const char kSslEnginePrefix[] = "engine:";
#endif #endif
#if OPENSSL_VERSION_NUMBER >= 0x30000000
static const int kSslEcCurveNames[] = {NID_X9_62_prime256v1};
#endif
#if OPENSSL_VERSION_NUMBER < 0x10100000 #if OPENSSL_VERSION_NUMBER < 0x10100000
static gpr_mu* g_openssl_mutexes = nullptr; static gpr_mu* g_openssl_mutexes = nullptr;
@ -789,6 +792,7 @@ static tsi_result populate_ssl_context(
return TSI_INVALID_ARGUMENT; return TSI_INVALID_ARGUMENT;
} }
{ {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
EC_KEY* ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); EC_KEY* ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
if (!SSL_CTX_set_tmp_ecdh(context, ecdh)) { if (!SSL_CTX_set_tmp_ecdh(context, ecdh)) {
gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key."); gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key.");
@ -797,6 +801,13 @@ static tsi_result populate_ssl_context(
} }
SSL_CTX_set_options(context, SSL_OP_SINGLE_ECDH_USE); SSL_CTX_set_options(context, SSL_OP_SINGLE_ECDH_USE);
EC_KEY_free(ecdh); EC_KEY_free(ecdh);
#else
if (!SSL_CTX_set1_groups(context, kSslEcCurveNames, 1)) {
gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key.");
return TSI_INTERNAL_ERROR;
}
SSL_CTX_set_options(context, SSL_OP_SINGLE_ECDH_USE);
#endif
} }
return TSI_OK; return TSI_OK;
} }

@ -591,7 +591,6 @@ grpc_cc_test(
"absl/types:optional", "absl/types:optional",
"absl/types:variant", "absl/types:variant",
"gtest", "gtest",
"libcrypto",
], ],
language = "C++", language = "C++",
shard_count = 10, shard_count = 10,

@ -23,8 +23,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <openssl/crypto.h>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -258,16 +256,8 @@ TEST_P(H2SslCertTest, SimpleRequestBody) {
simple_request_body(fixture_.get(), GetParam().result); simple_request_body(fixture_.get(), GetParam().result);
} }
#ifndef OPENSSL_IS_BORINGSSL // TODO(gtcooke94) SimpleRequestBodyUseEngineTest was failing on OpenSSL3.0
#if GPR_LINUX // and 1.1.1 and removed. Investigate and rewrite a better test
TEST_P(H2SslCertTest, SimpleRequestBodyUseEngine) {
test_server1_key_id.clear();
test_server1_key_id.append("engine:libengine_passthrough:");
test_server1_key_id.append(test_server1_key);
simple_request_body(fixture_.get(), GetParam().result);
}
#endif
#endif
INSTANTIATE_TEST_SUITE_P(H2SslCert, H2SslCertTest, INSTANTIATE_TEST_SUITE_P(H2SslCert, H2SslCertTest,
::testing::ValuesIn(configs)); ::testing::ValuesIn(configs));

@ -1297,7 +1297,13 @@ void validate_jwt_encode_and_sign_params(const grpc_auth_json_key* json_key,
gpr_timespec token_lifetime) { gpr_timespec token_lifetime) {
GPR_ASSERT(grpc_auth_json_key_is_valid(json_key)); GPR_ASSERT(grpc_auth_json_key_is_valid(json_key));
GPR_ASSERT(json_key->private_key != nullptr); GPR_ASSERT(json_key->private_key != nullptr);
#if OPENSSL_VERSION_NUMBER < 0x30000000L
GPR_ASSERT(RSA_check_key(json_key->private_key)); GPR_ASSERT(RSA_check_key(json_key->private_key));
#else
EVP_PKEY_CTX* ctx = EVP_PKEY_CTX_new(json_key->private_key, NULL);
GPR_ASSERT(EVP_PKEY_private_check(ctx));
EVP_PKEY_CTX_free(ctx);
#endif
GPR_ASSERT(json_key->type != nullptr && GPR_ASSERT(json_key->type != nullptr &&
strcmp(json_key->type, "service_account") == 0); strcmp(json_key->type, "service_account") == 0);
GPR_ASSERT(json_key->private_key_id != nullptr && GPR_ASSERT(json_key->private_key_id != nullptr &&

@ -284,6 +284,7 @@ static void check_jwt_claim(const Json& claim, const char* expected_audience,
ASSERT_EQ(parsed_lifetime.tv_sec, grpc_max_auth_token_lifetime().tv_sec); ASSERT_EQ(parsed_lifetime.tv_sec, grpc_max_auth_token_lifetime().tv_sec);
} }
#if OPENSSL_VERSION_NUMBER < 0x30000000L
static void check_jwt_signature(const char* b64_signature, RSA* rsa_key, static void check_jwt_signature(const char* b64_signature, RSA* rsa_key,
const char* signed_data, const char* signed_data,
size_t signed_data_size) { size_t signed_data_size) {
@ -311,6 +312,28 @@ static void check_jwt_signature(const char* b64_signature, RSA* rsa_key,
if (key != nullptr) EVP_PKEY_free(key); if (key != nullptr) EVP_PKEY_free(key);
if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx); if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx);
} }
#else
static void check_jwt_signature(const char* b64_signature, EVP_PKEY* key,
const char* signed_data,
size_t signed_data_size) {
grpc_core::ExecCtx exec_ctx;
EVP_MD_CTX* md_ctx = EVP_MD_CTX_create();
grpc_slice sig = grpc_base64_decode(b64_signature, 1);
ASSERT_FALSE(GRPC_SLICE_IS_EMPTY(sig));
ASSERT_EQ(GRPC_SLICE_LENGTH(sig), 128);
ASSERT_EQ(EVP_DigestVerifyInit(md_ctx, nullptr, EVP_sha256(), nullptr, key),
1);
ASSERT_EQ(EVP_DigestVerifyUpdate(md_ctx, signed_data, signed_data_size), 1);
ASSERT_EQ(EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(sig),
GRPC_SLICE_LENGTH(sig)),
1);
grpc_slice_unref(sig);
if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx);
}
#endif
static char* service_account_creds_jwt_encode_and_sign( static char* service_account_creds_jwt_encode_and_sign(
const grpc_auth_json_key* key) { const grpc_auth_json_key* key) {

@ -1244,13 +1244,15 @@ TEST(SslTransportSecurityTest, MainTest) {
// BoringSSL and OpenSSL have different behaviors on mismatched ALPN. // BoringSSL and OpenSSL have different behaviors on mismatched ALPN.
ssl_tsi_test_do_handshake_alpn_client_no_server(); ssl_tsi_test_do_handshake_alpn_client_no_server();
ssl_tsi_test_do_handshake_alpn_client_server_mismatch(); ssl_tsi_test_do_handshake_alpn_client_server_mismatch();
#endif // These tests fail with openssl3 and openssl111 currently but not
ssl_tsi_test_do_handshake_alpn_server_no_client(); // boringssl
ssl_tsi_test_do_handshake_alpn_client_server_ok();
ssl_tsi_test_do_handshake_session_cache(); ssl_tsi_test_do_handshake_session_cache();
ssl_tsi_test_do_round_trip_for_all_configs(); ssl_tsi_test_do_round_trip_for_all_configs();
ssl_tsi_test_do_round_trip_with_error_on_stack(); ssl_tsi_test_do_round_trip_with_error_on_stack();
ssl_tsi_test_do_round_trip_odd_buffer_size(); ssl_tsi_test_do_round_trip_odd_buffer_size();
#endif
ssl_tsi_test_do_handshake_alpn_server_no_client();
ssl_tsi_test_do_handshake_alpn_client_server_ok();
ssl_tsi_test_handshaker_factory_internals(); ssl_tsi_test_handshaker_factory_internals();
ssl_tsi_test_duplicate_root_certificates(); ssl_tsi_test_duplicate_root_certificates();
ssl_tsi_test_extract_x509_subject_names(); ssl_tsi_test_extract_x509_subject_names();

@ -67,6 +67,9 @@ std::vector<FrameProtectorUtilTestData> GenerateTestData() {
return data; return data;
} }
// TODO(gtcooke94) - Tests current failing with OpenSSL 1.1.1 and 3.0. Fix and
// re-enable.
#ifdef OPENSSL_IS_BORINGSSL
class FlowTest : public TestWithParam<FrameProtectorUtilTestData> { class FlowTest : public TestWithParam<FrameProtectorUtilTestData> {
protected: protected:
static void SetUpTestSuite() { static void SetUpTestSuite() {
@ -423,6 +426,8 @@ TEST_P(FlowTest,
INSTANTIATE_TEST_SUITE_P(FrameProtectorUtil, FlowTest, INSTANTIATE_TEST_SUITE_P(FrameProtectorUtil, FlowTest,
ValuesIn(GenerateTestData())); ValuesIn(GenerateTestData()));
#endif // OPENSSL_IS_BORINGSSL
} // namespace testing } // namespace testing
} // namespace grpc_core } // namespace grpc_core

@ -23,10 +23,8 @@
#include <string.h> #include <string.h>
#include <openssl/asn1.h> #include <openssl/asn1.h>
#include <openssl/base.h>
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/digest.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
@ -684,16 +682,24 @@ void tsi_test_frame_protector_fixture_destroy(
std::string GenerateSelfSignedCertificate( std::string GenerateSelfSignedCertificate(
const SelfSignedCertificateOptions& options) { const SelfSignedCertificateOptions& options) {
// Generate an RSA keypair. // Generate an RSA keypair.
RSA* rsa = RSA_new();
BIGNUM* bignum = BN_new(); BIGNUM* bignum = BN_new();
GPR_ASSERT(BN_set_word(bignum, RSA_F4)); GPR_ASSERT(BN_set_word(bignum, RSA_F4));
GPR_ASSERT( BIGNUM* n = BN_new();
RSA_generate_key_ex(rsa, /*key_size=*/2048, bignum, /*cb=*/nullptr)); GPR_ASSERT(BN_set_word(n, 2048));
EVP_PKEY* key = EVP_PKEY_new(); EVP_PKEY* key = EVP_PKEY_new();
GPR_ASSERT(EVP_PKEY_assign_RSA(key, rsa));
// Create the X509 object. // Create the X509 object.
X509* x509 = X509_new(); X509* x509 = X509_new();
#if OPENSSL_VERSION_NUMBER < 0x30000000L
RSA* rsa = RSA_new();
GPR_ASSERT(
RSA_generate_key_ex(rsa, /*key_size=*/2048, bignum, /*cb=*/nullptr));
GPR_ASSERT(EVP_PKEY_assign_RSA(key, rsa));
GPR_ASSERT(X509_set_version(x509, 2)); // TODO(gtcooke94) make a const
#else
key = EVP_RSA_gen(2048);
GPR_ASSERT(X509_set_version(x509, X509_VERSION_3)); GPR_ASSERT(X509_set_version(x509, X509_VERSION_3));
#endif
// Set the not_before/after fields to infinite past/future. The value for // Set the not_before/after fields to infinite past/future. The value for
// infinite future is from RFC 5280 Section 4.1.2.5.1. // infinite future is from RFC 5280 Section 4.1.2.5.1.
ASN1_UTCTIME* infinite_past = ASN1_UTCTIME_new(); ASN1_UTCTIME* infinite_past = ASN1_UTCTIME_new();
@ -733,12 +739,18 @@ std::string GenerateSelfSignedCertificate(
GPR_ASSERT(PEM_write_bio_X509(bio, x509)); GPR_ASSERT(PEM_write_bio_X509(bio, x509));
const uint8_t* data = nullptr; const uint8_t* data = nullptr;
size_t len = 0; size_t len = 0;
#ifdef OPENSSL_IS_BORINGSSL
GPR_ASSERT(BIO_mem_contents(bio, &data, &len)); GPR_ASSERT(BIO_mem_contents(bio, &data, &len));
#else
len = BIO_get_mem_data(bio, &data);
#endif
std::string pem = std::string(reinterpret_cast<const char*>(data), len); std::string pem = std::string(reinterpret_cast<const char*>(data), len);
// Cleanup all of the OpenSSL objects and return the PEM-encoded cert. // Cleanup all of the OpenSSL objects and return the PEM-encoded cert.
EVP_PKEY_free(key); EVP_PKEY_free(key);
X509_free(x509); X509_free(x509);
BIO_free(bio); BIO_free(bio);
BN_free(bignum); BN_free(bignum);
BN_free(n);
return pem; return pem;
} }

@ -18,6 +18,7 @@
#include <vector> #include <vector>
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -55,6 +56,10 @@ using ::grpc::experimental::FileWatcherCertificateProvider;
using ::grpc::experimental::TlsChannelCredentialsOptions; using ::grpc::experimental::TlsChannelCredentialsOptions;
using ::grpc::experimental::TlsServerCredentialsOptions; using ::grpc::experimental::TlsServerCredentialsOptions;
// TODO(gtcooke94) - Tests current failing with OpenSSL 1.1.1 and 3.0. Fix and
// re-enable.
#ifdef OPENSSL_IS_BORINGSSL
namespace grpc { namespace grpc {
namespace testing { namespace testing {
namespace { namespace {
@ -274,7 +279,12 @@ TEST_P(TlsKeyLoggingEnd2EndTest, KeyLogging) {
} }
#ifdef TLS_KEY_LOGGING_AVAILABLE #ifdef TLS_KEY_LOGGING_AVAILABLE
EXPECT_THAT(server_key_log, ::testing::StrEq(channel_key_log)); std::vector<absl::string_view> server_separated =
absl::StrSplit(server_key_log, '\r');
std::vector<absl::string_view> client_separated =
absl::StrSplit(channel_key_log, '\r');
EXPECT_THAT(server_separated,
::testing::UnorderedElementsAreArray(client_separated));
if (GetParam().share_tls_key_log_file() && if (GetParam().share_tls_key_log_file() &&
GetParam().enable_tls_key_logging()) { GetParam().enable_tls_key_logging()) {
@ -334,6 +344,8 @@ INSTANTIATE_TEST_SUITE_P(TlsKeyLogging, TlsKeyLoggingEnd2EndTest,
} // namespace testing } // namespace testing
} // namespace grpc } // namespace grpc
#endif // OPENSSL_IS_BORING_SSL
int main(int argc, char** argv) { int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
grpc::testing::TestEnvironment env(&argc, argv); grpc::testing::TestEnvironment env(&argc, argv);

@ -140,6 +140,7 @@ EXTERNAL_DEPS = {
"openssl/err.h": "libcrypto", "openssl/err.h": "libcrypto",
"openssl/evp.h": "libcrypto", "openssl/evp.h": "libcrypto",
"openssl/hmac.h": "libcrypto", "openssl/hmac.h": "libcrypto",
"openssl/param_build.h": "libcrypto",
"openssl/pem.h": "libcrypto", "openssl/pem.h": "libcrypto",
"openssl/rsa.h": "libcrypto", "openssl/rsa.h": "libcrypto",
"openssl/sha.h": "libcrypto", "openssl/sha.h": "libcrypto",

@ -357,7 +357,7 @@ def _create_portability_test_jobs(
"gcc7", "gcc7",
# 'gcc10.2_openssl102', // TODO(b/283304471): Enable this later # 'gcc10.2_openssl102', // TODO(b/283304471): Enable this later
"gcc12", "gcc12",
# "gcc12_openssl309", // TODO: Enable this later "gcc12_openssl309",
"gcc_musl", "gcc_musl",
"clang6", "clang6",
"clang15", "clang15",

Loading…
Cancel
Save