• 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 GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
20 #define GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
21 
22 #include <memory>
23 #include <vector>
24 
25 #include <grpc/grpc_security_constants.h>
26 #include <grpcpp/security/auth_metadata_processor.h>
27 #include <grpcpp/security/tls_credentials_options.h>
28 #include <grpcpp/support/config.h>
29 
30 struct grpc_server;
31 
32 namespace grpc {
33 
34 struct SslServerCredentialsOptions;
35 }  // namespace grpc
36 namespace grpc_impl {
37 class Server;
38 
39 /// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
40 class ServerCredentials {
41  public:
42   virtual ~ServerCredentials();
43 
44   /// This method is not thread-safe and has to be called before the server is
45   /// started. The last call to this function wins.
46   virtual void SetAuthMetadataProcessor(
47       const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) = 0;
48 
49  private:
50   friend class ::grpc_impl::Server;
51 
52   /// Tries to bind \a server to the given \a addr (eg, localhost:1234,
53   /// 192.168.1.1:31416, [::1]:27182, etc.)
54   ///
55   /// \return bound port number on success, 0 on failure.
56   // TODO(dgq): the "port" part seems to be a misnomer.
57   virtual int AddPortToServer(const std::string& addr, grpc_server* server) = 0;
58 };
59 
60 /// Builds SSL ServerCredentials given SSL specific options
61 std::shared_ptr<ServerCredentials> SslServerCredentials(
62     const grpc::SslServerCredentialsOptions& options);
63 
64 /// Builds insecure server credentials.
65 std::shared_ptr<ServerCredentials> InsecureServerCredentials();
66 
67 namespace experimental {
68 
69 /// Options to create ServerCredentials with ALTS
70 struct AltsServerCredentialsOptions {
71   /// Add fields if needed.
72 };
73 
74 /// Builds ALTS ServerCredentials given ALTS specific options
75 std::shared_ptr<ServerCredentials> AltsServerCredentials(
76     const AltsServerCredentialsOptions& options);
77 
78 /// Builds Local ServerCredentials.
79 std::shared_ptr<ServerCredentials> LocalServerCredentials(
80     grpc_local_connect_type type);
81 
82 /// Builds TLS ServerCredentials given TLS options.
83 std::shared_ptr<ServerCredentials> TlsServerCredentials(
84     const TlsCredentialsOptions& options);
85 
86 }  // namespace experimental
87 }  // namespace grpc_impl
88 
89 #endif  // GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
90