1
#pragma once
2

            
3
#include <functional>
4

            
5
#include "envoy/common/callback.h"
6
#include "envoy/common/pure.h"
7
#include "envoy/extensions/transport_sockets/tls/v3/cert.pb.h"
8
#include "envoy/init/target.h"
9
#include "envoy/ssl/certificate_validation_context_config.h"
10
#include "envoy/ssl/tls_certificate_config.h"
11

            
12
namespace Envoy {
13
namespace Secret {
14

            
15
/**
16
 * A secret provider for each kind of secret.
17
 */
18
template <class SecretType> class SecretProvider {
19
public:
20
20226
  virtual ~SecretProvider() = default;
21

            
22
  /**
23
   * @return the secret. Returns nullptr if the secret is not ready.
24
   */
25
  virtual const SecretType* secret() const PURE;
26

            
27
  /**
28
   * Add secret validation callback into secret provider.
29
   * It is safe to call this method by main thread and callback is safe to be invoked
30
   * on main thread.
31
   * @param callback callback that is executed by secret provider.
32
   * @return CallbackHandle the handle which can remove that validation callback.
33
   */
34
  ABSL_MUST_USE_RESULT virtual Common::CallbackHandlePtr
35
  addValidationCallback(std::function<absl::Status(const SecretType&)> callback) PURE;
36

            
37
  /**
38
   * Add secret update callback into secret provider.
39
   * It is safe to call this method by main thread and callback is safe to be invoked
40
   * on main thread.
41
   * @param callback callback that is executed by secret provider.
42
   * @return CallbackHandle the handle which can remove that update callback.
43
   */
44
  ABSL_MUST_USE_RESULT virtual Common::CallbackHandlePtr
45
  addUpdateCallback(std::function<absl::Status()> callback) PURE;
46

            
47
  /**
48
   * Add secret remove callback into the secret provider, which is triggered
49
   * when the server explicitly removes a resource. Once the resource is
50
   * removed, no futher updates are expected. It is safe to call this method
51
   * by main thread and callback is safe to be invoked on main thread.
52
   * @param callback callback that is executed by secret provider.
53
   * @return CallbackHandle the handle which can remove that update callback.
54
   */
55
  ABSL_MUST_USE_RESULT virtual Common::CallbackHandlePtr
56
  addRemoveCallback(std::function<absl::Status()> callback) PURE;
57

            
58
  /**
59
   * @return const Init::Target* A shared init target that can be used by multiple init managers.
60
   * nullptr if the provider isn't dynamic.
61
   */
62
  virtual const Init::Target* initTarget() { return nullptr; }
63

            
64
  /**
65
   * Start initializating the provider (when not using the init manager).
66
   */
67
  virtual void start() PURE;
68
};
69

            
70
using TlsCertificatePtr =
71
    std::unique_ptr<envoy::extensions::transport_sockets::tls::v3::TlsCertificate>;
72
using CertificateValidationContextPtr =
73
    std::unique_ptr<envoy::extensions::transport_sockets::tls::v3::CertificateValidationContext>;
74
using TlsSessionTicketKeysPtr =
75
    std::unique_ptr<envoy::extensions::transport_sockets::tls::v3::TlsSessionTicketKeys>;
76
using GenericSecretPtr =
77
    std::unique_ptr<envoy::extensions::transport_sockets::tls::v3::GenericSecret>;
78

            
79
using TlsCertificateConfigProvider =
80
    SecretProvider<envoy::extensions::transport_sockets::tls::v3::TlsCertificate>;
81
using TlsCertificateConfigProviderSharedPtr = std::shared_ptr<TlsCertificateConfigProvider>;
82

            
83
using CertificateValidationContextConfigProvider =
84
    SecretProvider<envoy::extensions::transport_sockets::tls::v3::CertificateValidationContext>;
85
using CertificateValidationContextConfigProviderSharedPtr =
86
    std::shared_ptr<CertificateValidationContextConfigProvider>;
87

            
88
using TlsSessionTicketKeysConfigProvider =
89
    SecretProvider<envoy::extensions::transport_sockets::tls::v3::TlsSessionTicketKeys>;
90
using TlsSessionTicketKeysConfigProviderSharedPtr =
91
    std::shared_ptr<TlsSessionTicketKeysConfigProvider>;
92

            
93
using GenericSecretConfigProvider =
94
    SecretProvider<envoy::extensions::transport_sockets::tls::v3::GenericSecret>;
95
using GenericSecretConfigProviderSharedPtr = std::shared_ptr<GenericSecretConfigProvider>;
96

            
97
} // namespace Secret
98
} // namespace Envoy