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/frameworks/common/src/random_mbedtls.cpp b/frameworks/common/src/random_mbedtls.cpp index f7cf0f8f1bc43ea1d1d08f9f3413906822ab6da9..082298f5dadccf80d374831a7852a26fe18f3820 100644 --- a/frameworks/common/src/random_mbedtls.cpp +++ b/frameworks/common/src/random_mbedtls.cpp @@ -34,7 +34,7 @@ extern "C" unsigned int GetRandomUint32() int RandomMbedtls::GenerateRandomArray(unsigned char *randStr, unsigned int len) { - if (randStr == NULL || len == 0) { + if (randStr == nullptr || len == 0) { return RET_FAILED; } int ret; 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 c9a97a081289fe52cbff9a79bf056646fb123587..b2740bf081cc53c38de2598b1806e53fea9b7a7e 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 56a4ada183414994e980c6fb6d840e1fa6c09999..29fbaebd110bd85bbfb93a3a7738ec58a22ceb59 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp @@ -1780,7 +1780,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); @@ -1822,7 +1822,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 662ba98c19808949ae936c47cb9fe7b68e8f13cd..326907e1e905edc97741548789653e7984fe892e 100644 --- a/interfaces/innerkits/nativetoken/src/nativetoken.c +++ b/interfaces/innerkits/nativetoken/src/nativetoken.c @@ -43,7 +43,7 @@ int32_t GetFileBuff(const char *cfg, char **retBuff) return ATRET_FAILED; } - size_t fileSize = fileStat.st_size; + size_t fileSize = (unsigned)fileStat.st_size; FILE *cfgFd = fopen(filePath, "r"); if (cfgFd == NULL) { @@ -250,6 +250,8 @@ int GetRandomTokenId(uint32_t *randNum) } len = read(fd, &random, sizeof(random)); (void)close(fd); + fd = -1; + 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/interfaces/kits/accesstoken/napi/include/napi_atmanager.h b/interfaces/kits/accesstoken/napi/include/napi_atmanager.h index f6d444a7862469e8c1e4f752d2f747b16d17effc..adf43828e064034f8b3f498c876db4e10f80c032 100644 --- a/interfaces/kits/accesstoken/napi/include/napi_atmanager.h +++ b/interfaces/kits/accesstoken/napi/include/napi_atmanager.h @@ -26,13 +26,13 @@ namespace OHOS { namespace Security { namespace AccessToken { -#define ASYN_THREAD_EXEC_SUCC 0 -#define ASYN_THREAD_EXEC_FAIL -1 -#define ACCESSTOKEN_PERMISSION_GRANT_FAIL -1 -#define ACCESSTOKEN_PERMISSION_GRANT_SUCC 0 -#define ACCESSTOKEN_PERMISSION_REVOKE_FAIL -1 -#define ACCESSTOKEN_PERMISSION_REVOKE_SUCC 0 -#define VALUE_BUFFER_SIZE 128 +const int ASYN_THREAD_EXEC_SUCC = 0; +const int ASYN_THREAD_EXEC_FAIL = -1; +const int ACCESSTOKEN_PERMISSION_GRANT_FAIL = -1; +const int ACCESSTOKEN_PERMISSION_GRANT_SUCC = 0; +const int ACCESSTOKEN_PERMISSION_REVOKE_FAIL = -1; +const int ACCESSTOKEN_PERMISSION_REVOKE_SUCC = 0; +const int VALUE_BUFFER_SIZE = 128; static thread_local napi_ref atManagerRef_; const std::string ATMANAGER_CLASS_NAME = "atManager"; 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 e2cad901f4f815fcf70f4ff9b2183b1e9978a626..3a1a9e89ad49308edfa21f00264a4ae3c57c2c3b 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 0d5c8916a84de923121a3a7b09c64f4b48e97dd5..032b7b038054e88668c1a220e67188e6f94d1fd9 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp @@ -117,7 +117,7 @@ void AccessTokenManagerStub::GetReqPermissionsInner(MessageParcel& data, Message 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 @@ -