diff --git a/BUILD.gn b/BUILD.gn index 5ec5d0389bae1650357da8e4587734dfcad6ac8f..c838065740a691f29ba3ce8032dea5234ae93843 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 a6a6a3bd984692328e8a83390fe1d1207a9731d4..3d92eff5c87b4dbb35f7b33bd5ac394102cbe37d 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 dc412e4776f3f1aacfea40da9506dfff5ce9608a..43562c09cefb46db268b65fa7e84019af4ace66f 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 17346a945f1e7e02f1c32b8a06340b53796eb804..dba0ef361891be52141a0121bbf152f00ae5f119 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 a64bae599dd1cfdbe182e2800b1ddbb02313b158..55ed6e19f592c64d3b1c4d9b7ba9d5f8862d35c8 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 f481a593ee24c16665374123fb280e86dae2537a..4e45faf9d6614caf4cc66f4e4f80ada3d8265e3a 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 58d197aea1de9f5a85529ef9e073de179dbac8ea..5ef3d0a76e324f2cdd8b2fc57c85c0b575aae56e 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 ba115e24dcfedff529ab7005804849183ae3c289..7ce4c8b8212dadea90b71adea9b49dab37a1c87e 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 16f2b96b3170a369d3bd26ea9dbb74b1643418cc..ca884c8a06ef4bab390ee2d256e34d484f1c7dd3 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 edbdb874b4bf76d6246b25a5b554b99045cbcf12..72adb4346a3042db59e215562da24c618310542b 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 50eeb5261ee22de007f3cd4d34360585c5823176..b6e11d2adb3e0c6c8d408b41e7f2908259da3981 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 20df0ec3255ef896a951340304d1b213b6ebdcff..c4634b55f0151bd10216c02dc2b6ae589895401d 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 fd5e262678ce2b168df126ed7234a84120c74dad..30d164b865ff7504f9b5a976503b01d3fb01d9c9 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 481f379ac48282dbf8c8d7cfdfecfefbde900fe4..2194d40d5d5ed0afc87aa12a0f1b730999bb5f9d 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 e6b1b793dc5880712ab37c90fe6d38fe12f2c108..72f5b2e7cdd505328e2bd6456e6b5ee7d2e97a42 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 d0180f065ac4c267ee887c38f183beff485ccfa0..9917e5e57f3058b532ed1bd248441018a6af6dfe 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 094198a2bf7fde62dad3495d73d4b39df9d25a14..3d88bb7638af48a1d008101dbdc0dea26059828c 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 3810056789d2d5cad9cb693d19fb698b53450abe..7fef139d900a5b72fcce88d3e508050c38f809a1 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 f1746070219d37110bd7d66ee23b38e63d6d03ce..b56ef03802610b5c99414eea9ea5d5d381556f79 100644 --- a/services/accesstokenmanager/main/sa_profile/3503.xml +++ b/services/accesstokenmanager/main/sa_profile/3503.xml @@ -1,5 +1,5 @@ -