xref: /aosp_15_r20/system/keymaster/include/keymaster/keymaster_configuration.h (revision 789431f29546679ab5188a97751fb38e3018d44d)
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 
17 #ifndef SYSTEM_KEYMASTER_KEYMASTER_CONFIGURATION_H_
18 #define SYSTEM_KEYMASTER_KEYMASTER_CONFIGURATION_H_
19 
20 #include <optional>
21 #include <string>
22 #include <vector>
23 
24 #include <stdint.h>
25 
26 #include <hardware/keymaster2.h>
27 #include <hardware/keymaster_defs.h>
28 
29 namespace keymaster {
30 
31 /**
32  * Retrieves OS version information from system build properties and configures the provided
33  * keymaster device.
34  */
35 keymaster_error_t ConfigureDevice(keymaster2_device_t* dev);
36 
37 /**
38  * Parses OS version string, returning in integer form. For example, "6.1.2" will be returned as
39  * 60102.  Ignores any non-numeric suffix, and allows short build numbers, e.g. "6" -> 60000 and
40  * "6.1" -> 60100. Returns 0 if the string doesn't contain a numeric version number.
41  */
42 uint32_t GetOsVersion(const char* version_string);
43 
44 /**
45  * Retrieves and parses OS version information from build properties. Returns 0 if the string
46  * doesn't contain a numeric version number.
47  */
48 uint32_t GetOsVersion();
49 
50 /**
51  * Parses OS patch level string, returning year and month in integer form. For example, "2016-03-25"
52  * will be returned as 201603. Returns 0 if the string doesn't contain a date in the form
53  * YYYY-MM-DD; returns YYYMM on success.
54  */
55 uint32_t GetOsPatchlevel(const char* patchlevel_string);
56 
57 /**
58  * Retrieves and parses OS patch level from build properties. Returns 0 if the string doesn't
59  * contain a date in the form YYYY-MM-DD; returns YYYYMM on success.
60  */
61 uint32_t GetOsPatchlevel();
62 
63 /**
64  * Retrieves and parses vendor patch level from build properties (which may require SELinux
65  * permission). Returns 0 if the string doesn't contain a date in the form YYYY-MM-DD; returns
66  * YYYYMMDD on success.
67  */
68 uint32_t GetVendorPatchlevel();
69 
70 /**
71  * Retrieves the verified boot state from properties (which may require SELinux permission).
72  */
73 std::string GetVerifiedBootState();
74 
75 /**
76  * Retrieves the bootloader state (locked or unlocked) from properties (which may require
77  * SELinux permission).
78  */
79 std::string GetBootloaderState();
80 
81 /**
82  * Parses the given verified boot metadata digest. Returns nullopt if the value is not a binary
83  * string.
84  */
85 std::optional<std::vector<uint8_t>> GetVbmetaDigest(std::string_view vbmeta_string);
86 
87 /**
88  * Retrieves and parses the verified boot metadata digest from properties (which may require
89  * SELinux permission). Returns nullopt if the property is not a binary string.
90  */
91 std::optional<std::vector<uint8_t>> GetVbmetaDigest();
92 
93 }  // namespace keymaster
94 
95 #endif  // SYSTEM_KEYMASTER_KEYMASTER_CONFIGURATION_H_
96