From 8a5e45a63a2aa00b1c21c4ccc4ff110e124d244f Mon Sep 17 00:00:00 2001 From: Zhou Shihui Date: Mon, 22 Jul 2024 16:05:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E7=95=99=E6=95=B0=E6=8D=AE=E5=8D=B8?= =?UTF-8?q?=E8=BD=BD=E6=97=B6=E4=B8=8D=E5=88=A0=E9=99=A4el5=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E5=92=8CkeyId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhou Shihui --- .../bundlemgr/include/base_bundle_installer.h | 2 +- .../include/installd/installd_host_impl.h | 4 +-- .../include/installd/installd_operator.h | 4 +-- services/bundlemgr/include/installd_client.h | 4 +-- .../include/ipc/installd_interface.h | 4 +-- .../bundlemgr/include/ipc/installd_proxy.h | 4 +-- .../bundlemgr/src/base_bundle_installer.cpp | 34 +++++++++---------- .../bundlemgr/src/el5_filekey_callback.cpp | 2 +- .../src/installd/installd_host_impl.cpp | 12 +++---- .../src/installd/installd_operator.cpp | 19 +++++++---- services/bundlemgr/src/installd_client.cpp | 12 +++---- services/bundlemgr/src/ipc/installd_host.cpp | 7 ++-- services/bundlemgr/src/ipc/installd_proxy.cpp | 7 ++-- .../test/mock/src/installd_client.cpp | 12 +++---- .../test/mock/src/mock_install_client.cpp | 4 +-- .../test/mock/src/mock_installd_host_impl.cpp | 4 +-- .../bms_install_daemon_host_impl_test.cpp | 4 +-- .../bms_install_daemon_ipc_test.cpp | 4 +-- .../bms_install_daemon_operator_test.cpp | 2 +- .../bms_installd_client_test.cpp | 4 +-- 20 files changed, 71 insertions(+), 78 deletions(-) diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index de9749f592..41a510fb88 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -680,7 +680,7 @@ private: void CreateScreenLockProtectionDir(); void DeleteScreenLockProtectionDir(const std::string bundleName) const; bool SetEncryptionDirPolicy(InnerBundleInfo &info); - void DeleteEncryptionKeyId(const InnerBundleInfo &oldInfo) const; + void DeleteEncryptionKeyId(const InnerBundleInfo &oldInfo, bool isKeepData) const; void CreateScreenLockProtectionExistDirs(const InnerBundleInfo &info, const std::string &dir); #ifdef APP_DOMAIN_VERIFY_ENABLED void PrepareSkillUri(const std::vector &skills, std::vector &skillUris) const; diff --git a/services/bundlemgr/include/installd/installd_host_impl.h b/services/bundlemgr/include/installd/installd_host_impl.h index ddac7fd8cb..4264368216 100644 --- a/services/bundlemgr/include/installd/installd_host_impl.h +++ b/services/bundlemgr/include/installd/installd_host_impl.h @@ -218,9 +218,9 @@ public: virtual ErrCode RemoveSignProfile(const std::string &bundleName) override; virtual ErrCode SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) override; + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) override; - virtual ErrCode DeleteEncryptionKeyId(const std::string &keyId) override; + virtual ErrCode DeleteEncryptionKeyId(const uint32_t accessTokenId) override; virtual ErrCode RemoveExtensionDir(int32_t userId, const std::vector &extensionBundleDirs) override; diff --git a/services/bundlemgr/include/installd/installd_operator.h b/services/bundlemgr/include/installd/installd_operator.h index 0b4f788bcc..0e763027fd 100644 --- a/services/bundlemgr/include/installd/installd_operator.h +++ b/services/bundlemgr/include/installd/installd_operator.h @@ -286,9 +286,9 @@ public: #endif static bool GenerateKeyIdAndSetPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId); + const int32_t userId, std::string &keyId, const uint32_t accessTokenId); - static bool DeleteKeyId(const std::string &keyId); + static bool DeleteKeyId(const uint32_t accessTokenId); private: static bool OpenHandle(void **handle); diff --git a/services/bundlemgr/include/installd_client.h b/services/bundlemgr/include/installd_client.h index 1c8c633250..0b7dc5cc23 100644 --- a/services/bundlemgr/include/installd_client.h +++ b/services/bundlemgr/include/installd_client.h @@ -221,9 +221,9 @@ public: ErrCode RemoveSignProfile(const std::string &bundleName); ErrCode SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId); + const int32_t userId, std::string &keyId, const uint32_t accessTokenId); - ErrCode DeleteEncryptionKeyId(const std::string &keyId); + ErrCode DeleteEncryptionKeyId(const uint32_t accessTokenId); ErrCode RemoveExtensionDir(int32_t userId, const std::vector &extensionBundleDirs); diff --git a/services/bundlemgr/include/ipc/installd_interface.h b/services/bundlemgr/include/ipc/installd_interface.h index 97a5d268c2..f64476c5c8 100644 --- a/services/bundlemgr/include/ipc/installd_interface.h +++ b/services/bundlemgr/include/ipc/installd_interface.h @@ -387,12 +387,12 @@ public: } virtual ErrCode SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { return ERR_OK; } - virtual ErrCode DeleteEncryptionKeyId(const std::string &keyId) + virtual ErrCode DeleteEncryptionKeyId(const uint32_t accessTokenId) { return ERR_OK; } diff --git a/services/bundlemgr/include/ipc/installd_proxy.h b/services/bundlemgr/include/ipc/installd_proxy.h index 0456ec3c79..b6170bbcdf 100644 --- a/services/bundlemgr/include/ipc/installd_proxy.h +++ b/services/bundlemgr/include/ipc/installd_proxy.h @@ -216,9 +216,9 @@ public: virtual ErrCode RemoveSignProfile(const std::string &bundleName) override; virtual ErrCode SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) override; + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) override; - virtual ErrCode DeleteEncryptionKeyId(const std::string &keyId) override; + virtual ErrCode DeleteEncryptionKeyId(const uint32_t accessTokenId) override; virtual ErrCode RemoveExtensionDir(int32_t userId, const std::vector &extensionBundleDirs) override; diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index bd8b141ba6..c39e318f29 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1439,7 +1439,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( APP_LOGW("remove group dir failed for %{public}s", oldInfo.GetBundleName().c_str()); } - DeleteEncryptionKeyId(oldInfo); + DeleteEncryptionKeyId(oldInfo, installParam.isKeepData); if (oldInfo.GetInnerBundleUserInfos().size() > 1) { LOG_D(BMS_TAG_INSTALLER, "only delete userinfo %{public}d", userId_); @@ -2834,9 +2834,10 @@ bool BaseBundleInstaller::SetEncryptionDirPolicy(InnerBundleInfo &info) } int32_t uid = userInfo.uid; + uint32_t accessTokenId = userInfo.accessTokenId; std::string bundleName = info.GetBundleName(); std::string keyId = ""; - auto result = InstalldClient::GetInstance()->SetEncryptionPolicy(uid, bundleName, userId_, keyId); + auto result = InstalldClient::GetInstance()->SetEncryptionPolicy(uid, bundleName, userId_, keyId, accessTokenId); if (result != ERR_OK) { LOG_E(BMS_TAG_INSTALLER, "SetEncryptionPolicy failed"); } @@ -2852,13 +2853,14 @@ bool BaseBundleInstaller::SetEncryptionDirPolicy(InnerBundleInfo &info) void BaseBundleInstaller::CreateScreenLockProtectionExistDirs(const InnerBundleInfo &info, const std::string &dir) { - LOG_I(BMS_TAG_INSTALLER, "CreateScreenLockProtectionExistDirs start"); InnerBundleUserInfo newInnerBundleUserInfo; if (!info.GetInnerBundleUserInfo(userId_, newInnerBundleUserInfo)) { LOG_E(BMS_TAG_INSTALLER, "bundle(%{public}s) get user(%{public}d) failed", info.GetBundleName().c_str(), userId_); return; } + LOG_I(BMS_TAG_INSTALLER, "create el5 dir: %{public}s, uid: %{public}d", + dir.c_str(), newInnerBundleUserInfo.uid); int32_t mode = S_IRWXU; int32_t gid = newInnerBundleUserInfo.uid; if (dir.find(ServiceConstants::DATABASE) != std::string::npos) { @@ -2905,30 +2907,26 @@ void BaseBundleInstaller::CreateScreenLockProtectionDir() } return; } - bool dirExist = false; for (const std::string &dir : dirs) { - if (InstalldClient::GetInstance()->IsExistDir(dir, dirExist) != ERR_OK) { - LOG_E(BMS_TAG_INSTALLER, "check if dir existed failed"); - return; - } - if (!dirExist) { - LOG_D(BMS_TAG_INSTALLER, "ScreenLockProtectionDir: %{public}s need to be created", dir.c_str()); - CreateScreenLockProtectionExistDirs(info, dir); - } + LOG_D(BMS_TAG_INSTALLER, "create el5 dir: %{public}s.", dir.c_str()); + CreateScreenLockProtectionExistDirs(info, dir); } - if (!dirExist) { - if (!SetEncryptionDirPolicy(info)) { - LOG_E(BMS_TAG_INSTALLER, "Encryption failed dir"); - } + if (!SetEncryptionDirPolicy(info)) { + LOG_E(BMS_TAG_INSTALLER, "Encryption failed dir"); } } -void BaseBundleInstaller::DeleteEncryptionKeyId(const InnerBundleInfo &oldInfo) const +void BaseBundleInstaller::DeleteEncryptionKeyId(const InnerBundleInfo &oldInfo, bool isKeepData) const { if (oldInfo.GetBundleName().empty()) { LOG_W(BMS_TAG_INSTALLER, "bundleName is empty"); return; } + if (isKeepData) { + LOG_I(BMS_TAG_INSTALLER, "uninstall with keep data, do not delete el5 dir"); + return; + } + LOG_I(BMS_TAG_INSTALLER, "uninstall without keep data, delete el5 dir"); std::vector dirs = GenerateScreenLockProtectionDir(oldInfo.GetBundleName()); for (const std::string &dir : dirs) { if (InstalldClient::GetInstance()->RemoveDir(dir) != ERR_OK) { @@ -2941,7 +2939,7 @@ void BaseBundleInstaller::DeleteEncryptionKeyId(const InnerBundleInfo &oldInfo) LOG_E(BMS_TAG_INSTALLER, "%{public}s get user %{public}d failed", oldInfo.GetBundleName().c_str(), userId_); return; } - if (InstalldClient::GetInstance()->DeleteEncryptionKeyId(userInfo.keyId) != ERR_OK) { + if (InstalldClient::GetInstance()->DeleteEncryptionKeyId(userInfo.accessTokenId) != ERR_OK) { LOG_W(BMS_TAG_INSTALLER, "delete encryption key id failed"); } } diff --git a/services/bundlemgr/src/el5_filekey_callback.cpp b/services/bundlemgr/src/el5_filekey_callback.cpp index e78a9988ae..674697a875 100644 --- a/services/bundlemgr/src/el5_filekey_callback.cpp +++ b/services/bundlemgr/src/el5_filekey_callback.cpp @@ -29,7 +29,7 @@ void El5FilekeyCallback::OnRegenerateAppKey(std::vectorSetEncryptionPolicy( - info.uid, info.bundleName, info.userId, keyId); + info.uid, info.bundleName, info.userId, keyId, info.accessTokenId); if (result != ERR_OK) { APP_LOGE("SetEncryptionPolicy failed for %{public}s", info.bundleName.c_str()); } diff --git a/services/bundlemgr/src/installd/installd_host_impl.cpp b/services/bundlemgr/src/installd/installd_host_impl.cpp index c6fd5c4607..a4e617f33d 100644 --- a/services/bundlemgr/src/installd/installd_host_impl.cpp +++ b/services/bundlemgr/src/installd/installd_host_impl.cpp @@ -1513,7 +1513,7 @@ bool InstalldHostImpl::CheckPathValid(const std::string &path, const std::string } ErrCode InstalldHostImpl::SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { if (!InstalldPermissionMgr::VerifyCallingPermission(Constants::FOUNDATION_UID)) { LOG_E(BMS_TAG_INSTALLD, "installd permission denied, only used for foundation process"); @@ -1523,24 +1523,20 @@ ErrCode InstalldHostImpl::SetEncryptionPolicy(int32_t uid, const std::string &bu LOG_E(BMS_TAG_INSTALLD, "Calling the function SetEncryptionPolicy with invalid param"); return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; } - if (!InstalldOperator::GenerateKeyIdAndSetPolicy(uid, bundleName, userId, keyId)) { + if (!InstalldOperator::GenerateKeyIdAndSetPolicy(uid, bundleName, userId, keyId, accessTokenId)) { LOG_E(BMS_TAG_INSTALLD, "EncryptionPaths fail"); return ERR_APPEXECFWK_INSTALLD_GENERATE_KEY_FAILED; } return ERR_OK; } -ErrCode InstalldHostImpl::DeleteEncryptionKeyId(const std::string &keyId) +ErrCode InstalldHostImpl::DeleteEncryptionKeyId(const uint32_t accessTokenId) { if (!InstalldPermissionMgr::VerifyCallingPermission(Constants::FOUNDATION_UID)) { LOG_E(BMS_TAG_INSTALLD, "installd permission denied, only used for foundation process"); return ERR_APPEXECFWK_INSTALLD_PERMISSION_DENIED; } - if (keyId.empty()) { - LOG_E(BMS_TAG_INSTALLD, "Calling the function DeleteEncryptionKeyId with invalid param"); - return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; - } - if (!InstalldOperator::DeleteKeyId(keyId)) { + if (!InstalldOperator::DeleteKeyId(accessTokenId)) { LOG_E(BMS_TAG_INSTALLD, "EncryptionPaths fail"); return ERR_APPEXECFWK_INSTALLD_DELETE_KEY_FAILED; } diff --git a/services/bundlemgr/src/installd/installd_operator.cpp b/services/bundlemgr/src/installd/installd_operator.cpp index a3ca0671a1..2fdb81111d 100644 --- a/services/bundlemgr/src/installd/installd_operator.cpp +++ b/services/bundlemgr/src/installd/installd_operator.cpp @@ -45,6 +45,7 @@ #include "bundle_service_constants.h" #include "bundle_util.h" #include "directory_ex.h" +#include "el5_filekey_manager_error.h" #include "el5_filekey_manager_kit.h" #include "parameters.h" #include "securec.h" @@ -2127,12 +2128,16 @@ int32_t InstalldOperator::CallIoctl(int32_t flag, int32_t associatedFlag, int32_ #endif bool InstalldOperator::GenerateKeyIdAndSetPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { - LOG_D(BMS_TAG_INSTALLD, "GenerateKeyId uid is %{public}d, bundleName is %{public}s, userId is %{public}d", - uid, bundleName.c_str(), userId); + LOG_D(BMS_TAG_INSTALLD, "GenerateKeyId uid is %{public}d, bundleName is %{public}s, userId is %{public}d, " + "accessTokenId is %{public}d", uid, bundleName.c_str(), userId, accessTokenId); auto ret = Security::AccessToken::El5FilekeyManagerKit::GenerateAppKey( - static_cast(uid), bundleName, keyId); + static_cast(uid), bundleName, accessTokenId, keyId); + if (ret == Security::AccessToken::EFM_ERR_KEYID_EXISTED) { + LOG_I(BMS_TAG_INSTALLD, "key id is existed"); + return true; + } if (ret != 0) { LOG_E(BMS_TAG_INSTALLD, "Call GenerateAppKey failed ret = %{public}d", ret); return false; @@ -2178,10 +2183,10 @@ bool InstalldOperator::GenerateKeyIdAndSetPolicy(int32_t uid, const std::string return true; } -bool InstalldOperator::DeleteKeyId(const std::string &keyId) +bool InstalldOperator::DeleteKeyId(const uint32_t accessTokenId) { - LOG_D(BMS_TAG_INSTALLD, "DeleteKeyId keyId is %{public}s", keyId.c_str()); - auto ret = Security::AccessToken::El5FilekeyManagerKit::DeleteAppKey(keyId); + LOG_D(BMS_TAG_INSTALLD, "DeleteKeyId accessTokenId is %{public}d", accessTokenId); + auto ret = Security::AccessToken::El5FilekeyManagerKit::DeleteAppKey(accessTokenId); if (ret != 0) { LOG_E(BMS_TAG_INSTALLD, "Call DeleteAppKey failed ret = %{public}d", ret); return false; diff --git a/services/bundlemgr/src/installd_client.cpp b/services/bundlemgr/src/installd_client.cpp index 4c7a2b4adc..168a9b5c16 100644 --- a/services/bundlemgr/src/installd_client.cpp +++ b/services/bundlemgr/src/installd_client.cpp @@ -520,22 +520,18 @@ ErrCode InstalldClient::ExtractEncryptedSoFiles(const std::string &hapPath, cons } ErrCode InstalldClient::SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { if (bundleName.empty()) { APP_LOGE("bundleName is empty"); return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; } - return CallService(&IInstalld::SetEncryptionPolicy, uid, bundleName, userId, keyId); + return CallService(&IInstalld::SetEncryptionPolicy, uid, bundleName, userId, keyId, accessTokenId); } -ErrCode InstalldClient::DeleteEncryptionKeyId(const std::string &keyId) +ErrCode InstalldClient::DeleteEncryptionKeyId(const uint32_t accessTokenId) { - if (keyId.empty()) { - APP_LOGE("keyId is empty"); - return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; - } - return CallService(&IInstalld::DeleteEncryptionKeyId, keyId); + return CallService(&IInstalld::DeleteEncryptionKeyId, accessTokenId); } ErrCode InstalldClient::RemoveExtensionDir(int32_t userId, const std::vector &extensionBundleDirs) diff --git a/services/bundlemgr/src/ipc/installd_host.cpp b/services/bundlemgr/src/ipc/installd_host.cpp index f315063955..7144844304 100644 --- a/services/bundlemgr/src/ipc/installd_host.cpp +++ b/services/bundlemgr/src/ipc/installd_host.cpp @@ -804,9 +804,10 @@ bool InstalldHost::HandleSetEncryptionDir(MessageParcel &data, MessageParcel &re int32_t uid = data.ReadInt32(); std::string bundleName = Str16ToStr8(data.ReadString16()); int32_t userId = data.ReadInt32(); + uint32_t accessTokenId = data.ReadUint32(); std::string keyId = ""; - ErrCode result = SetEncryptionPolicy(uid, bundleName, userId, keyId); + ErrCode result = SetEncryptionPolicy(uid, bundleName, userId, keyId, accessTokenId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result); if (!reply.WriteString(keyId)) { APP_LOGE("write keyId failed"); @@ -817,9 +818,9 @@ bool InstalldHost::HandleSetEncryptionDir(MessageParcel &data, MessageParcel &re bool InstalldHost::HandleDeleteEncryptionKeyId(MessageParcel &data, MessageParcel &reply) { - std::string keyId = Str16ToStr8(data.ReadString16()); + uint32_t accessTokenId = data.ReadUint32(); - ErrCode result = DeleteEncryptionKeyId(keyId); + ErrCode result = DeleteEncryptionKeyId(accessTokenId); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result); return true; } diff --git a/services/bundlemgr/src/ipc/installd_proxy.cpp b/services/bundlemgr/src/ipc/installd_proxy.cpp index 619a69493f..0676ef8a8d 100644 --- a/services/bundlemgr/src/ipc/installd_proxy.cpp +++ b/services/bundlemgr/src/ipc/installd_proxy.cpp @@ -774,13 +774,14 @@ ErrCode InstalldProxy::RemoveSignProfile(const std::string &bundleName) } ErrCode InstalldProxy::SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { MessageParcel data; INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor())); INSTALLD_PARCEL_WRITE(data, Int32, uid); INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(bundleName)); INSTALLD_PARCEL_WRITE(data, Int32, userId); + INSTALLD_PARCEL_WRITE(data, Uint32, accessTokenId); MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); @@ -793,11 +794,11 @@ ErrCode InstalldProxy::SetEncryptionPolicy(int32_t uid, const std::string &bundl return ERR_OK; } -ErrCode InstalldProxy::DeleteEncryptionKeyId(const std::string &keyId) +ErrCode InstalldProxy::DeleteEncryptionKeyId(const uint32_t accessTokenId) { MessageParcel data; INSTALLD_PARCEL_WRITE_INTERFACE_TOKEN(data, (GetDescriptor())); - INSTALLD_PARCEL_WRITE(data, String16, Str8ToStr16(keyId)); + INSTALLD_PARCEL_WRITE(data, Uint32, accessTokenId); MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); diff --git a/services/bundlemgr/test/mock/src/installd_client.cpp b/services/bundlemgr/test/mock/src/installd_client.cpp index 96cf7d4372..5267c1839f 100644 --- a/services/bundlemgr/test/mock/src/installd_client.cpp +++ b/services/bundlemgr/test/mock/src/installd_client.cpp @@ -419,13 +419,13 @@ ErrCode InstalldClient::RemoveSignProfile(const std::string &bundleName) } ErrCode InstalldClient::SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { if (bundleName.empty()) { APP_LOGE("bundleName is empty"); return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; } - return CallService(&IInstalld::SetEncryptionPolicy, uid, bundleName, userId, keyId); + return CallService(&IInstalld::SetEncryptionPolicy, uid, bundleName, userId, keyId, accessTokenId); } ErrCode InstalldClient::RemoveExtensionDir(int32_t userId, const std::vector &extensionBundleDirs) @@ -457,13 +457,9 @@ ErrCode InstalldClient::CreateExtensionDataDir(const CreateDirParam &createDirPa return CallService(&IInstalld::CreateExtensionDataDir, createDirParam); } -ErrCode InstalldClient::DeleteEncryptionKeyId(const std::string &keyId) +ErrCode InstalldClient::DeleteEncryptionKeyId(const uint32_t accessTokenId) { - if (keyId.empty()) { - APP_LOGE("keyId is empty"); - return ERR_APPEXECFWK_INSTALLD_PARAM_ERROR; - } - return CallService(&IInstalld::DeleteEncryptionKeyId, keyId); + return CallService(&IInstalld::DeleteEncryptionKeyId, accessTokenId); } bool InstalldClient::StartInstalldService() diff --git a/services/bundlemgr/test/mock/src/mock_install_client.cpp b/services/bundlemgr/test/mock/src/mock_install_client.cpp index a0e0b13b91..5274614c64 100644 --- a/services/bundlemgr/test/mock/src/mock_install_client.cpp +++ b/services/bundlemgr/test/mock/src/mock_install_client.cpp @@ -275,12 +275,12 @@ ErrCode InstalldClient::RemoveSignProfile(const std::string &bundleName) } ErrCode InstalldClient::SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { return ERR_OK; } -ErrCode InstalldClient::DeleteEncryptionKeyId(const std::string &keyId) +ErrCode InstalldClient::DeleteEncryptionKeyId(const uint32_t accessTokenId) { return ERR_OK; } diff --git a/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp b/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp index 5d45ff59b9..f2f9d16762 100755 --- a/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp +++ b/services/bundlemgr/test/mock/src/mock_installd_host_impl.cpp @@ -271,12 +271,12 @@ ErrCode InstalldHostImpl::RemoveSignProfile(const std::string &bundleName) } ErrCode InstalldHostImpl::SetEncryptionPolicy(int32_t uid, const std::string &bundleName, - const int32_t userId, std::string &keyId) + const int32_t userId, std::string &keyId, const uint32_t accessTokenId) { return ERR_OK; } -ErrCode InstalldHostImpl::DeleteEncryptionKeyId(const std::string &keyId) +ErrCode InstalldHostImpl::DeleteEncryptionKeyId(const uint32_t accessTokenId) { return ERR_OK; } diff --git a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_host_impl_test.cpp b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_host_impl_test.cpp index 4071cef3fc..bac15b706a 100755 --- a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_host_impl_test.cpp +++ b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_host_impl_test.cpp @@ -905,7 +905,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_5100, Function | Sma auto hostImpl = GetInstalldHostImpl(); ASSERT_NE(hostImpl, nullptr); std::string keyId = ""; - auto ret = hostImpl->SetEncryptionPolicy(0, "", 100, keyId); + auto ret = hostImpl->SetEncryptionPolicy(0, "", 100, keyId, 0); EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PERMISSION_DENIED); } @@ -919,7 +919,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_5200, Function | Sma { auto hostImpl = GetInstalldHostImpl(); ASSERT_NE(hostImpl, nullptr); - auto ret = hostImpl->DeleteEncryptionKeyId(""); + auto ret = hostImpl->DeleteEncryptionKeyId(0); EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALLD_PERMISSION_DENIED); } diff --git a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_ipc_test.cpp b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_ipc_test.cpp index 618c259f7e..18bf8ee545 100755 --- a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_ipc_test.cpp +++ b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_ipc_test.cpp @@ -826,7 +826,7 @@ HWTEST_F(BmsInstallDaemonIpcTest, InstalldProxyTest_4100, Function | SmallTest | std::string bundleName = TEST_STRING; int32_t userId = 100; std::string keyId = ""; - auto ret = proxy->SetEncryptionPolicy(uid, bundleName, userId, keyId); + auto ret = proxy->SetEncryptionPolicy(uid, bundleName, userId, keyId, 0); EXPECT_EQ(ret, ERR_OK); } @@ -840,7 +840,7 @@ HWTEST_F(BmsInstallDaemonIpcTest, InstalldProxyTest_4200, Function | SmallTest | auto proxy = GetInstallProxy(); EXPECT_NE(proxy, nullptr); - auto ret = proxy->DeleteEncryptionKeyId(TEST_STRING); + auto ret = proxy->DeleteEncryptionKeyId(0); EXPECT_EQ(ret, ERR_OK); } } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_operator_test.cpp b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_operator_test.cpp index 0fc73a2936..1be2de42ad 100755 --- a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_operator_test.cpp +++ b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_operator_test.cpp @@ -1237,7 +1237,7 @@ HWTEST_F(BmsInstallDaemonOperatorTest, InstalldOperatorTest_7500, Function | Sma HWTEST_F(BmsInstallDaemonOperatorTest, InstalldOperatorTest_7600, Function | SmallTest | Level0) { std::string keyId = ""; - bool res = InstalldOperator::GenerateKeyIdAndSetPolicy(0, "", 100, keyId); + bool res = InstalldOperator::GenerateKeyIdAndSetPolicy(0, "", 100, keyId, 0); EXPECT_EQ(res, false); } diff --git a/services/bundlemgr/test/unittest/bms_installd_client_test/bms_installd_client_test.cpp b/services/bundlemgr/test/unittest/bms_installd_client_test/bms_installd_client_test.cpp index 7203958ca2..0065623390 100644 --- a/services/bundlemgr/test/unittest/bms_installd_client_test/bms_installd_client_test.cpp +++ b/services/bundlemgr/test/unittest/bms_installd_client_test/bms_installd_client_test.cpp @@ -1110,7 +1110,7 @@ HWTEST_F(BmsInstalldClientTest, BmsInstalldClientTest_CopyFiles_0100, TestSize.L HWTEST_F(BmsInstalldClientTest, BmsInstalldClientTest_SetEncryptionPolicy_0100, TestSize.Level1) { std::string keyId = ""; - ErrCode result = installClient_->SetEncryptionPolicy(0, "", 100, keyId); + ErrCode result = installClient_->SetEncryptionPolicy(0, "", 100, keyId, 0); EXPECT_EQ(result, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR); } @@ -1121,7 +1121,7 @@ HWTEST_F(BmsInstalldClientTest, BmsInstalldClientTest_SetEncryptionPolicy_0100, */ HWTEST_F(BmsInstalldClientTest, BmsInstalldClientTest_DeleteEncryptionKeyId_0100, TestSize.Level1) { - ErrCode result = installClient_->DeleteEncryptionKeyId(""); + ErrCode result = installClient_->DeleteEncryptionKeyId(0); EXPECT_EQ(result, ERR_APPEXECFWK_INSTALLD_PARAM_ERROR); } -- Gitee