add userauth executor

Change-Id: Ieffd57c3e485abeabc0232618336f99d3e167805
Signed-off-by: Tianshi Liu <tianshi.liu@huawei.com>
This commit is contained in:
Tianshi Liu 2022-04-24 17:28:17 +08:00
parent 8e92c28456
commit 3bfa39f228
42 changed files with 2305 additions and 13 deletions

4
.gitignore vendored
View File

@ -37,4 +37,6 @@
*.out
*.app
# Hidden
.*
!/.gitignore

View File

@ -38,6 +38,7 @@
"//base/user_iam/user_auth/sa_profile:userauth_sa_profile",
"//base/user_iam/user_auth/sa_profile:useriam.init",
"//base/user_iam/user_auth/services:userauthservice",
"//base/user_iam/user_auth/common/executors:userauth_executors",
"//base/user_iam/user_auth/services/co_auth/common:useriam_common_lib",
"//base/user_iam/user_auth/frameworks/js/napi/user_idm:useridm"
],

View File

@ -43,3 +43,26 @@ ohos_source_set("iam_thread_pool") {
part_name = "user_auth"
subsystem_name = "useriam"
}
config("iam_utils_config") {
include_dirs = [ "utils" ]
}
ohos_source_set("iam_utils") {
include_dirs = [
"utils",
"logs",
]
sources = [ "utils/iam_mem.cpp" ]
external_deps = [
"hilog_native:libhilog",
"utils_base:utils",
]
public_configs = [ ":iam_utils_config" ]
part_name = "user_auth"
subsystem_name = "useriam"
}

66
common/executors/BUILD.gn Normal file
View File

@ -0,0 +1,66 @@
# 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")
config("userauth_executors_public_config") {
include_dirs = [ "include/public" ]
}
ohos_shared_library("userauth_executors") {
sources = [
"src/async_command/async_command_base.cpp",
"src/async_command/auth_command.cpp",
"src/async_command/custom_command.cpp",
"src/async_command/enroll_command.cpp",
"src/async_command/identify_command.cpp",
"src/driver.cpp",
"src/driver_manager.cpp",
"src/executor.cpp",
"src/framework/framework_executor_callback.cpp",
"src/idriver_manager.cpp",
"src/system_ability_status_listener.cpp",
]
include_dirs = [
"include",
"include/async_command",
"include/framework",
"//base/user_iam/user_auth/interfaces/inner_api/user_auth/",
"//base/user_iam/user_auth/interfaces/inner_api/common/",
"//base/user_iam/user_auth/common/utils",
"//base/user_iam/user_auth/common/logs",
"//base/user_iam/user_auth/services/co_auth/common/coauth/inc/",
"//base/user_iam/user_auth/services/co_auth/common/common/inc/",
]
public_configs = [ ":userauth_executors_public_config" ]
remove_configs = [ "//build/config/compiler:no_exceptions" ]
deps = [ "//base/user_iam/user_auth/common:iam_utils" ]
external_deps = [
"device_driver_framework:libhdf_host",
"device_driver_framework:libhdf_ipc_adapter",
"device_driver_framework:libhdf_utils",
"device_driver_framework:libhdi",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"samgr_standard:samgr_proxy",
"startup_l2:syspara_watchagent",
"user_auth:coauth_framework",
"utils_base:utils",
]
part_name = "user_auth"
}

View File

@ -0,0 +1,61 @@
/*
* 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 ASYNC_COMMAND_BASE_H
#define ASYNC_COMMAND_BASE_H
#include <future>
#include <mutex>
#include "co_auth_defines.h"
#include "executor.h"
#include "nocopyable.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class AsyncCommandBase : public std::enable_shared_from_this<AsyncCommandBase>,
public IAsyncCommand,
public IExecuteCallback,
public NoCopyable {
public:
AsyncCommandBase(std::string type, uint64_t scheduleId, std::shared_ptr<Executor> executor);
virtual ~AsyncCommandBase() = default;
void OnHdiDisconnect() override;
ResultCode StartProcess() override;
void OnResult(ResultCode result) override;
void OnResult(ResultCode result, const std::vector<uint8_t> &extraInfo) override;
virtual void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override = 0;
protected:
static int32_t GenerateCommandId();
virtual ResultCode SendRequest() = 0;
virtual void OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo) = 0;
const char *GetDescription();
uint64_t scheduleId_;
std::shared_ptr<Executor> executor_;
uint32_t commandId_;
private:
void EndProcess();
std::string str_;
std::promise<void> promise_;
std::future<void> future_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // ASYNC_COMMAND_BASE_H

View File

@ -0,0 +1,44 @@
/*
* 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 AUTH_COMMAND_H
#define AUTH_COMMAND_H
#include "async_command_base.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class AuthCommand : public AsyncCommandBase {
public:
AuthCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
virtual ~AuthCommand() = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
protected:
void OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo) override;
ResultCode SendRequest() override;
private:
uint32_t transNum_ = 1;
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // AUTH_COMMAND_H

View File

@ -0,0 +1,47 @@
/*
* 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 CUSTOM_COMMAND_H
#define CUSTOM_COMMAND_H
#include "async_command_base.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class CustomCommand : public AsyncCommandBase {
public:
CustomCommand(std::shared_ptr<Executor> executor, std::shared_ptr<AuthResPool::AuthAttributes> attributes);
virtual ~CustomCommand() = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
ResultCode GetResult();
protected:
void OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo) override;
ResultCode SendRequest() override;
private:
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
ResultCode result_;
std::promise<void> promise_;
std::future<void> future_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // CUSTOM_COMMAND_H

View File

@ -0,0 +1,44 @@
/*
* 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 ENROLL_COMMAND_H
#define ENROLL_COMMAND_H
#include "async_command_base.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class EnrollCommand : public AsyncCommandBase {
public:
EnrollCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
virtual ~EnrollCommand() = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
protected:
void OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo) override;
ResultCode SendRequest() override;
private:
uint32_t transNum_ = 1;
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // ENROLL_COMMAND_H

View File

@ -0,0 +1,37 @@
/*
* 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 IASYNC_COMMAND_H
#define IASYNC_COMMAND_H
#include <cstdint>
#include "co_auth_defines.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class IAsyncCommand {
public:
IAsyncCommand() = default;
virtual ~IAsyncCommand() = default;
virtual void OnHdiDisconnect() = 0;
virtual ResultCode StartProcess() = 0;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // IASYNC_COMMAND_H

View File

@ -0,0 +1,44 @@
/*
* 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 IDENTIFY_COMMAND_H
#define IDENTIFY_COMMAND_H
#include "async_command_base.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class IdentifyCommand : public AsyncCommandBase {
public:
IdentifyCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
virtual ~IdentifyCommand() = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
protected:
void OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo) override;
ResultCode SendRequest() override;
private:
uint32_t transNum_ = 1;
std::shared_ptr<AuthResPool::AuthAttributes> attributes_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // IDENTIFY_COMMAND_H

View File

@ -0,0 +1,47 @@
/*
* 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 EXECUTOR_DRIVER_H
#define EXECUTOR_DRIVER_H
#include <string>
#include <vector>
#include "executor.h"
#include "idriver_manager.h"
#include "nocopyable.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class Driver : public NoCopyable {
public:
Driver(const std::string &serviceName, HdiConfig hdiConfig);
virtual ~Driver() = default;
void OnHdiConnect();
void OnHdiDisconnect();
void OnFrameworkReady();
private:
std::recursive_mutex mutex_;
std::string serviceName_;
HdiConfig hdiConfig_;
std::vector<std::shared_ptr<Executor>> executorList_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // EXECUTOR_DRIVER_H

View File

@ -0,0 +1,58 @@
/*
* 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 DRIVER_MANAGER_H
#define DRIVER_MANAGER_H
#include <cstdint>
#include <map>
#include "driver.h"
#include "iauth_driver_hdi.h"
#include "idriver_manager.h"
#include "iservstat_listener_hdi.h"
#include "singleton.h"
#include "system_ability_status_listener.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
using namespace HDI::ServiceManager::V1_0;
class DriverManager : public ServStatListenerStub, public Singleton<DriverManager> {
public:
friend SystemAbilityStatusListener;
void OnReceive(const ServiceStatus &status) override;
int32_t Start(const std::map<std::string, HdiConfig> &hdiName2Config);
void OnFrameworkReady();
private:
bool HdiConfigIsValid(const std::map<std::string, HdiConfig> &hdiName2Config);
bool HdiDriverIsRunning(const std::string &serviceName);
void SubscribeHdiDriverStatus();
void SubscribeHdiManagerServiceStatus();
void SubscribeFrameworkRedayEvent();
void OnAllHdiDisconnect();
void OnAllHdiConnect();
std::recursive_mutex mutex_;
std::map<std::string, std::shared_ptr<Driver>> serviceName2Driver_;
std::map<std::string, HdiConfig> hdiName2Config_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // DRIVER_MANAGER_H

View File

@ -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.
*/
#ifndef EXCECUTOR_H
#define EXCECUTOR_H
#include <cstdint>
#include <mutex>
#include <set>
#include <string>
#include "iasync_command.h"
#include "iauth_executor_hdi.h"
#include "iexecute_callback.h"
#include "iexecutor_messenger.h"
#include "nocopyable.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class Executor : public std::enable_shared_from_this<Executor>, public NoCopyable {
public:
Executor(std::shared_ptr<IAuthExecutorHdi> executorHdi, uint16_t hdiId);
virtual ~Executor() = default;
void OnHdiConnect();
void OnHdiDisconnect();
void OnFrameworkReady();
void SetExecutorMessenger(const sptr<AuthResPool::IExecutorMessenger> &messenger);
sptr<AuthResPool::IExecutorMessenger> GetExecutorMessenger();
void AddCommand(std::shared_ptr<IAsyncCommand> command);
void RemoveCommand(std::shared_ptr<IAsyncCommand> command);
std::shared_ptr<IAuthExecutorHdi> GetExecutorHdi();
const char *GetDescription();
private:
void RegisterExecutorCallback(ExecutorInfo &executorInfo);
void RespondCallbackOnDisconnect();
void SetStr(const int32_t executorId);
sptr<AuthResPool::IExecutorMessenger> executorMessenger_;
std::recursive_mutex mutex_;
std::set<std::shared_ptr<IAsyncCommand>> command2Respond_;
std::shared_ptr<IAuthExecutorHdi> executorHdi_;
std::string str_;
uint16_t hdiId_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // EXCECUTOR_H

View File

@ -0,0 +1,66 @@
/*
* 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 FRAMEWORK_EXECUTOR_CALLBACK_H
#define FRAMEWORK_EXECUTOR_CALLBACK_H
#include <cstdint>
#include "auth_attributes.h"
#include "auth_executor.h"
#include "co_auth_defines.h"
#include "coauth.h"
#include "executor.h"
#include "executor_callback.h"
#include "nocopyable.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
using pAuthAttributes = std::shared_ptr<AuthResPool::AuthAttributes>;
class FrameworkExecutorCallback : public AuthResPool::ExecutorCallback, public NoCopyable {
public:
explicit FrameworkExecutorCallback(std::shared_ptr<Executor> executor);
virtual ~FrameworkExecutorCallback() = default;
int32_t OnBeginExecute(uint64_t scheduleId, std::vector<uint8_t> &publicKey, pAuthAttributes commandAttrs) override;
int32_t OnEndExecute(uint64_t scheduleId, pAuthAttributes consumerAttr) override;
int32_t OnSetProperty(pAuthAttributes properties) override;
void OnMessengerReady(const sptr<AuthResPool::IExecutorMessenger> &messenger, std::vector<uint8_t> &publicKey,
std::vector<uint64_t> &templateIds) override;
int32_t OnGetProperty(std::shared_ptr<AuthResPool::AuthAttributes> conditions,
std::shared_ptr<AuthResPool::AuthAttributes> values) override;
private:
ResultCode OnBeginExecuteInner(uint64_t scheduleId, std::vector<uint8_t> &publicKey, pAuthAttributes commandAttrs);
ResultCode OnEndExecuteInner(uint64_t scheduleId, pAuthAttributes consumerAttr);
ResultCode OnSetPropertyInner(pAuthAttributes properties);
ResultCode OnGetPropertyInner(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values);
ResultCode ProcessEnrollCommand(uint64_t scheduleId, pAuthAttributes properties);
ResultCode ProcessAuthCommand(uint64_t scheduleId, pAuthAttributes properties);
ResultCode ProcessIdentifyCommand(uint64_t scheduleId, pAuthAttributes properties);
ResultCode ProcessCancelCommand(uint64_t scheduleId);
ResultCode ProcessDeleteTemplateCommand(pAuthAttributes properties);
ResultCode ProcessCustomCommand(pAuthAttributes properties);
ResultCode ProcessGetTemplateCommand(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values);
std::shared_ptr<Executor> executor_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // FRAMEWORK_EXECUTOR_CALLBACK_H

View File

@ -0,0 +1,57 @@
/*
* 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 FRAMEWORK_TYPES_H
#define FRAMEWORK_TYPES_H
#include <cstdint>
#include <vector>
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
enum UserAuthResult : int32_t {
USERAUTH_SUCCESS = 0,
USERAUTH_ERROR = 1,
};
enum CommandId : int32_t {
LOCK_TEMPLATE = 0,
UNLOCK_TEMPLATE = 1,
VENDOR_COMMAND_BEGIN = 10000,
};
struct TemplateInfo {
uint32_t executorType;
int32_t freezingTime;
int32_t remainTimes;
std::vector<uint8_t> extraInfo;
};
enum AuthPropertyMode : int32_t {
PROPERMODE_DELETE = 0,
PROPERMODE_GET = 1,
PROPERMODE_SET = 2,
PROPERMODE_FREEZE = 3,
PROPERMODE_UNFREEZE = 4,
PROPERMODE_INIT_ALGORITHM = 5,
PROPERMODE_RELEASE_ALGORITHM = 6,
PROPERMODE_SET_SURFACE_ID = 100,
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // FRAMEWORK_TYPES_H

View File

@ -0,0 +1,37 @@
/*
* 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 IAUTH_DRIVER_HDI_H
#define IAUTH_DRIVER_HDI_H
#include <cstdint>
#include "iauth_executor_hdi.h"
#include "iremote_broker.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class IAuthDriverHdi {
public:
IAuthDriverHdi() = default;
virtual ~IAuthDriverHdi() = default;
virtual void GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> &executorList) = 0;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // IAUTH_DRIVER_HDI_H

View File

@ -0,0 +1,54 @@
/*
* 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 IAUTH_EXECUTOR_HDI_H
#define IAUTH_EXECUTOR_HDI_H
#include <cstdint>
#include <vector>
#include "co_auth_defines.h"
#include "framework_types.h"
#include "iexecute_callback.h"
#include "iauth_executor_hdi.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class IAuthExecutorHdi {
public:
IAuthExecutorHdi() = default;
virtual ~IAuthExecutorHdi() = default;
virtual UserIAM::ResultCode GetExecutorInfo(ExecutorInfo &info) = 0;
virtual UserIAM::ResultCode GetTemplateInfo(uint64_t templateId, UserAuth::TemplateInfo &info) = 0;
virtual UserIAM::ResultCode OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) = 0;
virtual UserIAM::ResultCode Enroll(uint64_t scheduleId, uint64_t callerUid, const std::vector<uint8_t> &extraInfo,
const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) = 0;
virtual UserIAM::ResultCode Authenticate(uint64_t scheduleId, uint64_t callerUid,
const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &extraInfo,
const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) = 0;
virtual UserIAM::ResultCode Identify(uint64_t scheduleId, uint64_t callerUid, const std::vector<uint8_t> &extraInfo,
const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) = 0;
virtual UserIAM::ResultCode Delete(const std::vector<uint64_t> &templateIdList) = 0;
virtual UserIAM::ResultCode Cancel(uint64_t scheduleId) = 0;
virtual UserIAM::ResultCode SendCommand(UserAuth::AuthPropertyMode commandId, const std::vector<uint8_t> &extraInfo,
const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) = 0;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // IAUTH_EXECUTOR_HDI_H

View File

@ -0,0 +1,42 @@
/*
* 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 IDRIVER_MANAGER_H
#define IDRIVER_MANAGER_H
#include <cstdint>
#include <map>
#include "iauth_driver_hdi.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
struct HdiConfig {
uint16_t id; // non-zero
std::shared_ptr<IAuthDriverHdi> driver;
};
class IDriverManager {
public:
IDriverManager() = default;
virtual ~IDriverManager() = default;
static int32_t Start(const std::map<std::string, HdiConfig> &hdiName2Config);
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // IDRIVER_MANAGER_H

View File

@ -0,0 +1,39 @@
/*
* 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 IEXECUTE_CALLBACK_H
#define IEXECUTE_CALLBACK_H
#include <cstdint>
#include <vector>
#include "co_auth_defines.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class IExecuteCallback {
public:
IExecuteCallback() = default;
virtual ~IExecuteCallback() = default;
virtual void OnResult(ResultCode result, const std::vector<uint8_t> &extraInfo) = 0;
virtual void OnResult(ResultCode result) = 0;
virtual void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) = 0;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // EXECUTE_CALLBACK_H

View File

@ -0,0 +1,47 @@
/*
* 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 SYSTEM_ABILITY_STATUS_LISTENER
#define SYSTEM_ABILITY_STATUS_LISTENER
#include <mutex>
#include <set>
#include <string>
#include "nocopyable.h"
#include "refbase.h"
#include "system_ability_status_change_stub.h"
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
class SystemAbilityStatusListener : public OHOS::SystemAbilityStatusChangeStub, public NoCopyable {
public:
static sptr<SystemAbilityStatusListener> GetInstance();
virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
private:
SystemAbilityStatusListener() = default;
virtual ~SystemAbilityStatusListener() = default;
static sptr<SystemAbilityStatusListener> instance_;
static std::mutex mutex_;
};
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS
#endif // SYSTEM_ABILITY_STATUS_LISTENER

View File

@ -0,0 +1,96 @@
/*
* 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 "async_command_base.h"
#include <sstream>
#include <string>
#include <vector>
#include <mutex>
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_para2str.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
AsyncCommandBase::AsyncCommandBase(std::string type, uint64_t scheduleId, std::shared_ptr<Executor> executor)
: scheduleId_(scheduleId),
executor_(executor)
{
commandId_ = GenerateCommandId();
std::ostringstream ss;
ss << "Command(type:" << type << ", id:" << commandId_ << ", scheduleId:" << Common::GetMaskedString(scheduleId_)
<< ")";
str_ = ss.str();
}
void AsyncCommandBase::OnHdiDisconnect()
{
IAM_LOGE("driver disconnect, %{public}s end process", GetDescription());
// Need new result code: hal invalid
OnResult(ResultCode::GENERAL_ERROR);
}
ResultCode AsyncCommandBase::StartProcess()
{
IAM_LOGI("%{public}s start process", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
executor_->AddCommand(shared_from_this());
ResultCode ret = SendRequest();
if (ret != ResultCode::SUCCESS) {
IAM_LOGE("send request failed");
return ret;
}
return ResultCode::SUCCESS;
}
void AsyncCommandBase::OnResult(ResultCode result)
{
std::vector<uint8_t> extraInfo;
OnResult(result, extraInfo);
}
void AsyncCommandBase::OnResult(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
OnResultInner(result, extraInfo);
EndProcess();
}
void AsyncCommandBase::EndProcess()
{
IAM_LOGI("%{public}s end process", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
executor_->RemoveCommand(shared_from_this());
}
const char *AsyncCommandBase::GetDescription()
{
return str_.c_str();
}
int32_t AsyncCommandBase::GenerateCommandId()
{
static std::mutex mutex;
static uint32_t commandId = 0;
std::lock_guard<std::mutex> guard(mutex);
commandId++;
return commandId;
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,97 @@
/*
* 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 "auth_command.h"
#include "framework_types.h"
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_para2str.h"
#include "iam_ptr.h"
#include "pool.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
AuthCommand::AuthCommand(
std::shared_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("AUTH", scheduleId, executor),
attributes_(attributes)
{
}
ResultCode AuthCommand::SendRequest()
{
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
std::vector<uint64_t> tempalteIdList;
std::vector<uint8_t> extraInfo;
uint64_t templateId = 0;
attributes_->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
uint64_t callerUid;
attributes_->GetUint64Value(AUTH_CALLER_UID, callerUid);
tempalteIdList.push_back(templateId);
ResultCode ret = hdi->Authenticate(scheduleId_, callerUid, tempalteIdList, extraInfo, shared_from_this());
IAM_LOGI("%{public}s authenticate result %{public}d", GetDescription(), ret);
return ret;
}
void AuthCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on result start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
std::shared_ptr<AuthResPool::AuthAttributes> authAttributes = Common::MakeShared<AuthResPool::AuthAttributes>();
IF_FALSE_LOGE_AND_RETURN(authAttributes != nullptr);
authAttributes->SetUint32Value(AUTH_RESULT_CODE, result);
authAttributes->SetUint8ArrayValue(AUTH_RESULT, nonConstExtraInfo);
int32_t ret = executorMessenger->Finish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGI("%{public}s call fininsh fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call fininsh success result=%{public}d", GetDescription(), result);
}
void AuthCommand::OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on acquire info start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
std::shared_ptr<AuthResPool::AuthMessage> msg = Common::MakeShared<AuthResPool::AuthMessage>(nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(msg != nullptr);
int32_t ret = executorMessenger->SendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
transNum_++;
if (ret != USERAUTH_SUCCESS) {
IAM_LOGI("%{public}s call SendData fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call SendData success acquire=%{public}d", GetDescription(), acquire);
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,87 @@
/*
* 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 "custom_command.h"
#include <chrono>
#include "iam_check.h"
#include "iam_logger.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
CustomCommand::CustomCommand(
std::shared_ptr<Executor> executor, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("CUSTOM", 0, executor),
attributes_(attributes)
{
}
ResultCode CustomCommand::SendRequest()
{
static const size_t MAX_TEMPLATE_LIST_LEN = 1000;
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
future_ = promise_.get_future();
uint32_t commandId = 0;
attributes_->GetUint32Value(AUTH_PROPERTY_MODE, commandId);
std::vector<uint64_t> templateIdList;
attributes_->GetUint64ArrayValue(AUTH_TEMPLATE_ID_LIST, templateIdList);
IF_FALSE_LOGE_AND_RETURN_VAL(templateIdList.size() < MAX_TEMPLATE_LIST_LEN, ResultCode::GENERAL_ERROR);
const uint8_t *src = static_cast<const uint8_t *>(static_cast<const void *>(&templateIdList[0]));
std::vector<uint8_t> extraInfo(src, src + templateIdList.size() * sizeof(uint64_t) / sizeof(uint8_t));
ResultCode ret =
hdi->SendCommand(static_cast<UserAuth::AuthPropertyMode>(commandId), extraInfo, shared_from_this());
IAM_LOGI("%{public}s send command result %{public}d", GetDescription(), ret);
return ret;
}
void CustomCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on result start", GetDescription());
result_ = result;
promise_.set_value();
}
void CustomCommand::OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGE("%{public}s not support", GetDescription());
}
ResultCode CustomCommand::GetResult()
{
if (!future_.valid()) {
IAM_LOGE("%{public}s get result before request send, error", GetDescription());
return ResultCode::GENERAL_ERROR;
}
IAM_LOGI("%{public}s begin wait future", GetDescription());
const std::chrono::seconds maxWaitTime(1);
auto ret = future_.wait_for(maxWaitTime);
if (ret != std::future_status::ready) {
IAM_LOGE("%{public}s future timeout", GetDescription());
return ResultCode::TIMEOUT;
}
IAM_LOGI("%{public}s get result %{public}d", GetDescription(), result_);
return result_;
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,95 @@
/*
* 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 "enroll_command.h"
#include "framework_types.h"
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_mem.h"
#include "iam_para2str.h"
#include "iam_ptr.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
EnrollCommand::EnrollCommand(
std::shared_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("ENROLL", scheduleId, executor),
attributes_(attributes)
{
}
ResultCode EnrollCommand::SendRequest()
{
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
std::vector<uint8_t> extraInfo;
uint64_t templateId = 0;
attributes_->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
uint64_t callerUid;
attributes_->GetUint64Value(AUTH_CALLER_UID, callerUid);
Common::Pack(extraInfo, templateId);
ResultCode ret = hdi->Enroll(scheduleId_, callerUid, extraInfo, shared_from_this());
IAM_LOGI("%{public}s enroll result %{public}d", GetDescription(), ret);
return ret;
}
void EnrollCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on result start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
std::shared_ptr<AuthResPool::AuthAttributes> authAttributes = Common::MakeShared<AuthResPool::AuthAttributes>();
IF_FALSE_LOGE_AND_RETURN(authAttributes != nullptr);
authAttributes->SetUint32Value(AUTH_RESULT_CODE, result);
authAttributes->SetUint8ArrayValue(AUTH_RESULT, nonConstExtraInfo);
int32_t ret = executorMessenger->Finish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGI("%{public}s call fininsh fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call fininsh success result=%{public}d", GetDescription(), result);
}
void EnrollCommand::OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on acquire info start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
std::shared_ptr<AuthResPool::AuthMessage> msg = Common::MakeShared<AuthResPool::AuthMessage>(nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(msg != nullptr);
int32_t ret = executorMessenger->SendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
transNum_++;
if (ret != USERAUTH_SUCCESS) {
IAM_LOGI("%{public}s call SendData fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call SendData success acquire=%{public}d", GetDescription(), acquire);
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,95 @@
/*
* 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 "identify_command.h"
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_para2str.h"
#include "iam_ptr.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
IdentifyCommand::IdentifyCommand(
std::shared_ptr<Executor> executor, uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> attributes)
: AsyncCommandBase("IDENTIFY", scheduleId, executor),
attributes_(attributes)
{
}
ResultCode IdentifyCommand::SendRequest()
{
IAM_LOGI("%{public}s send request start", GetDescription());
IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
std::vector<uint64_t> tempalteIdList;
std::vector<uint8_t> extraInfo;
uint64_t templateId = 0;
attributes_->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
uint64_t callerUid;
attributes_->GetUint64Value(AUTH_CALLER_UID, callerUid);
tempalteIdList.push_back(templateId);
ResultCode ret = hdi->Identify(scheduleId_, callerUid, extraInfo, shared_from_this());
IAM_LOGI("%{public}s identify result %{public}d", GetDescription(), ret);
return ret;
}
void IdentifyCommand::OnResultInner(ResultCode result, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on result start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
std::shared_ptr<AuthResPool::AuthAttributes> authAttributes = Common::MakeShared<AuthResPool::AuthAttributes>();
IF_FALSE_LOGE_AND_RETURN(authAttributes != nullptr);
authAttributes->SetUint32Value(AUTH_RESULT_CODE, result);
authAttributes->SetUint8ArrayValue(AUTH_RESULT, nonConstExtraInfo);
int32_t ret = executorMessenger->Finish(scheduleId_, ALL_IN_ONE, result, authAttributes);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGI("%{public}s call fininsh fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call fininsh success result=%{public}d", GetDescription(), result);
}
void IdentifyCommand::OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo)
{
IAM_LOGI("%{public}s on acquire info start", GetDescription());
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto executorMessenger = executor_->GetExecutorMessenger();
IF_FALSE_LOGE_AND_RETURN(executorMessenger != nullptr);
std::vector<uint8_t> nonConstExtraInfo(extraInfo.begin(), extraInfo.end());
std::shared_ptr<AuthResPool::AuthMessage> msg = Common::MakeShared<AuthResPool::AuthMessage>(nonConstExtraInfo);
IF_FALSE_LOGE_AND_RETURN(msg != nullptr);
int32_t ret = executorMessenger->SendData(scheduleId_, transNum_, TYPE_ALL_IN_ONE, TYPE_CO_AUTH, msg);
transNum_++;
if (ret != USERAUTH_SUCCESS) {
IAM_LOGI("%{public}s call SendData fail", GetDescription());
return;
}
IAM_LOGI("%{public}s call SendData success acquire=%{public}d", GetDescription(), acquire);
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,77 @@
/*
* 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 "driver.h"
#include <mutex>
#include "iam_logger.h"
#include "iam_ptr.h"
#include "iauth_driver_hdi.h"
#include "iauth_executor_hdi.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
Driver::Driver(const std::string &serviceName, HdiConfig hdiConfig) : serviceName_(serviceName), hdiConfig_(hdiConfig)
{
}
void Driver::OnHdiConnect()
{
IAM_LOGI("start");
OnHdiDisconnect();
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::vector<std::shared_ptr<IAuthExecutorHdi>> executorHdiList;
hdiConfig_.driver->GetExecutorList(executorHdiList);
IAM_LOGI("executorHdiList length is %{public}zu", executorHdiList.size());
for (const auto &executorHdi : executorHdiList) {
auto executor = Common::MakeShared<Executor>(executorHdi, hdiConfig_.id);
if (executor == nullptr) {
IAM_LOGE("make_shared failed");
continue;
}
executorList_.push_back(executor);
executor->OnHdiConnect();
IAM_LOGI("add executor %{public}s success", executor->GetDescription());
}
IAM_LOGI("success");
}
void Driver::OnHdiDisconnect()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (const auto &executor : executorList_) {
// executor is non-null
executor->OnHdiDisconnect();
}
executorList_.clear();
IAM_LOGI("success");
}
void Driver::OnFrameworkReady()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (const auto &executor : executorList_) {
// executor is non-null
executor->OnFrameworkReady();
}
IAM_LOGI("success");
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,213 @@
/*
* 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 "driver_manager.h"
#include <set>
#include "devsvc_manager_stub.h"
#include "hdf_device_desc.h"
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_ptr.h"
#include "iservice_registry.h"
#include "iservmgr_hdi.h"
#include "parameter.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
const std::string GROUP_SCHEDULE = "GROUP_SCHEDULE";
const char IAM_EVENT_KEY[] = "bootevent.useriam.fwkready";
int32_t DriverManager::Start(const std::map<std::string, HdiConfig> &hdiName2Config)
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!HdiConfigIsValid(hdiName2Config)) {
IAM_LOGE("service config is not valid");
return USERAUTH_ERROR;
}
hdiName2Config_ = hdiName2Config;
serviceName2Driver_.clear();
for (auto const &pair : hdiName2Config) {
auto driver = Common::MakeShared<Driver>(pair.first, pair.second);
if (driver == nullptr) {
IAM_LOGE("make_shared for driver %{public}s failed", pair.first.c_str());
continue;
}
serviceName2Driver_[pair.first] = driver;
IAM_LOGI("add driver %{public}s", pair.first.c_str());
}
SubscribeHdiManagerServiceStatus();
SubscribeHdiDriverStatus();
SubscribeFrameworkRedayEvent();
OnAllHdiConnect();
IAM_LOGI("success");
return USERAUTH_SUCCESS;
}
bool DriverManager::HdiConfigIsValid(const std::map<std::string, HdiConfig> &hdiName2Config)
{
std::set<uint16_t> idSet;
for (auto const &pair : hdiName2Config) {
uint16_t id = pair.second.id;
if (idSet.count(id) != 0) {
IAM_LOGE("duplicate hdi id %{public}d", id);
return false;
}
idSet.insert(id);
}
return true;
}
void DriverManager::SubscribeHdiDriverStatus()
{
IAM_LOGI("start");
auto servMgr = IServiceManager::Get();
if (servMgr == nullptr) {
IAM_LOGE("failed to get IServiceManager");
return;
}
int32_t ret = servMgr->RegisterServiceStatusListener(this, DEVICE_CLASS_USERAUTH);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("failed to register service status listener");
return;
}
IAM_LOGI("success");
}
bool DriverManager::HdiDriverIsRunning(const std::string &serviceName)
{
auto servMgr = IServiceManager::Get();
if (servMgr == nullptr) {
IAM_LOGE("failed to get IServiceManager");
return false;
}
auto service = servMgr->GetService(serviceName.c_str());
if (service == nullptr) {
IAM_LOGE("hdi driver is not running");
return false;
}
IAM_LOGI("hdi driver is running");
return true;
}
void DriverManager::OnReceive(const ServiceStatus &status)
{
IAM_LOGI("service %{public}s receive status", status.serviceName.c_str());
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (serviceName2Driver_.count(status.serviceName) == 0) {
IAM_LOGI("service name not match");
return;
}
switch (status.status) {
case SERVIE_STATUS_START:
IAM_LOGI("service %{public}s status change to start", status.serviceName.c_str());
if (!HdiDriverIsRunning(status.serviceName)) {
IAM_LOGE("service %{public}s is not running, ignore this message", status.serviceName.c_str());
break;
}
serviceName2Driver_[status.serviceName]->OnHdiConnect();
break;
case SERVIE_STATUS_STOP:
IAM_LOGI("service %{public}s status change to stop", status.serviceName.c_str());
if (HdiDriverIsRunning(status.serviceName)) {
IAM_LOGE("service %{public}s is running, ignore this message", status.serviceName.c_str());
break;
}
serviceName2Driver_[status.serviceName]->OnHdiDisconnect();
break;
default:
IAM_LOGE("service %{public}s status invalid", status.serviceName.c_str());
}
}
void DriverManager::SubscribeHdiManagerServiceStatus()
{
IAM_LOGI("start");
auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sam == nullptr) {
IAM_LOGE("failed to get SA manager");
return;
}
auto listener = SystemAbilityStatusListener::GetInstance();
IF_FALSE_LOGE_AND_RETURN(listener != nullptr);
int32_t ret = sam->SubscribeSystemAbility(DEVICE_SERVICE_MANAGER_SA_ID, listener);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("failed to subscribe status");
return;
}
IAM_LOGI("success");
}
void DriverManager::SubscribeFrameworkRedayEvent()
{
auto eventCallback = [](const char *key, const char *value, void *context) {
IAM_LOGI("receive useriam.fwkready event");
IF_FALSE_LOGE_AND_RETURN(key != nullptr);
IF_FALSE_LOGE_AND_RETURN(value != nullptr);
if (strcmp(key, IAM_EVENT_KEY) != 0) {
IAM_LOGE("event key mismatch");
return;
}
if (strcmp(value, "true")) {
IAM_LOGI("event value is not true");
return;
}
DriverManager::GetInstance().OnFrameworkReady();
};
int32_t ret = WatchParameter(IAM_EVENT_KEY, eventCallback, nullptr);
if (ret != USERAUTH_SUCCESS) {
IAM_LOGE("WatchParameter fail");
return;
}
IAM_LOGI("success");
}
void DriverManager::OnAllHdiDisconnect()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto const &pair : serviceName2Driver_) {
pair.second->OnHdiDisconnect();
}
IAM_LOGI("success");
}
void DriverManager::OnAllHdiConnect()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto const &pair : serviceName2Driver_) {
pair.second->OnHdiConnect();
}
IAM_LOGI("success");
}
void DriverManager::OnFrameworkReady()
{
IAM_LOGI("start");
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto const &pair : serviceName2Driver_) {
pair.second->OnFrameworkReady();
}
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,148 @@
/*
* 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 "executor.h"
#include <sstream>
#include "co_auth_defines.h"
#include "executor_mgr.h"
#include "framework_executor_callback.h"
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_mem.h"
#include "iam_para2str.h"
#include "iam_ptr.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
const int32_t INVALID_EXECUTOR_ID = -1;
Executor::Executor(std::shared_ptr<IAuthExecutorHdi> executorHdi, uint16_t hdiId)
: executorHdi_(executorHdi),
hdiId_(hdiId)
{
SetStr(INVALID_EXECUTOR_ID);
}
void Executor::OnHdiConnect()
{
IAM_LOGI("%{public}s start", GetDescription());
// register resource pool depends on hdi start, after hid connect re-register resource pool
OnFrameworkReady();
}
void Executor::OnHdiDisconnect()
{
IAM_LOGI("%{public}s start", GetDescription());
executorHdi_ = nullptr;
}
void Executor::OnFrameworkReady()
{
IAM_LOGI("%{public}s start", GetDescription());
ExecutorInfo executorInfo = {};
auto hdi = executorHdi_;
if (hdi == nullptr) {
IAM_LOGI("executorHdi_ is disconnected, skip framework ready process");
return;
}
ResultCode ret = hdi->GetExecutorInfo(executorInfo);
if (ret != ResultCode::SUCCESS) {
IAM_LOGE("Get executor info failed");
return;
}
SetStr(executorInfo.executorId);
RegisterExecutorCallback(executorInfo);
}
void Executor::RegisterExecutorCallback(ExecutorInfo &executorInfo)
{
IAM_LOGI("%{public}s start", GetDescription());
executorInfo.executorId = Common::CombineShortToInt(hdiId_, executorInfo.executorId);
auto executorCallback = Common::MakeShared<FrameworkExecutorCallback>(shared_from_this());
IF_FALSE_LOGE_AND_RETURN(executorCallback != nullptr);
UserIAM::AuthResPool::ExecutorMgr::GetInstance().Register(executorInfo, executorCallback);
IAM_LOGI("register executor callback ok, executor id=%{public}s",
Common::GetMaskedString(executorInfo.executorId).c_str());
}
void Executor::SetExecutorMessenger(const sptr<AuthResPool::IExecutorMessenger> &messenger)
{
IAM_LOGI("%{public}s start", GetDescription());
executorMessenger_ = messenger;
return;
}
sptr<AuthResPool::IExecutorMessenger> Executor::GetExecutorMessenger()
{
IAM_LOGI("%{public}s start", GetDescription());
return executorMessenger_;
}
void Executor::AddCommand(std::shared_ptr<IAsyncCommand> command)
{
IAM_LOGI("%{public}s start", GetDescription());
std::lock_guard<std::recursive_mutex> lock(mutex_);
IF_FALSE_LOGE_AND_RETURN(command != nullptr);
command2Respond_.insert(command);
}
void Executor::RemoveCommand(std::shared_ptr<IAsyncCommand> command)
{
IAM_LOGI("%{public}s start", GetDescription());
std::lock_guard<std::recursive_mutex> lock(mutex_);
command2Respond_.erase(command);
}
void Executor::RespondCallbackOnDisconnect()
{
IAM_LOGI("%{public}s start", GetDescription());
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (auto it = command2Respond_.begin(); it != command2Respond_.end();) {
auto cmdToProc = it;
it++;
(*cmdToProc)->OnHdiDisconnect();
}
command2Respond_.clear();
IAM_LOGI("success");
}
std::shared_ptr<IAuthExecutorHdi> Executor::GetExecutorHdi()
{
return executorHdi_;
}
const char *Executor::GetDescription()
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
return str_.c_str();
}
void Executor::SetStr(const int32_t executorId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::ostringstream ss;
if (executorId == INVALID_EXECUTOR_ID) {
ss << "Executor(hdiId:" << hdiId_ << ", executorId: not set)";
} else {
ss << "Executor(hdiId:" << hdiId_ << ", executorId:" << executorId << ")";
}
str_ = ss.str();
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,237 @@
/*
* 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 "framework_executor_callback.h"
#include "auth_command.h"
#include "custom_command.h"
#include "enroll_command.h"
#include "iam_check.h"
#include "iam_logger.h"
#include "iam_mem.h"
#include "iam_ptr.h"
#include "identify_command.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
FrameworkExecutorCallback::FrameworkExecutorCallback(std::shared_ptr<Executor> executor) : executor_(executor)
{
}
int32_t FrameworkExecutorCallback::OnBeginExecute(
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs)
{
return OnBeginExecuteInner(scheduleId, publicKey, commandAttrs);
}
ResultCode FrameworkExecutorCallback::OnBeginExecuteInner(
uint64_t scheduleId, std::vector<uint8_t> &publicKey, std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs)
{
static_cast<void>(publicKey);
IF_FALSE_LOGE_AND_RETURN_VAL(commandAttrs != nullptr, ResultCode::GENERAL_ERROR);
uint32_t commandId = 0;
IF_FALSE_LOGE_AND_RETURN_VAL(
commandAttrs->GetUint32Value(AUTH_SCHEDULE_MODE, commandId) == USERAUTH_SUCCESS, ResultCode::GENERAL_ERROR);
IAM_LOGI("start process cmd %{public}u", commandId);
ResultCode ret = ResultCode::GENERAL_ERROR;
switch (commandId) {
case SCHEDULE_MODE_ENROLL:
ret = ProcessEnrollCommand(scheduleId, commandAttrs);
break;
case SCHEDULE_MODE_AUTH:
ret = ProcessAuthCommand(scheduleId, commandAttrs);
break;
default:
IAM_LOGE("command id %{public}u is not supported", commandId);
}
IAM_LOGI("command id = %{public}u ret = %{public}d", commandId, ret);
return ret;
}
int32_t FrameworkExecutorCallback::OnEndExecute(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr)
{
return OnEndExecuteInner(scheduleId, consumerAttr);
}
ResultCode FrameworkExecutorCallback::OnEndExecuteInner(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr)
{
IF_FALSE_LOGE_AND_RETURN_VAL(consumerAttr != nullptr, ResultCode::GENERAL_ERROR);
uint32_t commandId = 0;
IF_FALSE_LOGE_AND_RETURN_VAL(
consumerAttr->GetUint32Value(AUTH_SCHEDULE_MODE, commandId) == USERAUTH_SUCCESS, ResultCode::GENERAL_ERROR);
IAM_LOGI("start process cmd %{public}u", commandId);
ResultCode ret = ResultCode::GENERAL_ERROR;
switch (commandId) {
case SCHEDULE_MODE_AUTH:
__attribute__((fallthrough));
case SCHEDULE_MODE_ENROLL:
ret = ProcessCancelCommand(scheduleId);
break;
default:
IAM_LOGE("Command id %{public}u is not supported", commandId);
break;
}
IAM_LOGI("command id = %{public}u ret = %{public}d", commandId, ret);
return ret;
}
void FrameworkExecutorCallback::OnMessengerReady(const sptr<AuthResPool::IExecutorMessenger> &messenger,
std::vector<uint8_t> &publicKey, std::vector<uint64_t> &templateIds)
{
IAM_LOGI("start");
IF_FALSE_LOGE_AND_RETURN(executor_ != nullptr);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN(hdi != nullptr);
executor_->SetExecutorMessenger(messenger);
std::vector<uint8_t> extraInfo;
hdi->OnRegisterFinish(templateIds, publicKey, extraInfo);
}
int32_t FrameworkExecutorCallback::OnSetProperty(std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
return OnSetPropertyInner(properties);
}
ResultCode FrameworkExecutorCallback::OnSetPropertyInner(std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
IF_FALSE_LOGE_AND_RETURN_VAL(properties != nullptr, ResultCode::GENERAL_ERROR);
uint32_t commandId = 0;
IF_FALSE_LOGE_AND_RETURN_VAL(
properties->GetUint32Value(AUTH_PROPERTY_MODE, commandId) == USERAUTH_SUCCESS, ResultCode::GENERAL_ERROR);
IAM_LOGI("start process cmd %{public}u", commandId);
ResultCode ret = ResultCode::GENERAL_ERROR;
if (commandId == PROPERMODE_DELETE) {
ret = ProcessDeleteTemplateCommand(properties);
} else {
ret = ProcessCustomCommand(properties);
}
IAM_LOGI("command id = %{public}u ret = %{public}d", commandId, ret);
return ret;
}
int32_t FrameworkExecutorCallback::OnGetProperty(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values)
{
return OnGetPropertyInner(conditions, values);
}
ResultCode FrameworkExecutorCallback::OnGetPropertyInner(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values)
{
IAM_LOGI("start");
IF_FALSE_LOGE_AND_RETURN_VAL(conditions != nullptr, ResultCode::GENERAL_ERROR);
uint32_t commandId = 0;
IF_FALSE_LOGE_AND_RETURN_VAL(
conditions->GetUint32Value(AUTH_PROPERTY_MODE, commandId) == USERAUTH_SUCCESS, ResultCode::GENERAL_ERROR);
if (commandId != PROPERMODE_GET) {
IAM_LOGI("command id not recognised");
return ResultCode::GENERAL_ERROR;
}
ResultCode ret = ProcessGetTemplateCommand(conditions, values);
IAM_LOGI("command id = %{public}u ret = %{public}d", commandId, ret);
return ret;
}
ResultCode FrameworkExecutorCallback::ProcessEnrollCommand(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
auto command = Common::MakeShared<EnrollCommand>(executor_, scheduleId, properties);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
return command->StartProcess();
}
ResultCode FrameworkExecutorCallback::ProcessAuthCommand(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
auto command = Common::MakeShared<AuthCommand>(executor_, scheduleId, properties);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
return command->StartProcess();
}
ResultCode FrameworkExecutorCallback::ProcessIdentifyCommand(
uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
auto command = Common::MakeShared<IdentifyCommand>(executor_, scheduleId, properties);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
return command->StartProcess();
}
ResultCode FrameworkExecutorCallback::ProcessCancelCommand(uint64_t scheduleId)
{
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
hdi->Cancel(scheduleId);
return ResultCode::SUCCESS;
}
ResultCode FrameworkExecutorCallback::ProcessDeleteTemplateCommand(
std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
IAM_LOGI("start");
IF_FALSE_LOGE_AND_RETURN_VAL(properties != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
uint64_t templateId = 0;
properties->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
std::vector<uint64_t> tempalteIdList;
tempalteIdList.push_back(templateId);
hdi->Delete(tempalteIdList);
return ResultCode::SUCCESS;
}
ResultCode FrameworkExecutorCallback::ProcessCustomCommand(std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
auto command = Common::MakeShared<CustomCommand>(executor_, properties);
IF_FALSE_LOGE_AND_RETURN_VAL(command != nullptr, ResultCode::GENERAL_ERROR);
ResultCode ret = command->StartProcess();
if (ret != ResultCode::SUCCESS) {
IAM_LOGI("start process command fail ret = %{public}d", ret);
return ret;
}
ret = command->GetResult();
return ret;
}
ResultCode FrameworkExecutorCallback::ProcessGetTemplateCommand(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values)
{
IAM_LOGI("start");
IF_FALSE_LOGE_AND_RETURN_VAL(conditions != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(values != nullptr, ResultCode::GENERAL_ERROR);
IF_FALSE_LOGE_AND_RETURN_VAL(executor_ != nullptr, ResultCode::GENERAL_ERROR);
auto hdi = executor_->GetExecutorHdi();
IF_FALSE_LOGE_AND_RETURN_VAL(hdi != nullptr, ResultCode::GENERAL_ERROR);
uint64_t templateId = 0;
conditions->GetUint64Value(AUTH_TEMPLATE_ID, templateId);
TemplateInfo templateInfo = {};
hdi->GetTemplateInfo(templateId, templateInfo);
uint64_t subType = 0;
Common::UnpackUint64(templateInfo.extraInfo, 0, subType);
values->SetUint64Value(AUTH_SUBTYPE, subType);
values->SetUint32Value(AUTH_REMAIN_TIME, templateInfo.freezingTime);
values->SetUint32Value(AUTH_REMAIN_COUNT, templateInfo.remainTimes);
return ResultCode::SUCCESS;
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,31 @@
/*
* 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 "idriver_manager.h"
#include "driver_manager.h"
#include "iam_logger.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
int32_t IDriverManager::Start(const std::map<std::string, HdiConfig> &hdiName2Config)
{
return Singleton<UserAuth::DriverManager>::GetInstance().Start(hdiName2Config);
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -0,0 +1,64 @@
/*
* 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 "system_ability_status_listener.h"
#include "driver_manager.h"
#include "iam_logger.h"
#include "system_ability_definition.h"
#define LOG_LABEL Common::LABEL_USER_AUTH_EXECUTOR
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
std::mutex SystemAbilityStatusListener::mutex_;
sptr<SystemAbilityStatusListener> SystemAbilityStatusListener::instance_ = nullptr;
sptr<SystemAbilityStatusListener> SystemAbilityStatusListener::GetInstance()
{
if (instance_ == nullptr) {
std::lock_guard<std::mutex> gurard(mutex_);
if (instance_ == nullptr) {
instance_ = new (std::nothrow) SystemAbilityStatusListener();
if (instance_ == nullptr) {
IAM_LOGE("create instance failed");
}
}
}
return instance_;
}
void SystemAbilityStatusListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
{
if (systemAbilityId != DEVICE_SERVICE_MANAGER_SA_ID) {
return;
}
IAM_LOGI("device service manager SA added");
Singleton<DriverManager>::GetInstance().SubscribeHdiDriverStatus();
}
void SystemAbilityStatusListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
{
if (systemAbilityId != DEVICE_SERVICE_MANAGER_SA_ID) {
return;
}
IAM_LOGI("device service manager SA removed");
// when hdi device manager die, hdi driver status is not reliable, disconnect all
Singleton<DriverManager>::GetInstance().OnAllHdiDisconnect();
}
} // namespace UserAuth
} // namespace UserIAM
} // namespace OHOS

View File

@ -19,8 +19,8 @@
#include "hilog/log.h"
namespace OHOS {
namespace UserIAM {
#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define FORMATTED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__
#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define FORMATTED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__
#ifdef COAUTH_HILOGF
#undef COAUTH_HILOGF

View File

@ -46,6 +46,8 @@ static constexpr unsigned int IAM_DOMAIN_ID_USER = 0xD002421;
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_USER_AUTH_NAPI = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_NAPI"};
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_USER_AUTH_SDK = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_SDK"};
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_USER_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_SA"};
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL_USER_AUTH_EXECUTOR = {
LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_EXECUTOR"};
// pin
static constexpr unsigned int IAM_DOMAIN_ID_PIN = 0xD002432;

View File

@ -20,8 +20,8 @@
namespace OHOS {
namespace UserIAM {
namespace UserAuth {
#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define FORMATED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__
#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define FORMATED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__
#ifdef USERAUTH_HILOGF
#undef USERAUTH_HILOGF

View File

@ -21,8 +21,8 @@
namespace OHOS {
namespace UserIAM {
namespace UserIDM {
#define filename__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define formated__(fmt, ...) "[%{public}s] %{public}s# " fmt, filename__, __FUNCTION__, ##__VA_ARGS__
#define filename__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define formated__(fmt, ...) "[%{public}s] %{public}s# " fmt, filename__, __FUNCTION__, ##__VA_ARGS__
#ifdef USERIDM_HILOGF
#undef USERIDM_HILOGF

View File

@ -214,8 +214,8 @@ bool ThreadGroups::ThreadGroup::PostTask(uint64_t transaction, const Task &task)
return true;
}
void ThreadGroups::ThreadGroup::EnsureTransaction(const ThreadPoolPtr &poolPtr, uint64_t transaction,
const std::string &name)
void ThreadGroups::ThreadGroup::EnsureTransaction(
const ThreadPoolPtr &poolPtr, uint64_t transaction, const std::string &name)
{
auto task = [transaction, name]() {
std::stringstream sstream;

View File

@ -47,12 +47,12 @@ public:
bool PostTask(const std::string &name, uint64_t transaction, const Task &task);
template <typename T, typename... Args, typename = std::enable_if_t<std::is_function_v<T> && !std::is_class_v<T>>>
bool PostTask(const std::string &name, uint64_t transaction, const T &task, Args &&...args)
bool PostTask(const std::string &name, uint64_t transaction, const T &task, Args &&... args)
{
static_assert(std::is_invocable<typename std::decay<T>::type, typename std::decay<Args>::type...>::value,
"arguments cannot invocable");
auto invoker = [task, tuple = std::make_tuple(std::forward<Args>(args)...)]() mutable {
std::apply([task](auto &&...args) { std::invoke(task, std::forward<Args>(args)...); }, tuple);
std::apply([task](auto &&... args) { std::invoke(task, std::forward<Args>(args)...); }, tuple);
};
return PostTask(name, transaction, invoker);
}

44
common/utils/iam_check.h Normal file
View File

@ -0,0 +1,44 @@
/*
* 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 IAM_CHECK_H
#define IAM_CHECK_H
#include "iam_logger.h"
namespace OHOS {
namespace UserIAM {
namespace Common {
// these macros are used to check condition that should never fail
#define IF_FALSE_LOGE_AND_RETURN(cond) \
do { \
if (!(cond)) { \
IAM_LOGE("(" #cond ") check fail, return"); \
return; \
} \
} while (0)
#define IF_FALSE_LOGE_AND_RETURN_VAL(cond, retVal) \
do { \
if (!(cond)) { \
IAM_LOGE("(" #cond ") check fail, return"); \
return (retVal); \
} \
} while (0)
} // namespace Common
} // namespace UserIAM
} // namespace OHOS
#endif // IAM_CHECK_H

37
common/utils/iam_mem.cpp Normal file
View File

@ -0,0 +1,37 @@
/*
* 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 "iam_mem.h"
#include "securec.h"
#define LOG_LABEL LABEL_IAM_COMMON
namespace OHOS {
namespace UserIAM {
namespace Common {
int32_t UnpackUint64(const std::vector<uint8_t> &src, size_t index, uint64_t &data)
{
if ((src.size() < index) || (src.size() - index < sizeof(uint64_t))) {
return 1;
}
if (memcpy_s(static_cast<void *>(&data), sizeof(uint64_t), &src[index], sizeof(uint64_t)) != 0) {
return 1;
}
return 0;
}
} // namespace Common
} // namespace UserIAM
} // namespace OHOS

42
common/utils/iam_mem.h Normal file
View File

@ -0,0 +1,42 @@
/*
* 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 IAM_MEM_H
#define IAM_MEM_H
#include <cstdint>
#include <vector>
namespace OHOS {
namespace UserIAM {
namespace Common {
template <typename T>
inline void Pack(std::vector<uint8_t> &dst, const T &data)
{
const uint8_t *src = static_cast<const uint8_t *>(static_cast<const void *>(&data));
dst.insert(dst.end(), src, src + sizeof(T));
}
int32_t UnpackUint64(const std::vector<uint8_t> &src, size_t index, uint64_t &data);
inline int32_t CombineShortToInt(int16_t upper, int16_t lower)
{
return (static_cast<int32_t>(upper) << 16) | lower;
}
} // namespace Common
} // namespace UserIAM
} // namespace OHOS
#endif // IAM_MEM_H

View File

@ -0,0 +1,49 @@
/*
* 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 IAM_PARA2STR_H
#define IAM_PARA2STR_H
#include <cinttypes>
#include <cstdint>
#include <string>
namespace OHOS {
namespace UserIAM {
namespace Common {
using namespace std;
const uint64_t UINT64_MASK = 0xffff;
const size_t MASKED_STRING_LEN = 11;
static inline std::string GetMaskedString(uint64_t val)
{
char bytes[MASKED_STRING_LEN] = {0};
if (std::snprintf(bytes, sizeof(bytes), "0xXXXX%04" PRIx64, val & UINT64_MASK) == 0) {
return "(snprintf fail)";
}
return std::string(bytes);
}
static inline std::string GetPointerNullStateString(void *p)
{
if (p == nullptr) {
return "null";
}
return "non-null";
}
} // namespace Common
} // namespace UserIAM
} // namespace OHOS
#endif // IAM_PARA2STR_H

View File

@ -30,7 +30,7 @@ static inline std::shared_ptr<T> SptrToStdSharedPtr(sptr<T> &other)
}
template <typename T, typename... Args>
static inline std::shared_ptr<T> MakeShared(Args &&...args)
static inline std::shared_ptr<T> MakeShared(Args &&... args)
{
try {
return std::make_shared<T>(std::forward<Args>(args)...);
@ -40,7 +40,7 @@ static inline std::shared_ptr<T> MakeShared(Args &&...args)
}
template <typename T, typename... Args>
static inline std::unique_ptr<T> MakeUnique(Args &&...args)
static inline std::unique_ptr<T> MakeUnique(Args &&... args)
{
try {
return std::make_unique<T>(std::forward<Args>(args)...);