1
#pragma once
2

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

            
7
#include "envoy/api/api.h"
8
#include "envoy/common/pure.h"
9
#include "envoy/extensions/transport_sockets/tls/v3/cert.pb.h"
10
#include "envoy/extensions/transport_sockets/tls/v3/common.pb.h"
11
#include "envoy/type/matcher/v3/string.pb.h"
12

            
13
#include "absl/types/optional.h"
14

            
15
namespace Envoy {
16
namespace Ssl {
17

            
18
// SECURITY NOTE
19
//
20
// When adding or changing this interface, it is likely that a change is needed to
21
// `DefaultCertValidator::updateDigestForSessionId` in
22
// `source/common/tls/cert_validator/default_validator.cc`.
23
class CertificateValidationContextConfig {
24
public:
25
6042
  virtual ~CertificateValidationContextConfig() = default;
26

            
27
  /**
28
   * @return The CA certificate to use for peer validation.
29
   */
30
  virtual const std::string& caCert() const PURE;
31

            
32
  /**
33
   * @return Path of the CA certificate to use for peer validation or "<inline>"
34
   * if the CA certificate was inlined.
35
   */
36
  virtual const std::string& caCertPath() const PURE;
37

            
38
  /**
39
   * @return the name of the CA certificate.
40
   */
41
  virtual const std::string& caCertName() const PURE;
42

            
43
  /**
44
   * @return The CRL to check if a cert is revoked.
45
   */
46
  virtual const std::string& certificateRevocationList() const PURE;
47

            
48
  /**
49
   * @return Path of the certificate revocation list, or "<inline>" if the CRL
50
   * was inlined.
51
   */
52
  virtual const std::string& certificateRevocationListPath() const PURE;
53

            
54
  /**
55
   * @return The subject alt name matchers to be verified, if enabled.
56
   */
57
  virtual const std::vector<envoy::extensions::transport_sockets::tls::v3::SubjectAltNameMatcher>&
58
  subjectAltNameMatchers() const PURE;
59

            
60
  /**
61
   * @return A list of a hex-encoded SHA-256 certificate hashes to be verified.
62
   */
63
  virtual const std::vector<std::string>& verifyCertificateHashList() const PURE;
64

            
65
  /**
66
   * @return A list of a hex-encoded SHA-256 SPKI hashes to be verified.
67
   */
68
  virtual const std::vector<std::string>& verifyCertificateSpkiList() const PURE;
69

            
70
  /**
71
   * @return whether to ignore expired certificates (both too new and too old).
72
   */
73
  virtual bool allowExpiredCertificate() const PURE;
74

            
75
  /**
76
   * @return client certificate validation configuration.
77
   */
78
  virtual envoy::extensions::transport_sockets::tls::v3::CertificateValidationContext::
79
      TrustChainVerification
80
      trustChainVerification() const PURE;
81

            
82
  /**
83
   * @return the configuration for the custom certificate validator if configured.
84
   */
85
  virtual const absl::optional<envoy::config::core::v3::TypedExtensionConfig>&
86
  customValidatorConfig() const PURE;
87

            
88
  /**
89
   * @return a reference to the api object.
90
   */
91
  virtual Api::Api& api() const PURE;
92

            
93
  /**
94
   * @return whether to validate certificate chain with all CRL or not.
95
   */
96
  virtual bool onlyVerifyLeafCertificateCrl() const PURE;
97

            
98
  /**
99
   * @return the max depth used when verifying the certificate-chain
100
   */
101
  virtual absl::optional<uint32_t> maxVerifyDepth() const PURE;
102

            
103
  /**
104
   * @return true if the SAN validation rules should be replaced with a rule to validate that the
105
   * certificate matches the transmitted SNI.
106
   */
107
  virtual bool autoSniSanMatch() const PURE;
108

            
109
  // SECURITY NOTE
110
  //
111
  // When adding or changing this interface, it is likely that a change is needed to
112
  // `DefaultCertValidator::updateDigestForSessionId` in
113
  // `source/common/tls/cert_validator/default_validator.cc`.
114
};
115

            
116
using CertificateValidationContextConfigPtr = std::unique_ptr<CertificateValidationContextConfig>;
117

            
118
} // namespace Ssl
119
} // namespace Envoy