3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
20 #define GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
22 #include <grpc/grpc_security.h>
24 #include <grpcpp/security/credentials.h>
25 #include <grpcpp/security/tls_credentials_options.h>
26 #include <grpcpp/support/config.h>
28 #include "absl/strings/str_cat.h"
29 // TODO(yashykt): We shouldn't be including "src/core" headers.
30 #include "src/core/lib/security/credentials/credentials.h"
31 #include "src/cpp/server/thread_pool_interface.h"
37 class SecureChannelCredentials final : public ChannelCredentials {
39 explicit SecureChannelCredentials(grpc_channel_credentials* c_creds);
40 ~SecureChannelCredentials() override {
41 if (c_creds_ != nullptr) c_creds_->Unref();
43 grpc_channel_credentials* GetRawCreds() { return c_creds_; }
45 std::shared_ptr<Channel> CreateChannelImpl(
46 const std::string& target, const ChannelArguments& args) override;
48 SecureChannelCredentials* AsSecureCredentials() override { return this; }
51 std::shared_ptr<Channel> CreateChannelWithInterceptors(
52 const std::string& target, const ChannelArguments& args,
53 std::vector<std::unique_ptr<
54 ::grpc::experimental::ClientInterceptorFactoryInterface>>
55 interceptor_creators) override;
56 grpc_channel_credentials* const c_creds_;
59 class SecureCallCredentials final : public CallCredentials {
61 explicit SecureCallCredentials(grpc_call_credentials* c_creds);
62 ~SecureCallCredentials() override {
63 if (c_creds_ != nullptr) c_creds_->Unref();
65 grpc_call_credentials* GetRawCreds() { return c_creds_; }
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()), "}");
75 grpc_call_credentials* const c_creds_;
80 std::shared_ptr<ChannelCredentials> WrapChannelCredentials(
81 grpc_channel_credentials* creds);
83 } // namespace internal
85 namespace experimental {
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.
90 grpc_sts_credentials_options StsCredentialsCppToCoreOptions(
91 const StsCredentialsOptions& options);
93 } // namespace experimental
95 class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen {
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,
101 grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
102 size_t* num_creds_md, grpc_status_code* status,
103 const char** error_details);
104 static char* DebugString(void* wrapper);
106 explicit MetadataCredentialsPluginWrapper(
107 std::unique_ptr<MetadataCredentialsPlugin> plugin);
111 grpc_auth_metadata_context context,
112 grpc_credentials_plugin_metadata_cb cb, void* user_data,
113 grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
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_;
122 #endif // GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H