mirror of
https://gitee.com/openharmony/security_huks
synced 2024-11-27 00:40:54 +00:00
!1393 Add exception branch handling
Merge pull request !1393 from Linzs.online/fix/rename
This commit is contained in:
commit
319ba10728
@ -78,7 +78,8 @@ int32_t HksStorageCopyKeyBlobFile(const char *srcPath, const char *srcFileName,
|
||||
const char *destPath, const char *destFileName);
|
||||
|
||||
int32_t HksStoreRenameKeyAlias(const struct HksStoreFileInfo *oldFileInfo,
|
||||
const struct HksStoreFileInfo *newFileInfo, const struct HksStoreMaterial *oldMaterial, bool isCopy);
|
||||
const struct HksStoreFileInfo *newFileInfo, const struct HksStoreMaterial *oldMaterial,
|
||||
const struct HksStoreMaterial *newMaterial, bool isCopy);
|
||||
|
||||
#ifdef HKS_ENABLE_SMALL_TO_SERVICE
|
||||
int32_t HksIsOldKeyPathCleared(uint32_t *keyCount);
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hks_type_enum.h"
|
||||
#ifndef _CUT_AUTHENTICATE_
|
||||
|
||||
#ifdef HKS_CONFIG_FILE
|
||||
@ -877,7 +878,8 @@ int32_t HksListAliasesByProcessName(const struct HksStoreFileInfo *fileInfo, str
|
||||
#endif
|
||||
|
||||
int32_t HksStoreRenameKeyAlias(const struct HksStoreFileInfo *oldFileInfo,
|
||||
const struct HksStoreFileInfo *newFileInfo, const struct HksStoreMaterial *oldMaterial, bool isCopy)
|
||||
const struct HksStoreFileInfo *newFileInfo, const struct HksStoreMaterial *oldMaterial,
|
||||
const struct HksStoreMaterial *newMaterial, bool isCopy)
|
||||
{
|
||||
int32_t ret;
|
||||
do {
|
||||
@ -887,11 +889,27 @@ int32_t HksStoreRenameKeyAlias(const struct HksStoreFileInfo *oldFileInfo,
|
||||
#ifdef SUPPORT_STORAGE_BACKUP
|
||||
ret = CopyKeyBlobFromSrc(oldFileInfo->bakPath.path, oldFileInfo->bakPath.fileName,
|
||||
newFileInfo->bakPath.path, newFileInfo->bakPath.fileName);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "hks copy old key blob failed, ret = %" LOG_PUBLIC "d.", ret)
|
||||
if (ret != HKS_SUCCESS) {
|
||||
HKS_LOG_I("Copy the old backup key failed, try to copy the new main key");
|
||||
ret = CopyKeyBlobFromSrc(newFileInfo->mainPath.path, newFileInfo->mainPath.fileName,
|
||||
newFileInfo->bakPath.path, newFileInfo->bakPath.fileName);
|
||||
if (ret != HKS_SUCCESS) {
|
||||
HKS_LOG_E("rename back key failed, try to delet the new main key. ret = %" LOG_PUBLIC "d.", ret);
|
||||
ret = HksStoreDeleteKeyBlob(newFileInfo, newMaterial);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "delet the new key failed, ret = %" LOG_PUBLIC "d.", ret)
|
||||
ret = HKS_ERROR_CORRUPT_FILE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!isCopy) {
|
||||
ret = HksStoreDeleteKeyBlob(oldFileInfo, oldMaterial);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "hks delete key blob failed, ret = %" LOG_PUBLIC "d.", ret)
|
||||
if (ret != HKS_SUCCESS) {
|
||||
HKS_LOG_I("Delete the old key failed, need to delete the new key");
|
||||
ret = HksStoreDeleteKeyBlob(newFileInfo, newMaterial);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "hks delete new key blob failed, ret = %" LOG_PUBLIC "d.", ret)
|
||||
ret = HKS_ERROR_REMOVE_FILE_FAIL;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
return ret;
|
||||
|
@ -584,10 +584,10 @@ int32_t HksManageStoreRenameKeyAlias(const struct HksProcessInfo *processInfo,
|
||||
struct HksParam *isNeedCopy = NULL;
|
||||
ret = HksGetParam(paramSet, HKS_TAG_IS_COPY_NEW_KEY, &isNeedCopy);
|
||||
if (ret == HKS_SUCCESS && isNeedCopy->boolParam == true) {
|
||||
ret = HksStoreRenameKeyAlias(&oldKeyFileInfo, &newKeyFileInfo, &oldKeyMaterial, true);
|
||||
ret = HksStoreRenameKeyAlias(&oldKeyFileInfo, &newKeyFileInfo, &oldKeyMaterial, &newKeyMaterial, true);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "hks rename key blod failed, ret = %" LOG_PUBLIC "d.", ret);
|
||||
} else {
|
||||
ret = HksStoreRenameKeyAlias(&oldKeyFileInfo, &newKeyFileInfo, &oldKeyMaterial, false);
|
||||
ret = HksStoreRenameKeyAlias(&oldKeyFileInfo, &newKeyFileInfo, &oldKeyMaterial, &newKeyMaterial, false);
|
||||
HKS_IF_NOT_SUCC_LOGE_BREAK(ret, "hks rename key blod failed, ret = %" LOG_PUBLIC "d.", ret);
|
||||
}
|
||||
} while (0);
|
||||
|
Loading…
Reference in New Issue
Block a user