Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/grpc/include/grpc++/security/credentials.h

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * 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
34 #ifndef GRPCXX_CREDENTIALS_H
35 #define GRPCXX_CREDENTIALS_H
36
37 #include <map>
38 #include <memory>
39
40 #include <grpc++/impl/codegen/grpc_library.h>
41 #include <grpc++/security/auth_context.h>
42 #include <grpc++/support/status.h>
43 #include <grpc++/support/string_ref.h>
44
45 struct grpc_call;
46
47 namespace grpc {
48 class ChannelArguments;
49 class Channel;
50 class SecureChannelCredentials;
51 class CallCredentials;
52 class SecureCallCredentials;
53
54 /// A channel credentials object encapsulates all the state needed by a client
55 /// to authenticate with a server for a given channel.
56 /// It can make various assertions, e.g., about the client’s identity, role
57 /// for all the calls on that channel.
58 ///
59 /// \see http://www.grpc.io/docs/guides/auth.html
60 class ChannelCredentials : private GrpcLibrary {
61 public:
62 ChannelCredentials();
63 ~ChannelCredentials();
64
65 protected:
66 friend std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
67 const std::shared_ptr<ChannelCredentials>& channel_creds,
68 const std::shared_ptr<CallCredentials>& call_creds);
69
70 virtual SecureChannelCredentials* AsSecureCredentials() = 0;
71
72 private:
73 friend std::shared_ptr<Channel> CreateCustomChannel(
74 const grpc::string& target,
75 const std::shared_ptr<ChannelCredentials>& creds,
76 const ChannelArguments& args);
77
78 virtual std::shared_ptr<Channel> CreateChannel(
79 const grpc::string& target, const ChannelArguments& args) = 0;
80 };
81
82 /// A call credentials object encapsulates the state needed by a client to
83 /// authenticate with a server for a given call on a channel.
84 ///
85 /// \see http://www.grpc.io/docs/guides/auth.html
86 class CallCredentials : private GrpcLibrary {
87 public:
88 CallCredentials();
89 ~CallCredentials();
90
91 /// Apply this instance's credentials to \a call.
92 virtual bool ApplyToCall(grpc_call* call) = 0;
93
94 protected:
95 friend std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
96 const std::shared_ptr<ChannelCredentials>& channel_creds,
97 const std::shared_ptr<CallCredentials>& call_creds);
98
99 friend std::shared_ptr<CallCredentials> CompositeCallCredentials(
100 const std::shared_ptr<CallCredentials>& creds1,
101 const std::shared_ptr<CallCredentials>& creds2);
102
103 virtual SecureCallCredentials* AsSecureCredentials() = 0;
104 };
105
106 /// Options used to build SslCredentials.
107 struct SslCredentialsOptions {
108 /// The buffer containing the PEM encoding of the server root certificates. If
109 /// this parameter is empty, the default roots will be used. The default
110 /// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
111 /// environment variable pointing to a file on the file system containing the
112 /// roots.
113 grpc::string pem_root_certs;
114
115 /// The buffer containing the PEM encoding of the client's private key. This
116 /// parameter can be empty if the client does not have a private key.
117 grpc::string pem_private_key;
118
119 /// The buffer containing the PEM encoding of the client's certificate chain.
120 /// This parameter can be empty if the client does not have a certificate
121 /// chain.
122 grpc::string pem_cert_chain;
123 };
124
125 // Factories for building different types of Credentials The functions may
126 // return empty shared_ptr when credentials cannot be created. If a
127 // Credentials pointer is returned, it can still be invalid when used to create
128 // a channel. A lame channel will be created then and all rpcs will fail on it.
129
130 /// Builds credentials with reasonable defaults.
131 ///
132 /// \warning Only use these credentials when connecting to a Google endpoint.
133 /// Using these credentials to connect to any other service may result in this
134 /// service being able to impersonate your client for requests to Google
135 /// services.
136 std::shared_ptr<ChannelCredentials> GoogleDefaultCredentials();
137
138 /// Builds SSL Credentials given SSL specific options
139 std::shared_ptr<ChannelCredentials> SslCredentials(
140 const SslCredentialsOptions& options);
141
142 /// Builds credentials for use when running in GCE
143 ///
144 /// \warning Only use these credentials when connecting to a Google endpoint.
145 /// Using these credentials to connect to any other service may result in this
146 /// service being able to impersonate your client for requests to Google
147 /// services.
148 std::shared_ptr<CallCredentials> GoogleComputeEngineCredentials();
149
150 /// Builds Service Account JWT Access credentials.
151 /// json_key is the JSON key string containing the client's private key.
152 /// token_lifetime_seconds is the lifetime in seconds of each Json Web Token
153 /// (JWT) created with this credentials. It should not exceed
154 /// grpc_max_auth_token_lifetime or will be cropped to this value.
155 std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials(
156 const grpc::string& json_key, long token_lifetime_seconds);
157
158 /// Builds refresh token credentials.
159 /// json_refresh_token is the JSON string containing the refresh token along
160 /// with a client_id and client_secret.
161 ///
162 /// \warning Only use these credentials when connecting to a Google endpoint.
163 /// Using these credentials to connect to any other service may result in this
164 /// service being able to impersonate your client for requests to Google
165 /// services.
166 std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials(
167 const grpc::string& json_refresh_token);
168
169 /// Builds access token credentials.
170 /// access_token is an oauth2 access token that was fetched using an out of band
171 /// mechanism.
172 ///
173 /// \warning Only use these credentials when connecting to a Google endpoint.
174 /// Using these credentials to connect to any other service may result in this
175 /// service being able to impersonate your client for requests to Google
176 /// services.
177 std::shared_ptr<CallCredentials> AccessTokenCredentials(
178 const grpc::string& access_token);
179
180 /// Builds IAM credentials.
181 ///
182 /// \warning Only use these credentials when connecting to a Google endpoint.
183 /// Using these credentials to connect to any other service may result in this
184 /// service being able to impersonate your client for requests to Google
185 /// services.
186 std::shared_ptr<CallCredentials> GoogleIAMCredentials(
187 const grpc::string& authorization_token,
188 const grpc::string& authority_selector);
189
190 /// Combines a channel credentials and a call credentials into a composite
191 /// channel credentials.
192 std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
193 const std::shared_ptr<ChannelCredentials>& channel_creds,
194 const std::shared_ptr<CallCredentials>& call_creds);
195
196 /// Combines two call credentials objects into a composite call credentials.
197 std::shared_ptr<CallCredentials> CompositeCallCredentials(
198 const std::shared_ptr<CallCredentials>& creds1,
199 const std::shared_ptr<CallCredentials>& creds2);
200
201 /// Credentials for an unencrypted, unauthenticated channel
202 std::shared_ptr<ChannelCredentials> InsecureChannelCredentials();
203
204 // User defined metadata credentials.
205 class MetadataCredentialsPlugin {
206 public:
207 virtual ~MetadataCredentialsPlugin() {}
208
209 // If this method returns true, the Process function will be scheduled in
210 // a different thread from the one processing the call.
211 virtual bool IsBlocking() const { return true; }
212
213 // Type of credentials this plugin is implementing.
214 virtual const char* GetType() const { return ""; }
215
216 // Gets the auth metatada produced by this plugin.
217 // The fully qualified method name is:
218 // service_url + "/" + method_name.
219 // The channel_auth_context contains (among other things), the identity of
220 // the server.
221 virtual Status GetMetadata(
222 grpc::string_ref service_url, grpc::string_ref method_name,
223 const AuthContext& channel_auth_context,
224 std::multimap<grpc::string, grpc::string>* metadata) = 0;
225 };
226
227 std::shared_ptr<CallCredentials> MetadataCredentialsFromPlugin(
228 std::unique_ptr<MetadataCredentialsPlugin> plugin);
229
230 } // namespace grpc
231
232 #endif // GRPCXX_CREDENTIALS_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698