secure_server_credentials.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
  19. #define GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
  20. #include <memory>
  21. #include <grpcpp/security/server_credentials.h>
  22. #include <grpc/grpc_security.h>
  23. #include "src/cpp/server/thread_pool_interface.h"
  24. namespace grpc {
  25. class AuthMetadataProcessorAyncWrapper final {
  26. public:
  27. static void Destroy(void* wrapper);
  28. static void Process(void* wrapper, grpc_auth_context* context,
  29. const grpc_metadata* md, size_t num_md,
  30. grpc_process_auth_metadata_done_cb cb, void* user_data);
  31. AuthMetadataProcessorAyncWrapper(
  32. const std::shared_ptr<AuthMetadataProcessor>& processor)
  33. : thread_pool_(CreateDefaultThreadPool()), processor_(processor) {}
  34. private:
  35. void InvokeProcessor(grpc_auth_context* context, const grpc_metadata* md,
  36. size_t num_md, grpc_process_auth_metadata_done_cb cb,
  37. void* user_data);
  38. std::unique_ptr<ThreadPoolInterface> thread_pool_;
  39. std::shared_ptr<AuthMetadataProcessor> processor_;
  40. };
  41. class SecureServerCredentials final : public ServerCredentials {
  42. public:
  43. explicit SecureServerCredentials(grpc_server_credentials* creds)
  44. : creds_(creds) {}
  45. ~SecureServerCredentials() override {
  46. grpc_server_credentials_release(creds_);
  47. }
  48. int AddPortToServer(const grpc::string& addr, grpc_server* server) override;
  49. void SetAuthMetadataProcessor(
  50. const std::shared_ptr<AuthMetadataProcessor>& processor) override;
  51. private:
  52. grpc_server_credentials* creds_;
  53. std::unique_ptr<AuthMetadataProcessorAyncWrapper> processor_;
  54. };
  55. } // namespace grpc
  56. #endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H