GRPC C++  1.26.0
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 
27 #include <grpcpp/support/config.h>
28 
29 #include "src/core/lib/security/credentials/credentials.h"
31 
32 namespace grpc_impl {
33 
34 class Channel;
35 
37  public:
38  explicit SecureChannelCredentials(grpc_channel_credentials* c_creds);
40  if (c_creds_ != nullptr) c_creds_->Unref();
41  }
42  grpc_channel_credentials* GetRawCreds() { return c_creds_; }
43 
44  std::shared_ptr<Channel> CreateChannelImpl(
45  const grpc::string& target, const ChannelArguments& args) override;
46 
47  SecureChannelCredentials* AsSecureCredentials() override { return this; }
48 
49  private:
50  std::shared_ptr<Channel> CreateChannelWithInterceptors(
51  const grpc::string& target, const ChannelArguments& args,
52  std::vector<std::unique_ptr<
54  interceptor_creators) override;
55  grpc_channel_credentials* const c_creds_;
56 };
57 
58 class SecureCallCredentials final : public CallCredentials {
59  public:
60  explicit SecureCallCredentials(grpc_call_credentials* c_creds);
62  if (c_creds_ != nullptr) c_creds_->Unref();
63  }
64  grpc_call_credentials* GetRawCreds() { return c_creds_; }
65 
66  bool ApplyToCall(grpc_call* call) override;
67  SecureCallCredentials* AsSecureCredentials() override { return this; }
68 
69  private:
70  grpc_call_credentials* const c_creds_;
71 };
72 
73 namespace experimental {
74 
75 // Transforms C++ STS Credentials options to core options. The pointers of the
76 // resulting core options point to the memory held by the C++ options so C++
77 // options need to be kept alive until after the core credentials creation.
78 grpc_sts_credentials_options StsCredentialsCppToCoreOptions(
79  const StsCredentialsOptions& options);
80 
81 } // namespace experimental
82 
83 } // namespace grpc_impl
84 
85 namespace grpc {
86 
88  public:
89  static void Destroy(void* wrapper);
90  static int GetMetadata(
91  void* wrapper, grpc_auth_metadata_context context,
92  grpc_credentials_plugin_metadata_cb cb, void* user_data,
93  grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
94  size_t* num_creds_md, grpc_status_code* status,
95  const char** error_details);
96 
98  std::unique_ptr<MetadataCredentialsPlugin> plugin);
99 
100  private:
101  void InvokePlugin(
102  grpc_auth_metadata_context context,
103  grpc_credentials_plugin_metadata_cb cb, void* user_data,
104  grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
105  size_t* num_creds_md, grpc_status_code* status_code,
106  const char** error_details);
107  std::unique_ptr<ThreadPoolInterface> thread_pool_;
108  std::unique_ptr<MetadataCredentialsPlugin> plugin_;
109 };
110 
111 } // namespace grpc
112 
113 #endif // GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
Definition: secure_credentials.h:87
static void Destroy(void *wrapper)
Definition: secure_credentials.cc:392
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:400
MetadataCredentialsPluginWrapper(std::unique_ptr< MetadataCredentialsPlugin > plugin)
Definition: secure_credentials.cc:495
A call credentials object encapsulates the state needed by a client to authenticate with a server for...
Definition: credentials_impl.h:111
Options for channel creation.
Definition: channel_arguments_impl.h:43
A channel credentials object encapsulates all the state needed by a client to authenticate with a ser...
Definition: credentials_impl.h:66
Definition: secure_credentials.h:58
~SecureCallCredentials()
Definition: secure_credentials.h:61
SecureCallCredentials * AsSecureCredentials() override
Definition: secure_credentials.h:67
grpc_call_credentials * GetRawCreds()
Definition: secure_credentials.h:64
SecureCallCredentials(grpc_call_credentials *c_creds)
Definition: secure_credentials.cc:72
bool ApplyToCall(grpc_call *call) override
Apply this instance's credentials to call.
Definition: secure_credentials.cc:77
Definition: secure_credentials.h:36
~SecureChannelCredentials()
Definition: secure_credentials.h:39
SecureChannelCredentials(grpc_channel_credentials *c_creds)
Definition: secure_credentials.cc:43
std::shared_ptr< Channel > CreateChannelImpl(const grpc::string &target, const ChannelArguments &args) override
Definition: secure_credentials.cc:49
SecureChannelCredentials * AsSecureCredentials() override
Definition: secure_credentials.h:47
grpc_channel_credentials * GetRawCreds()
Definition: secure_credentials.h:42
grpc_status_code
Definition: status.h:26
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
::grpc_impl::experimental::StsCredentialsOptions StsCredentialsOptions
Definition: credentials.h:104
grpc_sts_credentials_options StsCredentialsCppToCoreOptions(const StsCredentialsOptions &options)
Definition: secure_credentials.cc:236
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
::grpc_impl::Channel Channel
Definition: channel.h:26
std::string string
Definition: config.h:35
A single metadata element.
Definition: grpc_types.h:485