diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 2e3647104bc0bd5ab19c75e6b1899e993a2bdb4a..46a5734f61456deaeca84c57d203805a9f8d8ad2 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 6a4c57063858fbc04dd12083749ecc90d63bac63..57edca138b185da9f1ca5af21277e6e6129b6c6f 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 sensitiveKey = { "LOCALDEVICEID", "localAccountId", "networkId", "lnnPublicKey", + "transmitPublicKey", "DEVICEID", "deviceId", "keyValue", "deviceName", "REMOTE_DEVICE_NAME", "data" }; + + for (auto &element : paramJson.Items()) { + if (element.IsString() && sensitiveKey.find(element.Key()) != sensitiveKey.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 63cb2286acf7aa28870a3a056f6974fa19198093..a483b4ad8ea708ac6a9e695e46dfb89421af6dfc 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 38427822cfac8965e610baba0476133612bce07a..495371b11850d4c599f46f6fa49fbaf280a12c93 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 cf46c4ad2da4392d428ff775bc6e2b14242f392b..28759e22ccc46f9744215405d9a5787012705ddd 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; }