LCOV - code coverage report
Current view: top level - source/common/ssl/matching - inputs.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 8 47 17.0 %
Date: 2024-01-05 06:35:25 Functions: 24 42 57.1 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/extensions/matching/common_inputs/ssl/v3/ssl_inputs.pb.h"
       4             : #include "envoy/extensions/matching/common_inputs/ssl/v3/ssl_inputs.pb.validate.h"
       5             : #include "envoy/matcher/matcher.h"
       6             : 
       7             : #include "absl/strings/str_join.h"
       8             : 
       9             : namespace Envoy {
      10             : namespace Ssl {
      11             : namespace Matching {
      12             : 
      13             : template <class InputType, class ProtoType, class MatchingDataType>
      14             : class BaseFactory : public Matcher::DataInputFactory<MatchingDataType> {
      15             : protected:
      16          24 :   explicit BaseFactory(const std::string& name) : name_(name) {}
      17             : 
      18             : public:
      19         240 :   std::string name() const override { return "envoy.matching.inputs." + name_; }
      20             : 
      21             :   Matcher::DataInputFactoryCb<MatchingDataType>
      22           0 :   createDataInputFactoryCb(const Protobuf::Message&, ProtobufMessage::ValidationVisitor&) override {
      23           0 :     return []() { return std::make_unique<InputType>(); };
      24           0 :   };
      25           6 :   ProtobufTypes::MessagePtr createEmptyConfigProto() override {
      26           6 :     return std::make_unique<ProtoType>();
      27           6 :   }
      28             : 
      29             : private:
      30             :   const std::string name_;
      31             : };
      32             : 
      33             : template <class MatchingDataType> class UriSanInput : public Matcher::DataInput<MatchingDataType> {
      34             : public:
      35           0 :   Matcher::DataInputGetResult get(const MatchingDataType& data) const override {
      36           0 :     const auto& ssl = data.ssl();
      37           0 :     if (!ssl) {
      38           0 :       return {Matcher::DataInputGetResult::DataAvailability::NotAvailable, absl::monostate()};
      39           0 :     }
      40           0 :     const auto& uri = ssl->uriSanPeerCertificate();
      41           0 :     if (!uri.empty()) {
      42           0 :       return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable,
      43           0 :               absl::StrJoin(uri, ",")};
      44           0 :     }
      45           0 :     return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::monostate()};
      46           0 :   }
      47             : };
      48             : 
      49             : template <class MatchingDataType>
      50             : class UriSanInputBaseFactory
      51             :     : public BaseFactory<UriSanInput<MatchingDataType>,
      52             :                          envoy::extensions::matching::common_inputs::ssl::v3::UriSanInput,
      53             :                          MatchingDataType> {
      54             : public:
      55             :   UriSanInputBaseFactory()
      56             :       : BaseFactory<UriSanInput<MatchingDataType>,
      57             :                     envoy::extensions::matching::common_inputs::ssl::v3::UriSanInput,
      58           8 :                     MatchingDataType>("uri_san") {}
      59             : };
      60             : 
      61             : template <class MatchingDataType> class DnsSanInput : public Matcher::DataInput<MatchingDataType> {
      62             : public:
      63           0 :   Matcher::DataInputGetResult get(const MatchingDataType& data) const override {
      64           0 :     const auto& ssl = data.ssl();
      65           0 :     if (!ssl) {
      66           0 :       return {Matcher::DataInputGetResult::DataAvailability::NotAvailable, absl::monostate()};
      67           0 :     }
      68           0 :     const auto& dns = ssl->dnsSansPeerCertificate();
      69           0 :     if (!dns.empty()) {
      70           0 :       return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable,
      71           0 :               absl::StrJoin(dns, ",")};
      72           0 :     }
      73           0 :     return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::monostate()};
      74           0 :   }
      75             : };
      76             : 
      77             : template <class MatchingDataType>
      78             : class DnsSanInputBaseFactory
      79             :     : public BaseFactory<DnsSanInput<MatchingDataType>,
      80             :                          envoy::extensions::matching::common_inputs::ssl::v3::DnsSanInput,
      81             :                          MatchingDataType> {
      82             : public:
      83             :   DnsSanInputBaseFactory()
      84             :       : BaseFactory<DnsSanInput<MatchingDataType>,
      85             :                     envoy::extensions::matching::common_inputs::ssl::v3::DnsSanInput,
      86           8 :                     MatchingDataType>("dns_san") {}
      87             : };
      88             : 
      89             : template <class MatchingDataType> class SubjectInput : public Matcher::DataInput<MatchingDataType> {
      90             : public:
      91           0 :   Matcher::DataInputGetResult get(const MatchingDataType& data) const override {
      92           0 :     const auto& ssl = data.ssl();
      93           0 :     if (!ssl) {
      94           0 :       return {Matcher::DataInputGetResult::DataAvailability::NotAvailable, absl::monostate()};
      95           0 :     }
      96           0 :     const auto& subject = ssl->subjectPeerCertificate();
      97           0 :     if (!subject.empty()) {
      98           0 :       return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable,
      99           0 :               std::string(subject)};
     100           0 :     }
     101           0 :     return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, absl::monostate()};
     102           0 :   }
     103             : };
     104             : 
     105             : template <class MatchingDataType>
     106             : class SubjectInputBaseFactory
     107             :     : public BaseFactory<SubjectInput<MatchingDataType>,
     108             :                          envoy::extensions::matching::common_inputs::ssl::v3::SubjectInput,
     109             :                          MatchingDataType> {
     110             : public:
     111             :   SubjectInputBaseFactory()
     112             :       : BaseFactory<SubjectInput<MatchingDataType>,
     113             :                     envoy::extensions::matching::common_inputs::ssl::v3::SubjectInput,
     114           8 :                     MatchingDataType>("subject") {}
     115             : };
     116             : 
     117             : } // namespace Matching
     118             : } // namespace Ssl
     119             : } // namespace Envoy

Generated by: LCOV version 1.15