1
#pragma once
2

            
3
#include <cstdint>
4
#include <functional>
5
#include <list>
6

            
7
#include "envoy/common/time.h"
8
#include "envoy/server/factory_context.h"
9
#include "envoy/ssl/context_manager.h"
10
#include "envoy/ssl/private_key/private_key.h"
11
#include "envoy/stats/scope.h"
12

            
13
#include "source/common/tls/private_key/private_key_manager_impl.h"
14

            
15
namespace Envoy {
16
namespace Extensions {
17
namespace TransportSockets {
18
namespace Tls {
19

            
20
/**
21
 * The SSL context manager has the following threading model:
22
 * Contexts can be allocated the main thread. They can be released from any thread (and in practice
23
 * are since cluster information can be released from any thread). Context allocation/free is a very
24
 * uncommon thing so we just do a global lock to protect it all.
25
 */
26
class ContextManagerImpl final : public Envoy::Ssl::ContextManager {
27
public:
28
  explicit ContextManagerImpl(Server::Configuration::CommonFactoryContext& factory_context);
29
24052
  ~ContextManagerImpl() override = default;
30

            
31
  // Ssl::ContextManager
32
  absl::StatusOr<Ssl::ClientContextSharedPtr>
33
  createSslClientContext(Stats::Scope& scope,
34
                         const Envoy::Ssl::ClientContextConfig& config) override;
35
  absl::StatusOr<Ssl::ServerContextSharedPtr>
36
  createSslServerContext(Stats::Scope& scope, const Envoy::Ssl::ServerContextConfig& config,
37
                         Ssl::ContextAdditionalInitFunc additional_init) override;
38
  absl::optional<uint32_t> daysUntilFirstCertExpires() const override;
39
  absl::optional<uint64_t> secondsUntilFirstOcspResponseExpires() const override;
40
  void iterateContexts(std::function<void(const Envoy::Ssl::Context&)> callback) override;
41
4
  Ssl::PrivateKeyMethodManager& privateKeyMethodManager() override {
42
4
    return private_key_method_manager_;
43
4
  };
44
  void removeContext(const Envoy::Ssl::ContextSharedPtr& old_context) override;
45

            
46
private:
47
  Server::Configuration::CommonFactoryContext& factory_context_;
48
  absl::flat_hash_set<Envoy::Ssl::ContextSharedPtr> contexts_;
49
  PrivateKeyMethodManagerImpl private_key_method_manager_{};
50
};
51

            
52
} // namespace Tls
53
} // namespace TransportSockets
54
} // namespace Extensions
55
} // namespace Envoy