• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #include <grpcpp/security/credentials.h>
25 #include <grpcpp/support/config.h>
26 
27 #include "src/cpp/server/thread_pool_interface.h"
28 
29 namespace grpc {
30 
31 class SecureChannelCredentials final : public ChannelCredentials {
32  public:
33   explicit SecureChannelCredentials(grpc_channel_credentials* c_creds);
~SecureChannelCredentials()34   ~SecureChannelCredentials() { grpc_channel_credentials_release(c_creds_); }
GetRawCreds()35   grpc_channel_credentials* GetRawCreds() { return c_creds_; }
36 
37   std::shared_ptr<grpc::Channel> CreateChannel(
38       const string& target, const grpc::ChannelArguments& args) override;
AsSecureCredentials()39   SecureChannelCredentials* AsSecureCredentials() override { return this; }
40 
41  private:
42   grpc_channel_credentials* const c_creds_;
43 };
44 
45 class SecureCallCredentials final : public CallCredentials {
46  public:
47   explicit SecureCallCredentials(grpc_call_credentials* c_creds);
~SecureCallCredentials()48   ~SecureCallCredentials() { grpc_call_credentials_release(c_creds_); }
GetRawCreds()49   grpc_call_credentials* GetRawCreds() { return c_creds_; }
50 
51   bool ApplyToCall(grpc_call* call) override;
AsSecureCredentials()52   SecureCallCredentials* AsSecureCredentials() override { return this; }
53 
54  private:
55   grpc_call_credentials* const c_creds_;
56 };
57 
58 class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen {
59  public:
60   static void Destroy(void* wrapper);
61   static int GetMetadata(
62       void* wrapper, grpc_auth_metadata_context context,
63       grpc_credentials_plugin_metadata_cb cb, void* user_data,
64       grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
65       size_t* num_creds_md, grpc_status_code* status,
66       const char** error_details);
67 
68   explicit MetadataCredentialsPluginWrapper(
69       std::unique_ptr<MetadataCredentialsPlugin> plugin);
70 
71  private:
72   void InvokePlugin(
73       grpc_auth_metadata_context context,
74       grpc_credentials_plugin_metadata_cb cb, void* user_data,
75       grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
76       size_t* num_creds_md, grpc_status_code* status_code,
77       const char** error_details);
78   std::unique_ptr<ThreadPoolInterface> thread_pool_;
79   std::unique_ptr<MetadataCredentialsPlugin> plugin_;
80 };
81 
82 }  // namespace grpc
83 
84 #endif  // GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
85