1 /*
2 * Copyright (c) 2022-2025 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 #include "cm_napi_dialog_common.h"
17
18 #include <unordered_map>
19 #include "securec.h"
20
21 #include "cm_log.h"
22 #include "cm_type.h"
23 #include "iservice_registry.h"
24 #include "bundle_mgr_proxy.h"
25 #include "system_ability_definition.h"
26 #include "accesstoken_kit.h"
27 #include "ipc_skeleton.h"
28
29 using namespace OHOS::Security::AccessToken;
30
31 #define BYTE_SHIFT_16 0x10
32 #define BYTE_SHIFT_8 0x08
33 #define BYTE_SHIFT_6 0x06
34 #define BASE64_URL_TABLE_SIZE 0x3F
35 #define BASE64_GROUP_NUM 3
36 #define BYTE_INDEX_ZONE 0
37 #define BYTE_INDEX_ONE 1
38 #define BYTE_INDEX_TWO 2
39 #define BYTE_INDEX_THREE 3
40 #define BASE64_PADDING "="
41 #define BYTE_END_ONE 1
42 #define BYTE_END_TWO 2
43
44 static const char g_base64Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
45 namespace CMNapi {
46 namespace {
47 constexpr int CM_MAX_DATA_LEN = 0x6400000; // The maximum length is 100M
48
49 static const std::string DIALOG_NO_PERMISSION_MSG = "the caller has no permission";
50 static const std::string DIALOG_INVALID_PARAMS_MSG = "the input parameters is invalid";
51 static const std::string DIALOG_GENERIC_MSG = "There is an internal error. Possible causes: "
52 "1.IPC communication failed. 2.Memory operation error.";
53 static const std::string DIALOG_OPERATION_CANCELS_MSG = "the user cancels the installation operation";
54 static const std::string DIALOG_INSTALL_FAILED_MSG = "the user install certificate failed"
55 " in the certificate manager dialog";
56 static const std::string DIALOG_NOT_SUPPORTED_MSG = "the API is not supported on this device";
57
58 static const std::string DIALOG_OPERATION_FAILED_MSG = "the user operation failed "
59 "in the certification manager dialog: ";
60 static const std::string PARSE_CERT_FAILED_MSG = "parse the certificate failed.";
61 static const std::string ADVANCED_SECURITY_MSG = "the device enters advanced security mode.";
62 static const std::string INCORRECT_FORMAT_MSG = "the certificate is in an invalid format.";
63 static const std::string MAX_QUANTITY_REACHED_MSG = "the number of certificates or credentials "
64 "reaches the maxinum allowed.";
65 static const std::string SA_INTERNAL_ERROR_MSG = "sa internal error.";
66 static const std::string NOT_EXIST_MSG = "the certificate dose not exist.";
67 static const std::string NOT_ENTERPRISE_DEVICE_MSG = "The operation does not comply with the device security policy,"
68 "such as the device does not allow users to manage the ca certificate of the global user.";
69
70 static const std::unordered_map<int32_t, int32_t> DIALOG_CODE_TO_JS_CODE_MAP = {
71 // no permission
72 { CMR_DIALOG_ERROR_PERMISSION_DENIED, HAS_NO_PERMISSION },
73 // internal error
74 { CMR_DIALOG_ERROR_INTERNAL, DIALOG_ERROR_GENERIC },
75 // the user cancels the installation operation
76 { CMR_DIALOG_ERROR_OPERATION_CANCELS, DIALOG_ERROR_OPERATION_CANCELED },
77 // the user install certificate failed in the certificate manager dialog
78 { CMR_DIALOG_ERROR_INSTALL_FAILED, DIALOG_ERROR_INSTALL_FAILED },
79 // the API is not supported on this device
80 { CMR_DIALOG_ERROR_NOT_SUPPORTED, DIALOG_ERROR_NOT_SUPPORTED },
81 // The input parameter is invalid
82 { CMR_DIALOG_ERROR_PARAM_INVALID, PARAM_ERROR },
83
84 { CMR_DIALOG_ERROR_PARSE_CERT_FAILED, DIALOG_ERROR_INSTALL_FAILED },
85 { CMR_DIALOG_ERROR_ADVANCED_SECURITY, DIALOG_ERROR_INSTALL_FAILED },
86 { CMR_DIALOG_ERROR_INCORRECT_FORMAT, DIALOG_ERROR_INSTALL_FAILED },
87 { CMR_DIALOG_ERROR_MAX_QUANTITY_REACHED, DIALOG_ERROR_INSTALL_FAILED },
88 { CMR_DIALOG_ERROR_SA_INTERNAL_ERROR, DIALOG_ERROR_INSTALL_FAILED },
89 { CMR_DIALOG_ERROR_NOT_EXIST, DIALOG_ERROR_INSTALL_FAILED },
90 { CMR_DIALOG_ERROR_NOT_ENTERPRISE_DEVICE, DIALOG_ERROR_NOT_COMPLY_SECURITY_POLICY },
91 };
92
93 static const std::unordered_map<int32_t, std::string> DIALOG_CODE_TO_MSG_MAP = {
94 { CMR_DIALOG_ERROR_PERMISSION_DENIED, DIALOG_NO_PERMISSION_MSG },
95 { CMR_DIALOG_ERROR_INTERNAL, DIALOG_GENERIC_MSG },
96 { CMR_DIALOG_ERROR_OPERATION_CANCELS, DIALOG_OPERATION_CANCELS_MSG },
97 { CMR_DIALOG_ERROR_INSTALL_FAILED, DIALOG_INSTALL_FAILED_MSG },
98 { CMR_DIALOG_ERROR_NOT_SUPPORTED, DIALOG_NOT_SUPPORTED_MSG },
99 { CMR_DIALOG_ERROR_NOT_ENTERPRISE_DEVICE, NOT_ENTERPRISE_DEVICE_MSG },
100 { CMR_DIALOG_ERROR_PARAM_INVALID, DIALOG_INVALID_PARAMS_MSG },
101
102 { CMR_DIALOG_ERROR_PARSE_CERT_FAILED, DIALOG_OPERATION_FAILED_MSG + PARSE_CERT_FAILED_MSG },
103 { CMR_DIALOG_ERROR_ADVANCED_SECURITY, DIALOG_OPERATION_FAILED_MSG + ADVANCED_SECURITY_MSG },
104 { CMR_DIALOG_ERROR_INCORRECT_FORMAT, DIALOG_OPERATION_FAILED_MSG + INCORRECT_FORMAT_MSG },
105 { CMR_DIALOG_ERROR_MAX_QUANTITY_REACHED, DIALOG_OPERATION_FAILED_MSG + MAX_QUANTITY_REACHED_MSG },
106 { CMR_DIALOG_ERROR_SA_INTERNAL_ERROR, DIALOG_OPERATION_FAILED_MSG + SA_INTERNAL_ERROR_MSG },
107 { CMR_DIALOG_ERROR_NOT_EXIST, DIALOG_OPERATION_FAILED_MSG + NOT_EXIST_MSG },
108 };
109 } // namespace
110
CheckBasicPermission(void)111 static bool CheckBasicPermission(void)
112 {
113 AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID();
114
115 int result = AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.ACCESS_CERT_MANAGER");
116 if (result == PERMISSION_GRANTED) {
117 return true;
118 }
119
120 return false;
121 }
122
StartUIExtensionAbility(std::shared_ptr<CmUIExtensionRequestContext> asyncContext,OHOS::AAFwk::Want want,std::shared_ptr<CmUIExtensionCallback> uiExtCallback)123 void StartUIExtensionAbility(std::shared_ptr<CmUIExtensionRequestContext> asyncContext,
124 OHOS::AAFwk::Want want, std::shared_ptr<CmUIExtensionCallback> uiExtCallback)
125 {
126 /*
127 * Before starting the UIExtension, the permission is verified for interception.
128 * The verification will be performed again in the process of starting the com.ohos.certmanager application.
129 */
130 if (!CheckBasicPermission()) {
131 CM_LOG_E("not has basic permission");
132 ThrowError(asyncContext->env, HAS_NO_PERMISSION, DIALOG_NO_PERMISSION_MSG);
133 return;
134 }
135
136 CM_LOG_D("begin StartUIExtensionAbility");
137 auto abilityContext = asyncContext->context;
138 if (abilityContext == nullptr) {
139 CM_LOG_E("abilityContext is null");
140 ThrowError(asyncContext->env, PARAM_ERROR, "abilityContext is null");
141 return;
142 }
143 auto uiContent = abilityContext->GetUIContent();
144 if (uiContent == nullptr) {
145 CM_LOG_E("uiContent is null");
146 ThrowError(asyncContext->env, PARAM_ERROR, "uiContent is null");
147 return;
148 }
149
150 OHOS::Ace::ModalUIExtensionCallbacks extensionCallbacks = {
151 [uiExtCallback](int32_t releaseCode) { uiExtCallback->OnRelease(releaseCode); },
152 [uiExtCallback](int32_t resultCode, const OHOS::AAFwk::Want& result) {
153 uiExtCallback->OnResult(resultCode, result); },
154 [uiExtCallback](const OHOS::AAFwk::WantParams& request) { uiExtCallback->OnReceive(request); },
155 [uiExtCallback](int32_t errorCode, const std::string& name, const std::string& message) {
156 uiExtCallback->OnError(errorCode, name, message); },
157 [uiExtCallback](const std::shared_ptr<OHOS::Ace::ModalUIExtensionProxy>& uiProxy) {
158 uiExtCallback->OnRemoteReady(uiProxy); },
159 [uiExtCallback]() { uiExtCallback->OnDestroy(); }
160 };
161
162 OHOS::Ace::ModalUIExtensionConfig uiExtConfig;
163 uiExtConfig.isProhibitBack = false;
164 int32_t sessionId = uiContent->CreateModalUIExtension(want, extensionCallbacks, uiExtConfig);
165 CM_LOG_I("end CreateModalUIExtension");
166 if (sessionId == 0) {
167 CM_LOG_E("CreateModalUIExtension failed");
168 ThrowError(asyncContext->env, PARAM_ERROR, "CreateModalUIExtension failed");
169 }
170 uiExtCallback->SetSessionId(sessionId);
171 return;
172 }
173
EncodeBase64(const uint8_t * indata,const uint32_t length)174 static std::string EncodeBase64(const uint8_t *indata, const uint32_t length)
175 {
176 std::string encodeStr("");
177 if (indata == nullptr) {
178 CM_LOG_E("input param is invalid");
179 return encodeStr;
180 }
181 int i = 0;
182 while (i < (int)length) {
183 unsigned int octeta = i < (int)length ? *(indata + (i++)) : 0;
184 unsigned int octetb = i < (int)length ? *(indata + (i++)) : 0;
185 unsigned int octetc = i < (int)length ? *(indata + (i++)) : 0;
186
187 unsigned int triple = (octeta << BYTE_SHIFT_16) + (octetb << BYTE_SHIFT_8) + octetc;
188
189 encodeStr += g_base64Table[(triple >> BYTE_INDEX_THREE * BYTE_SHIFT_6) & BASE64_URL_TABLE_SIZE];
190 encodeStr += g_base64Table[(triple >> BYTE_INDEX_TWO * BYTE_SHIFT_6) & BASE64_URL_TABLE_SIZE];
191 encodeStr += g_base64Table[(triple >> BYTE_INDEX_ONE * BYTE_SHIFT_6) & BASE64_URL_TABLE_SIZE];
192 encodeStr += g_base64Table[(triple >> BYTE_INDEX_ZONE * BYTE_SHIFT_6) & BASE64_URL_TABLE_SIZE];
193 }
194
195 switch (BASE64_GROUP_NUM - (i % BASE64_GROUP_NUM)) {
196 case BYTE_END_TWO:
197 encodeStr.replace(encodeStr.length() - BYTE_END_TWO, 1, BASE64_PADDING);
198 encodeStr.replace(encodeStr.length() - BYTE_END_ONE, 1, BASE64_PADDING);
199 break;
200 case BYTE_END_ONE:
201 encodeStr.replace(encodeStr.length() - BYTE_END_ONE, 1, BASE64_PADDING);
202 break;
203 default:
204 break;
205 }
206 return encodeStr;
207 }
208
ParseCmUIAbilityContextReq(napi_env env,const napi_value & obj,std::shared_ptr<OHOS::AbilityRuntime::AbilityContext> & abilityContext)209 bool ParseCmUIAbilityContextReq(
210 napi_env env, const napi_value& obj, std::shared_ptr<OHOS::AbilityRuntime::AbilityContext>& abilityContext)
211 {
212 bool stageMode = false;
213 napi_status status = OHOS::AbilityRuntime::IsStageContext(env, obj, stageMode);
214 if (status != napi_ok || !stageMode) {
215 CM_LOG_E("not stage mode");
216 return false;
217 }
218
219 auto context = OHOS::AbilityRuntime::GetStageModeContext(env, obj);
220 if (context == nullptr) {
221 CM_LOG_E("get context failed");
222 return false;
223 }
224
225 abilityContext = OHOS::AbilityRuntime::Context::ConvertTo<OHOS::AbilityRuntime::AbilityContext>(context);
226 if (abilityContext == nullptr) {
227 CM_LOG_E("get abilityContext failed");
228 return false;
229 }
230 CM_LOG_I("end ParseUIAbilityContextReq");
231 return true;
232 }
233
ParseUint32(napi_env env,napi_value object,uint32_t & store)234 napi_value ParseUint32(napi_env env, napi_value object, uint32_t &store)
235 {
236 napi_valuetype type;
237 napi_typeof(env, object, &type);
238 if (type != napi_number) {
239 CM_LOG_E("param type is not number");
240 return nullptr;
241 }
242 uint32_t temp = 0;
243 napi_get_value_uint32(env, object, &temp);
244 store = temp;
245 return GetInt32(env, 0);
246 }
247
ParseBoolean(napi_env env,napi_value object,bool & status)248 napi_value ParseBoolean(napi_env env, napi_value object, bool &status)
249 {
250 napi_valuetype type;
251 napi_typeof(env, object, &type);
252 if (type != napi_boolean) {
253 CM_LOG_E("param type is not bool");
254 return nullptr;
255 }
256 bool temp = false;
257 napi_get_value_bool(env, object, &temp);
258 status = temp;
259 return GetInt32(env, 0);
260 }
261
ParseString(napi_env env,napi_value obj,CmBlob * & blob)262 napi_value ParseString(napi_env env, napi_value obj, CmBlob *&blob)
263 {
264 napi_valuetype type = napi_undefined;
265 NAPI_CALL(env, napi_typeof(env, obj, &type));
266 if (type != napi_string) {
267 CM_LOG_E("the type of param is not string");
268 return nullptr;
269 }
270 size_t length = 0;
271 napi_status status = napi_get_value_string_utf8(env, obj, nullptr, 0, &length);
272 if (status != napi_ok) {
273 GET_AND_THROW_LAST_ERROR((env));
274 CM_LOG_E("could not get string length");
275 return nullptr;
276 }
277
278 if ((length == 0) || (length > CM_MAX_DATA_LEN)) {
279 CM_LOG_E("input string length is 0 or too large, length: %d", length);
280 return nullptr;
281 }
282
283 char *data = static_cast<char *>(CmMalloc(length + 1));
284 if (data == nullptr) {
285 napi_throw_error(env, nullptr, "could not alloc memory");
286 CM_LOG_E("could not alloc memory");
287 return nullptr;
288 }
289 (void)memset_s(data, length + 1, 0, length + 1);
290
291 size_t res = 0;
292 status = napi_get_value_string_utf8(env, obj, data, length + 1, &res);
293 if (status != napi_ok) {
294 CmFree(data);
295 GET_AND_THROW_LAST_ERROR((env));
296 CM_LOG_E("could not get string");
297 return nullptr;
298 }
299
300 blob = static_cast<CmBlob *>(CmMalloc(sizeof(CmBlob)));
301 if (blob == nullptr) {
302 CmFree(data);
303 napi_throw_error(env, nullptr, "could not alloc memory");
304 CM_LOG_E("could not alloc memory");
305 return nullptr;
306 }
307 blob->data = reinterpret_cast<uint8_t *>(data);
308 blob->size = static_cast<uint32_t>((length + 1) & UINT32_MAX);
309
310 return GetInt32(env, 0);
311 }
312
GetUint8ArrayToBase64Str(napi_env env,napi_value object,std::string & certArray)313 napi_value GetUint8ArrayToBase64Str(napi_env env, napi_value object, std::string &certArray)
314 {
315 napi_typedarray_type arrayType;
316 napi_value arrayBuffer = nullptr;
317 size_t length = 0;
318 size_t offset = 0;
319 void *certData = nullptr;
320
321 napi_status status = napi_get_typedarray_info(
322 env, object, &arrayType, &length, static_cast<void **>(&certData), &arrayBuffer, &offset);
323 if (arrayType != napi_uint8_array) {
324 return nullptr;
325 }
326 if (status != napi_ok) {
327 CM_LOG_E("the type of param is not uint8_array");
328 return nullptr;
329 }
330 if (length > CM_MAX_DATA_LEN) {
331 CM_LOG_E("certData is too large, length = %x", length);
332 return nullptr;
333 }
334 uint8_t *data = nullptr;
335 if (length == 0) {
336 CM_LOG_D("The memory length created is only 1 Byte");
337 // The memory length created is only 1 Byte
338 data = static_cast<uint8_t *>(CmMalloc(1));
339 } else {
340 data = static_cast<uint8_t *>(CmMalloc(length));
341 }
342 if (data == nullptr) {
343 CM_LOG_E("Malloc failed");
344 return nullptr;
345 }
346 (void)memset_s(data, length, 0, length);
347 if (memcpy_s(data, length, certData, length) != EOK) {
348 CmFree(data);
349 CM_LOG_E("memcpy_s fail, length = %x", length);
350 return nullptr;
351 }
352 std::string encode = EncodeBase64(data, length);
353 certArray = encode;
354 CmFree(data);
355 return GetInt32(env, 0);
356 }
357
GetJsErrorMsg(int32_t errCode)358 static const char *GetJsErrorMsg(int32_t errCode)
359 {
360 auto iter = DIALOG_CODE_TO_MSG_MAP.find(errCode);
361 if (iter != DIALOG_CODE_TO_MSG_MAP.end()) {
362 return (iter->second).c_str();
363 }
364 return DIALOG_GENERIC_MSG.c_str();
365 }
366
TranformErrorCode(int32_t errorCode)367 int32_t TranformErrorCode(int32_t errorCode)
368 {
369 auto iter = DIALOG_CODE_TO_JS_CODE_MAP.find(errorCode);
370 if (iter != DIALOG_CODE_TO_JS_CODE_MAP.end()) {
371 return iter->second;
372 }
373 return DIALOG_ERROR_GENERIC;
374 }
375
GenerateBusinessError(napi_env env,int32_t errorCode)376 napi_value GenerateBusinessError(napi_env env, int32_t errorCode)
377 {
378 const char *errorMessage = GetJsErrorMsg(errorCode);
379 if (errorMessage == nullptr) {
380 return nullptr;
381 }
382
383 napi_value code = nullptr;
384 int32_t outputCode = TranformErrorCode(errorCode);
385 NAPI_CALL(env, napi_create_int32(env, outputCode, &code));
386 napi_value message = nullptr;
387 NAPI_CALL(env, napi_create_string_utf8(env, errorMessage, NAPI_AUTO_LENGTH, &message));
388
389 napi_value businessErrorMsg = nullptr;
390 NAPI_CALL(env, napi_create_error(env, nullptr, message, &businessErrorMsg));
391 NAPI_CALL(env, napi_set_named_property(env, businessErrorMsg, BUSINESS_ERROR_PROPERTY_CODE.c_str(), code));
392 return businessErrorMsg;
393 }
394
ThrowError(napi_env env,int32_t errorCode,const std::string errMsg)395 void ThrowError(napi_env env, int32_t errorCode, const std::string errMsg)
396 {
397 napi_value paramsError = nullptr;
398 napi_value outCode = nullptr;
399 napi_value message = nullptr;
400 NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, errorCode, &outCode));
401 NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, errMsg.c_str(), NAPI_AUTO_LENGTH, &message));
402 NAPI_CALL_RETURN_VOID(env, napi_create_error(env, nullptr, message, ¶msError));
403 NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, paramsError,
404 BUSINESS_ERROR_PROPERTY_CODE.c_str(), outCode));
405 NAPI_CALL_RETURN_VOID(env, napi_throw(env, paramsError));
406 }
407
GeneratePromise(napi_env env,napi_deferred deferred,int32_t resultCode,napi_value * result,int32_t length)408 void GeneratePromise(napi_env env, napi_deferred deferred, int32_t resultCode,
409 napi_value *result, int32_t length)
410 {
411 if (length < RESULT_NUMBER) {
412 return;
413 }
414 if (resultCode == CM_SUCCESS) {
415 NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, deferred, result[1]));
416 } else {
417 NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, deferred, result[0]));
418 }
419 }
420
GetBundleMgrProxy()421 static OHOS::sptr<OHOS::AppExecFwk::BundleMgrProxy> GetBundleMgrProxy()
422 {
423 auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
424 if (!systemAbilityManager) {
425 CM_LOG_E("fail to get system ability mgr.");
426 return nullptr;
427 }
428
429 auto remoteObject = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
430 if (!remoteObject) {
431 CM_LOG_E("fail to get bundle manager proxy.");
432 return nullptr;
433 }
434 return OHOS::iface_cast<OHOS::AppExecFwk::BundleMgrProxy>(remoteObject);
435 }
436
GetCallerBundleInfo(OHOS::AppExecFwk::BundleInfo & bundleInfo)437 static int32_t GetCallerBundleInfo(OHOS::AppExecFwk::BundleInfo &bundleInfo)
438 {
439 OHOS::sptr<OHOS::AppExecFwk::BundleMgrProxy> bundleMgrProxy = GetBundleMgrProxy();
440 if (bundleMgrProxy == nullptr) {
441 CM_LOG_E("Failed to get bundle manager proxy.");
442 return CM_FAILURE;
443 }
444
445 int32_t flags = static_cast<int32_t>(OHOS::AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_DEFAULT) |
446 static_cast<int32_t>(OHOS::AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
447 static_cast<int32_t>(OHOS::AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
448 static_cast<int32_t>(OHOS::AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY);
449 int32_t resCode = bundleMgrProxy->GetBundleInfoForSelf(flags, bundleInfo);
450 if (resCode != CM_SUCCESS) {
451 CM_LOG_E("Failed to get bundleInfo, resCode is %d", resCode);
452 return CM_FAILURE;
453 }
454 return CM_SUCCESS;
455 }
456
GetCallerLabelName(std::shared_ptr<CmUIExtensionRequestContext> asyncContext)457 int32_t GetCallerLabelName(std::shared_ptr<CmUIExtensionRequestContext> asyncContext)
458 {
459 if (asyncContext == nullptr || asyncContext->context == nullptr) {
460 CM_LOG_E("invalid param");
461 return CM_FAILURE;
462 }
463 OHOS::AppExecFwk::BundleInfo bundleInfo;
464 if (GetCallerBundleInfo(bundleInfo) != CM_SUCCESS) {
465 CM_LOG_E("Failed to get caller bundleInfo");
466 return CM_FAILURE;
467 }
468
469 if (asyncContext->context->GetResourceManager() == nullptr) {
470 CM_LOG_E("context get resourcemanager faild");
471 return CMR_ERROR_NULL_POINTER;
472 }
473
474 int32_t resCode = asyncContext->context->GetResourceManager()->GetStringById(bundleInfo.applicationInfo.labelId,
475 asyncContext->labelName);
476 if (resCode != CM_SUCCESS) {
477 CM_LOG_E("getStringById is faild, resCode is %d", resCode);
478 return CM_FAILURE;
479 }
480 return CM_SUCCESS;
481 }
482
483 } // namespace CertManagerNapi
484