From f129f2d6b9f500e268e20002cb90a73c0755ee64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Mon, 19 May 2025 09:42:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- common/include/dm_anonymous.h | 1 + common/src/dm_anonymous.cpp | 22 +++++++++++++++++++ .../auth_stages/auth_credential.cpp | 6 ++--- .../dm_auth_message_processor.cpp | 7 +++--- .../hichain/hichain_auth_connector.cpp | 6 ++--- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 2e3647104..46a5734f6 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -106,6 +106,7 @@ bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent); DM_EXPORT std::string SafetyDump(const JsonItemObject &jsonObj); std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index); bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &key); +std::string GetAnonyJsonString(const std::string &value); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_ANONYMOUS_H diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 6a4c57063..77f9f64d6 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -16,6 +16,8 @@ #include "dm_anonymous.h" #include "dm_log.h" #include +#include + namespace OHOS { namespace DistributedHardware { namespace { @@ -437,5 +439,25 @@ bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &ke } return true; } + +std::string GetAnonyJsonString(const std::string &value) +{ + if (value.empty()) { + return ""; + } + JsonObject paramJson(value); + if (paramJson.IsDiscarded()) { + return ""; + } + const std::set Sensitive_Key = { "LOCALDEVICEID", "localAccountId", "networkId", "lnnPublicKey", + "transmitPublicKey", "DEVICEID", "deviceId", "keyValue", "deviceName", "REMOTE_DEVICE_NAME", "data" }; + + for (auto &element : paramJson.Items()) { + if (element.IsString() && Sensitive_Key.find(element.Key()) != Sensitive_Key.end()) { + paramJson[element.Key()] = GetAnonyString(element.Get()); + } + } + return paramJson.Dump(); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp index 63cb2286a..a483b4ad8 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp @@ -315,8 +315,8 @@ int32_t AuthCredentialAgreeState::GenerateCredIdAndPublicKey(DmAuthScope authori (void)authContext->SetCredentialId(DM_AUTH_LOCAL_SIDE, authorizedScope, credId); (void)authContext->SetPublicKey(DM_AUTH_LOCAL_SIDE, authorizedScope, publicKey); LOGI("AuthCredentialAgreeState::GenerateCredIdAndPublicKey credId=%{public}s, publicKey=%{public}s.\n", - authContext->GetCredentialId(DM_AUTH_LOCAL_SIDE, authorizedScope).c_str(), - authContext->GetPublicKey(DM_AUTH_LOCAL_SIDE, authorizedScope).c_str()); + GetAnonyString(authContext->GetCredentialId(DM_AUTH_LOCAL_SIDE, authorizedScope)).c_str(), + GetAnonyString(authContext->GetPublicKey(DM_AUTH_LOCAL_SIDE, authorizedScope)).c_str()); LOGI("AuthCredentialAgreeState::GenerateCredIdAndPublicKey leave."); return DM_OK; } @@ -343,7 +343,7 @@ int32_t AuthCredentialAgreeState::AgreeCredential(DmAuthScope authorizedScope, std::string selfCredId = authContext->GetCredentialId(DM_AUTH_LOCAL_SIDE, authorizedScope); std::string credId; LOGI("AuthCredentialAgreeState::AgreeCredential agree with accountId %{public}d and param %{public}s.", - osAccountId, authParamsString.c_str()); + osAccountId, GetAnonyJsonString(authParamsString).c_str()); int32_t ret = authContext->hiChainAuthConnector->AgreeCredential(osAccountId, selfCredId, authParamsString, credId); if (ret != DM_OK) { diff --git a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 38427822c..495371b11 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -545,8 +545,7 @@ int32_t DmAuthMessageProcessor::ParseMessageRspCredExchange(const JsonObject &js LOGE("DmAuthMessageProcessor::ParseMessageRspCredExchange error, decrypt data failed."); return ERR_DM_FAILED; } - - LOGI("DmAuthMessageProcessor::ParseMessageRspCredExchange plainText=%{public}s", plainText.c_str()); + LOGI("plainText=%{public}s", GetAnonyJsonString(plainText).c_str()); JsonObject jsonData(plainText); @@ -590,7 +589,7 @@ std::string DmAuthMessageProcessor::CreateMessage(DmMessageType msgType, std::sh return ""; } int32_t ret = (this->*(itr->second))(context, jsonObj); - LOGI("DmAuthMessageProcessor::CreateMessage start. message is %{public}s", jsonObj.Dump().c_str()); + LOGI("start. message is %{public}s", GetAnonyJsonString(jsonObj.Dump()).c_str()); return (ret == DM_OK) ? jsonObj.Dump() : ""; } @@ -718,7 +717,7 @@ int32_t DmAuthMessageProcessor::CreateMessageRspCredExchange(std::shared_ptrEncryptMessage(plainText, cipherText); if (ret != DM_OK) { LOGI("DmAuthMessageProcessor::CreateMessageRspCredExchange encryptMessage failed."); diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index cf46c4ad2..28759e22c 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -158,7 +158,7 @@ int32_t HiChainAuthConnector::AddCredential(int32_t osAccountId, const std::stri LOGE("Hichain addCredential failed ret %{public}d.", ret); return ERR_DM_FAILED; } - LOGI("success ret=%{public}d, returnData=%{public}s.", ret, returnData); + LOGI("success ret=%{public}d, returnData=%{public}s.", ret, GetAnonyString(returnData).c_str()); credId = std::string(returnData); credManager->destroyInfo(&returnData); return DM_OK; @@ -166,7 +166,7 @@ int32_t HiChainAuthConnector::AddCredential(int32_t osAccountId, const std::stri int32_t HiChainAuthConnector::ExportCredential(int32_t osAccountId, const std::string &credId, std::string &publicKey) { - LOGI("start. osAccountId=%{public}d, credId=%{public}s", osAccountId, credId.c_str()); + LOGI("start. osAccountId=%{public}d, credId=%{public}s", osAccountId, GetAnonyString(credId).c_str()); char *returnData = NULL; const CredManager *credManager = GetCredMgrInstance(); int32_t ret = credManager->exportCredential(osAccountId, credId.c_str(), &returnData); @@ -200,7 +200,7 @@ int32_t HiChainAuthConnector::AgreeCredential(int32_t osAccountId, const std::st } credId = returnData; credManager->destroyInfo(&returnData); - LOGI("leave agreeCredId=%{public}s.", credId.c_str()); + LOGI("leave agreeCredId=%{public}s.", GetAnonyString(credId).c_str()); return DM_OK; } -- Gitee From feb20e828675bda803409352dab30ccbd9f1f42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Mon, 19 May 2025 11:47:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- common/src/dm_anonymous.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 77f9f64d6..57edca138 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -449,11 +449,11 @@ std::string GetAnonyJsonString(const std::string &value) if (paramJson.IsDiscarded()) { return ""; } - const std::set Sensitive_Key = { "LOCALDEVICEID", "localAccountId", "networkId", "lnnPublicKey", + const std::set sensitiveKey = { "LOCALDEVICEID", "localAccountId", "networkId", "lnnPublicKey", "transmitPublicKey", "DEVICEID", "deviceId", "keyValue", "deviceName", "REMOTE_DEVICE_NAME", "data" }; for (auto &element : paramJson.Items()) { - if (element.IsString() && Sensitive_Key.find(element.Key()) != Sensitive_Key.end()) { + if (element.IsString() && sensitiveKey.find(element.Key()) != sensitiveKey.end()) { paramJson[element.Key()] = GetAnonyString(element.Get()); } } -- Gitee