blob: 713654ad5ba79e4d9ad5de248a3a47f7b1c99303 [file] [log] [blame]
Julien Boeuf1d2240c2015-04-09 21:07:56 -07001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Julien Boeuf1d2240c2015-04-09 21:07:56 -07004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Julien Boeuffce25ee2015-04-10 08:44:20 -070034#ifndef GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
35#define GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
36
Julien Boeuf1d2240c2015-04-09 21:07:56 -070037#include <grpc/grpc_security.h>
38
Julien Boeuf5be92a32015-08-28 16:28:18 -070039#include <grpc++/security/credentials.h>
Craig Tillerf40df232016-03-25 13:38:14 -070040#include <grpc++/support/config.h>
Julien Boeuf1d2240c2015-04-09 21:07:56 -070041
Julien Boeuf2d041182015-08-31 20:30:09 -070042#include "src/cpp/server/thread_pool_interface.h"
43
Julien Boeuf1d2240c2015-04-09 21:07:56 -070044namespace grpc {
45
Vijay Paic0b2acb2016-11-01 16:31:56 -070046class SecureChannelCredentials final : public ChannelCredentials {
Julien Boeuf1d2240c2015-04-09 21:07:56 -070047 public:
David Garcia Quintase1300de2016-01-27 18:41:26 -080048 explicit SecureChannelCredentials(grpc_channel_credentials* c_creds);
49 ~SecureChannelCredentials() { grpc_channel_credentials_release(c_creds_); }
Julien Boeuf54a902e2015-10-12 13:26:21 -070050 grpc_channel_credentials* GetRawCreds() { return c_creds_; }
Julien Boeuf1d2240c2015-04-09 21:07:56 -070051
yang-g8c2be9f2015-08-19 16:28:09 -070052 std::shared_ptr<grpc::Channel> CreateChannel(
Vijay Paic0b2acb2016-11-01 16:31:56 -070053 const string& target, const grpc::ChannelArguments& args) override;
54 SecureChannelCredentials* AsSecureCredentials() override { return this; }
Julien Boeuf1d2240c2015-04-09 21:07:56 -070055
56 private:
Julien Boeuf54a902e2015-10-12 13:26:21 -070057 grpc_channel_credentials* const c_creds_;
Julien Boeuf1d2240c2015-04-09 21:07:56 -070058};
59
Vijay Paic0b2acb2016-11-01 16:31:56 -070060class SecureCallCredentials final : public CallCredentials {
Julien Boeuf54a902e2015-10-12 13:26:21 -070061 public:
David Garcia Quintase1300de2016-01-27 18:41:26 -080062 explicit SecureCallCredentials(grpc_call_credentials* c_creds);
63 ~SecureCallCredentials() { grpc_call_credentials_release(c_creds_); }
Julien Boeuf54a902e2015-10-12 13:26:21 -070064 grpc_call_credentials* GetRawCreds() { return c_creds_; }
65
Vijay Paic0b2acb2016-11-01 16:31:56 -070066 bool ApplyToCall(grpc_call* call) override;
67 SecureCallCredentials* AsSecureCredentials() override { return this; }
Julien Boeuf54a902e2015-10-12 13:26:21 -070068
69 private:
70 grpc_call_credentials* const c_creds_;
71};
72
Craig Tiller7c70b6c2017-01-23 07:48:42 -080073class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen {
Julien Boeuf2d041182015-08-31 20:30:09 -070074 public:
75 static void Destroy(void* wrapper);
Julien Boeuf3c957e62015-11-18 21:33:58 -080076 static void GetMetadata(void* wrapper, grpc_auth_metadata_context context,
Julien Boeuf2d041182015-08-31 20:30:09 -070077 grpc_credentials_plugin_metadata_cb cb,
78 void* user_data);
79
80 explicit MetadataCredentialsPluginWrapper(
81 std::unique_ptr<MetadataCredentialsPlugin> plugin);
82
83 private:
Julien Boeuf114f3942015-11-19 21:45:52 -080084 void InvokePlugin(grpc_auth_metadata_context context,
Julien Boeuf2d041182015-08-31 20:30:09 -070085 grpc_credentials_plugin_metadata_cb cb, void* user_data);
86 std::unique_ptr<ThreadPoolInterface> thread_pool_;
87 std::unique_ptr<MetadataCredentialsPlugin> plugin_;
88};
89
Julien Boeuf1d2240c2015-04-09 21:07:56 -070090} // namespace grpc
91
Julien Boeuffce25ee2015-04-10 08:44:20 -070092#endif // GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H