* Copyright (c) 2026 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.
*/
* @file ipc_caller_auth.h
* @brief IPC 侧调用方鉴权工具:封装 AccessTokenKit、IPCSkeleton 等通用能力。
*
* 不包含具体业务白名单(特定 UID、进程名、免检条件等),由调用方在业务层自行组合。
*/
#ifndef OHOS_FILEMANAGEMENT_DISK_MANAGER_IPC_CALLER_AUTH_H
#define OHOS_FILEMANAGEMENT_DISK_MANAGER_IPC_CALLER_AUTH_H
#include <cstdint>
#include <functional>
#include <string>
namespace OHOS {
namespace DiskManager {
inline const std::string PERMISSION_STORAGE_MANAGER = "ohos.permission.STORAGE_MANAGER";
inline const std::string PERMISSION_MOUNT_MANAGER = "ohos.permission.MOUNT_UNMOUNT_MANAGER";
inline const std::string PERMISSION_FORMAT_MANAGER = "ohos.permission.MOUNT_FORMAT_MANAGER";
* @class IpcCallerAuth
* @brief 基于当前 IPC 线程上下文(IPCSkeleton + AccessTokenKit)的通用鉴权与调用方信息读取。
*/
class IpcCallerAuth {
public:
static bool VerifyCallerPermission(const std::string &permissionName);
* 先按业务回调判定是否为可信调用方;否时再走 VerifyCallerPermission。
* @param permissionName 待校验权限名。
* @param trustWithoutPermission 返回 true 则跳过令牌权限校验。
*/
static bool VerifyCallerPermissionUnlessTrusted(const std::string &permissionName,
const std::function<bool()> &trustWithoutPermission);
static bool IsCallingSystemApp();
static bool VerifyNativeCallerMatches(const std::string &expectedProcessName, int32_t expectedUid);
static int32_t GetCallingUid();
static bool IsCallingUid(int32_t expectedUid);
static bool IsCallingNativeToken();
static bool IsCallingHapToken();
static std::string GetCallingBundleOrNativeProcessName();
static int32_t GetCallingUserId();
IpcCallerAuth() = delete;
~IpcCallerAuth() = delete;
};
using PermissionChecker = IpcCallerAuth;
}
}
#endif