From facadbf971dcd893b145cc213676ab0e32b821ec Mon Sep 17 00:00:00 2001 From: lsq Date: Tue, 22 Mar 2022 20:08:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E6=BA=90=E5=91=8A=E8=AD=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lsq Change-Id: Id4a8e1d85054a0028bfecec44ffdb4cb9392f0e5 Signed-off-by: lsq --- BUILD.gn | 2 +- access_token.gni | 4 +- .../accesstoken/include/hap_policy_parcel.h | 1 - interfaces/innerkits/accesstoken/BUILD.gn | 2 +- .../innerkits/accesstoken/test/BUILD.gn | 2 +- .../unittest/src/accesstoken_kit_test.cpp | 4 +- interfaces/innerkits/nativetoken/BUILD.gn | 2 +- .../innerkits/nativetoken/src/nativetoken.c | 2 + .../innerkits/nativetoken/test/BUILD.gn | 2 +- interfaces/innerkits/token_setproc/BUILD.gn | 2 +- .../innerkits/token_setproc/test/BUILD.gn | 2 +- interfaces/innerkits/tokensync/BUILD.gn | 2 +- interfaces/innerkits/tokensync/test/BUILD.gn | 4 +- services/accesstokenmanager/access_token.rc | 2 +- .../include/token/native_token_info_inner.h | 1 + .../cpp/include/token/native_token_receptor.h | 2 +- .../src/service/accesstoken_manager_stub.cpp | 2 +- .../cpp/src/token/native_token_receptor.cpp | 16 ++++++- .../main/sa_profile/3503.xml | 2 +- .../cpp/src/native_token_receptor_test.cpp | 4 +- .../command/sync_remote_hap_token_command.h | 2 +- .../include/device/device_info.h | 2 +- .../include/device/device_info_manager.h | 10 +++-- .../include/device/device_info_repository.h | 6 +-- .../include/remote/remote_command_manager.h | 2 +- .../include/remote/soft_bus_manager.h | 2 +- .../remote/soft_bus_session_listener.h | 1 + .../service/token_sync_manager_service.h | 4 +- services/tokensyncmanager/sa_profile/3504.xml | 2 +- .../src/command/base_remote_command.cpp | 2 +- .../command/delete_remote_token_command.cpp | 6 ++- .../src/device/device_info_manager.cpp | 44 ++++++++++--------- .../src/device/device_info_repository.cpp | 34 +++++++------- .../src/remote/remote_command_executor.cpp | 1 - .../src/remote/remote_command_factory.cpp | 12 ++--- .../src/remote/remote_command_manager.cpp | 2 +- .../soft_bus_device_connection_listener.cpp | 4 +- .../src/remote/soft_bus_manager.cpp | 5 +-- .../src/remote/soft_bus_session_listener.cpp | 7 +-- .../service/token_sync_manager_service.cpp | 14 +++--- services/tokensyncmanager/token_sync.rc | 2 +- 41 files changed, 123 insertions(+), 101 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 5ec5d0389..c83806574 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/access_token.gni b/access_token.gni index a6a6a3bd9..3d92eff5c 100644 --- a/access_token.gni +++ b/access_token.gni @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -9,7 +9,7 @@ # 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. +# limitations under the License. if (!defined(global_parts_info) || defined(global_parts_info.distributedhardware_device_manager_base)) { diff --git a/frameworks/accesstoken/include/hap_policy_parcel.h b/frameworks/accesstoken/include/hap_policy_parcel.h index dc412e477..43562c09c 100644 --- a/frameworks/accesstoken/include/hap_policy_parcel.h +++ b/frameworks/accesstoken/include/hap_policy_parcel.h @@ -20,7 +20,6 @@ #include "permission_def_parcel.h" #include "permission_state_full_parcel.h" - namespace OHOS { namespace Security { namespace AccessToken { diff --git a/interfaces/innerkits/accesstoken/BUILD.gn b/interfaces/innerkits/accesstoken/BUILD.gn index 17346a945..dba0ef361 100644 --- a/interfaces/innerkits/accesstoken/BUILD.gn +++ b/interfaces/innerkits/accesstoken/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/interfaces/innerkits/accesstoken/test/BUILD.gn b/interfaces/innerkits/accesstoken/test/BUILD.gn index a64bae599..55ed6e19f 100644 --- a/interfaces/innerkits/accesstoken/test/BUILD.gn +++ b/interfaces/innerkits/accesstoken/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp index f481a593e..4e45faf9d 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp @@ -1855,7 +1855,7 @@ HWTEST_F(AccessTokenKitTest, UpdateHapToken007, TestSize.Level1) GTEST_LOG_(INFO) << "tokenID :" << tokenID; PermissionDef permDefResult; - /* check permission define befor update */ + /* check permission define before update */ ret = AccessTokenKit::GetDefPermission("ohos.permission.test3", permDefResult); ASSERT_EQ(RET_FAILED, ret); @@ -1897,7 +1897,7 @@ HWTEST_F(AccessTokenKitTest, UpdateHapToken008, TestSize.Level1) GTEST_LOG_(INFO) << "tokenID :" << tokenID; PermissionDef permDefResult; - /* check permission define befor update */ + /* check permission define before update */ ret = AccessTokenKit::GetDefPermission(g_infoManagerTestPolicyPrams.permList[0].permissionName, permDefResult); ASSERT_EQ(g_infoManagerTestPolicyPrams.permList[0].permissionName, permDefResult.permissionName); ASSERT_EQ("label", permDefResult.label); diff --git a/interfaces/innerkits/nativetoken/BUILD.gn b/interfaces/innerkits/nativetoken/BUILD.gn index 58d197aea..5ef3d0a76 100644 --- a/interfaces/innerkits/nativetoken/BUILD.gn +++ b/interfaces/innerkits/nativetoken/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/interfaces/innerkits/nativetoken/src/nativetoken.c b/interfaces/innerkits/nativetoken/src/nativetoken.c index ba115e24d..7ce4c8b82 100644 --- a/interfaces/innerkits/nativetoken/src/nativetoken.c +++ b/interfaces/innerkits/nativetoken/src/nativetoken.c @@ -241,6 +241,7 @@ static int32_t CreateCfgFile(void) return ATRET_FAILED; } close(fd); + fd = -1; struct stat buf; if (stat(TOKEN_ID_CFG_DIR_PATH, &buf) != 0) { @@ -292,6 +293,7 @@ static int GetRandomTokenId(uint32_t *randNum) } len = read(fd, &random, sizeof(random)); (void)close(fd); + if (len != sizeof(random)) { ACCESSTOKEN_LOG_ERROR("[ATLIB-%s]:read failed.", __func__); return ATRET_FAILED; diff --git a/interfaces/innerkits/nativetoken/test/BUILD.gn b/interfaces/innerkits/nativetoken/test/BUILD.gn index 16f2b96b3..ca884c8a0 100644 --- a/interfaces/innerkits/nativetoken/test/BUILD.gn +++ b/interfaces/innerkits/nativetoken/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/interfaces/innerkits/token_setproc/BUILD.gn b/interfaces/innerkits/token_setproc/BUILD.gn index edbdb874b..72adb4346 100644 --- a/interfaces/innerkits/token_setproc/BUILD.gn +++ b/interfaces/innerkits/token_setproc/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 diff --git a/interfaces/innerkits/token_setproc/test/BUILD.gn b/interfaces/innerkits/token_setproc/test/BUILD.gn index 50eeb5261..b6e11d2ad 100644 --- a/interfaces/innerkits/token_setproc/test/BUILD.gn +++ b/interfaces/innerkits/token_setproc/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 diff --git a/interfaces/innerkits/tokensync/BUILD.gn b/interfaces/innerkits/tokensync/BUILD.gn index 20df0ec32..c4634b55f 100644 --- a/interfaces/innerkits/tokensync/BUILD.gn +++ b/interfaces/innerkits/tokensync/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 diff --git a/interfaces/innerkits/tokensync/test/BUILD.gn b/interfaces/innerkits/tokensync/test/BUILD.gn index fd5e26267..30d164b86 100644 --- a/interfaces/innerkits/tokensync/test/BUILD.gn +++ b/interfaces/innerkits/tokensync/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -22,8 +22,6 @@ ohos_unittest("libtokensync_sdk_test") { "//utils/native/base/include", "//third_party/googletest/include", "//base/security/access_token/interfaces/innerkits/tokensync/include", - - #"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include/permission/", "//base/security/access_token/interfaces/innerkits/accesstoken/include", ] diff --git a/services/accesstokenmanager/access_token.rc b/services/accesstokenmanager/access_token.rc index 481f379ac..2194d40d5 100644 --- a/services/accesstokenmanager/access_token.rc +++ b/services/accesstokenmanager/access_token.rc @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 diff --git a/services/accesstokenmanager/main/cpp/include/token/native_token_info_inner.h b/services/accesstokenmanager/main/cpp/include/token/native_token_info_inner.h index e6b1b793d..72f5b2e7c 100644 --- a/services/accesstokenmanager/main/cpp/include/token/native_token_info_inner.h +++ b/services/accesstokenmanager/main/cpp/include/token/native_token_info_inner.h @@ -31,6 +31,7 @@ static const std::string JSON_VERSION = "version"; static const std::string JSON_TOKEN_ID = "tokenId"; static const std::string JSON_TOKEN_ATTR = "tokenAttr"; static const std::string JSON_DCAPS = "dcaps"; +static const int MAX_DCAPS_NUM = 32; class NativeTokenInfoInner final { public: diff --git a/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h b/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h index d0180f065..9917e5e57 100644 --- a/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h +++ b/services/accesstokenmanager/main/cpp/include/token/native_token_receptor.h @@ -42,7 +42,7 @@ private: int ReadCfgFile(std::string &nativeRawData); void FromJson(const nlohmann::json &jsonObject, std::vector>& tokenInfos); - void ParserNativeRawData(const std::string& nativeRawData, + int32_t ParserNativeRawData(const std::string& nativeRawData, std::vector>& tokenInfos); void from_json(const nlohmann::json& j, NativeTokenInfo& p); diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp index 094198a2b..3d88bb763 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp @@ -144,7 +144,7 @@ void AccessTokenManagerStub::GetSelfPermissionsStateInner(MessageParcel& data, M void AccessTokenManagerStub::GetPermissionFlagInner(MessageParcel& data, MessageParcel& reply) { unsigned int callingTokenID = IPCSkeleton::GetCallingTokenID(); - ACCESSTOKEN_LOG_INFO(LABEL, "callingTokenID: %{public}d", callingTokenID); + ACCESSTOKEN_LOG_INFO(LABEL, "callingTokenID: %{public}u", callingTokenID); AccessTokenID tokenID = data.ReadUint32(); std::string permissionName = data.ReadString(); if (!IsAuthorizedCalling() && diff --git a/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp b/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp index 381005678..7fef139d9 100644 --- a/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/native_token_receptor.cpp @@ -83,22 +83,30 @@ void from_json(const nlohmann::json& j, std::shared_ptr& p if (j.find(JSON_DCAPS) != j.end()) { native.dcap = j.at(JSON_DCAPS).get>(); + if (native.dcap.size() > MAX_DCAPS_NUM) { + return; + } } else { return; } p = std::make_shared(native); } -void NativeTokenReceptor::ParserNativeRawData(const std::string& nativeRawData, +int32_t NativeTokenReceptor::ParserNativeRawData(const std::string& nativeRawData, std::vector>& tokenInfos) { nlohmann::json jsonRes = nlohmann::json::parse(nativeRawData, nullptr, false); + if (jsonRes.is_discarded()) { + ACCESSTOKEN_LOG_ERROR(LABEL, "jsonRes is invalid."); + return RET_FAILED; + } for (auto it = jsonRes.begin(); it != jsonRes.end(); it++) { auto token = it->get>(); if (token != nullptr) { tokenInfos.emplace_back(token); } } + return RET_SUCCESS; } int NativeTokenReceptor::ReadCfgFile(std::string& nativeRawData) @@ -155,7 +163,11 @@ int NativeTokenReceptor::Init() return RET_FAILED; } std::vector> tokenInfos; - ParserNativeRawData(nativeRawData, tokenInfos); + ret = ParserNativeRawData(nativeRawData, tokenInfos); + if (ret != RET_SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "ParserNativeRawData failed."); + return RET_FAILED; + } AccessTokenInfoManager::GetInstance().ProcessNativeTokenInfos(tokenInfos); ready_ = true; diff --git a/services/accesstokenmanager/main/sa_profile/3503.xml b/services/accesstokenmanager/main/sa_profile/3503.xml index f17460702..b56ef0380 100644 --- a/services/accesstokenmanager/main/sa_profile/3503.xml +++ b/services/accesstokenmanager/main/sa_profile/3503.xml @@ -1,5 +1,5 @@ -