grpc 1.59.2 → 1.59.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 759d825c6725ecef82f2e56b725a43704250217a4cbff252302a070bf11e3849
4
- data.tar.gz: 1156877963781d0594e138c6b5d31695230946eb4738647cec37706691912e15
3
+ metadata.gz: a2f9c97b2899a98b0aa10617cf7d44f43c790a94ae5254ed9f5aeb00d981fc5f
4
+ data.tar.gz: 8de2a6a60e16d1f737e2feac45432deca18279de9ec5d53b91a6fad053a40cba
5
5
  SHA512:
6
- metadata.gz: 5f79426b08ab87c3c5d184f083f51ae3cad7433839409223d74ea30ee2f3c2a731a94cae642c616e256154a2f5f585c8904a2c4bb9233c679558ed942fe319fd
7
- data.tar.gz: f00070bbbcd743d96acea7052edae32162a6450465fdeb319bc332a4bd38984fd2a4929e8c903197e748846b88bc6da0bd70e2c4377af722768de7e27a22b89c
6
+ metadata.gz: 9ec764417ad5ce529fae525c381d4d8cc0a201ef3ca7637702a1f2562606bf43ac4e9896a3649b88087c01dea10248f0d6d339a01559248c62ebf75b28fbb83d
7
+ data.tar.gz: 514767e299520918851cb034c80a9765ade6f230488a9c278ffff02cca9e9c9610a459e1d6ce8dafd4f87fbac9696c2efb816defb5c9b31ca784436bef481b16
data/Makefile CHANGED
@@ -411,7 +411,7 @@ Q = @
411
411
  endif
412
412
 
413
413
  CORE_VERSION = 36.0.0
414
- CPP_VERSION = 1.59.2
414
+ CPP_VERSION = 1.59.5
415
415
 
416
416
  CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
417
417
  CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
@@ -1482,11 +1482,13 @@ LIBGRPC_SRC = \
1482
1482
  src/core/lib/experiments/experiments.cc \
1483
1483
  src/core/lib/gprpp/load_file.cc \
1484
1484
  src/core/lib/gprpp/per_cpu.cc \
1485
+ src/core/lib/gprpp/posix/directory_reader.cc \
1485
1486
  src/core/lib/gprpp/ref_counted_string.cc \
1486
1487
  src/core/lib/gprpp/status_helper.cc \
1487
1488
  src/core/lib/gprpp/time.cc \
1488
1489
  src/core/lib/gprpp/time_averaged_stats.cc \
1489
1490
  src/core/lib/gprpp/validation_errors.cc \
1491
+ src/core/lib/gprpp/windows/directory_reader.cc \
1490
1492
  src/core/lib/gprpp/work_serializer.cc \
1491
1493
  src/core/lib/handshaker/proxy_mapper_registry.cc \
1492
1494
  src/core/lib/http/format_request.cc \
@@ -1636,6 +1638,7 @@ LIBGRPC_SRC = \
1636
1638
  src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc \
1637
1639
  src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc \
1638
1640
  src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc \
1641
+ src/core/lib/security/credentials/tls/grpc_tls_crl_provider.cc \
1639
1642
  src/core/lib/security/credentials/tls/tls_credentials.cc \
1640
1643
  src/core/lib/security/credentials/tls/tls_utils.cc \
1641
1644
  src/core/lib/security/credentials/xds/xds_credentials.cc \
@@ -1750,6 +1753,7 @@ PUBLIC_HEADERS_C += \
1750
1753
  include/grpc/fork.h \
1751
1754
  include/grpc/grpc.h \
1752
1755
  include/grpc/grpc_audit_logging.h \
1756
+ include/grpc/grpc_crl_provider.h \
1753
1757
  include/grpc/grpc_posix.h \
1754
1758
  include/grpc/grpc_security.h \
1755
1759
  include/grpc/grpc_security_constants.h \
@@ -2266,6 +2270,7 @@ PUBLIC_HEADERS_C += \
2266
2270
  include/grpc/fork.h \
2267
2271
  include/grpc/grpc.h \
2268
2272
  include/grpc/grpc_audit_logging.h \
2273
+ include/grpc/grpc_crl_provider.h \
2269
2274
  include/grpc/grpc_posix.h \
2270
2275
  include/grpc/grpc_security.h \
2271
2276
  include/grpc/grpc_security_constants.h \
@@ -3656,6 +3661,8 @@ src/core/ext/xds/xds_route_config.cc: $(OPENSSL_DEP)
3656
3661
  src/core/ext/xds/xds_routing.cc: $(OPENSSL_DEP)
3657
3662
  src/core/ext/xds/xds_server_config_fetcher.cc: $(OPENSSL_DEP)
3658
3663
  src/core/ext/xds/xds_transport_grpc.cc: $(OPENSSL_DEP)
3664
+ src/core/lib/gprpp/posix/directory_reader.cc: $(OPENSSL_DEP)
3665
+ src/core/lib/gprpp/windows/directory_reader.cc: $(OPENSSL_DEP)
3659
3666
  src/core/lib/http/httpcli_security_connector.cc: $(OPENSSL_DEP)
3660
3667
  src/core/lib/json/json_util.cc: $(OPENSSL_DEP)
3661
3668
  src/core/lib/matchers/matchers.cc: $(OPENSSL_DEP)
@@ -3685,6 +3692,7 @@ src/core/lib/security/credentials/tls/grpc_tls_certificate_match.cc: $(OPENSSL_D
3685
3692
  src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc: $(OPENSSL_DEP)
3686
3693
  src/core/lib/security/credentials/tls/grpc_tls_certificate_verifier.cc: $(OPENSSL_DEP)
3687
3694
  src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc: $(OPENSSL_DEP)
3695
+ src/core/lib/security/credentials/tls/grpc_tls_crl_provider.cc: $(OPENSSL_DEP)
3688
3696
  src/core/lib/security/credentials/tls/tls_credentials.cc: $(OPENSSL_DEP)
3689
3697
  src/core/lib/security/credentials/xds/xds_credentials.cc: $(OPENSSL_DEP)
3690
3698
  src/core/lib/security/security_connector/alts/alts_security_connector.cc: $(OPENSSL_DEP)
@@ -0,0 +1,94 @@
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
+
22
+ #include <grpc/support/port_platform.h>
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.
46
+ class CertificateInfo {
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
86
+ /**
87
+ * EXPERIMENTAL API - Subject to change
88
+ *
89
+ * Sets the crl provider in the options.
90
+ */
91
+ void grpc_tls_credentials_options_set_crl_provider(
92
+ grpc_tls_credentials_options* options,
93
+ std::shared_ptr<grpc_core::experimental::CrlProvider> provider);
94
+ #endif /* GRPC_GRPC_CRL_PROVIDER_H */
@@ -815,6 +815,24 @@ GRPCAPI void grpc_tls_certificate_provider_release(
815
815
  */
816
816
  GRPCAPI grpc_tls_credentials_options* grpc_tls_credentials_options_create(void);
817
817
 
818
+ /**
819
+ * EXPERIMENTAL API - Subject to change
820
+ *
821
+ * Sets the minimum TLS version that will be negotiated during the TLS
822
+ * handshake. If not set, the underlying SSL library will set it to TLS v1.2.
823
+ */
824
+ GRPCAPI void grpc_tls_credentials_options_set_min_tls_version(
825
+ grpc_tls_credentials_options* options, grpc_tls_version min_tls_version);
826
+
827
+ /**
828
+ * EXPERIMENTAL API - Subject to change
829
+ *
830
+ * Sets the maximum TLS version that will be negotiated during the TLS
831
+ * handshake. If not set, the underlying SSL library will set it to TLS v1.3.
832
+ */
833
+ GRPCAPI void grpc_tls_credentials_options_set_max_tls_version(
834
+ grpc_tls_credentials_options* options, grpc_tls_version max_tls_version);
835
+
818
836
  /**
819
837
  * EXPERIMENTAL API - Subject to change
820
838
  *
@@ -9,6 +9,7 @@ header "byte_buffer.h"
9
9
  header "fork.h"
10
10
  header "grpc.h"
11
11
  header "grpc_audit_logging.h"
12
+ header "grpc_crl_provider.h"
12
13
  header "grpc_posix.h"
13
14
  header "grpc_security.h"
14
15
  header "grpc_security_constants.h"
@@ -91,12 +91,14 @@ constexpr Base64InverseTable kBase64InverseTable;
91
91
  class HPackParser::Input {
92
92
  public:
93
93
  Input(grpc_slice_refcount* current_slice_refcount, const uint8_t* begin,
94
- const uint8_t* end, absl::BitGenRef bitsrc, HpackParseResult& error)
94
+ const uint8_t* end, absl::BitGenRef bitsrc,
95
+ HpackParseResult& frame_error, HpackParseResult& field_error)
95
96
  : current_slice_refcount_(current_slice_refcount),
96
97
  begin_(begin),
97
98
  end_(end),
98
99
  frontier_(begin),
99
- error_(error),
100
+ frame_error_(frame_error),
101
+ field_error_(field_error),
100
102
  bitsrc_(bitsrc) {}
101
103
 
102
104
  // If input is backed by a slice, retrieve its refcount. If not, return
@@ -215,14 +217,18 @@ class HPackParser::Input {
215
217
 
216
218
  // Check if we saw an EOF
217
219
  bool eof_error() const {
218
- return min_progress_size_ != 0 || error_.connection_error();
220
+ return min_progress_size_ != 0 || frame_error_.connection_error();
221
+ }
222
+
223
+ // Reset the field error to be ok
224
+ void ClearFieldError() {
225
+ if (field_error_.ok()) return;
226
+ field_error_ = HpackParseResult();
219
227
  }
220
228
 
221
229
  // Minimum number of bytes to unstuck the current parse
222
230
  size_t min_progress_size() const { return min_progress_size_; }
223
231
 
224
- bool has_error() const { return !error_.ok(); }
225
-
226
232
  // Set the current error - tweaks the error to include a stream id so that
227
233
  // chttp2 does not close the connection.
228
234
  // Intended for errors that are specific to a stream and recoverable.
@@ -246,10 +252,7 @@ class HPackParser::Input {
246
252
  // read prior to being able to get further in this parse.
247
253
  void UnexpectedEOF(size_t min_progress_size) {
248
254
  GPR_ASSERT(min_progress_size > 0);
249
- if (min_progress_size_ != 0 || error_.connection_error()) {
250
- GPR_DEBUG_ASSERT(eof_error());
251
- return;
252
- }
255
+ if (eof_error()) return;
253
256
  // Set min progress size, taking into account bytes parsed already but not
254
257
  // consumed.
255
258
  min_progress_size_ = min_progress_size + (begin_ - frontier_);
@@ -302,13 +305,18 @@ class HPackParser::Input {
302
305
  // Do not use this directly, instead use SetErrorAndContinueParsing or
303
306
  // SetErrorAndStopParsing.
304
307
  void SetError(HpackParseResult error) {
305
- if (!error_.ok() || min_progress_size_ > 0) {
306
- if (error.connection_error() && !error_.connection_error()) {
307
- error_ = std::move(error); // connection errors dominate
308
+ SetErrorFor(frame_error_, error);
309
+ SetErrorFor(field_error_, std::move(error));
310
+ }
311
+
312
+ void SetErrorFor(HpackParseResult& error, HpackParseResult new_error) {
313
+ if (!error.ok() || min_progress_size_ > 0) {
314
+ if (new_error.connection_error() && !error.connection_error()) {
315
+ error = std::move(new_error); // connection errors dominate
308
316
  }
309
317
  return;
310
318
  }
311
- error_ = std::move(error);
319
+ error = std::move(new_error);
312
320
  }
313
321
 
314
322
  // Refcount if we are backed by a slice
@@ -320,7 +328,8 @@ class HPackParser::Input {
320
328
  // Frontier denotes the first byte past successfully processed input
321
329
  const uint8_t* frontier_;
322
330
  // Current error
323
- HpackParseResult& error_;
331
+ HpackParseResult& frame_error_;
332
+ HpackParseResult& field_error_;
324
333
  // If the error was EOF, we flag it here by noting how many more bytes would
325
334
  // be needed to make progress
326
335
  size_t min_progress_size_ = 0;
@@ -597,6 +606,7 @@ class HPackParser::Parser {
597
606
  bool ParseTop() {
598
607
  GPR_DEBUG_ASSERT(state_.parse_state == ParseState::kTop);
599
608
  auto cur = *input_->Next();
609
+ input_->ClearFieldError();
600
610
  switch (cur >> 4) {
601
611
  // Literal header not indexed - First byte format: 0000xxxx
602
612
  // Literal header never indexed - First byte format: 0001xxxx
@@ -702,7 +712,7 @@ class HPackParser::Parser {
702
712
  break;
703
713
  }
704
714
  gpr_log(
705
- GPR_DEBUG, "HTTP:%d:%s:%s: %s%s", log_info_.stream_id, type,
715
+ GPR_INFO, "HTTP:%d:%s:%s: %s%s", log_info_.stream_id, type,
706
716
  log_info_.is_client ? "CLI" : "SVR", memento.md.DebugString().c_str(),
707
717
  memento.parse_status == nullptr
708
718
  ? ""
@@ -951,11 +961,10 @@ class HPackParser::Parser {
951
961
  state_.string_length)
952
962
  : String::Parse(input_, state_.is_string_huff_compressed,
953
963
  state_.string_length);
954
- HpackParseResult& status = state_.frame_error;
955
964
  absl::string_view key_string;
956
965
  if (auto* s = absl::get_if<Slice>(&state_.key)) {
957
966
  key_string = s->as_string_view();
958
- if (status.ok()) {
967
+ if (state_.field_error.ok()) {
959
968
  auto r = ValidateKey(key_string);
960
969
  if (r != ValidateMetadataResult::kOk) {
961
970
  input_->SetErrorAndContinueParsing(
@@ -965,7 +974,7 @@ class HPackParser::Parser {
965
974
  } else {
966
975
  const auto* memento = absl::get<const HPackTable::Memento*>(state_.key);
967
976
  key_string = memento->md.key();
968
- if (status.ok() && memento->parse_status != nullptr) {
977
+ if (state_.field_error.ok() && memento->parse_status != nullptr) {
969
978
  input_->SetErrorAndContinueParsing(*memento->parse_status);
970
979
  }
971
980
  }
@@ -992,16 +1001,16 @@ class HPackParser::Parser {
992
1001
  key_string.size() + value.wire_size + hpack_constants::kEntryOverhead;
993
1002
  auto md = grpc_metadata_batch::Parse(
994
1003
  key_string, std::move(value_slice), state_.add_to_table, transport_size,
995
- [key_string, &status, this](absl::string_view message, const Slice&) {
996
- if (!status.ok()) return;
1004
+ [key_string, this](absl::string_view message, const Slice&) {
1005
+ if (!state_.field_error.ok()) return;
997
1006
  input_->SetErrorAndContinueParsing(
998
1007
  HpackParseResult::MetadataParseError(key_string));
999
1008
  gpr_log(GPR_ERROR, "Error parsing '%s' metadata: %s",
1000
1009
  std::string(key_string).c_str(),
1001
1010
  std::string(message).c_str());
1002
1011
  });
1003
- HPackTable::Memento memento{std::move(md),
1004
- status.PersistentStreamErrorOrNullptr()};
1012
+ HPackTable::Memento memento{
1013
+ std::move(md), state_.field_error.PersistentStreamErrorOrNullptr()};
1005
1014
  input_->UpdateFrontier();
1006
1015
  state_.parse_state = ParseState::kTop;
1007
1016
  if (state_.add_to_table) {
@@ -1163,13 +1172,13 @@ grpc_error_handle HPackParser::Parse(
1163
1172
  std::vector<uint8_t> buffer = std::move(unparsed_bytes_);
1164
1173
  return ParseInput(
1165
1174
  Input(nullptr, buffer.data(), buffer.data() + buffer.size(), bitsrc,
1166
- state_.frame_error),
1175
+ state_.frame_error, state_.field_error),
1167
1176
  is_last, call_tracer);
1168
1177
  }
1169
- return ParseInput(
1170
- Input(slice.refcount, GRPC_SLICE_START_PTR(slice),
1171
- GRPC_SLICE_END_PTR(slice), bitsrc, state_.frame_error),
1172
- is_last, call_tracer);
1178
+ return ParseInput(Input(slice.refcount, GRPC_SLICE_START_PTR(slice),
1179
+ GRPC_SLICE_END_PTR(slice), bitsrc, state_.frame_error,
1180
+ state_.field_error),
1181
+ is_last, call_tracer);
1173
1182
  }
1174
1183
 
1175
1184
  grpc_error_handle HPackParser::ParseInput(
@@ -236,6 +236,8 @@ class HPackParser {
236
236
  HPackTable hpack_table;
237
237
  // Error so far for this frame (set by class Input)
238
238
  HpackParseResult frame_error;
239
+ // Error so far for this field (set by class Input)
240
+ HpackParseResult field_error;
239
241
  // Length of frame so far.
240
242
  uint32_t frame_length = 0;
241
243
  // Length of the string being parsed
@@ -68,7 +68,8 @@ Chttp2PingRatePolicy::RequestSendPing(Duration next_allowed_ping_interval,
68
68
  if (max_pings_without_data_ != 0 && pings_before_data_required_ == 0) {
69
69
  return TooManyRecentPings{};
70
70
  }
71
- if (max_inflight_pings_ != 0 && inflight_pings > max_inflight_pings_) {
71
+ if (max_inflight_pings_ != 0 &&
72
+ inflight_pings > static_cast<size_t>(max_inflight_pings_)) {
72
73
  return TooManyRecentPings{};
73
74
  }
74
75
  const Timestamp next_allowed_ping =
@@ -0,0 +1,48 @@
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_SRC_CORE_LIB_GPRPP_DIRECTORY_READER_H
20
+ #define GRPC_SRC_CORE_LIB_GPRPP_DIRECTORY_READER_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include <memory>
25
+
26
+ #include "absl/functional/function_ref.h"
27
+ #include "absl/status/status.h"
28
+ #include "absl/strings/string_view.h"
29
+
30
+ namespace grpc_core {
31
+
32
+ class DirectoryReader {
33
+ public:
34
+ virtual ~DirectoryReader() = default;
35
+ // Returns the name of the directory being read.
36
+ virtual absl::string_view Name() const = 0;
37
+ // Calls callback for each name in the directory except for "." and "..".
38
+ // Returns non-OK if there was an error reading the directory.
39
+ virtual absl::Status ForEach(
40
+ absl::FunctionRef<void(absl::string_view)> callback) = 0;
41
+ };
42
+
43
+ std::unique_ptr<DirectoryReader> MakeDirectoryReader(
44
+ absl::string_view filename);
45
+
46
+ } // namespace grpc_core
47
+
48
+ #endif // GRPC_SRC_CORE_LIB_GPRPP_DIRECTORY_READER_H
@@ -0,0 +1,82 @@
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
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include <memory>
22
+
23
+ #include "absl/functional/function_ref.h"
24
+ #include "absl/status/status.h"
25
+ #include "absl/strings/string_view.h"
26
+
27
+ #if defined(GPR_LINUX) || defined(GPR_ANDROID) || defined(GPR_FREEBSD) || \
28
+ defined(GPR_APPLE)
29
+
30
+ #include <dirent.h>
31
+
32
+ #include <string>
33
+
34
+ #include "src/core/lib/gprpp/directory_reader.h"
35
+
36
+ namespace grpc_core {
37
+
38
+ namespace {
39
+ const char kSkipEntriesSelf[] = ".";
40
+ const char kSkipEntriesParent[] = "..";
41
+ } // namespace
42
+
43
+ class DirectoryReaderImpl : public DirectoryReader {
44
+ public:
45
+ explicit DirectoryReaderImpl(absl::string_view directory_path)
46
+ : directory_path_(directory_path) {}
47
+ absl::string_view Name() const override { return directory_path_; }
48
+ absl::Status ForEach(absl::FunctionRef<void(absl::string_view)>) override;
49
+
50
+ private:
51
+ const std::string directory_path_;
52
+ };
53
+
54
+ std::unique_ptr<DirectoryReader> MakeDirectoryReader(
55
+ absl::string_view filename) {
56
+ return std::make_unique<DirectoryReaderImpl>(filename);
57
+ }
58
+
59
+ absl::Status DirectoryReaderImpl::ForEach(
60
+ absl::FunctionRef<void(absl::string_view)> callback) {
61
+ // Open the dir for reading
62
+ DIR* directory = opendir(directory_path_.c_str());
63
+ if (directory == nullptr) {
64
+ return absl::InternalError("Could not read crl directory.");
65
+ }
66
+ struct dirent* directory_entry;
67
+ // Iterate over everything in the directory
68
+ while ((directory_entry = readdir(directory)) != nullptr) {
69
+ const absl::string_view file_name = directory_entry->d_name;
70
+ // Skip "." and ".."
71
+ if (file_name == kSkipEntriesParent || file_name == kSkipEntriesSelf) {
72
+ continue;
73
+ }
74
+ // Call the callback with this filename
75
+ callback(file_name);
76
+ }
77
+ closedir(directory);
78
+ return absl::OkStatus();
79
+ }
80
+ } // namespace grpc_core
81
+
82
+ #endif // GPR_LINUX || GPR_ANDROID || GPR_FREEBSD || GPR_APPLE
@@ -0,0 +1,80 @@
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
+ #include <grpc/support/port_platform.h>
20
+
21
+ #if defined(GPR_WINDOWS)
22
+
23
+ #include <sys/stat.h>
24
+ #include <windows.h>
25
+
26
+ #include <string>
27
+ #include <vector>
28
+
29
+ #include "absl/status/statusor.h"
30
+ #include "absl/strings/string_view.h"
31
+
32
+ #include <grpc/support/log.h>
33
+
34
+ #include "src/core/lib/gprpp/directory_reader.h"
35
+ namespace grpc_core {
36
+
37
+ namespace {
38
+ const char kSkipEntriesSelf[] = ".";
39
+ const char kSkipEntriesParent[] = "..";
40
+ } // namespace
41
+
42
+ class DirectoryReaderImpl : public DirectoryReader {
43
+ public:
44
+ explicit DirectoryReaderImpl(absl::string_view directory_path)
45
+ : directory_path_(directory_path) {}
46
+ absl::string_view Name() const override { return directory_path_; }
47
+ absl::Status ForEach(absl::FunctionRef<void(absl::string_view)>) override;
48
+
49
+ private:
50
+ const std::string directory_path_;
51
+ };
52
+
53
+ std::unique_ptr<DirectoryReader> MakeDirectoryReader(
54
+ absl::string_view filename) {
55
+ return std::make_unique<DirectoryReaderImpl>(filename);
56
+ }
57
+
58
+ // Reference for reading directory in Windows:
59
+ // https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c
60
+ // https://learn.microsoft.com/en-us/windows/win32/fileio/listing-the-files-in-a-directory
61
+ absl::Status DirectoryReaderImpl::ForEach(
62
+ absl::FunctionRef<void(absl::string_view)> callback) {
63
+ std::string search_path = absl::StrCat(directory_path_, "/*");
64
+ WIN32_FIND_DATAA find_data;
65
+ HANDLE hFind = ::FindFirstFileA(search_path.c_str(), &find_data);
66
+ if (hFind == INVALID_HANDLE_VALUE) {
67
+ return absl::InternalError("Could not read crl directory.");
68
+ }
69
+ do {
70
+ if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
71
+ callback(find_data.cFileName);
72
+ }
73
+ } while (::FindNextFileA(hFind, &find_data));
74
+ ::FindClose(hFind);
75
+ return absl::OkStatus();
76
+ }
77
+
78
+ } // namespace grpc_core
79
+
80
+ #endif // GPR_WINDOWS
@@ -20,6 +20,9 @@
20
20
 
21
21
  #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h"
22
22
 
23
+ #include <memory>
24
+
25
+ #include <grpc/grpc_crl_provider.h>
23
26
  #include <grpc/support/log.h>
24
27
 
25
28
  #include "src/core/lib/debug/trace.h"
@@ -128,3 +131,22 @@ void grpc_tls_credentials_options_set_send_client_ca_list(
128
131
  }
129
132
  options->set_send_client_ca_list(send_client_ca_list);
130
133
  }
134
+
135
+ void grpc_tls_credentials_options_set_crl_provider(
136
+ grpc_tls_credentials_options* options,
137
+ std::shared_ptr<grpc_core::experimental::CrlProvider> provider) {
138
+ GPR_ASSERT(options != nullptr);
139
+ options->set_crl_provider(std::move(provider));
140
+ }
141
+
142
+ void grpc_tls_credentials_options_set_min_tls_version(
143
+ grpc_tls_credentials_options* options, grpc_tls_version min_tls_version) {
144
+ GPR_ASSERT(options != nullptr);
145
+ options->set_min_tls_version(min_tls_version);
146
+ }
147
+
148
+ void grpc_tls_credentials_options_set_max_tls_version(
149
+ grpc_tls_credentials_options* options, grpc_tls_version max_tls_version) {
150
+ GPR_ASSERT(options != nullptr);
151
+ options->set_max_tls_version(max_tls_version);
152
+ }
@@ -61,6 +61,8 @@ struct grpc_tls_credentials_options
61
61
  const std::string& identity_cert_name() const { return identity_cert_name_; }
62
62
  const std::string& tls_session_key_log_file_path() const { return tls_session_key_log_file_path_; }
63
63
  const std::string& crl_directory() const { return crl_directory_; }
64
+ // Returns the CRL Provider
65
+ std::shared_ptr<grpc_core::experimental::CrlProvider> crl_provider() const { return crl_provider_; }
64
66
  bool send_client_ca_list() const { return send_client_ca_list_; }
65
67
 
66
68
  // Setters for member fields.
@@ -82,6 +84,7 @@ struct grpc_tls_credentials_options
82
84
  void set_tls_session_key_log_file_path(std::string tls_session_key_log_file_path) { tls_session_key_log_file_path_ = std::move(tls_session_key_log_file_path); }
83
85
  // gRPC will enforce CRLs on all handshakes from all hashed CRL files inside of the crl_directory. If not set, an empty string will be used, which will not enable CRL checking. Only supported for OpenSSL version > 1.1.
84
86
  void set_crl_directory(std::string crl_directory) { crl_directory_ = std::move(crl_directory); }
87
+ void set_crl_provider(std::shared_ptr<grpc_core::experimental::CrlProvider> crl_provider) { crl_provider_ = std::move(crl_provider); }
85
88
  void set_send_client_ca_list(bool send_client_ca_list) { send_client_ca_list_ = send_client_ca_list; }
86
89
 
87
90
  bool operator==(const grpc_tls_credentials_options& other) const {
@@ -98,6 +101,7 @@ struct grpc_tls_credentials_options
98
101
  identity_cert_name_ == other.identity_cert_name_ &&
99
102
  tls_session_key_log_file_path_ == other.tls_session_key_log_file_path_ &&
100
103
  crl_directory_ == other.crl_directory_ &&
104
+ (crl_provider_ == other.crl_provider_) &&
101
105
  send_client_ca_list_ == other.send_client_ca_list_;
102
106
  }
103
107
 
@@ -115,6 +119,7 @@ struct grpc_tls_credentials_options
115
119
  std::string identity_cert_name_;
116
120
  std::string tls_session_key_log_file_path_;
117
121
  std::string crl_directory_;
122
+ std::shared_ptr<grpc_core::experimental::CrlProvider> crl_provider_;
118
123
  bool send_client_ca_list_ = false;
119
124
  };
120
125