!944 添加 XCollie 机制

Merge pull request !944 from 率率/xcollie
This commit is contained in:
openharmony_ci 2024-06-25 11:50:01 +00:00 committed by Gitee
commit 1a28e9452a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 125 additions and 0 deletions

View File

@ -33,6 +33,7 @@
"ability_runtime",
"bundle_framework",
"hilog",
"hicollie",
"ipc",
"safwk",
"samgr",

View File

@ -73,10 +73,12 @@ ohos_source_set("iam_utils") {
sources = [
"utils/iam_mem.cpp",
"utils/iam_time.cpp",
"utils/xcollie_helper.cpp",
]
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
]
@ -99,6 +101,7 @@ ohos_source_set("iam_test") {
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
]

View File

@ -0,0 +1,40 @@
/*
* 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 "xcollie_helper.h"
#include "xcollie/xcollie.h"
#include "xcollie/xcollie_define.h"
#include "iam_logger.h"
#define LOG_TAG "USER_AUTH_SA"
namespace OHOS {
namespace UserIam {
namespace Common {
XCollieHelper::XCollieHelper(const std::string &name, unsigned int timeout)
{
id_ = HiviewDFX::XCollie::GetInstance()
.SetTimer(name, timeout, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_DEFAULT);
}
XCollieHelper::~XCollieHelper()
{
HiviewDFX::XCollie::GetInstance().CancelTimer(id_);
}
} // namespace Common
} // namespace UserIam
} // namespace OHOS

View File

@ -0,0 +1,37 @@
/*
* 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 RELIABILITY_XCOLLIE_HELPER_H
#define RELIABILITY_XCOLLIE_HELPER_H
#include <string>
namespace OHOS {
namespace UserIam {
namespace Common {
constexpr unsigned int API_CALL_TIMEOUT = 5; // 5s
class XCollieHelper {
public:
XCollieHelper(const std::string &name, unsigned int timeout);
~XCollieHelper();
private:
int id_;
};
} // namespace Common
} // namespace UserIam
} // namespace OHOS
#endif

View File

@ -39,6 +39,7 @@
#include "resource_node_pool.h"
#include "template_cache_manager.h"
#include "remote_msg_util.h"
#include "xcollie_helper.h"
#define LOG_TAG "USER_AUTH_SA"
@ -129,6 +130,7 @@ void CoAuthService::AddExecutorDeathRecipient(uint64_t executorIndex, AuthType a
uint64_t CoAuthService::ExecutorRegister(const ExecutorRegisterInfo &info, sptr<ExecutorCallbackInterface> &callback)
{
IAM_LOGI("register resource node begin");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (callback == nullptr) {
IAM_LOGE("executor callback is nullptr");
return INVALID_EXECUTOR_INDEX;
@ -179,6 +181,7 @@ uint64_t CoAuthService::ExecutorRegister(const ExecutorRegisterInfo &info, sptr<
void CoAuthService::ExecutorUnregister(uint64_t executorIndex)
{
IAM_LOGI("delete resource node begin");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (!IpcCommon::CheckPermission(*this, ACCESS_AUTH_RESPOOL)) {
IAM_LOGE("failed to check permission");
return;

View File

@ -41,6 +41,7 @@
#include "remote_iam_callback.h"
#include "remote_auth_service.h"
#include "device_manager_util.h"
#include "xcollie_helper.h"
#define LOG_TAG "USER_AUTH_SA"
@ -244,6 +245,7 @@ void UserAuthService::GetProperty(int32_t userId, AuthType authType,
const std::vector<Attributes::AttributeKey> &keys, sptr<GetExecutorPropertyCallbackInterface> &callback)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN(callback != nullptr);
Attributes values;
@ -299,6 +301,7 @@ void UserAuthService::SetProperty(int32_t userId, AuthType authType, const Attri
sptr<SetExecutorPropertyCallbackInterface> &callback)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");
return;
@ -517,6 +520,7 @@ uint64_t UserAuthService::AuthUser(AuthParamInner &authParam, std::optional<Remo
sptr<UserAuthCallbackInterface> &callback)
{
IAM_LOGI("start, %{public}s", GetAuthParamStr(authParam, remoteAuthParam).c_str());
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
auto contextCallback = GetAuthContextCallback(INNER_API_VERSION_10000, authParam.challenge, authParam.authType,
authParam.authTrustLevel, callback);
if (contextCallback == nullptr) {
@ -594,6 +598,7 @@ int32_t UserAuthService::PrepareRemoteAuthInner(const std::string &networkId)
int32_t UserAuthService::PrepareRemoteAuth(const std::string &networkId, sptr<UserAuthCallbackInterface> &callback)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");
return INVALID_PARAMETERS;
@ -673,6 +678,7 @@ uint64_t UserAuthService::Identify(const std::vector<uint8_t> &challenge, AuthTy
sptr<UserAuthCallbackInterface> &callback)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");
@ -720,6 +726,7 @@ uint64_t UserAuthService::Identify(const std::vector<uint8_t> &challenge, AuthTy
int32_t UserAuthService::CancelAuthOrIdentify(uint64_t contextId)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
bool checkRet = !IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION) &&
!IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION);
if (checkRet) {
@ -1101,6 +1108,7 @@ int32_t UserAuthService::RegistUserAuthSuccessEventListener(const std::vector<Au
const sptr<AuthEventListenerInterface> &listener)
{
IAM_LOGE("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS);
if (!CheckAuthTypeIsValid(authType)) {
@ -1126,6 +1134,7 @@ int32_t UserAuthService::UnRegistUserAuthSuccessEventListener(
const sptr<AuthEventListenerInterface> &listener)
{
IAM_LOGE("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS);
if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) {
@ -1145,6 +1154,7 @@ int32_t UserAuthService::UnRegistUserAuthSuccessEventListener(
int32_t UserAuthService::SetGlobalConfigParam(const GlobalConfigParam &param)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) {
IAM_LOGE("failed to check permission");
return CHECK_PERMISSION_FAILED;

View File

@ -36,6 +36,7 @@
#include "user_idm_callback_proxy.h"
#include "user_idm_database.h"
#include "user_idm_session_controller.h"
#include "xcollie_helper.h"
#define LOG_TAG "USER_AUTH_SA"
@ -66,6 +67,7 @@ void UserIdmService::OnStop()
int32_t UserIdmService::OpenSession(int32_t userId, std::vector<uint8_t> &challenge)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) {
IAM_LOGE("failed to check permission");
return CHECK_PERMISSION_FAILED;
@ -91,6 +93,7 @@ int32_t UserIdmService::OpenSession(int32_t userId, std::vector<uint8_t> &challe
void UserIdmService::CloseSession(int32_t userId)
{
IAM_LOGI("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) {
IAM_LOGE("failed to check permission");
return;
@ -139,6 +142,7 @@ int32_t UserIdmService::GetCredentialInfoInner(int32_t userId, AuthType authType
int32_t UserIdmService::GetCredentialInfo(int32_t userId, AuthType authType,
const sptr<IdmGetCredInfoCallbackInterface> &callback)
{
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");
return INVALID_PARAMETERS;
@ -182,6 +186,7 @@ int32_t UserIdmService::GetSecInfoInner(int32_t userId, SecUserInfo &secUserInfo
int32_t UserIdmService::GetSecInfo(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback)
{
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");
return INVALID_PARAMETERS;
@ -239,6 +244,7 @@ void UserIdmService::StartEnroll(Enrollment::EnrollmentPara &para,
void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPara,
const sptr<IdmCallbackInterface> &callback, bool isUpdate)
{
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN(callback != nullptr);
Attributes extraInfo;
@ -280,6 +286,7 @@ void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPar
void UserIdmService::UpdateCredential(int32_t userId, const CredentialPara &credPara,
const sptr<IdmCallbackInterface> &callback)
{
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (callback == nullptr) {
IAM_LOGE("callback is nullptr");
return;
@ -298,6 +305,7 @@ void UserIdmService::UpdateCredential(int32_t userId, const CredentialPara &cred
int32_t UserIdmService::Cancel(int32_t userId)
{
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) {
IAM_LOGE("failed to check permission");
return CHECK_PERMISSION_FAILED;
@ -341,6 +349,7 @@ int32_t UserIdmService::CancelCurrentEnroll()
int32_t UserIdmService::EnforceDelUser(int32_t userId, const sptr<IdmCallbackInterface> &callback)
{
IAM_LOGI("to delete userid: %{public}d", userId);
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, INVALID_PARAMETERS);
Attributes extraInfo;
@ -388,6 +397,7 @@ int32_t UserIdmService::EnforceDelUser(int32_t userId, const sptr<IdmCallbackInt
void UserIdmService::DelUser(int32_t userId, const std::vector<uint8_t> authToken,
const sptr<IdmCallbackInterface> &callback)
{
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN(callback != nullptr);
Attributes extraInfo;
@ -441,6 +451,7 @@ void UserIdmService::DelUser(int32_t userId, const std::vector<uint8_t> authToke
void UserIdmService::DelCredential(int32_t userId, uint64_t credentialId,
const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback)
{
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN(callback != nullptr);
Attributes extraInfo;
@ -612,6 +623,7 @@ void UserIdmService::ClearRedundancyCredentialInner()
void UserIdmService::ClearRedundancyCredential(const sptr<IdmCallbackInterface> &callback)
{
IAM_LOGE("start");
Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT);
IF_FALSE_LOGE_AND_RETURN(callback != nullptr);
Attributes extraInfo;

View File

@ -33,6 +33,7 @@ ohos_source_set("attributes_fuzzer") {
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
]
@ -58,6 +59,7 @@ ohos_source_set("dfx_fuzzer") {
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
@ -98,6 +100,7 @@ ohos_source_set("userauth_client_ipc_fuzzer") {
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
"ipc:ipc_single",
]
@ -124,6 +127,7 @@ ohos_source_set("userauth_service_base_fuzzer") {
external_deps = [
"c_utils:utils",
"drivers_interface_user_auth:libuser_auth_proxy_2.0",
"hicollie:libhicollie",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
@ -198,6 +202,7 @@ ohos_source_set("userauth_service_core_fuzzer") {
"c_utils:utils",
"device_manager:devicemanagersdk",
"drivers_interface_user_auth:libuser_auth_proxy_2.0",
"hicollie:libhicollie",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
@ -274,6 +279,7 @@ ohos_source_set("userauth_service_context_fuzzer") {
"ability_runtime:extension_manager",
"c_utils:utils",
"drivers_interface_user_auth:libuser_auth_proxy_2.0",
"hicollie:libhicollie",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
@ -327,6 +333,7 @@ ohos_source_set("userauth_service_ipc_fuzzer") {
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
"ipc:ipc_single",
]
@ -362,6 +369,7 @@ ohos_source_set("userauth_service_remote_connect_fuzzer") {
"c_utils:utils",
"device_manager:devicemanagersdk",
"dsoftbus:softbus_client",
"hicollie:libhicollie",
"hilog:libhilog",
"init:libbegetutil",
"safwk:system_ability_fwk",
@ -416,6 +424,7 @@ ohos_source_set("userauth_services_ipc_fuzzer") {
"c_utils:utils",
"device_manager:devicemanagersdk",
"drivers_interface_user_auth:libuser_auth_proxy_2.0",
"hicollie:libhicollie",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
@ -452,6 +461,7 @@ ohos_source_set("iam_thread_pool_fuzzer") {
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
]
@ -471,10 +481,12 @@ ohos_source_set("iam_utils_fuzzer") {
sources = [
"../../../common/utils/iam_mem.cpp",
"../../../common/utils/iam_time.cpp",
"../../../common/utils/xcollie_helper.cpp",
]
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
]
@ -493,6 +505,7 @@ ohos_source_set("iam_test_fuzzer") {
external_deps = [
"c_utils:utils",
"hicollie:libhicollie",
"hilog:libhilog",
]

View File

@ -46,6 +46,7 @@ ohos_fuzztest("CoAuthServiceFuzzTest") {
deps = [
"../../common_fuzzer:attributes_fuzzer",
"../../common_fuzzer:iam_test_fuzzer",
"../../common_fuzzer:iam_utils_fuzzer",
"../../common_fuzzer:userauth_services_ipc_fuzzer",
]

View File

@ -43,6 +43,7 @@ ohos_fuzztest("CoAuthStubFuzzTest") {
deps = [
"../../common_fuzzer:attributes_fuzzer",
"../../common_fuzzer:iam_test_fuzzer",
"../../common_fuzzer:iam_utils_fuzzer",
"../../common_fuzzer:userauth_services_ipc_fuzzer",
]

View File

@ -49,6 +49,7 @@ ohos_fuzztest("ContextCallbackImplFuzzTest") {
"../../../common_fuzzer:attributes_fuzzer",
"../../../common_fuzzer:dfx_fuzzer",
"../../../common_fuzzer:iam_test_fuzzer",
"../../../common_fuzzer:iam_utils_fuzzer",
"../../../common_fuzzer:userauth_service_base_fuzzer",
"../../../common_fuzzer:userauth_service_context_fuzzer",
"../../../common_fuzzer:userauth_service_core_fuzzer",

View File

@ -50,6 +50,7 @@ ohos_fuzztest("ContextPoolImplFuzzTest") {
"../../../common_fuzzer:attributes_fuzzer",
"../../../common_fuzzer:dfx_fuzzer",
"../../../common_fuzzer:iam_test_fuzzer",
"../../../common_fuzzer:iam_utils_fuzzer",
"../../../common_fuzzer:userauth_service_context_fuzzer",
"../../../common_fuzzer:userauth_service_core_fuzzer",
"../../../common_fuzzer:userauth_services_ipc_fuzzer",

View File

@ -49,6 +49,7 @@ ohos_fuzztest("ServiceCoreFuzzTest") {
deps = [
"../../common_fuzzer:attributes_fuzzer",
"../../common_fuzzer:iam_test_fuzzer",
"../../common_fuzzer:iam_utils_fuzzer",
"../../common_fuzzer:userauth_services_ipc_fuzzer",
]

View File

@ -40,6 +40,7 @@ ohos_fuzztest("SoftBusFuzzTest") {
deps = [
"../../common_fuzzer:attributes_fuzzer",
"../../common_fuzzer:iam_test_fuzzer",
"../../common_fuzzer:iam_utils_fuzzer",
"../../common_fuzzer:userauth_service_remote_connect_fuzzer",
"../../common_fuzzer:userauth_services_ipc_fuzzer",
]