permissions.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef KEYSTORE_PERMISSIONS_H_
  17. #define KEYSTORE_PERMISSIONS_H_
  18. #include <unistd.h>
  19. /* Here are the permissions, actions, users, and the main function. */
  20. enum perm_t {
  21. P_GET_STATE = 1 << 0,
  22. P_GET = 1 << 1,
  23. P_INSERT = 1 << 2,
  24. P_DELETE = 1 << 3,
  25. P_EXIST = 1 << 4,
  26. P_LIST = 1 << 5,
  27. P_RESET = 1 << 6,
  28. P_PASSWORD = 1 << 7,
  29. P_LOCK = 1 << 8,
  30. P_UNLOCK = 1 << 9,
  31. P_IS_EMPTY = 1 << 10,
  32. P_SIGN = 1 << 11,
  33. P_VERIFY = 1 << 12,
  34. P_GRANT = 1 << 13,
  35. P_DUPLICATE = 1 << 14,
  36. P_CLEAR_UID = 1 << 15,
  37. P_ADD_AUTH = 1 << 16,
  38. P_USER_CHANGED = 1 << 17,
  39. P_GEN_UNIQUE_ID = 1 << 18,
  40. };
  41. const char* get_perm_label(perm_t perm);
  42. /**
  43. * Returns the UID that the callingUid should act as. This is here for
  44. * legacy support of the WiFi and VPN systems and should be removed
  45. * when WiFi can operate in its own namespace.
  46. */
  47. uid_t get_keystore_euid(uid_t uid);
  48. /**
  49. * Returns true if the uid/pid/sid has a permission. Checks based on sid if available.
  50. *
  51. * sid may be null on older kernels
  52. */
  53. bool has_permission(uid_t uid, perm_t perm, pid_t spid, const char* sid);
  54. /**
  55. * Returns true if the callingUid is allowed to interact in the targetUid's
  56. * namespace.
  57. */
  58. bool is_granted_to(uid_t callingUid, uid_t targetUid);
  59. int configure_selinux();
  60. /*
  61. * Keystore grants.
  62. *
  63. * What are keystore grants?
  64. *
  65. * Keystore grants are a mechanism that allows an app to grant the permission to use one of its
  66. * keys to an other app.
  67. *
  68. * Liftime of a grant:
  69. *
  70. * A keystore grant is ephemeral in that is never persistently stored. When the keystore process
  71. * exits, all grants are lost. Also, grants can be explicitly revoked by the granter by invoking
  72. * the ungrant operation.
  73. *
  74. * What happens when a grant is created?
  75. *
  76. * The grant operation expects a valid key alias and the uid of the grantee, i.e., the app that
  77. * shall be allowed to use the key denoted by the alias. It then makes an entry in the grant store
  78. * which generates a new alias of the form <alias>_KEYSTOREGRANT_<random_grant_no_>. This grant
  79. * alias is returned to the caller which can pass the new alias to the grantee. For every grantee,
  80. * the grant store keeps a set of grants, an entry of which holds the following information:
  81. * - the owner of the key by uid, aka granter uid,
  82. * - the original alias of the granted key, and
  83. * - the random grant number.
  84. * (See "grant_store.h:class Grant")
  85. *
  86. * What happens when a grant is used?
  87. *
  88. * Upon any keystore operation that expects an alias, the alias and the caller's uid are used
  89. * to retrieve a key file. If that fails some operations try to retrieve a key file indirectly
  90. * through a grant. These operations include:
  91. * - attestKey
  92. * - begin
  93. * - exportKey
  94. * - get
  95. * - getKeyCharacteristics
  96. * - del
  97. * - exist
  98. * - getmtime
  99. * Operations that DO NOT follow the grant indirection are:
  100. * - import
  101. * - generate
  102. * - grant
  103. * - ungrant
  104. * Especially, the latter two mean that neither can a grantee transitively grant a granted key
  105. * to a third, nor can they relinquish access to the key or revoke access to the key by a third.
  106. */
  107. #endif // KEYSTORE_PERMISSIONS_H_