-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: support BoringSSL private key async functionality (#6326)
This PR adds BoringSSL private key API abstraction, as discussed in #6248. All comments and discussion is welcomed to get the API sufficient for most private key API tasks. The PR contains the proposed API and the way how it can be used from ssl_socket.h. Also there is some code showing how the PrivateKeyMethodProvider is coming from TLS certificate config. Two example private key method providers are included in the tests. Description: tls: support BoringSSL private key async functionality Risk Level: medium Testing: two basic private key provider implementation Docs Changes: TLS arch doc, cert.proto doc Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
- Loading branch information
Showing
37 changed files
with
1,679 additions
and
63 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
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
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
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
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
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
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,35 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "private_key_interface", | ||
hdrs = ["private_key.h"], | ||
external_deps = ["ssl"], | ||
deps = [ | ||
":private_key_callbacks_interface", | ||
"//include/envoy/event:dispatcher_interface", | ||
"@envoy_api//envoy/api/v2/auth:cert_cc", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "private_key_config_interface", | ||
hdrs = ["private_key_config.h"], | ||
deps = [ | ||
":private_key_interface", | ||
"//include/envoy/registry", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "private_key_callbacks_interface", | ||
hdrs = ["private_key_callbacks.h"], | ||
external_deps = ["ssl"], | ||
) |
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,85 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <string> | ||
|
||
#include "envoy/api/v2/auth/cert.pb.h" | ||
#include "envoy/common/pure.h" | ||
#include "envoy/event/dispatcher.h" | ||
#include "envoy/ssl/private_key/private_key_callbacks.h" | ||
|
||
#include "openssl/ssl.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
namespace Configuration { | ||
// Prevent a dependency loop with the forward declaration. | ||
class TransportSocketFactoryContext; | ||
} // namespace Configuration | ||
} // namespace Server | ||
|
||
namespace Ssl { | ||
|
||
using BoringSslPrivateKeyMethodSharedPtr = std::shared_ptr<SSL_PRIVATE_KEY_METHOD>; | ||
|
||
class PrivateKeyMethodProvider { | ||
public: | ||
virtual ~PrivateKeyMethodProvider() = default; | ||
|
||
/** | ||
* Register an SSL connection to private key operations by the provider. | ||
* @param ssl a SSL connection object. | ||
* @param cb a callbacks object, whose "complete" method will be invoked | ||
* when the asynchronous processing is complete. | ||
* @param dispatcher supplies the owning thread's dispatcher. | ||
*/ | ||
virtual void registerPrivateKeyMethod(SSL* ssl, PrivateKeyConnectionCallbacks& cb, | ||
Event::Dispatcher& dispatcher) PURE; | ||
|
||
/** | ||
* Unregister an SSL connection from private key operations by the provider. | ||
* @param ssl a SSL connection object. | ||
* @throw EnvoyException if registration fails. | ||
*/ | ||
virtual void unregisterPrivateKeyMethod(SSL* ssl) PURE; | ||
|
||
/** | ||
* Check whether the private key method satisfies FIPS requirements. | ||
* @return true if FIPS key requirements are satisfied, false if not. | ||
*/ | ||
virtual bool checkFips() PURE; | ||
|
||
/** | ||
* Get the private key methods from the provider. | ||
* @return the private key methods associated with this provider and | ||
* configuration. | ||
*/ | ||
virtual BoringSslPrivateKeyMethodSharedPtr getBoringSslPrivateKeyMethod() PURE; | ||
}; | ||
|
||
using PrivateKeyMethodProviderSharedPtr = std::shared_ptr<PrivateKeyMethodProvider>; | ||
|
||
/** | ||
* A manager for finding correct user-provided functions for handling BoringSSL private key | ||
* operations. | ||
*/ | ||
class PrivateKeyMethodManager { | ||
public: | ||
virtual ~PrivateKeyMethodManager() = default; | ||
|
||
/** | ||
* Finds and returns a private key operations provider for BoringSSL. | ||
* | ||
* @param config a protobuf message object containing a PrivateKeyProvider message. | ||
* @param factory_context context that provides components for creating and | ||
* initializing connections using asynchronous private key operations. | ||
* @return PrivateKeyMethodProvider the private key operations provider, or nullptr if | ||
* no provider can be used with the context configuration. | ||
*/ | ||
virtual PrivateKeyMethodProviderSharedPtr createPrivateKeyMethodProvider( | ||
const envoy::api::v2::auth::PrivateKeyProvider& config, | ||
Envoy::Server::Configuration::TransportSocketFactoryContext& factory_context) PURE; | ||
}; | ||
|
||
} // namespace Ssl | ||
} // namespace Envoy |
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,25 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <string> | ||
|
||
#include "envoy/common/pure.h" | ||
|
||
namespace Envoy { | ||
namespace Ssl { | ||
|
||
class PrivateKeyConnectionCallbacks { | ||
public: | ||
virtual ~PrivateKeyConnectionCallbacks() = default; | ||
|
||
/** | ||
* Callback function which is called when the asynchronous private key | ||
* operation has been completed (with either success or failure). The | ||
* provider will communicate the success status when SSL_do_handshake() | ||
* is called the next time. | ||
*/ | ||
virtual void onPrivateKeyMethodComplete() PURE; | ||
}; | ||
|
||
} // namespace Ssl | ||
} // namespace Envoy |
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,22 @@ | ||
#pragma once | ||
|
||
#include "envoy/api/v2/auth/cert.pb.h" | ||
#include "envoy/registry/registry.h" | ||
#include "envoy/ssl/private_key/private_key.h" | ||
|
||
namespace Envoy { | ||
namespace Ssl { | ||
|
||
// Base class which the private key operation provider implementations can register. | ||
|
||
class PrivateKeyMethodProviderInstanceFactory { | ||
public: | ||
virtual ~PrivateKeyMethodProviderInstanceFactory() = default; | ||
virtual PrivateKeyMethodProviderSharedPtr createPrivateKeyMethodProviderInstance( | ||
const envoy::api::v2::auth::PrivateKeyProvider& config, | ||
Server::Configuration::TransportSocketFactoryContext& factory_context) PURE; | ||
virtual std::string name() const PURE; | ||
}; | ||
|
||
} // namespace Ssl | ||
} // namespace Envoy |
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
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
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
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
Oops, something went wrong.