fix coding issue; get template onRegisterFinish

Signed-off-by: Tianshi Liu <tianshi.liu@huawei.com>
Change-Id: I9672b23d4765122983190b1e5887d7cd7c537dc6
This commit is contained in:
Tianshi Liu
2022-05-24 14:19:44 +08:00
parent c8f0bae072
commit fced1270dd
16 changed files with 151 additions and 49 deletions
+19
View File
@@ -64,3 +64,22 @@ ohos_source_set("iam_utils") {
part_name = "user_auth"
}
config("iam_test_config") {
include_dirs = [ "test" ]
}
ohos_source_set("iam_test") {
testonly = true
include_dirs = [ "//base/user_iam/user_auth/common/logs" ]
external_deps = [
"hilog_native:libhilog",
"utils_base:utils",
]
public_configs = [ ":iam_test_config" ]
sources = [ "test/iam_fuzz_test.cpp" ]
part_name = "user_auth"
}
@@ -32,13 +32,13 @@ class AsyncCommandBase : public std::enable_shared_from_this<AsyncCommandBase>,
public NoCopyable {
public:
AsyncCommandBase(std::string type, uint64_t scheduleId, std::shared_ptr<Executor> executor);
virtual ~AsyncCommandBase() = default;
~AsyncCommandBase() override = 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;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override = 0;
protected:
static uint32_t GenerateCommandId();
@@ -51,7 +51,7 @@ protected:
private:
void EndProcess();
std::string str_;
std::string description_;
};
} // namespace UserAuth
} // namespace UserIAM
@@ -25,7 +25,7 @@ class AuthCommand : public AsyncCommandBase {
public:
AuthCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
virtual ~AuthCommand() = default;
~AuthCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
@@ -26,7 +26,7 @@ namespace UserAuth {
class CustomCommand : public AsyncCommandBase {
public:
CustomCommand(std::shared_ptr<Executor> executor, std::shared_ptr<AuthResPool::AuthAttributes> attributes);
virtual ~CustomCommand() = default;
~CustomCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
@@ -25,7 +25,7 @@ class EnrollCommand : public AsyncCommandBase {
public:
EnrollCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
virtual ~EnrollCommand() = default;
~EnrollCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
@@ -25,7 +25,7 @@ class IdentifyCommand : public AsyncCommandBase {
public:
IdentifyCommand(std::shared_ptr<Executor> executor, uint64_t scheduleId,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
virtual ~IdentifyCommand() = default;
~IdentifyCommand() override = default;
void OnAcquireInfo(int32_t acquire, const std::vector<uint8_t> &extraInfo) override;
+1 -1
View File
@@ -30,7 +30,7 @@ namespace UserAuth {
class Driver : public NoCopyable {
public:
Driver(const std::string &serviceName, HdiConfig hdiConfig);
virtual ~Driver() = default;
~Driver() override = default;
void OnHdiConnect();
void OnHdiDisconnect();
+2 -3
View File
@@ -34,7 +34,7 @@ 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;
~Executor() override = default;
void OnHdiConnect();
void OnHdiDisconnect();
@@ -49,12 +49,11 @@ public:
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_;
std::string description_;
uint16_t hdiId_;
};
} // namespace UserAuth
@@ -33,32 +33,34 @@ enum ScheduleMode {
SCHEDULE_MODE_ENROLL = 0,
SCHEDULE_MODE_AUTH = 1,
};
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;
~FrameworkExecutorCallback() override = 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;
int32_t OnBeginExecute(uint64_t scheduleId, std::vector<uint8_t> &publicKey,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs) override;
int32_t OnEndExecute(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr) override;
int32_t OnSetProperty(std::shared_ptr<AuthResPool::AuthAttributes> 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 OnBeginExecuteInner(uint64_t scheduleId, std::vector<uint8_t> &publicKey,
std::shared_ptr<AuthResPool::AuthAttributes> commandAttrs);
ResultCode OnEndExecuteInner(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> consumerAttr);
ResultCode OnSetPropertyInner(std::shared_ptr<AuthResPool::AuthAttributes> 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 ProcessEnrollCommand(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessAuthCommand(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessIdentifyCommand(uint64_t scheduleId, std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessCancelCommand(uint64_t scheduleId);
ResultCode ProcessDeleteTemplateCommand(pAuthAttributes properties);
ResultCode ProcessCustomCommand(pAuthAttributes properties);
ResultCode ProcessDeleteTemplateCommand(std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessCustomCommand(std::shared_ptr<AuthResPool::AuthAttributes> properties);
ResultCode ProcessGetTemplateCommand(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values);
@@ -32,12 +32,12 @@ class SystemAbilityStatusListener : public OHOS::SystemAbilityStatusChangeStub,
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;
void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
private:
SystemAbilityStatusListener() = default;
virtual ~SystemAbilityStatusListener() = default;
~SystemAbilityStatusListener() override = default;
static sptr<SystemAbilityStatusListener> instance_;
static std::mutex mutex_;
@@ -36,7 +36,7 @@ AsyncCommandBase::AsyncCommandBase(std::string type, uint64_t scheduleId, std::s
{
std::ostringstream ss;
ss << "Command(type:" << type << ", id:" << commandId_ << ", scheduleId:" << GET_MASKED_STRING(scheduleId_) << ")";
str_ = ss.str();
description_ = ss.str();
}
void AsyncCommandBase::OnHdiDisconnect()
@@ -82,7 +82,7 @@ void AsyncCommandBase::EndProcess()
const char *AsyncCommandBase::GetDescription()
{
return str_.c_str();
return description_.c_str();
}
uint32_t AsyncCommandBase::GenerateCommandId()
+8 -18
View File
@@ -31,13 +31,17 @@
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);
auto hdi = executorHdi_;
IF_FALSE_LOGE_AND_RETURN(hdi != nullptr);
ExecutorInfo executorInfo = {};
IF_FALSE_LOGE_AND_RETURN(hdi->GetExecutorInfo(executorInfo) == ResultCode::SUCCESS);
std::ostringstream ss;
ss << "Executor(hdiId:" << hdiId_ << ", executorId:" << executorInfo.executorId << ")";
description_ = ss.str();
}
void Executor::OnHdiConnect()
@@ -67,7 +71,6 @@ void Executor::OnFrameworkReady()
IAM_LOGE("Get executor info failed");
return;
}
SetStr(executorInfo.executorId);
RegisterExecutorCallback(executorInfo);
}
@@ -135,20 +138,7 @@ std::shared_ptr<IAuthExecutorHdi> Executor::GetExecutorHdi()
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();
return description_.c_str();
}
} // namespace UserAuth
} // namespace UserIAM
@@ -14,6 +14,7 @@
*/
#include "framework_executor_callback.h"
#include "auth_command.h"
#include "custom_command.h"
#include "enroll_command.h"
@@ -111,6 +112,7 @@ int32_t FrameworkExecutorCallback::OnSetProperty(std::shared_ptr<AuthResPool::Au
{
return OnSetPropertyInner(properties);
}
ResultCode FrameworkExecutorCallback::OnSetPropertyInner(std::shared_ptr<AuthResPool::AuthAttributes> properties)
{
IF_FALSE_LOGE_AND_RETURN_VAL(properties != nullptr, ResultCode::GENERAL_ERROR);
@@ -133,6 +135,7 @@ int32_t FrameworkExecutorCallback::OnGetProperty(
{
return OnGetPropertyInner(conditions, values);
}
ResultCode FrameworkExecutorCallback::OnGetPropertyInner(
std::shared_ptr<AuthResPool::AuthAttributes> conditions, std::shared_ptr<AuthResPool::AuthAttributes> values)
{
+58
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.
*/
#include "iam_fuzz_test.h"
#include "iam_logger.h"
#include "securec.h"
#define LOG_LABEL OHOS::UserIAM::Common::LABEL_IAM_COMMON
namespace OHOS {
namespace UserIAM {
namespace Common {
namespace {
constexpr int32_t MAX_DATA_LEN = 200;
}
void FillFuzzUint8Vector(Parcel &parcel, std::vector<uint8_t> &data)
{
uint32_t len = parcel.ReadUint32() % MAX_DATA_LEN;
auto buffer = parcel.ReadBuffer(len);
if (buffer == nullptr) {
IAM_LOGE("ReadBuffer len %{public}u fail", len);
return;
}
data.resize(len);
memcpy_s(static_cast<void *>(&data[0]), len, buffer, len);
IAM_LOGI("fill buffer len %{public}u ok", len);
}
void FillFuzzUint64Vector(Parcel &parcel, std::vector<uint64_t> &data)
{
uint32_t len = parcel.ReadUint32() % MAX_DATA_LEN;
uint32_t memLen = len * sizeof(uint64_t);
auto buffer = parcel.ReadBuffer(memLen);
if (buffer == nullptr) {
IAM_LOGE("ReadBuffer len %{public}u fail", memLen);
return;
}
data.resize(len);
memcpy_s(static_cast<void *>(&data[0]), memLen, buffer, memLen);
IAM_LOGI("fill buffer len %{public}u ok", len);
}
} // namespace Common
} // namespace UserIAM
} // namespace OHOS
+32
View File
@@ -0,0 +1,32 @@
/*
* 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_FUZZ_TEST_H
#define IAM_FUZZ_TEST_H
#include <vector>
#include "parcel.h"
namespace OHOS {
namespace UserIAM {
namespace Common {
void FillFuzzUint8Vector(Parcel &parcel, std::vector<uint8_t> &data);
void FillFuzzUint64Vector(Parcel &parcel, std::vector<uint64_t> &data);
} // namespace Common
} // namespace UserIAM
} // namespace OHOS
#endif // IAM_FUZZ_TEST_H
+1 -2
View File
@@ -35,8 +35,7 @@ static inline std::string GetMaskedString(uint16_t val)
return ss.str();
}
#define GET_MASKED_STRING(val) \
OHOS::UserIAM::Common::GetMaskedString(static_cast<uint16_t>(val))
#define GET_MASKED_STRING(val) OHOS::UserIAM::Common::GetMaskedString(static_cast<uint16_t>(val))
static inline std::string GetPointerNullStateString(void *p)
{