Skip to content

Commit

Permalink
Fixes MAISTRA-2324:
Browse files Browse the repository at this point in the history
port of tls: separate out cert validation logic from ContextImpl (#14757)
  • Loading branch information
Dmitri Dolguikh committed May 4, 2021
1 parent 310c404 commit 057f294
Show file tree
Hide file tree
Showing 18 changed files with 1,126 additions and 765 deletions.
19 changes: 18 additions & 1 deletion source/extensions/transport_sockets/tls/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ envoy_cc_library(
"abseil_node_hash_set",
"abseil_synchronization",
"ssl",
"bssl_wrapper_lib",
"bssl_wrapper_lib",
],
# TLS is core functionality.
visibility = ["//visibility:public"],
deps = [
":openssl_impl_lib",
":stats_lib",
":utility_lib",
"//include/envoy/ssl:context_config_interface",
"//include/envoy/ssl:context_interface",
Expand All @@ -164,13 +165,29 @@ envoy_cc_library(
"//source/common/runtime:runtime_features_lib",
"//source/common/stats:symbol_table_lib",
"//source/common/stats:utility_lib",
"//source/extensions/transport_sockets/tls/cert_validator:cert_validator_lib",
"//source/extensions/transport_sockets/tls/ocsp:ocsp_lib",
"//source/extensions/transport_sockets/tls/private_key:private_key_manager_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/type/matcher/v3:pkg_cc_proto",
],
)

envoy_cc_library(
name = "stats_lib",
srcs = ["stats.cc"],
hdrs = ["stats.h"],
external_deps = [
"ssl",
],
deps = [
"//include/envoy/stats:stats_interface",
"//include/envoy/stats:stats_macros",
"//source/common/stats:symbol_table_lib",
"//source/common/stats:utility_lib",
],
)

envoy_cc_library(
name = "utility_lib",
srcs = ["utility.cc"],
Expand Down
39 changes: 39 additions & 0 deletions source/extensions/transport_sockets/tls/cert_validator/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_extension_package",
)

licenses(["notice"]) # Apache 2

envoy_extension_package()

envoy_cc_library(
name = "cert_validator_lib",
srcs = [
"default_validator.cc",
],
hdrs = [
"cert_validator.h",
"default_validator.h",
],
external_deps = [
"ssl",
"bssl_wrapper_lib",
],
# TLS is core functionality.
visibility = ["//visibility:public"],
deps = [
"//include/envoy/ssl:context_config_interface",
"//include/envoy/ssl:ssl_socket_extended_info_interface",
"//source/common/common:assert_lib",
"//source/common/common:base64_lib",
"//source/common/common:hex_lib",
"//source/common/common:utility_lib",
"//source/common/runtime:runtime_features_lib",
"//source/common/stats:symbol_table_lib",
"//source/common/stats:utility_lib",
"//source/extensions/transport_sockets/tls:stats_lib",
"//source/extensions/transport_sockets/tls:utility_lib",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once

#include <array>
#include <deque>
#include <functional>
#include <string>
#include <vector>

#include "envoy/common/pure.h"
#include "envoy/network/transport_socket.h"
#include "envoy/ssl/context.h"
#include "envoy/ssl/context_config.h"
#include "envoy/ssl/private_key/private_key.h"
#include "envoy/ssl/ssl_socket_extended_info.h"

#include "common/common/matchers.h"
#include "common/stats/symbol_table_impl.h"

#include "extensions/transport_sockets/tls/stats.h"

#include "absl/synchronization/mutex.h"
#include "openssl/ssl.h"
#include "openssl/x509v3.h"

namespace Envoy {
namespace Extensions {
namespace TransportSockets {
namespace Tls {

class CertValidator {
public:
virtual ~CertValidator() = default;

/**
* Called to add the client validation context information to a given ssl context
*
* @param context the store context
* @param require_client_cert whether or not client cert is required
*/
virtual void addClientValidationContext(SSL_CTX* context, bool require_client_cert) PURE;

/**
* Called by verifyCallback to do the actual cert chain verification.
*
* @param store_ctx the store context
* @param ssl_extended_info the info for storing the validation status
* @param leaf_cert the peer certificate to verify
* @return 1 to indicate verification success and 0 to indicate verification failure.
*/
virtual int
doVerifyCertChain(X509_STORE_CTX* store_ctx, Ssl::SslExtendedSocketInfo* ssl_extended_info,
X509& leaf_cert,
const Network::TransportSocketOptions* transport_socket_options) PURE;

/**
* Called to initialize all ssl contexts
*
* @param contexts the store context
* @param handshaker_provides_certificates whether or not a handshaker implementation provides
* certificates itself.
* @return the ssl verification mode flag
*/
virtual int initializeSslContexts(std::vector<SSL_CTX*> contexts,
bool handshaker_provides_certificates) PURE;

/**
* Called when calculation hash for session context ids
*
* @param md the store context
* @param hash_buffer the buffer used for digest calculation
* @param hash_length the expected length of hash
*/
virtual void updateDigestForSessionId(bssl::ScopedEVP_MD_CTX& md,
uint8_t hash_buffer[EVP_MAX_MD_SIZE],
unsigned hash_length) PURE;

virtual size_t daysUntilFirstCertExpires() const PURE;
virtual std::string getCaFileName() const PURE;
virtual Envoy::Ssl::CertificateDetailsPtr getCaCertInformation() const PURE;
};

using CertValidatorPtr = std::unique_ptr<CertValidator>;

} // namespace Tls
} // namespace TransportSockets
} // namespace Extensions
} // namespace Envoy
Loading

0 comments on commit 057f294

Please sign in to comment.