blob: 1f7b7a6579218176a0830607bee81d583902d189 [file] [log] [blame]
Shawn Willdenc1d1fee2016-01-26 22:44:56 -07001/*
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
17#ifndef KEYSTORE_PERMISSIONS_H_
18#define KEYSTORE_PERMISSIONS_H_
19
20#include <unistd.h>
21
22/* Here are the permissions, actions, users, and the main function. */
23enum perm_t {
24 P_GET_STATE = 1 << 0,
25 P_GET = 1 << 1,
26 P_INSERT = 1 << 2,
27 P_DELETE = 1 << 3,
28 P_EXIST = 1 << 4,
29 P_LIST = 1 << 5,
30 P_RESET = 1 << 6,
31 P_PASSWORD = 1 << 7,
32 P_LOCK = 1 << 8,
33 P_UNLOCK = 1 << 9,
34 P_IS_EMPTY = 1 << 10,
35 P_SIGN = 1 << 11,
36 P_VERIFY = 1 << 12,
37 P_GRANT = 1 << 13,
38 P_DUPLICATE = 1 << 14,
39 P_CLEAR_UID = 1 << 15,
40 P_ADD_AUTH = 1 << 16,
41 P_USER_CHANGED = 1 << 17,
Shawn Willdene2a7b522017-04-11 09:27:40 -060042 P_GEN_UNIQUE_ID = 1 << 18,
Shawn Willdenc1d1fee2016-01-26 22:44:56 -070043};
44
45const char* get_perm_label(perm_t perm);
46
47/**
48 * Returns the UID that the callingUid should act as. This is here for
49 * legacy support of the WiFi and VPN systems and should be removed
50 * when WiFi can operate in its own namespace.
51 */
52uid_t get_keystore_euid(uid_t uid);
53
54bool has_permission(uid_t uid, perm_t perm, pid_t spid);
55
56/**
57 * Returns true if the callingUid is allowed to interact in the targetUid's
58 * namespace.
59 */
60bool is_granted_to(uid_t callingUid, uid_t targetUid);
61
62int configure_selinux();
63
Janis Danisevskisf9f55452017-09-21 11:29:47 -070064/*
65 * Keystore grants.
66 *
67 * What are keystore grants?
68 *
69 * Keystore grants are a mechanism that allows an app to grant the permission to use one of its
70 * keys to an other app.
71 *
72 * Liftime of a grant:
73 *
74 * A keystore grant is ephemeral in that is never persistently stored. When the keystore process
75 * exits, all grants are lost. Also, grants can be explicitly revoked by the granter by invoking
76 * the ungrant operation.
77 *
78 * What happens when a grant is created?
79 *
80 * The grant operation expects a valid key alias and the uid of the grantee, i.e., the app that
81 * shall be allowed to use the key denoted by the alias. It then makes an entry in the grant store
82 * which generates a new alias of the form <alias>_KEYSTOREGRANT_<random_grant_no_>. This grant
83 * alias is returned to the caller which can pass the new alias to the grantee. For every grantee,
84 * the grant store keeps a set of grants, an entry of which holds the following information:
85 * - the owner of the key by uid, aka granter uid,
86 * - the original alias of the granted key, and
87 * - the random grant number.
88 * (See "grant_store.h:class Grant")
89 *
90 * What happens when a grant is used?
91 *
92 * Upon any keystore operation that expects an alias, the alias and the caller's uid are used
93 * to retrieve a key file. If that fails some operations try to retrieve a key file indirectly
94 * through a grant. These operations include:
95 * - attestKey
96 * - begin
97 * - exportKey
98 * - get
99 * - getKeyCharacteristics
100 * - del
101 * - exist
102 * - getmtime
103 * Operations that DO NOT follow the grant indirection are:
104 * - import
105 * - generate
106 * - grant
107 * - ungrant
108 * Especially, the latter two mean that neither can a grantee transitively grant a granted key
109 * to a third, nor can they relinquish access to the key or revoke access to the key by a third.
110 */
111
Shawn Willdenc1d1fee2016-01-26 22:44:56 -0700112#endif // KEYSTORE_PERMISSIONS_H_