diff --git a/BUILD.gn b/BUILD.gn index 5ab61f4069fa06396b18841e10937ed8cbbc7262..717e54770a9af89b019dcf875105e53dacccacf3 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -27,10 +27,7 @@ group("cert_manager_sdk_test") { group("cert_manager_napi") { if (os_level == "standard") { if (support_jsapi) { - deps = [ - "./interfaces/kits/napi:certmanager", - "./interfaces/kits/napi:certmanagerdialog", - ] + deps = [ "./interfaces/kits/napi:certmanager" ] } } } diff --git a/bundle.json b/bundle.json index df299919c7e108712ad6d0128f65e6c788d71a91..4e657fe8d6baef81058292173178f6b9da8e4184 100644 --- a/bundle.json +++ b/bundle.json @@ -35,8 +35,6 @@ "deps": { "components": [ "ability_base", - "ace_engine", - "ability_runtime", "access_token", "bounds_checking_function", "bundle_framework", diff --git a/frameworks/cert_manager_standard/main/common/include/cert_manager_service_ipc_interface_code.h b/frameworks/cert_manager_standard/main/common/include/cert_manager_service_ipc_interface_code.h index 91b6a2e9f26fe231ddb9fcf20bb7683b127a7515..ceb40b3fe00b33e21b2d7ed939e996bee49230a8 100644 --- a/frameworks/cert_manager_standard/main/common/include/cert_manager_service_ipc_interface_code.h +++ b/frameworks/cert_manager_standard/main/common/include/cert_manager_service_ipc_interface_code.h @@ -32,7 +32,6 @@ enum CertManagerInterfaceCode { CM_MSG_UNINSTALL_APP_CERTIFICATE, CM_MSG_UNINSTALL_ALL_APP_CERTIFICATE, CM_MSG_GET_APP_CERTIFICATE_LIST, - CM_MSG_GET_CALLING_APP_CERTIFICATE_LIST, CM_MSG_GET_APP_CERTIFICATE, CM_MSG_GRANT_APP_CERT, CM_MSG_GET_AUTHED_LIST, diff --git a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/include/cm_ipc_client.h b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/include/cm_ipc_client.h index d1cff5de26ed53b9b67ee27f0d58f0296d74e755..2c49f340d5d19e4bdacd6b11cbb7b35cd26161f9 100755 --- a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/include/cm_ipc_client.h +++ b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/include/cm_ipc_client.h @@ -41,8 +41,6 @@ int32_t CmClientUninstallAllAppCert(enum CertManagerInterfaceCode type); int32_t CmClientGetAppCertList(const uint32_t store, struct CredentialList *certificateList); -int32_t CmClientGetCallingAppCertList(const uint32_t store, struct CredentialList *certificateList); - int32_t CmClientGetAppCert(const struct CmBlob *keyUri, const uint32_t store, struct Credential *certificate); int32_t CmClientGrantAppCertificate(const struct CmBlob *keyUri, uint32_t appUid, struct CmBlob *authUri); diff --git a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c index 756a7919dadc5f9a67877b5d699055d986f4bc47..5c99be21a11871835c8e350ef1a1adccfc8843cb 100644 --- a/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c +++ b/frameworks/cert_manager_standard/main/os_dependency/cm_ipc/src/cm_ipc_client.c @@ -432,11 +432,6 @@ int32_t CmClientGetAppCertList(const uint32_t store, struct CredentialList *cert return GetAppCertList(CM_MSG_GET_APP_CERTIFICATE_LIST, store, certificateList); } -int32_t CmClientGetCallingAppCertList(const uint32_t store, struct CredentialList *certificateList) -{ - return GetAppCertList(CM_MSG_GET_CALLING_APP_CERTIFICATE_LIST, store, certificateList); -} - static int32_t GetAppCertInitBlob(struct CmBlob *outBlob) { uint32_t buffSize = sizeof(uint32_t) + sizeof(uint32_t) + MAX_LEN_SUBJECT_NAME + diff --git a/interfaces/innerkits/cert_manager_standard/main/include/cert_manager_api.h b/interfaces/innerkits/cert_manager_standard/main/include/cert_manager_api.h index b0843a0f1355fb270f26ae84d33fa393c84cc6b1..0198f40d4027a2a769b3463ff7f9e235fc54838d 100644 --- a/interfaces/innerkits/cert_manager_standard/main/include/cert_manager_api.h +++ b/interfaces/innerkits/cert_manager_standard/main/include/cert_manager_api.h @@ -39,8 +39,6 @@ CM_API_EXPORT int32_t CmUninstallAllAppCert(void); CM_API_EXPORT int32_t CmGetAppCertList(const uint32_t store, struct CredentialList *certificateList); -CM_API_EXPORT int32_t CmCallingGetAppCertList(const uint32_t store, struct CredentialList *certificateList); - CM_API_EXPORT int32_t CmGetAppCert(const struct CmBlob *keyUri, const uint32_t store, struct Credential *certificate); CM_API_EXPORT int32_t CmGrantAppCertificate(const struct CmBlob *keyUri, uint32_t appUid, struct CmBlob *authUri); diff --git a/interfaces/innerkits/cert_manager_standard/main/src/cert_manager_api.c b/interfaces/innerkits/cert_manager_standard/main/src/cert_manager_api.c index 36d549a9330c8ec688d8fbb5bad7e828893ba675..fc0b31615b886170b8b94429a65ef7af90fe5d75 100644 --- a/interfaces/innerkits/cert_manager_standard/main/src/cert_manager_api.c +++ b/interfaces/innerkits/cert_manager_standard/main/src/cert_manager_api.c @@ -128,16 +128,6 @@ CM_API_EXPORT int32_t CmGetAppCertList(const uint32_t store, struct CredentialLi return ret; } -CM_API_EXPORT int32_t CmCallingGetAppCertList(const uint32_t store, struct CredentialList *certificateList) -{ - if (certificateList == NULL || CM_STORE_CHECK(store)) { - return CMR_ERROR_INVALID_ARGUMENT; - } - - int32_t ret = CmClientGetCallingAppCertList(store, certificateList); - return ret; -} - CM_API_EXPORT int32_t CmGetAppCert(const struct CmBlob *keyUri, const uint32_t store, struct Credential *certificate) { diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index d2ec35d3d677a991382bd9cd5893b70d2cb670e7..2e4b4b2c5b1d308915e1bdbe8faf5040831f10d4 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -68,55 +68,3 @@ ohos_shared_library("certmanager") { subsystem_name = "security" part_name = "certificate_manager" } - -ohos_shared_library("certmanagerdialog") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - boundary_sanitize = true - debug = false - integer_overflow = true - ubsan = true - } - defines = [ - "L2_STANDARD", - "_HARDWARE_ROOT_KEY_", - "_CM_LOG_ENABLE_", - ] - - include_dirs = [ - "../../../frameworks/cert_manager_standard/main/common/include", - "include", - "include/dialog", - ] - - sources = [ - "src/cm_napi_common.cpp", - "src/dialog/cm_napi_dialog.cpp", - "src/dialog/cm_napi_open_dialog.cpp", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_context", - "ability_runtime:napi_base_context", - "ability_runtime:napi_common", - "ace_engine:ace_uicontent", - "c_utils:utils", - "napi:ace_napi", - ] - cflags_cc = [ - "-Wall", - "-Werror", - ] - deps = [ "../../innerkits/cert_manager_standard/main:cert_manager_sdk" ] - - relative_install_dir = "module/security" - subsystem_name = "security" - part_name = "certificate_manager" -} diff --git a/interfaces/kits/napi/include/cm_napi_get_app_cert_list.h b/interfaces/kits/napi/include/cm_napi_get_app_cert_list.h index 55ba141cc971478520222d3bda04d4b538d93832..1ca4281d0818a7f3c039b0216fd0cb1f141b47cc 100644 --- a/interfaces/kits/napi/include/cm_napi_get_app_cert_list.h +++ b/interfaces/kits/napi/include/cm_napi_get_app_cert_list.h @@ -25,8 +25,6 @@ napi_value CMNapiGetAllPublicCertList(napi_env env, napi_callback_info info); napi_value CMNapiGetPrivateAppCertList(napi_env env, napi_callback_info info); napi_value CMNapiGetSystemAppCertList(napi_env env, napi_callback_info info); - -napi_value CMNapiGetCallingPrivateAppCertList(napi_env env, napi_callback_info info); } // namespace CertManagerNapi #endif // CM_NAPI_GET_APP_CERTIFICATE_LIST_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/cm_napi_get_app_cert_list_common.h b/interfaces/kits/napi/include/cm_napi_get_app_cert_list_common.h index c9396b11329604beca2d90dcebaf717dfca3a8b4..b95a206fc0ca8e1e5012cb6575f2e4a4604af1fb 100755 --- a/interfaces/kits/napi/include/cm_napi_get_app_cert_list_common.h +++ b/interfaces/kits/napi/include/cm_napi_get_app_cert_list_common.h @@ -43,11 +43,7 @@ napi_value GetAppCertListWriteResult(napi_env env, GetAppCertListAsyncContext co napi_value GetAppCertListAsyncWork(napi_env env, GetAppCertListAsyncContext asyncContext); -napi_value GetCallingAppCertListAsyncWork(napi_env env, GetAppCertListAsyncContext asyncContext); - napi_value CMNapiGetAppCertListCommon(napi_env env, napi_callback_info info, uint32_t store); - -napi_value CMNapiGetCallingAppCertListCommon(napi_env env, napi_callback_info info, uint32_t store); } // namespace CertManagerNapi #endif // CM_NAPI_GET_APP_CERTIFICATE_LIST_COMMON_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/dialog/cm_napi_open_dialog.h b/interfaces/kits/napi/include/dialog/cm_napi_open_dialog.h deleted file mode 100644 index e7fb0287d254b4744482b8dd14cd9b9e80f22bff..0000000000000000000000000000000000000000 --- a/interfaces/kits/napi/include/dialog/cm_napi_open_dialog.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CM_NAPI_OPEN_DIALOG_H -#define CM_NAPI_OPEN_DIALOG_H - -#include "ability_context.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#include "napi_base_context.h" -#include "napi_common_want.h" -#include "ui_content.h" - -#include "cm_napi_common.h" - -namespace CMNapi { -napi_value CMNapiOpenCertManagerDialog(napi_env env, napi_callback_info info); - -enum CmDialogErrorCode { - DIALOG_ERROR_GENERIC = 29700001, - DIALOG_ERROR_OPERATION_CANCELED = 29700002, -}; - -enum CmDialogPageType { - PAGE_MAIN = 1, - PAGE_CA_CERTIFICATE = 2, - PAGE_CREDENTIAL = 3, - PAGE_INSTALL_CERTIFICATE = 4 -}; - -struct CommonAsyncContext { - explicit CommonAsyncContext(napi_env env); - virtual ~CommonAsyncContext(); - napi_env env = nullptr; - napi_status status = napi_invalid_arg; - int32_t errCode = 0; - napi_deferred deferred = nullptr; // promise handle -}; - -struct CmUIExtensionRequestContext : public CommonAsyncContext { - explicit CmUIExtensionRequestContext(napi_env env) : CommonAsyncContext(env) {}; - std::shared_ptr context = nullptr; - uint32_t pageType = 0; -}; - -class CmUIExtensionCallback { -public: - explicit CmUIExtensionCallback(std::shared_ptr& reqContext); - void SetSessionId(const int32_t sessionId); - void OnRelease(const int32_t releaseCode); - void OnResult(const int32_t resultCode, const OHOS::AAFwk::Want& result); - void OnReceive(const OHOS::AAFwk::WantParams& request); - void OnError(const int32_t code, const std::string& name, const std::string& message); - void OnRemoteReady(const std::shared_ptr& uiProxy); - void OnDestroy(); - void SendMessageBack(); - -private: - bool SetErrorCode(int32_t errCode); - int32_t sessionId_ = 0; - int32_t resultCode_ = 0; - OHOS::AAFwk::Want resultWant_; - std::shared_ptr reqContext_ = nullptr; - bool alreadyCallback_ = false; -}; - -} // namespace CertManagerNapi -#endif // CM_NAPI_OPEN_DIALOG_H diff --git a/interfaces/kits/napi/src/cm_napi.cpp b/interfaces/kits/napi/src/cm_napi.cpp index 99e8aa0c0ac38dc43c8a1c23b9c132446414707a..41e7f944959cc294e56a304b4c5024574855553c 100644 --- a/interfaces/kits/napi/src/cm_napi.cpp +++ b/interfaces/kits/napi/src/cm_napi.cpp @@ -136,7 +136,6 @@ extern "C" { DECLARE_NAPI_FUNCTION("uninstallPrivateCertificate", CMNapiUninstallPrivateAppCert), DECLARE_NAPI_FUNCTION("getAllAppPrivateCertificates", CMNapiGetPrivateAppCertList), DECLARE_NAPI_FUNCTION("getPrivateCertificate", CMNapiGetPrivateAppCertInfo), - DECLARE_NAPI_FUNCTION("getPrivateCertificates", CMNapiGetCallingPrivateAppCertList), /* grant, sign and verify */ DECLARE_NAPI_FUNCTION("grantPublicCertificate", CMNapiGrantPublicCertificate), diff --git a/interfaces/kits/napi/src/cm_napi_get_app_cert_list.cpp b/interfaces/kits/napi/src/cm_napi_get_app_cert_list.cpp index b45552903f93600812fcab40c5564a278834e826..1bee2fe64318cfe21d8048cbdfc2583001aaf580 100644 --- a/interfaces/kits/napi/src/cm_napi_get_app_cert_list.cpp +++ b/interfaces/kits/napi/src/cm_napi_get_app_cert_list.cpp @@ -33,9 +33,4 @@ napi_value CMNapiGetSystemAppCertList(napi_env env, napi_callback_info info) { return CMNapiGetAppCertListCommon(env, info, APPLICATION_SYSTEM_CERTIFICATE_STORE); } - -napi_value CMNapiGetCallingPrivateAppCertList(napi_env env, napi_callback_info info) -{ - return CMNapiGetCallingAppCertListCommon(env, info, APPLICATION_PRIVATE_CERTIFICATE_STORE); -} } // namespace CertManagerNapi diff --git a/interfaces/kits/napi/src/cm_napi_get_app_cert_list_common.cpp b/interfaces/kits/napi/src/cm_napi_get_app_cert_list_common.cpp index a9f109364cf7090f050ff9137366889a3bca4529..4e911043190feb676c58d5ffff76dc4d4f3009e5 100644 --- a/interfaces/kits/napi/src/cm_napi_get_app_cert_list_common.cpp +++ b/interfaces/kits/napi/src/cm_napi_get_app_cert_list_common.cpp @@ -160,58 +160,6 @@ napi_value GetAppCertListAsyncWork(napi_env env, GetAppCertListAsyncContext asyn return promise; } -napi_value GetCallingAppCertListAsyncWork(napi_env env, GetAppCertListAsyncContext asyncContext) -{ - napi_value promise = nullptr; - GenerateNapiPromise(env, asyncContext->callback, &asyncContext->deferred, &promise); - - napi_value resourceName = nullptr; - NAPI_CALL(env, napi_create_string_latin1(env, "GetCallingAppCertListAsyncWork", NAPI_AUTO_LENGTH, &resourceName)); - - NAPI_CALL(env, napi_create_async_work( - env, - nullptr, - resourceName, - [](napi_env env, void *information) { - GetAppCertListAsyncContext mcontext = static_cast(information); - - mcontext->credentialList = static_cast(CmMalloc(sizeof(struct CredentialList))); - if (mcontext->credentialList != nullptr) { - InitAppCertList(mcontext->credentialList); - } - mcontext->result = CmCallingGetAppCertList(mcontext->store, mcontext->credentialList); - }, - [](napi_env env, napi_status status, void *information) { - GetAppCertListAsyncContext mcontext = static_cast(information); - napi_value res[RESULT_NUMBER] = { nullptr }; - if (mcontext->result == CM_SUCCESS) { - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, 0, &res[0])); - res[1] = GetAppCertListWriteResult(env, mcontext); - } else { - res[0] = GenerateBusinessError(env, mcontext->result); - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &res[1])); - } - if (mcontext->deferred != nullptr) { - GeneratePromise(env, mcontext->deferred, mcontext->result, res, CM_ARRAY_SIZE(res)); - } else { - GenerateCallback(env, mcontext->callback, res, CM_ARRAY_SIZE(res), mcontext->result); - } - DeleteGetAppCertListAsyncContext(env, mcontext); - CM_LOG_D("get calling app cert list end"); - }, - static_cast(asyncContext), - &asyncContext->asyncWork)); - - napi_status status = napi_queue_async_work(env, asyncContext->asyncWork); - if (status != napi_ok) { - GET_AND_THROW_LAST_ERROR((env)); - DeleteGetAppCertListAsyncContext(env, asyncContext); - CM_LOG_E("get calling app cert list could not queue async work"); - return nullptr; - } - return promise; -} - napi_value CMNapiGetAppCertListCommon(napi_env env, napi_callback_info info, uint32_t store) { GetAppCertListAsyncContext context = CreateGetAppCertListAsyncContext(); @@ -236,29 +184,4 @@ napi_value CMNapiGetAppCertListCommon(napi_env env, napi_callback_info info, uin } return result; } - -napi_value CMNapiGetCallingAppCertListCommon(napi_env env, napi_callback_info info, uint32_t store) -{ - GetAppCertListAsyncContext context = CreateGetAppCertListAsyncContext(); - if (context == nullptr) { - CM_LOG_E("could not create context"); - return nullptr; - } - - context->store = store; - - napi_value result = GetAppCertListParseParams(env, info, context); - if (result == nullptr) { - CM_LOG_E("could not parse params"); - DeleteGetAppCertListAsyncContext(env, context); - return nullptr; - } - result = GetCallingAppCertListAsyncWork(env, context); - if (result == nullptr) { - CM_LOG_E("could not start async work"); - DeleteGetAppCertListAsyncContext(env, context); - return nullptr; - } - return result; -} } // namespace CertManagerNapi diff --git a/interfaces/kits/napi/src/dialog/cm_napi_dialog.cpp b/interfaces/kits/napi/src/dialog/cm_napi_dialog.cpp deleted file mode 100644 index 6c839cca48682235c9c797ac13cabad2230e91bc..0000000000000000000000000000000000000000 --- a/interfaces/kits/napi/src/dialog/cm_napi_dialog.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "napi/native_api.h" -#include "napi/native_node_api.h" - -#include "cm_napi_common.h" - -#include "cm_napi_open_dialog.h" - -namespace CMNapi { -inline void AddInt32Property(napi_env env, napi_value object, const char *name, int32_t value) -{ - napi_value property = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, value, &property)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, object, name, property)); -} - -static napi_value CreateCmErrorCode(napi_env env) -{ - napi_value dialogErrorCode = nullptr; - NAPI_CALL(env, napi_create_object(env, &dialogErrorCode)); - - AddInt32Property(env, dialogErrorCode, "ERROR_GENERIC", DIALOG_ERROR_GENERIC); - AddInt32Property(env, dialogErrorCode, "ERROR_OPERATION_CANCELED", DIALOG_ERROR_OPERATION_CANCELED); - - return dialogErrorCode; -} - -static napi_value CreateCmDialogPageType(napi_env env) -{ - napi_value dialogPageType = nullptr; - NAPI_CALL(env, napi_create_object(env, &dialogPageType)); - - AddInt32Property(env, dialogPageType, "PAGE_MAIN", PAGE_MAIN); - AddInt32Property(env, dialogPageType, "PAGE_CA_CERTIFICATE", PAGE_CA_CERTIFICATE); - AddInt32Property(env, dialogPageType, "PAGE_CREDENTIAL", PAGE_CREDENTIAL); - AddInt32Property(env, dialogPageType, "PAGE_INSTALL_CERTIFICATE", PAGE_INSTALL_CERTIFICATE); - - return dialogPageType; -} -} // namespace CertManagerNapi - -using namespace CMNapi; - -extern "C" { -static napi_value CMDialogNapiRegister(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - DECLARE_NAPI_PROPERTY("CertificateDialogErrorCode", CreateCmErrorCode(env)), - DECLARE_NAPI_PROPERTY("CertificateDialogPageType", CreateCmDialogPageType(env)), - - /* dialog */ - DECLARE_NAPI_FUNCTION("openCertificateManagerDialog", CMNapiOpenCertManagerDialog), - }; - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); - return exports; -} - -static napi_module g_module = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = CMDialogNapiRegister, - .nm_modname = "security.certManagerDialog", - .nm_priv = nullptr, - .reserved = { nullptr }, -}; - -__attribute__((constructor)) void CMDialogNapiRegister(void) -{ - napi_module_register(&g_module); -} -} diff --git a/interfaces/kits/napi/src/dialog/cm_napi_open_dialog.cpp b/interfaces/kits/napi/src/dialog/cm_napi_open_dialog.cpp deleted file mode 100644 index 654a08aa0ebdaebd0ab12131ac9d85ad553fc930..0000000000000000000000000000000000000000 --- a/interfaces/kits/napi/src/dialog/cm_napi_open_dialog.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "cm_napi_open_dialog.h" - -#include "securec.h" - -#include "cert_manager_api.h" -#include "cm_log.h" - -#include "cm_napi_common.h" -#include "want.h" -#include "want_params_wrapper.h" - -namespace CMNapi { -namespace { -const std::string PARAM_UI_EXTENSION_TYPE = "ability.want.params.uiExtensionType"; -const std::string SYS_COMMON_UI = "sys/commonUI"; -const std::string CERT_MANAGER_BUNDLENAME = "com.ohos.certmanager"; -const std::string CERT_MANAGER_ABILITYNAME = "CertPickerUIExtAbility"; -const std::string CERT_MANAGER_PAGE_TYPE = "pageType"; -constexpr int32_t PARAM0 = 0; -constexpr int32_t PARAM1 = 1; -constexpr int32_t PARAM_SIZE_TWO = 2; -constexpr int32_t ERROR_STR_LEN = 256; -} // namespace - -CommonAsyncContext::CommonAsyncContext(napi_env env) -{ - CM_LOG_D("CommonAsyncContext"); - this->env = env; -} - -CommonAsyncContext::~CommonAsyncContext() -{ - CM_LOG_D("~CommonAsyncContext"); -} - -CmUIExtensionCallback::CmUIExtensionCallback(std::shared_ptr& reqContext) -{ - this->reqContext_ = reqContext; -} - -void CmUIExtensionCallback::SetSessionId(const int32_t sessionId) -{ - this->sessionId_ = sessionId; -} - -bool CmUIExtensionCallback::SetErrorCode(int32_t code) -{ - if (this->reqContext_ == nullptr) { - CM_LOG_E("OnError reqContext is nullptr"); - return false; - } - if (this->alreadyCallback_) { - CM_LOG_D("alreadyCallback"); - return false; - } - this->alreadyCallback_ = true; - this->reqContext_->errCode = code; - return true; -} - -void CmUIExtensionCallback::OnRelease(const int32_t releaseCode) -{ - CM_LOG_D("UIExtensionComponent OnRelease(), releaseCode = %d", releaseCode); - if (SetErrorCode(releaseCode)) { - SendMessageBack(); - } -} - -void CmUIExtensionCallback::OnResult(const int32_t resultCode, const OHOS::AAFwk::Want& result) -{ - CM_LOG_D("UIExtensionComponent OnResult(), resultCode = %d", resultCode); - this->resultCode_ = resultCode; - this->resultWant_ = result; - if (SetErrorCode(0)) { - SendMessageBack(); - } -} - -void CmUIExtensionCallback::OnReceive(const OHOS::AAFwk::WantParams& request) -{ - CM_LOG_D("UIExtensionComponent OnReceive()"); - if (SetErrorCode(0)) { - SendMessageBack(); - } -} - -void CmUIExtensionCallback::OnError(const int32_t errorCode, const std::string& name, const std::string& message) -{ - CM_LOG_E("UIExtensionComponent OnError(), errorCode = %d, name = %s, message = %s", - errorCode, name.c_str(), message.c_str()); - if (SetErrorCode(errorCode)) { - SendMessageBack(); - } - char errStr[ERROR_STR_LEN] = { 0 }; - if (sprintf_s(errStr, ERROR_STR_LEN, "UIExtensionComponent OnError(), errorCode = %d, name = %s, message = %s", - errorCode, name.c_str(), message.c_str()) < 0) { - CM_LOG_E("copy error str failed"); - return; - } - ThrowError(this->reqContext_->env, PARAM_ERROR, errStr); -} - -void CmUIExtensionCallback::OnRemoteReady(const std::shared_ptr& uiProxy) -{ - CM_LOG_D("UIExtensionComponent OnRemoteReady()"); -} - -void CmUIExtensionCallback::OnDestroy() -{ - CM_LOG_D("UIExtensionComponent OnDestroy()"); - if (SetErrorCode(0)) { - SendMessageBack(); - } -} - -void ProcessCallback(napi_env env, const CommonAsyncContext* asyncContext) -{ - napi_value args[PARAM_SIZE_TWO] = {nullptr}; - - if (asyncContext->errCode == CM_SUCCESS) { - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, 0, &args[PARAM0])); - NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, true, &args[PARAM1])); - } else { - args[PARAM0] = GenerateBusinessError(env, asyncContext->errCode); - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &args[PARAM1])); - } - - if (asyncContext->deferred != nullptr) { - GeneratePromise(env, asyncContext->deferred, asyncContext->errCode, args, CM_ARRAY_SIZE(args)); - } -} - -void CmUIExtensionCallback::SendMessageBack() -{ - CM_LOG_I("start SendMessageBack"); - if (this->reqContext_ == nullptr) { - CM_LOG_E("reqContext is nullptr"); - return; - } - - auto abilityContext = this->reqContext_->context; - if (abilityContext != nullptr) { - auto uiContent = abilityContext->GetUIContent(); - if (uiContent != nullptr) { - CM_LOG_D("CloseModalUIExtension"); - uiContent->CloseModalUIExtension(this->sessionId_); - } - } - - CM_LOG_D("ProcessCallback"); - ProcessCallback(this->reqContext_->env, this->reqContext_.get()); -} - -bool ParseCmUIAbilityContextReq( - napi_env env, const napi_value& obj, std::shared_ptr& abilityContext) -{ - bool stageMode = false; - napi_status status = OHOS::AbilityRuntime::IsStageContext(env, obj, stageMode); - if (status != napi_ok || !stageMode) { - CM_LOG_E("not stage mode"); - return false; - } - - auto context = OHOS::AbilityRuntime::GetStageModeContext(env, obj); - if (context == nullptr) { - CM_LOG_E("get context failed"); - return false; - } - - abilityContext = OHOS::AbilityRuntime::Context::ConvertTo(context); - if (abilityContext == nullptr) { - CM_LOG_E("get abilityContext failed"); - return false; - } - CM_LOG_I("end ParseUIAbilityContextReq"); - return true; -} - -static void StartUIExtensionAbility(std::shared_ptr asyncContext, - OHOS::AAFwk::Want want) -{ - CM_LOG_D("begin StartUIExtensionAbility"); - if (asyncContext == nullptr) { - CM_LOG_E("asyncContext is null"); - ThrowError(asyncContext->env, PARAM_ERROR, "asyncContext is null"); - return; - } - auto abilityContext = asyncContext->context; - if (abilityContext == nullptr) { - CM_LOG_E("abilityContext is null"); - ThrowError(asyncContext->env, PARAM_ERROR, "abilityContext is null"); - return; - } - auto uiContent = abilityContext->GetUIContent(); - if (uiContent == nullptr) { - CM_LOG_E("uiContent is null"); - ThrowError(asyncContext->env, PARAM_ERROR, "uiContent is null"); - return; - } - - auto uiExtCallback = std::make_shared(asyncContext); - OHOS::Ace::ModalUIExtensionCallbacks extensionCallbacks = { - [uiExtCallback](int32_t releaseCode) { uiExtCallback->OnRelease(releaseCode); }, - [uiExtCallback](int32_t resultCode, const OHOS::AAFwk::Want& result) { - uiExtCallback->OnResult(resultCode, result); }, - [uiExtCallback](const OHOS::AAFwk::WantParams& request) { uiExtCallback->OnReceive(request); }, - [uiExtCallback](int32_t errorCode, const std::string& name, const std::string& message) { - uiExtCallback->OnError(errorCode, name, message); }, - [uiExtCallback](const std::shared_ptr& uiProxy) { - uiExtCallback->OnRemoteReady(uiProxy); }, - [uiExtCallback]() { uiExtCallback->OnDestroy(); } - }; - - OHOS::Ace::ModalUIExtensionConfig uiExtConfig; - uiExtConfig.isProhibitBack = false; - int32_t sessionId = uiContent->CreateModalUIExtension(want, extensionCallbacks, uiExtConfig); - CM_LOG_I("end CreateModalUIExtension sessionId = %d", sessionId); - if (sessionId == 0) { - CM_LOG_E("CreateModalUIExtension failed, sessionId is %d", sessionId); - ThrowError(asyncContext->env, PARAM_ERROR, "CreateModalUIExtension failed"); - } - uiExtCallback->SetSessionId(sessionId); - return; -} - -napi_value CMNapiOpenCertManagerDialog(napi_env env, napi_callback_info info) -{ - CM_LOG_I("cert manager dialog enter"); - size_t argc = PARAM_SIZE_TWO; - napi_value argv[PARAM_SIZE_TWO] = { nullptr }; - napi_value result = nullptr; - NAPI_CALL(env, napi_get_undefined(env, &result)); - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); - if (argc != PARAM_SIZE_TWO) { - CM_LOG_E("params number mismatch"); - std::string errMsg = "Parameter Error. Params number mismatch, need " + std::to_string(PARAM_SIZE_TWO) - + ", given " + std::to_string(argc); - ThrowError(env, PARAM_ERROR, errMsg); - return result; - } - - // Parse first argument for context. - auto asyncContext = std::make_shared(env); - if (!ParseCmUIAbilityContextReq(env, argv[PARAM0], asyncContext->context)) { - CM_LOG_E("ParseUIAbilityContextReq failed"); - ThrowError(env, PARAM_ERROR, "Get context failed."); - return result; - } - - // Parse second argument for page type. - result = ParseUint32(env, argv[PARAM1], asyncContext->pageType); - if (result == nullptr) { - CM_LOG_E("parse type failed"); - ThrowError(env, PARAM_ERROR, "parse type failed"); - return result; - } - - asyncContext->env = env; - OHOS::AAFwk::Want want; - want.SetElementName(CERT_MANAGER_BUNDLENAME, CERT_MANAGER_ABILITYNAME); - want.SetParam(CERT_MANAGER_PAGE_TYPE, static_cast(asyncContext->pageType)); - want.SetParam(PARAM_UI_EXTENSION_TYPE, SYS_COMMON_UI); - NAPI_CALL(env, napi_create_promise(env, &asyncContext->deferred, &result)); - - // Start ui extension by context. - StartUIExtensionAbility(asyncContext, want); - CM_LOG_D("cert manager dialog end"); - return result; -} -} // namespace CMNapi - diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager.h b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager.h index 1f9cbb51a6320a54c3c38ea1c402015c0ce56562..2fbd3d876e1a532aa911174f4405fdc7059662b6 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager.h +++ b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager.h @@ -43,9 +43,6 @@ int32_t CmRemoveAllAppCert(const struct CmContext *context); int32_t CmServiceGetAppCertList(const struct CmContext *context, uint32_t store, struct CmBlob *fileNames, const uint32_t fileSize, uint32_t *fileCount); -int32_t CmServiceGetCallingAppCertList(const struct CmContext *context, uint32_t store, struct CmBlob *fileNames, - const uint32_t fileSize, uint32_t *fileCount); - void CmFreeFileNames(struct CmBlob *fileNames, const uint32_t fileSize); int32_t CmGetUri(const char *filePath, struct CmBlob *uriBlob); diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_check.h b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_check.h index 863bf81d368a12b11060e955aa22a52482c60006..02e8d0372999d4c60b59df8cb9327bd9c7229546 100755 --- a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_check.h +++ b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_check.h @@ -37,8 +37,6 @@ int32_t CmServiceUninstallAppCertCheck(struct CmContext *cmContext, const uint32 int32_t CmServiceGetAppCertListCheck(const struct CmContext *cmContext, const uint32_t store); -int32_t CmServiceGetCallingAppCertListCheck(const struct CmContext *cmContext, const uint32_t store); - int32_t CmServiceGetAppCertCheck(struct CmContext *cmContext, const uint32_t store, const struct CmBlob *keyUri); int32_t CmServiceInstallUserCertCheck(struct CmContext *cmContext, const struct CmBlob *userCert, diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c index c704364b92f53b6f11fa3ec85d699de76341b94d..c071d0d3b11d69b52c91de1f7b3d778fc1de7edd 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c +++ b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager.c @@ -286,36 +286,6 @@ static int32_t CmAppCertGetFilePath(const struct CmContext *context, const uint3 return CM_SUCCESS; } -static int32_t CmCallingAppCertGetFilePath(const struct CmContext *context, const uint32_t store, struct CmBlob *path) -{ - int32_t ret = CM_FAILURE; - - switch (store) { - case CM_CREDENTIAL_STORE : - ret = sprintf_s((char*)path->data, MAX_PATH_LEN, "%s%u/%u", - CREDNTIAL_STORE, context->userId, context->uid); - break; - case CM_PRI_CREDENTIAL_STORE : - ret = sprintf_s((char*)path->data, MAX_PATH_LEN, "%s%u/%u", - APP_CA_STORE, context->userId, context->uid); - break; - case CM_SYS_CREDENTIAL_STORE: - ret = sprintf_s((char *)path->data, MAX_PATH_LEN, "%s%u/%u", - SYS_CREDNTIAL_STORE, context->userId, context->uid); - break; - case CM_USER_TRUSTED_STORE: - ret = sprintf_s((char *)path->data, MAX_PATH_LEN, "%s%u/%u", - USER_CA_STORE, context->userId, context->uid); - break; - default: - break; - } - if (ret < 0) { - return CM_FAILURE; - } - return CM_SUCCESS; -} - void CmFreeFileNames(struct CmBlob *fileNames, const uint32_t fileSize) { if (fileNames == NULL) { @@ -484,27 +454,6 @@ int32_t CmServiceGetAppCertList(const struct CmContext *context, uint32_t store, return CM_SUCCESS; } -int32_t CmServiceGetCallingAppCertList(const struct CmContext *context, uint32_t store, struct CmBlob *fileNames, - const uint32_t fileSize, uint32_t *fileCount) -{ - char pathBuf[CERT_MAX_PATH_LEN] = {0}; - struct CmBlob path = { sizeof(pathBuf), (uint8_t*)pathBuf }; - - int32_t ret = CmCallingAppCertGetFilePath(context, store, &path); - if (ret != CM_SUCCESS) { - CM_LOG_E("Get file path for store:%u faild", store); - return CM_FAILURE; - } - - ret = CmUidLayerGetFileCountAndNames(pathBuf, fileNames, fileSize, fileCount); - if (ret != CM_SUCCESS) { - CM_LOG_E("Get file count and names from path faild ret:%d", ret); - return ret; - } - - return CM_SUCCESS; -} - static int32_t GetCertOrCredCount(const struct CmContext *context, const uint32_t store, uint32_t *certCount) { uint32_t fileCount = 0; diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_check.c b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_check.c index 622222c1089854ef8a175f7fff7f1ffd65b3a864..40b804ed59e2e69741c5ac25d710571270e1b5d3 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_check.c +++ b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_check.c @@ -359,39 +359,6 @@ int32_t CmServiceGetAppCertListCheck(const struct CmContext *cmContext, const ui return CM_SUCCESS; } -int32_t CmServiceGetCallingAppCertListCheck(const struct CmContext *cmContext, const uint32_t store) -{ - if (CM_STORE_CHECK(store)) { - CM_LOG_E("invalid input arguments store:%u", store); - return CMR_ERROR_INVALID_ARGUMENT; - } - - if (store == CM_SYS_CREDENTIAL_STORE) { - return CmGetSysAppCertListCheck(cmContext, store); - } - - if (!CmHasCommonPermission()) { - CM_LOG_E("permission check failed"); - return CMR_ERROR_PERMISSION_DENIED; - } - - if (store == CM_PRI_CREDENTIAL_STORE) { - return CM_SUCCESS; - } - - if (!CmHasPrivilegedPermission()) { - CM_LOG_E("permission check failed"); - return CMR_ERROR_PERMISSION_DENIED; - } - - if (!CmIsSystemApp()) { - CM_LOG_E("get app cert list: caller is not system app"); - return CMR_ERROR_NOT_SYSTEMP_APP; - } - - return CM_SUCCESS; -} - int32_t CmServiceGetAppCertCheck(struct CmContext *cmContext, const uint32_t store, const struct CmBlob *keyUri) { if (CM_STORE_CHECK(store)) { diff --git a/services/cert_manager_standard/cert_manager_service.cfg b/services/cert_manager_standard/cert_manager_service.cfg index 09ee859e86ff03cdf107b99c39de129dea0c4b09..193d499326356c6634548ab25296cd403451c456 100644 --- a/services/cert_manager_standard/cert_manager_service.cfg +++ b/services/cert_manager_standard/cert_manager_service.cfg @@ -2,9 +2,9 @@ "jobs" : [{ "name" : "post-fs-data", "cmds" : [ - "mkdir /data/service/el1/public/cert_manager_service 0700 cert_manager_server cert_manager_server", + "mkdir /data/service/el1/public/cert_manager_service 0701 cert_manager_server cert_manager_server", "mkdir /data/service/el1/public/cert_manager_service/status 0700 cert_manager_server cert_manager_server", - "mkdir /data/service/el1/public/cert_manager_service/certificates 0700 cert_manager_server cert_manager_server", + "mkdir /data/service/el1/public/cert_manager_service/certificates 0701 cert_manager_server cert_manager_server", "mkdir /data/service/el1/public/cert_manager_service/certificates/credential 0700 cert_manager_server cert_manager_server", "mkdir /data/service/el1/public/cert_manager_service/certificates/user 0700 cert_manager_server cert_manager_server", "mkdir /data/service/el1/public/cert_manager_service/certificates/priv_credential 0700 cert_manager_server cert_manager_server", diff --git a/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.c b/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.c index 2648db5d6a41dd68bfe2db2ed2cb7b4bb4e4070f..19e63bc26670a0e45805b716bf8f9362525a9de4 100644 --- a/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.c +++ b/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.c @@ -491,56 +491,6 @@ void CmIpcServiceGetAppCertList(const struct CmBlob *paramSetBlob, struct CmBlob CM_LOG_D("CmIpcServiceGetAppCertList end:%d", ret); } -void CmIpcServiceGetCallingAppCertList(const struct CmBlob *paramSetBlob, struct CmBlob *outData, - const struct CmContext *context) -{ - int32_t ret; - (void)outData; - uint32_t store; - uint32_t fileCount = 0; - struct CmContext cmContext = {0}; - struct CmBlob certificateList = { 0, NULL }; - struct CmBlob fileNamesBlob[MAX_COUNT_CERTIFICATE]; - uint32_t len = MAX_COUNT_CERTIFICATE * sizeof(struct CmBlob); - (void)memset_s(fileNamesBlob, len, 0, len); - struct CmParamSet *paramSets = NULL; - struct CmParamOut params[] = { - { .tag = CM_TAG_PARAM0_UINT32, .uint32Param = &store }, - }; - - do { - ret = GetInputParams(paramSetBlob, ¶mSets, &cmContext, params, CM_ARRAY_SIZE(params)); - if (ret != CM_SUCCESS) { - CM_LOG_E("CmIpcServiceGetCallingAppCertList get input params failed, ret = %d", ret); - break; - } - - ret = CmServiceGetCallingAppCertListCheck(&cmContext, store); - if (ret != CM_SUCCESS) { - CM_LOG_E("CmServiceGetCallingAppCertListCheck fail, ret = %d", ret); - break; - } - - ret = CmServiceGetCallingAppCertList(&cmContext, store, fileNamesBlob, MAX_COUNT_CERTIFICATE, &fileCount); - if (ret != CM_SUCCESS) { - CM_LOG_E("Get calling App cert list fail, ret = %d", ret); - break; - } - - ret = CmServiceGetAppCertListPack(&certificateList, fileNamesBlob, fileCount); - if (ret != CM_SUCCESS) { - CM_LOG_E("CmServiceGetAppCertListPack pack fail, ret = %d", ret); - } - } while (0); - - CmReport(__func__, &cmContext, NULL, ret); - CmSendResponse(context, ret, &certificateList); - CmFreeParamSet(¶mSets); - CmFreeFileNames(fileNamesBlob, fileCount); - CM_FREE_BLOB(certificateList); - CM_LOG_D("CmServiceGetCallingAppCertListCheck end:%d", ret); -} - static int32_t CopyCertificateInfoToBuffer(const struct CmBlob *certBlob, const struct CmBlob *certificateInfo, uint32_t *offset) { diff --git a/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.h b/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.h index 7f93f037725be91750e91f651c32cca90eab2dd5..a7a4e3bdcad68612f4dfa95301f722dcb07b5dd9 100644 --- a/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.h +++ b/services/cert_manager_standard/cert_manager_service/main/os_dependency/idl/cm_ipc/cm_ipc_service.h @@ -43,9 +43,6 @@ void CmIpcServiceUninstallAllAppCert(const struct CmBlob *paramSetBlob, struct C void CmIpcServiceGetAppCertList(const struct CmBlob *paramSetBlob, struct CmBlob *outData, const struct CmContext *context); -void CmIpcServiceGetCallingAppCertList(const struct CmBlob *paramSetBlob, struct CmBlob *outData, - const struct CmContext *context); - void CmIpcServiceGetAppCert(const struct CmBlob *paramSetBlob, struct CmBlob *outData, const struct CmContext *context); diff --git a/services/cert_manager_standard/cert_manager_service/main/os_dependency/sa/cm_sa.cpp b/services/cert_manager_standard/cert_manager_service/main/os_dependency/sa/cm_sa.cpp index 32e472b6abef25abb914838f9df5a5688d956c4c..384a612caded5045de2983d6b8f45133316a53ad 100644 --- a/services/cert_manager_standard/cert_manager_service/main/os_dependency/sa/cm_sa.cpp +++ b/services/cert_manager_standard/cert_manager_service/main/os_dependency/sa/cm_sa.cpp @@ -63,7 +63,6 @@ static struct CmIpcPoint g_cmIpcHandler[] = { { CM_MSG_UNINSTALL_APP_CERTIFICATE, CmIpcServiceUninstallAppCert }, { CM_MSG_UNINSTALL_ALL_APP_CERTIFICATE, CmIpcServiceUninstallAllAppCert }, { CM_MSG_GET_APP_CERTIFICATE_LIST, CmIpcServiceGetAppCertList }, - { CM_MSG_GET_CALLING_APP_CERTIFICATE_LIST, CmIpcServiceGetCallingAppCertList }, { CM_MSG_GET_APP_CERTIFICATE, CmIpcServiceGetAppCert }, { CM_MSG_GRANT_APP_CERT, CmIpcServiceGrantAppCertificate }, diff --git a/test/unittest/src/cm_app_cert_test.cpp b/test/unittest/src/cm_app_cert_test.cpp index 45234d57a78caea17edcdebd9fb2129e6002920e..e601374e5f5c09e8922f9dff511ba29996c3d9fe 100644 --- a/test/unittest/src/cm_app_cert_test.cpp +++ b/test/unittest/src/cm_app_cert_test.cpp @@ -526,49 +526,6 @@ HWTEST_F(CmAppCertTest, CmGetAppCertListAbnormalTest004, TestSize.Level0) } } -/** - * @tc.name: CmGetCallingAppCertListPriCert005 - * @tc.desc: Test CertManager get app cert list interface own private - * @tc.type: FUNC - * @tc.require: AR000H0MI8 /SR000H09N9 - */ -HWTEST_F(CmAppCertTest, CmGetCallingAppCertListPriCert005, TestSize.Level0) -{ - uint8_t certAliasBuf[] = "OtherKeyA"; - struct CmBlob certAlias = { sizeof(certAliasBuf), certAliasBuf }; - - uint8_t uriBuf[MAX_LEN_URI] = {0}; - struct CmBlob keyUri = { sizeof(uriBuf), uriBuf }; - - int32_t ret = CmInstallAppCert(&g_appCert, &g_appCertPwd, &certAlias, CM_PRI_CREDENTIAL_STORE, &keyUri); - EXPECT_EQ(ret, CM_SUCCESS) << "CmGetCallingAppCertListPriCert005 install failed, retcode:" << ret; - - struct CredentialList certificateList = { 0, nullptr }; - uint32_t buffSize = MAX_COUNT_CERTIFICATE * sizeof(struct CredentialAbstract); - certificateList.credentialAbstract = static_cast(CmMalloc(buffSize)); - ASSERT_TRUE(certificateList.credentialAbstract != nullptr); - certificateList.credentialCount = MAX_COUNT_CERTIFICATE; - (void)memset_s(certificateList.credentialAbstract, buffSize, 0, buffSize); - - ret = CmCallingGetAppCertList(CM_PRI_CREDENTIAL_STORE, &certificateList); - EXPECT_EQ(ret, CM_SUCCESS) << "CmGetCallingAppCertListPriCert005 test failed, retcode:" << ret; - - struct CredentialAbstractResult expectList[] = { - { - { "ak", "OtherKeyA", "oh:t=ak;o=keyA;u=100;a=500" }, false - } - }; - uint32_t length = sizeof(expectList) / sizeof(expectList[0]); - for (uint32_t j = 0; j < length; ++j) { - bool bFind = FindCredentialAbstract(&(expectList[j].credentialAbstract), &certificateList); - EXPECT_EQ(bFind, expectList[j].bExpectResult); - } - - if (certificateList.credentialAbstract != nullptr) { - CmFree(certificateList.credentialAbstract); - } -} - /** * @tc.name: AppCertUnInstallBaseTest001 * @tc.desc: Test CertManager unInstall app cert interface base function