| 1 | /* |
|---|---|
| 2 | * |
| 3 | * Copyright 2019 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_H |
| 20 | #define GRPCPP_SECURITY_SERVER_CREDENTIALS_H |
| 21 | |
| 22 | #include <grpcpp/security/server_credentials_impl.h> |
| 23 | |
| 24 | namespace grpc_impl { |
| 25 | |
| 26 | class Server; |
| 27 | } // namespace grpc_impl |
| 28 | namespace grpc { |
| 29 | |
| 30 | typedef ::grpc_impl::ServerCredentials ServerCredentials; |
| 31 | |
| 32 | /// Options to create ServerCredentials with SSL |
| 33 | struct SslServerCredentialsOptions { |
| 34 | /// \warning Deprecated |
| 35 | SslServerCredentialsOptions() |
| 36 | : force_client_auth(false), |
| 37 | client_certificate_request(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE) {} |
| 38 | SslServerCredentialsOptions( |
| 39 | grpc_ssl_client_certificate_request_type request_type) |
| 40 | : force_client_auth(false), client_certificate_request(request_type) {} |
| 41 | |
| 42 | struct PemKeyCertPair { |
| 43 | grpc::string private_key; |
| 44 | grpc::string cert_chain; |
| 45 | }; |
| 46 | grpc::string pem_root_certs; |
| 47 | std::vector<PemKeyCertPair> pem_key_cert_pairs; |
| 48 | /// \warning Deprecated |
| 49 | bool force_client_auth; |
| 50 | |
| 51 | /// If both \a force_client_auth and \a client_certificate_request |
| 52 | /// fields are set, \a force_client_auth takes effect, i.e. |
| 53 | /// \a REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY |
| 54 | /// will be enforced. |
| 55 | grpc_ssl_client_certificate_request_type client_certificate_request; |
| 56 | }; |
| 57 | |
| 58 | static inline std::shared_ptr<ServerCredentials> SslServerCredentials( |
| 59 | const SslServerCredentialsOptions& options) { |
| 60 | return ::grpc_impl::SslServerCredentials(options); |
| 61 | } |
| 62 | |
| 63 | static inline std::shared_ptr<ServerCredentials> InsecureServerCredentials() { |
| 64 | return ::grpc_impl::InsecureServerCredentials(); |
| 65 | } |
| 66 | |
| 67 | namespace experimental { |
| 68 | |
| 69 | typedef ::grpc_impl::experimental::AltsServerCredentialsOptions |
| 70 | AltsServerCredentialsOptions; |
| 71 | |
| 72 | static inline std::shared_ptr<ServerCredentials> AltsServerCredentials( |
| 73 | const AltsServerCredentialsOptions& options) { |
| 74 | return ::grpc_impl::experimental::AltsServerCredentials(options); |
| 75 | } |
| 76 | |
| 77 | static inline std::shared_ptr<ServerCredentials> LocalServerCredentials( |
| 78 | grpc_local_connect_type type) { |
| 79 | return ::grpc_impl::experimental::LocalServerCredentials(type); |
| 80 | } |
| 81 | |
| 82 | /// Builds TLS ServerCredentials given TLS options. |
| 83 | static inline std::shared_ptr<ServerCredentials> TlsServerCredentials( |
| 84 | const ::grpc_impl::experimental::TlsCredentialsOptions& options) { |
| 85 | return ::grpc_impl::experimental::TlsServerCredentials(options); |
| 86 | } |
| 87 | |
| 88 | } // namespace experimental |
| 89 | } // namespace grpc |
| 90 | |
| 91 | #endif // GRPCPP_SECURITY_SERVER_CREDENTIALS_H |
| 92 |
