Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Julien Boeuf | fce25ee | 2015-04-10 08:44:20 -0700 | [diff] [blame] | 19 | #ifndef GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H |
| 20 | #define GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H |
| 21 | |
Julien Boeuf | c2274e7 | 2015-08-10 12:45:17 -0700 | [diff] [blame] | 22 | #include <memory> |
| 23 | |
Julien Boeuf | 5be92a3 | 2015-08-28 16:28:18 -0700 | [diff] [blame] | 24 | #include <grpc++/security/server_credentials.h> |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 25 | |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 26 | #include <grpc/grpc_security.h> |
| 27 | |
Julien Boeuf | 5b3516e | 2015-08-26 11:19:10 -0700 | [diff] [blame] | 28 | #include "src/cpp/server/thread_pool_interface.h" |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 29 | |
| 30 | namespace grpc { |
| 31 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 32 | class AuthMetadataProcessorAyncWrapper final { |
Julien Boeuf | c2274e7 | 2015-08-10 12:45:17 -0700 | [diff] [blame] | 33 | public: |
Craig Tiller | ddf3a51 | 2015-09-24 13:03:44 -0700 | [diff] [blame] | 34 | static void Destroy(void* wrapper); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 35 | |
Julien Boeuf | 8da211f | 2015-08-14 12:57:42 -0700 | [diff] [blame] | 36 | static void Process(void* wrapper, grpc_auth_context* context, |
| 37 | const grpc_metadata* md, size_t num_md, |
Julien Boeuf | c2274e7 | 2015-08-10 12:45:17 -0700 | [diff] [blame] | 38 | grpc_process_auth_metadata_done_cb cb, void* user_data); |
| 39 | |
| 40 | AuthMetadataProcessorAyncWrapper( |
| 41 | const std::shared_ptr<AuthMetadataProcessor>& processor) |
| 42 | : thread_pool_(CreateDefaultThreadPool()), processor_(processor) {} |
| 43 | |
| 44 | private: |
Julien Boeuf | bf25bb0 | 2015-08-14 12:36:11 -0700 | [diff] [blame] | 45 | void InvokeProcessor(grpc_auth_context* context, const grpc_metadata* md, |
Julien Boeuf | 8da211f | 2015-08-14 12:57:42 -0700 | [diff] [blame] | 46 | size_t num_md, grpc_process_auth_metadata_done_cb cb, |
Julien Boeuf | bf25bb0 | 2015-08-14 12:36:11 -0700 | [diff] [blame] | 47 | void* user_data); |
Julien Boeuf | c2274e7 | 2015-08-10 12:45:17 -0700 | [diff] [blame] | 48 | std::unique_ptr<ThreadPoolInterface> thread_pool_; |
| 49 | std::shared_ptr<AuthMetadataProcessor> processor_; |
| 50 | }; |
| 51 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 52 | class SecureServerCredentials final : public ServerCredentials { |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 53 | public: |
| 54 | explicit SecureServerCredentials(grpc_server_credentials* creds) |
| 55 | : creds_(creds) {} |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 56 | ~SecureServerCredentials() override { |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 57 | grpc_server_credentials_release(creds_); |
| 58 | } |
| 59 | |
Vijay Pai | 713c7b8 | 2016-11-01 16:33:18 -0700 | [diff] [blame] | 60 | int AddPortToServer(const grpc::string& addr, grpc_server* server) override; |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 61 | |
Julien Boeuf | c2274e7 | 2015-08-10 12:45:17 -0700 | [diff] [blame] | 62 | void SetAuthMetadataProcessor( |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 63 | const std::shared_ptr<AuthMetadataProcessor>& processor) override; |
Julien Boeuf | c2274e7 | 2015-08-10 12:45:17 -0700 | [diff] [blame] | 64 | |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 65 | private: |
Julien Boeuf | c2274e7 | 2015-08-10 12:45:17 -0700 | [diff] [blame] | 66 | grpc_server_credentials* creds_; |
| 67 | std::unique_ptr<AuthMetadataProcessorAyncWrapper> processor_; |
Julien Boeuf | 1d2240c | 2015-04-09 21:07:56 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace grpc |
| 71 | |
Julien Boeuf | fce25ee | 2015-04-10 08:44:20 -0700 | [diff] [blame] | 72 | #endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H |