diff --git a/interfaces/innerkits/code_sign_utils/src/code_sign_enable_multi_task.cpp b/interfaces/innerkits/code_sign_utils/src/code_sign_enable_multi_task.cpp index dd828fda85543eca76294a418d434382734a9472..3e3d7d9423ea6eab719d09774b7cb681ddecba47 100644 --- a/interfaces/innerkits/code_sign_utils/src/code_sign_enable_multi_task.cpp +++ b/interfaces/innerkits/code_sign_utils/src/code_sign_enable_multi_task.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -48,7 +48,7 @@ bool CodeSignEnableMultiTask::ExecuteEnableCodeSignTask(int32_t &taskRet, const SortTaskData(); for (uint32_t i = 0; i < enableData_.size(); i++) { - LOG_DEBUG(LABEL, "index: %{public}d, name:%{public}s, %{public}lld", + LOG_DEBUG("index: %{public}d, name:%{public}s, %{public}lld", i, enableData_[i].first.c_str(), enableData_[i].second.data_size); ExecuteEnableCodeSignTask(i, taskRet, ownerId, path, func); } @@ -72,7 +72,7 @@ void CodeSignEnableMultiTask::ExecuteEnableCodeSignTask(uint32_t &index, int32_t const std::string &ownerId, const std::string &path, CallbackFunc &func) { auto enableCodeSignTask = [this, index, &ownerId, &path, &func, &taskRet]() { - LOG_DEBUG(LABEL, "ExecuteEnableCodeSignTask task called"); + LOG_DEBUG("ExecuteEnableCodeSignTask task called"); { std::unique_lock lock(cvLock_); if (taskRet != CS_SUCCESS) { @@ -90,7 +90,7 @@ void CodeSignEnableMultiTask::ExecuteEnableCodeSignTask(uint32_t &index, int32_t if (ret == CS_SUCCESS) { ret = func(this->enableData_[index].first, this->enableData_[index].second); } - LOG_DEBUG(LABEL, "Task return info index: %{public}d, ret: %{public}d", index, ret); + LOG_DEBUG("Task return info index: %{public}d, ret: %{public}d", index, ret); std::unique_lock lock(cvLock_); if (taskRet == CS_SUCCESS) { @@ -118,11 +118,11 @@ int32_t CodeSignEnableMultiTask::CheckOwnerId(const std::string &path, const std ret = SignerInfo::ParseOwnerIdFromSignature(sigBuffer, retId); if (ret != CS_SUCCESS) { ReportInvalidOwner(path, ownerId, "invalid"); - LOG_ERROR(LABEL, "get ownerId from signature failed, ret %{public}d", ret); + LOG_ERROR("get ownerId from signature failed, ret %{public}d", ret); } else if (retId != ownerId) { ret = CS_ERR_INVALID_OWNER_ID; ReportInvalidOwner(path, ownerId, retId); - LOG_ERROR(LABEL, "invalid ownerId retId %{public}s ownerId %{public}s", retId.c_str(), ownerId.c_str()); + LOG_ERROR("invalid ownerId retId %{public}s ownerId %{public}s", retId.c_str(), ownerId.c_str()); } return ret; } diff --git a/interfaces/innerkits/code_sign_utils/src/code_sign_helper.cpp b/interfaces/innerkits/code_sign_utils/src/code_sign_helper.cpp index 8c3932f28794c6a0aefabc2d813e5aa1a3029a06..e21bd681cb6f03ed929de7c46573aeab4fee4656 100644 --- a/interfaces/innerkits/code_sign_utils/src/code_sign_helper.cpp +++ b/interfaces/innerkits/code_sign_utils/src/code_sign_helper.cpp @@ -69,7 +69,7 @@ int32_t CodeSignHelper::ExecuteMultiTask(int32_t ret, const std::string &ownerId { bool waitStatus = multiTask_.ExecuteEnableCodeSignTask(ret, ownerId, path, func); if (!waitStatus) { - LOG_ERROR(LABEL, "enable code sign timeout"); + LOG_ERROR("enable code sign timeout"); return CS_ERR_ENABLE_TIMEOUT; } return ret; @@ -84,7 +84,7 @@ void CodeSignHelper::ShowCodeSignInfo(const std::string &path, const struct code rootHashPtr = reinterpret_cast(arg.root_hash_ptr); } - LOG_DEBUG(LABEL, "{ " + LOG_DEBUG("{ " "file:%{public}s version:%{public}d hash_algorithm:%{public}d block_size:%{public}d sig_size:%{public}d " "data_size:%{public}lld salt_size:%{public}d salt:[%{public}d, ..., %{public}d, ..., %{public}d] " "flags:%{public}d tree_offset:%{public}lld root_hash:[%{public}d, %{public}d, %{public}d, ..., %{public}d, " diff --git a/interfaces/innerkits/code_sign_utils/src/code_sign_utils.cpp b/interfaces/innerkits/code_sign_utils/src/code_sign_utils.cpp index 72e9bbe7955c94d4c6d0334deab2678a90392098..f40f6b6e48f52929608f09ec943418f48cd42697 100644 --- a/interfaces/innerkits/code_sign_utils/src/code_sign_utils.cpp +++ b/interfaces/innerkits/code_sign_utils/src/code_sign_utils.cpp @@ -49,7 +49,7 @@ constexpr uint32_t HASH_PAGE_SIZE = 4096; #define NOT_SATISFIED_RETURN(CONDITION, ERROR_CODE, LOG_MESSAGE, ...) do { \ if (!(CONDITION)) { \ - LOG_ERROR(LABEL, LOG_MESSAGE, ##__VA_ARGS__); \ + LOG_ERROR(LOG_MESSAGE, ##__VA_ARGS__); \ return (ERROR_CODE); \ } \ } while (0) @@ -57,7 +57,7 @@ constexpr uint32_t HASH_PAGE_SIZE = 4096; int32_t CodeSignUtils::EnforceCodeSignForApp(const EntryMap &entryPath, const std::string &signatureFile) { - LOG_INFO(LABEL, "Start to enforce"); + LOG_INFO("Start to enforce"); // no files to enable, return directly if (entryPath.empty()) { return CS_SUCCESS; @@ -82,7 +82,7 @@ int32_t CodeSignUtils::EnforceCodeSignForApp(const EntryMap &entryPath, for (const auto &pathPair: entryPath) { const std::string &entryName = pathPair.first; const std::string &targetFile = pathPair.second; - LOG_DEBUG(LABEL, "Enable entry %{public}s, path = %{public}s", entryName.c_str(), targetFile.c_str()); + LOG_DEBUG("Enable entry %{public}s, path = %{public}s", entryName.c_str(), targetFile.c_str()); NOT_SATISFIED_RETURN(CheckFilePathValid(targetFile, Constants::ENABLE_APP_BASE_PATH), CS_ERR_FILE_PATH, "App file is invalid."); @@ -103,7 +103,7 @@ int32_t CodeSignUtils::EnforceCodeSignForApp(const EntryMap &entryPath, return ret; } } - LOG_INFO(LABEL, "Enforcing app complete"); + LOG_INFO("Enforcing app complete"); return CS_SUCCESS; } @@ -111,14 +111,14 @@ int32_t CodeSignUtils::IsSupportFsVerity(const std::string &path) { struct statx stat = {}; if (Statx(AT_FDCWD, path.c_str(), 0, STATX_ALL, &stat) != 0) { - LOG_ERROR(LABEL, "Get attributes failed, errno = <%{public}d, %{public}s>", + LOG_ERROR("Get attributes failed, errno = <%{public}d, %{public}s>", errno, strerror(errno)); return CS_ERR_FILE_INVALID; } if (stat.stx_attributes_mask & STATX_ATTR_VERITY) { return CS_SUCCESS; } - LOG_INFO(LABEL, "Fs-verity is not supported."); + LOG_INFO("Fs-verity is not supported."); return CS_ERR_FSVREITY_NOT_SUPPORTED; } @@ -127,7 +127,7 @@ int32_t CodeSignUtils::IsFsVerityEnabled(int fd) unsigned int flags; int ret = ioctl(fd, FS_IOC_GETFLAGS, &flags); if (ret < 0) { - LOG_ERROR(LABEL, "Get verity flags by ioctl failed. errno = <%{public}d, %{public}s>", + LOG_ERROR("Get verity flags by ioctl failed. errno = <%{public}d, %{public}s>", errno, strerror(errno)); return CS_ERR_FILE_INVALID; } @@ -148,7 +148,7 @@ int32_t CodeSignUtils::EnableCodeSignForFile(const std::string &path, const stru int32_t error; int32_t fd = open(path.c_str(), O_RDONLY); if (fd < 0) { - LOG_ERROR(LABEL, "Open file failed, path = %{public}s, errno = <%{public}d, %{public}s>", + LOG_ERROR("Open file failed, path = %{public}s, errno = <%{public}d, %{public}s>", path.c_str(), errno, strerror(errno)); return CS_ERR_FILE_OPEN; } @@ -156,7 +156,7 @@ int32_t CodeSignUtils::EnableCodeSignForFile(const std::string &path, const stru do { ret = IsFsVerityEnabled(fd); if (ret == CS_SUCCESS) { - LOG_INFO(LABEL, "Fs-verity has been enabled."); + LOG_INFO("Fs-verity has been enabled."); break; } else if (ret == CS_ERR_FILE_INVALID) { break; @@ -170,7 +170,7 @@ int32_t CodeSignUtils::EnableCodeSignForFile(const std::string &path, const stru } FinishTrace(HITRACE_TAG_ACCESS_CONTROL); if (error < 0) { - LOG_ERROR(LABEL, "Enable fs-verity failed, errno = <%{public}d, %{public}s>", + LOG_ERROR("Enable fs-verity failed, errno = <%{public}d, %{public}s>", errno, strerror(errno)); ReportEnableError(path, errno); ret = CS_ERR_ENABLE; @@ -179,7 +179,7 @@ int32_t CodeSignUtils::EnableCodeSignForFile(const std::string &path, const stru ret = CS_SUCCESS; } while (0); close(fd); - LOG_INFO(LABEL, "Enforcing file complete and ret = %{public}d", ret); + LOG_INFO("Enforcing file complete and ret = %{public}d", ret); return ret; } @@ -212,7 +212,7 @@ int32_t CodeSignUtils::EnforceCodeSignForFile(const std::string &path, const uin int32_t CodeSignUtils::EnforceCodeSignForAppWithOwnerId(const std::string &ownerId, const std::string &path, const EntryMap &entryPathMap, FileType type) { - LOG_INFO(LABEL, "Start to enforce codesign FileType:%{public}d, entryPathMap size:%{public}u, path = %{public}s", + LOG_INFO("Start to enforce codesign FileType:%{public}d, entryPathMap size:%{public}u, path = %{public}s", type, static_cast(entryPathMap.size()), path.c_str()); if (type == FILE_ENTRY_ADD || type == FILE_ENTRY_ONLY || type == FILE_ALL) { { @@ -220,7 +220,7 @@ int32_t CodeSignUtils::EnforceCodeSignForAppWithOwnerId(const std::string &owner storedEntryMap_.insert(entryPathMap.begin(), entryPathMap.end()); } if (type == FILE_ENTRY_ADD) { - LOG_DEBUG(LABEL, "Add entryPathMap complete"); + LOG_DEBUG("Add entryPathMap complete"); return CS_SUCCESS; } } else if (type >= FILE_TYPE_MAX) { @@ -251,7 +251,7 @@ int32_t CodeSignUtils::ProcessCodeSignBlock(const std::string &ownerId, const st int32_t CodeSignUtils::HandleCodeSignBlockFailure(const std::string &realPath, int32_t ret) { if ((ret == CS_CODE_SIGN_NOT_EXISTS) && InPermissiveMode()) { - LOG_DEBUG(LABEL, "Code sign not exists"); + LOG_DEBUG("Code sign not exists"); return CS_SUCCESS; } ReportParseCodeSig(realPath, ret); @@ -269,8 +269,7 @@ int32_t CodeSignUtils::EnableKeyInProfile(const std::string &bundleName, const B if (ret == CS_SUCCESS) { return ret; } - LOG_ERROR( - LABEL, "Enable key in profile failed. errno = <%{public}d, %{public}s>", errno, strerror(errno)); + LOG_ERROR("Enable key in profile failed. errno = <%{public}d, %{public}s>", errno, strerror(errno)); return CS_ERR_PROFILE; } @@ -280,8 +279,7 @@ int32_t CodeSignUtils::RemoveKeyInProfile(const std::string &bundleName) if (ret == CS_SUCCESS) { return ret; } - LOG_ERROR( - LABEL, "Remove key in profile failed. errno = <%{public}d, %{public}s>", errno, strerror(errno)); + LOG_ERROR("Remove key in profile failed. errno = <%{public}d, %{public}s>", errno, strerror(errno)); return CS_ERR_PROFILE; } @@ -299,7 +297,7 @@ bool CodeSignUtils::InPermissiveMode() file.close(); if (content == Constants::PERMISSIVE_CODE_SIGN_MODE) { - LOG_DEBUG(LABEL, "Permissive mode is on."); + LOG_DEBUG("Permissive mode is on."); return true; } return false; diff --git a/interfaces/innerkits/local_code_sign/src/local_code_sign_client.cpp b/interfaces/innerkits/local_code_sign/src/local_code_sign_client.cpp index a1043edf1b3df86879211d19184b588be1b2c208..3c4aee5148a6bf350c6a6233c7216c775075e0c5 100644 --- a/interfaces/innerkits/local_code_sign/src/local_code_sign_client.cpp +++ b/interfaces/innerkits/local_code_sign/src/local_code_sign_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -29,27 +29,27 @@ LocalCodeSignClient::LocalCodeSignClient() { localCodeSignSvrRecipient_ = new (std::nothrow) LocalCodeSignSvrRecipient(); if (localCodeSignSvrRecipient_ == nullptr) { - LOG_ERROR(LABEL, "Create LocalCodeSignSvrRecipient failed."); + LOG_ERROR("Create LocalCodeSignSvrRecipient failed."); } } void LocalCodeSignClient::LocalCodeSignSvrRecipient::OnRemoteDied(const wptr &remote) { if (remote == nullptr) { - LOG_ERROR(LABEL, "OnRemoteDied remote is nullptr."); + LOG_ERROR("OnRemoteDied remote is nullptr."); return; } - LOG_INFO(LABEL, "LocalCodeSignSvrRecipient OnRemoteDied."); + LOG_INFO("LocalCodeSignSvrRecipient OnRemoteDied."); LocalCodeSignClient::GetInstance().OnRemoteLocalCodeSignSvrDied(remote); } int32_t LocalCodeSignClient::StartSA() { std::unique_lock lock(proxyMutex_); - LOG_DEBUG(LABEL, "Start LocalCodeSignService"); + LOG_DEBUG("Start LocalCodeSignService"); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { - LOG_ERROR(LABEL, "Get system ability mgr failed."); + LOG_ERROR("Get system ability mgr failed."); return CS_ERR_SA_GET_SAMGR; } sptr loadCallback = new (std::nothrow) LocalCodeSignLoadCallback(); @@ -58,35 +58,35 @@ int32_t LocalCodeSignClient::StartSA() } int32_t ret = samgr->LoadSystemAbility(LOCAL_CODE_SIGN_SA_ID, loadCallback); if (ret != ERR_OK) { - LOG_ERROR(LABEL, "Load systemAbility failed, systemAbilityId:%{public}d ret code:%{public}d", + LOG_ERROR("Load systemAbility failed, systemAbilityId:%{public}d ret code:%{public}d", LOCAL_CODE_SIGN_SA_ID, ret); return CS_ERR_SA_LOAD_FAILED; } - LOG_INFO(LABEL, "To load system ability."); + LOG_INFO("To load system ability."); auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(LOAD_SA_TIMEOUT_MS), [this]() { return localCodeSignProxy_ != nullptr; }); if (!waitStatus) { - LOG_ERROR(LABEL, "code sign load SA timeout"); + LOG_ERROR("code sign load SA timeout"); return CS_ERR_SA_LOAD_TIMEOUT; } - LOG_INFO(LABEL, "code sign load SA successfully"); + LOG_INFO("code sign load SA successfully"); return CS_SUCCESS; } void LocalCodeSignClient::FinishStartSA(const sptr &remoteObject) { - LOG_DEBUG(LABEL, "LocalCodeSignClient FinishStartSA"); + LOG_DEBUG("LocalCodeSignClient FinishStartSA"); std::lock_guard lock(proxyMutex_); if (localCodeSignSvrRecipient_ == nullptr) { - LOG_ERROR(LABEL, "localCodeSignSvrRecipient_ is nullptr."); + LOG_ERROR("localCodeSignSvrRecipient_ is nullptr."); return; } if (!remoteObject->AddDeathRecipient(localCodeSignSvrRecipient_)) { - LOG_ERROR(LABEL, "AddDeathRecipient failed"); + LOG_ERROR("AddDeathRecipient failed"); } localCodeSignProxy_ = iface_cast(remoteObject); if ((localCodeSignProxy_ == nullptr) || (localCodeSignProxy_->AsObject() == nullptr)) { - LOG_ERROR(LABEL, "Get code sign proxy failed."); + LOG_ERROR("Get code sign proxy failed."); return; } proxyConVar_.notify_one(); @@ -108,7 +108,7 @@ void LocalCodeSignClient::CheckLocalCodeSignProxy() } sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { - LOG_ERROR(LABEL, "Get system ability mgr failed."); + LOG_ERROR("Get system ability mgr failed."); return; } auto remoteObject = samgr->CheckSystemAbility(LOCAL_CODE_SIGN_SA_ID); @@ -125,7 +125,7 @@ void LocalCodeSignClient::CheckLocalCodeSignProxy() int32_t LocalCodeSignClient::InitLocalCertificate(ByteBuffer &cert) { - LOG_DEBUG(LABEL, "InitLocalCertificate called"); + LOG_DEBUG("InitLocalCertificate called"); CheckLocalCodeSignProxy(); std::lock_guard lock(proxyMutex_); if (localCodeSignProxy_ == nullptr) { @@ -133,7 +133,7 @@ int32_t LocalCodeSignClient::InitLocalCertificate(ByteBuffer &cert) } int32_t ret = localCodeSignProxy_->InitLocalCertificate(cert); if (ret != CS_SUCCESS) { - LOG_ERROR(LABEL, "InitLocalCertificate err, error code = %{public}d", ret); + LOG_ERROR("InitLocalCertificate err, error code = %{public}d", ret); return ret; } return CS_SUCCESS; @@ -141,7 +141,7 @@ int32_t LocalCodeSignClient::InitLocalCertificate(ByteBuffer &cert) int32_t LocalCodeSignClient::SignLocalCode(const std::string &ownerID, const std::string &path, ByteBuffer &signature) { - LOG_DEBUG(LABEL, "SignLocalCode called"); + LOG_DEBUG("SignLocalCode called"); CheckLocalCodeSignProxy(); std::lock_guard lock(proxyMutex_); if (localCodeSignProxy_ == nullptr) { @@ -149,10 +149,10 @@ int32_t LocalCodeSignClient::SignLocalCode(const std::string &ownerID, const std } int32_t ret = localCodeSignProxy_->SignLocalCode(ownerID, path, signature); if (ret != CS_SUCCESS) { - LOG_ERROR(LABEL, "SignLocalCode err, error code = %{public}d", ret); + LOG_ERROR("SignLocalCode err, error code = %{public}d", ret); return ret; } - LOG_INFO(LABEL, "SignLocalCode successfully"); + LOG_INFO("SignLocalCode successfully"); return CS_SUCCESS; } @@ -160,17 +160,17 @@ void LocalCodeSignClient::OnRemoteLocalCodeSignSvrDied(const wptr { std::lock_guard lock(proxyMutex_); if (localCodeSignProxy_ == nullptr) { - LOG_ERROR(LABEL, "localCodeSignProxy_ is nullptr."); + LOG_ERROR("localCodeSignProxy_ is nullptr."); return; } sptr remoteObject = remote.promote(); if (remoteObject == nullptr) { - LOG_ERROR(LABEL, "OnRemoteDied remote promoted failed"); + LOG_ERROR("OnRemoteDied remote promoted failed"); return; } if (localCodeSignProxy_->AsObject() != remoteObject) { - LOG_ERROR(LABEL, "OnRemoteLocalCodeSignSvrDied not found remote object."); + LOG_ERROR("OnRemoteLocalCodeSignSvrDied not found remote object."); return; } localCodeSignProxy_->AsObject()->RemoveDeathRecipient(localCodeSignSvrRecipient_); diff --git a/interfaces/innerkits/local_code_sign/src/local_code_sign_load_callback.cpp b/interfaces/innerkits/local_code_sign/src/local_code_sign_load_callback.cpp index 3dc7d437aaf5e5c825ea26493aa56f08acbd14f2..747be0e06d02e5dbaf493e3e25d8743d1d00cb63 100644 --- a/interfaces/innerkits/local_code_sign/src/local_code_sign_load_callback.cpp +++ b/interfaces/innerkits/local_code_sign/src/local_code_sign_load_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -30,14 +30,14 @@ LocalCodeSignLoadCallback::LocalCodeSignLoadCallback() void LocalCodeSignLoadCallback::OnLoadSystemAbilitySuccess( int32_t systemAbilityId, const sptr &remoteObject) { - LOG_INFO(LABEL, "load local code sign SA success, systemAbilityId:%{public}d, remoteObject result:%{public}s", + LOG_INFO("load local code sign SA success, systemAbilityId:%{public}d, remoteObject result:%{public}s", systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); if (systemAbilityId != LOCAL_CODE_SIGN_SA_ID) { - LOG_ERROR(LABEL, "start systemabilityId is not codesignSAId!"); + LOG_ERROR("start systemabilityId is not codesignSAId!"); return; } if (remoteObject == nullptr) { - LOG_ERROR(LABEL, "remoteObject is nullptr"); + LOG_ERROR("remoteObject is nullptr"); return; } LocalCodeSignClient::GetInstance().FinishStartSA(remoteObject); @@ -45,7 +45,7 @@ void LocalCodeSignLoadCallback::OnLoadSystemAbilitySuccess( void LocalCodeSignLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { - LOG_ERROR(LABEL, "load local code sign SA failed, systemAbilityId: %{public}d", systemAbilityId); + LOG_ERROR("load local code sign SA failed, systemAbilityId: %{public}d", systemAbilityId); LocalCodeSignClient::GetInstance().FailStartSA(); } } diff --git a/interfaces/innerkits/local_code_sign/src/local_code_sign_proxy.cpp b/interfaces/innerkits/local_code_sign/src/local_code_sign_proxy.cpp index 70886810250945e9344c74820dc02ac5986bbcc9..aa265069463a8e105890dac2df79cde0957824b4 100644 --- a/interfaces/innerkits/local_code_sign/src/local_code_sign_proxy.cpp +++ b/interfaces/innerkits/local_code_sign/src/local_code_sign_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -54,17 +54,17 @@ int32_t LocalCodeSignProxy::SignLocalCode(const std::string &ownerID, const std: return CS_ERR_REMOTE_CONNECTION; } if (!data.WriteInterfaceToken(GetDescriptor())) { - LOG_ERROR(LABEL, "Write interface token failed."); + LOG_ERROR("Write interface token failed."); return CS_ERR_IPC_WRITE_DATA; } if (!data.WriteString(filePath)) { - LOG_ERROR(LABEL, "Write string failed."); + LOG_ERROR("Write string failed."); return CS_ERR_IPC_WRITE_DATA; } if (!ownerID.empty()) { if (!data.WriteString(ownerID)) { - LOG_ERROR(LABEL, "Write ownerID string failed."); + LOG_ERROR("Write ownerID string failed."); return CS_ERR_IPC_WRITE_DATA; } } @@ -89,7 +89,7 @@ int32_t LocalCodeSignProxy::ReadResultFromReply(MessageParcel &reply, ByteBuffer return CS_ERR_IPC_READ_DATA; } if (size > MAX_REPLY_BUFFER_SIZE) { - LOG_ERROR(LABEL, "Invalid reply data size."); + LOG_ERROR("Invalid reply data size."); return CS_ERR_IPC_MSG_INVALID; } const uint8_t *outData = reply.ReadBuffer(size); diff --git a/services/key_enable/utils/include/cert_path.h b/services/key_enable/utils/include/cert_path.h index 7f4dd021fba403ac884fdfc8994426a2754694ed..114ad30ed2578b582a1262bbe80b97b896bbbf59 100644 --- a/services/key_enable/utils/include/cert_path.h +++ b/services/key_enable/utils/include/cert_path.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -16,6 +16,10 @@ #ifndef CODE_SIGN_IOCTL_UTILS_H #define CODE_SIGN_IOCTL_UTILS_H +#ifndef LOG_RUST +#define LOG_RUST +#endif + #include #define CERT_DEVICE_PATH "/dev/code_sign" diff --git a/services/key_enable/utils/include/key_utils.h b/services/key_enable/utils/include/key_utils.h index c2dbf60718f8aaa62461272f676a76caa49959da..f44e535c46fc8b748649cca23cb5039a089da6e0 100644 --- a/services/key_enable/utils/include/key_utils.h +++ b/services/key_enable/utils/include/key_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -16,6 +16,10 @@ #ifndef CODE_SIGN_KEY_UTILS_H #define CODE_SIGN_KEY_UTILS_H +#ifndef LOG_RUST +#define LOG_RUST +#endif + #include typedef int32_t KeySerial; diff --git a/services/key_enable/utils/include/local_code_sign_utils.h b/services/key_enable/utils/include/local_code_sign_utils.h index 20ed8b8efda155f3d5bd9ba454bcacc9628f4475..2734e5ff68cb66e84893200606826809647caa02 100644 --- a/services/key_enable/utils/include/local_code_sign_utils.h +++ b/services/key_enable/utils/include/local_code_sign_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -19,6 +19,10 @@ #include #include +#ifndef LOG_RUST +#define LOG_RUST +#endif + #include "errcode.h" #ifdef __cplusplus diff --git a/services/key_enable/utils/src/cert_path.cpp b/services/key_enable/utils/src/cert_path.cpp index 2de5bd6b92db89c7b80bfa18edf3fd8ba73ce87c..c4618255b0fda8778835e657271cfbb7c49f180d 100644 --- a/services/key_enable/utils/src/cert_path.cpp +++ b/services/key_enable/utils/src/cert_path.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "cert_path.h" + #include #include #include @@ -23,7 +25,6 @@ #include #include "log.h" #include "errcode.h" -#include "cert_path.h" using namespace OHOS::Security::CodeSign; diff --git a/services/local_code_sign/include/local_sign_key.h b/services/local_code_sign/include/local_sign_key.h index 91b7fef6107df2387c539b106c0841af741062cf..6c8587eefa58edf36d5ef015c47e5b6b65d7e04c 100644 --- a/services/local_code_sign/include/local_sign_key.h +++ b/services/local_code_sign/include/local_sign_key.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -48,18 +48,18 @@ private: { int32_t ret = HksInitParamSet(¶mSet); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksInitParamSet failed"); + LOG_ERROR("HksInitParamSet failed"); return false; } ret = HksAddParams(paramSet, tmpParams, paramCount); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksAddParams failed"); + LOG_ERROR("HksAddParams failed"); return false; } ret = HksBuildParamSet(¶mSet); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksBuildParamSet failed"); + LOG_ERROR("HksBuildParamSet failed"); return false; } return true; diff --git a/services/local_code_sign/src/local_code_sign_service.cpp b/services/local_code_sign/src/local_code_sign_service.cpp index 47b100167ac43c26bf4cf3dd9cdfa3bd5f922777..8c52d5849360368816f55a629520cb78caae06a6 100644 --- a/services/local_code_sign/src/local_code_sign_service.cpp +++ b/services/local_code_sign/src/local_code_sign_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -45,18 +45,18 @@ LocalCodeSignService::~LocalCodeSignService() void LocalCodeSignService::OnStart() { - LOG_INFO(LABEL, "LocalCodeSignService OnStart"); + LOG_INFO("LocalCodeSignService OnStart"); if (state_ == ServiceRunningState::STATE_RUNNING) { - LOG_INFO(LABEL, "LocalCodeSignService has already started."); + LOG_INFO("LocalCodeSignService has already started."); return; } if (!Init()) { - LOG_ERROR(LABEL, "Init LocalCodeSignService failed."); + LOG_ERROR("Init LocalCodeSignService failed."); return; } bool ret = Publish(DelayedSingleton::GetInstance().get()); if (!ret) { - LOG_ERROR(LABEL, "Publish service failed."); + LOG_ERROR("Publish service failed."); return; } state_ = ServiceRunningState::STATE_RUNNING; @@ -77,12 +77,12 @@ void LocalCodeSignService::DelayUnloadTask() auto task = [this]() { sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { - LOG_ERROR(LABEL, "Get system ability mgr failed."); + LOG_ERROR("Get system ability mgr failed."); return; } int32_t ret = samgr->UnloadSystemAbility(LOCAL_CODE_SIGN_SA_ID); if (ret != ERR_OK) { - LOG_ERROR(LABEL, "Remove system ability failed."); + LOG_ERROR("Remove system ability failed."); return; } }; @@ -92,7 +92,7 @@ void LocalCodeSignService::DelayUnloadTask() void LocalCodeSignService::OnStop() { - LOG_INFO(LABEL, "LocalCodeSignService OnStop"); + LOG_INFO("LocalCodeSignService OnStop"); state_ = ServiceRunningState::STATE_NOT_START; } @@ -100,12 +100,12 @@ int32_t LocalCodeSignService::InitLocalCertificate(ByteBuffer &cert) { LocalSignKey &key = LocalSignKey::GetInstance(); if (!key.InitKey()) { - LOG_ERROR(LABEL, "Init key failed."); + LOG_ERROR("Init key failed."); return CS_ERR_HUKS_INIT_KEY; } const ByteBuffer *keyCert = key.GetSignCert(); if (keyCert == nullptr) { - LOG_ERROR(LABEL, "Get cert failed."); + LOG_ERROR("Get cert failed."); return CS_ERR_HUKS_OBTAIN_CERT; } if (!cert.CopyFrom(keyCert->GetBuffer(), keyCert->GetSize())) { @@ -118,17 +118,17 @@ int32_t LocalCodeSignService::SignLocalCode(const std::string &ownerID, const st ByteBuffer &signature) { if (ownerID.length() > MAX_OWNER_ID_LEN) { - LOG_ERROR(LABEL, "ownerID len %{public}u should not exceed %{public}u", ownerID.length(), MAX_OWNER_ID_LEN); + LOG_ERROR("ownerID len %{public}u should not exceed %{public}u", ownerID.length(), MAX_OWNER_ID_LEN); return CS_ERR_INVALID_OWNER_ID; } ByteBuffer digest; std::string realPath; if (!OHOS::PathToRealPath(filePath, realPath)) { - LOG_INFO(LABEL, "Get real path failed, path = %{public}s", filePath.c_str()); + LOG_INFO("Get real path failed, path = %{public}s", filePath.c_str()); return CS_ERR_FILE_PATH; } if (!FsverityUtilsHelper::GetInstance().GenerateFormattedDigest(realPath.c_str(), digest)) { - LOG_ERROR(LABEL, "Generate formatted fsverity digest failed."); + LOG_ERROR("Generate formatted fsverity digest failed."); return CS_ERR_COMPUTE_DIGEST; } return PKCS7Generator::GenerateSignature(ownerID, LocalSignKey::GetInstance(), DEFAULT_HASH_ALGORITHM.c_str(), diff --git a/services/local_code_sign/src/local_sign_key.cpp b/services/local_code_sign/src/local_sign_key.cpp index 7bbf54e94ba49988f7a6a9d34968f17c17a8110f..c31b4516f20a0a0d21fddf30e8c02ddc39b6c000 100644 --- a/services/local_code_sign/src/local_sign_key.cpp +++ b/services/local_code_sign/src/local_sign_key.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -83,7 +83,7 @@ bool LocalSignKey::InitKey() return false; } } else if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksKeyExist fail, ret is %{public}d!", ret); + LOG_ERROR("HksKeyExist fail, ret is %{public}d!", ret); return false; } return true; @@ -100,7 +100,7 @@ const ByteBuffer *LocalSignKey::GetSignCert() } cert_ = new (std::nothrow) ByteBuffer(); if (cert_ == nullptr) { - LOG_ERROR(LABEL, "Alloc memory for cert blob failed."); + LOG_ERROR("Alloc memory for cert blob failed."); return nullptr; } // get cert chain with 4 certs. the first is sign cert @@ -118,7 +118,7 @@ const HksCertChain *LocalSignKey::GetCertChain() } certChain_ = QueryCertChain(); if (certChain_ == nullptr) { - LOG_ERROR(LABEL, "QueryCertChain failed."); + LOG_ERROR("QueryCertChain failed."); return nullptr; } return certChain_; @@ -140,7 +140,7 @@ HksCertChain *LocalSignKey::QueryCertChain() // get cert chain by huks attest int32_t ret = HksAttestKey(&LOCAL_SIGN_KEY_ALIAS, paramSet.GetParamSet(), certChain); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksAttestKey fail, ret is %{public}d!", ret); + LOG_ERROR("HksAttestKey fail, ret is %{public}d!", ret); return nullptr; } return certChain; @@ -183,7 +183,7 @@ bool LocalSignKey::GenerateKey() } int32_t ret = HksGenerateKey(&LOCAL_SIGN_KEY_ALIAS, paramSet.GetParamSet(), nullptr); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksGenerateKey failed, ret is %{public}d!", ret); + LOG_ERROR("HksGenerateKey failed, ret is %{public}d!", ret); return false; } return true; @@ -200,7 +200,7 @@ bool LocalSignKey::GetSignParamSet(HUKSParamSet ¶mSet) bool LocalSignKey::Sign(const ByteBuffer &data, ByteBuffer &signature) { if (data.GetSize() > MAX_SIGN_SIZE) { - LOG_ERROR(LABEL, "Data to sign is too long"); + LOG_ERROR("Data to sign is too long"); return false; } struct HksBlob inData = { @@ -234,7 +234,7 @@ bool LocalSignKey::SignByHUKS(const struct HksBlob *inData, struct HksBlob *outD struct HksBlob handle = { sizeof(uint64_t), tmpHandle }; int32_t ret = HksInit(&LOCAL_SIGN_KEY_ALIAS, paramSet.GetParamSet(), &handle, nullptr); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksInit failed"); + LOG_ERROR("HksInit failed"); return false; } @@ -245,12 +245,12 @@ bool LocalSignKey::SignByHUKS(const struct HksBlob *inData, struct HksBlob *outD }; tmpOutData.data = static_cast(malloc(tmpOutData.size)); if (tmpOutData.data == nullptr) { - LOG_ERROR(LABEL, "Alloc memory for blob failed."); + LOG_ERROR("Alloc memory for blob failed."); return false; } ret = HksUpdate(&handle, paramSet.GetParamSet(), inData, &tmpOutData); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksUpdate Failed."); + LOG_ERROR("HksUpdate Failed."); free(tmpOutData.data); return CS_ERR_PARAM_INVALID; } @@ -260,7 +260,7 @@ bool LocalSignKey::SignByHUKS(const struct HksBlob *inData, struct HksBlob *outD ret = HksFinish(&handle, paramSet.GetParamSet(), &tmpOutData, outData); free(tmpOutData.data); if (ret != HKS_SUCCESS) { - LOG_ERROR(LABEL, "HksFinish Failed."); + LOG_ERROR("HksFinish Failed."); return false; } return true; diff --git a/services/local_code_sign/src/permission_utils.cpp b/services/local_code_sign/src/permission_utils.cpp index d5c485a5c09ec04b677cd8a78323d1761b5929a6..af2e44c89abbb6335d89cedd1f92200ad381405a 100644 --- a/services/local_code_sign/src/permission_utils.cpp +++ b/services/local_code_sign/src/permission_utils.cpp @@ -65,7 +65,7 @@ bool PermissionUtils::VerifyCallingProcess(const std::vector &valid const AccessToken::AccessTokenID &callerTokenId) { if (!g_isAtmInited && !HasATMInitilized()) { - LOG_DEBUG(LABEL, "AccessTokenManager has not started yet."); + LOG_DEBUG("AccessTokenManager has not started yet."); return true; } for (const auto &caller: validCallers) { @@ -74,7 +74,7 @@ bool PermissionUtils::VerifyCallingProcess(const std::vector &valid return true; } } - LOG_ERROR(LABEL, "Invalid caller."); + LOG_ERROR("Invalid caller."); return false; } } diff --git a/test/unittest/enable_verity_test.cpp b/test/unittest/enable_verity_test.cpp index dbde5fa6991de8a46ce9f8f7662823fe65ed40cf..7ca9d369d7eb64f461e70d31d960251fb382fcf2 100644 --- a/test/unittest/enable_verity_test.cpp +++ b/test/unittest/enable_verity_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -155,7 +155,7 @@ static bool ReadDataFromFile(const std::string &path, ByteBuffer &data) size_t ret = fread(data.GetBuffer(), 1, fileSize, file); (void)fclose(file); if (ret < fileSize) { - LOG_ERROR(LABEL, "Read size (%{public}zu) < file size", ret); + LOG_ERROR("Read size (%{public}zu) < file size", ret); return false; } return true; @@ -209,7 +209,7 @@ static bool ExpandFile(const std::string &srcPath, const std::string &expandData (void)fclose(fout); return false; } - LOG_ERROR(LABEL, "write padding = %{public}zu", writeSize); + LOG_ERROR("write padding = %{public}zu", writeSize); totalSize += writeSize; } CopyData(expandDataFile, fout); @@ -281,7 +281,7 @@ int32_t EnableVerityOnOneFile(const std::string filePath, int error = ioctl(fd, FS_IOC_ENABLE_CODE_SIGN, arg); if (error < 0) { - LOG_ERROR(LABEL, "Enable fs-verity failed, errno = <%{public}d, %{public}s>", + LOG_ERROR("Enable fs-verity failed, errno = <%{public}d, %{public}s>", errno, strerror(errno)); ret = errno; } @@ -373,7 +373,7 @@ HWTEST_F(EnableVerityTest, EnableVerityTest_0001, TestSize.Level0) { for (int i = 0; i < TEST_FILE_NUM; i++) { std::string filePath = TEST_FILES_DIR + TEST_FILES_LIST[i]; - LOG_INFO(LABEL, "Test on file path = %{public}s", filePath.c_str()); + LOG_INFO("Test on file path = %{public}s", filePath.c_str()); struct code_sign_enable_arg arg = {}; ByteBuffer signature; FillCommonArgs(filePath, false, &arg, signature); @@ -450,7 +450,7 @@ HWTEST_F(EnableVerityTest, EnableVerityTest_0004, TestSize.Level0) { for (int i = 0; i < TEST_FILE_NUM; i++) { std::string filePath = TEST_FILES_DIR + TEST_FILES_LIST[i]; - LOG_INFO(LABEL, "Test on file path = %{public}s", filePath.c_str()); + LOG_INFO("Test on file path = %{public}s", filePath.c_str()); struct code_sign_enable_arg arg = {}; ByteBuffer signature; diff --git a/test/unittest/multi_thread_local_sign_test.cpp b/test/unittest/multi_thread_local_sign_test.cpp index 6d6b960d4e1f5e053d72d2f260ad8e9c1018739c..f6d27b9b7e8a484cd6a8fb62340136984982ce00 100644 --- a/test/unittest/multi_thread_local_sign_test.cpp +++ b/test/unittest/multi_thread_local_sign_test.cpp @@ -45,7 +45,7 @@ uint64_t GetFileSize(int32_t fd) { struct stat st; if (fstat(fd, &st) != 0) { - LOG_ERROR(LABEL, "Stat file failed, errno = <%{public}d, %{public}s>", + LOG_ERROR("Stat file failed, errno = <%{public}d, %{public}s>", errno, strerror(errno)); return 0; } diff --git a/test/unittest/resources/ohos_test.xml b/test/unittest/resources/ohos_test.xml index 9fabad86c7d40628151f55aa6a07824c5fe72d10..22db761f53aa41030cf4300014aac28b2a77d048 100644 --- a/test/unittest/resources/ohos_test.xml +++ b/test/unittest/resources/ohos_test.xml @@ -1,5 +1,5 @@ -