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 a6e1f1cb63845fb22a7bcf3a1c0f36ea8ebb65a3..cbb47b2d92bf5a1eae047db30ac610376f8653dc 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 @@ -47,6 +47,7 @@ enum CertManagerInterfaceCode { CM_MSG_INSTALL_USER_CERTIFICATE, CM_MSG_UNINSTALL_USER_CERTIFICATE, CM_MSG_UNINSTALL_ALL_USER_CERTIFICATE, + CM_MSG_GET_TARGET_USER_CERTIFICATE_LIST, /* new cmd type must be added before CM_MSG_MAX */ CM_MSG_MAX, 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..b5abb21a614e099494bfb05b2ac4fed4ae0fd9d9 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 @@ -63,6 +63,8 @@ int32_t CmClientAbort(const struct CmBlob *handle); int32_t CmClientGetUserCertList(const uint32_t store, struct CertList *certificateList); +int32_t CmClientGetTarUserCertList(const uint32_t userId, struct CertList *certificateList); + int32_t CmClientGetUserCertInfo(const struct CmBlob *certUri, const uint32_t store, struct CertInfo *certificateInfo); 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..a2486f943d17d9b9ee687172ef5a52f3ff4ceb23 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 @@ -862,11 +862,58 @@ static int32_t GetUserCertList(enum CertManagerInterfaceCode type, const uint32_ return ret; } +static int32_t GetTarUserCertList(enum CertManagerInterfaceCode type, const uint32_t userId, + struct CertList *certificateList) +{ + int32_t ret = CM_SUCCESS; + struct CmBlob outBlob = {0, NULL}; + struct CmBlob parcelBlob = {0, NULL}; + struct CmParamSet *sendParamSet = NULL; + struct CmParam params[] = { + { .tag = CM_TAG_PARAM0_UINT32, .uint32Param = userId }, + }; + + do { + ret = CmSendParcelInit(params, CM_ARRAY_SIZE(params), &parcelBlob, &sendParamSet); + if (ret != CM_SUCCESS) { + CM_LOG_E("get cert list sendParcel failed"); + break; + } + + ret = GetCertListInitOutData(&outBlob); + if (ret != CM_SUCCESS) { + CM_LOG_E("malloc getcertlist outdata failed"); + break; + } + + ret = SendRequest(type, &parcelBlob, &outBlob); + if (ret != CM_SUCCESS) { + CM_LOG_E("GetCertList request failed, ret: %d", ret); + break; + } + + ret = CmCertificateListUnpackFromService(&outBlob, certificateList); + if (ret != CM_SUCCESS) { + CM_LOG_E("getcertlist unpack from service failed"); + break; + } + } while (0); + + CmFreeParamSet(&sendParamSet); + CM_FREE_BLOB(outBlob); + return ret; +} + int32_t CmClientGetUserCertList(const uint32_t store, struct CertList *certificateList) { return GetUserCertList(CM_MSG_GET_USER_CERTIFICATE_LIST, store, certificateList); } +int32_t CmClientGetTarUserCertList(const uint32_t userId, struct CertList *certificateList) +{ + return GetTarUserCertList(CM_MSG_GET_TARGET_USER_CERTIFICATE_LIST, userId, certificateList); +} + static int32_t GetUserCertInfo(enum CertManagerInterfaceCode type, const struct CmBlob *certUri, const uint32_t store, struct CertInfo *userCertInfo) { 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..66b7d7c6af816282956dd2e065ea2c5979caac3d 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 @@ -61,6 +61,8 @@ CM_API_EXPORT int32_t CmAbort(const struct CmBlob *handle); CM_API_EXPORT int32_t CmGetUserCertList(uint32_t store, struct CertList *certificateList); +CM_API_EXPORT int32_t CmGetTarUserCertList(uint32_t userId, struct CertList *certificateList); + CM_API_EXPORT int32_t CmGetUserCertInfo(const struct CmBlob *certUri, uint32_t store, struct CertInfo *certificateInfo); 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..1a5cfda16d8587758fe8b37c8673363aa39f66ef 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 @@ -267,6 +267,18 @@ CM_API_EXPORT int32_t CmGetUserCertList(uint32_t store, struct CertList *certifi return ret; } +CM_API_EXPORT int32_t CmGetTarUserCertList(uint32_t userId, struct CertList *certificateList) +{ + CM_LOG_D("enter get target user cert list"); + if (certificateList == NULL) { + return CMR_ERROR_NULL_POINTER; + } + + int32_t ret = CmClientGetTarUserCertList(userId, certificateList); + CM_LOG_D("leave get cert list, result = %d", ret); + return ret; +} + CM_API_EXPORT int32_t CmGetUserCertInfo(const struct CmBlob *certUri, uint32_t store, struct CertInfo *certificateInfo) { CM_LOG_D("enter get cert info"); diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_service.h b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_service.h index d15122c0f503d9a5fc26b9b6da92f85886ec4d06..c566b2fb72093c720d26affa22fb84e5ebcb6bff 100755 --- a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_service.h +++ b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_service.h @@ -53,6 +53,8 @@ int32_t CmServiceAbort(const struct CmContext *context, const struct CmBlob *han int32_t CmServiceGetCertList(const struct CmContext *context, uint32_t store, struct CmMutableBlob *certFileList); +int32_t CmServiceGetTarCertList(const struct CmContext *context, uint32_t userId, struct CmMutableBlob *certFileList); + int32_t CmServiceGetCertInfo(struct CmContext *context, const struct CmBlob *certUri, uint32_t store, struct CmBlob *certificateData, uint32_t *status); diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_service.c b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_service.c index ad9328cf2d0e1d92095d8dd371d845d93ea78d3f..9a9c314e727529751220c7530e6f2f5633b5539e 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_service.c +++ b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_service.c @@ -431,6 +431,36 @@ static int32_t CmGetUserCertPathList(const struct CmContext *context, uint32_t s return ret; } +static int32_t CmGetTarUserCertPathList(const struct CmContext *context, uint32_t userId, struct CmMutableBlob *pathList) +{ + int32_t ret = CM_SUCCESS; + struct CmMutableBlob targetUserPathList = { 0, NULL }; + struct CmMutableBlob nullUserPathList = { 0, NULL }; + + /* update target userid */ + struct CmContext userContext = { userId, context->uid, {0} }; + do { + ret = CmGetCertPathList(&userContext, CM_USER_TRUSTED_STORE, &targetUserPathList); + if (ret != CM_SUCCESS) { + CM_LOG_E("get target user certPathList fail, ret = %d", ret); + break; + } + + + /* merge callerPathList and sysServicePathList */ + ret = MergeUserPathList(&targetUserPathList, &nullUserPathList, pathList); + if (ret != CM_SUCCESS) { + CM_LOG_E("merge target cert path list failed"); + break; + } + } while (0); + + if (targetUserPathList.data != NULL) { + CmFreePathList((struct CmMutableBlob *)targetUserPathList.data, targetUserPathList.size); + } + return ret; +} + int32_t CmServiceGetCertList(const struct CmContext *context, uint32_t store, struct CmMutableBlob *certFileList) { int32_t ret = CM_SUCCESS; @@ -470,6 +500,33 @@ int32_t CmServiceGetCertList(const struct CmContext *context, uint32_t store, st return ret; } +int32_t CmServiceGetTarCertList(const struct CmContext *context, uint32_t userId, struct CmMutableBlob *certFileList) +{ + int32_t ret = CM_SUCCESS; + struct CmMutableBlob pathList = { 0, NULL }; /* uid path list */ + + do { + /* get all uid path for caller and system service */ + ret = CmGetTarUserCertPathList(context, userId, &pathList); + if (ret != CM_SUCCESS) { + CM_LOG_E("GetTarUserCertPathList fail, ret = %d", ret); + break; + } + + /* create certFilelist(path + name) */ + ret = CreateCertFileList(&pathList, certFileList); + if (ret != CM_SUCCESS) { + CM_LOG_E("CreateCertFileList fail, ret = %d", ret); + break; + } + } while (0); + + if (pathList.data != NULL) { + CmFreePathList((struct CmMutableBlob *)pathList.data, pathList.size); + } + return ret; +} + static int32_t CmServiceGetSysCertInfo(const struct CmContext *context, const struct CmBlob *certUri, uint32_t store, struct CmBlob *certificateData, uint32_t *status) { 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..a1d3df9ffb2538598d9756555f8156a5b5526334 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 @@ -1051,6 +1051,59 @@ void CmIpcServiceGetUserCertList(const struct CmBlob *paramSetBlob, struct CmBlo CmFreeParamSet(¶mSet); } +void CmIpcServiceGetTarUserCertList(const struct CmBlob *paramSetBlob, struct CmBlob *outData, + const struct CmContext *context) +{ + int32_t ret = CM_SUCCESS; + uint32_t userId; + struct CmContext cmContext = {0}; + struct CmParamSet *paramSet = NULL; + struct CmMutableBlob certFileList = { 0, NULL }; + struct CmParamOut params[] = { + { .tag = CM_TAG_PARAM0_UINT32, .uint32Param = &userId }, + }; + + do { + if (!CmHasCommonPermission()) { + CM_LOG_E("caller no permission"); + ret = CMR_ERROR_PERMISSION_DENIED; + break; + } + + ret = GetInputParams(paramSetBlob, ¶mSet, &cmContext, params, CM_ARRAY_SIZE(params)); + if (ret != CM_SUCCESS) { + CM_LOG_E("GetUserCertList get input params failed, ret = %d", ret); + break; + } + + ret = CmServiceGetTarCertList(&cmContext, userId, &certFileList); + if (ret != CM_SUCCESS) { + CM_LOG_E("GetTarCertList failed, ret = %d", ret); + break; + } + + ret = CmServiceGetCertListPack(&cmContext, CM_USER_TRUSTED_STORE, &certFileList, outData); + if (ret != CM_SUCCESS) { + CM_LOG_E("CmServiceGetCertListPack pack fail, ret = %d", ret); + break; + } + + CmSendResponse(context, ret, outData); + } while (0); + + struct CmBlob tempBlob = { 0, NULL }; + CmReport(__func__, &cmContext, &tempBlob, ret); + + if (ret != CM_SUCCESS) { + CmSendResponse(context, ret, NULL); + } + + if (certFileList.data != NULL) { + CmFreeCertFiles((struct CertFileInfo *)certFileList.data, certFileList.size); + } + CmFreeParamSet(¶mSet); +} + void CmIpcServiceGetUserCertInfo(const struct CmBlob *paramSetBlob, struct CmBlob *outData, const struct CmContext *context) { 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..fbf650cebf8fabc4c24284d5395dadb27c283996 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 @@ -76,6 +76,9 @@ void CmIpcServiceAbort(const struct CmBlob *paramSetBlob, struct CmBlob *outData void CmIpcServiceGetUserCertList(const struct CmBlob *paramSetBlob, struct CmBlob *outData, const struct CmContext *context); +void CmIpcServiceGetTarUserCertList(const struct CmBlob *paramSetBlob, struct CmBlob *outData, + const struct CmContext *context); + void CmIpcServiceGetUserCertInfo(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 bd54929a8ca88094acef6b4330044d929cf5a911..5661c72f16be31be3040a143f67f8ef56c279688 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 @@ -75,6 +75,7 @@ static struct CmIpcPoint g_cmIpcHandler[] = { { CM_MSG_ABORT, CmIpcServiceAbort }, { CM_MSG_GET_USER_CERTIFICATE_LIST, CmIpcServiceGetUserCertList }, + { CM_MSG_GET_TARGET_USER_CERTIFICATE_LIST, CmIpcServiceGetTarUserCertList }, { CM_MSG_GET_USER_CERTIFICATE_INFO, CmIpcServiceGetUserCertInfo }, { CM_MSG_SET_USER_CERTIFICATE_STATUS, CmIpcServiceSetUserCertStatus }, { CM_MSG_INSTALL_USER_CERTIFICATE, CmIpcServiceInstallUserCert }, diff --git a/test/unittest/src/cm_user_cert_test.cpp b/test/unittest/src/cm_user_cert_test.cpp index 3d2d2e1757765e7935f6504f9e56039fa945d659..b35804f66597af464d8e3f50326ff34f11e5b4ad 100755 --- a/test/unittest/src/cm_user_cert_test.cpp +++ b/test/unittest/src/cm_user_cert_test.cpp @@ -1074,6 +1074,64 @@ HWTEST_F(CmUserCertTest, GetUserCertListTest005, TestSize.Level0) FreeCertList(certList005); } +/** + * @tc.name: GetUserCertListTest006 + * @tc.desc: Test CertManager Get user cert list interface base function + * @tc.type: FUNC + * @tc.require: AR000H0MJ8 /SR000H09N7 + */ +HWTEST_F(CmUserCertTest, GetUserCertListTest006, TestSize.Level0) +{ + int32_t ret; + + uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]); + for (uint32_t i = 0; i < size; i++) { + uint8_t uriBuf018[MAX_URI_LEN] = {0}; + struct CmBlob certUri = { sizeof(uriBuf018), uriBuf018 }; + ret = CmInstallUserCACert(&userCert[i], &certAlias[i], TEST_USERID, true, &certUri); + EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Install test failed, recode:" << ret; + } + + struct CertList *certList006 = nullptr; + InitCertList(&certList006); + ret = CmGetTarUserCertList(TEST_USERID, certList006); + EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert list test failed, recode:" << ret; + FreeCertList(certList006); + + ret = CmUninstallAllUserTrustedCert(); + EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret; +} + +/** + * @tc.name: GetUserCertListTest007 + * @tc.desc: Test CertManager Get user cert list interface Abnormal function + * @tc.type: FUNC + * @tc.require: AR000H0MJ8 /SR000H09N7 + */ +HWTEST_F(CmUserCertTest, GetUserCertListTest007, TestSize.Level0) +{ + int32_t ret; + + uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]); + for (uint32_t i = 0; i < size; i++) { + uint8_t uriBuf019[MAX_URI_LEN] = {0}; + struct CmBlob certUri = { sizeof(uriBuf019), uriBuf019 }; + ret = CmInstallUserCACert(&userCert[i], &certAlias[i], TEST_USERID, true, &certUri); + EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Install test failed, recode:" << ret; + } + + for (uint32_t times = 0; times < PERFORMACE_COUNT; ++times) { + struct CertList *certList007 = nullptr; + InitCertList(&certList007); + ret = CmGetTarUserCertList(TEST_USERID, certList007); + EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert list test failed, recode:" << ret; + FreeCertList(certList007); + } + + ret = CmUninstallAllUserTrustedCert(); + EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret; +} + /** * @tc.name: GetUserCertInfoTest001 * @tc.desc: Test CertManager Get user cert info interface base function