diff --git a/BUILD.gn b/BUILD.gn index 01805d6c9e70abcd18462e79b755cb32e34b8c3b..e7662fad40fb94029c5feab41613aa9e205c7887 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 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 @@ -22,6 +22,7 @@ group("accesstoken_build_module") { "//base/security/access_token/interfaces/kits:napi_packages", "//base/security/access_token/services/accesstokenmanager:accesstoken_manager_service", "//base/security/access_token/services/accesstokenmanager/main/sa_profile:accesstoken_sa_profile_standard", + "//base/security/access_token/tools/accesstoken:tools_atm", ] } } diff --git a/frameworks/accesstoken/include/i_accesstoken_manager.h b/frameworks/accesstoken/include/i_accesstoken_manager.h index 0cb3e8219d36593f43e9682bf9d068c783eedd07..a9d38c17d7a2e5f89d7ec57f39da7371b41c312c 100644 --- a/frameworks/accesstoken/include/i_accesstoken_manager.h +++ b/frameworks/accesstoken/include/i_accesstoken_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -68,7 +68,8 @@ public: virtual int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID) = 0; virtual AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) = 0; virtual int DeleteRemoteDeviceTokens(const std::string& deviceID) = 0; - virtual int DumpToken(std::string& dumpInfo) = 0; + + virtual void DumpTokenInfo(std::string& tokenInfo) = 0; enum class InterfaceCode { VERIFY_ACCESSTOKEN = 0xff10, @@ -97,7 +98,7 @@ public: DELETE_REMOTE_DEVICE_TOKEN = 0xff2c, GET_NATIVE_REMOTE_TOKEN = 0xff2f, - DUMP = 0xff30, + DUMP_TOKENINFO = 0xff30, }; }; } // namespace AccessToken diff --git a/interfaces/innerkits/accesstoken/include/accesstoken_kit.h b/interfaces/innerkits/accesstoken/include/accesstoken_kit.h index 5d1da2003b400a4bd167e895def13b49f7937dbd..abad9656cc764446d4ef90a20ce2f308732cf8e6 100644 --- a/interfaces/innerkits/accesstoken/include/accesstoken_kit.h +++ b/interfaces/innerkits/accesstoken/include/accesstoken_kit.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -61,7 +61,7 @@ public: static int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID); static AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID); static int DeleteRemoteDeviceTokens(const std::string& deviceID); - static int DumpToken(std::string& dumpInfo); + static void DumpTokenInfo(std::string& dumpInfo); }; } // namespace AccessToken } // namespace Security diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp index fd2b02f46bc2b65585e69eb105767f96e4bffe70..17e4e4622a7505a5c7d83935374e3b8311f8a974 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_kit.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -328,9 +328,10 @@ AccessTokenID AccessTokenKit::GetRemoteNativeTokenID(const std::string& deviceID return AccessTokenManagerClient::GetInstance().GetRemoteNativeTokenID(deviceID, tokenID); } -int AccessTokenKit::DumpToken(std::string& dumpInfo) +void AccessTokenKit::DumpTokenInfo(std::string& dumpInfo) { - return AccessTokenManagerClient::GetInstance().DumpToken(dumpInfo); + ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + AccessTokenManagerClient::GetInstance().DumpTokenInfo(dumpInfo); } } // namespace AccessToken } // namespace Security diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp index 2675cf886c45d00e41b0fc90a1c16c99ae627477..2d18c4b00b632e41d0d4fbb39aaa2681bca1cf78 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -373,16 +373,15 @@ int AccessTokenManagerClient::DeleteRemoteDeviceTokens(const std::string& device return res; } -int AccessTokenManagerClient::DumpToken(std::string& dumpInfo) +void AccessTokenManagerClient::DumpTokenInfo(std::string& dumpInfo) { ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s: called!", __func__); auto proxy = GetProxy(); if (proxy == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "proxy is null"); - return RET_FAILED; + ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s: proxy is null", __func__); + return; } - AccessTokenID res = proxy->DumpToken(dumpInfo); - return res; + proxy->DumpTokenInfo(dumpInfo); } void AccessTokenManagerClient::InitProxy() diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h index 5d4e92642d5023e03430529dbb4b84e4fb6ca879..d0c3157048d5ef1041eef1829965adb767cec7fc 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -66,7 +66,7 @@ public: int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID); AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID); int DeleteRemoteDeviceTokens(const std::string& deviceID); - int DumpToken(std::string& dumpInfo); + void DumpTokenInfo(std::string& dumpInfo); void OnRemoteDiedHandle(); private: diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp index 0f73695760119d1444fac5824c0457413eb5277d..c43e1761b10015a45f452ecc09d18c9f97465ae6 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -832,29 +832,27 @@ int AccessTokenManagerProxy::DeleteRemoteDeviceTokens(const std::string& deviceI return result; } -int AccessTokenManagerProxy::DumpToken(std::string& dumpInfo) +void AccessTokenManagerProxy::DumpTokenInfo(std::string& dumpInfo) { MessageParcel data; data.WriteInterfaceToken(IAccessTokenManager::GetDescriptor()); MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); + MessageOption option; sptr remote = Remote(); if (remote == nullptr) { - ACCESSTOKEN_LOG_ERROR(LABEL, "remote service null."); - return RET_FAILED; + ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s: remote service null.", __func__); + return; } int32_t requestResult = remote->SendRequest( - static_cast(IAccessTokenManager::InterfaceCode::DUMP), data, reply, option); + static_cast(IAccessTokenManager::InterfaceCode::DUMP_TOKENINFO), data, reply, option); if (requestResult != NO_ERROR) { - ACCESSTOKEN_LOG_ERROR(LABEL, "send request fail, result: %{public}d", requestResult); - return RET_FAILED; + ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s send request fail, result: %{public}d", __func__, requestResult); + return; } dumpInfo = reply.ReadString(); - AccessTokenID result = reply.ReadInt32(); - ACCESSTOKEN_LOG_DEBUG(LABEL, "get result from server data = %{public}d", result); - return result; + ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s get result from server dumpInfo = %{public}s", __func__, dumpInfo.c_str()); } } // namespace AccessToken } // namespace Security diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h index 913f3022db15a5d0fed77a8b11c5f09f44041fea..d1c297e360c5265c5376438e8d160fbd9b95342f 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -67,7 +67,7 @@ public: AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) override; int DeleteRemoteDeviceTokens(const std::string& deviceID) override; - int DumpToken(std::string& dumpInfo) override; + void DumpTokenInfo(std::string& dumpInfo) override; private: static inline BrokerDelegator delegator_; }; diff --git a/interfaces/kits/accesstoken/BUILD.gn b/interfaces/kits/accesstoken/BUILD.gn index 845943ab38babd7b37ff52e710d9b6dba1aa7c92..2b0349b6ad2c1666dc20768e82617934208035ad 100644 --- a/interfaces/kits/accesstoken/BUILD.gn +++ b/interfaces/kits/accesstoken/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 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 @@ -15,34 +15,18 @@ import("//build/ohos.gni") ohos_shared_library("libabilityaccessctrl") { include_dirs = [ - "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", - "//foundation/ace/napi/interfaces/kits", - "//third_party/json/single_include", - "//third_party/node/src", - "//utils/system/safwk/native/include", - "//foundation/communication/dsoftbus/interfaces/kits/transport", - "//foundation/communication/dsoftbus/interfaces/kits/common", - "//foundation/communication/dsoftbus/interfaces/kits/bus_center", - "//third_party/json/include", - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", "//base/security/access_token/frameworks/common/include", - "//base/security/access_token/interfaces/kits/accesstoken/napi/include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", + "//base/security/access_token/interfaces/kits/accesstoken/napi/include", + "//foundation/ace/napi/interfaces/innerkits", + "//foundation/ace/napi/interfaces/kits", ] sources = [ "//base/security/access_token/interfaces/kits/accesstoken/napi/src/napi_atmanager.cpp" ] deps = [ - "//base/notification/ans_standard/frameworks/ans/core:ans_core", "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", - "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara", - "//foundation/aafwk/standard/interfaces/innerkits/base:base", "//foundation/ace/napi:ace_napi", - "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", ] cflags_cc = [ "-DHILOG_ENABLE" ] external_deps = [ diff --git a/interfaces/kits/accesstoken/napi/src/napi_atmanager.cpp b/interfaces/kits/accesstoken/napi/src/napi_atmanager.cpp index 02dd841c4922adfbf9249e6adfdbd9602063059c..4dc7532addaff58bebba83db8e07e7b764933bdb 100644 --- a/interfaces/kits/accesstoken/napi/src/napi_atmanager.cpp +++ b/interfaces/kits/accesstoken/napi/src/napi_atmanager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -268,7 +268,7 @@ void NapiAtManager::GrantUserGrantedPermissionExcute(napi_env env, void *data) asyncContext->permissionName, asyncContext->flag); - ACCESSTOKEN_LOG_DEBUG(LABEL, + ACCESSTOKEN_LOG_DEBUG(LABEL, "tokenId = %{public}d, permissionName = %{public}s, flag = %{public}d, grant result = %{public}d.", asyncContext->tokenId, asyncContext->permissionName, asyncContext->flag, asyncContext->result); diff --git a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h index 9cf112728ed19297058bca770516d77132f499b3..011605648aab8e435a1fadb139db42d826779ba9 100644 --- a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h +++ b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -67,7 +67,7 @@ public: AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID) override; int DeleteRemoteDeviceTokens(const std::string& deviceID) override; - int DumpToken(std::string& dumpInfo) override; + void DumpTokenInfo(std::string& dumpInfo) override; private: bool Initialize() const; diff --git a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h index 6021a07305ea8860630bdb978d7e36c1fc56ce1d..269ce13966086831e3f301fba8ff699b5d61baba 100644 --- a/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h +++ b/services/accesstokenmanager/main/cpp/include/service/accesstoken_manager_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -61,7 +61,7 @@ private: void DeleteRemoteDeviceTokensInner(MessageParcel& data, MessageParcel& reply); void GetRemoteNativeTokenIDInner(MessageParcel& data, MessageParcel& reply); void GetRemoteHapTokenIDInner(MessageParcel& data, MessageParcel& reply); - void DumpTokenInner(MessageParcel& data, MessageParcel& reply); + void DumpTokenInfoInner(MessageParcel& data, MessageParcel& reply); bool IsAuthorizedCalling() const; static const int SYSTEM_UID = 1000; diff --git a/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h b/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h index dae3e0c83192b6cc2ba3ab9a2992ab3fafa51dec..db85e4eda245fa0a676d7c5a365a27889924c620 100644 --- a/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h +++ b/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -50,7 +50,7 @@ public: AccessTokenID AllocLocalTokenID(const std::string& remoteDeviceID, AccessTokenID remoteTokenID); void ProcessNativeTokenInfos(const std::vector>& tokenInfos); int UpdateHapToken(AccessTokenID tokenID, const std::string& appIDDesc, const HapPolicyParams& policy); - void Dump(std::string& dumpInfo); + void DumpTokenInfo(std::string& dumpInfo); void RefreshTokenInfoIfNeeded(); /* tokensync needed */ diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp index 9cb3d050755137a1fe4df66b5e0eb202a6144661..f70246e47d297e0011978c82f772b6ea075bb6d5 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_policy_set.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -247,75 +247,82 @@ void PermissionPolicySet::GetPermissionStateList(std::vector infoGuard(this->permPolicySetLock_); - info.append(",\n\t"); - info.append(R"("permDefList": [)"); + info.append(R"( "permDefList": [)"); + info.append("\n"); for (auto iter = permList_.begin(); iter != permList_.end(); iter++) { - info.append("\n\t\t"); PermDefToString(*iter, info); if (iter != (permList_.end() - 1)) { - info.append(","); + info.append(",\n"); } } - info.append("]"); + info.append("\n ],\n"); - info.append(",\n\t"); - info.append(R"("permStateList": [)"); + info.append(R"( "permStateList": [)"); + info.append("\n"); for (auto iter = permStateList_.begin(); iter != permStateList_.end(); iter++) { - info.append("\n\t\t"); PermStateFullToString(*iter, info); if (iter != (permStateList_.end() - 1)) { - info.append(","); + info.append(",\n"); } } - info.append("]"); + info.append("\n ]\n"); } } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp index f5927dc9a79698e3f9bddba9051e82bc3d35b17a..7127e00861b825bb145a21e92aa21edd32e82ed9 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -302,10 +302,11 @@ int AccessTokenManagerService::DeleteRemoteDeviceTokens(const std::string& devic return AccessTokenInfoManager::GetInstance().DeleteRemoteDeviceTokens(deviceID); } -int AccessTokenManagerService::DumpToken(std::string& dumpInfo) +void AccessTokenManagerService::DumpTokenInfo(std::string& dumpInfo) { - AccessTokenInfoManager::GetInstance().Dump(dumpInfo); - return 0; + ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + + AccessTokenInfoManager::GetInstance().DumpTokenInfo(dumpInfo); } bool AccessTokenManagerService::Initialize() const 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 6d4bd91239b3db657979c093a9f2ed475b4fc6ff..27ef4f38a156a1af345d1fd087dd0ab77c42756e 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -382,17 +382,15 @@ void AccessTokenManagerStub::DeleteRemoteDeviceTokensInner(MessageParcel& data, reply.WriteInt32(result); } -void AccessTokenManagerStub::DumpTokenInner(MessageParcel& data, MessageParcel& reply) +void AccessTokenManagerStub::DumpTokenInfoInner(MessageParcel& data, MessageParcel& reply) { if (!IsAuthorizedCalling()) { ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called, permission denied", __func__); - reply.WriteInt32(RET_FAILED); return; } - std::string dumpInfo; - int result = this->DumpToken(dumpInfo); + std::string dumpInfo = ""; + this->DumpTokenInfo(dumpInfo); reply.WriteString(dumpInfo); - reply.WriteUint32(result); } bool AccessTokenManagerStub::IsAuthorizedCalling() const @@ -452,8 +450,8 @@ AccessTokenManagerStub::AccessTokenManagerStub() &AccessTokenManagerStub::DeleteRemoteDeviceTokensInner; requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::GET_NATIVE_REMOTE_TOKEN)] = &AccessTokenManagerStub::GetRemoteNativeTokenIDInner; - requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::DUMP)] = - &AccessTokenManagerStub::DumpTokenInner; + requestFuncMap_[static_cast(IAccessTokenManager::InterfaceCode::DUMP_TOKENINFO)] = + &AccessTokenManagerStub::DumpTokenInfoInner; } AccessTokenManagerStub::~AccessTokenManagerStub() diff --git a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp index 5b456fdfce5d5b31b2913a37307887b9f6dd2661..059403f0cebf3228e767c29b9baf108c07904fcf 100644 --- a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -843,25 +843,28 @@ void AccessTokenInfoManager::RefreshTokenInfoIfNeeded() }); } -void AccessTokenInfoManager::Dump(std::string& dumpInfo) +void AccessTokenInfoManager::DumpTokenInfo(std::string& dumpInfo) { + ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_INFO(LABEL, "get hapTokenInfo"); + Utils::UniqueReadGuard hapInfoGuard(this->hapTokenInfoLock_); for (auto iter = hapTokenInfoMap_.begin(); iter != hapTokenInfoMap_.end(); iter++) { if (iter->second != nullptr) { - dumpInfo.append("\n"); iter->second->ToString(dumpInfo); dumpInfo.append("\n"); } } + ACCESSTOKEN_LOG_INFO(LABEL, "get nativeTokenInfo"); Utils::UniqueReadGuard nativeInfoGuard(this->nativeTokenInfoLock_); for (auto iter = nativeTokenInfoMap_.begin(); iter != nativeTokenInfoMap_.end(); iter++) { if (iter->second != nullptr) { - dumpInfo.append("\n"); iter->second->ToString(dumpInfo); dumpInfo.append("\n"); } } + ACCESSTOKEN_LOG_INFO(LABEL, "get tokeninfo: %{public}s", dumpInfo.c_str()); } } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp b/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp index d8e846ea3667e08c74aeb02f6b538b6859547c0a..254d10b3d921177498e0c31a7b192dedfe156124 100644 --- a/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/hap_token_info_inner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -231,16 +231,18 @@ void HapTokenInfoInner::SetRemote(bool isRemote) void HapTokenInfoInner::ToString(std::string& info) const { - info.append(R"({"tokenID": )" + std::to_string(tokenInfoBasic_.tokenID)); - info.append(R"(, "tokenAttr": )" + std::to_string(tokenInfoBasic_.tokenAttr)); - info.append(R"(, "ver": )" + std::to_string(tokenInfoBasic_.ver)); - info.append(R"(, "userId": )" + std::to_string(tokenInfoBasic_.userID)); - info.append(R"(, "bundleName": ")" + tokenInfoBasic_.bundleName + R"(")"); - info.append(R"(, "instIndex": )" + std::to_string(tokenInfoBasic_.instIndex)); - info.append(R"(, "appID": ")" + tokenInfoBasic_.appID + R"(")"); - info.append(R"(, "deviceID": ")" + tokenInfoBasic_.deviceID + R"(")"); - info.append(R"(, "apl": )" + std::to_string(tokenInfoBasic_.apl)); - info.append(R"(, "isRemote": )" + std::to_string(isRemote_)); + info.append(R"({)"); + info.append("\n"); + info.append(R"( "tokenID": )" + std::to_string(tokenInfoBasic_.tokenID) + ",\n"); + info.append(R"( "tokenAttr": )" + std::to_string(tokenInfoBasic_.tokenAttr) + ",\n"); + info.append(R"( "ver": )" + std::to_string(tokenInfoBasic_.ver) + ",\n"); + info.append(R"( "userId": )" + std::to_string(tokenInfoBasic_.userID) + ",\n"); + info.append(R"( "bundleName": ")" + tokenInfoBasic_.bundleName + R"(")" + ",\n"); + info.append(R"( "instIndex": )" + std::to_string(tokenInfoBasic_.instIndex) + ",\n"); + info.append(R"( "appID": ")" + tokenInfoBasic_.appID + R"(")" + ",\n"); + info.append(R"( "deviceID": ")" + tokenInfoBasic_.deviceID + R"(")" + ",\n"); + info.append(R"( "apl": )" + std::to_string(tokenInfoBasic_.apl) + ",\n"); + info.append(R"( "isRemote": )" + std::to_string(isRemote_) + ",\n"); if (permPolicySet_ != nullptr) { permPolicySet_->ToString(info); diff --git a/services/accesstokenmanager/main/cpp/src/token/native_token_info_inner.cpp b/services/accesstokenmanager/main/cpp/src/token/native_token_info_inner.cpp index 58d0ed35de4e0594f0697729f6204b9e44c8941d..0f85b2e7bbff6070a102e421f06a7bfd9602c79e 100644 --- a/services/accesstokenmanager/main/cpp/src/token/native_token_info_inner.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/native_token_info_inner.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -184,13 +184,15 @@ void NativeTokenInfoInner::SetDcaps(const std::string& dcapStr) void NativeTokenInfoInner::ToString(std::string& info) const { - info.append(R"({"tokenID": )" + std::to_string(tokenInfoBasic_.tokenID)); - info.append(R"(, "tokenAttr": )" + std::to_string(tokenInfoBasic_.tokenAttr)); - info.append(R"(, "ver": )" + std::to_string(tokenInfoBasic_.ver)); - info.append(R"(, "processName": ")" + tokenInfoBasic_.processName + R"(")"); - info.append(R"(, "apl": )" + std::to_string(tokenInfoBasic_.apl)); - info.append(R"(, "dcap": ")" + DcapToString(tokenInfoBasic_.dcap) + R"(")"); - info.append(R"(, "isRemote": )" + std::to_string(isRemote_? 1 : 0)); + info.append(R"({)"); + info.append("\n"); + info.append(R"( "tokenID": )" + std::to_string(tokenInfoBasic_.tokenID) + ",\n"); + info.append(R"( "tokenAttr": )" + std::to_string(tokenInfoBasic_.tokenAttr) + ",\n"); + info.append(R"( "ver": )" + std::to_string(tokenInfoBasic_.ver) + ",\n"); + info.append(R"( "processName": ")" + tokenInfoBasic_.processName + R"(")" + ",\n"); + info.append(R"( "apl": )" + std::to_string(tokenInfoBasic_.apl) + ",\n"); + info.append(R"( "dcap": ")" + DcapToString(tokenInfoBasic_.dcap) + R"(")" + ",\n"); + info.append(R"( "isRemote": )" + std::to_string(isRemote_? 1 : 0) + ",\n"); info.append("}"); } } // namespace AccessToken diff --git a/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp b/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp index d981b08d9fade47f44b341d5b427d44009afee1d..8879bcb3f454162d913475de10b0a036e8e39bd9 100644 --- a/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp +++ b/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 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 @@ -101,7 +101,7 @@ HWTEST_F(AccessTokenInfoManagerTest, Init001, TestSize.Level1) { AccessTokenInfoManager::GetInstance().Init(); std::string dumpInfo; - AccessTokenInfoManager::GetInstance().Dump(dumpInfo); + AccessTokenInfoManager::GetInstance().DumpTokenInfo(dumpInfo); GTEST_LOG_(INFO) << "dump all:" << dumpInfo.c_str(); // delete test token diff --git a/tools/accesstoken/BUILD.gn b/tools/accesstoken/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ed8b0ee1e95b8f659070b24b26f679cc2a75df1a --- /dev/null +++ b/tools/accesstoken/BUILD.gn @@ -0,0 +1,62 @@ +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# 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. + +import("//build/ohos.gni") + +ohos_source_set("tools_atm_source_set") { + include_dirs = [ + "//base/security/access_token/tools/accesstoken/include", + "//base/security/access_token/frameworks/common/include", + "//foundation/aafwk/standard/tools/aa/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/main/cpp/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/aafwk/standard/services/common/include", + ] + + sources = [ + "//foundation/aafwk/standard/tools/aa/src/shell_command.cpp", + "src/atm_command.cpp", + "src/atm_receiver_impl.cpp", + "src/main.cpp", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//foundation/aafwk/standard/tools/aa:aa", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "//utils/native/base:utils", + ] + + cflags = [ "-DHILOG_ENABLE" ] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + +ohos_executable("atm") { + deps = [ ":tools_atm_source_set" ] + + install_enable = true + subsystem_name = "security" + part_name = "access_token" +} + +group("tools_atm") { + deps = [ ":atm" ] +} diff --git a/tools/accesstoken/include/atm_command.h b/tools/accesstoken/include/atm_command.h new file mode 100644 index 0000000000000000000000000000000000000000..922429d5a86d8ead4bea6ad8c837bbea84fdcf33 --- /dev/null +++ b/tools/accesstoken/include/atm_command.h @@ -0,0 +1,48 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ + +#ifndef ACCESSTOKENMANAGER_COMMAND_H +#define ACCESSTOKENMANAGER_COMMAND_H + +#include "shell_command.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +const std::string TOOLS_NAME = "atm"; +const std::string HELP_MSG = "usage: atm \n" + "These are common atm commands list:\n" + " help list available commands\n" + " dump list token info\n"; + +class AtmCommand : public OHOS::AAFwk::ShellCommand { +public: + AtmCommand(int argc, char *argv[]); + ~AtmCommand() override + {} + +private: + ErrCode CreateCommandMap() override; + ErrCode CreateMessageMap() override; + ErrCode init() override; + + ErrCode RunAsHelpCommand(); + ErrCode RunAsDumpCommand(); +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // ACCESSTOKENMANAGER_COMMAND_H \ No newline at end of file diff --git a/tools/accesstoken/include/atm_receiver_impl.h b/tools/accesstoken/include/atm_receiver_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..7bacf3f57c8c82059cf0a0abed73f410f7e56997 --- /dev/null +++ b/tools/accesstoken/include/atm_receiver_impl.h @@ -0,0 +1,43 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ + +#ifndef ACCESSTOKENMANAGER_RECEIVER_IMPL_H +#define ACCESSTOKENMANAGER_RECEIVER_IMPL_H + +#include +#include "status_receiver_host.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class AtmReceiverImpl : public AppExecFwk::StatusReceiverHost { +public: + AtmReceiverImpl(); + virtual ~AtmReceiverImpl() override; + + virtual void OnStatusNotify(const int process) override; + virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override; + int32_t GetResultCode() const; + +private: + mutable std::promise resultMsgSignal_; + + DISALLOW_COPY_AND_MOVE(AtmReceiverImpl); +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // ACCESSTOKENMANAGER_RECEIVER_IMPL_H \ No newline at end of file diff --git a/tools/accesstoken/src/atm_command.cpp b/tools/accesstoken/src/atm_command.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5b1556ae40c45d5ad0b016ae847ff521b63181e --- /dev/null +++ b/tools/accesstoken/src/atm_command.cpp @@ -0,0 +1,79 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ + +#include "atm_command.h" + +#include "accesstoken_kit.h" +#include "status_receiver_host.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +AtmCommand::AtmCommand(int argc, char *argv[]) : ShellCommand(argc, argv, TOOLS_NAME) +{} + +ErrCode AtmCommand::CreateCommandMap() +{ + commandMap_ = { + {"help", std::bind(&AtmCommand::RunAsHelpCommand, this)}, + {"dump", std::bind(&AtmCommand::RunAsDumpCommand, this)}, + }; + + return OHOS::ERR_OK; +} + +ErrCode AtmCommand::CreateMessageMap() +{ + messageMap_ = { + // error + message + // currently there is no error to use + // { + // AppExecFwk::IStatusReceiver::ERR_USER_REMOVE_FALIED, + // "error: user remove failed.", + // }, + }; + + return OHOS::ERR_OK; +} + +ErrCode AtmCommand::init() +{ + ErrCode result = OHOS::ERR_OK; + + // there is no need to get proxy currently, the function used in class AccessTokenKit is static + + return result; +} + +ErrCode AtmCommand::RunAsHelpCommand() +{ + resultReceiver_.append(HELP_MSG); + + return OHOS::ERR_OK; +} + +ErrCode AtmCommand::RunAsDumpCommand() +{ + int result = OHOS::ERR_OK; + std::string tokenInfo = ""; + + AccessTokenKit::DumpTokenInfo(tokenInfo); + resultReceiver_ = tokenInfo + "\n"; + + return result; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/tools/accesstoken/src/atm_receiver_impl.cpp b/tools/accesstoken/src/atm_receiver_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d7333b96c14bb090ccabcb05f314c3bd64ad28a --- /dev/null +++ b/tools/accesstoken/src/atm_receiver_impl.cpp @@ -0,0 +1,59 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ + +#include "accesstoken_log.h" +#include "atm_receiver_impl.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AccessTokenManagerTools" +}; +} + +AtmReceiverImpl::AtmReceiverImpl() +{ + ACCESSTOKEN_LOG_DEBUG(LABEL, "create atm status receiver instance"); +} + +AtmReceiverImpl::~AtmReceiverImpl() +{ + ACCESSTOKEN_LOG_DEBUG(LABEL, "destory atm status receiver instance"); +} + +void AtmReceiverImpl::OnFinished(const int32_t resultCode, const std::string &resultMsg) +{ + ACCESSTOKEN_LOG_DEBUG(LABEL, "on finished result is %{public}d, %{public}s", resultCode, resultMsg.c_str()); + resultMsgSignal_.set_value(resultCode); +} + +void AtmReceiverImpl::OnStatusNotify(const int process) +{ + ACCESSTOKEN_LOG_DEBUG(LABEL, "on OnStatusNotify is %{public}d", process); +} + +int32_t AtmReceiverImpl::GetResultCode() const +{ + auto future = resultMsgSignal_.get_future(); + future.wait(); + int32_t resultCode = future.get(); + + return resultCode; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/tools/accesstoken/src/main.cpp b/tools/accesstoken/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57f7ce64e87a47cc7ed7ac1223f97a6411fe6bf2 --- /dev/null +++ b/tools/accesstoken/src/main.cpp @@ -0,0 +1,24 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ +#include + +#include "atm_command.h" + +int main(int argc, char *argv[]) +{ + OHOS::Security::AccessToken::AtmCommand cmd(argc, argv); + std::cout << cmd.ExecCommand(); + return 0; +} \ No newline at end of file