GRPC C++  1.62.0
grpc_crl_provider.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2023 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #ifndef GRPC_GRPC_CRL_PROVIDER_H
20 #define GRPC_GRPC_CRL_PROVIDER_H
21 
23 
24 #include <memory>
25 #include <string>
26 
27 #include "absl/status/statusor.h"
28 #include "absl/strings/string_view.h"
29 
30 #include <grpc/grpc_security.h>
31 
32 namespace grpc_core {
33 namespace experimental {
34 
35 // Opaque representation of a CRL. Must be thread safe.
36 class Crl {
37  public:
38  static absl::StatusOr<std::unique_ptr<Crl>> Parse(
39  absl::string_view crl_string);
40  virtual ~Crl() = default;
41  virtual absl::string_view Issuer() = 0;
42 };
43 
44 // Information about a certificate to be used to fetch its associated CRL. Must
45 // be thread safe.
47  public:
48  virtual ~CertificateInfo() = default;
49  virtual absl::string_view Issuer() const = 0;
50 };
51 
52 // The base class for CRL Provider implementations.
53 // CrlProviders can be passed in as a way to supply CRLs during handshakes.
54 // CrlProviders must be thread safe. They are on the critical path of gRPC
55 // creating a connection and doing a handshake, so the implementation of
56 // `GetCrl` should be very fast. It is suggested to have an in-memory map of
57 // CRLs for quick lookup and return, and doing expensive updates to this map
58 // asynchronously.
59 class CrlProvider {
60  public:
61  virtual ~CrlProvider() = default;
62  // Get the CRL associated with a certificate. Read-only.
63  virtual std::shared_ptr<Crl> GetCrl(
64  const CertificateInfo& certificate_info) = 0;
65 };
66 
67 absl::StatusOr<std::shared_ptr<CrlProvider>> CreateStaticCrlProvider(
68  absl::Span<const std::string> crls);
69 
70 // Creates a CRL Provider that periodically and asynchronously reloads a
71 // directory. The refresh_duration minimum is 60 seconds. The
72 // reload_error_callback provides a way for the user to specifically log or
73 // otherwise notify of errors during reloading. Since reloading is asynchronous
74 // and not on the main codepath, the grpc process will continue to run through
75 // reloading errors, so this mechanism is an important way to provide signals to
76 // your monitoring and alerting setup.
77 absl::StatusOr<std::shared_ptr<CrlProvider>> CreateDirectoryReloaderCrlProvider(
78  absl::string_view directory, std::chrono::seconds refresh_duration,
79  std::function<void(absl::Status)> reload_error_callback);
80 
81 } // namespace experimental
82 } // namespace grpc_core
83 
84 // TODO(gtcooke94) - Mark with api macro when all wrapped langauges support C++
85 // in core APIs
93  std::shared_ptr<grpc_core::experimental::CrlProvider> provider);
94 #endif /* GRPC_GRPC_CRL_PROVIDER_H */
grpc_core::experimental::CrlProvider::~CrlProvider
virtual ~CrlProvider()=default
grpc_core::experimental::Crl
Definition: grpc_crl_provider.h:36
grpc_core::experimental::CertificateInfo
Definition: grpc_crl_provider.h:46
grpc_tls_credentials_options_set_crl_provider
void grpc_tls_credentials_options_set_crl_provider(grpc_tls_credentials_options *options, std::shared_ptr< grpc_core::experimental::CrlProvider > provider)
EXPERIMENTAL API - Subject to change.
grpc_core
Definition: grpc_audit_logging.h:32
grpc_security.h
grpc_core::experimental::Crl::~Crl
virtual ~Crl()=default
grpc_core::experimental::CrlProvider
Definition: grpc_crl_provider.h:59
grpc_core::experimental::CrlProvider::GetCrl
virtual std::shared_ptr< Crl > GetCrl(const CertificateInfo &certificate_info)=0
grpc_core::experimental::CreateStaticCrlProvider
absl::StatusOr< std::shared_ptr< CrlProvider > > CreateStaticCrlProvider(absl::Span< const std::string > crls)
grpc_core::experimental::CreateDirectoryReloaderCrlProvider
absl::StatusOr< std::shared_ptr< CrlProvider > > CreateDirectoryReloaderCrlProvider(absl::string_view directory, std::chrono::seconds refresh_duration, std::function< void(absl::Status)> reload_error_callback)
grpc_tls_credentials_options
struct grpc_tls_credentials_options grpc_tls_credentials_options
— TLS channel/server credentials — It is used for experimental purpose for now and subject to change.
Definition: grpc_security.h:714
grpc_core::experimental::CertificateInfo::Issuer
virtual absl::string_view Issuer() const =0
grpc_core::experimental::Crl::Parse
static absl::StatusOr< std::unique_ptr< Crl > > Parse(absl::string_view crl_string)
grpc_core::experimental::Crl::Issuer
virtual absl::string_view Issuer()=0
grpc_core::experimental::CertificateInfo::~CertificateInfo
virtual ~CertificateInfo()=default
grpc::protobuf::util::Status
::absl::Status Status
Definition: config_protobuf.h:97
port_platform.h