GRPC C++  1.39.1
secure_credentials.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 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_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
20 #define GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
21 
22 #include <grpc/grpc_security.h>
23 
26 #include <grpcpp/support/config.h>
27 
28 #include "absl/strings/str_cat.h"
29 // TODO(yashykt): We shouldn't be including "src/core" headers.
32 
33 namespace grpc {
34 
35 class Channel;
36 
38  public:
41  if (c_creds_ != nullptr) c_creds_->Unref();
42  }
43  grpc_channel_credentials* GetRawCreds() { return c_creds_; }
44 
45  std::shared_ptr<Channel> CreateChannelImpl(
46  const std::string& target, const ChannelArguments& args) override;
47 
48  SecureChannelCredentials* AsSecureCredentials() override { return this; }
49 
50  private:
51  std::shared_ptr<Channel> CreateChannelWithInterceptors(
52  const std::string& target, const ChannelArguments& args,
53  std::vector<std::unique_ptr<
55  interceptor_creators) override;
56  grpc_channel_credentials* const c_creds_;
57 };
58 
59 class SecureCallCredentials final : public CallCredentials {
60  public:
63  if (c_creds_ != nullptr) c_creds_->Unref();
64  }
65  grpc_call_credentials* GetRawCreds() { return c_creds_; }
66 
67  bool ApplyToCall(grpc_call* call) override;
68  SecureCallCredentials* AsSecureCredentials() override { return this; }
69  std::string DebugString() override {
70  return absl::StrCat("SecureCallCredentials{",
71  std::string(c_creds_->debug_string()), "}");
72  }
73 
74  private:
75  grpc_call_credentials* const c_creds_;
76 };
77 
78 namespace internal {
79 
80 std::shared_ptr<ChannelCredentials> WrapChannelCredentials(
82 
83 } // namespace internal
84 
85 namespace experimental {
86 
87 // Transforms C++ STS Credentials options to core options. The pointers of the
88 // resulting core options point to the memory held by the C++ options so C++
89 // options need to be kept alive until after the core credentials creation.
91  const StsCredentialsOptions& options);
92 
93 } // namespace experimental
94 
96  public:
97  static void Destroy(void* wrapper);
98  static int GetMetadata(
99  void* wrapper, grpc_auth_metadata_context context,
100  grpc_credentials_plugin_metadata_cb cb, void* user_data,
102  size_t* num_creds_md, grpc_status_code* status,
103  const char** error_details);
104  static char* DebugString(void* wrapper);
105 
107  std::unique_ptr<MetadataCredentialsPlugin> plugin);
108 
109  private:
110  void InvokePlugin(
112  grpc_credentials_plugin_metadata_cb cb, void* user_data,
114  size_t* num_creds_md, grpc_status_code* status_code,
115  const char** error_details);
116  std::unique_ptr<ThreadPoolInterface> thread_pool_;
117  std::unique_ptr<MetadataCredentialsPlugin> plugin_;
118 };
119 
120 } // namespace grpc
121 
122 #endif // GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
A call credentials object encapsulates the state needed by a client to authenticate with a server for...
Definition: credentials.h:126
Options for channel creation.
Definition: channel_arguments.h:39
A channel credentials object encapsulates all the state needed by a client to authenticate with a ser...
Definition: credentials.h:69
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
Definition: secure_credentials.h:95
static void Destroy(void *wrapper)
Definition: secure_credentials.cc:423
static int GetMetadata(void *wrapper, grpc_auth_metadata_context context, grpc_credentials_plugin_metadata_cb cb, void *user_data, grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX], size_t *num_creds_md, grpc_status_code *status, const char **error_details)
Definition: secure_credentials.cc:431
static char * DebugString(void *wrapper)
Definition: secure_credentials.cc:416
MetadataCredentialsPluginWrapper(std::unique_ptr< MetadataCredentialsPlugin > plugin)
Definition: secure_credentials.cc:526
Definition: secure_credentials.h:59
bool ApplyToCall(grpc_call *call) override
Apply this instance's credentials to call.
Definition: secure_credentials.cc:81
grpc_call_credentials * GetRawCreds()
Definition: secure_credentials.h:65
SecureCallCredentials * AsSecureCredentials() override
Definition: secure_credentials.h:68
std::string DebugString() override
Definition: secure_credentials.h:69
SecureCallCredentials(grpc_call_credentials *c_creds)
Definition: secure_credentials.cc:76
~SecureCallCredentials() override
Definition: secure_credentials.h:62
Definition: secure_credentials.h:37
~SecureChannelCredentials() override
Definition: secure_credentials.h:40
grpc_channel_credentials * GetRawCreds()
Definition: secure_credentials.h:43
SecureChannelCredentials * AsSecureCredentials() override
Definition: secure_credentials.h:48
std::shared_ptr< Channel > CreateChannelImpl(const std::string &target, const ChannelArguments &args) override
Definition: secure_credentials.cc:53
SecureChannelCredentials(grpc_channel_credentials *c_creds)
Definition: secure_credentials.cc:47
void Unref()
Definition: ref_counted.h:302
grpc_status_code
Definition: status.h:26
void(* grpc_credentials_plugin_metadata_cb)(void *user_data, const grpc_metadata *creds_md, size_t num_creds_md, grpc_status_code status, const char *error_details)
Callback function to be called by the metadata credentials plugin implementation when the metadata is...
Definition: grpc_security.h:396
#define GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX
Maximum number of metadata entries returnable by a credentials plugin via a synchronous return.
Definition: grpc_security.h:428
grpc_sts_credentials_options StsCredentialsCppToCoreOptions(const StsCredentialsOptions &options)
Definition: secure_credentials.cc:245
std::shared_ptr< ChannelCredentials > WrapChannelCredentials(grpc_channel_credentials *creds)
Definition: secure_credentials.cc:87
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
Context that can be used by metadata credentials plugin in order to create auth related metadata.
Definition: grpc_security.h:402
Definition: credentials.h:173
virtual std::string debug_string()
Definition: credentials.h:202
Definition: call.cc:139
Definition: credentials.h:102
A single metadata element.
Definition: grpc_types.h:519
Options for creating STS Oauth Token Exchange credentials following the IETF draft https://tools....
Definition: grpc_security.h:366