1 /*
2  * Copyright (C) 2021 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 #include <stdbool.h>
18 #include <stdint.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <uapi/trusty_uuid.h>
22 
23 #include <interface/keymaster/keymaster.h>
24 
25 #define TLOG_TAG "KMAccessPolicy"
26 #include <trusty_log.h>
27 
28 /*
29  * Note: This access policy is replicated in
30  * trusty/user/app/keymint/generic_access_policy/lib.rs for Keymint Rust. Any
31  * updates to this access policy should be replicated there as well.
32  */
33 static uuid_t accessible_uuids[] = {
34         /* gatekeeper uuid */
35         {0x38ba0cdc,
36          0xdf0e,
37          0x11e4,
38          {0x98, 0x69, 0x23, 0x3f, 0xb6, 0xae, 0x47, 0x95}},
39         /* confirmation ui uuid */
40         {0x7dee2364,
41          0xc036,
42          0x425b,
43          {0xb0, 0x86, 0xdf, 0x0f, 0x6c, 0x23, 0x3c, 0x1b}},
44         /* unit test uuid */
45         {0xf3ba7629,
46          0xe8cc,
47          0x44a0,
48          {0x88, 0x4d, 0xf9, 0x16, 0xf7, 0x03, 0xa2, 0x00}},
49 };
50 
keymaster_check_target_access_policy(uuid_t * uuid)51 bool keymaster_check_target_access_policy(uuid_t* uuid) {
52     for (auto accessible_uuid : accessible_uuids) {
53         if (memcmp(uuid, &accessible_uuid, sizeof(accessible_uuid)) == 0) {
54             return true;
55         }
56     }
57     return false;
58 }
59 
keymaster_check_secure_target_access_policy_provisioning(const uuid_t * uuid)60 bool keymaster_check_secure_target_access_policy_provisioning(
61         const uuid_t* uuid) {
62     /* Not Supported */
63     return false;
64 }
65