-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
18 changed files
with
1,126 additions
and
765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
source/extensions/transport_sockets/tls/cert_validator/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
87 changes: 87 additions & 0 deletions
87
source/extensions/transport_sockets/tls/cert_validator/cert_validator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.