alts_credentials_fuzzer.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 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 <string.h>
20 
21 #include <grpc/grpc.h>
22 #include <grpc/grpc_security.h>
23 #include <grpc/support/alloc.h>
24 #include <grpc/support/log.h>
26 
27 #include "src/core/lib/gpr/env.h"
32 
36 
37 // Logging
38 bool squelch = true;
39 bool leak_check = true;
40 
41 static void dont_log(gpr_log_func_args* /*args*/) {}
42 
43 // Add a random number of target service accounts to client options.
47  for (size_t i = 0; i < n; i++) {
48  char* service_account = grpc_fuzzer_get_next_string(inp, nullptr);
49  if (service_account != nullptr) {
51  options, service_account);
52  gpr_free(service_account);
53  }
54  }
55  // Added to improve code coverage.
57  nullptr);
59  nullptr, "this is service account");
60 }
61 
62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
63  char* grpc_trace_fuzzer = gpr_getenv("GRPC_TRACE_FUZZER");
64  if (squelch && grpc_trace_fuzzer == nullptr) {
66  }
67  gpr_free(grpc_trace_fuzzer);
68  input_stream inp = {data, data + size};
69  grpc_init();
70  bool is_on_gcp = grpc_alts_is_running_on_gcp();
71  while (inp.cur != inp.end) {
72  bool enable_untrusted_alts = grpc_fuzzer_get_next_byte(&inp) & 0x01;
73  char* handshaker_service_url =
75  ? grpc_fuzzer_get_next_string(&inp, nullptr)
76  : nullptr;
77  if (grpc_fuzzer_get_next_byte(&inp) & 0x01) {
78  // Test ALTS channel credentials.
83  options, handshaker_service_url, enable_untrusted_alts);
84  if (!enable_untrusted_alts && !is_on_gcp) {
85  GPR_ASSERT(cred == nullptr);
86  } else {
87  GPR_ASSERT(cred != nullptr);
88  }
91  } else {
92  // Test ALTS server credentials.
97  options, handshaker_service_url, enable_untrusted_alts);
98  if (!enable_untrusted_alts && !is_on_gcp) {
99  GPR_ASSERT(cred == nullptr);
100  } else {
101  GPR_ASSERT(cred != nullptr);
102  }
105  }
106  gpr_free(handshaker_service_url);
107  }
108  grpc_shutdown();
109  return 0;
110 }
grpc_alts_credentials_options_destroy
GRPCAPI void grpc_alts_credentials_options_destroy(grpc_alts_credentials_options *options)
Definition: grpc_alts_credentials_options.cc:38
log.h
grpc_core::testing::grpc_fuzzer_get_next_string
char * grpc_fuzzer_get_next_string(input_stream *inp, bool *special)
Definition: fuzzer_util.cc:37
fuzzer_util.h
regen-readme.inp
inp
Definition: regen-readme.py:11
grpc_alts_credentials_create_customized
grpc_channel_credentials * grpc_alts_credentials_create_customized(const grpc_alts_credentials_options *options, const char *handshaker_service_url, bool enable_untrusted_alts)
Definition: alts_credentials.cc:92
string.h
options
double_dict options[]
Definition: capstone_test.c:55
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
grpc_alts_is_running_on_gcp
bool grpc_alts_is_running_on_gcp()
Definition: check_gcp_environment_no_op.cc:27
check_gcp_environment.h
env.h
grpc_security.h
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
gpr_log_func_args
Definition: include/grpc/impl/codegen/log.h:77
leak_check
bool leak_check
Definition: alts_credentials_fuzzer.cc:39
string_util.h
grpc_alts_credentials_client_options_create
GRPCAPI grpc_alts_credentials_options * grpc_alts_credentials_client_options_create(void)
Definition: grpc_alts_credentials_client_options.cc:73
read_target_service_accounts
static void read_target_service_accounts(input_stream *inp, grpc_alts_credentials_options *options)
Definition: alts_credentials_fuzzer.cc:44
gpr_getenv
char * gpr_getenv(const char *name)
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_server_credentials_release
GRPCAPI void grpc_server_credentials_release(grpc_server_credentials *creds)
Definition: credentials.cc:95
grpc_alts_credentials_client_options_add_target_service_account
GRPCAPI void grpc_alts_credentials_client_options_add_target_service_account(grpc_alts_credentials_options *options, const char *service_account)
Definition: grpc_alts_credentials_client_options.cc:45
grpc.h
grpc_alts_credentials_options.h
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
grpc_core::testing::input_stream
Definition: fuzzer_util.h:31
grpc_core::testing::grpc_fuzzer_get_next_byte
uint8_t grpc_fuzzer_get_next_byte(input_stream *inp)
Definition: fuzzer_util.cc:30
dont_log
static void dont_log(gpr_log_func_args *)
Definition: alts_credentials_fuzzer.cc:41
grpc_channel_credentials_release
GRPCAPI void grpc_channel_credentials_release(grpc_channel_credentials *creds)
Definition: credentials.cc:36
grpc_server_credentials
Definition: src/core/lib/security/credentials/credentials.h:259
alts_credentials.h
grpc_alts_credentials_options
Definition: grpc_alts_credentials_options.h:35
grpc_alts_credentials_server_options_create
GRPCAPI grpc_alts_credentials_options * grpc_alts_credentials_server_options_create(void)
Definition: grpc_alts_credentials_server_options.cc:36
squelch
bool squelch
Definition: alts_credentials_fuzzer.cc:38
alloc.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: alts_credentials_fuzzer.cc:62
grpc_alts_server_credentials_create_customized
grpc_server_credentials * grpc_alts_server_credentials_create_customized(const grpc_alts_credentials_options *options, const char *handshaker_service_url, bool enable_untrusted_alts)
Definition: alts_credentials.cc:101
gpr_set_log_function
GPRAPI void gpr_set_log_function(gpr_log_func func)
Definition: log.cc:143
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
grpc_channel_credentials
Definition: src/core/lib/security/credentials/credentials.h:96
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:40