diff --git a/interfaces/innerkits/cert_manager_standard/main/include/cm_type.h b/interfaces/innerkits/cert_manager_standard/main/include/cm_type.h index 1b6f49f451f9453786b0ce390cbc5d23b8d62069..2f3b04ed77a5e65fcbc8b861dc7adeb4110864af 100644 --- a/interfaces/innerkits/cert_manager_standard/main/include/cm_type.h +++ b/interfaces/innerkits/cert_manager_standard/main/include/cm_type.h @@ -76,7 +76,7 @@ extern "C" { #define CM_USER_TRUSTED_STORE 2 #define CM_PRI_CREDENTIAL_STORE 3 #define CM_SYS_CREDENTIAL_STORE 4 -#define CM_SOTRE_CHECK(a) \ +#define CM_STORE_CHECK(a) \ (((a) != CM_CREDENTIAL_STORE) && ((a) != CM_PRI_CREDENTIAL_STORE) && ((a) != CM_SYS_CREDENTIAL_STORE)) enum CmKeyDigest { 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 64008a95efd07721345941a55aa204daa34fe7e8..49182948de0d42dc88dab95e26a4718df54bbd0c 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 @@ -85,7 +85,7 @@ CM_API_EXPORT int32_t CmInstallAppCert(const struct CmBlob *appCert, const struc { CM_LOG_D("enter install app certificate"); if (appCert == NULL || appCertPwd == NULL || certAlias == NULL || - keyUri == NULL || keyUri->data == NULL || CM_SOTRE_CHECK(store)) { + keyUri == NULL || keyUri->data == NULL || CM_STORE_CHECK(store)) { return CMR_ERROR_INVALID_ARGUMENT; } @@ -107,7 +107,7 @@ CM_API_EXPORT int32_t CmInstallAppCert(const struct CmBlob *appCert, const struc CM_API_EXPORT int32_t CmUninstallAppCert(const struct CmBlob *keyUri, const uint32_t store) { CM_LOG_D("enter uninstall app certificate"); - if (keyUri == NULL || CM_SOTRE_CHECK(store)) { + if (keyUri == NULL || CM_STORE_CHECK(store)) { return CMR_ERROR_INVALID_ARGUMENT; } @@ -129,7 +129,7 @@ CM_API_EXPORT int32_t CmUninstallAllAppCert(void) CM_API_EXPORT int32_t CmGetAppCertList(const uint32_t store, struct CredentialList *certificateList) { CM_LOG_D("enter get app certificatelist"); - if (certificateList == NULL || CM_SOTRE_CHECK(store)) { + if (certificateList == NULL || CM_STORE_CHECK(store)) { return CMR_ERROR_INVALID_ARGUMENT; } @@ -142,7 +142,7 @@ CM_API_EXPORT int32_t CmGetAppCert(const struct CmBlob *keyUri, const uint32_t s struct Credential *certificate) { CM_LOG_D("enter get app certificate"); - if (keyUri == NULL || certificate == NULL || CM_SOTRE_CHECK(store)) { + if (keyUri == NULL || certificate == NULL || CM_STORE_CHECK(store)) { return CMR_ERROR_INVALID_ARGUMENT; } 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 9beb4faa2588d7d6667f74c98dcf69964041b027..e8e24755682e6bdc5a866825fc0457fb1014f9ab 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 @@ -75,7 +75,7 @@ int32_t CmRemoveAllUserCert(const struct CmContext *context, uint32_t store, con * @retval 0 success * @retval <0 failure */ -int32_t CmRemoveBakeupUserCert(const struct CmContext *context, const struct CmBlob *certUri, +int32_t CmRemoveBackupUserCert(const struct CmContext *context, const struct CmBlob *certUri, const char *userCertConfigFilePath); #ifdef __cplusplus 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 a46a44bf0d90407b6cf6d4e77cdbad5723e862df..c983c289ee47995f0c01b1e60da3f2f16d389169 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 @@ -68,7 +68,7 @@ int32_t CmUninstallAllUserCert(const struct CmContext *context); int32_t CmServiceSetCertStatus(const struct CmContext *context, const struct CmBlob *certUri, uint32_t store, uint32_t status); -int32_t CmSetStatusBakeupCert( +int32_t CmSetStatusBackupCert( const struct CmContext *context, const struct CmBlob *certUri, uint32_t store, uint32_t status); #ifdef __cplusplus diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_storage.h b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_storage.h index b3d1f8ab61c9ac18da7d49d59d8dcda348531ee1..df260c6813b71578442aed9506475a6b25e323c9 100755 --- a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_storage.h +++ b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_storage.h @@ -97,7 +97,7 @@ int32_t CmGetCertConfPath(uint32_t userId, uint32_t uid, const struct CmBlob *ce * @brief Construct the absolute path of the directory where the CA certificate backup file is stored * * @param[in] userId User ID - * @param[out] certBackupDir The buffer that holds the absolute path of the {bakeupRootDir}/{userId} directory + * @param[out] certBackupDir The buffer that holds the absolute path of the {backupRootDir}/{userId} directory * @param[in] certBackupDirLen Maximum length of the certBackupDir buffer * @return int32_t result * @retval 0 success diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_updateflag.h b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_updateflag.h index c024436cc3f7e99dac73507c23ff34da3c0f0886..9f544dc75fe858ec9037d604f9dd98930d78cce2 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_updateflag.h +++ b/services/cert_manager_standard/cert_manager_engine/main/core/include/cert_manager_updateflag.h @@ -36,7 +36,7 @@ extern "C" { * @retval 0 success * @retval <0 failure */ -int32_t IsCertNeedBakeup(uint32_t userId, uint32_t uid, const struct CmBlob *certUri, bool *needUpdate); +int32_t IsCertNeedBackup(uint32_t userId, uint32_t uid, const struct CmBlob *certUri, bool *needUpdate); /** * @brief Read the user certificate data @@ -62,7 +62,7 @@ int32_t CmReadCertData(uint32_t store, const struct CmContext *context, const st * @retval 0 success * @retval <0 failure */ -int32_t CmBakeupUserCert(const struct CmContext *context, const struct CmBlob *certUri, const struct CmBlob *certData); +int32_t CmBackupUserCert(const struct CmContext *context, const struct CmBlob *certUri, const struct CmBlob *certData); /** * @brief Back up all user certificates @@ -71,7 +71,7 @@ int32_t CmBakeupUserCert(const struct CmContext *context, const struct CmBlob *c * @retval 0 success * @retval <0 failure */ -int32_t CmBakeupAllSaUserCerts(void); +int32_t CmBackupAllSaUserCerts(void); #ifdef __cplusplus } 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 33d99e22ad31d30cca405217f138adbdb7562a1d..0939b687765686777036e415c89b93f1452526da 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 @@ -528,23 +528,23 @@ int32_t CmStoreUserCert(const char *path, const struct CmBlob *userCert, const c int32_t CmGenerateSaConf(const char *userCertConfigPath, const char *userCertBakupDirPath, const char *userCertName) { int32_t ret = CM_SUCCESS; - char userCertBakeupFilePath[CERT_MAX_PATH_LEN] = { 0 }; + char userCertBackupFilePath[CERT_MAX_PATH_LEN] = { 0 }; if (userCertBakupDirPath == NULL) { - if (snprintf_s(userCertBakeupFilePath, CERT_MAX_PATH_LEN, CERT_MAX_PATH_LEN - 1, "%s", userCertName) < 0) { - CM_LOG_E("construct userCertBakeupFilePath failed"); + if (snprintf_s(userCertBackupFilePath, CERT_MAX_PATH_LEN, CERT_MAX_PATH_LEN - 1, "%s", userCertName) < 0) { + CM_LOG_E("construct userCertBackupFilePath failed"); return CMR_ERROR_INVALID_OPERATION; } } else { - if (snprintf_s(userCertBakeupFilePath, CERT_MAX_PATH_LEN, CERT_MAX_PATH_LEN - 1, "%s/%s", userCertBakupDirPath, + if (snprintf_s(userCertBackupFilePath, CERT_MAX_PATH_LEN, CERT_MAX_PATH_LEN - 1, "%s/%s", userCertBakupDirPath, userCertName) < 0) { - CM_LOG_E("construct userCertBakeupFilePath failed"); + CM_LOG_E("construct userCertBackupFilePath failed"); return CMR_ERROR_INVALID_OPERATION; } } - if (CmFileWrite(NULL, userCertConfigPath, 0, (const uint8_t *)userCertBakeupFilePath, - strlen(userCertBakeupFilePath)) != CMR_OK) { + if (CmFileWrite(NULL, userCertConfigPath, 0, (const uint8_t *)userCertBackupFilePath, + strlen(userCertBackupFilePath)) != CMR_OK) { CM_LOG_E("Failed to write saconf file content"); ret = CMR_ERROR_WRITE_FILE_FAIL; } @@ -556,7 +556,7 @@ int32_t CmRemoveUserCert(struct CmMutableBlob *pathBlob, const struct CmBlob *ce return CertManagerFileRemove((char *)pathBlob->data, (char *)certUri->data); } -int32_t CmBakeupRemove(uint32_t userId, const char *path, const struct CmBlob *certUri) +int32_t CmBackupRemove(uint32_t userId, const char *path, const struct CmBlob *certUri) { if (path == NULL) { CM_LOG_E("input params is invaild"); @@ -571,9 +571,9 @@ int32_t CmBakeupRemove(uint32_t userId, const char *path, const struct CmBlob *c return CM_FAILURE; } - ret = CmRemoveBakeupUserCert(NULL, NULL, userCertConfigFilePath); + ret = CmRemoveBackupUserCert(NULL, NULL, userCertConfigFilePath); if (ret != CMR_OK) { - CM_LOG_E("User Cert remove config and bakeup file failed, ret: %d", ret); + CM_LOG_E("User Cert remove config and backup file failed, ret: %d", ret); } return ret; } @@ -594,9 +594,9 @@ static int32_t RemoveAllUserCert(const struct CmContext *context, uint32_t store for (uint32_t i = 0; i < fileNames.size; i++) { certUri.data = (uint8_t *)fNames[i].data; certUri.size = fNames[i].size - 1; - ret = CmBakeupRemove(context->userId, path, &certUri); + ret = CmBackupRemove(context->userId, path, &certUri); if (ret != CMR_OK) { - CM_LOG_E("User Cert %u remove config and bakeup file failed, ret: %d", i, ret); + CM_LOG_E("User Cert %u remove config and backup file failed, ret: %d", i, ret); continue; } ret = CertManagerFileRemove(path, (char *)fNames[i].data); @@ -668,7 +668,7 @@ int32_t CmRemoveAllUserCert(const struct CmContext *context, uint32_t store, con return ret; } -int32_t CmRemoveBakeupUserCert(const struct CmContext *context, const struct CmBlob *certUri, +int32_t CmRemoveBackupUserCert(const struct CmContext *context, const struct CmBlob *certUri, const char *userCertConfigFilePath) { int32_t ret = CM_SUCCESS; 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 de776fe4bc4dc26bc457ff3a1768e033dd4005b8..4c993dec600341d9ffc4cf1a4c57a21968d60c64 100755 --- 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 @@ -210,7 +210,7 @@ int32_t CmServiceInstallAppCertCheck(const struct CmAppCertParam *certParam, str return CMR_ERROR_INVALID_ARGUMENT; } - if (CM_SOTRE_CHECK(certParam->store)) { + if (CM_STORE_CHECK(certParam->store)) { CM_LOG_E("CmInstallAppCertCheck store check fail, store:%u", certParam->store); return CMR_ERROR_INVALID_ARGUMENT; } @@ -291,7 +291,7 @@ static int32_t checkCallerAndUri(struct CmContext *cmContext, const struct CmBlo int32_t CmServiceUninstallAppCertCheck(struct CmContext *cmContext, const uint32_t store, const struct CmBlob *keyUri) { - if (CM_SOTRE_CHECK(store)) { + if (CM_STORE_CHECK(store)) { CM_LOG_E("invalid input arguments store:%u", store); return CMR_ERROR_INVALID_ARGUMENT; } @@ -339,7 +339,7 @@ static int32_t CmGetSysAppCertListCheck(const struct CmContext *cmContext, const int32_t CmServiceGetAppCertListCheck(const struct CmContext *cmContext, const uint32_t store) { - if (CM_SOTRE_CHECK(store)) { + if (CM_STORE_CHECK(store)) { CM_LOG_E("invalid input arguments store:%u", store); return CMR_ERROR_INVALID_ARGUMENT; } @@ -363,7 +363,7 @@ int32_t CmServiceGetAppCertListCheck(const struct CmContext *cmContext, const ui int32_t CmServiceGetAppCertCheck(struct CmContext *cmContext, const uint32_t store, const struct CmBlob *keyUri) { - if (CM_SOTRE_CHECK(store)) { + if (CM_STORE_CHECK(store)) { CM_LOG_E("invalid input arguments store:%u", store); return CMR_ERROR_INVALID_ARGUMENT; } 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 74f90a1bd1dd07a12f4b8a9bb1b3aebc6bfa0bae..c3b8343f7a20e27a57dc4139745875404582a840 100755 --- 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 @@ -547,6 +547,20 @@ int32_t CmX509ToPEM(const X509 *x509, struct CmBlob *userCertPem) return ret; } +static int32_t TryBackupUserCert(const struct CmContext *context, const struct CmBlob *userCert, + struct CmBlob *certUri, struct CmMutableBlob *pathBlob) +{ + int32_t ret = CmBackupUserCert(context, certUri, userCert); + if (ret != CM_SUCCESS) { + CM_LOG_E("CmBackupUserCert fail"); + if (CmRemoveUserCert(pathBlob, certUri) != CM_SUCCESS) { + CM_LOG_E("CmBackupUserCert fail and CmRemoveUserCert fail"); + } + return CM_FAILURE; + } + return ret; +} + int32_t CmInstallUserCert(const struct CmContext *context, const struct CmBlob *userCert, const struct CmBlob *certAlias, const uint32_t status, struct CmBlob *certUri) { @@ -582,13 +596,9 @@ int32_t CmInstallUserCert(const struct CmContext *context, const struct CmBlob * } if (status == CERT_STATUS_ENABLED) { - ret = CmBakeupUserCert(context, certUri, userCert); + ret = TryBackupUserCert(context, userCert, certUri, &pathBlob); if (ret != CM_SUCCESS) { - CM_LOG_E("CmBakeupUserCert fail"); - if (CmRemoveUserCert(&pathBlob, certUri) != CM_SUCCESS) { - CM_LOG_E("CmBakeupUserCert fail and CmRemoveUserCert fail"); - } - ret = CM_FAILURE; + CM_LOG_E("BackupUserCert fail"); break; } } @@ -638,22 +648,22 @@ static int32_t CmComparisonCallerIdWithUri(const struct CmContext *context, int32_t CmRmUserCert(const char *usrCertConfigFilepath) { int32_t ret = CM_SUCCESS; - uint8_t usrCertBakeupFilePath[CERT_MAX_PATH_LEN + 1] = { 0 }; + uint8_t usrCertBackupFilePath[CERT_MAX_PATH_LEN + 1] = { 0 }; uint32_t size = 0; ret = CmIsFileExist(NULL, usrCertConfigFilepath); if (ret != CMR_OK) { return CM_SUCCESS; } - size = CmFileRead(NULL, usrCertConfigFilepath, 0, usrCertBakeupFilePath, CERT_MAX_PATH_LEN); + size = CmFileRead(NULL, usrCertConfigFilepath, 0, usrCertBackupFilePath, CERT_MAX_PATH_LEN); if (size == 0) { CM_LOG_E("CmFileRead read size 0 invalid ,fail"); return CM_FAILURE; } - ret = CmFileRemove(NULL, (const char *)usrCertBakeupFilePath); + ret = CmFileRemove(NULL, (const char *)usrCertBackupFilePath); if (ret != CM_SUCCESS) { - CM_LOG_E("Remove cert bakeup file fail"); + CM_LOG_E("Remove cert backup file fail"); } return ret; } @@ -702,9 +712,9 @@ int32_t CmUninstallUserCert(const struct CmContext *context, const struct CmBlob break; } - ret = CmRemoveBakeupUserCert(context, certUri, NULL); + ret = CmRemoveBackupUserCert(context, certUri, NULL); if (ret != CM_SUCCESS) { - CM_LOG_E("CmRemoveBakeupUserCert fail"); + CM_LOG_E("CmRemoveBackupUserCert fail"); break; } ret = CmSetStatusEnable(context, &pathBlob, certUri, store); @@ -748,14 +758,14 @@ int32_t CmServiceSetCertStatus(const struct CmContext *context, const struct CmB return SetcertStatus(context, certUri, store, status, NULL); } -int32_t CmSetStatusBakeupCert( +int32_t CmSetStatusBackupCert( const struct CmContext *context, const struct CmBlob *certUri, uint32_t store, uint32_t status) { int32_t ret = CM_SUCCESS; if (status == CERT_STATUS_ENANLED) { bool needUpdate = false; - ret = IsCertNeedBakeup(context->userId, context->uid, certUri, &needUpdate); + ret = IsCertNeedBackup(context->userId, context->uid, certUri, &needUpdate); if (ret != CM_SUCCESS) { CM_LOG_E("Check cert is need update failed, ret = %d", ret); return CMR_ERROR_INVALID_OPERATION; @@ -771,16 +781,16 @@ int32_t CmSetStatusBakeupCert( return CM_FAILURE; } - ret = CmBakeupUserCert(context, certUri, &certificateData); + ret = CmBackupUserCert(context, certUri, &certificateData); if (ret != CM_SUCCESS) { - CM_LOG_E("CmBakeupUserCert failed, ret = %d", ret); + CM_LOG_E("CmBackupUserCert failed, ret = %d", ret); ret = CM_FAILURE; } CM_FREE_BLOB(certificateData); } else if (status == CERT_STATUS_DISABLED) { - ret = CmRemoveBakeupUserCert(context, certUri, NULL); + ret = CmRemoveBackupUserCert(context, certUri, NULL); if (ret != CM_SUCCESS) { - CM_LOG_E("CmRemoveBakeupUserCert fail, ret = %d", ret); + CM_LOG_E("CmRemoveBackupUserCert fail, ret = %d", ret); } } diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_storage.c b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_storage.c index 29d9c5c4e23c2b2a2619dbce0c4a9bdc7f26155e..49fdea8a0cf57ba066052e40a0b3fe902969f5ec 100755 --- a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_storage.c +++ b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_storage.c @@ -11,38 +11,38 @@ * 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 "cert_manager_storage.h" - + */ + +#include "cert_manager_storage.h" + #include -#include - +#include + #include "cert_manager_file_operator.h" -#include "cert_manager_mem.h" -#include "cert_manager_uri.h" -#include "cm_log.h" +#include "cert_manager_mem.h" +#include "cert_manager_uri.h" +#include "cm_log.h" #include "cm_type.h" #include "securec.h" - -int32_t GetRootPath(uint32_t store, char *rootPath, uint32_t pathLen) + +int32_t GetRootPath(uint32_t store, char *rootPath, uint32_t pathLen) { errno_t ret; /* keep \0 at end */ switch (store) { - case CM_CREDENTIAL_STORE: + case CM_CREDENTIAL_STORE: ret = memcpy_s(rootPath, pathLen - 1, CREDNTIAL_STORE, strlen(CREDNTIAL_STORE)); - break; - case CM_SYSTEM_TRUSTED_STORE: - ret = memcpy_s(rootPath, pathLen - 1, SYSTEM_CA_STORE, strlen(SYSTEM_CA_STORE)); - break; - case CM_USER_TRUSTED_STORE: - ret = memcpy_s(rootPath, pathLen - 1, USER_CA_STORE, strlen(USER_CA_STORE)); - break; - case CM_PRI_CREDENTIAL_STORE: - ret = memcpy_s(rootPath, pathLen - 1, PRI_CREDNTIAL_STORE, strlen(PRI_CREDNTIAL_STORE)); - break; + break; + case CM_SYSTEM_TRUSTED_STORE: + ret = memcpy_s(rootPath, pathLen - 1, SYSTEM_CA_STORE, strlen(SYSTEM_CA_STORE)); + break; + case CM_USER_TRUSTED_STORE: + ret = memcpy_s(rootPath, pathLen - 1, USER_CA_STORE, strlen(USER_CA_STORE)); + break; + case CM_PRI_CREDENTIAL_STORE: + ret = memcpy_s(rootPath, pathLen - 1, PRI_CREDNTIAL_STORE, strlen(PRI_CREDNTIAL_STORE)); + break; case CM_SYS_CREDENTIAL_STORE: ret = memcpy_s(rootPath, pathLen - 1, SYS_CREDNTIAL_STORE, strlen(SYS_CREDNTIAL_STORE)); break; @@ -52,17 +52,17 @@ int32_t GetRootPath(uint32_t store, char *rootPath, uint32_t pathLen) if (ret != EOK) { CM_LOG_E("copy path failed, store = %u", store); - return CMR_ERROR_INVALID_OPERATION; + return CMR_ERROR_INVALID_OPERATION; } return CM_SUCCESS; } -int32_t ConstructUserIdPath(const struct CmContext *context, uint32_t store, +int32_t ConstructUserIdPath(const struct CmContext *context, uint32_t store, char *userIdPath, uint32_t pathLen) { - char rootPath[CERT_MAX_PATH_LEN] = { 0 }; - int32_t ret = GetRootPath(store, rootPath, CERT_MAX_PATH_LEN); + char rootPath[CERT_MAX_PATH_LEN] = { 0 }; + int32_t ret = GetRootPath(store, rootPath, CERT_MAX_PATH_LEN); if (ret != CM_SUCCESS) { return ret; } @@ -71,7 +71,7 @@ int32_t ConstructUserIdPath(const struct CmContext *context, uint32_t store, if (snprintf_s(userIdPath, pathLen, pathLen - 1, "%s%u", rootPath, context->userId) < 0) { CM_LOG_E("construct user id path failed"); - return CMR_ERROR_INVALID_OPERATION; + return CMR_ERROR_INVALID_OPERATION; } CM_LOG_I("userId path: %s", userIdPath); @@ -85,18 +85,18 @@ int32_t ConstructUserIdPath(const struct CmContext *context, uint32_t store, return CM_SUCCESS; } -int32_t ConstructUidPath(const struct CmContext *context, uint32_t store, +int32_t ConstructUidPath(const struct CmContext *context, uint32_t store, char *uidPath, uint32_t pathLen) { - char userIdPath[CERT_MAX_PATH_LEN] = { 0 }; - int32_t ret = ConstructUserIdPath(context, store, userIdPath, CERT_MAX_PATH_LEN); + char userIdPath[CERT_MAX_PATH_LEN] = { 0 }; + int32_t ret = ConstructUserIdPath(context, store, userIdPath, CERT_MAX_PATH_LEN); if (ret != CM_SUCCESS) { return ret; } if (snprintf_s(uidPath, pathLen, pathLen - 1, "%s/%u", userIdPath, context->uid) < 0) { CM_LOG_E("construct uid path failed"); - return CMR_ERROR_INVALID_OPERATION; + return CMR_ERROR_INVALID_OPERATION; } ret = CmMakeDir(uidPath); @@ -108,18 +108,18 @@ int32_t ConstructUidPath(const struct CmContext *context, uint32_t store, return CM_SUCCESS; } -int32_t ConstructAuthListPath(const struct CmContext *context, uint32_t store, +int32_t ConstructAuthListPath(const struct CmContext *context, uint32_t store, char *authListPath, uint32_t pathLen) { - char uidPath[CERT_MAX_PATH_LEN] = { 0 }; - int32_t ret = ConstructUidPath(context, store, uidPath, CERT_MAX_PATH_LEN); + char uidPath[CERT_MAX_PATH_LEN] = { 0 }; + int32_t ret = ConstructUidPath(context, store, uidPath, CERT_MAX_PATH_LEN); if (ret != CM_SUCCESS) { return ret; } if (snprintf_s(authListPath, pathLen, pathLen - 1, "%s/%s", uidPath, "authlist") < 0) { CM_LOG_E("construct authlist failed"); - return CMR_ERROR_INVALID_OPERATION; + return CMR_ERROR_INVALID_OPERATION; } ret = CmMakeDir(authListPath); @@ -130,13 +130,13 @@ int32_t ConstructAuthListPath(const struct CmContext *context, uint32_t store, return CM_SUCCESS; } - -int32_t CmStorageGetBuf(const char *path, const char *fileName, struct CmBlob *storageBuf) + +int32_t CmStorageGetBuf(const char *path, const char *fileName, struct CmBlob *storageBuf) { uint32_t fileSize = CmFileSize(path, fileName); if (fileSize > MAX_OUT_BLOB_SIZE) { CM_LOG_E("file size[%u] invalid", fileSize); - return CMR_ERROR_INVALID_OPERATION; + return CMR_ERROR_INVALID_OPERATION; } if (fileSize == 0) { @@ -154,33 +154,33 @@ int32_t CmStorageGetBuf(const char *path, const char *fileName, struct CmBlob *s if (readSize == 0) { CM_LOG_E("read file size 0 invalid"); CMFree(data); - return CMR_ERROR_NOT_EXIST; + return CMR_ERROR_NOT_EXIST; } - storageBuf->data = data; - storageBuf->size = fileSize; + storageBuf->data = data; + storageBuf->size = fileSize; return CM_SUCCESS; -} - -int32_t CmStorageGetAppCert(const struct CmContext *context, uint32_t store, - const struct CmBlob *keyUri, struct CmBlob *certBlob) -{ +} + +int32_t CmStorageGetAppCert(const struct CmContext *context, uint32_t store, + const struct CmBlob *keyUri, struct CmBlob *certBlob) +{ uint32_t uid = 0; - int32_t ret = CertManagerGetUidFromUri(keyUri, &uid); + int32_t ret = CertManagerGetUidFromUri(keyUri, &uid); if (ret != CM_SUCCESS) { return ret; } - struct CmContext uriContext = { context->userId, uid, { 0 } }; - char uidPath[CERT_MAX_PATH_LEN] = { 0 }; - ret = ConstructUidPath(&uriContext, store, uidPath, CERT_MAX_PATH_LEN); + struct CmContext uriContext = { context->userId, uid, { 0 } }; + char uidPath[CERT_MAX_PATH_LEN] = { 0 }; + ret = ConstructUidPath(&uriContext, store, uidPath, CERT_MAX_PATH_LEN); if (ret != CM_SUCCESS) { return ret; } - return CmStorageGetBuf(uidPath, (const char *)keyUri->data, certBlob); -} - + return CmStorageGetBuf(uidPath, (const char *)keyUri->data, certBlob); +} + int32_t CmGetCertFilePath(const struct CmContext *context, uint32_t store, struct CmMutableBlob *pathBlob) { char pathPtr[CERT_MAX_PATH_LEN] = {0}; @@ -225,7 +225,7 @@ static int32_t GetCertConfRootDir(char *confRootDir, uint32_t dirLen) } if (dirLen < sizeof(CERT_BACKUP_CONFIG_ROOT_DIR)) { - CM_LOG_E("dirLen(%u) is too small for save user cert bakeup config file root path", dirLen); + CM_LOG_E("dirLen(%u) is too small for save user cert backup config file root path", dirLen); return CMR_ERROR_BUFFER_TOO_SMALL; } @@ -344,21 +344,21 @@ int32_t CmGetCertConfPath(uint32_t userId, uint32_t uid, const struct CmBlob *ce /** * @brief Get the user certificate backup file root directory * - * @param[out] certBakeupRootDir Save the buffer of the user certificate backup file root directory - * @param[in] dirLen Maximum length of the certBakeupRootDir buffer + * @param[out] certBackupRootDir Save the buffer of the user certificate backup file root directory + * @param[in] dirLen Maximum length of the certBackupRootDir buffer * @return int32_t result * @retval 0 success  * @retval <0 failure */ -static int32_t GetCertBakeupRootDir(char *certBakeupRootDir, uint32_t dirLen) +static int32_t GetCertBackupRootDir(char *certBackupRootDir, uint32_t dirLen) { - if (certBakeupRootDir == NULL) { + if (certBackupRootDir == NULL) { CM_LOG_E("Input params invalid"); return CMR_ERROR_INVALID_ARGUMENT; } if (dirLen < sizeof(CERT_BACKUP_ROOT_DIR)) { - CM_LOG_E("dirLen(%u) is too small for save user cert bakeup root path", dirLen); + CM_LOG_E("dirLen(%u) is too small for save user cert backup root path", dirLen); return CMR_ERROR_BUFFER_TOO_SMALL; } @@ -372,8 +372,8 @@ static int32_t GetCertBakeupRootDir(char *certBakeupRootDir, uint32_t dirLen) return CMR_ERROR_MAKE_DIR_FAIL; } - if (snprintf_s(certBakeupRootDir, dirLen, dirLen - 1, "%s", CERT_BACKUP_ROOT_DIR) < 0) { - CM_LOG_E("Construct certBakeupRootDir failed"); + if (snprintf_s(certBackupRootDir, dirLen, dirLen - 1, "%s", CERT_BACKUP_ROOT_DIR) < 0) { + CM_LOG_E("Construct certBackupRootDir failed"); return CM_FAILURE; } @@ -385,7 +385,7 @@ int32_t CmGetCertBackupDir(uint32_t userId, char *certBackupDir, uint32_t certBa int32_t ret = CM_SUCCESS; char rootPath[CERT_MAX_PATH_LEN] = { 0 }; - ret = GetCertBakeupRootDir(rootPath, CERT_MAX_PATH_LEN); + ret = GetCertBackupRootDir(rootPath, CERT_MAX_PATH_LEN); if (ret != CM_SUCCESS) { CM_LOG_E("Get user cert root path failed"); return ret; diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_updateflag.c b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_updateflag.c index 5fd2a9f3ca5505de13091c09d452bbde7da19562..f135fe832d31019c659320a0453bac6e1f3ea1c7 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_updateflag.c +++ b/services/cert_manager_standard/cert_manager_engine/main/core/src/cert_manager_updateflag.c @@ -102,7 +102,7 @@ static int32_t SetUpdateFlag(uint8_t updateFlag) return ret; } -int32_t IsCertNeedBakeup(uint32_t userId, uint32_t uid, const struct CmBlob *certUri, bool *needUpdate) +int32_t IsCertNeedBackup(uint32_t userId, uint32_t uid, const struct CmBlob *certUri, bool *needUpdate) { int32_t ret = CM_SUCCESS; char configPath[CERT_MAX_PATH_LEN] = { 0 }; @@ -130,20 +130,20 @@ int32_t IsCertNeedBakeup(uint32_t userId, uint32_t uid, const struct CmBlob *cer break; } uint32_t size = 0; - char bakeupPath[CERT_MAX_PATH_LEN] = { 0 }; - size = CmFileRead(NULL, configPath, 0, (uint8_t *)bakeupPath, CERT_MAX_PATH_LEN - 1); + char backupPath[CERT_MAX_PATH_LEN] = { 0 }; + size = CmFileRead(NULL, configPath, 0, (uint8_t *)backupPath, CERT_MAX_PATH_LEN - 1); if (size == 0) { - CM_LOG_E("read cert bakeup file path from configPath failed."); + CM_LOG_E("read cert backup file path from configPath failed."); *needUpdate = true; break; } - ret = CmIsFileExist(NULL, (const char *)bakeupPath); + ret = CmIsFileExist(NULL, (const char *)backupPath); if (ret == CMR_OK) { *needUpdate = false; break; } else if (ret != CMR_ERROR_NOT_EXIST) { - CM_LOG_E("check cert bakeup file return err code: %d.", ret); + CM_LOG_E("check cert backup file return err code: %d.", ret); } *needUpdate = true; } while (0); @@ -233,7 +233,7 @@ int32_t CmConstructContextFromUri(const char *certUri, struct CmContext *context return ret; } -static int32_t BakeupUserCert(const X509 *userCertX509, const struct CmBlob *userCert, const struct CmContext *context, +static int32_t BackupUserCert(const X509 *userCertX509, const struct CmBlob *userCert, const struct CmContext *context, const struct CmBlob *certUri) { char userCertConfigFilePath[CERT_MAX_PATH_LEN] = { 0 }; @@ -245,9 +245,9 @@ static int32_t BakeupUserCert(const X509 *userCertX509, const struct CmBlob *use return CM_FAILURE; } - ret = CmRemoveBakeupUserCert(context, certUri, userCertConfigFilePath); + ret = CmRemoveBackupUserCert(context, certUri, userCertConfigFilePath); if (ret != CMR_OK) { - CM_LOG_E("Remove user cert config and bakeup file failed, ret: %d", ret); + CM_LOG_E("Remove user cert config and backup file failed, ret: %d", ret); } ret = CmGetCertBackupFilePath(userCertX509, context->userId, userCertBackupFilePath, CERT_MAX_PATH_LEN); @@ -270,7 +270,7 @@ static int32_t BakeupUserCert(const X509 *userCertX509, const struct CmBlob *use return CM_SUCCESS; } -int32_t CmBakeupUserCert(const struct CmContext *context, const struct CmBlob *certUri, const struct CmBlob *certData) +int32_t CmBackupUserCert(const struct CmContext *context, const struct CmBlob *certUri, const struct CmBlob *certData) { if ((context == NULL) || (CmCheckBlob(certUri) != CM_SUCCESS) || (CmCheckBlob(certData) != CM_SUCCESS)) { CM_LOG_E("Invalid input arguments"); @@ -294,9 +294,9 @@ int32_t CmBakeupUserCert(const struct CmContext *context, const struct CmBlob *c break; } - ret = BakeupUserCert(userCertX509, (const struct CmBlob *)&certPemData, context, certUri); + ret = BackupUserCert(userCertX509, (const struct CmBlob *)&certPemData, context, certUri); if (ret != CM_SUCCESS) { - CM_LOG_E("BakeupUserCert fail"); + CM_LOG_E("BackupUserCert fail"); ret = CM_FAILURE; break; } @@ -325,7 +325,7 @@ static int32_t UpdateUserCert(uint32_t userId, uint32_t uid, const char *certPat certUri.size = strlen(uriStr); bool needUpdate = false; - ret = IsCertNeedBakeup(userId, uid, &certUri, &needUpdate); + ret = IsCertNeedBackup(userId, uid, &certUri, &needUpdate); if (ret != CM_SUCCESS) { CM_LOG_E("Check cert is need update failed, ret = %d", ret); return CMR_ERROR_INVALID_OPERATION; @@ -349,7 +349,7 @@ static int32_t UpdateUserCert(uint32_t userId, uint32_t uid, const char *certPat return CM_FAILURE; } - ret = CmBakeupUserCert(&context, &certUri, &certificateData); + ret = CmBackupUserCert(&context, &certUri, &certificateData); if (ret != CM_SUCCESS) { CM_LOG_E("update user certUri failed, ret = %d", ret); ret = CM_FAILURE; @@ -456,7 +456,7 @@ static int32_t UpdateAllUserCerts(void) return CM_SUCCESS; } -int32_t CmBakeupAllSaUserCerts(void) +int32_t CmBackupAllSaUserCerts(void) { int32_t ret = 0; uint8_t updateFlag = 0; diff --git a/services/cert_manager_standard/cert_manager_engine/main/core/src/cm_event_process.c b/services/cert_manager_standard/cert_manager_engine/main/core/src/cm_event_process.c index 38b5aff17ba2febad6daa9807b26066ca3e139d1..f2d98e9ef4bd612b7c603aa3a5f7ee6e617c28a9 100644 --- a/services/cert_manager_standard/cert_manager_engine/main/core/src/cm_event_process.c +++ b/services/cert_manager_standard/cert_manager_engine/main/core/src/cm_event_process.c @@ -325,7 +325,7 @@ static int32_t CmTraversalDir(const struct CmContext *context, const char *path, return ret; } -static int32_t CmTraversalBakeupUidDir(const char *certConfigUidDirPath) +static int32_t CmTraversalBackupUidDir(const char *certConfigUidDirPath) { if (certConfigUidDirPath == NULL) { CM_LOG_E("input params is invaild"); @@ -344,10 +344,10 @@ static int32_t CmTraversalBakeupUidDir(const char *certConfigUidDirPath) for (uint32_t i = 0; i < fileCounts; i++) { struct CmBlob *certConfigFilePath = &fileNames[i]; - /* Delete user cert bakeup and config file */ - ret = CmRemoveBakeupUserCert(NULL, NULL, (const char *)certConfigFilePath->data); + /* Delete user cert backup and config file */ + ret = CmRemoveBackupUserCert(NULL, NULL, (const char *)certConfigFilePath->data); if (ret != CM_SUCCESS) { - CM_LOG_E("CmRemoveBakeupUserCert failed"); + CM_LOG_E("CmRemoveBackupUserCert failed"); continue; } } @@ -357,7 +357,7 @@ static int32_t CmTraversalBakeupUidDir(const char *certConfigUidDirPath) return CM_SUCCESS; } -static int32_t CmTraversalBakeupUserIdDir(const char *certConfigUserIdDirPath) +static int32_t CmTraversalBackupUserIdDir(const char *certConfigUserIdDirPath) { if (certConfigUserIdDirPath == NULL) { CM_LOG_E("input params is invaild"); @@ -384,9 +384,9 @@ static int32_t CmTraversalBakeupUserIdDir(const char *certConfigUserIdDirPath) continue; } - ret = CmTraversalBakeupUidDir(certConfigUidDirPath); + ret = CmTraversalBackupUidDir(certConfigUidDirPath); if (ret != CM_SUCCESS) { - CM_LOG_E("CmTraversalBakeupUidDir failed, ret = %d", ret); + CM_LOG_E("CmTraversalBackupUidDir failed, ret = %d", ret); continue; } @@ -402,7 +402,7 @@ static int32_t CmTraversalBakeupUserIdDir(const char *certConfigUserIdDirPath) return CM_SUCCESS; } -static int32_t CmTraversalBakeupUserCert(uint32_t userId) +static int32_t CmTraversalBackupUserCert(uint32_t userId) { int32_t ret = CM_SUCCESS; char certConfigUserIdDirPath[CERT_MAX_PATH_LEN] = { 0 }; @@ -412,9 +412,9 @@ static int32_t CmTraversalBakeupUserCert(uint32_t userId) return CM_FAILURE; } - ret = CmTraversalBakeupUserIdDir(certConfigUserIdDirPath); + ret = CmTraversalBackupUserIdDir(certConfigUserIdDirPath); if (ret != CM_SUCCESS) { - CM_LOG_E("CmTraversalBakeupUserIdDir failed, ret = %d", ret); + CM_LOG_E("CmTraversalBackupUserIdDir failed, ret = %d", ret); return CM_FAILURE; } @@ -425,16 +425,16 @@ static int32_t CmTraversalBakeupUserCert(uint32_t userId) return CMR_ERROR_REMOVE_FILE_FAIL; } - /* Delete {bakeupRootDir}/{userid} directory */ - char certBakeupUserIdDirPath[CERT_MAX_PATH_LEN] = { 0 }; - ret = CmGetCertBackupDir(userId, certBakeupUserIdDirPath, CERT_MAX_PATH_LEN); + /* Delete {backupRootDir}/{userid} directory */ + char certBackupUserIdDirPath[CERT_MAX_PATH_LEN] = { 0 }; + ret = CmGetCertBackupDir(userId, certBackupUserIdDirPath, CERT_MAX_PATH_LEN); if (ret != CM_SUCCESS) { - CM_LOG_E("Construct certBakeupUserIdDirPath failed"); + CM_LOG_E("Construct certBackupUserIdDirPath failed"); return CM_FAILURE; } - ret = CmDirRemove(certBakeupUserIdDirPath); + ret = CmDirRemove(certBackupUserIdDirPath); if (ret != CM_SUCCESS) { - CM_LOG_E("Remove user certBakeupUserIdDirPath fail, ret = %d", ret); + CM_LOG_E("Remove user certBackupUserIdDirPath fail, ret = %d", ret); return CMR_ERROR_REMOVE_FILE_FAIL; } @@ -468,10 +468,10 @@ int32_t CmDeleteProcessInfo(const struct CmContext *context) CM_LOG_E("CmDeleteUserCa faild"); } - /* Delete user ca bakeup and config */ - ret = CmTraversalBakeupUserCert(context->userId); + /* Delete user ca backup and config */ + ret = CmTraversalBackupUserCert(context->userId); if (ret != CM_SUCCESS) { - CM_LOG_E("Delete user ca bakeup and config file failed"); + CM_LOG_E("Delete user ca backup and config file failed"); } } 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 732832e047555f1d27e99f50cadf069e318f7a73..b9c8f844e2737c754fa372fbd1ed47ce6ee0e66d 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 @@ -1079,9 +1079,9 @@ void CmIpcServiceSetUserCertStatus(const struct CmBlob *paramSetBlob, struct CmB CM_LOG_E("set user cert status failed, ret = %d", ret); break; } - ret = CmSetStatusBakeupCert(&cmContext, &certUri, store, status); + ret = CmSetStatusBackupCert(&cmContext, &certUri, store, status); if (ret != CM_SUCCESS) { - CM_LOG_E("CmSetStatusBakeupCert failed, ret = %d", ret); + CM_LOG_E("CmSetStatusBackupCert failed, ret = %d", ret); break; } } while (0); 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 cbcfbb4726bea726a43a1cfd7cbcb923a8b470be..9b1a72c8fc047d536257816f444f399497983d0b 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 @@ -266,7 +266,7 @@ void CertManagerService::OnStart(const SystemAbilityOnDemandReason& startReason) runningState_ = STATE_RUNNING; CM_LOG_D("CertManagerService start success."); - (void)CmBakeupAllSaUserCerts(); + (void)CmBackupAllSaUserCerts(); } void CertManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)