mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-11-23 07:39:51 +00:00
!688 add callerName and CheckForegroundApplication
Merge pull request !688 from liuziwei/master
This commit is contained in:
commit
9c8ee5d1c9
@ -22,6 +22,8 @@ namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
const int32_t INVALID_AUTH_TYPE = -1;
|
||||
const int32_t INNER_API_VERSION_10000 = 10000;
|
||||
|
||||
#define IAM_TRY(action0, action1) \
|
||||
do { \
|
||||
try { \
|
||||
|
@ -9,7 +9,8 @@
|
||||
"ohos.permission.ACCESS_AUTH_RESPOOL",
|
||||
"ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION",
|
||||
"ohos.permission.MANAGE_LOCAL_ACCOUNTS",
|
||||
"ohos.permission.VIBRATE"
|
||||
"ohos.permission.VIBRATE",
|
||||
"ohos.permission.GET_RUNNING_INFO"
|
||||
],
|
||||
"permission_acls" : [
|
||||
"ohos.permission.ACCESS_AUTH_RESPOOL",
|
||||
|
@ -34,11 +34,13 @@ using HdiExecutorRegisterInfo = OHOS::HDI::UserAuth::V1_2::ExecutorRegisterInfo;
|
||||
using HdiExecutorInfo = OHOS::HDI::UserAuth::V1_2::ExecutorInfo;
|
||||
using HdiScheduleInfoV1_0 = OHOS::HDI::UserAuth::V1_2::ScheduleInfo;
|
||||
using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_2::ScheduleInfoV1_1;
|
||||
using HdiAuthSolution = OHOS::HDI::UserAuth::V1_2::AuthSolution;
|
||||
using HdiAuthSolutionV1_0 = OHOS::HDI::UserAuth::V1_2::AuthSolution;
|
||||
using HdiAuthSolution = OHOS::HDI::UserAuth::V1_2::AuthSolutionV1_2;
|
||||
using HdiExecutorSendMsg = OHOS::HDI::UserAuth::V1_2::ExecutorSendMsg;
|
||||
using HdiAuthResultInfo = OHOS::HDI::UserAuth::V1_2::AuthResultInfo;
|
||||
using HdiIdentifyResultInfo = OHOS::HDI::UserAuth::V1_2::IdentifyResultInfo;
|
||||
using HdiEnrollParam = OHOS::HDI::UserAuth::V1_2::EnrollParam;
|
||||
using HdiEnrollParamV1_0 = OHOS::HDI::UserAuth::V1_2::EnrollParam;
|
||||
using HdiEnrollParam = OHOS::HDI::UserAuth::V1_2::EnrollParamV1_2;
|
||||
using HdiCredentialInfo = OHOS::HDI::UserAuth::V1_2::CredentialInfo;
|
||||
using HdiEnrolledInfo = OHOS::HDI::UserAuth::V1_2::EnrolledInfo;
|
||||
using HdiEnrollResultInfo = OHOS::HDI::UserAuth::V1_2::EnrollResultInfo;
|
||||
|
@ -67,7 +67,6 @@ public:
|
||||
virtual void OnResult(int32_t resultCode, const Attributes &finalResult) = 0;
|
||||
virtual void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector<uint8_t> &acquireMsg) const = 0;
|
||||
virtual void SetTraceCallerName(std::string callerName) = 0;
|
||||
virtual std::string GetTraceCallerName() = 0;
|
||||
virtual void SetTraceRequestContextId(uint64_t requestContextId) = 0;
|
||||
virtual void SetTraceAuthContextId(uint64_t authContextId) = 0;
|
||||
virtual void SetTraceUserId(int32_t userId) = 0;
|
||||
|
@ -22,23 +22,17 @@
|
||||
#include <string>
|
||||
|
||||
#include "singleton.h"
|
||||
#include "authentication_impl.h"
|
||||
#include "enrollment_impl.h"
|
||||
#include "context.h"
|
||||
#include "context_callback.h"
|
||||
#include "identification_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ContextFactory : public DelayedSingleton<ContextFactory> {
|
||||
public:
|
||||
struct AuthContextPara {
|
||||
int32_t userId {0};
|
||||
AuthType authType {ALL};
|
||||
AuthTrustLevel atl {ATL1};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> challenge;
|
||||
bool endAfterFirstFail;
|
||||
};
|
||||
|
||||
struct AuthWidgetContextPara {
|
||||
struct AuthProfile {
|
||||
int32_t pinSubType {0};
|
||||
@ -48,34 +42,21 @@ public:
|
||||
};
|
||||
|
||||
int32_t userId {0};
|
||||
int32_t sdkVersion {0};
|
||||
uint32_t tokenId {0};
|
||||
std::string callingBundleName {""};
|
||||
std::string callerName {""};
|
||||
std::vector<uint8_t> challenge {};
|
||||
std::vector<AuthType> authTypeList {};
|
||||
AuthTrustLevel atl {ATL1};
|
||||
WidgetParam widgetParam {};
|
||||
std::map<AuthType, AuthProfile> authProfileMap {};
|
||||
};
|
||||
|
||||
struct IdentifyContextPara {
|
||||
AuthType authType {ALL};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> challenge;
|
||||
};
|
||||
|
||||
struct EnrollContextPara {
|
||||
int32_t userId {0};
|
||||
AuthType authType {ALL};
|
||||
PinSubType pinType {PIN_SIX};
|
||||
bool isUpdate {false};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> token;
|
||||
};
|
||||
static std::shared_ptr<Context> CreateSimpleAuthContext(const AuthContextPara ¶,
|
||||
static std::shared_ptr<Context> CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateIdentifyContext(const IdentifyContextPara ¶,
|
||||
static std::shared_ptr<Context> CreateIdentifyContext(const Identification::IdentificationPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateEnrollContext(const EnrollContextPara ¶,
|
||||
static std::shared_ptr<Context> CreateEnrollContext(const Enrollment::EnrollmentPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback);
|
||||
static std::shared_ptr<Context> CreateWidgetContext(const AuthWidgetContextPara ¶,
|
||||
|
@ -88,15 +88,6 @@ void ContextCallbackImpl::SetTraceCallerName(std::string callerName)
|
||||
metaData_.callerName = callerName;
|
||||
}
|
||||
|
||||
std::string ContextCallbackImpl::GetTraceCallerName()
|
||||
{
|
||||
if (!metaData_.callerName.has_value()) {
|
||||
IAM_LOGI("metaData callerName is null");
|
||||
return "";
|
||||
}
|
||||
return metaData_.callerName.value();
|
||||
}
|
||||
|
||||
void ContextCallbackImpl::SetTraceRequestContextId(uint64_t requestContextId)
|
||||
{
|
||||
metaData_.requestContextId = requestContextId;
|
||||
|
@ -31,7 +31,6 @@ public:
|
||||
void OnResult(int32_t resultCode, const Attributes &finalResult) override;
|
||||
void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector<uint8_t> &acquireMsg) const override;
|
||||
void SetTraceCallerName(std::string callerName) override;
|
||||
std::string GetTraceCallerName() override;
|
||||
void SetTraceRequestContextId(uint64_t requestContextId) override;
|
||||
void SetTraceAuthContextId(uint64_t authContextId) override;
|
||||
void SetTraceUserId(int32_t userId) override;
|
||||
|
@ -14,15 +14,12 @@
|
||||
*/
|
||||
#include "context_factory.h"
|
||||
|
||||
#include "authentication_impl.h"
|
||||
#include "context_callback_impl.h"
|
||||
#include "context_pool.h"
|
||||
#include "enroll_context.h"
|
||||
#include "enrollment_impl.h"
|
||||
#include "iam_check.h"
|
||||
#include "iam_logger.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "identification_impl.h"
|
||||
#include "identify_context.h"
|
||||
#include "simple_auth_context.h"
|
||||
#include "widget_context.h"
|
||||
@ -32,12 +29,12 @@
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
std::shared_ptr<Context> ContextFactory::CreateSimpleAuthContext(const AuthContextPara ¶,
|
||||
std::shared_ptr<Context> ContextFactory::CreateSimpleAuthContext(const Authentication::AuthenticationPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback)
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
|
||||
uint64_t newContextId = ContextPool::GetNewContextId();
|
||||
auto auth = Common::MakeShared<AuthenticationImpl>(newContextId, para.userId, para.authType, para.atl);
|
||||
auto auth = Common::MakeShared<AuthenticationImpl>(newContextId, para);
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(auth != nullptr, nullptr);
|
||||
auth->SetChallenge(para.challenge);
|
||||
auth->SetAccessTokenId(para.tokenId);
|
||||
@ -45,7 +42,7 @@ std::shared_ptr<Context> ContextFactory::CreateSimpleAuthContext(const AuthConte
|
||||
return Common::MakeShared<SimpleAuthContext>(newContextId, auth, callback);
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> ContextFactory::CreateIdentifyContext(const IdentifyContextPara ¶,
|
||||
std::shared_ptr<Context> ContextFactory::CreateIdentifyContext(const Identification::IdentificationPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback)
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
|
||||
@ -57,12 +54,12 @@ std::shared_ptr<Context> ContextFactory::CreateIdentifyContext(const IdentifyCon
|
||||
return Common::MakeShared<IdentifyContext>(newContextId, identify, callback);
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> ContextFactory::CreateEnrollContext(const EnrollContextPara ¶,
|
||||
std::shared_ptr<Context> ContextFactory::CreateEnrollContext(const Enrollment::EnrollmentPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback)
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
|
||||
uint64_t newContextId = ContextPool::GetNewContextId();
|
||||
auto enroll = Common::MakeShared<EnrollmentImpl>(para.userId, para.authType);
|
||||
auto enroll = Common::MakeShared<EnrollmentImpl>(para);
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(enroll != nullptr, nullptr);
|
||||
enroll->SetAuthToken(para.token);
|
||||
enroll->SetAccessTokenId(para.tokenId);
|
||||
|
@ -126,7 +126,7 @@ std::shared_ptr<ContextCallback> WidgetContext::GetAuthContextCallback(AuthType
|
||||
iamCallback->OnResult(ResultCode::GENERAL_ERROR, extraInfo);
|
||||
return nullptr;
|
||||
}
|
||||
widgetCallback->SetTraceCallerName(callerCallback_->GetTraceCallerName());
|
||||
widgetCallback->SetTraceCallerName(para_.callerName);
|
||||
widgetCallback->SetTraceRequestContextId(contextId_);
|
||||
widgetCallback->SetTraceAuthTrustLevel(authTrustLevel);
|
||||
widgetCallback->SetTraceAuthType(authType);
|
||||
@ -146,13 +146,15 @@ std::shared_ptr<Context> WidgetContext::BuildTask(const std::vector<uint8_t> &ch
|
||||
auto widgetCallback = GetAuthContextCallback(authType, authTrustLevel, iamCallback);
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(widgetCallback != nullptr, nullptr);
|
||||
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.tokenId = tokenId;
|
||||
para.userId = userId;
|
||||
para.authType = authType;
|
||||
para.atl = authTrustLevel;
|
||||
para.challenge = challenge;
|
||||
para.endAfterFirstFail = true;
|
||||
para.callerName = para_.callerName;
|
||||
para.sdkVersion = para_.sdkVersion;
|
||||
auto context = ContextFactory::CreateSimpleAuthContext(para, widgetCallback);
|
||||
if (context == nullptr || !ContextPool::Instance().Insert(context)) {
|
||||
IAM_LOGE("failed to insert context");
|
||||
|
@ -24,8 +24,7 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class AuthWidgetHelper {
|
||||
public:
|
||||
static bool InitWidgetContextParam(
|
||||
int32_t userId, const AuthParam &authParam, std::vector<AuthType> &validType,
|
||||
static bool InitWidgetContextParam(const AuthParam &authParam, std::vector<AuthType> &validType,
|
||||
const WidgetParam &widgetParam, ContextFactory::AuthWidgetContextPara ¶);
|
||||
static int32_t CheckValidSolution(int32_t userId,
|
||||
const std::vector<AuthType> &authTypeList, const AuthTrustLevel &atl, std::vector<AuthType> &validTypeList);
|
||||
|
@ -26,6 +26,17 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class Authentication {
|
||||
public:
|
||||
struct AuthenticationPara {
|
||||
int32_t userId {0};
|
||||
AuthType authType {ALL};
|
||||
AuthTrustLevel atl {ATL1};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> challenge;
|
||||
bool endAfterFirstFail;
|
||||
std::string callerName;
|
||||
int32_t sdkVersion;
|
||||
};
|
||||
|
||||
struct AuthResultInfo {
|
||||
int32_t result;
|
||||
int32_t freezingTime;
|
||||
|
@ -28,6 +28,17 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class Enrollment {
|
||||
public:
|
||||
struct EnrollmentPara {
|
||||
int32_t userId {0};
|
||||
AuthType authType {ALL};
|
||||
PinSubType pinType {PIN_SIX};
|
||||
bool isUpdate {false};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> token;
|
||||
std::string callerName;
|
||||
int32_t sdkVersion;
|
||||
};
|
||||
|
||||
virtual ~Enrollment() = default;
|
||||
|
||||
virtual void SetExecutorSensorHint(uint32_t executorSensorHint) = 0;
|
||||
|
@ -26,11 +26,17 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class Identification {
|
||||
public:
|
||||
struct IdentificationPara {
|
||||
AuthType authType {ALL};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> challenge;
|
||||
};
|
||||
struct IdentifyResultInfo {
|
||||
int32_t result;
|
||||
int32_t userId;
|
||||
std::vector<uint8_t> token;
|
||||
};
|
||||
|
||||
virtual ~Identification() = default;
|
||||
|
||||
virtual void SetExecutor(uint32_t executorIndex) = 0;
|
||||
|
@ -26,13 +26,12 @@ namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
|
||||
bool AuthWidgetHelper::InitWidgetContextParam(
|
||||
int32_t userId, const AuthParam &authParam, std::vector<AuthType> &validType,
|
||||
bool AuthWidgetHelper::InitWidgetContextParam(const AuthParam &authParam, std::vector<AuthType> &validType,
|
||||
const WidgetParam &widgetParam, ContextFactory::AuthWidgetContextPara ¶)
|
||||
{
|
||||
for (auto &authType : validType) {
|
||||
ContextFactory::AuthWidgetContextPara::AuthProfile profile;
|
||||
if (!GetUserAuthProfile(userId, authType, profile)) {
|
||||
if (!GetUserAuthProfile(para.userId, authType, profile)) {
|
||||
IAM_LOGE("get user auth profile failed");
|
||||
return false;
|
||||
}
|
||||
@ -43,7 +42,6 @@ bool AuthWidgetHelper::InitWidgetContextParam(
|
||||
WidgetClient::Instance().SetSensorInfo(profile.sensorInfo);
|
||||
}
|
||||
}
|
||||
para.userId = userId;
|
||||
para.challenge = std::move(authParam.challenge);
|
||||
para.authTypeList = std::move(validType);
|
||||
para.atl = authParam.authTrustLevel;
|
||||
|
@ -23,11 +23,8 @@
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
AuthenticationImpl::AuthenticationImpl(uint64_t contextId, int32_t userId, AuthType authType, AuthTrustLevel atl)
|
||||
: contextId_(contextId),
|
||||
userId_(userId),
|
||||
authType_(authType),
|
||||
atl_(atl)
|
||||
AuthenticationImpl::AuthenticationImpl(uint64_t contextId, const AuthenticationPara &authPara)
|
||||
: contextId_(contextId), authPara_(authPara)
|
||||
{
|
||||
}
|
||||
|
||||
@ -81,22 +78,25 @@ std::vector<Authentication::AuthExecutorMsg> AuthenticationImpl::GetAuthExecutor
|
||||
bool AuthenticationImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
|
||||
std::shared_ptr<ScheduleNodeCallback> callback)
|
||||
{
|
||||
IAM_LOGE("UserId:%{public}d AuthType:%{public}d ATL:%{public}u", userId_, authType_, atl_);
|
||||
IAM_LOGE("UserId:%{public}d AuthType:%{public}d ATL:%{public}u", authPara_.userId, authPara_.authType,
|
||||
authPara_.atl);
|
||||
auto hdi = HdiWrapper::GetHdiInstance();
|
||||
if (!hdi) {
|
||||
IAM_LOGE("bad hdi");
|
||||
return false;
|
||||
}
|
||||
HdiAuthSolution solution = {
|
||||
.userId = userId_,
|
||||
.authTrustLevel = atl_,
|
||||
.authType = static_cast<HdiAuthType>(authType_),
|
||||
.userId = authPara_.userId,
|
||||
.authTrustLevel = authPara_.atl,
|
||||
.authType = static_cast<HdiAuthType>(authPara_.authType),
|
||||
.executorSensorHint = executorSensorHint,
|
||||
.challenge = challenge_,
|
||||
.callerName = authPara_.callerName,
|
||||
.apiVersion = authPara_.sdkVersion,
|
||||
};
|
||||
std::vector<HdiScheduleInfo> infos;
|
||||
IamHitraceHelper traceHelper("hdi BeginAuthentication");
|
||||
auto result = hdi->BeginAuthenticationV1_1(contextId_, solution, infos);
|
||||
auto result = hdi->BeginAuthenticationV1_2(contextId_, solution, infos);
|
||||
if (result != HDF_SUCCESS) {
|
||||
IAM_LOGE("hdi BeginAuthentication failed, err is %{public}d", result);
|
||||
SetLatestError(result);
|
||||
|
@ -27,7 +27,7 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class AuthenticationImpl final : public Authentication, public NoCopyable {
|
||||
public:
|
||||
AuthenticationImpl(uint64_t contextId, int32_t userId, AuthType authType, AuthTrustLevel atl);
|
||||
AuthenticationImpl(uint64_t contextId, const AuthenticationPara &authPara);
|
||||
~AuthenticationImpl() override;
|
||||
|
||||
void SetExecutor(uint32_t executorIndex) override;
|
||||
@ -48,9 +48,7 @@ protected:
|
||||
|
||||
private:
|
||||
uint64_t contextId_;
|
||||
int32_t userId_;
|
||||
AuthType authType_;
|
||||
AuthTrustLevel atl_;
|
||||
AuthenticationPara authPara_;
|
||||
bool endAfterFirstFail_ {false};
|
||||
|
||||
uint32_t executorSensorHint {0};
|
||||
|
@ -28,7 +28,8 @@
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
EnrollmentImpl::EnrollmentImpl(int32_t userId, AuthType authType) : userId_(userId), authType_(authType)
|
||||
EnrollmentImpl::EnrollmentImpl(EnrollmentPara enrollPara)
|
||||
: enrollPara_(enrollPara)
|
||||
{
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ void EnrollmentImpl::SetIsUpdate(bool isUpdate)
|
||||
bool EnrollmentImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
|
||||
std::shared_ptr<ScheduleNodeCallback> callback)
|
||||
{
|
||||
IAM_LOGE("UserId:%{public}d AuthType:%{public}d", userId_, authType_);
|
||||
IAM_LOGE("UserId:%{public}d AuthType:%{public}d", enrollPara_.userId, enrollPara_.authType);
|
||||
auto hdi = HdiWrapper::GetHdiInstance();
|
||||
if (!hdi) {
|
||||
IAM_LOGE("bad hdi");
|
||||
@ -96,11 +97,13 @@ bool EnrollmentImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &scheduleL
|
||||
|
||||
HdiScheduleInfo info = {};
|
||||
HdiEnrollParam param = {
|
||||
.authType = static_cast<HdiAuthType>(authType_),
|
||||
.authType = static_cast<HdiAuthType>(enrollPara_.authType),
|
||||
.executorSensorHint = executorSensorHint_,
|
||||
.callerName = enrollPara_.callerName,
|
||||
.apiVersion = enrollPara_.sdkVersion,
|
||||
};
|
||||
IamHitraceHelper traceHelper("hdi BeginEnrollment");
|
||||
auto result = hdi->BeginEnrollmentV1_1(userId_, authToken_, param, info);
|
||||
auto result = hdi->BeginEnrollmentV1_2(enrollPara_.userId, authToken_, param, info);
|
||||
if (result != HDF_SUCCESS) {
|
||||
IAM_LOGE("hdi BeginEnrollment failed, err is %{public}d", result);
|
||||
SetLatestError(result);
|
||||
@ -125,11 +128,11 @@ bool EnrollmentImpl::Start(std::vector<std::shared_ptr<ScheduleNode>> &scheduleL
|
||||
bool EnrollmentImpl::GetSecUserId(std::optional<uint64_t> &secUserId)
|
||||
{
|
||||
secUserId = std::nullopt;
|
||||
if (authType_ != PIN) {
|
||||
if (enrollPara_.authType != PIN) {
|
||||
IAM_LOGI("no need return sec user id");
|
||||
return true;
|
||||
}
|
||||
auto userInfo = UserIdmDatabase::Instance().GetSecUserInfo(userId_);
|
||||
auto userInfo = UserIdmDatabase::Instance().GetSecUserInfo(enrollPara_.userId);
|
||||
if (userInfo != nullptr) {
|
||||
secUserId = userInfo->GetSecUserId();
|
||||
return true;
|
||||
@ -140,9 +143,9 @@ bool EnrollmentImpl::GetSecUserId(std::optional<uint64_t> &secUserId)
|
||||
return false;
|
||||
}
|
||||
|
||||
IAM_LOGE("current user id %{public}d get fail", userId_);
|
||||
IAM_LOGE("current user id %{public}d get fail", enrollPara_.userId);
|
||||
std::vector<std::shared_ptr<CredentialInfoInterface>> credInfos;
|
||||
if (UserIdmDatabase::Instance().DeleteUserEnforce(userId_, credInfos) != SUCCESS) {
|
||||
if (UserIdmDatabase::Instance().DeleteUserEnforce(enrollPara_.userId, credInfos) != SUCCESS) {
|
||||
IAM_LOGE("failed to enforce delete user");
|
||||
}
|
||||
return false;
|
||||
@ -159,13 +162,14 @@ bool EnrollmentImpl::Update(const std::vector<uint8_t> &scheduleResult, uint64_t
|
||||
}
|
||||
|
||||
HdiEnrollResultInfo resultInfo = {};
|
||||
auto result = hdi->UpdateEnrollmentResult(userId_, scheduleResult, resultInfo);
|
||||
auto result = hdi->UpdateEnrollmentResult(enrollPara_.userId, scheduleResult, resultInfo);
|
||||
if (result != HDF_SUCCESS) {
|
||||
IAM_LOGE("hdi UpdateEnrollmentResult failed, err is %{public}d, userId is %{public}d", result, userId_);
|
||||
IAM_LOGE("hdi UpdateEnrollmentResult failed, err is %{public}d, userId is %{public}d", result,
|
||||
enrollPara_.userId);
|
||||
SetLatestError(result);
|
||||
return false;
|
||||
}
|
||||
IAM_LOGI("hdi UpdateEnrollmentResult success, userId is %{public}d", userId_);
|
||||
IAM_LOGI("hdi UpdateEnrollmentResult success, userId is %{public}d", enrollPara_.userId);
|
||||
|
||||
credentialId = resultInfo.credentialId;
|
||||
rootSecret = resultInfo.rootSecret;
|
||||
@ -181,7 +185,7 @@ bool EnrollmentImpl::Update(const std::vector<uint8_t> &scheduleResult, uint64_t
|
||||
return true;
|
||||
}
|
||||
|
||||
info = Common::MakeShared<CredentialInfoImpl>(userId_, resultInfo.oldInfo);
|
||||
info = Common::MakeShared<CredentialInfoImpl>(enrollPara_.userId, resultInfo.oldInfo);
|
||||
if (info == nullptr) {
|
||||
IAM_LOGE("bad alloc");
|
||||
return false;
|
||||
@ -202,7 +206,7 @@ bool EnrollmentImpl::Cancel()
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = hdi->CancelEnrollment(userId_);
|
||||
auto result = hdi->CancelEnrollment(enrollPara_.userId);
|
||||
if (result != HDF_SUCCESS) {
|
||||
IAM_LOGE("hdi CancelEnrollment failed, err is %{public}d", result);
|
||||
SetLatestError(result);
|
||||
|
@ -27,7 +27,7 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class EnrollmentImpl final : public Enrollment, public NoCopyable {
|
||||
public:
|
||||
EnrollmentImpl(int32_t userId, AuthType authType);
|
||||
explicit EnrollmentImpl(EnrollmentPara enrollPara);
|
||||
~EnrollmentImpl() override;
|
||||
|
||||
void SetExecutorSensorHint(uint32_t executorSensorHint) override;
|
||||
@ -51,8 +51,7 @@ protected:
|
||||
private:
|
||||
bool GetSecUserId(std::optional<uint64_t> &secUserId);
|
||||
|
||||
int32_t userId_;
|
||||
AuthType authType_;
|
||||
EnrollmentPara enrollPara_;
|
||||
std::vector<uint8_t> authToken_;
|
||||
std::optional<uint64_t> secUserId_ {std::nullopt};
|
||||
|
||||
|
@ -55,6 +55,7 @@ ohos_source_set("userauth_services_ipc") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:app_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
|
@ -42,13 +42,13 @@ class IpcCommon final : public NoCopyable {
|
||||
public:
|
||||
using Recipient = std::function<void()>;
|
||||
static int32_t GetCallingUserId(IPCObjectStub &stub, int32_t &userId);
|
||||
static bool GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName);
|
||||
static int32_t GetActiveUserId(std::optional<int32_t> &userId);
|
||||
static int32_t GetAllUserId(std::vector<int32_t> &userIds);
|
||||
static bool CheckPermission(IPCObjectStub &stub, Permission permission);
|
||||
static uint32_t GetAccessTokenId(IPCObjectStub &stub);
|
||||
static uint32_t GetTokenId(IPCObjectStub &stub);
|
||||
static std::string GetCallerName(IPCObjectStub &stub);
|
||||
static bool GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName);
|
||||
static bool CheckForegroundApplication(const std::string &bundleName);
|
||||
class PeerDeathRecipient final : public IPCObjectProxy::DeathRecipient {
|
||||
public:
|
||||
explicit PeerDeathRecipient(Recipient &&recipient) : recipient_(std::forward<Recipient>(recipient))
|
||||
|
@ -70,12 +70,15 @@ private:
|
||||
int32_t CheckAuthWidgetType(const std::vector<AuthType> &authType);
|
||||
int32_t CheckAuthWidgetParam(
|
||||
int32_t userId, const AuthParam &authParam, const WidgetParam &widgetParam, std::vector<AuthType> &validType);
|
||||
uint64_t StartWidgetContext(int32_t userId, const std::shared_ptr<ContextCallback> &contextCallback,
|
||||
const AuthParam &authParam, const WidgetParam &widgetParam, std::vector<AuthType> &validType);
|
||||
uint64_t StartAuthContext(int32_t apiVersion, ContextFactory::AuthContextPara para,
|
||||
uint64_t StartWidgetContext(const std::shared_ptr<ContextCallback> &contextCallback, const AuthParam &authParam,
|
||||
const WidgetParam &widgetParam, std::vector<AuthType> &validType,
|
||||
ContextFactory::AuthWidgetContextPara ¶);
|
||||
uint64_t StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para,
|
||||
const std::shared_ptr<ContextCallback> &contextCallback);
|
||||
bool Insert2ContextPool(const std::shared_ptr<Context> &context);
|
||||
bool CheckCallerIsSystemApp();
|
||||
int32_t CheckAuthPermissionAndParam(int32_t authType, bool isBundleName, const std::string &callerName,
|
||||
AuthTrustLevel authTrustLevel);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -16,8 +16,11 @@
|
||||
#include "ipc_common.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "app_mgr_interface.h"
|
||||
#include "iam_common_defines.h"
|
||||
#include "iam_logger.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "tokenid_kit.h"
|
||||
#ifdef HAS_OS_ACCOUNT_PART
|
||||
#include "os_account_manager.h"
|
||||
@ -71,26 +74,6 @@ int32_t IpcCommon::GetCallingUserId(IPCObjectStub &stub, int32_t &userId)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
bool IpcCommon::GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName)
|
||||
{
|
||||
uint32_t tokenId = GetAccessTokenId(stub);
|
||||
using namespace Security::AccessToken;
|
||||
ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId);
|
||||
if (callingType != TOKEN_HAP) {
|
||||
IAM_LOGE("the caller is not a hap");
|
||||
return false;
|
||||
}
|
||||
HapTokenInfo hapTokenInfo;
|
||||
int result = AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo);
|
||||
if (result != SUCCESS) {
|
||||
IAM_LOGE("failed to get hap token info, result = %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
bundleName = hapTokenInfo.bundleName;
|
||||
IAM_LOGI("get callingInfo, bundleName is %{public}s", bundleName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t IpcCommon::GetActiveUserId(std::optional<int32_t> &userId)
|
||||
{
|
||||
if (userId.has_value() && userId.value() != 0) {
|
||||
@ -137,6 +120,31 @@ int32_t IpcCommon::GetAllUserId(std::vector<int32_t> &userIds)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
bool IpcCommon::CheckForegroundApplication(const std::string &bundleName)
|
||||
{
|
||||
sptr<ISystemAbilityManager> samgrClient = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgrClient == nullptr) {
|
||||
IAM_LOGI("Get system ability manager failed");
|
||||
return false;
|
||||
}
|
||||
sptr<AppExecFwk::IAppMgr> iAppManager =
|
||||
iface_cast<AppExecFwk::IAppMgr>(samgrClient->GetSystemAbility(APP_MGR_SERVICE_ID));
|
||||
if (iAppManager == nullptr) {
|
||||
IAM_LOGI("Failed to get ability manager service");
|
||||
return false;
|
||||
}
|
||||
std::vector<AppExecFwk::AppStateData> foregroundAppList;
|
||||
iAppManager->GetForegroundApplications(foregroundAppList);
|
||||
auto it = std::find_if(foregroundAppList.begin(), foregroundAppList.end(), [bundleName] (auto foregroundApp) {
|
||||
return bundleName.compare(foregroundApp.bundleName) == 0;
|
||||
});
|
||||
if (it == foregroundAppList.end()) {
|
||||
IAM_LOGI("app : %{public}s is not foreground", bundleName.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IpcCommon::CheckPermission(IPCObjectStub &stub, Permission permission)
|
||||
{
|
||||
switch (permission) {
|
||||
@ -270,27 +278,37 @@ bool IpcCommon::CheckCallerIsSystemApp(IPCObjectStub &stub)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string IpcCommon::GetCallerName(IPCObjectStub &stub)
|
||||
bool IpcCommon::GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName)
|
||||
{
|
||||
std::string callerName = "";
|
||||
if (GetCallingBundleName(stub, callerName)) {
|
||||
return callerName;
|
||||
}
|
||||
uint32_t tokenId = GetAccessTokenId(stub);
|
||||
using namespace Security::AccessToken;
|
||||
ATokenTypeEnum callingType = AccessTokenKit::GetTokenTypeFlag(tokenId);
|
||||
if (callingType != TOKEN_NATIVE) {
|
||||
IAM_LOGE("the caller is not a native service");
|
||||
return callerName;
|
||||
if (callingType == TOKEN_HAP) {
|
||||
isBundleName = true;
|
||||
HapTokenInfo hapTokenInfo;
|
||||
int result = AccessTokenKit::GetHapTokenInfo(tokenId, hapTokenInfo);
|
||||
if (result != SUCCESS) {
|
||||
IAM_LOGE("failed to get hap token info, result = %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
callerName = hapTokenInfo.bundleName;
|
||||
IAM_LOGI("caller bundleName is %{public}s", callerName.c_str());
|
||||
return true;
|
||||
} else if (callingType == TOKEN_NATIVE) {
|
||||
isBundleName = false;
|
||||
NativeTokenInfo nativeTokenInfo;
|
||||
int res = AccessTokenKit::GetNativeTokenInfo(tokenId, nativeTokenInfo);
|
||||
if (res != SUCCESS) {
|
||||
IAM_LOGE("failed to get native token info, res = %{public}d", res);
|
||||
return false;
|
||||
}
|
||||
callerName = nativeTokenInfo.processName;
|
||||
IAM_LOGI("caller processName is %{public}s", callerName.c_str());
|
||||
return true;
|
||||
}
|
||||
NativeTokenInfo nativeTokenInfo;
|
||||
int res = AccessTokenKit::GetNativeTokenInfo(tokenId, nativeTokenInfo);
|
||||
if (res != SUCCESS) {
|
||||
IAM_LOGE("failed to get native token info, res = %{public}d", res);
|
||||
return callerName;
|
||||
}
|
||||
callerName = nativeTokenInfo.processName;
|
||||
return callerName;
|
||||
isBundleName = false;
|
||||
IAM_LOGI("caller is not a hap or a native");
|
||||
return false;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -277,12 +277,32 @@ std::shared_ptr<ContextCallback> UserAuthService::GetAuthContextCallback(int32_t
|
||||
contextCallback->SetTraceAuthType(authType);
|
||||
contextCallback->SetTraceAuthTrustLevel(authTrustLevel);
|
||||
contextCallback->SetTraceAuthWidgetType(authType);
|
||||
std::string callerName = IpcCommon::GetCallerName(*this);
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
contextCallback->SetTraceSdkVersion(apiVersion);
|
||||
return contextCallback;
|
||||
}
|
||||
|
||||
int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t authType, bool isBundleName,
|
||||
const std::string &callerName, AuthTrustLevel authTrustLevel)
|
||||
{
|
||||
if (!IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION)) {
|
||||
IAM_LOGE("failed to check permission");
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
if (isBundleName && (!IpcCommon::CheckForegroundApplication(callerName))) {
|
||||
IAM_LOGE("failed to check foreground application");
|
||||
return CHECK_PERMISSION_FAILED;
|
||||
}
|
||||
if (authType == PIN) {
|
||||
IAM_LOGE("authType not support");
|
||||
return TYPE_NOT_SUPPORT;
|
||||
}
|
||||
if (!CheckAuthTrustLevel(authTrustLevel)) {
|
||||
IAM_LOGE("authTrustLevel is not in correct range");
|
||||
return TRUST_LEVEL_NOT_SUPPORT;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector<uint8_t> &challenge,
|
||||
AuthType authType, AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback)
|
||||
{
|
||||
@ -292,15 +312,19 @@ uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector<uint8_t> &c
|
||||
IAM_LOGE("contextCallback is nullptr");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
Attributes extraInfo;
|
||||
if (!IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION)) {
|
||||
IAM_LOGE("failed to check permission");
|
||||
contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo);
|
||||
if ((!IpcCommon::GetCallerName(*this, isBundleName, callerName)) && isBundleName) {
|
||||
IAM_LOGE("get bundle name fail");
|
||||
contextCallback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
if (authType == PIN) {
|
||||
IAM_LOGE("authType not support");
|
||||
contextCallback->OnResult(TYPE_NOT_SUPPORT, extraInfo);
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
int32_t checkRet = CheckAuthPermissionAndParam(authType, isBundleName, callerName, authTrustLevel);
|
||||
if (checkRet != SUCCESS) {
|
||||
IAM_LOGE("check auth permission and param fail");
|
||||
contextCallback->OnResult(checkRet, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
int32_t userId;
|
||||
@ -310,22 +334,21 @@ uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector<uint8_t> &c
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
contextCallback->SetTraceUserId(userId);
|
||||
if (!CheckAuthTrustLevel(authTrustLevel)) {
|
||||
IAM_LOGE("authTrustLevel is not in correct range");
|
||||
contextCallback->OnResult(TRUST_LEVEL_NOT_SUPPORT, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
para.userId = userId;
|
||||
para.authType = authType;
|
||||
para.atl = authTrustLevel;
|
||||
para.challenge = std::move(challenge);
|
||||
para.endAfterFirstFail = true;
|
||||
if (isBundleName) {
|
||||
para.callerName = callerName;
|
||||
}
|
||||
para.sdkVersion = apiVersion;
|
||||
return StartAuthContext(apiVersion, para, contextCallback);
|
||||
}
|
||||
|
||||
uint64_t UserAuthService::StartAuthContext(int32_t apiVersion, ContextFactory::AuthContextPara para,
|
||||
uint64_t UserAuthService::StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para,
|
||||
const std::shared_ptr<ContextCallback> &contextCallback)
|
||||
{
|
||||
Attributes extraInfo;
|
||||
@ -352,14 +375,22 @@ uint64_t UserAuthService::AuthUser(int32_t userId, const std::vector<uint8_t> &c
|
||||
AuthType authType, AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback)
|
||||
{
|
||||
IAM_LOGI("start");
|
||||
static const uint32_t innerApiVersion = 0x80000000;
|
||||
auto contextCallback = GetAuthContextCallback(innerApiVersion, challenge, authType, authTrustLevel, callback);
|
||||
auto contextCallback = GetAuthContextCallback(INNER_API_VERSION_10000, challenge, authType, authTrustLevel,
|
||||
callback);
|
||||
if (contextCallback == nullptr) {
|
||||
IAM_LOGE("contextCallback is nullptr");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
contextCallback->SetTraceUserId(userId);
|
||||
Attributes extraInfo;
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
if ((!IpcCommon::GetCallerName(*this, isBundleName, callerName)) && isBundleName) {
|
||||
IAM_LOGE("get bundle name fail");
|
||||
contextCallback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
if (!CheckAuthTrustLevel(authTrustLevel)) {
|
||||
IAM_LOGE("authTrustLevel is not in correct range");
|
||||
contextCallback->OnResult(TRUST_LEVEL_NOT_SUPPORT, extraInfo);
|
||||
@ -370,14 +401,18 @@ uint64_t UserAuthService::AuthUser(int32_t userId, const std::vector<uint8_t> &c
|
||||
contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
para.userId = userId;
|
||||
para.authType = authType;
|
||||
para.atl = authTrustLevel;
|
||||
para.challenge = std::move(challenge);
|
||||
para.endAfterFirstFail = false;
|
||||
return StartAuthContext(innerApiVersion, para, contextCallback);
|
||||
if (isBundleName) {
|
||||
para.callerName = callerName;
|
||||
}
|
||||
para.sdkVersion = INNER_API_VERSION_10000;
|
||||
return StartAuthContext(INNER_API_VERSION_10000, para, contextCallback);
|
||||
}
|
||||
|
||||
uint64_t UserAuthService::Identify(const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
@ -407,7 +442,7 @@ uint64_t UserAuthService::Identify(const std::vector<uint8_t> &challenge, AuthTy
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
ContextFactory::IdentifyContextPara para = {};
|
||||
Identification::IdentificationPara para = {};
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
para.authType = authType;
|
||||
para.challenge = std::move(challenge);
|
||||
@ -556,19 +591,13 @@ int32_t UserAuthService::CheckAuthWidgetParam(
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint64_t UserAuthService::StartWidgetContext(int32_t userId, const std::shared_ptr<ContextCallback> &contextCallback,
|
||||
const AuthParam &authParam, const WidgetParam &widgetParam, std::vector<AuthType> &validType)
|
||||
uint64_t UserAuthService::StartWidgetContext(const std::shared_ptr<ContextCallback> &contextCallback,
|
||||
const AuthParam &authParam, const WidgetParam &widgetParam, std::vector<AuthType> &validType,
|
||||
ContextFactory::AuthWidgetContextPara ¶)
|
||||
{
|
||||
Attributes extraInfo;
|
||||
ContextFactory::AuthWidgetContextPara para;
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
|
||||
std::string bundleName = "";
|
||||
if (!IpcCommon::GetCallingBundleName(*this, bundleName)) {
|
||||
IAM_LOGE("get calling bundle name failed");
|
||||
}
|
||||
para.callingBundleName = bundleName;
|
||||
if (!AuthWidgetHelper::InitWidgetContextParam(userId, authParam, validType, widgetParam, para)) {
|
||||
if (!AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para)) {
|
||||
IAM_LOGE("init widgetContext failed");
|
||||
contextCallback->OnResult(ResultCode::GENERAL_ERROR, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
@ -598,6 +627,10 @@ uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParam &authPa
|
||||
IAM_LOGE("contextCallback is nullptr");
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
static_cast<void>(IpcCommon::GetCallerName(*this, isBundleName, callerName));
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
Attributes extraInfo;
|
||||
if (!IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION)) {
|
||||
IAM_LOGE("CheckPermission failed");
|
||||
@ -617,7 +650,14 @@ uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParam &authPa
|
||||
contextCallback->OnResult(checkRet, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
return StartWidgetContext(userId, contextCallback, authParam, widgetParam, validType);
|
||||
ContextFactory::AuthWidgetContextPara para;
|
||||
para.userId = userId;
|
||||
if (isBundleName) {
|
||||
para.callingBundleName = callerName;
|
||||
para.callerName = callerName;
|
||||
}
|
||||
para.sdkVersion = apiVersion;
|
||||
return StartWidgetContext(contextCallback, authParam, widgetParam, validType, para);
|
||||
}
|
||||
|
||||
bool UserAuthService::Insert2ContextPool(const std::shared_ptr<Context> &context)
|
||||
@ -648,8 +688,6 @@ std::shared_ptr<ContextCallback> UserAuthService::GetAuthContextCallback(int32_t
|
||||
callback->OnResult(ResultCode::GENERAL_ERROR, extraInfo);
|
||||
return nullptr;
|
||||
}
|
||||
std::string callerName = IpcCommon::GetCallerName(*this);
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
contextCallback->SetTraceSdkVersion(apiVersion);
|
||||
contextCallback->SetTraceAuthTrustLevel(authParam.authTrustLevel);
|
||||
|
||||
|
@ -210,7 +210,9 @@ void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPar
|
||||
callback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return;
|
||||
}
|
||||
std::string callerName = IpcCommon::GetCallerName(*this);
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
static_cast<void>(IpcCommon::GetCallerName(*this, isBundleName, callerName));
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
contextCallback->SetTraceUserId(userId);
|
||||
contextCallback->SetTraceAuthType(credPara.authType);
|
||||
@ -223,13 +225,17 @@ void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPar
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
CancelCurrentEnrollIfExist();
|
||||
ContextFactory::EnrollContextPara para = {};
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.authType = credPara.authType;
|
||||
para.userId = userId;
|
||||
para.pinType = credPara.pinType;
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
para.token = credPara.token;
|
||||
para.isUpdate = isUpdate;
|
||||
para.sdkVersion = INNER_API_VERSION_10000;
|
||||
if (isBundleName) {
|
||||
para.callerName = callerName;
|
||||
}
|
||||
auto context = ContextFactory::CreateEnrollContext(para, contextCallback);
|
||||
if (context == nullptr || !ContextPool::Instance().Insert(context)) {
|
||||
IAM_LOGE("failed to insert context");
|
||||
@ -319,7 +325,9 @@ int32_t UserIdmService::EnforceDelUser(int32_t userId, const sptr<IdmCallbackInt
|
||||
callback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
contextCallback->SetTraceCallerName(IpcCommon::GetCallerName(*this));
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
static_cast<void>(IpcCommon::GetCallerName(*this, isBundleName, callerName));
|
||||
contextCallback->SetTraceUserId(userId);
|
||||
|
||||
if (!IpcCommon::CheckPermission(*this, ENFORCE_USER_IDM)) {
|
||||
@ -362,8 +370,9 @@ void UserIdmService::DelUser(int32_t userId, const std::vector<uint8_t> authToke
|
||||
callback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return;
|
||||
}
|
||||
std::string callerName = IpcCommon::GetCallerName(*this);
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
static_cast<void>(IpcCommon::GetCallerName(*this, isBundleName, callerName));
|
||||
contextCallback->SetTraceUserId(userId);
|
||||
|
||||
if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) {
|
||||
@ -405,8 +414,9 @@ void UserIdmService::DelCredential(int32_t userId, uint64_t credentialId,
|
||||
callback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return;
|
||||
}
|
||||
std::string callerName = IpcCommon::GetCallerName(*this);
|
||||
contextCallback->SetTraceCallerName(callerName);
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
static_cast<void>(IpcCommon::GetCallerName(*this, isBundleName, callerName));
|
||||
contextCallback->SetTraceUserId(userId);
|
||||
|
||||
if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) {
|
||||
@ -505,7 +515,7 @@ int32_t UserIdmService::EnforceDelUserInner(int32_t userId, std::shared_ptr<Cont
|
||||
ret = ResourceNodeUtils::NotifyExecutorToDeleteTemplates(credInfos, changeReasonTrace);
|
||||
if (ret != SUCCESS) {
|
||||
IAM_LOGE("failed to delete executor info, error code : %{public}d", ret);
|
||||
//EnforceDelUser return success for caller.
|
||||
// The caller doesn't need to care executor delete result.
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -528,6 +538,9 @@ void UserIdmService::ClearRedundancyCredentialInner()
|
||||
IAM_LOGE("no userInfo");
|
||||
return;
|
||||
}
|
||||
bool isBundleName = false;
|
||||
std::string callerName = "";
|
||||
static_cast<void>(IpcCommon::GetCallerName(*this, isBundleName, callerName));
|
||||
|
||||
for (const auto &iter : userInfos) {
|
||||
int32_t userId = iter->GetUserId();
|
||||
@ -537,7 +550,7 @@ void UserIdmService::ClearRedundancyCredentialInner()
|
||||
continue;
|
||||
}
|
||||
callbackForTrace->SetTraceUserId(userId);
|
||||
callbackForTrace->SetTraceCallerName(IpcCommon::GetCallerName(*this));
|
||||
callbackForTrace->SetTraceCallerName(callerName);
|
||||
std::vector<int32_t>::iterator it = std::find(accountInfo.begin(), accountInfo.end(), userId);
|
||||
if (it == accountInfo.end()) {
|
||||
ret = EnforceDelUserInner(userId, callbackForTrace, "DeleteRedundancy");
|
||||
|
@ -328,6 +328,7 @@ ohos_source_set("userauth_services_ipc_fuzzer") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:app_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
|
@ -36,7 +36,6 @@ public:
|
||||
MOCK_CONST_METHOD3(
|
||||
OnAcquireInfo, void(ExecutorRole src, int32_t moduleType, const std::vector<uint8_t> &acquireMsg));
|
||||
MOCK_METHOD1(SetTraceCallerName, void(std::string callerName));
|
||||
MOCK_METHOD0(GetTraceCallerName, std::string());
|
||||
MOCK_METHOD1(SetTraceRequestContextId, void(uint64_t requestContextId));
|
||||
MOCK_METHOD1(SetTraceAuthContextId, void(uint64_t authContextId));
|
||||
MOCK_METHOD1(SetTraceUserId, void(int32_t userId));
|
||||
|
@ -44,12 +44,6 @@ int32_t IpcCommon::GetCallingUserId(IPCObjectStub &stub, int32_t &userId)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
bool IpcCommon::GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName)
|
||||
{
|
||||
bundleName = TEST_CALLER_BUNDLE_NAME;
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t IpcCommon::GetActiveUserId(std::optional<int32_t> &userId)
|
||||
{
|
||||
if (userId.has_value() && userId.value() != 0) {
|
||||
@ -141,10 +135,16 @@ void IpcCommon::SetSkipUserFlag(bool isSkip)
|
||||
skipFlag_ = isSkip;
|
||||
}
|
||||
|
||||
std::string IpcCommon::GetCallerName(IPCObjectStub &stub)
|
||||
bool IpcCommon::GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName)
|
||||
{
|
||||
std::string callerName = "";
|
||||
return callerName;
|
||||
callerName = "";
|
||||
isBundleName = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IpcCommon::CheckForegroundApplication(const std::string &bundleName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -42,17 +42,17 @@ enum Permission {
|
||||
class IpcCommon final : public NoCopyable {
|
||||
public:
|
||||
static int32_t GetCallingUserId(IPCObjectStub &stub, int32_t &userId);
|
||||
static bool GetCallingBundleName(IPCObjectStub &stub, std::string &bundleName);
|
||||
static int32_t GetActiveUserId(std::optional<int32_t> &userId);
|
||||
static int32_t GetAllUserId(std::vector<int32_t> &userIds);
|
||||
static bool CheckPermission(IPCObjectStub &stub, Permission permission);
|
||||
static std::string GetCallerName(IPCObjectStub &stub);
|
||||
static bool GetCallerName(IPCObjectStub &stub, bool &isBundleName, std::string &callerName);
|
||||
static uint32_t GetAccessTokenId(IPCObjectStub &stub);
|
||||
static void SetAccessTokenId(uint32_t tokenId, bool isSetTokenId);
|
||||
static void AddPermission(Permission perm);
|
||||
static void DeleteAllPermission();
|
||||
static uint32_t GetTokenId(IPCObjectStub &stub);
|
||||
static void SetSkipUserFlag(bool isSkip);
|
||||
static bool CheckForegroundApplication(const std::string &bundleName);
|
||||
|
||||
private:
|
||||
static std::set<Permission> permSet_;
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
MOCK_METHOD2(OpenSession, int32_t(int32_t userId, std::vector<uint8_t> &challenge));
|
||||
MOCK_METHOD1(CloseSession, int32_t(int32_t userId));
|
||||
MOCK_METHOD4(BeginEnrollment,
|
||||
int32_t(int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
int32_t(int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParamV1_0 ¶m,
|
||||
HdiScheduleInfoV1_0 &info));
|
||||
MOCK_METHOD3(UpdateEnrollmentResult, int32_t(int32_t userId, const std::vector<uint8_t> &scheduleResult,
|
||||
HdiEnrollResultInfo &info));
|
||||
@ -54,7 +54,7 @@ public:
|
||||
int32_t(int32_t userId, const std::vector<uint8_t> &authToken, std::vector<HdiCredentialInfo> &deletedInfos));
|
||||
MOCK_METHOD2(EnforceDeleteUser, int32_t(int32_t userId, std::vector<HdiCredentialInfo> &deletedInfos));
|
||||
MOCK_METHOD3(BeginAuthentication,
|
||||
int32_t(uint64_t contextId, const HdiAuthSolution ¶m, std::vector<HdiScheduleInfoV1_0> &scheduleInfos));
|
||||
int32_t(uint64_t contextId, const HdiAuthSolutionV1_0 ¶m, std::vector<HdiScheduleInfoV1_0> &scheduleInfos));
|
||||
MOCK_METHOD3(UpdateAuthenticationResult,
|
||||
int32_t(uint64_t contextId, const std::vector<uint8_t> &scheduleResult, HdiAuthResultInfo &info));
|
||||
MOCK_METHOD1(CancelAuthentication, int32_t(uint64_t contextId));
|
||||
@ -68,15 +68,20 @@ public:
|
||||
MOCK_METHOD4(GetValidSolution, int32_t(int32_t userId, const std::vector<HdiAuthType> &authTypes,
|
||||
uint32_t authTrustLevel, std::vector<HdiAuthType> &validTypes));
|
||||
MOCK_METHOD4(BeginEnrollmentV1_1,
|
||||
int32_t(int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
int32_t(int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParamV1_0 ¶m,
|
||||
HdiScheduleInfo &info));
|
||||
MOCK_METHOD3(BeginAuthenticationV1_1,
|
||||
int32_t(uint64_t contextId, const HdiAuthSolution ¶m, std::vector<HdiScheduleInfo> &scheduleInfos));
|
||||
int32_t(uint64_t contextId, const HdiAuthSolutionV1_0 ¶m, std::vector<HdiScheduleInfo> &scheduleInfos));
|
||||
MOCK_METHOD5(BeginIdentificationV1_1,
|
||||
int32_t(uint64_t contextId, HdiAuthType authType, const std::vector<uint8_t> &challenge, uint32_t executorId,
|
||||
HdiScheduleInfo &scheduleInfo));
|
||||
MOCK_METHOD1(GetAllUserInfo, int32_t(std::vector<UserInfo> &userInfos));
|
||||
MOCK_METHOD1(GetAllExtUserInfo, int32_t(std::vector<ExtUserInfo> &userInfos));
|
||||
MOCK_METHOD4(BeginEnrollmentV1_2,
|
||||
int32_t(int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
HdiScheduleInfo &info));
|
||||
MOCK_METHOD3(BeginAuthenticationV1_2,
|
||||
int32_t(uint64_t contextId, const HdiAuthSolution ¶m, std::vector<HdiScheduleInfo> &scheduleInfos));
|
||||
};
|
||||
|
||||
class MockIUserAuthInterface::Holder : public Singleton<MockIUserAuthInterface::Holder> {
|
||||
|
@ -56,7 +56,6 @@ void AuthWidgetHelperTest::TearDown()
|
||||
|
||||
HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, TestSize.Level0)
|
||||
{
|
||||
int32_t userId = 1;
|
||||
AuthParam authParam;
|
||||
authParam.authType.push_back(FACE);
|
||||
authParam.authType.push_back(ALL);
|
||||
@ -67,13 +66,13 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, Te
|
||||
widgetParam.title = "使用密码验证";
|
||||
widgetParam.navigationButtonText = "确定";
|
||||
ContextFactory::AuthWidgetContextPara para;
|
||||
para.userId = 1;
|
||||
std::vector<AuthType> validType;
|
||||
EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(userId, authParam, validType, widgetParam, para));
|
||||
EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam002, TestSize.Level0)
|
||||
{
|
||||
int32_t userId = 1;
|
||||
AuthParam authParam;
|
||||
authParam.authType.push_back(FACE);
|
||||
authParam.authType.push_back(ALL);
|
||||
@ -84,8 +83,9 @@ HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam002, Te
|
||||
widgetParam.title = "使用密码验证";
|
||||
widgetParam.navigationButtonText = "确定";
|
||||
ContextFactory::AuthWidgetContextPara para;
|
||||
para.userId = 1;
|
||||
std::vector<AuthType> validType = authParam.authType;
|
||||
EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(userId, authParam, validType, widgetParam, para));
|
||||
EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckValidSolution, TestSize.Level0)
|
||||
|
@ -62,12 +62,16 @@ void AuthenticationImplTest::TearDown()
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationHdiError, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 0x1234567;
|
||||
constexpr int32_t userId = 0x11;
|
||||
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, BeginAuthenticationV1_1(contextId, _, _)).WillRepeatedly(Return(1));
|
||||
EXPECT_CALL(*mock, BeginAuthenticationV1_2(contextId, _, _)).WillRepeatedly(Return(1));
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
EXPECT_FALSE(authentication->Start(scheduleList, nullptr));
|
||||
}
|
||||
@ -75,12 +79,17 @@ HWTEST_F(AuthenticationImplTest, AuthenticationHdiError, TestSize.Level0)
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationHdiEmpty, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 0x1234567;
|
||||
constexpr int32_t userId = 0x11;
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, BeginAuthenticationV1_1(contextId, _, _)).WillRepeatedly(Return(0));
|
||||
EXPECT_CALL(*mock, BeginAuthenticationV1_2(contextId, _, _)).WillRepeatedly(Return(0));
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
EXPECT_FALSE(authentication->Start(scheduleList, nullptr));
|
||||
}
|
||||
@ -88,7 +97,12 @@ HWTEST_F(AuthenticationImplTest, AuthenticationHdiEmpty, TestSize.Level0)
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationInvalidExecutor, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 0x1234567;
|
||||
constexpr int32_t userId = 0x11;
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
constexpr int32_t executorInfoIndex = 0x100;
|
||||
constexpr int32_t scheduleId = 0x1122;
|
||||
|
||||
@ -112,10 +126,10 @@ HWTEST_F(AuthenticationImplTest, AuthenticationInvalidExecutor, TestSize.Level0)
|
||||
};
|
||||
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, BeginAuthenticationV1_1(contextId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillInfoList),
|
||||
EXPECT_CALL(*mock, BeginAuthenticationV1_2(contextId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillInfoList),
|
||||
Return(0)));
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
EXPECT_FALSE(authentication->Start(scheduleList, nullptr));
|
||||
}
|
||||
@ -123,7 +137,12 @@ HWTEST_F(AuthenticationImplTest, AuthenticationInvalidExecutor, TestSize.Level0)
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate001, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 54871;
|
||||
constexpr int32_t userId = 1534;
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
@ -136,7 +155,7 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate001, TestSize.Level
|
||||
}
|
||||
);
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
EXPECT_NE(authentication, nullptr);
|
||||
std::vector<uint8_t> scheduleResult;
|
||||
Authentication::AuthResultInfo info = {};
|
||||
@ -146,7 +165,12 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate001, TestSize.Level
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate002, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 54871;
|
||||
constexpr int32_t userId = 1534;
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
@ -163,7 +187,7 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate002, TestSize.Level
|
||||
}
|
||||
);
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
EXPECT_NE(authentication, nullptr);
|
||||
std::vector<uint8_t> scheduleResult;
|
||||
Authentication::AuthResultInfo info = {};
|
||||
@ -173,10 +197,14 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate002, TestSize.Level
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestSetEndAfterFirstFail, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 1234;
|
||||
constexpr int32_t userId = 5678;
|
||||
AuthType authType = FACE;
|
||||
AuthTrustLevel atl = ATL3;
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, authType, atl);
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
EXPECT_NE(authentication, nullptr);
|
||||
bool endAfterFirstFail = true;
|
||||
authentication->SetEndAfterFirstFail(endAfterFirstFail);
|
||||
@ -185,8 +213,14 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestSetEndAfterFirstFail, Tes
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetLatestError, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 1234;
|
||||
constexpr int32_t userId = 5678;
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
ASSERT_NE(authentication, nullptr);
|
||||
int32_t lastError = authentication->GetLatestError();
|
||||
EXPECT_EQ(ResultCode::GENERAL_ERROR, lastError);
|
||||
@ -195,8 +229,14 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetLatestError, TestSize.
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetAuthExecutorMsgs, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 1234;
|
||||
constexpr int32_t userId = 5678;
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
ASSERT_NE(authentication, nullptr);
|
||||
auto authExecutorMsgs = authentication->GetAuthExecutorMsgs();
|
||||
EXPECT_EQ(authExecutorMsgs.size(), 0);
|
||||
@ -205,16 +245,19 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestGetAuthExecutorMsgs, Test
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 34567;
|
||||
constexpr uint64_t userId = 25781;
|
||||
constexpr uint64_t executorIndex = 60;
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, CancelAuthentication(_))
|
||||
.Times(2)
|
||||
.WillOnce(Return(HDF_SUCCESS))
|
||||
.WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _))
|
||||
EXPECT_CALL(*mockHdi, CancelAuthentication(_)).Times(2)
|
||||
.WillOnce(Return(HDF_SUCCESS)).WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _))
|
||||
.WillRepeatedly(
|
||||
[](uint64_t contextId, const HdiAuthSolution ¶m, std::vector<HdiScheduleInfo> &scheduleInfos) {
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
@ -239,7 +282,7 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0)
|
||||
auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, FACE, ALL_IN_ONE);
|
||||
EXPECT_NE(resourceNode, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
EXPECT_NE(authentication, nullptr);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
|
@ -59,7 +59,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_001, TestSize.Level0
|
||||
sptr<UserAuthCallbackInterface> callback(new (std::nothrow) MockUserAuthCallback());
|
||||
ASSERT_NE(callback, nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL);
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
Authentication::AuthenticationPara para = {};
|
||||
auto context = factory->CreateSimpleAuthContext(para, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
EXPECT_NE(context->GetContextId(), 0U);
|
||||
@ -74,7 +74,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_002, TestSize.Level0
|
||||
// Error: callback is null
|
||||
sptr<UserAuthCallbackInterface> callback(nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL);
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
Authentication::AuthenticationPara para = {};
|
||||
auto context = factory->CreateSimpleAuthContext(para, contextCallback);
|
||||
ASSERT_EQ(context, nullptr);
|
||||
}
|
||||
@ -87,7 +87,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_001, TestSize.Level0)
|
||||
sptr<UserAuthCallbackInterface> callback(new (std::nothrow) MockUserAuthCallback());
|
||||
ASSERT_NE(callback, nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY);
|
||||
ContextFactory::IdentifyContextPara para = {};
|
||||
Identification::IdentificationPara para = {};
|
||||
auto context = factory->CreateIdentifyContext(para, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
EXPECT_NE(context->GetContextId(), 0U);
|
||||
@ -102,7 +102,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_002, TestSize.Level0)
|
||||
// Error: callback is null
|
||||
sptr<UserAuthCallbackInterface> callback(nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY);
|
||||
ContextFactory::IdentifyContextPara para = {};
|
||||
Identification::IdentificationPara para = {};
|
||||
auto context = factory->CreateIdentifyContext(para, contextCallback);
|
||||
ASSERT_EQ(context, nullptr);
|
||||
}
|
||||
@ -115,7 +115,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_001, TestSize.Lev
|
||||
sptr<IdmCallbackInterface> callback(new (std::nothrow) MockIdmCallback());
|
||||
ASSERT_NE(callback, nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL);
|
||||
ContextFactory::EnrollContextPara para = {};
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
auto context = factory->CreateEnrollContext(para, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
EXPECT_NE(context->GetContextId(), 0U);
|
||||
@ -130,7 +130,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_002, TestSize.Lev
|
||||
// Error: callback is null
|
||||
sptr<IdmCallbackInterface> callback(nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL);
|
||||
ContextFactory::EnrollContextPara para = {};
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
auto context = factory->CreateEnrollContext(para, contextCallback);
|
||||
ASSERT_EQ(context, nullptr);
|
||||
}
|
||||
|
@ -58,23 +58,31 @@ void EnrollmentImplTest::TearDown()
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentHdiError, TestSize.Level0)
|
||||
{
|
||||
constexpr int32_t userId = 0x11;
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, BeginEnrollmentV1_1(userId, _, _, _)).WillRepeatedly(Return(1));
|
||||
EXPECT_CALL(*mock, BeginEnrollmentV1_2(para.userId, _, _, _)).WillRepeatedly(Return(1));
|
||||
|
||||
auto enrollment = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enrollment = std::make_shared<EnrollmentImpl>(para);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
EXPECT_FALSE(enrollment->Start(scheduleList, nullptr));
|
||||
}
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentHdiEmpty, TestSize.Level0)
|
||||
{
|
||||
constexpr int32_t userId = 0x11;
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, BeginEnrollmentV1_1(userId, _, _, _)).WillRepeatedly(Return(0));
|
||||
EXPECT_CALL(*mock, BeginEnrollmentV1_2(para.userId, _, _, _)).WillRepeatedly(Return(0));
|
||||
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
EXPECT_FALSE(enroll->Start(scheduleList, nullptr));
|
||||
}
|
||||
@ -87,12 +95,16 @@ HWTEST_F(EnrollmentImplTest, EnrollmentHdiEmpty, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiError, TestSize.Level0)
|
||||
{
|
||||
constexpr int32_t userId = 0x11;
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(Return(1));
|
||||
EXPECT_CALL(*mock, UpdateEnrollmentResult(para.userId, _, _)).WillRepeatedly(Return(1));
|
||||
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
std::vector<uint8_t> scheduleResult = {1, 2, 3};
|
||||
uint64_t credentialId = 0;
|
||||
std::shared_ptr<CredentialInfoInterface> info = nullptr;
|
||||
@ -103,10 +115,13 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiError, TestSize.Level0)
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_001, TestSize.Level0)
|
||||
{
|
||||
constexpr int32_t userId = 0x11;
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
constexpr uint64_t credentialIdRet = 0x12;
|
||||
std::vector<uint8_t> scheduleResult = {1, 2, 3};
|
||||
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
auto fillUpInfos = [](HdiEnrollResultInfo &infoRet) {
|
||||
HdiCredentialInfo oldInfo = {
|
||||
@ -123,12 +138,13 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_001, TestSize.Level0)
|
||||
};
|
||||
infoRet = info;
|
||||
};
|
||||
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
|
||||
EXPECT_CALL(*mock, UpdateEnrollmentResult(para.userId, _, _))
|
||||
.WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
|
||||
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
enroll->SetIsUpdate(true);
|
||||
HdiCredentialInfo oldInfo = {};
|
||||
std::shared_ptr<CredentialInfoInterface> info = std::make_shared<CredentialInfoImpl>(userId, oldInfo);
|
||||
std::shared_ptr<CredentialInfoInterface> info = std::make_shared<CredentialInfoImpl>(para.userId, oldInfo);
|
||||
uint64_t credentialId = 0;
|
||||
std::vector<uint8_t> rootSecret;
|
||||
std::optional<uint64_t> secUserId = std::nullopt;
|
||||
@ -147,10 +163,14 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_001, TestSize.Level0)
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_002, TestSize.Level0)
|
||||
{
|
||||
int32_t userId = 1206;
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.userId = 1206;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = PIN;
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, UpdateEnrollmentResult(_, _, _)).WillRepeatedly(Return(0));
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
enroll->SetIsUpdate(false);
|
||||
|
||||
std::vector<uint8_t> scheduleResult = {1, 2, 3};
|
||||
@ -178,7 +198,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_002, TestSize.Level0)
|
||||
}
|
||||
);
|
||||
|
||||
enroll = std::make_shared<EnrollmentImpl>(userId, PIN);
|
||||
enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
enroll->SetIsUpdate(false);
|
||||
EXPECT_FALSE(enroll->Update(scheduleResult, credentialId, info, rootSecret, secUserId));
|
||||
EXPECT_FALSE(enroll->Update(scheduleResult, credentialId, info, rootSecret, secUserId));
|
||||
@ -186,16 +206,20 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful_002, TestSize.Level0)
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t userId = 34567;
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
constexpr uint64_t executorIndex = 60;
|
||||
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, CancelEnrollment(_))
|
||||
.Times(2)
|
||||
.WillOnce(Return(HDF_SUCCESS))
|
||||
.WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _))
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _))
|
||||
.WillRepeatedly(
|
||||
[](int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
HdiScheduleInfo &info) {
|
||||
@ -219,7 +243,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0)
|
||||
auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, FACE, ALL_IN_ONE);
|
||||
EXPECT_NE(resourceNode, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
EXPECT_NE(enroll, nullptr);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
@ -235,9 +259,13 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_001, TestSize.Level0)
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_002, TestSize.Level0)
|
||||
{
|
||||
uint64_t userId = 34567;
|
||||
Enrollment::EnrollmentPara para = {};
|
||||
para.userId = 34567;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = PIN;
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, BeginEnrollmentV1_1(_, _, _, _)).WillRepeatedly(Return(1));
|
||||
EXPECT_CALL(*mock, BeginEnrollmentV1_2(_, _, _, _)).WillRepeatedly(Return(1));
|
||||
EXPECT_CALL(*mock, GetUserInfo(_, _, _, _))
|
||||
.WillOnce(Return(1))
|
||||
.WillRepeatedly(
|
||||
@ -254,7 +282,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_002, TestSize.Level0)
|
||||
}
|
||||
);
|
||||
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_FALSE(enroll->Start(scheduleList, callback));
|
||||
@ -262,7 +290,7 @@ HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart_002, TestSize.Level0)
|
||||
enroll->SetIsUpdate(true);
|
||||
EXPECT_FALSE(enroll->Start(scheduleList, callback));
|
||||
|
||||
enroll = std::make_shared<EnrollmentImpl>(userId, PIN);
|
||||
enroll = std::make_shared<EnrollmentImpl>(para);
|
||||
enroll->SetIsUpdate(true);
|
||||
EXPECT_FALSE(enroll->Start(scheduleList, callback));
|
||||
EXPECT_FALSE(enroll->Start(scheduleList, callback));
|
||||
|
@ -271,7 +271,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth001, TestSize.Level0)
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)).WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)).WillOnce(Return(HDF_FAILURE));
|
||||
|
||||
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
|
||||
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
|
||||
@ -333,7 +333,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth003, TestSize.Level0)
|
||||
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)).Times(2).WillRepeatedly(Return(NOT_ENROLLED));
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)).Times(2).WillRepeatedly(Return(NOT_ENROLLED));
|
||||
contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
@ -368,7 +368,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth004, TestSize.Level0)
|
||||
IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _))
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _))
|
||||
.WillRepeatedly(
|
||||
[&context](uint64_t contextId, const HdiAuthSolution ¶m, std::vector<HdiScheduleInfo> &scheduleInfos) {
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
@ -436,7 +436,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0)
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _)).Times(1);
|
||||
IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION);
|
||||
sptr<UserAuthCallbackInterface> callbackInterface = testCallback;
|
||||
uint64_t contextId = service.AuthUser(testUserId, testChallenge, testAuthType,
|
||||
@ -504,7 +504,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0)
|
||||
IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_1(_, _, _))
|
||||
EXPECT_CALL(*mockHdi, BeginAuthenticationV1_2(_, _, _))
|
||||
.WillRepeatedly(
|
||||
[&context](uint64_t contextId, const HdiAuthSolution ¶m, std::vector<HdiScheduleInfo> &scheduleInfos) {
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
|
@ -336,7 +336,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential002, TestSize.Level0)
|
||||
);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _)).WillRepeatedly(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _)).WillRepeatedly(Return(HDF_FAILURE));
|
||||
|
||||
service.AddCredential(testUserId, testCredPara, testCallback, false);
|
||||
IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION);
|
||||
@ -368,7 +368,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential003, TestSize.Level0)
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _))
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _))
|
||||
.WillOnce(
|
||||
[&context](int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
HdiScheduleInfo &info) {
|
||||
@ -489,7 +489,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential002, TestSize.Level0)
|
||||
}
|
||||
);
|
||||
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_1(_, _, _, _)).WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollmentV1_2(_, _, _, _)).WillOnce(Return(HDF_FAILURE));
|
||||
|
||||
testCredPara.token = {1, 2, 3, 4};
|
||||
service.UpdateCredential(testUserId, testCredPara, testCallback);
|
||||
|
Loading…
Reference in New Issue
Block a user