xref: /interface/sdk_c/security/asset/inc/asset_api.h (revision 7777dab0)
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
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 */
15
16#ifndef ASSET_API_H
17#define ASSET_API_H
18
19#include <stdint.h>
20#include <stdlib.h>
21
22#include "asset_type.h"
23
24/**
25 * @addtogroup AssetApi
26 * @{
27 *
28 * @brief Provides APIs for storing and managing short sensitive data of users, including adding, deleting, updating,
29 * and querying the data.
30 * The short sensitive data refers to sensitive data shorter than 1024 bytes, including the user passwords
31 * (accounts/passwords), token data (application credentials), and critical data in plaintext (bank card numbers).
32 *
33 * @since 11
34 */
35
36/**
37 * @file asset_api.h
38 *
39 * @brief Declares the APIs for accessing assets.
40 *
41 * @library libasset_ndk.z.so
42 * @kit AssetStoreKit
43 * @syscap SystemCapability.Security.Asset
44 * @since 11
45 */
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50/**
51 * @brief Adds an asset. Permission ohos.permission.STORE_PERSISTENT_DATA is required when the Asset needs to be stored
52 *     persistently by setting {@link ASSET_TAG_IS_PERSISTENT} tag.
53 *
54 * @param attributes Pointer to the attributes of the asset to add.
55 * @param attributes Number of the attributes of the asset to add.
56 * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
57 *     {@link ASSET_PERMISSION_DENIED} 201 - The caller doesn't have the permission.
58 *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
59 *         1. Mandatory parameters are left unspecified.
60 *         2. Incorrect parameter types.
61 *         3. Parameter verification failed.
62 *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
63 *     {@link ASSET_DUPLICATED} 24000003 - The asset already exists.
64 *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
65 *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
66 *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
67 *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
68 *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
69 *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
70 *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
71 *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
72 *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
73 *     {@link ASSET_FILE_OPERATION_ERROR} 24000014 - The file operation failed.
74 *     {@link ASSET_GET_SYSTEM_TIME_ERROR} 24000015 - Getting the system time failed.
75 * @since 11
76 */
77int32_t OH_Asset_Add(const Asset_Attr *attributes, uint32_t attrCnt);
78
79/**
80 * @brief Removes one or more assets.
81 *
82 * @param query Pointer to the conditions for removing the assets.
83 * @param queryCnt Number of conditions for removing the assets.
84 * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
85 *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
86 *         1. Incorrect parameter types.
87 *         2. Parameter verification failed.
88 *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
89 *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
90 *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
91 *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
92 *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
93 *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
94 *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
95 *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
96 *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
97 *     {@link ASSET_GET_SYSTEM_TIME_ERROR} 24000015 - Getting the system time failed.
98 * @since 11
99 */
100int32_t OH_Asset_Remove(const Asset_Attr *query, uint32_t queryCnt);
101
102/**
103 * @brief Updates an asset.
104 *
105 * @param query Pointer to the conditions for updating the asset.
106 * @param queryCnt Number of conditions for updating the asset.
107 * @param attributes Pointer to the attributes of the asset to update.
108 * @param attributes Number of the attributes of the asset to update.
109 * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
110 *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
111 *         1. Mandatory parameters are left unspecified.
112 *         2. Incorrect parameter types.
113 *         3. Parameter verification failed.
114 *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
115 *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
116 *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
117 *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
118 *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
119 *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
120 *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
121 *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
122 *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
123 *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
124 *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
125 *     {@link ASSET_GET_SYSTEM_TIME_ERROR} 24000015 - Getting the system time failed.
126 * @since 11
127 */
128int32_t OH_Asset_Update(const Asset_Attr *query, uint32_t queryCnt,
129    const Asset_Attr *attributesToUpdate, uint32_t updateCnt);
130
131/**
132 * @brief Preprocesses data before querying the asset that can be accessed only after a successful user authentication.
133 *
134 * @param query Pointer to the search criteria of the asset.
135 * @param queryCnt Number of the search criteria.
136 * @param challenge Pointer to the challenge value to be used when <b>OH_Asset_Query</b> is called.
137 * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
138 *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
139 *         1. Incorrect parameter types.
140 *         2. Parameter verification failed.
141 *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
142 *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
143 *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
144 *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
145 *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
146 *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
147 *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
148 *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
149 *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
150 *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
151 *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
152 *     {@link ASSET_LIMIT_EXCEEDED} 24000016 - The cache exceeds the limit.
153 *     {@link ASSET_UNSUPPORTED} 24000017 - The capability is not supported.
154 * @since 11
155 */
156int32_t OH_Asset_PreQuery(const Asset_Attr *query, uint32_t queryCnt, Asset_Blob *challenge);
157
158/**
159 * @brief Queries assets.
160 *
161 * @param query Pointer to the search criteria.
162 * @param queryCnt Number of the search criteria.
163 * @param resultSet Pointer to the query result obtained.
164 * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
165 *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
166 *         1. Incorrect parameter types.
167 *         2. Parameter verification failed.
168 *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
169 *     {@link ASSET_NOT_FOUND} 24000002 - The asset is not found.
170 *     {@link ASSET_ACCESS_DENIED} 24000004 - Access to the asset is denied.
171 *     {@link ASSET_STATUS_MISMATCH} 24000005 - The screen lock status does not match.
172 *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
173 *     {@link ASSET_DATA_CORRUPTED} 24000007 - The asset is corrupted.
174 *     {@link ASSET_DATABASE_ERROR} 24000008 - The database operation failed.
175 *     {@link ASSET_CRYPTO_ERROR} 24000009 - The cryptography operation failed.
176 *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
177 *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
178 *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
179 *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
180 *     {@link ASSET_UNSUPPORTED} 24000017 - The capability is not supported.
181 * @since 11
182 */
183int32_t OH_Asset_Query(const Asset_Attr *query, uint32_t queryCnt, Asset_ResultSet *resultSet);
184
185/**
186 * @brief Processes data after the query of the asset that requires user authentication.
187 *
188 * @param handle Pointer to the handle of the data to process, which includes the challenge value returned by
189 *     <b>OH_Asset_PreQuery</b>.
190 * @param handleCnt Number of the elements in the handle attribute set.
191 * @return {@link ASSET_SUCCESS} 0 - The operation is successful.
192 *     {@link ASSET_INVALID_ARGUMENT} 401 - Parameter error. Possible causes:
193 *         1. Mandatory parameters are left unspecified.
194 *         2. Incorrect parameter types.
195 *         3. Parameter verification failed.
196 *     {@link ASSET_SERVICE_UNAVAILABLE} 24000001 - The ASSET service is unavailable.
197 *     {@link ASSET_OUT_OF_MEMORY} 24000006 - Insufficient memory.
198 *     {@link ASSET_IPC_ERROR} 24000010 - IPC failed.
199 *     {@link ASSET_BMS_ERROR} 24000011 - Calling the Bundle Manager service failed.
200 *     {@link ASSET_ACCOUNT_ERROR} 24000012 - Calling the OS Account service failed.
201 *     {@link ASSET_ACCESS_TOKEN_ERROR} 24000013 - Calling the Access Token service failed.
202 * @since 11
203 */
204int32_t OH_Asset_PostQuery(const Asset_Attr *handle, uint32_t handleCnt);
205
206/**
207 * @brief Parses the query result to obtain the specified attribute value.
208 *
209 * @param result Pointer to the query result to parse, which is obtained by <b>OH_Asset_Query</b>.
210 * @param tag Tag of the attribute to obtain.
211 * @return Returns <b>Asset_Attr</b> obtained if the operation is successful; returns <b>NULL</b> otherwise.
212 *     The attribute does not need to be released by the service.
213 * @since 11
214 */
215Asset_Attr *OH_Asset_ParseAttr(const Asset_Result *result, Asset_Tag tag);
216
217/**
218 * @brief Releases the memory occupied by the challenge value.
219 *
220 * @param blob Pointer to the challenge value (obtained by <b>OH_Asset_PreQuery</b>) to release.
221 * @since 11
222 */
223void OH_Asset_FreeBlob(Asset_Blob *blob);
224
225/**
226 * @brief Releases the memory occupied by the query result.
227 *
228 * @param resultSet Pointer to the query result (obtained by <b>OH_Asset_Query</b>) to release.
229 * @since 11
230 */
231void OH_Asset_FreeResultSet(Asset_ResultSet *resultSet);
232
233#ifdef __cplusplus
234}
235#endif
236
237/** @} */
238#endif // ASSET_API_H
239