1
#pragma once
2

            
3
#include <memory>
4
#include <string>
5

            
6
#include "envoy/admin/v3/certs.pb.h"
7
#include "envoy/common/pure.h"
8
#include "envoy/common/time.h"
9

            
10
#include "absl/types/optional.h"
11

            
12
namespace Envoy {
13
namespace Ssl {
14

            
15
using CertificateDetailsPtr = std::unique_ptr<envoy::admin::v3::CertificateDetails>;
16

            
17
/**
18
 * SSL Context is used as a template for SSL connection configuration.
19
 */
20
class Context {
21
public:
22
7051
  virtual ~Context() = default;
23

            
24
  /**
25
   * @return the number of days in this context until the next certificate will expire, the value is
26
   * set when not expired.
27
   */
28
  virtual absl::optional<uint32_t> daysUntilFirstCertExpires() const PURE;
29

            
30
  /**
31
   * @return certificate details conforming to proto admin.v2alpha.certs.
32
   */
33
  virtual CertificateDetailsPtr getCaCertInformation() const PURE;
34

            
35
  /**
36
   * @return certificate details conforming to proto admin.v2alpha.certs.
37
   */
38
  virtual std::vector<CertificateDetailsPtr> getCertChainInformation() const PURE;
39

            
40
  /**
41
   * @return the number of seconds in this context until the next OCSP response will
42
   * expire, or `absl::nullopt` if no OCSP responses exist.
43
   */
44
  virtual absl::optional<uint64_t> secondsUntilFirstOcspResponseExpires() const PURE;
45
};
46
using ContextSharedPtr = std::shared_ptr<Context>;
47

            
48
class ClientContext : public virtual Context {};
49
using ClientContextSharedPtr = std::shared_ptr<ClientContext>;
50

            
51
class ServerContext : public virtual Context {};
52
using ServerContextSharedPtr = std::shared_ptr<ServerContext>;
53

            
54
class OcspResponseWrapper {
55
public:
56
1190
  virtual ~OcspResponseWrapper() = default;
57
  /**
58
   * @returns the seconds until this OCSP response expires.
59
   */
60
  virtual uint64_t secondsUntilExpiration() const PURE;
61

            
62
  /**
63
   * @return The beginning of the validity window for this response.
64
   */
65
  virtual Envoy::SystemTime getThisUpdate() const PURE;
66

            
67
  /**
68
   * The time at which this response is considered to expire. If
69
   * the underlying response does not have a value, then the current
70
   * time is returned.
71
   *
72
   * @return The end of the validity window for this response.
73
   */
74
  virtual Envoy::SystemTime getNextUpdate() const PURE;
75

            
76
  /**
77
   * Determines whether the OCSP response can no longer be considered valid.
78
   * This can be true if the nextUpdate field of the response has passed
79
   * or is not present, indicating that there is always more updated information
80
   * available.
81
   *
82
   * @returns bool if the OCSP response is expired.
83
   */
84
  virtual bool isExpired() PURE;
85

            
86
  /**
87
   * @return std::vector<uint8_t>& a reference to the underlying bytestring representation
88
   * of the OCSP response
89
   */
90
  virtual const std::vector<uint8_t>& rawBytes() const PURE;
91
};
92

            
93
} // namespace Ssl
94
} // namespace Envoy