binder_security_policy.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2021 gRPC authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H
  15. #define GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H
  16. #include <memory>
  17. namespace grpc {
  18. namespace experimental {
  19. namespace binder {
  20. // EXPERIMENTAL Determinines if a connection is allowed to be
  21. // established on Android. See https://source.android.com/security/app-sandbox
  22. // for more info about UID.
  23. class SecurityPolicy {
  24. public:
  25. virtual ~SecurityPolicy() = default;
  26. // Returns true if the UID is authorized to connect.
  27. // Must return the same value for the same inputs so callers can safely cache
  28. // the result.
  29. virtual bool IsAuthorized(int uid) = 0;
  30. };
  31. // EXPERIMENTAL Allows all connection. Anything on the Android device will be
  32. // able to connect, use with caution!
  33. class UntrustedSecurityPolicy : public SecurityPolicy {
  34. public:
  35. UntrustedSecurityPolicy();
  36. ~UntrustedSecurityPolicy() override;
  37. bool IsAuthorized(int uid) override;
  38. };
  39. // EXPERIMENTAL Only allows the connections from processes with the same UID. In
  40. // most cases this means "from the same APK".
  41. class InternalOnlySecurityPolicy : public SecurityPolicy {
  42. public:
  43. InternalOnlySecurityPolicy();
  44. ~InternalOnlySecurityPolicy() override;
  45. bool IsAuthorized(int uid) override;
  46. };
  47. } // namespace binder
  48. } // namespace experimental
  49. } // namespace grpc
  50. #endif // GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H