From d8d88d6f4d1f7e951346044ba781a87f7beb8439 Mon Sep 17 00:00:00 2001 From: dujingcheng Date: Mon, 23 May 2022 18:44:45 +0800 Subject: [PATCH] deviceId Anonymize Signed-off-by: dujingcheng Change-Id: I5da18c1e7acb95971f2fefb09b2aaeffec2090ba --- services/bundlemgr/src/hidump_helper.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/services/bundlemgr/src/hidump_helper.cpp b/services/bundlemgr/src/hidump_helper.cpp index 7b44e62f..2823a43a 100644 --- a/services/bundlemgr/src/hidump_helper.cpp +++ b/services/bundlemgr/src/hidump_helper.cpp @@ -25,6 +25,7 @@ const int32_t MIN_ARGS_SIZE = 1; const int32_t MAX_ARGS_SIZE = 2; const int32_t FIRST_PARAM = 0; const int32_t SECOND_PARAM = 1; +const int32_t NON_ANONYMIZE_LEN = 4; const std::string ARGS_HELP = "-h"; const std::string ARGS_ABILITY = "-ability"; const std::string ARGS_ABILITY_LIST = "-ability-list"; @@ -42,6 +43,22 @@ const std::unordered_map ARGS_MAP = { { ARGS_BUNDLE_LIST, HidumpFlag::GET_BUNDLE_LIST }, { ARGS_DEVICEID, HidumpFlag::GET_DEVICEID }, }; + +std::string AnonymizeDeviceId(const std::string &deviceId) +{ + int32_t totalLen = static_cast(strlen(deviceId.c_str())); + int32_t anonymizeCharNum = totalLen - NON_ANONYMIZE_LEN - NON_ANONYMIZE_LEN; + if (anonymizeCharNum <= 0) { + return deviceId; + } + + std::string newDeviceId; + newDeviceId + .append(deviceId.substr(0, NON_ANONYMIZE_LEN)) + .append(anonymizeCharNum, '*') + .append(deviceId.substr(totalLen - NON_ANONYMIZE_LEN, NON_ANONYMIZE_LEN)); + return newDeviceId; +} } HidumpHelper::HidumpHelper(const std::weak_ptr &dataMgr) @@ -364,7 +381,7 @@ ErrCode HidumpHelper::GetAllDeviced(std::string &result) } for (auto deviceId : deviceIds) { - result.append(deviceId); + result.append(AnonymizeDeviceId(deviceId)); result.append("\n"); }