mirror of
https://github.com/openharmony/useriam_user_auth.git
synced 2026-07-19 22:33:53 -04:00
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 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.
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<filefilterlist>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
|
||||
<filteritem type="filename" name="*.png" desc="The framework image"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <if_system_ability_manager.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <system_ability_definition.h>
|
||||
|
||||
#include "system_ability_definition.h"
|
||||
#include "userauth_common.h"
|
||||
#include "user_auth.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
UserAuth::UserAuth() = default;
|
||||
UserAuth::~UserAuth() = default;
|
||||
|
||||
sptr<IUserAuth> UserAuth::GetProxy()
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth GetProxy is start");
|
||||
std::lock_guard lock(mutex_);
|
||||
if (proxy_ != nullptr) {
|
||||
return proxy_;
|
||||
}
|
||||
|
||||
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sam == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Failed to get system manager");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IRemoteObject> obj = sam->CheckSystemAbility(USERAUTH_SERVICE_SA_ID);
|
||||
if (obj == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Failed to get userauth manager service");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IRemoteObject::DeathRecipient> dr = new UserAuthDeathRecipient();
|
||||
if ((obj->IsProxyObject()) && (!obj->AddDeathRecipient(dr))) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Failed to add death recipient");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
proxy_ = iface_cast<IUserAuth>(obj);
|
||||
deathRecipient_ = dr;
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Succeed to connect userauth manager service");
|
||||
return proxy_;
|
||||
}
|
||||
|
||||
void UserAuth::ResetProxy(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth ResetProxy is start");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
RETURN_IF(proxy_ == nullptr);
|
||||
|
||||
auto serviceRemote = proxy_->AsObject();
|
||||
if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
|
||||
serviceRemote->RemoveDeathRecipient(deathRecipient_);
|
||||
proxy_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void UserAuth::UserAuthDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "OnRemoteDied is start");
|
||||
if (remote == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "OnRemoteDied failed, remote is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
UserAuth::GetInstance().ResetProxy(remote);
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth UserAuthDeathRecipient::Recv death notice.");
|
||||
}
|
||||
|
||||
int32_t UserAuth::GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth GetAvailableStatus is start");
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
return E_RET_NOSERVER;
|
||||
}
|
||||
|
||||
int32_t ret = proxy_->GetAvailableStatus(authType, authTurstLevel);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UserAuth::GetProperty(const GetPropertyRequest request, std::shared_ptr<UserAuthCallback> callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth GetProperty is start");
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
callback->onSetExecutorProperty(E_RET_NOSERVER);
|
||||
return ;
|
||||
}
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth GetProperty callback is Null");
|
||||
}
|
||||
|
||||
sptr<IUserAuthCallback> asyncStub = new UserAuthAsyncStub(callback);
|
||||
proxy_->GetProperty(request, asyncStub);
|
||||
}
|
||||
void UserAuth::SetProperty(const SetPropertyRequest request, std::shared_ptr<UserAuthCallback> callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth SetProperty is start");
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
ExecutorProperty result;
|
||||
result.result = E_RET_NOSERVER;
|
||||
callback->onExecutorPropertyInfo(result);
|
||||
return ;
|
||||
}
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SetProperty callback is Null");
|
||||
}
|
||||
|
||||
sptr<IUserAuthCallback> asyncStub = new UserAuthAsyncStub(callback);
|
||||
proxy_->SetProperty(request, asyncStub);
|
||||
}
|
||||
uint64_t UserAuth::Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
|
||||
std::shared_ptr<UserAuthCallback> callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth Auth is start");
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
return E_RET_NOSERVER;
|
||||
}
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Auth callback is Null");
|
||||
return INVALID_PARAMETERS;
|
||||
}
|
||||
sptr<IUserAuthCallback> asyncStub = new UserAuthAsyncStub(callback);
|
||||
uint64_t ret = proxy_->Auth(challenge, authType, authTurstLevel, asyncStub);
|
||||
return ret;
|
||||
}
|
||||
uint64_t UserAuth::AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, std::shared_ptr<UserAuthCallback> callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth AuthUser is start");
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
return E_RET_NOSERVER;
|
||||
}
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth AuthUser callback is Null");
|
||||
return INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
sptr<IUserAuthCallback> asyncStub = new UserAuthAsyncStub(callback);
|
||||
uint64_t ret = proxy_->AuthUser(userId, challenge, authType, authTurstLevel, asyncStub);
|
||||
return ret;
|
||||
}
|
||||
int32_t UserAuth::CancelAuth(const uint64_t contextId)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth CancelAuth is start");
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
return E_RET_NOSERVER;
|
||||
}
|
||||
|
||||
int32_t ret = proxy_->CancelAuth(contextId);
|
||||
return ret;
|
||||
}
|
||||
int32_t UserAuth::GetVersion()
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth GetVersion is start");
|
||||
auto proxy = GetProxy();
|
||||
if (proxy == nullptr) {
|
||||
return INVALID_PARAMETERS;
|
||||
}
|
||||
|
||||
int32_t ret = proxy_->GetVersion();
|
||||
return ret;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <message_parcel.h>
|
||||
|
||||
#include "userauth_common.h"
|
||||
#include "iuser_auth.h"
|
||||
#include "userauth_async_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
UserAuthAsyncStub::UserAuthAsyncStub(std::shared_ptr<UserAuthCallback>& impl)
|
||||
{
|
||||
callback_ = impl;
|
||||
}
|
||||
int32_t UserAuthAsyncStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthAsyncStub::OnRemoteRequest");
|
||||
|
||||
std::u16string descripter = UserAuthAsyncStub::GetDescriptor();
|
||||
std::u16string remoteDescripter = data.ReadInterfaceToken();
|
||||
if (descripter != remoteDescripter) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub::OnRemoteRequest failed, descriptor is not matched!");
|
||||
return E_GET_POWER_SERVICE_FAILED;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_ACQUIRENFO):
|
||||
return onAcquireInfoStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_ONRESULT):
|
||||
return onResultStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_GETEXPORP):
|
||||
return onExecutorPropertyInfoStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_SETEXPORP):
|
||||
return onSetExecutorPropertyStub(data, reply);
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t UserAuthAsyncStub::onAcquireInfoStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthAsyncStub OnAcquireInfoStub enter ");
|
||||
|
||||
int32_t ret = SUCCESS;
|
||||
int32_t module;
|
||||
uint32_t acquireInfo;
|
||||
int32_t extraInfo;
|
||||
|
||||
if (!data.ReadInt32(module)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadInt32(module).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(acquireInfo)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint32(acquireInfo).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadInt32(extraInfo)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadInt32(extraInfo).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
this->onAcquireInfo(module, acquireInfo, extraInfo);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth failed to WriteInt32(ret)");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAsyncStub::onResultStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthAsyncStub onResultStub enter ");
|
||||
|
||||
int32_t ret = SUCCESS;
|
||||
AuthResult authResult;
|
||||
std::vector<uint8_t> token;
|
||||
uint32_t remainTimes;
|
||||
uint32_t freezingTime;
|
||||
int32_t result = GENERAL_ERROR;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadInt32(result).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&token)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUInt8Vector(&token).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(remainTimes)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint32(remainTimes).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(freezingTime)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint32(freezingTime).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
authResult.freezingTime = freezingTime;
|
||||
authResult.remainTimes = remainTimes;
|
||||
authResult.token.clear();
|
||||
authResult.token.assign(token.begin(), token.end());
|
||||
|
||||
this->onResult(result, authResult);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth failed to WriteInt32(ret)");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAsyncStub::onExecutorPropertyInfoStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthAsyncStub onExecutorPropertyInfoStub enter ");
|
||||
|
||||
int32_t ret = SUCCESS;
|
||||
int32_t result;
|
||||
uint32_t authSubType;
|
||||
uint32_t remainTimes;
|
||||
uint32_t freezingTime;
|
||||
ExecutorProperty executorProperty;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadInt32(result).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(authSubType)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint32(authSubType).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(remainTimes)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint32(remainTimes).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(freezingTime)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint32(freezingTime).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
executorProperty.authSubType = static_cast<AuthSubType>(authSubType);
|
||||
executorProperty.freezingTime = freezingTime;
|
||||
executorProperty.remainTimes = remainTimes;
|
||||
executorProperty.result = static_cast<AuthSubType>(result);
|
||||
|
||||
this->onExecutorPropertyInfo(executorProperty);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth failed to WriteInt32(ret)");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAsyncStub::onSetExecutorPropertyStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauth onSetExecutorPropertyStub enter ");
|
||||
|
||||
int32_t ret = SUCCESS;
|
||||
int32_t result = GENERAL_ERROR;
|
||||
|
||||
if (!data.ReadInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadInt32(result).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
this->onSetExecutorProperty(result);
|
||||
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth failed to WriteInt32(ret)");
|
||||
ret = E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UserAuthAsyncStub::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub onAcquireInfo enter");
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub module:%{public}d", module);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub acquireInfo:%{public}d", acquireInfo);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub extraInfo:%{public}d", extraInfo);
|
||||
if (callback_ == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauthAsyncStub onAcquireInfo callback_ is Null");
|
||||
return ;
|
||||
}
|
||||
callback_->onAcquireInfo(module, acquireInfo, extraInfo);
|
||||
}
|
||||
|
||||
void UserAuthAsyncStub::onResult(const int32_t result, const AuthResult extraInfot)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub onResult enter");
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub result:%{public}d", result);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub remainTimes:%{public}d", extraInfot.remainTimes);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub freezingTime:%{public}d", extraInfot.freezingTime);
|
||||
|
||||
if (callback_ == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauthAsyncStub onResult callback_ is Null");
|
||||
return ;
|
||||
}
|
||||
callback_->onResult(result, extraInfot);
|
||||
}
|
||||
|
||||
void UserAuthAsyncStub::onExecutorPropertyInfo(const ExecutorProperty result)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthAsyncStub onExecutorPropertyInfo enter");
|
||||
|
||||
if (callback_ == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub onExecutorPropertyInfo callback_ is Null");
|
||||
return ;
|
||||
}
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub result:%{public}d", result.result);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub authSubType:%{public}d", result.authSubType);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub remainTimes:%{public}d", result.freezingTime);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub freezingTime:%{public}d", result.freezingTime);
|
||||
callback_->onExecutorPropertyInfo(result);
|
||||
}
|
||||
|
||||
void UserAuthAsyncStub::onSetExecutorProperty(const int32_t result)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthAsyncStub onSetExecutorProperty enter");
|
||||
|
||||
if (callback_ == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthAsyncStub onSetExecutorProperty callback_ is Null");
|
||||
return ;
|
||||
}
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "userauthAsyncStub result:%{public}d", result);
|
||||
callback_->onSetExecutorProperty(result);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <message_parcel.h>
|
||||
#include <string_ex.h>
|
||||
#include "userauth_common.h"
|
||||
#include "userauth_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
UserAuthProxy::UserAuthProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IUserAuth>(object) {}
|
||||
|
||||
int32_t UserAuthProxy::GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy GetAvailableStatus is start");
|
||||
int32_t result = GENERAL_ERROR;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!");
|
||||
return result;
|
||||
}
|
||||
|
||||
WRITE_PARCEL_WITH_RET(data, Uint32, static_cast<uint32_t>(authType), E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Uint32, static_cast<uint32_t>(authTurstLevel), E_READ_PARCEL_ERROR);
|
||||
|
||||
bool ret = SendRequest(static_cast<int32_t>(IUserAuth::USER_AUTH_GET_AVAILABLE_STATUS), data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret);
|
||||
return IPC_ERROR;
|
||||
}
|
||||
if (!reply.ReadInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Readback fail!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy GetProperty is start");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!");
|
||||
return ;
|
||||
}
|
||||
|
||||
WRITE_PARCEL_NO_RET(data, Uint32, static_cast<uint32_t>(request.authType));
|
||||
WRITE_PARCEL_NO_RET(data, UInt32Vector, (request.keys));
|
||||
WRITE_PARCEL_NO_RET(data, RemoteObject, callback->AsObject());
|
||||
|
||||
bool ret = SendRequest(static_cast<int32_t>(IUserAuth::USER_AUTH_GET_PROPERTY), data, reply, option);
|
||||
if (!ret) {
|
||||
ExecutorProperty result;
|
||||
result.result = IPC_ERROR;
|
||||
callback->onExecutorPropertyInfo(result);
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy SetProperty is start");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_ASYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!");
|
||||
return ;
|
||||
}
|
||||
|
||||
WRITE_PARCEL_NO_RET(data, Uint32, static_cast<uint32_t>(request.authType));
|
||||
WRITE_PARCEL_NO_RET(data, Uint32, static_cast<uint32_t>(request.key));
|
||||
WRITE_PARCEL_NO_RET(data, UInt8Vector, request.setInfo);
|
||||
WRITE_PARCEL_NO_RET(data, RemoteObject, callback->AsObject());
|
||||
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_SET_PROPERTY, data, reply, option);
|
||||
if (!ret) {
|
||||
int32_t result = IPC_ERROR;
|
||||
callback->onSetExecutorProperty(result);
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy Auth is start");
|
||||
u_int64_t result = SUCCESS;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!");
|
||||
return result;
|
||||
}
|
||||
|
||||
WRITE_PARCEL_WITH_RET(data, Uint64, challenge, E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Uint32, static_cast<uint32_t>(authType), E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Uint32, static_cast<uint32_t>(authTurstLevel), E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), E_READ_PARCEL_ERROR);
|
||||
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH, data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret);
|
||||
return result;
|
||||
}
|
||||
if (!reply.ReadUint64(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Readback fail!");
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy AuthUser is start");
|
||||
u_int64_t result = SUCCESS;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
|
||||
return result;
|
||||
}
|
||||
|
||||
WRITE_PARCEL_WITH_RET(data, Int32, userId, E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Uint64, challenge, E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Uint32, static_cast<uint32_t>(authType), E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, Uint32, static_cast<uint32_t>(authTurstLevel), E_READ_PARCEL_ERROR);
|
||||
WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), E_READ_PARCEL_ERROR);
|
||||
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH_USER, data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret);
|
||||
return result;
|
||||
}
|
||||
if (!reply.ReadUint64(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Readback fail!");
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UserAuthProxy::CancelAuth(const uint64_t contextId)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy CancelAuth is start");
|
||||
int32_t result = GENERAL_ERROR;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
|
||||
return result;
|
||||
}
|
||||
|
||||
WRITE_PARCEL_WITH_RET(data, Uint64, contextId, E_READ_PARCEL_ERROR);
|
||||
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_CANCEL_AUTH, data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret);
|
||||
return IPC_ERROR;
|
||||
}
|
||||
if (!reply.ReadInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UserAuthProxy::GetVersion()
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy GetVersion is start");
|
||||
int32_t result = GENERAL_ERROR;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_GET_VERSION, data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret);
|
||||
return IPC_ERROR;
|
||||
}
|
||||
if (!reply.ReadInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "Readback fail!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool UserAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption option)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy SendRequest is start");
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = remote->SendRequest(code, data, reply, option);
|
||||
if (result != OHOS::UserIAM::UserAuth::SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "UserAuthProxy SendRequest fail");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
+379
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import{AsyncCallback} from './basic';
|
||||
|
||||
declare namespace userIAM
|
||||
{
|
||||
class UserAuth
|
||||
{
|
||||
/**
|
||||
* constructor.
|
||||
*
|
||||
* @return Constructor to get the userauth class instance
|
||||
*/
|
||||
constructor();
|
||||
|
||||
/**
|
||||
* getVersion.
|
||||
*
|
||||
* @return Get version information
|
||||
*/
|
||||
getVersion() : number;
|
||||
|
||||
/**
|
||||
* getAvailabeStatus.
|
||||
*
|
||||
* <p>Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
|
||||
*
|
||||
* @param authType Credential type for authentication.
|
||||
* @param authTrustLevel Credibility level of certification results.
|
||||
* @return number.
|
||||
*/
|
||||
getAvailabeStatus(authType : AuthType, authTrustLevel : AuthTurstLevel) : number;
|
||||
/**
|
||||
* getProperty.
|
||||
*
|
||||
* <p>Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
|
||||
*
|
||||
* @param request the attribute field list, authentication credential type, and credential subclass.
|
||||
* @return ExecutorProperty: Get the attribute, pass in the credential type and the key to get, and return the value
|
||||
* corresponding to the key (support to query subclasses / remaining authentication times / freezing time)
|
||||
*/
|
||||
getProperty(request : GetPropertyRequest) : Promise<ExecutorProperty>;
|
||||
getProperty(request: GetPropertyRequest, callback: AsyncCallback<ExecutorProperty>): void
|
||||
|
||||
/**
|
||||
* getProperty.
|
||||
*
|
||||
* <p>Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
|
||||
*
|
||||
* @param request pass in the credential type and the key value to be set.
|
||||
* @return number.
|
||||
*/
|
||||
setProperty(request: SetPropertyRequest): Promise<number>;
|
||||
setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>): void
|
||||
|
||||
/**
|
||||
* auth
|
||||
*
|
||||
* <p>Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
|
||||
*
|
||||
* @param challenge pass in challenge value.
|
||||
* @param authMethod authentication method.
|
||||
* @param authTrustLevel Credibility level of certification results.
|
||||
* @param callback Return results and acquireinfo through callback.
|
||||
* @return BigInt.
|
||||
*/
|
||||
auth(challenge: BigInt, authMethod: number, authTrustLevel: AuthTurstLevel, callback: IUserAuthCallback): BigInt;
|
||||
|
||||
/**
|
||||
* authUser
|
||||
*
|
||||
* <p>Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
|
||||
*
|
||||
* @param userId Incoming user ID.
|
||||
* @param challenge pass in challenge value.
|
||||
* @param authMethod authentication method.
|
||||
* @param authTrustLevel Credibility level of certification results.
|
||||
* @param callback Return results and acquireinfo through callback.
|
||||
* @return BigInt.
|
||||
*/
|
||||
authUser(userId: number, challenge: BigInt, authMethod: number, authTrustLevel: AuthTurstLevel, callback : IUserAuthCallback): BigInt;
|
||||
|
||||
/**
|
||||
* getProperty.
|
||||
*
|
||||
* <p>Permissions required: {@code ohos.permission.ACCESS_USER_AUTH}
|
||||
*
|
||||
* @param contextID Cancel authentication and pass in ContextID.
|
||||
* @return number.
|
||||
*/
|
||||
cancelAuth(contextID : BigInt) : number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Credential type for authentication
|
||||
*/
|
||||
enum AuthType {
|
||||
/**
|
||||
* Authentication type pin.
|
||||
*/
|
||||
PIN = 1,
|
||||
/**
|
||||
* Authentication type face.
|
||||
*/
|
||||
FACE = 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Credential subtype: 6-digit digital password, user-defined digital password,
|
||||
* user-defined mixed password, 2D face, 3D face
|
||||
*/
|
||||
enum AuthSubType{
|
||||
/**
|
||||
* Authentication sub type six number pin.
|
||||
*/
|
||||
PIN_SIX = 10000,
|
||||
/**
|
||||
* Authentication sub type self defined number pin.
|
||||
*/
|
||||
PIN_NUMBER = 10001,
|
||||
/**
|
||||
* Authentication sub type 2D face.
|
||||
*/
|
||||
PIN_MIXED = 10002,
|
||||
/**
|
||||
* Authentication sub type 2D face.
|
||||
*/
|
||||
FACE_2D = 20000,
|
||||
/**
|
||||
* Authentication sub type 3D face.
|
||||
*/
|
||||
FACE_3D = 20001
|
||||
}
|
||||
|
||||
/**
|
||||
* Credibility level of certification results
|
||||
*/
|
||||
enum AuthTurstLevel {
|
||||
/**
|
||||
* Authentication result trusted level 1.
|
||||
*/
|
||||
ATL1 = 10000,
|
||||
/**
|
||||
* Authentication result trusted level 2.
|
||||
*/
|
||||
ATL2 = 20000,
|
||||
/**
|
||||
* Authentication result trusted level 3.
|
||||
*/
|
||||
ATL3 = 30000,
|
||||
/**
|
||||
* Authentication result trusted level 4.
|
||||
*/
|
||||
ATL4 = 40000
|
||||
}
|
||||
|
||||
/**
|
||||
* Actuator attribute list
|
||||
*/
|
||||
enum GetPropertyType {
|
||||
/**
|
||||
* Authentication remain times.
|
||||
*/
|
||||
AUTH_SUB_TYPE = 1,
|
||||
/**
|
||||
* Authentication remain times.
|
||||
*/
|
||||
REMAIN_TIMES = 2,
|
||||
/**
|
||||
* Authentication freezing time.
|
||||
*/
|
||||
FREEZING_TIME = 3
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute request: the attribute field list, authentication credential type, and credential subclass
|
||||
* requested to be obtained
|
||||
*/
|
||||
interface GetPropertyRequest {
|
||||
authType : AuthType;
|
||||
keys : Array<GetPropertyType>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actuator attribute: subclass, remaining authentication times, freezing time
|
||||
*/
|
||||
interface ExecutorProperty {
|
||||
result: number;
|
||||
authSubType : AuthSubType;
|
||||
remainTimes ?: number;
|
||||
freezingTime ?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actuator attribute list
|
||||
*/
|
||||
enum SetPropertyType {
|
||||
/**
|
||||
* init algorithm.
|
||||
*/
|
||||
INIT_ALGORITHM = 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute request: pass in the credential type and the key value to be set
|
||||
*/
|
||||
interface SetPropertyRequest {
|
||||
authType : AuthType;
|
||||
key : SetPropertyType;
|
||||
setInfo : Uint8Array;
|
||||
}
|
||||
/**
|
||||
* Actuator attribute: subclass, remaining authentication times, freezing time
|
||||
*/
|
||||
interface ExecutorProperty {
|
||||
result : number;
|
||||
authSubType : AuthSubType;
|
||||
remainTimes ?: number;
|
||||
freezingTime ?: number;
|
||||
}
|
||||
/**
|
||||
* Authentication method and priority: currently only faces are supported
|
||||
*/
|
||||
enum AuthMethod {
|
||||
/**
|
||||
* Authentication method PIN.
|
||||
*/
|
||||
PIN_ONLY = 0xF,
|
||||
/**
|
||||
* Authentication method face.
|
||||
*/
|
||||
FACE_ONLY = 0xF0
|
||||
}
|
||||
|
||||
/**
|
||||
* The authentication result code is returned through the callback, the authentication is passed, the authentication
|
||||
* token is returned in extrainfo, the authentication fails, the remaining authentication times are returned in
|
||||
* extrainfo, the authentication actuator is locked, and the freezing time / acquireinfo is returned in extrainfo
|
||||
*/
|
||||
interface IUserAuthCallback {
|
||||
onResult: (result : number, extraInfo : AuthResult) => void;
|
||||
onAcquireInfo ?: (module : number, acquire : number, extraInfo : any) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the module of acquireinfo
|
||||
*/
|
||||
enum Module {
|
||||
/**
|
||||
* Acquire information from FaceAuth.
|
||||
*/
|
||||
FACE_AUTH = 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication result: authentication token, remaining authentication times, freezing time
|
||||
*/
|
||||
interface AuthResult {
|
||||
token ?: Uint8Array;
|
||||
remainTimes ?: number;
|
||||
freezingTime ?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Result code
|
||||
*/
|
||||
enum ResultCode {
|
||||
/**
|
||||
* Indicates that authentication is success or ability is supported.
|
||||
*/
|
||||
SUCCESS = 0,
|
||||
/**
|
||||
* Indicates the authenticator fails to identify user.
|
||||
*/
|
||||
FAIL = 1,
|
||||
/**
|
||||
* Indicates other errors.
|
||||
*/
|
||||
GENERAL_ERROR = 2,
|
||||
/**
|
||||
* Indicates that authentication has been canceled.
|
||||
*/
|
||||
CANCELED = 3,
|
||||
/**
|
||||
* Indicates that authentication has timed out.
|
||||
*/
|
||||
TIMEOUT = 4,
|
||||
/**
|
||||
* Indicates that this authentication type is not supported.
|
||||
*/
|
||||
TYPE_NOT_SUPPORT = 5,
|
||||
/**
|
||||
* Indicates that the authentication trust level is not supported.
|
||||
*/
|
||||
TRUST_LEVEL_NOT_SUPPORT = 6,
|
||||
/**
|
||||
* Indicates that the authentication task is busy. Wait for a few seconds and try again.
|
||||
*/
|
||||
BUSY = 7,
|
||||
/**
|
||||
* Indicates incorrect parameters.
|
||||
*/
|
||||
INVALID_PARAMETERS = 8,
|
||||
/**
|
||||
* Indicates that the authenticator is locked.
|
||||
*/
|
||||
LOCKED = 9,
|
||||
/**
|
||||
* Indicates that the user has not enrolled the authenticator.
|
||||
*/
|
||||
NOT_ENROLLED = 10
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumeration of prompt codes during authentication
|
||||
*/
|
||||
enum FaceTipsCode {
|
||||
/**
|
||||
* Indicates that the obtained facial image is too bright due to high illumination.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_BRIGHT = 1,
|
||||
/**
|
||||
* Indicates that the obtained facial image is too dark due to low illumination.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_DARK = 2,
|
||||
/**
|
||||
* Indicates that the face is too close to the device.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_CLOSE = 3,
|
||||
/**
|
||||
* Indicates that the face is too far away from the device.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_FAR = 4,
|
||||
/**
|
||||
* Indicates that the device is too high, and that only the upper part of the face is captured.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_HIGH = 5,
|
||||
/**
|
||||
* Indicates that the device is too low, and that only the lower part of the face is captured.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_LOW = 6,
|
||||
/**
|
||||
* Indicates that the device is deviated to the right, and that only the right part of the face is captured.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_RIGHT = 7,
|
||||
/**
|
||||
* Indicates that the device is deviated to the left, and that only the left part of the face is captured.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_LEFT = 8,
|
||||
/**
|
||||
* Indicates that the face moves too fast during facial information collection.
|
||||
*/
|
||||
FACE_AUTH_TIP_TOO_MUCH_MOTION = 9,
|
||||
/**
|
||||
* Indicates that the face is not facing the device.
|
||||
*/
|
||||
FACE_AUTH_TIP_POOR_GAZE = 10,
|
||||
/**
|
||||
* Indicates that no face is detected.
|
||||
*/
|
||||
FACE_AUTH_TIP_NOT_DETECTED = 11,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default userIAM;
|
||||
@@ -0,0 +1,69 @@
|
||||
# Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
|
||||
config("userauth_public_config") {
|
||||
include_dirs = [
|
||||
"include"
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("userauth") {
|
||||
include_dirs = [
|
||||
# "common/include",
|
||||
# "//third_party/node/src",
|
||||
# "//foundation/ace/napi/interfaces/kits",
|
||||
# "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
]
|
||||
|
||||
|
||||
cflags = [
|
||||
"-fPIC",
|
||||
"-g3",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/auth_native_module.cpp",
|
||||
"src/user_auth_impl.cpp",
|
||||
"src/auth_build.cpp",
|
||||
"src/result_convert.cpp",
|
||||
"src/user_auth_helper.cpp",
|
||||
"src/authapi_callback.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${userauth_innerkits_path}/native:userauth_framework",
|
||||
"//foundation/ace/napi:ace_napi"
|
||||
]
|
||||
|
||||
configs = [
|
||||
"${userauth_utils_path}:utils_config",
|
||||
]
|
||||
|
||||
public_configs = [ ":userauth_public_config" ]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
relative_install_dir = "module"
|
||||
|
||||
part_name = "userauth"
|
||||
subsystem_name = "userauth"
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FACERECOGNITION_AUTH_BUILD_H
|
||||
#define FACERECOGNITION_AUTH_BUILD_H
|
||||
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include "userauth_info.h"
|
||||
|
||||
#include "auth_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class AuthBuild {
|
||||
public:
|
||||
AuthBuild();
|
||||
~AuthBuild();
|
||||
Napi_SetPropertyRequest SetPropertyRequestBuild(napi_env env, napi_value object);
|
||||
Napi_GetPropertyRequest GetPropertyRequestBuild(napi_env env, napi_value object);
|
||||
napi_value GetNapiExecutorProperty(napi_env env, Napi_ExecutorProperty property);
|
||||
napi_value BuildAuthResult(napi_env env, Napi_AuthResult authResult);
|
||||
bool NapiTypeObject(napi_env env, napi_value value);
|
||||
bool NapiTypeBitInt(napi_env env, napi_value value);
|
||||
bool NapiTypeNumber(napi_env env, napi_value value);
|
||||
|
||||
void AuthUserCallBackResult(napi_env env, AuthUserInfo *userInfo);
|
||||
void AuthUserCallBackAcquireInfo(napi_env env, AuthUserInfo *userInfo);
|
||||
void AuthCallBackAcquireInfo(napi_env env, AuthInfo *authInfo);
|
||||
void AuthCallBackResult(napi_env env, AuthInfo *authInfo);
|
||||
uint64_t GetUint8ArrayTo64(napi_env env, napi_value value);
|
||||
int NapiGetValueInt(napi_env env, napi_value value);
|
||||
napi_value Uint64ToUint8Array(napi_env env, uint64_t value);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif // FACERECOGNITION_AUTH_BUILD_H
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 OHOS_USERAUTH_COMMON_H
|
||||
#define OHOS_USERAUTH_COMMON_H
|
||||
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "auth_object.h"
|
||||
#include "userauth_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
#define ARGS_MAX_COUNT 10
|
||||
#define ARGS_ASYNC_COUNT 1
|
||||
#define GET_VALUE_ERROR (-1)
|
||||
#define NAPI_GET_STRING_SIZE 128
|
||||
|
||||
#define ARGS_ONE 1
|
||||
#define ARGS_TWO 2
|
||||
#define ARGS_THREE 3
|
||||
#define ARGS_FOUR 4
|
||||
#define ARGS_FIVE 5
|
||||
#define ARGS_SIX 6
|
||||
#define ARGS_SEVEN 7
|
||||
#define ARGS_EIGHT 8
|
||||
#define ARGS_NINE 9
|
||||
#define ARGS_TEN 10
|
||||
|
||||
#define PARAM0 0
|
||||
#define PARAM1 1
|
||||
#define PARAM2 2
|
||||
#define PARAM3 3
|
||||
#define PARAM4 4
|
||||
#define PARAM5 5
|
||||
#define PARAM6 6
|
||||
#define PARAM7 7
|
||||
#define PARAM8 8
|
||||
#define PARAM9 9
|
||||
#define PARAM10 10
|
||||
|
||||
struct CallBackInfo {
|
||||
napi_env env;
|
||||
napi_ref callBack = 0;
|
||||
napi_deferred deferred;
|
||||
};
|
||||
|
||||
struct GetVersionInfo {
|
||||
GetVersionInfo() : asyncWork(nullptr) {};
|
||||
CallBackInfo callBackInfo;
|
||||
napi_async_work asyncWork;
|
||||
};
|
||||
|
||||
struct GetPropertyInfo {
|
||||
GetPropertyInfo() : asyncWork(nullptr), result(nullptr) {};
|
||||
CallBackInfo callBackInfo;
|
||||
napi_async_work asyncWork;
|
||||
napi_value result;
|
||||
int32_t authType;
|
||||
UserIAM::UserAuth::ExecutorProperty property;
|
||||
std::vector<uint32_t> keys;
|
||||
};
|
||||
|
||||
struct SetPropertyInfo {
|
||||
SetPropertyInfo() : asyncWork(nullptr), result(nullptr) {};
|
||||
CallBackInfo callBackInfo;
|
||||
napi_async_work asyncWork;
|
||||
napi_value result;
|
||||
int authType;
|
||||
int32_t key;
|
||||
std::vector<uint8_t> setInfo;
|
||||
};
|
||||
|
||||
struct AuthInfo {
|
||||
AuthInfo() : asyncWork(nullptr) {};
|
||||
CallBackInfo callBackInfo;
|
||||
napi_callback_info info;
|
||||
napi_async_work asyncWork;
|
||||
napi_value jsFunction;
|
||||
napi_ref onResultCallBack;
|
||||
napi_ref onAcquireInfoCallBack;
|
||||
napi_value onResultData[ARGS_TWO];
|
||||
napi_value onAcquireInfoData[ARGS_THREE];
|
||||
uint64_t challenge;
|
||||
int32_t authType;
|
||||
int32_t authTrustLevel;
|
||||
|
||||
int32_t module;
|
||||
uint32_t acquireInfo;
|
||||
bool extraInfoIsNull;
|
||||
int32_t result;
|
||||
Napi_AuthResult authResult;
|
||||
};
|
||||
|
||||
struct AuthUserInfo {
|
||||
AuthUserInfo() : asyncWork(nullptr) {};
|
||||
CallBackInfo callBackInfo;
|
||||
napi_callback_info info;
|
||||
napi_async_work asyncWork;
|
||||
napi_value jsFunction;
|
||||
napi_value onResultCallBack;
|
||||
napi_value onAcquireInfoCallBack;
|
||||
napi_value onResultData[ARGS_TWO];
|
||||
napi_value onAcquireInfoData[ARGS_THREE];
|
||||
int32_t userId;
|
||||
uint64_t challenge;
|
||||
int32_t authType;
|
||||
int32_t authTrustLevel;
|
||||
|
||||
int32_t module;
|
||||
uint32_t acquireInfo;
|
||||
bool extraInfoIsNull;
|
||||
int32_t result;
|
||||
Napi_AuthResult authResult;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif /* OHOS_USERAUTH_COMMON_H */
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 HILOG_WRAPPER_H
|
||||
#define HILOG_WRAPPER_H
|
||||
|
||||
#define CONFIG_HILOG
|
||||
#ifdef CONFIG_HILOG
|
||||
|
||||
#include "hilog/log.h"
|
||||
|
||||
#ifdef HILOG_FATAL
|
||||
#undef HILOG_FATAL
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_ERROR
|
||||
#undef HILOG_ERROR
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_WARN
|
||||
#undef HILOG_WARN
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_INFO
|
||||
#undef HILOG_INFO
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_DEBUG
|
||||
#undef HILOG_DEBUG
|
||||
#endif
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0, "UserAuthNapi===>"};
|
||||
|
||||
#define HILOG_FATAL(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LOG_LABEL, __VA_ARGS__)
|
||||
#define HILOG_ERROR(...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, __VA_ARGS__)
|
||||
#define HILOG_WARN(...) (void)OHOS::HiviewDFX::HiLog::Warn(LOG_LABEL, __VA_ARGS__)
|
||||
#define HILOG_INFO(...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, __VA_ARGS__)
|
||||
#define HILOG_DEBUG(...) (void)OHOS::HiviewDFX::HiLog::Debug(LOG_LABEL, __VA_ARGS__)
|
||||
#else
|
||||
|
||||
#define HILOG_FATAL(...)
|
||||
#define HILOG_ERROR(...)
|
||||
#define HILOG_WARN(...)
|
||||
#define HILOG_INFO(...)
|
||||
#define HILOG_DEBUG(...)
|
||||
|
||||
#endif // CONFIG_HILOG
|
||||
|
||||
#endif // HILOG_WRAPPER_H
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef AUTH_OBJECT_H
|
||||
#define AUTH_OBJECT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class Napi_ExecutorProperty {
|
||||
public:
|
||||
int32_t result_ = 0;
|
||||
int32_t authSubType_ = 0;
|
||||
uint32_t remainTimes_ = 0;
|
||||
uint32_t freezingTime_ = 0;
|
||||
};
|
||||
|
||||
class Napi_SetPropertyRequest {
|
||||
public:
|
||||
int32_t authType_ = 0;
|
||||
int32_t key_ = 0;
|
||||
std::vector<std::uint8_t> setInfo_;
|
||||
};
|
||||
|
||||
class Napi_GetPropertyRequest {
|
||||
public:
|
||||
int32_t authType_ = 0;
|
||||
std::vector<uint32_t> keys_;
|
||||
};
|
||||
|
||||
class Napi_AuthResult {
|
||||
public:
|
||||
std::vector<uint8_t> token_;
|
||||
uint32_t remainTimes_;
|
||||
uint32_t freezingTime_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif // AUTH_OBJECT_H
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 AUTHAPI_CALLBACK_H
|
||||
#define AUTHAPI_CALLBACK_H
|
||||
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include "userauth_callback.h"
|
||||
#include "userauth_info.h"
|
||||
|
||||
#include "auth_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class AuthApiCallback : public UserAuthCallback {
|
||||
public:
|
||||
AuthApiCallback();
|
||||
virtual ~AuthApiCallback();
|
||||
Napi_ExecutorProperty peoperty_;
|
||||
GetPropertyInfo *getPropertyInfo_;
|
||||
SetPropertyInfo *setPropertyInfo_;
|
||||
AuthInfo *authInfo_;
|
||||
AuthUserInfo *userInfo_;
|
||||
void onExecutorPropertyInfo(const ExecutorProperty result) override;
|
||||
void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override;
|
||||
void onResult(const int32_t result, const AuthResult extraInfo) override;
|
||||
void onSetExecutorProperty(const int32_t result) override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif // AUTHAPI_CALLBACK_H
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 RESULT_CONVERT_H
|
||||
#define RESULT_CONVERT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include "auth_common.h"
|
||||
#include "auth_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class ResultConvert {
|
||||
public:
|
||||
ResultConvert();
|
||||
~ResultConvert();
|
||||
std::vector<uint8_t> NapiGetValueUint8Array(napi_env env, napi_value jsObject, std::string key);
|
||||
napi_value BuildArrayExecutorProperty(napi_env env, Napi_ExecutorProperty property);
|
||||
napi_valuetype GetType(napi_env env, napi_value value);
|
||||
std::string GetStringValueByKey(napi_env env, napi_value jsObject, std::string key);
|
||||
int32_t NapiGetValueInt32(napi_env env, napi_value value);
|
||||
std::vector<uint32_t> GetInt32ArrayValueByKey(napi_env env, napi_value jsObject, std::string key);
|
||||
int32_t GetInt32ValueByKey(napi_env env, napi_value jsObject, std::string key);
|
||||
int NapiGetValueInt(napi_env env, napi_value value);
|
||||
void SetPropertyUint8Array(napi_env env, napi_value &jsObject, uint64_t value, std::string key);
|
||||
napi_value GetAuthInfoRet(napi_env env, uint64_t Ret);
|
||||
void SetPropertyUint8ArrayTest(napi_env env, napi_value &jsObject, std::vector<uint8_t> value, std::string key);
|
||||
std::vector<uint8_t> ConvertUint8(uint64_t value);
|
||||
napi_value BuildNapiUint8Array(napi_env env, std::vector<uint8_t> value);
|
||||
|
||||
private:
|
||||
void SetPropertyInt(napi_env env, napi_value &jsObject, int32_t value, std::string key);
|
||||
void SetPropertyUint(napi_env env, napi_value &jsObject, uint32_t value, std::string key);
|
||||
void SetPropertyBigint(napi_env env, napi_value &jsObject, uint64_t value, std::string key);
|
||||
std::string NapiGetValueString(napi_env env, napi_value value);
|
||||
napi_value GetNapiValue(napi_env env, const std::string keyChar, napi_value object);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif // RESULT_CONVERT_H
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FACERECOGNITION_PIN_AUTH_HELPER_H
|
||||
#define FACERECOGNITION_PIN_AUTH_HELPER_H
|
||||
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
/**
|
||||
* @brief Napi initialization
|
||||
*
|
||||
* @param env
|
||||
* @param exports
|
||||
*/
|
||||
void Init(napi_env env, napi_value exports);
|
||||
|
||||
/**
|
||||
* @brief Get the Ctor object
|
||||
*
|
||||
* @param env
|
||||
* @return napi_value UserAuth Instance
|
||||
*/
|
||||
napi_value GetCtor(napi_env env);
|
||||
/**
|
||||
* @brief Construction method
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value UserAuth Instance
|
||||
*/
|
||||
napi_value Constructor(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Instance passed to context
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Instance
|
||||
*/
|
||||
napi_value UserAuthServiceConstructor(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Get the Version object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Specific version number results
|
||||
*/
|
||||
napi_value GetVersion(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Get the Availabe Status object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Verify that the certification capability is available
|
||||
*/
|
||||
napi_value GetAvailabeStatus(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Get the Property object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value It supports querying subclasses / remaining authentication times / freezing time
|
||||
*/
|
||||
napi_value GetProperty(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Set the Property object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Set properties: can be used to initialize algorithms
|
||||
*/
|
||||
napi_value SetProperty(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief user authentication
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Enter the challenge value, authentication method, trust level and callback, and return the result
|
||||
* and acquireinfo through the callback
|
||||
*/
|
||||
napi_value Auth(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief user authentication
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Pass in the user ID, challenge value, authentication method, trust level and callback, and return
|
||||
* the result acquireinfo through the callback
|
||||
*/
|
||||
napi_value AuthUser(napi_env env, napi_callback_info info);
|
||||
|
||||
/**
|
||||
* @brief Cancel authentication
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value success or fail
|
||||
*/
|
||||
napi_value CancelAuth(napi_env env, napi_callback_info info);
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif // FACERECOGNITION_PIN_AUTH_HELPER_H
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FACERECOGNITION_USER_AUTH_H
|
||||
#define FACERECOGNITION_USER_AUTH_H
|
||||
|
||||
#include "auth_common.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthImpl {
|
||||
public:
|
||||
UserAuthImpl();
|
||||
~UserAuthImpl();
|
||||
|
||||
napi_value GetVersion(napi_env env, napi_callback_info info);
|
||||
napi_value GetVersion(napi_env env, GetVersionInfo *getVersionInfo);
|
||||
napi_value GetAvailabeStatus(napi_env env, napi_callback_info info);
|
||||
napi_value GetProperty(napi_env env, napi_callback_info info);
|
||||
napi_value SetProperty(napi_env env, napi_callback_info info);
|
||||
napi_value Auth(napi_env env, napi_callback_info info);
|
||||
napi_value AuthUser(napi_env env, napi_callback_info info);
|
||||
napi_value CancelAuth(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
napi_value GetPropertyWrap(napi_env env, napi_callback_info info, GetPropertyInfo *getPropertyInfo);
|
||||
napi_value GetPropertyAsync(napi_env env, GetPropertyInfo *getPropertyInfo);
|
||||
napi_value GetPropertyPromise(napi_env env, GetPropertyInfo *getPropertyInfo);
|
||||
|
||||
napi_value SetPropertyWrap(napi_env env, napi_callback_info info, SetPropertyInfo *setPropertyInfo);
|
||||
napi_value SetPropertyAsync(napi_env env, SetPropertyInfo *setPropertyInfo);
|
||||
napi_value SetPropertyPromise(napi_env env, SetPropertyInfo *setPropertyInfo);
|
||||
|
||||
napi_value AuthWrap(napi_env env, AuthInfo *authInfo);
|
||||
static void AuthExecute(napi_env env, void *data);
|
||||
static void AuthExecuteDone(napi_env env, napi_status status, void *data);
|
||||
napi_value AuthUserWrap(napi_env env, AuthUserInfo *userInfo);
|
||||
static void AuthUserExecute(napi_env env, void *data);
|
||||
static void AuthUserExecuteDone(napi_env env, napi_status status, void *data);
|
||||
static void AuthCallBack(napi_env env, AuthInfo *authInfo);
|
||||
static void AuthUserCallBack(napi_env env, AuthUserInfo *userInfo);
|
||||
|
||||
static void SetPropertyExecute(napi_env env, void *data);
|
||||
static void SetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data);
|
||||
static void SetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data);
|
||||
static void GetPropertyExecute(napi_env env, void *data);
|
||||
static void GetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data);
|
||||
static void GetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif // FACERECOGNITION_USER_AUTH_H
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "auth_build.h"
|
||||
|
||||
#include "auth_common.h"
|
||||
#include "auth_hilog_wrapper.h"
|
||||
#include "auth_object.h"
|
||||
#include "result_convert.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
AuthBuild::AuthBuild(void)
|
||||
{
|
||||
}
|
||||
AuthBuild::~AuthBuild()
|
||||
{
|
||||
}
|
||||
|
||||
Napi_SetPropertyRequest AuthBuild::SetPropertyRequestBuild(napi_env env, napi_value object)
|
||||
{
|
||||
Napi_SetPropertyRequest request;
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("SetPropertyRequestBuild object is null ");
|
||||
return request;
|
||||
}
|
||||
UserAuth::ResultConvert convert;
|
||||
request.authType_ = convert.GetInt32ValueByKey(env, object, "authType");
|
||||
request.key_ = convert.GetInt32ValueByKey(env, object, "key");
|
||||
request.setInfo_ = convert.NapiGetValueUint8Array(env, object, "setInfo");
|
||||
HILOG_INFO(" AuthBuild::SetPropertyRequestBuild authType = %{public}d", request.authType_);
|
||||
HILOG_INFO(" AuthBuild::SetPropertyRequestBuild key = %{public}d", request.key_);
|
||||
return request;
|
||||
}
|
||||
|
||||
Napi_GetPropertyRequest AuthBuild::GetPropertyRequestBuild(napi_env env, napi_value object)
|
||||
{
|
||||
Napi_GetPropertyRequest request;
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("GetPropertyRequestBuild object is null ");
|
||||
return request;
|
||||
}
|
||||
UserAuth::ResultConvert convert;
|
||||
request.authType_ = convert.GetInt32ValueByKey(env, object, "authType");
|
||||
request.keys_ = convert.GetInt32ArrayValueByKey(env, object, "keys");
|
||||
HILOG_INFO(" AuthBuild::GetPropertyRequestBuild authType = %{public}d", request.authType_);
|
||||
return request;
|
||||
}
|
||||
|
||||
napi_value AuthBuild::GetNapiExecutorProperty(napi_env env, Napi_ExecutorProperty property)
|
||||
{
|
||||
ResultConvert convert;
|
||||
return convert.BuildArrayExecutorProperty(env, property);
|
||||
}
|
||||
|
||||
bool AuthBuild::NapiTypeObject(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ResultConvert convert;
|
||||
napi_valuetype isObject = convert.GetType(env, value);
|
||||
if (isObject == napi_object) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthBuild::NapiTypeBitInt(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ResultConvert convert;
|
||||
napi_valuetype isBigInt = convert.GetType(env, value);
|
||||
if (isBigInt == napi_bigint) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthBuild::NapiTypeNumber(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
return false;
|
||||
}
|
||||
ResultConvert convert;
|
||||
napi_valuetype isNumber = convert.GetType(env, value);
|
||||
if (isNumber == napi_number) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
napi_value AuthBuild::BuildAuthResult(napi_env env, Napi_AuthResult authResult)
|
||||
{
|
||||
HILOG_INFO("BuildAuthResult start");
|
||||
napi_value object = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
|
||||
napi_value keyToken = nullptr;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, "token", NAPI_AUTO_LENGTH, &keyToken));
|
||||
|
||||
ResultConvert convert;
|
||||
napi_value token = convert.BuildNapiUint8Array(env, authResult.token_);
|
||||
NAPI_CALL(env, napi_set_property(env, object, keyToken, token));
|
||||
|
||||
napi_value keyRemainTimes = nullptr;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, "remainTimes", NAPI_AUTO_LENGTH, &keyRemainTimes));
|
||||
uint32_t remainTimes = authResult.remainTimes_;
|
||||
napi_value remainTimesValue = nullptr;
|
||||
NAPI_CALL(env, napi_create_uint32(env, remainTimes, &remainTimesValue));
|
||||
NAPI_CALL(env, napi_set_property(env, object, keyRemainTimes, remainTimesValue));
|
||||
|
||||
napi_value keyFreezingTime = nullptr;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, "freezingTime", NAPI_AUTO_LENGTH, &keyFreezingTime));
|
||||
uint32_t freezingTime = authResult.freezingTime_;
|
||||
napi_value freezingTimeValue = nullptr;
|
||||
NAPI_CALL(env, napi_create_uint32(env, freezingTime, &freezingTimeValue));
|
||||
NAPI_CALL(env, napi_set_property(env, object, keyFreezingTime, freezingTimeValue));
|
||||
HILOG_INFO("BuildAuthResult end");
|
||||
return object;
|
||||
}
|
||||
|
||||
void AuthBuild::AuthUserCallBackResult(napi_env env, AuthUserInfo *userInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start ", __func__);
|
||||
napi_status status;
|
||||
int32_t result = userInfo->result;
|
||||
napi_value dataResult = 0;
|
||||
status = napi_create_int32(env, result, &dataResult);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_int32 faild");
|
||||
}
|
||||
userInfo->onResultData[0] = dataResult;
|
||||
|
||||
napi_value resultExtraInfo = BuildAuthResult(env, userInfo->authResult);
|
||||
userInfo->onResultData[1] = resultExtraInfo;
|
||||
HILOG_INFO("%{public}s, end", __func__);
|
||||
}
|
||||
|
||||
void AuthBuild::AuthUserCallBackAcquireInfo(napi_env env, AuthUserInfo *userInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start ", __func__);
|
||||
napi_value jsModule = 0;
|
||||
napi_status status;
|
||||
int32_t jsModeValue = userInfo->module;
|
||||
status = napi_create_int32(env, jsModeValue, &jsModule);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_int32 faild");
|
||||
}
|
||||
userInfo->onAcquireInfoData[0] = jsModule;
|
||||
napi_value acquire = 0;
|
||||
uint32_t acquireValue = userInfo->acquireInfo;
|
||||
status = napi_create_uint32(env, acquireValue, &acquire);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_uint32 faild");
|
||||
}
|
||||
userInfo->onAcquireInfoData[1] = acquire;
|
||||
|
||||
if (userInfo->extraInfoIsNull) {
|
||||
napi_value result = 0;
|
||||
status = napi_get_null(env, &result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_null faild");
|
||||
}
|
||||
userInfo->onAcquireInfoData[ARGS_TWO] = result;
|
||||
} else {
|
||||
HILOG_INFO("%{public}s, extraInfo Is not Null ", __func__);
|
||||
napi_value result = 0;
|
||||
status = napi_get_null(env, &result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_null faild");
|
||||
}
|
||||
userInfo->onAcquireInfoData[ARGS_TWO] = result;
|
||||
}
|
||||
}
|
||||
|
||||
void AuthBuild::AuthCallBackAcquireInfo(napi_env env, AuthInfo *authInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start ", __func__);
|
||||
napi_status status;
|
||||
napi_value jsModule = 0;
|
||||
int32_t jsModeValue = authInfo->module;
|
||||
status = napi_create_int32(env, jsModeValue, &jsModule);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_int32 faild");
|
||||
}
|
||||
authInfo->onAcquireInfoData[0] = jsModule;
|
||||
napi_value acquire = 0;
|
||||
uint32_t acquireValue = authInfo->acquireInfo;
|
||||
status = napi_create_uint32(env, acquireValue, &acquire);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_uint32 faild");
|
||||
}
|
||||
authInfo->onAcquireInfoData[1] = acquire;
|
||||
|
||||
if (authInfo->extraInfoIsNull) {
|
||||
napi_value result = 0;
|
||||
status = napi_get_null(env, &result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_null faild");
|
||||
}
|
||||
authInfo->onAcquireInfoData[ARGS_TWO] = result;
|
||||
} else {
|
||||
HILOG_INFO("%{public}s, extraInfo Is not Null ", __func__);
|
||||
napi_value result = 0;
|
||||
status = napi_get_null(env, &result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_null faild");
|
||||
}
|
||||
authInfo->onAcquireInfoData[ARGS_TWO] = result;
|
||||
}
|
||||
HILOG_INFO("%{public}s, end", __func__);
|
||||
}
|
||||
|
||||
void AuthBuild::AuthCallBackResult(napi_env env, AuthInfo *authInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start ", __func__);
|
||||
napi_status status;
|
||||
int32_t result = authInfo->result;
|
||||
napi_value dataResult = 0;
|
||||
status = napi_create_int32(env, result, &dataResult);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_null faild");
|
||||
}
|
||||
authInfo->onResultData[0] = dataResult;
|
||||
|
||||
napi_value resultExtraInfo = BuildAuthResult(env, authInfo->authResult);
|
||||
authInfo->onResultData[1] = resultExtraInfo;
|
||||
HILOG_INFO("%{public}s, end", __func__);
|
||||
}
|
||||
|
||||
uint64_t AuthBuild::GetUint8ArrayTo64(napi_env env, napi_value value)
|
||||
{
|
||||
napi_typedarray_type arraytype;
|
||||
std::string challenge;
|
||||
size_t length = 0;
|
||||
napi_value buffer = nullptr;
|
||||
size_t offset = 0;
|
||||
uint8_t *data = nullptr;
|
||||
bool isTypedArray = false;
|
||||
napi_is_typedarray(env, value, &isTypedArray);
|
||||
if (isTypedArray) {
|
||||
HILOG_INFO("args[PIN_PARAMS_ONE] is a array");
|
||||
} else {
|
||||
HILOG_INFO("args[PIN_PARAMS_ONE] is not a uint8array");
|
||||
}
|
||||
napi_get_typedarray_info(env, value, &arraytype, &length, reinterpret_cast<void **>(&data), &buffer, &offset);
|
||||
if (arraytype == napi_uint8_array) {
|
||||
HILOG_INFO("InputerImpl, OnSetData get uint8 array ");
|
||||
} else {
|
||||
HILOG_ERROR("InputerImpl, OnSetData get uint8 array error");
|
||||
return 0;
|
||||
}
|
||||
if (offset != 0) {
|
||||
HILOG_INFO(" offset is =============>%{public}d", offset);
|
||||
return 0;
|
||||
}
|
||||
std::vector<uint8_t> result(data, data+length);
|
||||
challenge.assign(result.begin(), result.end());
|
||||
uint64_t resultUint64 = atol(challenge.c_str());
|
||||
return resultUint64;
|
||||
}
|
||||
|
||||
int AuthBuild::NapiGetValueInt(napi_env env, napi_value value)
|
||||
{
|
||||
ResultConvert convert;
|
||||
return convert.NapiGetValueInt(env, value);
|
||||
}
|
||||
napi_value AuthBuild::Uint64ToUint8Array(napi_env env, uint64_t value)
|
||||
{
|
||||
ResultConvert convert;
|
||||
return convert.BuildNapiUint8Array(env, convert.ConvertUint8(value));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <napi/native_api.h>
|
||||
#include "user_auth_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
static napi_value ModuleInit(napi_env env, napi_value exports)
|
||||
{
|
||||
OHOS::UserIAM::UserAuth::Init(env, exports);
|
||||
return exports;
|
||||
}
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module module = {.nm_version = 1, // NAPI v1
|
||||
.nm_flags = 0, // normal
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = ModuleInit,
|
||||
.nm_modname = "UserAuth",
|
||||
.nm_priv = nullptr,
|
||||
.reserved = {}};
|
||||
napi_module_register(&module);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "authapi_callback.h"
|
||||
|
||||
#include "auth_build.h"
|
||||
#include "auth_hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
AuthApiCallback::AuthApiCallback()
|
||||
{
|
||||
}
|
||||
|
||||
AuthApiCallback::~AuthApiCallback()
|
||||
{
|
||||
}
|
||||
|
||||
void AuthApiCallback::onExecutorPropertyInfo(const ExecutorProperty result)
|
||||
{
|
||||
napi_status status;
|
||||
HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 1 = %{public}d", result.result);
|
||||
peoperty_.result_ = result.result;
|
||||
HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 2 = %{public}d", result.authSubType);
|
||||
peoperty_.authSubType_ = result.authSubType;
|
||||
HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 3 = %{public}u", result.remainTimes);
|
||||
peoperty_.remainTimes_ = result.remainTimes;
|
||||
HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 4 = %{public}u", result.freezingTime);
|
||||
peoperty_.freezingTime_ = result.freezingTime;
|
||||
if (getPropertyInfo_ != nullptr) {
|
||||
AuthBuild authBuild;
|
||||
HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 5 ");
|
||||
getPropertyInfo_->result = authBuild.GetNapiExecutorProperty(getPropertyInfo_->callBackInfo.env, peoperty_);
|
||||
if (getPropertyInfo_->callBackInfo.callBack != nullptr) {
|
||||
HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 6 ");
|
||||
napi_value global = nullptr;
|
||||
status = napi_get_global(getPropertyInfo_->callBackInfo.env, &global);
|
||||
if (status != napi_ok) {
|
||||
HILOG_INFO("napi_get_global faild ");
|
||||
}
|
||||
napi_value resultData[1];
|
||||
resultData[0] = getPropertyInfo_->result;
|
||||
getPropertyInfo_->result = nullptr;
|
||||
napi_value result = nullptr;
|
||||
napi_value callBack = nullptr;
|
||||
status = napi_get_reference_value(
|
||||
getPropertyInfo_->callBackInfo.env, getPropertyInfo_->callBackInfo.callBack, &callBack);
|
||||
if (status != napi_ok) {
|
||||
HILOG_INFO("napi_get_reference_value faild ");
|
||||
}
|
||||
status = napi_call_function(getPropertyInfo_->callBackInfo.env, global, callBack, 1, resultData, &result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_INFO("napi_call_function faild ");
|
||||
}
|
||||
} else {
|
||||
napi_value result = getPropertyInfo_->result;
|
||||
napi_deferred deferred = getPropertyInfo_->callBackInfo.deferred;
|
||||
status = napi_resolve_deferred(getPropertyInfo_->callBackInfo.env, deferred, result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_INFO("napi_resolve_deferred faild ");
|
||||
}
|
||||
}
|
||||
delete getPropertyInfo_;
|
||||
getPropertyInfo_ = nullptr;
|
||||
} else {
|
||||
HILOG_INFO("AuthApiCallback onExecutorPropertyInfo getPropertyInfo_ is nullptr");
|
||||
}
|
||||
}
|
||||
|
||||
void AuthApiCallback::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo)
|
||||
{
|
||||
napi_status status;
|
||||
if (userInfo_ != nullptr) {
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 1");
|
||||
userInfo_->module = module;
|
||||
userInfo_->acquireInfo = acquireInfo;
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 2");
|
||||
if (extraInfo == 0) {
|
||||
userInfo_->extraInfoIsNull = true;
|
||||
} else {
|
||||
userInfo_->extraInfoIsNull = false;
|
||||
}
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 3");
|
||||
AuthBuild authBuild;
|
||||
authBuild.AuthUserCallBackAcquireInfo(userInfo_->callBackInfo.env, userInfo_);
|
||||
napi_value returnOnAcquire = nullptr;
|
||||
status = napi_call_function(userInfo_->callBackInfo.env, userInfo_->jsFunction, userInfo_->onAcquireInfoCallBack,
|
||||
ARGS_THREE, userInfo_->onAcquireInfoData, &returnOnAcquire);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_call_function faild");
|
||||
}
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ start 4");
|
||||
} else {
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo userInfo_ is nullptr ");
|
||||
}
|
||||
|
||||
if (authInfo_ != nullptr) {
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 1");
|
||||
authInfo_->module = module;
|
||||
authInfo_->acquireInfo = acquireInfo;
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 2");
|
||||
if (extraInfo == 0) {
|
||||
authInfo_->extraInfoIsNull = true;
|
||||
} else {
|
||||
authInfo_->extraInfoIsNull = false;
|
||||
}
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 3");
|
||||
AuthBuild authBuild;
|
||||
authBuild.AuthCallBackAcquireInfo(authInfo_->callBackInfo.env, authInfo_);
|
||||
napi_value callbackRef;
|
||||
status = napi_get_reference_value(authInfo_->callBackInfo.env, authInfo_->onAcquireInfoCallBack, &callbackRef);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_reference_value faild %{public}d", status);
|
||||
}
|
||||
napi_value returnOnAcquire = nullptr;
|
||||
status = napi_call_function(authInfo_->callBackInfo.env, authInfo_->jsFunction,
|
||||
callbackRef, ARGS_THREE, authInfo_->onAcquireInfoData, &returnOnAcquire);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_call_function faild");
|
||||
}
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ start 4");
|
||||
} else {
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo authInfo_ is nullptr ");
|
||||
}
|
||||
HILOG_INFO("AuthApiCallback onAcquireInfo end");
|
||||
}
|
||||
|
||||
void AuthApiCallback::onResult(const int32_t result, const AuthResult extraInfo)
|
||||
{
|
||||
napi_status status;
|
||||
if (userInfo_ != nullptr) {
|
||||
HILOG_INFO("AuthApiCallback onResult userInfo_");
|
||||
userInfo_->result = result;
|
||||
userInfo_->authResult.token_ = extraInfo.token;
|
||||
userInfo_->authResult.remainTimes_ = extraInfo.remainTimes;
|
||||
userInfo_->authResult.freezingTime_ = extraInfo.freezingTime;
|
||||
AuthBuild authBuild;
|
||||
authBuild.AuthUserCallBackResult(userInfo_->callBackInfo.env, userInfo_);
|
||||
napi_value return_val = nullptr;
|
||||
status = napi_call_function(userInfo_->callBackInfo.env, userInfo_->jsFunction,
|
||||
userInfo_->onResultCallBack, ARGS_TWO, userInfo_->onResultData, &return_val);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_call_function faild");
|
||||
}
|
||||
} else {
|
||||
HILOG_INFO("AuthApiCallback onResult userInfo_ is nullptr ");
|
||||
}
|
||||
if (authInfo_ != nullptr) {
|
||||
HILOG_INFO("AuthApiCallback onResult authInfo_");
|
||||
authInfo_->result = result;
|
||||
authInfo_->authResult.token_ = extraInfo.token;
|
||||
authInfo_->authResult.remainTimes_ = extraInfo.remainTimes;
|
||||
authInfo_->authResult.freezingTime_ = extraInfo.freezingTime;
|
||||
AuthBuild authBuild;
|
||||
authBuild.AuthCallBackResult(authInfo_->callBackInfo.env, authInfo_);
|
||||
napi_value return_val = nullptr;
|
||||
napi_value callbackRef;
|
||||
status = napi_get_reference_value(authInfo_->callBackInfo.env, authInfo_->onResultCallBack, &callbackRef);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_reference_value faild %{public}d", status);
|
||||
}
|
||||
status = napi_call_function(authInfo_->callBackInfo.env, authInfo_->jsFunction, callbackRef,
|
||||
ARGS_TWO, authInfo_->onResultData, &return_val);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_call_function faild %{public}d", status);
|
||||
}
|
||||
delete authInfo_;
|
||||
authInfo_ = nullptr;
|
||||
} else {
|
||||
HILOG_INFO("AuthApiCallback onResult authInfo_ is nullptr ");
|
||||
}
|
||||
HILOG_INFO("AuthApiCallback onResult end");
|
||||
}
|
||||
|
||||
void AuthApiCallback::onSetExecutorProperty(const int32_t result)
|
||||
{
|
||||
HILOG_INFO("onSetExecutorProperty 1 = %{public}d", result);
|
||||
napi_status status;
|
||||
if (setPropertyInfo_ != nullptr) {
|
||||
status = napi_create_int32(setPropertyInfo_->callBackInfo.env, result, &setPropertyInfo_->result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_int32 faild");
|
||||
}
|
||||
if (setPropertyInfo_->callBackInfo.callBack != nullptr) {
|
||||
napi_value global = nullptr;
|
||||
status = napi_get_global(setPropertyInfo_->callBackInfo.env, &global);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_global faild");
|
||||
}
|
||||
napi_value resultData[1];
|
||||
resultData[0] = setPropertyInfo_->result;
|
||||
setPropertyInfo_->result = nullptr;
|
||||
napi_value result = nullptr;
|
||||
napi_value callBack = nullptr;
|
||||
status = napi_get_reference_value(
|
||||
setPropertyInfo_->callBackInfo.env, setPropertyInfo_->callBackInfo.callBack, &callBack);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_reference_value faild");
|
||||
}
|
||||
status = napi_call_function(setPropertyInfo_->callBackInfo.env, global, callBack, 1, resultData, &result);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_call_function faild");
|
||||
}
|
||||
} else {
|
||||
napi_value result = setPropertyInfo_->result;
|
||||
napi_deferred deferred = setPropertyInfo_->callBackInfo.deferred;
|
||||
status = napi_resolve_deferred(setPropertyInfo_->callBackInfo.env, deferred, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,361 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "securec.h"
|
||||
#include "auth_hilog_wrapper.h"
|
||||
#include "result_convert.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
ResultConvert::ResultConvert(void)
|
||||
{
|
||||
}
|
||||
|
||||
ResultConvert::~ResultConvert()
|
||||
{
|
||||
}
|
||||
|
||||
napi_value ResultConvert::BuildArrayExecutorProperty(napi_env env, Napi_ExecutorProperty property)
|
||||
{
|
||||
napi_value jsObject = nullptr;
|
||||
napi_create_object(env, &jsObject);
|
||||
SetPropertyInt(env, jsObject, property.result_, "result");
|
||||
SetPropertyInt(env, jsObject, property.authSubType_, "authSubType");
|
||||
SetPropertyUint(env, jsObject, property.remainTimes_, "remainTimes");
|
||||
SetPropertyUint(env, jsObject, property.freezingTime_, "freezingTime");
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> ResultConvert::ConvertUint8(uint64_t value)
|
||||
{
|
||||
std::string number = std::to_string(value); // trimmed to fit
|
||||
int length = number.length();
|
||||
HILOG_INFO("ResultConvert ConvertUint8 strat result %{public}d", length);
|
||||
std::vector<uint8_t> uint8Array;
|
||||
for (int i = 0; i < length; i++) {
|
||||
char charVlaue = number.at(i);
|
||||
uint8_t result = (uint8_t)atoi(&charVlaue);
|
||||
HILOG_INFO("ResultConvert ConvertUint8 strat result %{public}u", result);
|
||||
uint8Array.push_back(result);
|
||||
}
|
||||
return uint8Array;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::BuildNapiUint8Array(napi_env env, std::vector<uint8_t> value)
|
||||
{
|
||||
HILOG_INFO("ResultConvert SetPropertyUint8ArrayTest strat ");
|
||||
void *data = nullptr;
|
||||
napi_value buffer = nullptr;
|
||||
NAPI_CALL(env, napi_create_arraybuffer(env, value.size(), &data, &buffer));
|
||||
if (memcpy_s(data, value.size(), value.data(), value.size()) != 0) {
|
||||
HILOG_INFO("ResultConvert SetPropertyUint8ArrayTest error");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value keyValue = nullptr;
|
||||
NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, value.size(), buffer, 0, &keyValue));
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
void ResultConvert::SetPropertyUint8ArrayTest(
|
||||
napi_env env, napi_value &jsObject, std::vector<uint8_t> value, std::string key)
|
||||
{
|
||||
napi_status status;
|
||||
napi_value keyValue = BuildNapiUint8Array(env, value);
|
||||
if (keyValue == nullptr) {
|
||||
status = napi_create_int64(env, -1, &keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_int64 faild");
|
||||
}
|
||||
}
|
||||
napi_value resultKey = nullptr;
|
||||
status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_string_utf8 faild");
|
||||
}
|
||||
status = napi_set_property(env, jsObject, resultKey, keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_set_property faild");
|
||||
}
|
||||
HILOG_INFO("ResultConvert SetPropertyUint8ArrayTest end");
|
||||
}
|
||||
|
||||
void ResultConvert::SetPropertyUint8Array(napi_env env, napi_value &jsObject, uint64_t value, std::string key)
|
||||
{
|
||||
HILOG_INFO("BuildArrayExecutorProperty SetPropertyUint8Array strat");
|
||||
napi_status status;
|
||||
napi_value keyValue = GetAuthInfoRet(env, value);
|
||||
napi_value resultKey = nullptr;
|
||||
status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_string_utf8 faild");
|
||||
}
|
||||
status = napi_set_property(env, jsObject, resultKey, keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_set_property faild");
|
||||
}
|
||||
HILOG_INFO("BuildArrayExecutorProperty SetPropertyUint8Array end");
|
||||
}
|
||||
|
||||
napi_value ResultConvert::GetAuthInfoRet(napi_env env, uint64_t Ret)
|
||||
{
|
||||
HILOG_INFO("GetAuthInfoRet strat");
|
||||
std::string RetCode = std::to_string(Ret);
|
||||
size_t bufefersize;
|
||||
void *cdata = nullptr;
|
||||
napi_value arrayBuffer = nullptr;
|
||||
const char *CCrets = RetCode.c_str();
|
||||
bufefersize = RetCode.size();
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env, napi_create_arraybuffer(env, bufefersize, &cdata, &arrayBuffer));
|
||||
if (memcpy_s(cdata, bufefersize, reinterpret_cast<const void *>(CCrets), bufefersize) != EOK) {
|
||||
HILOG_INFO("memcpy_s failed");
|
||||
}
|
||||
NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, bufefersize, arrayBuffer, 0, &result));
|
||||
HILOG_INFO("GetAuthInfoRet end");
|
||||
return result;
|
||||
}
|
||||
|
||||
void ResultConvert::SetPropertyInt(napi_env env, napi_value &jsObject, int32_t value, std::string key)
|
||||
{
|
||||
napi_status status;
|
||||
napi_value keyValue = 0;
|
||||
status = napi_create_int32(env, value, &keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_int32 faild");
|
||||
}
|
||||
napi_value resultKey = nullptr;
|
||||
status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_string_utf8 faild");
|
||||
}
|
||||
status = napi_set_property(env, jsObject, resultKey, keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_set_property faild");
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::SetPropertyUint(napi_env env, napi_value &jsObject, uint32_t value, std::string key)
|
||||
{
|
||||
napi_status status;
|
||||
napi_value keyValue = 0;
|
||||
status = napi_create_uint32(env, value, &keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_uint32 faild");
|
||||
}
|
||||
napi_value resultKey = nullptr;
|
||||
status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_string_utf8 faild");
|
||||
}
|
||||
status = napi_set_property(env, jsObject, resultKey, keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_set_property faild");
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::SetPropertyBigint(napi_env env, napi_value &jsObject, uint64_t value, std::string key)
|
||||
{
|
||||
napi_status status;
|
||||
napi_value keyValue = 0;
|
||||
status = napi_create_bigint_uint64(env, value, &keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_bigint_uint64 faild");
|
||||
}
|
||||
napi_value resultKey = nullptr;
|
||||
status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &resultKey);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_create_string_utf8 faild");
|
||||
}
|
||||
status = napi_set_property(env, jsObject, resultKey, keyValue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_set_property faild");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> ResultConvert::NapiGetValueUint8Array(napi_env env, napi_value jsObject, std::string key)
|
||||
{
|
||||
napi_value jsValue = GetNapiValue(env, key.c_str(), jsObject);
|
||||
std::vector<uint8_t> RetNull;
|
||||
if (jsValue == nullptr) {
|
||||
return RetNull;
|
||||
}
|
||||
napi_typedarray_type arraytype;
|
||||
size_t length = 0;
|
||||
napi_value buffer = nullptr;
|
||||
size_t offset = 0;
|
||||
uint8_t *data = nullptr;
|
||||
bool isTypedArray = false;
|
||||
napi_is_typedarray(env, jsValue, &isTypedArray);
|
||||
if (isTypedArray) {
|
||||
HILOG_INFO("args[PIN_PARAMS_ONE] is a array");
|
||||
} else {
|
||||
HILOG_INFO("args[PIN_PARAMS_ONE] is not a uint8array");
|
||||
}
|
||||
napi_get_typedarray_info(env, jsValue, &arraytype, &length, reinterpret_cast<void **>(&data), &buffer, &offset);
|
||||
if (arraytype == napi_uint8_array) {
|
||||
HILOG_INFO("InputerImpl, OnSetData get uint8 array ");
|
||||
} else {
|
||||
HILOG_ERROR("InputerImpl, OnSetData get uint8 array error");
|
||||
return RetNull;
|
||||
}
|
||||
if (offset != 0) {
|
||||
HILOG_INFO(" offset is =============>%{public}d", offset);
|
||||
return RetNull;
|
||||
}
|
||||
std::vector<uint8_t> result(data, data+length);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_valuetype ResultConvert::GetType(napi_env env, napi_value value)
|
||||
{
|
||||
napi_status status;
|
||||
if (value == nullptr) {
|
||||
return napi_null;
|
||||
}
|
||||
napi_valuetype type;
|
||||
status = napi_typeof(env, value, &type);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_typeof faild");
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
std::string ResultConvert::GetStringValueByKey(napi_env env, napi_value jsObject, std::string key)
|
||||
{
|
||||
napi_value value = GetNapiValue(env, key.c_str(), jsObject);
|
||||
std::string result = NapiGetValueString(env, value);
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t ResultConvert::GetInt32ValueByKey(napi_env env, napi_value jsObject, std::string key)
|
||||
{
|
||||
napi_value value = GetNapiValue(env, key.c_str(), jsObject);
|
||||
return NapiGetValueInt32(env, value);
|
||||
}
|
||||
|
||||
std::vector<uint32_t> ResultConvert::GetInt32ArrayValueByKey(napi_env env, napi_value jsObject, std::string key)
|
||||
{
|
||||
napi_status status;
|
||||
napi_value array = GetNapiValue(env, key.c_str(), jsObject);
|
||||
std::vector<uint32_t> values;
|
||||
if (array == nullptr) {
|
||||
return values;
|
||||
}
|
||||
std::vector<uint32_t>RetNull = {0};
|
||||
napi_typedarray_type arraytype;
|
||||
size_t length = 0;
|
||||
napi_value buffer = nullptr;
|
||||
size_t offset = 0;
|
||||
uint8_t *data = nullptr;
|
||||
bool isTypedArray = false;
|
||||
status = napi_is_typedarray(env, array, &isTypedArray);
|
||||
if (status != napi_ok) {
|
||||
HILOG_INFO("napi_is_typedarray is failed");
|
||||
}
|
||||
if (isTypedArray) {
|
||||
HILOG_INFO("args[PIN_PARAMS_ONE] is a array");
|
||||
} else {
|
||||
HILOG_INFO("args[PIN_PARAMS_ONE] is not a uint8array");
|
||||
return RetNull;
|
||||
}
|
||||
status = napi_get_typedarray_info(env, array, &arraytype, &length, reinterpret_cast<void **>(&data), &buffer, &offset);
|
||||
if (status != napi_ok) {
|
||||
HILOG_INFO("napi_get_typedarray_info is failed");
|
||||
}
|
||||
if (arraytype == napi_uint32_array) {
|
||||
HILOG_INFO("InputerImpl, OnSetData get uint8 array ");
|
||||
} else {
|
||||
HILOG_ERROR("InputerImpl, OnSetData get uint8 array error");
|
||||
return RetNull;
|
||||
}
|
||||
if (offset != 0) {
|
||||
HILOG_INFO(" offset is =============>%{public}d",offset);
|
||||
return RetNull;
|
||||
}
|
||||
std::vector<uint32_t>result(data, data + length);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ResultConvert::NapiGetValueString(napi_env env, napi_value value)
|
||||
{
|
||||
napi_status status;
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("AuthBuild NapiGetValueString value is nullptr");
|
||||
return "";
|
||||
}
|
||||
std::string resultValue = "";
|
||||
char valueString[NAPI_GET_STRING_SIZE];
|
||||
size_t valueSize = NAPI_GET_STRING_SIZE;
|
||||
size_t resultSize = 0;
|
||||
status =napi_get_value_string_utf8(env, value, valueString, valueSize, &resultSize);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_get_value_string_utf8 faild");
|
||||
}
|
||||
resultValue = valueString;
|
||||
if (resultValue == "") {
|
||||
HILOG_ERROR("ContactsBuild NapiGetValueString Data error");
|
||||
return "";
|
||||
}
|
||||
return resultValue;
|
||||
}
|
||||
|
||||
int32_t ResultConvert::NapiGetValueInt32(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
return GET_VALUE_ERROR;
|
||||
}
|
||||
int32_t result;
|
||||
napi_status status = napi_get_value_int32(env, value, &result);
|
||||
if (status != napi_ok) {
|
||||
return GET_VALUE_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ResultConvert::NapiGetValueInt(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
return GET_VALUE_ERROR;
|
||||
}
|
||||
int32_t result;
|
||||
napi_status status = napi_get_value_int32(env, value, &result);
|
||||
if (status != napi_ok) {
|
||||
return GET_VALUE_ERROR;
|
||||
}
|
||||
int ret = result;
|
||||
return ret;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::GetNapiValue(napi_env env, const std::string keyChar, napi_value object)
|
||||
{
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("ResultConvert::GetNapiValue object is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value key = nullptr;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, keyChar.c_str(), NAPI_AUTO_LENGTH, &key));
|
||||
bool result = false;
|
||||
NAPI_CALL(env, napi_has_property(env, object, key, &result));
|
||||
if (result) {
|
||||
napi_value value = nullptr;
|
||||
NAPI_CALL(env, napi_get_property(env, object, key, &value));
|
||||
return value;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "user_auth_helper.h"
|
||||
|
||||
#include "auth_hilog_wrapper.h"
|
||||
#include "user_auth_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
/**
|
||||
* @brief Instance passed to context
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Instance
|
||||
*/
|
||||
napi_value UserAuthServiceConstructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
std::shared_ptr<UserAuthImpl> userAuthImpl;
|
||||
userAuthImpl.reset(new UserAuthImpl());
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argc = 1;
|
||||
napi_value argv[1] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
|
||||
NAPI_CALL(env, napi_wrap(
|
||||
env, thisVar, userAuthImpl.get(),
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
UserAuthImpl *userAuthImpl = static_cast<UserAuthImpl *>(data);
|
||||
if (userAuthImpl != nullptr) {
|
||||
delete userAuthImpl;
|
||||
}
|
||||
},
|
||||
nullptr, nullptr));
|
||||
// Pull up the face service process
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Version object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Specific version number results
|
||||
*/
|
||||
napi_value GetVersion(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
HILOG_INFO("UserAuthHelper, GetVersion");
|
||||
return userAuthImpl->GetVersion(env, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Availabe Status object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Verify that the certification capability is available
|
||||
*/
|
||||
napi_value GetAvailabeStatus(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
HILOG_INFO("UserAuthHelper, getAvailabeStatus");
|
||||
return userAuthImpl->GetAvailabeStatus(env, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Property object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value It supports querying subclasses / remaining authentication times / freezing time
|
||||
*/
|
||||
napi_value GetProperty(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
HILOG_INFO("UserAuthHelper, GetProperty");
|
||||
return userAuthImpl->GetProperty(env, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the Property object
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Set properties: can be used to initialize algorithms
|
||||
*/
|
||||
napi_value SetProperty(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
HILOG_INFO("UserAuthHelper, SetProperty");
|
||||
return userAuthImpl->SetProperty(env, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief user authentication
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Enter the challenge value, authentication method, trust level and callback, and return the result
|
||||
* and acquireinfo through the callback
|
||||
*/
|
||||
napi_value Auth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
HILOG_INFO("UserAuthHelper, Auth");
|
||||
return userAuthImpl->Auth(env, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief user authentication
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value Pass in the user ID, challenge value, authentication method, trust level and callback, and return
|
||||
* the result acquireinfo through the callback
|
||||
*/
|
||||
napi_value AuthUser(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
HILOG_INFO("UserAuthHelper, AuthUser");
|
||||
return userAuthImpl->AuthUser(env, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cancel authentication
|
||||
*
|
||||
* @param env
|
||||
* @param info
|
||||
* @return napi_value success or fail
|
||||
*/
|
||||
napi_value CancelAuth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
size_t argcAsync = 0;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
|
||||
UserAuthImpl *userAuthImpl = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void **)&userAuthImpl));
|
||||
HILOG_INFO("UserAuthHelper, CancelAuth");
|
||||
return userAuthImpl->CancelAuth(env, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Napi initialization
|
||||
*
|
||||
* @param env
|
||||
* @param exports
|
||||
*/
|
||||
void Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_status status;
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_FUNCTION("constructor", UserAuth::Constructor),
|
||||
};
|
||||
status = napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_define_properties faild");
|
||||
}
|
||||
}
|
||||
|
||||
napi_value Constructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
napi_value userAuth = nullptr;
|
||||
NAPI_CALL(env, napi_new_instance(env, GetCtor(env), 0, nullptr, &userAuth));
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
return userAuth;
|
||||
}
|
||||
|
||||
napi_value GetCtor(napi_env env)
|
||||
{
|
||||
napi_value cons = nullptr;
|
||||
napi_property_descriptor clzDes[] = {
|
||||
DECLARE_NAPI_FUNCTION("getVersion", UserAuth::GetVersion),
|
||||
DECLARE_NAPI_FUNCTION("getAvailabeStatus", UserAuth::GetAvailabeStatus),
|
||||
DECLARE_NAPI_FUNCTION("getProperty", UserAuth::GetProperty),
|
||||
DECLARE_NAPI_FUNCTION("setProperty", UserAuth::SetProperty),
|
||||
DECLARE_NAPI_FUNCTION("auth", UserAuth::Auth),
|
||||
DECLARE_NAPI_FUNCTION("authUser", UserAuth::AuthUser),
|
||||
DECLARE_NAPI_FUNCTION("cancelAuth", UserAuth::CancelAuth),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_class(env, "UserAuth", NAPI_AUTO_LENGTH, UserAuthServiceConstructor, nullptr,
|
||||
sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
|
||||
return cons;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,490 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "user_auth_impl.h"
|
||||
|
||||
#include "user_auth.h"
|
||||
#include "userauth_callback.h"
|
||||
#include "userauth_info.h"
|
||||
|
||||
#include "auth_build.h"
|
||||
#include "auth_hilog_wrapper.h"
|
||||
#include "authapi_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
UserAuthImpl::UserAuthImpl()
|
||||
{
|
||||
}
|
||||
|
||||
UserAuthImpl::~UserAuthImpl()
|
||||
{
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::GetVersion(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("GetVersion start");
|
||||
int32_t result = UserAuth::GetInstance().GetVersion();
|
||||
HILOG_INFO("GetVersion result = %{public}d ", result);
|
||||
napi_value version = 0;
|
||||
NAPI_CALL(env, napi_create_int32(env, result, &version));
|
||||
return version;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::GetAvailabeStatus(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start", __func__);
|
||||
napi_value argv[ARGS_MAX_COUNT] = {nullptr};
|
||||
size_t argc = ARGS_MAX_COUNT;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
if (argc != ARGS_TWO) {
|
||||
HILOG_ERROR("%{public}s, parms error.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
AuthBuild authBuild;
|
||||
AuthType authType = AuthType(authBuild.NapiGetValueInt(env, argv[0]));
|
||||
HILOG_INFO("GetAvailabeStatus authType");
|
||||
AuthTurstLevel authTurstLevel = AuthTurstLevel(authBuild.NapiGetValueInt(env, argv[1]));
|
||||
HILOG_INFO("GetAvailabeStatus authTrustLevel");
|
||||
int32_t result = UserAuth::GetInstance().GetAvailableStatus(authType, authTurstLevel);
|
||||
napi_value ret = 0;
|
||||
NAPI_CALL(env, napi_create_int32(env, result, &ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::GetProperty(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GetPropertyInfo *getPropertyInfo = new (std::nothrow) GetPropertyInfo();
|
||||
getPropertyInfo->callBackInfo.env = env;
|
||||
return GetPropertyWrap(env, info, getPropertyInfo);
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::GetPropertyWrap(napi_env env, napi_callback_info info, GetPropertyInfo *getPropertyInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, called", __func__);
|
||||
size_t argcAsync = ARGS_TWO;
|
||||
const size_t argcPromise = ARGS_ONE;
|
||||
const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr));
|
||||
if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) {
|
||||
HILOG_ERROR("%{public}s, Wrong argument count.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
if (argcAsync > PARAM1) {
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_typeof(env, args[PARAM1], &valuetype);
|
||||
if (valuetype == napi_function) {
|
||||
NAPI_CALL(env, napi_create_reference(env, args[PARAM1], 1, &(getPropertyInfo->callBackInfo.callBack)));
|
||||
}
|
||||
}
|
||||
|
||||
// C++ need js parms get
|
||||
AuthBuild authBuild;
|
||||
if (authBuild.NapiTypeObject(env, args[0])) {
|
||||
Napi_GetPropertyRequest request = authBuild.GetPropertyRequestBuild(env, args[0]);
|
||||
getPropertyInfo->authType = request.authType_;
|
||||
getPropertyInfo->keys = request.keys_;
|
||||
}
|
||||
|
||||
napi_value ret = 0;
|
||||
if (argcAsync > argcPromise) {
|
||||
ret = GetPropertyAsync(env, getPropertyInfo);
|
||||
} else {
|
||||
ret = GetPropertyPromise(env, getPropertyInfo);
|
||||
}
|
||||
HILOG_INFO("%{public}s,end.", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UserAuthImpl::GetPropertyExecute(napi_env env, void *data)
|
||||
{
|
||||
HILOG_INFO("GetPropertyExecute, worker pool thread execute.");
|
||||
GetPropertyInfo *getPropertyInfo = static_cast<GetPropertyInfo *>(data);
|
||||
if (getPropertyInfo != nullptr) {
|
||||
// do something C++
|
||||
AuthBuild authBuild;
|
||||
AuthType authTypeGet = AuthType(getPropertyInfo->authType);
|
||||
|
||||
GetPropertyRequest request;
|
||||
request.authType = authTypeGet;
|
||||
request.keys = getPropertyInfo->keys;
|
||||
HILOG_INFO("GetPropertyExecute start 1");
|
||||
AuthApiCallback *object = new AuthApiCallback();
|
||||
object->getPropertyInfo_ = getPropertyInfo;
|
||||
std::shared_ptr<AuthApiCallback> callback;
|
||||
callback.reset(object);
|
||||
UserAuth::GetInstance().GetProperty(request, callback);
|
||||
} else {
|
||||
HILOG_ERROR("GetPropertyExecute, asynccallBackInfo == nullptr");
|
||||
}
|
||||
HILOG_INFO("GetPropertyExecute, worker pool thread execute end.");
|
||||
}
|
||||
|
||||
void UserAuthImpl::GetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
HILOG_INFO("GetPropertyPromiseExecuteDone, start");
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("GetPropertyPromiseExecuteDone status is not ok===>");
|
||||
return;
|
||||
}
|
||||
GetPropertyInfo *getPropertyInfo = static_cast<GetPropertyInfo *>(data);
|
||||
napi_delete_async_work(env, getPropertyInfo->asyncWork);
|
||||
HILOG_INFO("GetPropertyPromiseExecuteDone, end");
|
||||
}
|
||||
|
||||
void UserAuthImpl::GetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("SetPropertyAsyncExecuteDone status is not ok===>");
|
||||
return;
|
||||
}
|
||||
GetPropertyInfo *getPropertyInfo = static_cast<GetPropertyInfo *>(data);
|
||||
napi_delete_async_work(env, getPropertyInfo->asyncWork);
|
||||
HILOG_INFO("GetPropertyPromiseExecuteDone, end");
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::GetPropertyAsync(napi_env env, GetPropertyInfo *getPropertyInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, asyncCallback.", __func__);
|
||||
if (getPropertyInfo == nullptr) {
|
||||
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
napi_value resourceName = 0;
|
||||
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
|
||||
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, GetPropertyExecute, GetPropertyAsyncExecuteDone,
|
||||
(void *)getPropertyInfo, &getPropertyInfo->asyncWork));
|
||||
NAPI_CALL(env, napi_queue_async_work(env, getPropertyInfo->asyncWork));
|
||||
napi_value result = 0;
|
||||
NAPI_CALL(env, napi_get_null(env, &result));
|
||||
HILOG_INFO("%{public}s, asyncCallback end.", __func__);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::GetPropertyPromise(napi_env env, GetPropertyInfo *getPropertyInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, promise.", __func__);
|
||||
if (getPropertyInfo == nullptr) {
|
||||
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
napi_value resourceName = 0;
|
||||
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
|
||||
napi_deferred deferred;
|
||||
napi_value promise = 0;
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
getPropertyInfo->callBackInfo.callBack = nullptr;
|
||||
getPropertyInfo->callBackInfo.deferred = deferred;
|
||||
|
||||
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, GetPropertyExecute, GetPropertyPromiseExecuteDone,
|
||||
(void *)getPropertyInfo, &getPropertyInfo->asyncWork));
|
||||
NAPI_CALL(env, napi_queue_async_work(env, getPropertyInfo->asyncWork));
|
||||
HILOG_INFO("%{public}s, promise end.", __func__);
|
||||
return promise;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::SetProperty(napi_env env, napi_callback_info info)
|
||||
{
|
||||
SetPropertyInfo *setPropertyInfo = new (std::nothrow) SetPropertyInfo();
|
||||
setPropertyInfo->callBackInfo.env = env;
|
||||
return SetPropertyWrap(env, info, setPropertyInfo);
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::SetPropertyWrap(napi_env env, napi_callback_info info, SetPropertyInfo *setPropertyInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, called", __func__);
|
||||
size_t argcAsync = ARGS_TWO;
|
||||
const size_t argcPromise = ARGS_ONE;
|
||||
const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT;
|
||||
napi_value args[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, nullptr, nullptr));
|
||||
if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) {
|
||||
HILOG_ERROR("%{public}s, Wrong argument count.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
if (argcAsync > PARAM1) {
|
||||
napi_valuetype valuetype = napi_undefined;
|
||||
napi_typeof(env, args[PARAM1], &valuetype);
|
||||
if (valuetype == napi_function) {
|
||||
NAPI_CALL(env, napi_create_reference(env, args[PARAM1], 1, &(setPropertyInfo->callBackInfo.callBack)));
|
||||
}
|
||||
}
|
||||
|
||||
// C++ need js parms get
|
||||
AuthBuild authBuild;
|
||||
if (authBuild.NapiTypeObject(env, args[0])) {
|
||||
Napi_SetPropertyRequest request = authBuild.SetPropertyRequestBuild(env, args[0]);
|
||||
setPropertyInfo->authType = request.authType_;
|
||||
setPropertyInfo->key = request.key_;
|
||||
setPropertyInfo->setInfo = request.setInfo_;
|
||||
}
|
||||
|
||||
napi_value ret = 0;
|
||||
if (argcAsync > argcPromise) {
|
||||
ret = SetPropertyAsync(env, setPropertyInfo);
|
||||
} else {
|
||||
ret = SetPropertyPromise(env, setPropertyInfo);
|
||||
}
|
||||
HILOG_INFO("%{public}s,end.", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UserAuthImpl::SetPropertyExecute(napi_env env, void *data)
|
||||
{
|
||||
HILOG_INFO("setPropertyExecute, worker pool thread execute.");
|
||||
SetPropertyInfo *setPropertyInfo = static_cast<SetPropertyInfo *>(data);
|
||||
if (setPropertyInfo != nullptr) {
|
||||
// do something C++
|
||||
AuthBuild authBuild;
|
||||
AuthType authTypeGet = AuthType(setPropertyInfo->authType);
|
||||
|
||||
SetPropertyRequest request;
|
||||
request.authType = authTypeGet;
|
||||
request.key = SetPropertyType(setPropertyInfo->key);
|
||||
request.setInfo = setPropertyInfo->setInfo;
|
||||
HILOG_INFO("SetPropertyExecute start 1");
|
||||
AuthApiCallback *object = new AuthApiCallback();
|
||||
object->setPropertyInfo_ = setPropertyInfo;
|
||||
std::shared_ptr<AuthApiCallback> callback;
|
||||
callback.reset(object);
|
||||
callback->setPropertyInfo_ = setPropertyInfo;
|
||||
UserAuth::GetInstance().SetProperty(request, callback);
|
||||
} else {
|
||||
HILOG_ERROR("setPropertyExecute, asynccallBackInfo == nullptr");
|
||||
}
|
||||
HILOG_INFO("setPropertyExecute, worker pool thread execute end.");
|
||||
}
|
||||
|
||||
void UserAuthImpl::SetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
HILOG_INFO("SetPropertyPromiseExecuteDone, start");
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("SetPropertyPromiseExecuteDone status is not ok===>");
|
||||
return;
|
||||
}
|
||||
SetPropertyInfo *setPropertyInfo = static_cast<SetPropertyInfo *>(data);
|
||||
napi_delete_async_work(env, setPropertyInfo->asyncWork);
|
||||
delete setPropertyInfo;
|
||||
setPropertyInfo = nullptr;
|
||||
HILOG_INFO("SetPropertyPromiseExecuteDone, start");
|
||||
}
|
||||
|
||||
void UserAuthImpl::SetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("setPropertyAsyncExecuteDone status is not ok===>");
|
||||
return;
|
||||
}
|
||||
if (data != nullptr) {
|
||||
SetPropertyInfo *setPropertyInfo = static_cast<SetPropertyInfo *>(data);
|
||||
if (setPropertyInfo->asyncWork != nullptr) {
|
||||
napi_delete_async_work(env, setPropertyInfo->asyncWork);
|
||||
}
|
||||
delete setPropertyInfo;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::SetPropertyAsync(napi_env env, SetPropertyInfo *setPropertyInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, asyncCallback.", __func__);
|
||||
if (setPropertyInfo == nullptr) {
|
||||
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
napi_value resourceName = 0;
|
||||
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
|
||||
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, SetPropertyExecute, SetPropertyAsyncExecuteDone,
|
||||
(void *)setPropertyInfo, &setPropertyInfo->asyncWork));
|
||||
NAPI_CALL(env, napi_queue_async_work(env, setPropertyInfo->asyncWork));
|
||||
napi_value result = 0;
|
||||
NAPI_CALL(env, napi_get_null(env, &result));
|
||||
HILOG_INFO("%{public}s, asyncCallback end.", __func__);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::SetPropertyPromise(napi_env env, SetPropertyInfo *setPropertyInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, promise.", __func__);
|
||||
if (setPropertyInfo == nullptr) {
|
||||
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
napi_value resourceName = 0;
|
||||
NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
|
||||
napi_deferred deferred;
|
||||
napi_value promise = 0;
|
||||
NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
|
||||
setPropertyInfo->callBackInfo.callBack = nullptr;
|
||||
setPropertyInfo->callBackInfo.deferred = deferred;
|
||||
|
||||
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, SetPropertyExecute, SetPropertyPromiseExecuteDone,
|
||||
(void *)setPropertyInfo, &setPropertyInfo->asyncWork));
|
||||
NAPI_CALL(env, napi_queue_async_work(env, setPropertyInfo->asyncWork));
|
||||
HILOG_INFO("%{public}s, promise end.", __func__);
|
||||
return promise;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::Auth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start", __func__);
|
||||
AuthInfo *authInfo = new (std::nothrow) AuthInfo();
|
||||
authInfo->info = info;
|
||||
authInfo->callBackInfo.env = env;
|
||||
size_t argc = ARGS_MAX_COUNT;
|
||||
napi_value argv[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, authInfo->info, &argc, argv, nullptr, nullptr));
|
||||
if (argc != ARGS_FOUR) {
|
||||
HILOG_ERROR("%{public}s, parms error.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
AuthBuild authBuild;
|
||||
authInfo->challenge = authBuild.GetUint8ArrayTo64(env, argv[0]);
|
||||
|
||||
if (authBuild.NapiTypeNumber(env, argv[1])) {
|
||||
int64_t type;
|
||||
NAPI_CALL(env, napi_get_value_int64(env, argv[1], &type));
|
||||
authInfo->authType = type;
|
||||
}
|
||||
|
||||
if (authBuild.NapiTypeNumber(env, argv[ARGS_TWO])) {
|
||||
int64_t level;
|
||||
NAPI_CALL(env, napi_get_value_int64(env, argv[ARGS_TWO], &level));
|
||||
authInfo->authTrustLevel = level;
|
||||
}
|
||||
|
||||
if (authBuild.NapiTypeObject(env, argv[ARGS_THREE])) {
|
||||
HILOG_INFO("%{public}s, get callback function start.", __func__);
|
||||
authInfo->jsFunction = argv[ARGS_THREE];
|
||||
napi_value value;
|
||||
NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_THREE], "onResult", &value));
|
||||
NAPI_CALL(env, napi_create_reference(env, value, 1, &authInfo->onResultCallBack));
|
||||
NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_THREE], "onAcquireInfo", &value));
|
||||
NAPI_CALL(env, napi_create_reference(env, value, 1, &authInfo->onAcquireInfoCallBack));
|
||||
}
|
||||
return AuthWrap(env, authInfo);
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::AuthWrap(napi_env env, AuthInfo *authInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start.", __func__);
|
||||
if (authInfo == nullptr) {
|
||||
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
AuthBuild authBuild;
|
||||
AuthApiCallback *object = new AuthApiCallback();
|
||||
object->authInfo_ = authInfo;
|
||||
object->userInfo_ = nullptr;
|
||||
std::shared_ptr<AuthApiCallback> callback;
|
||||
callback.reset(object);
|
||||
uint64_t result = UserAuth::GetInstance().Auth(
|
||||
authInfo->challenge, AuthType(authInfo->authType), AuthTurstLevel(authInfo->authTrustLevel), callback);
|
||||
HILOG_INFO("UserAuth::GetInstance().Auth.result = %{public}llu", result);
|
||||
|
||||
// auth BigInt
|
||||
napi_value key = authBuild.Uint64ToUint8Array(env, result);
|
||||
HILOG_INFO("%{public}s, end.", __func__);
|
||||
// callback->authInfo_ = nullptr;
|
||||
// delete authInfo;
|
||||
return key;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::AuthUser(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start.", __func__);
|
||||
AuthUserInfo *userInfo = new (std::nothrow) AuthUserInfo();
|
||||
userInfo->callBackInfo.env = env;
|
||||
userInfo->info = info;
|
||||
size_t argc = ARGS_MAX_COUNT;
|
||||
napi_value argv[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, userInfo->info, &argc, argv, nullptr, nullptr));
|
||||
if (argc != ARGS_FIVE) {
|
||||
HILOG_ERROR("%{public}s, parms error.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
AuthBuild authBuild;
|
||||
if (authBuild.NapiTypeNumber(env, argv[0])) {
|
||||
int32_t id = 0;
|
||||
NAPI_CALL(env, napi_get_value_int32(env, argv[0], &id));
|
||||
userInfo->userId = id;
|
||||
}
|
||||
|
||||
userInfo->challenge = authBuild.GetUint8ArrayTo64(env, argv[1]);
|
||||
|
||||
if (authBuild.NapiTypeNumber(env, argv[ARGS_TWO])) {
|
||||
int32_t type = 0;
|
||||
napi_get_value_int32(env, argv[ARGS_TWO], &type);
|
||||
userInfo->authType = type;
|
||||
}
|
||||
|
||||
if (authBuild.NapiTypeNumber(env, argv[ARGS_THREE])) {
|
||||
int32_t level = 0;
|
||||
NAPI_CALL(env, napi_get_value_int32(env, argv[ARGS_THREE], &level));
|
||||
userInfo->authTrustLevel = level;
|
||||
}
|
||||
|
||||
if (authBuild.NapiTypeObject(env, argv[ARGS_FOUR])) {
|
||||
userInfo->jsFunction = argv[ARGS_FOUR];
|
||||
NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_FOUR], "onResult", &userInfo->onResultCallBack));
|
||||
NAPI_CALL(env, napi_get_named_property(env, argv[ARGS_FOUR], "onAcquireInfo",
|
||||
&userInfo->onAcquireInfoCallBack));
|
||||
}
|
||||
return AuthUserWrap(env, userInfo);
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::AuthUserWrap(napi_env env, AuthUserInfo *userInfo)
|
||||
{
|
||||
HILOG_INFO("%{public}s, start.", __func__);
|
||||
if (userInfo == nullptr) {
|
||||
HILOG_ERROR("%{public}s, param == nullptr.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
AuthApiCallback *object = new AuthApiCallback();
|
||||
object->authInfo_ = nullptr;
|
||||
object->userInfo_ = userInfo;
|
||||
std::shared_ptr<AuthApiCallback> callback;
|
||||
callback.reset(object);
|
||||
uint64_t result = UserAuth::GetInstance().AuthUser(userInfo->userId, userInfo->challenge,
|
||||
AuthType(userInfo->authType), AuthTurstLevel(userInfo->authTrustLevel), callback);
|
||||
HILOG_INFO("UserAuth::GetInstance().AuthUser. result = %{public}llu", result);
|
||||
AuthBuild authBuild;
|
||||
napi_value key = authBuild.Uint64ToUint8Array(env, result);
|
||||
HILOG_INFO("%{public}s, end.", __func__);
|
||||
callback->userInfo_ = nullptr;
|
||||
delete userInfo;
|
||||
return key;
|
||||
}
|
||||
|
||||
napi_value UserAuthImpl::CancelAuth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGS_MAX_COUNT;
|
||||
napi_value argv[ARGS_MAX_COUNT] = {nullptr};
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
|
||||
|
||||
AuthBuild authBuild;
|
||||
uint64_t contextId = authBuild.GetUint8ArrayTo64(env, argv[0]);
|
||||
HILOG_INFO("CancelAuth contextId = %{public}llu", contextId);
|
||||
|
||||
int32_t result = UserAuth::GetInstance().CancelAuth(contextId);
|
||||
HILOG_INFO("CancelAuth result = %{public}d", result);
|
||||
napi_value key = 0;
|
||||
NAPI_CALL(env, napi_create_int32(env, result, &key));
|
||||
return key;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,55 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
|
||||
config("userauth_private_config") {
|
||||
include_dirs = [
|
||||
"//utils/system/safwk/napi/include",
|
||||
#"${userauth_frameworks_path}/kitsimpl/include",
|
||||
"//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
]
|
||||
}
|
||||
|
||||
config("userauth_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("userauth_framework") {
|
||||
sources = [
|
||||
"../../../frameworks/kitsimpl/src/userauth_proxy.cpp",
|
||||
"../../../frameworks/kitsimpl/src/userauth.cpp",
|
||||
"../../../frameworks/kitsimpl/src/userauth_async_stub.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
"${userauth_utils_path}:utils_config",
|
||||
":userauth_private_config"
|
||||
]
|
||||
|
||||
public_configs = [ ":userauth_public_config" ]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"//base/useriam/coauth/interfaces/innerkits:coauth_framework",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "${userauth_native_part_name}"
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 IUSERAUTH_H
|
||||
#define IUSERAUTH_H
|
||||
|
||||
#include <iremote_broker.h>
|
||||
|
||||
#include "iuserauth_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class IUserAuth : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
USER_AUTH_GET_AVAILABLE_STATUS = 0,
|
||||
USER_AUTH_GET_PROPERTY,
|
||||
USER_AUTH_SET_PROPERTY,
|
||||
USER_AUTH_AUTH,
|
||||
USER_AUTH_AUTH_USER,
|
||||
USER_AUTH_CANCEL_AUTH,
|
||||
USER_AUTH_GET_VERSION,
|
||||
USER_AUTH_ONRESULT,
|
||||
USER_AUTH_GETEXPORP,
|
||||
USER_AUTH_SETEXPORP,
|
||||
USER_AUTH_ACQUIRENFO
|
||||
};
|
||||
|
||||
virtual int32_t GetAvailableStatus(const AuthType authType, AuthTurstLevel authTurstLevel) = 0;
|
||||
virtual void GetProperty(const GetPropertyRequest request, sptr<IUserAuthCallback> &callback) = 0;
|
||||
virtual void SetProperty(const SetPropertyRequest request, sptr<IUserAuthCallback> &callback) = 0;
|
||||
virtual uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
|
||||
sptr<IUserAuthCallback> &callback) = 0;
|
||||
virtual uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, sptr<IUserAuthCallback> &callback) = 0;
|
||||
virtual int32_t CancelAuth(const uint64_t contextId) = 0;
|
||||
virtual int32_t GetVersion() = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.UserAuth.IUserAuth");
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // IUSERAUTH_H
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 IUSERAUTH_CALLBACK_H
|
||||
#define IUSERAUTH_CALLBACK_H
|
||||
|
||||
#include <iremote_broker.h>
|
||||
#include <iremote_object.h>
|
||||
|
||||
#include "userauth_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class IUserAuthCallback : public IRemoteBroker {
|
||||
public:
|
||||
|
||||
virtual void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) = 0;
|
||||
virtual void onResult(const int32_t result, const AuthResult extraInfo) = 0;
|
||||
virtual void onExecutorPropertyInfo(const ExecutorProperty result) = 0;
|
||||
virtual void onSetExecutorProperty(const int32_t result) = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIAM.UserAuth.IUserAuthCallback");
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // IUSERAUTH_CALLBACK_H
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_CLIENT_H
|
||||
#define USERAUTH_CLIENT_H
|
||||
|
||||
#include <mutex>
|
||||
#include <singleton.h>
|
||||
#include <iremote_object.h>
|
||||
|
||||
#include "iuser_auth.h"
|
||||
#include "userauth_async_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuth : public DelayedRefSingleton<UserAuth> {
|
||||
DECLARE_DELAYED_REF_SINGLETON(UserAuth);
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(UserAuth);
|
||||
|
||||
int32_t GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel);
|
||||
void GetProperty(const GetPropertyRequest request, std::shared_ptr<UserAuthCallback> callback);
|
||||
void SetProperty(const SetPropertyRequest request, std::shared_ptr<UserAuthCallback> callback);
|
||||
uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
|
||||
std::shared_ptr<UserAuthCallback> callback);
|
||||
uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, std::shared_ptr<UserAuthCallback> callback);
|
||||
int32_t CancelAuth(const uint64_t contextId);
|
||||
int32_t GetVersion();
|
||||
|
||||
private:
|
||||
class UserAuthDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
UserAuthDeathRecipient() = default;
|
||||
~UserAuthDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(UserAuthDeathRecipient);
|
||||
};
|
||||
void ResetProxy(const wptr<IRemoteObject>& remote);
|
||||
sptr<IUserAuth> GetProxy();
|
||||
|
||||
std::mutex mutex_;
|
||||
sptr<IUserAuth> proxy_ {nullptr};
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_CLIENT_H
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_ASYNC_STUB_H
|
||||
#define USERAUTH_ASYNC_STUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include "iuserauth_callback.h"
|
||||
#include "userauth_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthAsyncStub : public IRemoteStub<IUserAuthCallback> {
|
||||
public:
|
||||
explicit UserAuthAsyncStub(std::shared_ptr<UserAuthCallback>& impl);
|
||||
~UserAuthAsyncStub() = default;
|
||||
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override;
|
||||
void onResult(const int32_t result, const AuthResult extraInfo) override;
|
||||
void onExecutorPropertyInfo(const ExecutorProperty result) override;
|
||||
void onSetExecutorProperty(const int32_t result) override;
|
||||
|
||||
private:
|
||||
int32_t onAcquireInfoStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t onResultStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t onExecutorPropertyInfoStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t onSetExecutorPropertyStub(MessageParcel& data, MessageParcel& reply);
|
||||
std::shared_ptr<UserAuthCallback> callback_ {nullptr};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // USERAUTH_ASYNC_STUB_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_CALLBACK_H
|
||||
#define USERAUTH_CALLBACK_H
|
||||
|
||||
#include "userauth_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthCallback {
|
||||
public:
|
||||
|
||||
virtual void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) = 0;
|
||||
virtual void onResult(const int32_t result, const AuthResult extraInfo) = 0;
|
||||
virtual void onExecutorPropertyInfo(const ExecutorProperty result) = 0;
|
||||
virtual void onSetExecutorProperty(const int32_t result) = 0;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // IUSERAUTH_CALLBACK_H
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_INFO_H
|
||||
#define USERAUTH_INFO_H
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
#define SIGN_LEN 32
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
// 认证的类型(口令,人脸)
|
||||
enum AuthType: uint32_t {
|
||||
PIN = 1,
|
||||
FACE = 2,
|
||||
};
|
||||
// 认证子类型(2D人脸,3D人脸...)
|
||||
enum AuthSubType: uint32_t {
|
||||
/**
|
||||
* Authentication sub type six number pin.
|
||||
*/
|
||||
PIN_SIX = 10000,
|
||||
/**
|
||||
* Authentication sub type self defined number pin.
|
||||
*/
|
||||
PIN_NUMBER = 10001,
|
||||
/**
|
||||
* Authentication sub type 2D face.
|
||||
*/
|
||||
PIN_MIXED = 10002,
|
||||
/**
|
||||
* Authentication sub type 2D face.
|
||||
*/
|
||||
FACE_2D = 20000,
|
||||
/**
|
||||
* Authentication sub type 3D face.
|
||||
*/
|
||||
FACE_3D = 20001
|
||||
};
|
||||
// 认证结果可信等级
|
||||
enum AuthTurstLevel: uint32_t {
|
||||
// level 1-4
|
||||
ATL1 = 10000,
|
||||
ATL2 = 20000,
|
||||
ATL3 = 30000,
|
||||
ATL4 = 40000
|
||||
};
|
||||
// 执行器属性列表
|
||||
enum GetPropertyType: uint32_t {
|
||||
// 认证子类型(此时认证类型已确认)
|
||||
AUTH_SUB_TYPE = 1,
|
||||
// 剩余认证次数
|
||||
REMAIN_TIMES = 2,
|
||||
// 冻结时间
|
||||
FREEZING_TIME = 3,
|
||||
};
|
||||
// 获得属性请求
|
||||
struct GetPropertyRequest {
|
||||
AuthType authType;
|
||||
// GetPropertyType
|
||||
std::vector<uint32_t> keys;
|
||||
};
|
||||
// 执行器属性
|
||||
struct ExecutorProperty {
|
||||
int32_t result;
|
||||
AuthSubType authSubType;
|
||||
uint32_t remainTimes;
|
||||
uint32_t freezingTime;
|
||||
};
|
||||
// 执行器属性列表
|
||||
enum AuthPropertyMode: uint32_t {
|
||||
PROPERMODE_DELETE = 0,
|
||||
PROPERMODE_GET = 1,
|
||||
PROPERMODE_SET = 2,
|
||||
PROPERMODE_FREEZE = 3,
|
||||
PROPERMODE_UNFREEZE = 4,
|
||||
};
|
||||
// 执行器属性列表
|
||||
enum SetPropertyType: uint32_t {
|
||||
INIT_ALGORITHM = 1,
|
||||
FREEZE_TEMPLATE = 2,
|
||||
THAW_TEMPLATE = 3,
|
||||
};
|
||||
struct SetPropertyRequest {
|
||||
AuthType authType;
|
||||
SetPropertyType key;
|
||||
std::vector<uint8_t> setInfo;
|
||||
};
|
||||
// 认证结果
|
||||
struct AuthResult {
|
||||
std::vector<uint8_t> token;
|
||||
uint32_t remainTimes;
|
||||
uint32_t freezingTime;
|
||||
};
|
||||
struct CoAuthInfo {
|
||||
AuthType authType;
|
||||
uint64_t callerID;
|
||||
uint64_t contextID;
|
||||
std::string pkgName;
|
||||
std::vector<uint64_t> sessionIds;
|
||||
};
|
||||
|
||||
struct FreezInfo {
|
||||
uint64_t callerID;
|
||||
std::string pkgName;
|
||||
int32_t resultCode;
|
||||
AuthType authType;
|
||||
};
|
||||
|
||||
// 结果码
|
||||
enum ResultCode: int32_t {
|
||||
/**
|
||||
* Indicates that authentication is success or ability is supported.
|
||||
*/
|
||||
SUCCESS = 0,
|
||||
/**
|
||||
* Indicates the authenticator fails to identify user.
|
||||
*/
|
||||
FAIL = 1,
|
||||
/**
|
||||
* Indicates other errors.
|
||||
*/
|
||||
GENERAL_ERROR = 2,
|
||||
/**
|
||||
* Indicates that authentication has been canceled.
|
||||
*/
|
||||
CANCELED = 3,
|
||||
/**
|
||||
* Indicates that authentication has timed out.
|
||||
*/
|
||||
TIMEOUT = 4,
|
||||
/**
|
||||
* Indicates that this authentication type is not supported.
|
||||
*/
|
||||
TYPE_NOT_SUPPORT = 5,
|
||||
/**
|
||||
* Indicates that the authentication trust level is not supported.
|
||||
*/
|
||||
TRUST_LEVEL_NOT_SUPPORT = 6,
|
||||
/**
|
||||
* Indicates that the authentication task is busy. Wait for a few seconds and try again.
|
||||
*/
|
||||
BUSY = 7,
|
||||
/**
|
||||
* Indicates incorrect parameters.
|
||||
*/
|
||||
INVALID_PARAMETERS = 8,
|
||||
/**
|
||||
* Indicates that the authenticator is locked.
|
||||
*/
|
||||
LOCKED = 9,
|
||||
/**
|
||||
* Indicates that the user has not enrolled the authenticator.
|
||||
*/
|
||||
NOT_ENROLLED = 10,
|
||||
/**
|
||||
* Indicates that IPC communication error.
|
||||
*/
|
||||
IPC_ERROR = 11,
|
||||
/**
|
||||
* Indicates that invalid contextId.
|
||||
*/
|
||||
INVALID_CONTEXTID = 12,
|
||||
/**
|
||||
* Indicates that WRITE PARCEL ERROR.
|
||||
*/
|
||||
E_WRITE_PARCEL_ERROR = 13,
|
||||
/**
|
||||
* Indicates that READ PARCEL ERROR
|
||||
*/
|
||||
E_READ_PARCEL_ERROR = 14,
|
||||
/**
|
||||
* Indicates that POWER SERVICE FAILED
|
||||
*/
|
||||
E_GET_POWER_SERVICE_FAILED = 15,
|
||||
/**
|
||||
* Indicates that executor schudle undone
|
||||
*/
|
||||
E_RET_UNDONE = 16,
|
||||
/**
|
||||
* Indicates that executor schudle undone
|
||||
*/
|
||||
E_RET_NOSERVER = 17,
|
||||
/**
|
||||
* ERRORCODE_MAX.
|
||||
*/
|
||||
ERRORCODE_MAX = 18
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_INFO_H
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_PROXY_H
|
||||
#define USERAUTH_PROXY_H
|
||||
|
||||
#include <iremote_proxy.h>
|
||||
#include "iuser_auth.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthProxy : public IRemoteProxy<IUserAuth> {
|
||||
public:
|
||||
explicit UserAuthProxy(const sptr<IRemoteObject> &impl);
|
||||
~UserAuthProxy() = default;
|
||||
|
||||
int32_t GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel) override;
|
||||
void GetProperty(const GetPropertyRequest request, sptr<IUserAuthCallback>& callback) override;
|
||||
void SetProperty(const SetPropertyRequest request, sptr<IUserAuthCallback>& callback) override;
|
||||
uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
|
||||
sptr<IUserAuthCallback>& callback) override;
|
||||
uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, sptr<IUserAuthCallback>& callback) override;
|
||||
int32_t CancelAuth(const uint64_t contextId) override;
|
||||
int32_t GetVersion() override;
|
||||
|
||||
private:
|
||||
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption option);
|
||||
static inline BrokerDelegator<UserAuthProxy> delegator_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_PROXY_H
|
||||
@@ -0,0 +1,59 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
## Build userauth.so {{{
|
||||
config("userauth_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include"
|
||||
]
|
||||
cflags = [ ]
|
||||
}
|
||||
|
||||
ohos_shared_library("userauthnorth") {
|
||||
sources = [
|
||||
"src/auth_native_module.cpp",
|
||||
"src/user_auth_helper_north.cpp",
|
||||
]
|
||||
|
||||
include_dirs=[
|
||||
"third_party/node/src"
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//base/useriam/userauth/interfaces/innerkits/napi:userauth",
|
||||
"${userauth_innerkits_path}/native:userauth_framework"
|
||||
]
|
||||
|
||||
public_configs = [ ":userauth_public_config" ]
|
||||
|
||||
external_deps = [
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
} else {
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
}
|
||||
|
||||
public_deps = []
|
||||
relative_install_dir = "module"
|
||||
part_name = "userauth"
|
||||
subsystem_name = "userauth"
|
||||
}
|
||||
## Build userauth.so }}}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FACERECOGNITION_PIN_AUTH_HELPER_NORTH_H
|
||||
#define FACERECOGNITION_PIN_AUTH_HELPER_NORTH_H
|
||||
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserAuthNorth {
|
||||
void Init(napi_env env, napi_value exports);
|
||||
napi_value Constructor(napi_env env, napi_callback_info info);
|
||||
napi_value GetCtor(napi_env env);
|
||||
} // namespace PinAuth
|
||||
} // namespace OHOS
|
||||
#endif // FACERECOGNITION_PIN_AUTH_HELPER_NORTH_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <napi/native_api.h>
|
||||
|
||||
#include "user_auth_helper_north.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserAuthNorth {
|
||||
static napi_value ModuleInit(napi_env env, napi_value exports)
|
||||
{
|
||||
OHOS::UserAuthNorth::Init(env, exports);
|
||||
return exports;
|
||||
}
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module module = {
|
||||
.nm_version = 1, // NAPI v1
|
||||
.nm_flags = 0, // normal
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = ModuleInit,
|
||||
.nm_modname = "UserAuthNorth",
|
||||
.nm_priv = nullptr,
|
||||
.reserved = {}
|
||||
};
|
||||
napi_module_register(&module);
|
||||
}
|
||||
} // namespace UserAuthNorth
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "user_auth_helper_north.h"
|
||||
|
||||
#include "auth_hilog_wrapper.h"
|
||||
#include "user_auth_impl.h"
|
||||
#include "user_auth_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserAuthNorth {
|
||||
napi_value Constructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
napi_value userAuth = nullptr;
|
||||
NAPI_CALL(env, napi_new_instance(env, GetCtor(env), 0, nullptr, &userAuth));
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
HILOG_INFO("UserAuthNorth, Constructor start");
|
||||
return userAuth;
|
||||
}
|
||||
|
||||
napi_value GetCtor(napi_env env)
|
||||
{
|
||||
napi_value cons = nullptr;
|
||||
napi_property_descriptor clzDes[] = {
|
||||
DECLARE_NAPI_FUNCTION("getVersion", UserIAM::UserAuth::GetVersion),
|
||||
DECLARE_NAPI_FUNCTION("getAvailabeStatus", UserIAM::UserAuth::GetAvailabeStatus),
|
||||
DECLARE_NAPI_FUNCTION("auth", UserIAM::UserAuth::Auth),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_class(env, "UserAuthNorth", NAPI_AUTO_LENGTH,
|
||||
UserIAM::UserAuth::UserAuthServiceConstructor, nullptr,
|
||||
sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
|
||||
return cons;
|
||||
}
|
||||
|
||||
void Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_status status;
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_FUNCTION("constructor", Constructor),
|
||||
};
|
||||
status = napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("napi_define_properties faild");
|
||||
}
|
||||
}
|
||||
} // namespace UserAuthNorth
|
||||
} // namespace OHOS
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"subsystem": "useriam",
|
||||
"parts": {
|
||||
"userauth": {
|
||||
"variants": [
|
||||
"wearable",
|
||||
"phone"
|
||||
],
|
||||
"module_list": [
|
||||
"//base/useriam/userauth/sa_profile:userauth_sa_profile",
|
||||
"//base/useriam/userauth/services:userauthservice",
|
||||
"//base/useriam/userauth/interfaces/innerkits/native:userauth_framework",
|
||||
"//base/useriam/userauth/interfaces/kits/napi:userauthnorth",
|
||||
"//base/useriam/userauth/interfaces/innerkits/napi:userauth"
|
||||
],
|
||||
"inner_kits": [
|
||||
|
||||
],
|
||||
"test_list": [
|
||||
"//base/useriam/userauth/test:userauth_native_test"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2021 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.
|
||||
-->
|
||||
<info>
|
||||
<process>useriam</process>
|
||||
<systemability>
|
||||
<name>5201</name>
|
||||
<libpath>libuserauthservice.z.so</libpath>
|
||||
<run-on-create>true</run-on-create>
|
||||
<distributed>false</distributed>
|
||||
<dump-level>1</dump-level>
|
||||
</systemability>
|
||||
</info>
|
||||
@@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
import("//build/ohos/sa_profile/sa_profile.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_sa_profile("userauth_sa_profile") {
|
||||
sources = [ "5201.xml" ]
|
||||
part_name = "${userauth_native_part_name}"
|
||||
}
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
|
||||
config("userauth_private_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//base/useriam/coauth/common/interface",
|
||||
# "//utils/system/safwk/native/include",
|
||||
# "//third_party/openssl/include/openssl",
|
||||
# "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("userauthservice") {
|
||||
sources = [
|
||||
"src/userauth_service.cpp",
|
||||
"src/userauth_adapter.cpp",
|
||||
"src/userauth_controller.cpp",
|
||||
"src/userauth_stub.cpp",
|
||||
"src/userauth_excallback_impl.cpp",
|
||||
"src/userauth_async_proxy.cpp",
|
||||
"src/userauth_datamgr.cpp",
|
||||
"src/context_thread_pool.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
"${userauth_utils_path}:utils_config",
|
||||
":userauth_private_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/useriam/coauth/interfaces/innerkits:coauth_framework",
|
||||
"//base/useriam/useridm/interfaces/innerkits:useridm_framework",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${userauth_innerkits_path}/native:userauth_framework",
|
||||
"//drivers/peripheral/display/hal:hdi_display_device",
|
||||
"//utils/native/base:utils",
|
||||
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
|
||||
"//base/useriam/coauth/common:useriam_common_lib",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "${userauth_native_part_name}"
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_THREADPOOL_H
|
||||
#define USERAUTH_THREADPOOL_H
|
||||
#include <stdint.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include "thread_pool.h"
|
||||
|
||||
#define THREADPOOLNAME "userauthThreadPool"
|
||||
#define THREADPOOLMAXSTART 3
|
||||
#define THREADPOOLMAXTASK 6
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class ContextThreadPool : ThreadPool {
|
||||
public:
|
||||
|
||||
static ContextThreadPool &GetInstance();
|
||||
uint32_t Start(int threadsNum)
|
||||
{
|
||||
return ThreadPool::Start(threadsNum);
|
||||
}
|
||||
void Stop()
|
||||
{
|
||||
ThreadPool::Stop();
|
||||
}
|
||||
|
||||
void SetMaxTaskNum(int maxSize)
|
||||
{
|
||||
ThreadPool::SetMaxTaskNum(maxSize);
|
||||
}
|
||||
|
||||
// for testability
|
||||
size_t GetMaxTaskNum() const
|
||||
{
|
||||
return ThreadPool::GetMaxTaskNum();
|
||||
}
|
||||
size_t GetCurTaskNum()
|
||||
{
|
||||
return ThreadPool::GetCurTaskNum();
|
||||
}
|
||||
size_t GetThreadsNum() const
|
||||
{
|
||||
return ThreadPool::GetThreadsNum();
|
||||
}
|
||||
|
||||
bool AddTask(const uint64_t context, const ThreadPool::Task& f);
|
||||
|
||||
void TaskFunction(const uint64_t context, const ThreadPool::Task& f);
|
||||
|
||||
private:
|
||||
class ContextTask {
|
||||
public:
|
||||
explicit ContextTask();
|
||||
~ContextTask();
|
||||
|
||||
ThreadPool::Task GetTask();
|
||||
|
||||
void AddTask(const ThreadPool::Task& f);
|
||||
private:
|
||||
std::vector<ThreadPool::Task> tasks;
|
||||
};
|
||||
explicit ContextThreadPool(const std::string &name);
|
||||
~ContextThreadPool();
|
||||
private:
|
||||
ThreadPool::Task CheckTask(const uint64_t context);
|
||||
std::map<uint64_t, ContextTask> ctMap_;
|
||||
std::mutex taskMutex_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_ADAPTER_H
|
||||
#define USERAUTH_ADAPTER_H
|
||||
|
||||
#include "userauth_info.h"
|
||||
#include "iuserauth_callback.h"
|
||||
#include "set_prop_callback.h"
|
||||
#include "auth_attributes.h"
|
||||
#include "co_auth.h"
|
||||
#include "context_thread_pool.h"
|
||||
#include "userauth_interface.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthAdapter {
|
||||
public:
|
||||
static UserAuthAdapter &GetInstance();
|
||||
int32_t GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel);
|
||||
|
||||
/* Get the executor authentication properties */
|
||||
void GetPropAuthInfo(uint64_t callerUID, std::string pkgName, GetPropertyRequest requset,
|
||||
sptr<IUserAuthCallback>& callback);
|
||||
|
||||
/** This method is called to set the executor properties
|
||||
* after the callback of the coAuth is called to obtain the scheduling token
|
||||
* and the authentication result is successful.
|
||||
* */
|
||||
void CoauthSetPropAuthInfo(int32_t resultCode, uint64_t callerUID, std::string pkgName, UserAuthToken authToken,
|
||||
SetPropertyRequest requset, sptr<IUserAuthCallback>& callback);
|
||||
|
||||
/* Set the executor authentication properties */
|
||||
void SetPropAuthInfo(uint64_t callerUID, std::string pkgName, int32_t resultCode, UserAuthToken authToken,
|
||||
SetPropertyRequest requset, std::vector<uint64_t> templateIds,
|
||||
sptr<IUserAuthCallback>& callback);
|
||||
void GetPropAuthInfoCoauth(uint64_t callerUID, std::string pkgName, int32_t resultCode, UserAuthToken authToken,
|
||||
GetPropertyRequest requset, sptr<IUserAuthCallback>& callback);
|
||||
int32_t GetUserID(int32_t &userID);
|
||||
int32_t GetCallerUid(uint64_t &callerUID);
|
||||
int32_t GetPkgName(std::string &pkgName);
|
||||
int32_t GenerateSolution(AuthSolution param, std::vector<uint64_t> &sessionIds);
|
||||
int32_t RequestAuthResult(uint64_t contextId, std::vector<uint8_t> scheduleToken,
|
||||
UserAuthToken &authToken, std::vector<uint64_t> &sessionIds);
|
||||
int32_t CancelContext(uint64_t contextId, std::vector<uint64_t> &sessionIds);
|
||||
int32_t Cancel(uint64_t sessionId);
|
||||
int32_t GetExecutorProp(uint64_t callerUID, std::string pkgName, uint64_t templateId, GetPropertyRequest requset,
|
||||
ExecutorProperty &result);
|
||||
int32_t SetExecutorProp(uint64_t callerUID, std::string pkgName, SetPropertyRequest requset,
|
||||
sptr<IUserAuthCallback>& callback);
|
||||
int32_t GetVersion();
|
||||
int32_t coAuth(CoAuthInfo coAuthInfo, sptr<IUserAuthCallback>& callback);
|
||||
|
||||
private:
|
||||
UserAuthAdapter() = default;
|
||||
~UserAuthAdapter() = default;
|
||||
int32_t GetEachExecutorProp(GetPropertyRequest &requset, ExecutorProperty &result, uint32_t &value,
|
||||
std::shared_ptr<OHOS::UserIAM::AuthResPool::AuthAttributes> pAuthAttributes);
|
||||
int32_t SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttributes &authAttributes,
|
||||
uint64_t callerUID, std::string pkgName,
|
||||
SetPropertyRequest requset, std::vector<uint64_t> templateIds,
|
||||
std::shared_ptr<CoAuth::SetPropCallback> &setPropCallback);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_ADAPTER_H
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_ASYNC_PROXY_H
|
||||
#define USERAUTH_ASYNC_PROXY_H
|
||||
|
||||
#include <iremote_proxy.h>
|
||||
|
||||
#include "useridm_callback.h"
|
||||
#include "iuserauth_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthAsyncProxy : public IRemoteProxy<IUserAuthCallback> {
|
||||
public:
|
||||
explicit UserAuthAsyncProxy(const sptr<IRemoteObject> &object)
|
||||
: IRemoteProxy<IUserAuthCallback>(object) {}
|
||||
~UserAuthAsyncProxy() = default;
|
||||
|
||||
void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override;
|
||||
void onResult(const int32_t result, const AuthResult extraInfo) override;
|
||||
void onExecutorPropertyInfo(const ExecutorProperty result) override;
|
||||
void onSetExecutorProperty(const int32_t result) override;
|
||||
|
||||
private:
|
||||
bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply);
|
||||
void WriteFailResult(const ExecutorProperty &result, ExecutorProperty &resultFail,
|
||||
MessageParcel &data);
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<UserAuthAsyncProxy> delegator_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_ASYNC_PROXY_H
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_CONTROLLER_H
|
||||
#define USERAUTH_CONTROLLER_H
|
||||
|
||||
#include "userauth_info.h"
|
||||
#include "userauth_adapter.h"
|
||||
#include "iuserauth_callback.h"
|
||||
#include "userauth_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthController {
|
||||
public:
|
||||
int32_t GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel);
|
||||
void GetPropAuthInfo(std::string pkgName, uint64_t callerUID, GetPropertyRequest getPropertyRequest,
|
||||
sptr<IUserAuthCallback>& callback);
|
||||
int32_t SetExecutorProp(uint64_t callerUID, std::string pkgName, SetPropertyRequest setPropertyrequest,
|
||||
sptr<IUserAuthCallback>& callback);
|
||||
int32_t GetUserID(int32_t &userID);
|
||||
int32_t GetCallerUid(uint64_t &callerUID);
|
||||
int32_t GetPkgName(std::string &pkgName);
|
||||
int32_t AddContextID(uint64_t contextID);
|
||||
int32_t IsContextIDExist(uint64_t contextID);
|
||||
int32_t GenerateContextID(uint64_t &contextID);
|
||||
int32_t DeleteContextID(uint64_t contextID);
|
||||
int32_t GenerateSolution(AuthSolution param, std::vector<uint64_t> &sessionIds);
|
||||
int32_t coAuth(CoAuthInfo coAuthInfo, sptr<IUserAuthCallback>& callback);
|
||||
int32_t CancelContext(uint64_t contextId, std::vector<uint64_t> &sessionIds);
|
||||
int32_t Cancel(uint64_t sessionId);
|
||||
int32_t GetVersion();
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_CONTROLLER_H
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_DATAMGR_H
|
||||
#define USERAUTH_DATAMGR_H
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include "iuserauth_callback.h"
|
||||
#include "userauth_adapter.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthDataMgr : public Singleton<UserAuthDataMgr> {
|
||||
public:
|
||||
static UserAuthDataMgr &GetInstance();
|
||||
int32_t AddContextID(uint64_t contextID);
|
||||
int32_t IsContextIDExist(uint64_t contextID);
|
||||
int32_t GenerateContextID(uint64_t &contextID);
|
||||
int32_t DeleteContextID(uint64_t contextID);
|
||||
|
||||
private:
|
||||
const int USERAUTH_RAND_BITS = 64;
|
||||
UserAuthDataMgr() = default;
|
||||
~UserAuthDataMgr() = default;
|
||||
std::mutex mutex_;
|
||||
std::set<uint64_t> contextIDs_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_DATAMGR_H
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_EXCALLBACK_IMPL_H
|
||||
#define USERAUTH_EXCALLBACK_IMPL_H
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "iuserauth_callback.h"
|
||||
#include "userauth_controller.h"
|
||||
#include "coauth_callback.h"
|
||||
#include "set_prop_callback.h"
|
||||
#include "useridm_callback.h"
|
||||
#include "useridm_info.h"
|
||||
#include "userauth_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthCallbackImplCoAuth : public CoAuth::CoAuthCallback {
|
||||
public:
|
||||
explicit UserAuthCallbackImplCoAuth(const sptr<IUserAuthCallback>& impl, CoAuthInfo coAuthInfo, bool resultFlag);
|
||||
virtual ~UserAuthCallbackImplCoAuth() = default;
|
||||
|
||||
void OnFinish(uint32_t resultCode, std::vector<uint8_t> &scheduleToken) override;
|
||||
void OnAcquireInfo(uint32_t acquire) override;
|
||||
void OnFinishHandle(uint32_t resultCode, std::vector<uint8_t> scheduleToken);
|
||||
void OnAcquireInfoHandle(uint32_t acquire);
|
||||
static int32_t SaveCoauthCallback(uint64_t contextId, std::shared_ptr<CoAuth::CoAuthCallback> coauthCallback);
|
||||
static int32_t DeleteCoauthCallback(uint64_t contextId);
|
||||
private:
|
||||
int32_t callbackCount_ = 0;
|
||||
int32_t callbackNowCount_ = 0;
|
||||
uint64_t callbackContextID_ = 0;
|
||||
std::string pkgName_ = "";
|
||||
uint64_t callerUid_ = 0;
|
||||
bool callbackResultFlag_ = false;
|
||||
sptr<IUserAuthCallback> callback_ { nullptr };
|
||||
AuthType authType_;
|
||||
std::mutex mutex_;
|
||||
static std::mutex coauthCallbackmutex_;
|
||||
static std::map<uint64_t, std::shared_ptr<CoAuth::CoAuthCallback>> saveCoauthCallback_;
|
||||
};
|
||||
|
||||
class UserAuthCallbackImplSetProp : public CoAuth::SetPropCallback {
|
||||
public:
|
||||
explicit UserAuthCallbackImplSetProp(const sptr<IUserAuthCallback>& impl);
|
||||
virtual ~UserAuthCallbackImplSetProp() = default;
|
||||
|
||||
void OnResult(uint32_t result, std::vector<uint8_t> &extraInfo) override;
|
||||
|
||||
private:
|
||||
sptr<IUserAuthCallback> callback_ { nullptr };
|
||||
};
|
||||
|
||||
class UserAuthCallbackImplSetPropFreez : public CoAuth::SetPropCallback {
|
||||
public:
|
||||
explicit UserAuthCallbackImplSetPropFreez(const sptr<IUserAuthCallback>& impl,
|
||||
std::vector<uint64_t> templateIds, UserAuthToken authToken, FreezInfo freezInfo);
|
||||
virtual ~UserAuthCallbackImplSetPropFreez() = default;
|
||||
|
||||
void OnResult(uint32_t result, std::vector<uint8_t> &extraInfo) override;
|
||||
|
||||
private:
|
||||
sptr<IUserAuthCallback> callback_ { nullptr };
|
||||
std::vector<uint64_t> templateIds_;
|
||||
int32_t resultCode_;
|
||||
UserAuthToken authToken_;
|
||||
AuthType authType_;
|
||||
std::string pkgName_;
|
||||
uint64_t callerUid_;
|
||||
};
|
||||
|
||||
class UserAuthCallbackImplIDMGetPorp : public UserIDM::GetInfoCallback {
|
||||
public:
|
||||
explicit UserAuthCallbackImplIDMGetPorp(const sptr<IUserAuthCallback>& impl,
|
||||
GetPropertyRequest requst, uint64_t callerUID, std::string pkgName);
|
||||
virtual ~UserAuthCallbackImplIDMGetPorp() = default;
|
||||
|
||||
void OnGetInfo(std::vector<UserIDM::CredentialInfo>& info) override;
|
||||
|
||||
private:
|
||||
sptr<IUserAuthCallback> callback_ { nullptr };
|
||||
GetPropertyRequest requst_;
|
||||
std::string pkgName_;
|
||||
uint64_t callerUid_;
|
||||
};
|
||||
|
||||
class UserAuthCallbackImplIDMCothGetPorpFreez : public UserIDM::GetInfoCallback {
|
||||
public:
|
||||
explicit UserAuthCallbackImplIDMCothGetPorpFreez(const sptr<IUserAuthCallback>& impl,
|
||||
uint64_t callerUid, std::string pkgName, int32_t resultCode,
|
||||
UserAuthToken authToken, SetPropertyRequest requset);
|
||||
virtual ~UserAuthCallbackImplIDMCothGetPorpFreez() = default;
|
||||
|
||||
void OnGetInfo(std::vector<UserIDM::CredentialInfo>& info) override;
|
||||
|
||||
private:
|
||||
sptr<IUserAuthCallback> callback_ { nullptr };
|
||||
UserAuthToken authToken_;
|
||||
int32_t resultCode_;
|
||||
SetPropertyRequest requset_;
|
||||
std::string pkgName_;
|
||||
uint64_t callerUid_;
|
||||
};
|
||||
|
||||
class UserAuthCallbackImplIDMGetPorpCoauth : public UserIDM::GetInfoCallback {
|
||||
public:
|
||||
explicit UserAuthCallbackImplIDMGetPorpCoauth(const sptr<IUserAuthCallback>& impl,
|
||||
uint64_t callerUid, std::string pkgName, int32_t resultCode, UserAuthToken authToken,
|
||||
GetPropertyRequest requset);
|
||||
virtual ~UserAuthCallbackImplIDMGetPorpCoauth() = default;
|
||||
|
||||
void OnGetInfo(std::vector<UserIDM::CredentialInfo>& info) override;
|
||||
|
||||
private:
|
||||
sptr<IUserAuthCallback> callback_ { nullptr };
|
||||
UserAuthToken authToken_;
|
||||
int32_t resultCode_;
|
||||
GetPropertyRequest requset_;
|
||||
std::string pkgName_;
|
||||
uint64_t callerUid_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_EXCALLBACK_IMPL_H
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_SERVICE_H
|
||||
#define USERAUTH_SERVICE_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <system_ability.h>
|
||||
#include <system_ability_definition.h>
|
||||
|
||||
#include "userauth_stub.h"
|
||||
#include "userauth_controller.h"
|
||||
#include "iuser_auth.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthService : public UserAuthStub, public SystemAbility {
|
||||
public:
|
||||
DECLARE_SYSTEM_ABILITY(UserAuthService);
|
||||
explicit UserAuthService(int32_t systemAbilityId, bool runOnCreate = false);
|
||||
~UserAuthService() override;
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
int32_t GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel) override;
|
||||
void GetProperty(const GetPropertyRequest request, sptr<IUserAuthCallback>& callback) override;
|
||||
void SetProperty(const SetPropertyRequest request, sptr<IUserAuthCallback>& callback) override;
|
||||
uint64_t Auth(const uint64_t challenge, const AuthType authType, const AuthTurstLevel authTurstLevel,
|
||||
sptr<IUserAuthCallback>& callback) override;
|
||||
uint64_t AuthUser(const int32_t userId, const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, sptr<IUserAuthCallback>& callback) override;
|
||||
int32_t CancelAuth(const uint64_t contextId) override;
|
||||
int32_t GetVersion() override;
|
||||
|
||||
private:
|
||||
int32_t GetControllerData(sptr<IUserAuthCallback>& callback, AuthResult &extraInfo,
|
||||
const AuthTurstLevel authTurstLevel, uint64_t &callerID,
|
||||
std::string &callerName, uint64_t &contextID);
|
||||
class UserAuthServiceCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
UserAuthServiceCallbackDeathRecipient(sptr<IUserAuthCallback>& impl);
|
||||
~UserAuthServiceCallbackDeathRecipient() = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
|
||||
|
||||
private:
|
||||
sptr<IUserAuthCallback> callback_ { nullptr };
|
||||
DISALLOW_COPY_AND_MOVE(UserAuthServiceCallbackDeathRecipient);
|
||||
};
|
||||
UserAuthController userauthController_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_SERVICE_H
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_STUB_H
|
||||
#define USERAUTH_STUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include "iuser_auth.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UserAuthStub : public IRemoteStub<IUserAuth> {
|
||||
public:
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
private:
|
||||
int32_t GetAvailableStatusStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t GetPropertyStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t SetPropertyStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t AuthStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t AuthUserStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t CancelAuthStub(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t GetVersionStub(MessageParcel& data, MessageParcel& reply);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USERAUTH_STUB_H
|
||||
Executable
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "context_thread_pool.h"
|
||||
#include "userauth_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
ContextThreadPool::ContextThreadPool(const std::string &name) : ThreadPool(name) {
|
||||
}
|
||||
|
||||
ContextThreadPool::~ContextThreadPool() {
|
||||
}
|
||||
|
||||
ContextThreadPool &ContextThreadPool::GetInstance()
|
||||
{
|
||||
static ContextThreadPool instance(THREADPOOLNAME);
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool ContextThreadPool::AddTask(const uint64_t context, const ThreadPool::Task& f)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "userauth AddTask is start!");
|
||||
std::lock_guard<std::mutex> taskMutexGuard(taskMutex_);
|
||||
if (ThreadPool::GetCurTaskNum() >= ThreadPool::GetMaxTaskNum()) {
|
||||
return false;
|
||||
}
|
||||
ContextTask contextTask;
|
||||
bool hasContextTask = false;
|
||||
if (ctMap_.count(context) != 0) {
|
||||
hasContextTask = true;
|
||||
contextTask = ctMap_[context];
|
||||
}
|
||||
auto task = std::bind(&ContextThreadPool::TaskFunction, this, context, f);
|
||||
if (!hasContextTask) {
|
||||
ThreadPool::AddTask(task);
|
||||
} else {
|
||||
contextTask.AddTask(task);
|
||||
}
|
||||
ctMap_[context] = contextTask;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ContextThreadPool::TaskFunction(const uint64_t context, const ThreadPool::Task& f)
|
||||
{
|
||||
f();
|
||||
ThreadPool::Task next = CheckTask(context);
|
||||
if (next != nullptr) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
ThreadPool::Task ContextThreadPool::CheckTask(const uint64_t context)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "userauth CheckTask is start!");
|
||||
std::lock_guard<std::mutex> taskMutexGuard(taskMutex_);
|
||||
if (ctMap_.count(context) != 0) {
|
||||
ContextTask contextTask = ctMap_[context];
|
||||
ThreadPool::Task next = contextTask.GetTask();
|
||||
ctMap_[context] = contextTask;
|
||||
if (next == nullptr) {
|
||||
ctMap_.erase(context);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ContextThreadPool::ContextTask::ContextTask() {
|
||||
}
|
||||
|
||||
ContextThreadPool::ContextTask::~ContextTask() {
|
||||
}
|
||||
|
||||
ThreadPool::Task ContextThreadPool::ContextTask::GetTask()
|
||||
{
|
||||
if (!tasks.empty()) {
|
||||
Task f = tasks.front();
|
||||
tasks.erase(tasks.begin());
|
||||
return f;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ContextThreadPool::ContextTask::AddTask(const ThreadPool::Task& f)
|
||||
{
|
||||
tasks.push_back(f);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,413 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "userauth_adapter.h"
|
||||
#include "userauth_common.h"
|
||||
#include "userauth_info.h"
|
||||
#include "auth_attributes.h"
|
||||
#include "co_auth.h"
|
||||
#include "useridm_client.h"
|
||||
#include "useridm_info.h"
|
||||
#include "userauth_datamgr.h"
|
||||
#include "userauth_excallback_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
const int32_t cUserId = 12345;
|
||||
const uint64_t cCallerUID = 0;
|
||||
|
||||
UserAuthAdapter &UserAuthAdapter::GetInstance()
|
||||
{
|
||||
static UserAuthAdapter instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetAuthTrustLevel is start!");
|
||||
int32_t ret = OHOS::UserIAM::UserAuth::GetAuthTrustLevel(userId, authType, authTrustLevel);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GetAuthTrustLevel ERROR!");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UserAuthAdapter::GetPropAuthInfo(uint64_t callerUID, std::string pkgName, GetPropertyRequest requset,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetPropAuthInfo is start!");
|
||||
|
||||
std::shared_ptr<UserIDM::GetInfoCallback> getInfoCallback =
|
||||
std::make_shared<UserAuthCallbackImplIDMGetPorp>(callback, requset, callerUID, pkgName);
|
||||
int32_t ret = UserIDM::UserIDMClient::GetInstance().GetAuthInfo(static_cast<UserIDM::AuthType>(requset.authType),
|
||||
getInfoCallback);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GetPropAuthInfo ERROR!");
|
||||
}
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetPropAuthInfo is end!");
|
||||
}
|
||||
|
||||
void UserAuthAdapter::SetPropAuthInfo(uint64_t callerUID, std::string pkgName, int32_t resultCode,
|
||||
UserAuthToken authToken, SetPropertyRequest requset,
|
||||
std::vector<uint64_t> templateIds,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth SetPropAuthInfo is start!");
|
||||
FreezInfo freezInfo;
|
||||
freezInfo.callerID = callerUID;
|
||||
freezInfo.authType = requset.authType;
|
||||
freezInfo.pkgName = pkgName;
|
||||
freezInfo.resultCode = resultCode;
|
||||
std::shared_ptr<CoAuth::SetPropCallback> setPropCallback =
|
||||
std::make_shared<UserAuthCallbackImplSetPropFreez>(callback, templateIds, authToken, freezInfo);
|
||||
OHOS::UserIAM::AuthResPool::AuthAttributes authAttributes;
|
||||
int32_t ret = SetProPropAuthInfo(authAttributes, callerUID, pkgName, requset, templateIds, setPropCallback);
|
||||
if (ret != SUCCESS) {
|
||||
return;
|
||||
}
|
||||
CoAuth::CoAuth::GetInstance().SetExecutorProp(authAttributes, setPropCallback);
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth SetPropAuthInfo is end!");
|
||||
}
|
||||
int32_t UserAuthAdapter::SetProPropAuthInfo(OHOS::UserIAM::AuthResPool::AuthAttributes &authAttributes,
|
||||
uint64_t callerUID, std::string pkgName,
|
||||
SetPropertyRequest requset, std::vector<uint64_t> templateIds,
|
||||
std::shared_ptr<CoAuth::SetPropCallback> &setPropCallback)
|
||||
{
|
||||
uint32_t value;
|
||||
int32_t ret = authAttributes.SetUint32Value(AUTH_TYPE, requset.authType);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_TYPE ERROR!");
|
||||
std::vector<uint8_t> extraInfo;
|
||||
setPropCallback->OnResult(ret, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
value = requset.key ==SetPropertyType::FREEZE_TEMPLATE ?
|
||||
static_cast<uint32_t>(AuthPropertyMode::PROPERMODE_FREEZE)
|
||||
: static_cast<uint32_t>(AuthPropertyMode::PROPERMODE_UNFREEZE);
|
||||
ret = authAttributes.SetUint32Value(AUTH_PROPERTY_MODE, value);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_PROPERTY_MODE ERROR!");
|
||||
std::vector<uint8_t> extraInfo;
|
||||
setPropCallback->OnResult(ret, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
ret = authAttributes.SetUint64Value(AUTH_CALLER_UID, callerUID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_CALLER_UID ERROR!");
|
||||
std::vector<uint8_t> extraInfo;
|
||||
setPropCallback->OnResult(ret, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
std::vector<uint8_t> pkgNameValue;
|
||||
pkgName.resize(pkgName.size());
|
||||
pkgNameValue.clear();
|
||||
pkgNameValue.assign(pkgName.begin(), pkgName.end());
|
||||
ret = authAttributes.SetUint8ArrayValue(AUTH_CALLER_NAME, pkgNameValue);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint8ArrayValue->AUTH_CALLER_NAME ERROR!");
|
||||
std::vector<uint8_t> extraInfo;
|
||||
setPropCallback->OnResult(ret, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
if (ret != SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
ret = authAttributes.SetUint64ArrayValue(AUTH_TEMPLATE_ID_LIST, templateIds);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint64ArrayValue AUTH_TEMPLATE_ID_LIST ERROR!");
|
||||
std::vector<uint8_t> extraInfo;
|
||||
setPropCallback->OnResult(ret, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
void UserAuthAdapter::GetPropAuthInfoCoauth(uint64_t callerUID, std::string pkgName, int32_t resultCode,
|
||||
UserAuthToken authToken, GetPropertyRequest requset,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetPropAuthInfoCoauth is start!");
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "GetPropertyRequest requset key is %{public}u!", requset.keys.front());
|
||||
std::shared_ptr<UserIDM::GetInfoCallback> getInfoCallback =
|
||||
std::make_shared<UserAuthCallbackImplIDMGetPorpCoauth>(callback, callerUID, pkgName, resultCode,
|
||||
authToken, requset);
|
||||
int32_t ret = UserIDM::UserIDMClient::GetInstance().GetAuthInfo(static_cast<UserIDM::AuthType>(requset.authType),
|
||||
getInfoCallback);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GetPropAuthInfoCoauth ERROR!");
|
||||
}
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetPropAuthInfoCoauth is end!");
|
||||
}
|
||||
|
||||
void UserAuthAdapter::CoauthSetPropAuthInfo(int32_t resultCode, uint64_t callerUID, std::string pkgName,
|
||||
UserAuthToken authToken, SetPropertyRequest requset,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth CoauthSetPropAuthInfo is start!");
|
||||
std::shared_ptr<UserIDM::GetInfoCallback> setPropCallback =
|
||||
std::make_shared<UserAuthCallbackImplIDMCothGetPorpFreez>(callback, callerUID, pkgName, resultCode,
|
||||
authToken, requset);
|
||||
int32_t ret = UserIDM::UserIDMClient::GetInstance().GetAuthInfo(static_cast<UserIDM::AuthType>(requset.authType),
|
||||
setPropCallback);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth CoauthSetPropAuthInfo ERROR!");
|
||||
}
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth CoauthSetPropAuthInfo is end!");
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GetUserID(int32_t &userID)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetUserID is start!");
|
||||
// 打桩 IAMTA
|
||||
userID = cUserId;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GetCallerUid(uint64_t &callerUID)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetCallerUid is start!");
|
||||
// 打桩 IAMTA
|
||||
callerUID = cCallerUID;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GetPkgName(std::string &pkgName)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetPkgName is start!");
|
||||
// 打桩 IAMTA
|
||||
pkgName = "CallerIsTest";
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GenerateSolution(AuthSolution param, std::vector<uint64_t> &sessionIds)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GenerateSolution is start!");
|
||||
int32_t ret = OHOS::UserIAM::UserAuth::GenerateSolution(param, sessionIds);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GenerateSolution ERROR!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::RequestAuthResult(uint64_t contextId, std::vector<uint8_t> scheduleToken,
|
||||
UserAuthToken &authToken, std::vector<uint64_t> &sessionIds)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth RequestAuthResult is start!");
|
||||
int32_t ret = OHOS::UserIAM::UserAuth::RequestAuthResult(contextId, scheduleToken, authToken, sessionIds);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth RequestAuthResult ERROR!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::CancelContext(uint64_t contextId, std::vector<uint64_t> &sessionIds)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth CancelContext is start!");
|
||||
int32_t ret = OHOS::UserIAM::UserAuth::CancelContext(contextId, sessionIds);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth CancelContext ERROR!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::Cancel(uint64_t sessionId)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth Cancel is start!");
|
||||
int32_t ret = CoAuth::CoAuth::GetInstance().Cancel(sessionId);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth Cancel ERROR!");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GetVersion()
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetVersion is start!");
|
||||
int32_t version = 1235;
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GetExecutorProp(uint64_t callerUID, std::string pkgName, uint64_t templateId,
|
||||
GetPropertyRequest requset, ExecutorProperty &result)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GetExecutorProp is start!");
|
||||
uint32_t value;
|
||||
|
||||
auto pAuthAttributes (std::make_shared<OHOS::UserIAM::AuthResPool::AuthAttributes>());
|
||||
OHOS::UserIAM::AuthResPool::AuthAttributes cAuthAttributes;
|
||||
int32_t ret = cAuthAttributes.SetUint32Value(AUTH_TYPE, requset.authType);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_TYPE ERROR!");
|
||||
return ret;
|
||||
}
|
||||
ret = cAuthAttributes.SetUint32Value(AUTH_PROPERTY_MODE, PROPERMODE_GET);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_PROPERTY_MODE ERROR!");
|
||||
result.result = ret;
|
||||
return ret;
|
||||
}
|
||||
ret = cAuthAttributes.SetUint64Value(AUTH_TEMPLATE_ID, templateId);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint64Value AUTH_TEMPLATE_ID ERROR!");
|
||||
result.result = ret;
|
||||
return ret;
|
||||
}
|
||||
ret = cAuthAttributes.SetUint64Value(AUTH_CALLER_UID, callerUID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_CALLER_UID ERROR!");
|
||||
return ret;
|
||||
}
|
||||
std::vector<uint8_t> pkgNameValue;
|
||||
pkgName.resize(pkgName.size());
|
||||
pkgNameValue.clear();
|
||||
pkgNameValue.assign(pkgName.begin(), pkgName.end());
|
||||
ret = cAuthAttributes.SetUint8ArrayValue(AUTH_CALLER_NAME, pkgNameValue);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint8ArrayValue->AUTH_CALLER_NAME ERROR!");
|
||||
result.result = ret;
|
||||
return ret;
|
||||
}
|
||||
ret = CoAuth::CoAuth::GetInstance().GetExecutorProp(cAuthAttributes, pAuthAttributes);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth CoAuth_->GetExecutorProp ERROR!");
|
||||
result.result = ret;
|
||||
return ret;
|
||||
}
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "GetPropertyRequest requset key is %{public}u!", requset.keys.front());
|
||||
if (GetEachExecutorProp(requset, result, value, pAuthAttributes) != SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
result.result = SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::GetEachExecutorProp(GetPropertyRequest &requset, ExecutorProperty &result, uint32_t &value,
|
||||
std::shared_ptr<OHOS::UserIAM::AuthResPool::AuthAttributes> pAuthAttributes)
|
||||
{
|
||||
uint64_t tmpValue;
|
||||
int32_t ret = SUCCESS;
|
||||
for (size_t i = 0; i < requset.keys.size(); i++) {
|
||||
//for (std::vector<uint32_t>::const_iterator iter = requset.keys.begin(); iter != requset.keys.end(); ++iter) {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "GetPropertyRequest *iter is %{public}u!", requset.keys[i]);
|
||||
switch (requset.keys[i]) {
|
||||
case AUTH_SUB_TYPE:
|
||||
ret = pAuthAttributes->GetUint64Value(AUTH_SUBTYPE, tmpValue);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "GetUint32Value->AUTH_SUBTYPE ERROR!");
|
||||
result.result = ret;
|
||||
return ret;
|
||||
}
|
||||
value = static_cast<uint32_t>(tmpValue);
|
||||
result.authSubType = static_cast<AuthSubType>(value);
|
||||
break;
|
||||
case AUTH_REMAIN_COUNT:
|
||||
ret = pAuthAttributes->GetUint32Value(AUTH_REMAIN_COUNT, result.remainTimes);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "GetUint32Value->AUTH_REMAIN_COUNT ERROR!");
|
||||
result.result = ret;
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case AUTH_REMAIN_TIME:
|
||||
ret = pAuthAttributes->GetUint32Value(AUTH_REMAIN_TIME, result.freezingTime);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "GetUint32Value->AUTH_REMAIN_TIME ERROR!");
|
||||
result.result = ret;
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "The key to get ExecutorProp is invalid.");
|
||||
result.result = INVALID_PARAMETERS;
|
||||
return INVALID_PARAMETERS;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::SetExecutorProp(uint64_t callerUID, std::string pkgName, SetPropertyRequest requset,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth SetExecutorProp is start!");
|
||||
|
||||
std::shared_ptr<CoAuth::SetPropCallback> setPropCallback = std::make_shared<UserAuthCallbackImplSetProp>(callback);
|
||||
OHOS::UserIAM::AuthResPool::AuthAttributes pAuthAttributes;
|
||||
int32_t ret = pAuthAttributes.SetUint32Value(AUTH_PROPERTY_MODE, PROPERMODE_SET);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value SET_AUTH_PROPERTY_MODE ERROR!");
|
||||
return ret;
|
||||
}
|
||||
ret = pAuthAttributes.SetUint64Value(AUTH_CALLER_UID, callerUID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_CALLER_UID ERROR!");
|
||||
return ret;
|
||||
}
|
||||
std::vector<uint8_t> pkgNameValue;
|
||||
pkgName.resize(pkgName.size());
|
||||
pkgNameValue.clear();
|
||||
pkgNameValue.assign(pkgName.begin(), pkgName.end());
|
||||
ret = pAuthAttributes.SetUint8ArrayValue(AUTH_CALLER_NAME, pkgNameValue);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint8ArrayValue->AUTH_CALLER_NAME ERROR!");
|
||||
return ret;
|
||||
}
|
||||
ret = pAuthAttributes.SetUint32Value(AUTH_TYPE, requset.authType);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint32Value AUTH_TYPE ERROR!");
|
||||
return ret;
|
||||
}
|
||||
ret = pAuthAttributes.SetUint8ArrayValue(AUTH_SIGNATURE, requset.setInfo);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SetUint8ArrayValue init ERROR!");
|
||||
return ret;
|
||||
}
|
||||
CoAuth::CoAuth::GetInstance().SetExecutorProp(pAuthAttributes, setPropCallback);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthAdapter::coAuth(CoAuthInfo coAuthInfo, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth coAuthHandle is start!");
|
||||
|
||||
std::shared_ptr<CoAuth::CoAuthCallback> coAuthCallback =
|
||||
std::make_shared<UserAuthCallbackImplCoAuth>(callback, coAuthInfo, false);
|
||||
OHOS::UserIAM::CoAuth::AuthInfo authInfo;
|
||||
int32_t ret = authInfo.SetPkgName(coAuthInfo.pkgName);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth pAuthInfo_ SetPkgName ERROR!");
|
||||
return ret;
|
||||
}
|
||||
ret = authInfo.SetCallerUid(coAuthInfo.callerID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth pAuthInfo_ SetCallerUid ERROR!");
|
||||
return ret;
|
||||
}
|
||||
ret = UserAuthCallbackImplCoAuth::SaveCoauthCallback(coAuthInfo.contextID, coAuthCallback);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth SaveCoauthCallback ERROR!");
|
||||
return ret;
|
||||
}
|
||||
for (std::vector<uint64_t>::iterator iter = coAuthInfo.sessionIds.begin();
|
||||
iter != coAuthInfo.sessionIds.end(); ++iter) {
|
||||
CoAuth::CoAuth::GetInstance().coAuth(*iter, authInfo, coAuthCallback);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
Executable
+214
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "userauth_async_proxy.h"
|
||||
#include "userauth_common.h"
|
||||
#include "iuser_auth.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
void UserAuthAsyncProxy::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "userauthAsyncProxy onAcquireInfo enter");
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth write descriptor failed!");
|
||||
return ;
|
||||
}
|
||||
if (!data.WriteInt32(module)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(module).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(acquireInfo)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(acquireInfo).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteInt32(extraInfo)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(extraInfo).");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_ACQUIRENFO, data, reply);
|
||||
if (ret) {
|
||||
int32_t result = reply.ReadInt32();
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result);
|
||||
}
|
||||
return;
|
||||
}
|
||||
void UserAuthAsyncProxy::onResult(const int32_t result, const AuthResult extraInfo)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "userauthAsyncProxy onResult enter");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
AuthResult extraInfoFail;
|
||||
if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGI(MODULE_SERVICE, "userauth write descriptor failed!");
|
||||
return ;
|
||||
}
|
||||
if (result != SUCCESS) {
|
||||
extraInfoFail.freezingTime = 0;
|
||||
extraInfoFail.remainTimes = 0;
|
||||
if (!data.WriteInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(result).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(extraInfoFail.token)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUInt8Vector(extraInfoFail.token).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(extraInfoFail.remainTimes)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to extraInfoFail.remainTimes.");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(extraInfoFail.freezingTime)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(extraInfoFail.freezingTime).");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!data.WriteInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(result).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(extraInfo.token)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUInt8Vector(extraInfo.token).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(extraInfo.remainTimes)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(extraInfo.remainTimes).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(extraInfo.freezingTime)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(extraInfo.freezingTime).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_ONRESULT, data, reply);
|
||||
if (ret) {
|
||||
int32_t result = reply.ReadInt32();
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void UserAuthAsyncProxy::onExecutorPropertyInfo(const ExecutorProperty result)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "userauthAsyncProxy onExecutorPropertyInfo enter");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
ExecutorProperty resultFail;
|
||||
if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGI(MODULE_SERVICE, "userauth write descriptor failed!");
|
||||
return ;
|
||||
}
|
||||
if (result.result != SUCCESS) {
|
||||
WriteFailResult(result, resultFail, data);
|
||||
} else {
|
||||
if (!data.WriteInt32(result.result)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(result.result).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(result.authSubType)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(result.authSubType).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(result.remainTimes)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(result.remainTimes).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(result.freezingTime)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(result.freezingTime).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_GETEXPORP, data, reply);
|
||||
if (ret) {
|
||||
int32_t result = reply.ReadInt32();
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void UserAuthAsyncProxy::WriteFailResult(const ExecutorProperty &result, ExecutorProperty &resultFail,
|
||||
MessageParcel &data)
|
||||
{
|
||||
resultFail.authSubType = PIN_SIX;
|
||||
resultFail.freezingTime = 0;
|
||||
resultFail.remainTimes = 0;
|
||||
if (!data.WriteInt32(result.result)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(result.result).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(resultFail.authSubType)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(resultFail.authSubType).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(resultFail.remainTimes)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(resultFail.remainTimes).");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUint32(resultFail.freezingTime)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(resultFail.freezingTime).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void UserAuthAsyncProxy::onSetExecutorProperty(const int32_t result)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "userauthAsyncProxy onSetExecutorProperty enter");
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
if (!data.WriteInterfaceToken(UserAuthAsyncProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth write descriptor failed!");
|
||||
return ;
|
||||
}
|
||||
if (!data.WriteInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(result).");
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_SETEXPORP, data, reply);
|
||||
if (ret) {
|
||||
int32_t result = reply.ReadInt32();
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth result = %{public}d", result);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool UserAuthAsyncProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "userauthAsyncProxy SendRequest enter");
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth failed to get remote.");
|
||||
return false;
|
||||
}
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
int32_t result = remote->SendRequest(code, data, reply, option);
|
||||
if (result != OHOS::UserIAM::UserAuth::SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "userauth failed to SendRequest.result = %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIAM
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "userauth_controller.h"
|
||||
#include "userauth_datamgr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
int32_t UserAuthController::GetAuthTrustLevel(int32_t userId, uint32_t authType, uint32_t &authTrustLevel)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().GetAuthTrustLevel(userId, authType, authTrustLevel);
|
||||
}
|
||||
int32_t UserAuthController::SetExecutorProp(uint64_t callerUID, std::string pkgName,
|
||||
SetPropertyRequest setPropertyrequest,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().SetExecutorProp(callerUID, pkgName, setPropertyrequest, callback);
|
||||
}
|
||||
void UserAuthController::GetPropAuthInfo(std::string pkgName, uint64_t callerUID,
|
||||
GetPropertyRequest getPropertyRequest,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
UserAuthAdapter::GetInstance().GetPropAuthInfo(callerUID, pkgName, getPropertyRequest, callback);
|
||||
}
|
||||
int32_t UserAuthController::GetUserID(int32_t &userID)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().GetUserID(userID);
|
||||
}
|
||||
int32_t UserAuthController::GetCallerUid(uint64_t &callerUID)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().GetCallerUid(callerUID);
|
||||
}
|
||||
int32_t UserAuthController::GetPkgName(std::string &pkgName)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().GetPkgName(pkgName);
|
||||
}
|
||||
int32_t UserAuthController::GenerateSolution(AuthSolution param, std::vector<uint64_t> &sessionIds)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().GenerateSolution(param, sessionIds);
|
||||
}
|
||||
int32_t UserAuthController::coAuth(CoAuthInfo coAuthInfo, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().coAuth(coAuthInfo, callback);
|
||||
}
|
||||
int32_t UserAuthController::CancelContext(uint64_t contextId, std::vector<uint64_t> &sessionIds)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().CancelContext(contextId, sessionIds);
|
||||
}
|
||||
int32_t UserAuthController::Cancel(uint64_t sessionId)
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().Cancel(sessionId);
|
||||
}
|
||||
int32_t UserAuthController::AddContextID(uint64_t contextID)
|
||||
{
|
||||
return UserAuthDataMgr::GetInstance().AddContextID(contextID);
|
||||
}
|
||||
int32_t UserAuthController::IsContextIDExist(uint64_t contextID)
|
||||
{
|
||||
return UserAuthDataMgr::GetInstance().IsContextIDExist(contextID);
|
||||
}
|
||||
int32_t UserAuthController::GenerateContextID(uint64_t &contextID)
|
||||
{
|
||||
return UserAuthDataMgr::GetInstance().GenerateContextID(contextID);
|
||||
}
|
||||
int32_t UserAuthController::DeleteContextID(uint64_t contextID)
|
||||
{
|
||||
return UserAuthDataMgr::GetInstance().DeleteContextID(contextID);
|
||||
}
|
||||
int32_t UserAuthController::GetVersion()
|
||||
{
|
||||
return UserAuthAdapter::GetInstance().GetVersion();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "userauth_datamgr.h"
|
||||
#include "userauth_common.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
UserAuthDataMgr &UserAuthDataMgr::GetInstance()
|
||||
{
|
||||
static UserAuthDataMgr instance;
|
||||
return instance;
|
||||
}
|
||||
int32_t UserAuthDataMgr::AddContextID(uint64_t contextID)
|
||||
{
|
||||
int32_t ret = SUCCESS;
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth AddContextID is start");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (contextIDs_.count(contextID) == 1) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth AddContextID error, because contextID is exist");
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
contextIDs_.insert(contextID);
|
||||
|
||||
return ret;
|
||||
}
|
||||
int32_t UserAuthDataMgr::IsContextIDExist(uint64_t contextID)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth IsContextIDExist is start");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (contextIDs_.count(contextID) == 1) {
|
||||
return SUCCESS;
|
||||
}
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
int32_t UserAuthDataMgr::GenerateContextID(uint64_t &contextID)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GenerateContextID is start");
|
||||
BIGNUM *btmp = BN_new();
|
||||
if (btmp == nullptr) {
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
do {
|
||||
if (!BN_rand(btmp, USERAUTH_RAND_BITS, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY)) {
|
||||
BN_free(btmp);
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GenerateContextID fail");
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
char *tmprand = BN_bn2dec(btmp);
|
||||
contextID = std::atoll(tmprand);
|
||||
} while ((contextIDs_.count(contextID) == 1) || (contextID == 0));
|
||||
BN_free(btmp);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
int32_t UserAuthDataMgr::DeleteContextID(uint64_t contextID)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth DeleteContextID is start");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (contextIDs_.count(contextID) == 0) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth ContextID invalid");
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
contextIDs_.erase(contextID);
|
||||
return SUCCESS;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 "userauth_excallback_impl.h"
|
||||
#include "userauth_common.h"
|
||||
#include "userauth_datamgr.h"
|
||||
#include "coauth_info_define.h"
|
||||
#include "userauth_async_proxy.h"
|
||||
#include "securec.h"
|
||||
|
||||
#include <iservice_registry.h>
|
||||
#include <system_ability_definition.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
std::mutex UserAuthCallbackImplCoAuth::coauthCallbackmutex_;
|
||||
std::map<uint64_t, std::shared_ptr<CoAuth::CoAuthCallback>> UserAuthCallbackImplCoAuth::saveCoauthCallback_;
|
||||
UserAuthCallbackImplSetProp::UserAuthCallbackImplSetProp(const sptr<IUserAuthCallback>& impl)
|
||||
{
|
||||
if (impl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplSetProp impl callback is Null");
|
||||
return ;
|
||||
}
|
||||
callback_ = impl;
|
||||
}
|
||||
void UserAuthCallbackImplSetProp::OnResult(uint32_t result, std::vector<uint8_t> &extraInfo)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplSetProp OnResult enter");
|
||||
|
||||
if (callback_ == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplSetProp callback_ is Null");
|
||||
} else {
|
||||
callback_->onSetExecutorProperty(result);
|
||||
}
|
||||
}
|
||||
|
||||
UserAuthCallbackImplSetPropFreez::UserAuthCallbackImplSetPropFreez(const sptr<IUserAuthCallback>& impl,
|
||||
std::vector<uint64_t> templateIds,
|
||||
UserAuthToken authToken, FreezInfo freezInfo)
|
||||
{
|
||||
callback_ = impl;
|
||||
templateIds_.clear();
|
||||
templateIds_.assign(templateIds.begin(), templateIds.end());
|
||||
resultCode_ = freezInfo.resultCode;
|
||||
authToken_ = authToken;
|
||||
authType_ = freezInfo.authType;
|
||||
pkgName_ = freezInfo.pkgName;
|
||||
callerUid_ = freezInfo.callerID;
|
||||
}
|
||||
void UserAuthCallbackImplSetPropFreez::OnResult(uint32_t result, std::vector<uint8_t> &extraInfo)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplSetPropFreez OnResult enter");
|
||||
int32_t ret = SUCCESS;
|
||||
AuthResult authResult;
|
||||
ExecutorProperty executorProperty;
|
||||
GetPropertyRequest getPropertyRequest;
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplSetPropFreez is fail");
|
||||
}
|
||||
|
||||
getPropertyRequest.authType = authType_;
|
||||
getPropertyRequest.keys.push_back(AuthAttributeType::AUTH_REMAIN_COUNT);
|
||||
getPropertyRequest.keys.push_back(AuthAttributeType::AUTH_REMAIN_TIME);
|
||||
if (callback_ == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplSetPropFreez callback_ is Null");
|
||||
return;
|
||||
} else {
|
||||
if (templateIds_.size() == 0) {
|
||||
callback_->onResult(GENERAL_ERROR, authResult);
|
||||
return;
|
||||
}
|
||||
ret = UserAuthAdapter::GetInstance().GetExecutorProp(callerUid_, pkgName_, templateIds_.front(),
|
||||
getPropertyRequest, executorProperty);
|
||||
if (ret != SUCCESS) {
|
||||
executorProperty.freezingTime = 0;
|
||||
executorProperty.remainTimes = 0;
|
||||
}
|
||||
|
||||
authResult.freezingTime = executorProperty.freezingTime;
|
||||
authResult.remainTimes = executorProperty.remainTimes;
|
||||
authResult.token.resize(sizeof(UserAuthToken));
|
||||
if (memcpy_s(&authResult.token[0], authResult.token.size(), &authToken_, sizeof(UserAuthToken)) != EOK) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "copy authToken_ error");
|
||||
}
|
||||
callback_->onResult(resultCode_, authResult);
|
||||
}
|
||||
}
|
||||
|
||||
UserAuthCallbackImplCoAuth::UserAuthCallbackImplCoAuth(const sptr<IUserAuthCallback>& impl,
|
||||
CoAuthInfo coAuthInfo, bool resultFlag)
|
||||
{
|
||||
if (impl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplCoAuth impl callback is Null");
|
||||
return ;
|
||||
}
|
||||
callback_ = impl;
|
||||
authType_ = coAuthInfo.authType;
|
||||
callbackCount_ = coAuthInfo.sessionIds.size();
|
||||
callbackContextID_ = coAuthInfo.contextID;
|
||||
pkgName_ = coAuthInfo.pkgName;
|
||||
callbackResultFlag_ = resultFlag;
|
||||
callerUid_ = coAuthInfo.callerID;
|
||||
}
|
||||
void UserAuthCallbackImplCoAuth::OnFinish(uint32_t resultCode, std::vector<uint8_t> &scheduleToken)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplCoAuth OnFinish enter");
|
||||
AuthResult authResult;
|
||||
std::vector<uint8_t> scheduleToken_;
|
||||
scheduleToken_.assign(scheduleToken.begin(), scheduleToken.end());
|
||||
auto task = std::bind(&UserAuthCallbackImplCoAuth::OnFinishHandle, this, resultCode, scheduleToken_);
|
||||
bool ret = ContextThreadPool::GetInstance().AddTask(callbackContextID_, task);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "OnFinish ContextThreadPool is BUSY");
|
||||
callback_->onResult(BUSY, authResult);
|
||||
callbackResultFlag_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
void UserAuthCallbackImplCoAuth::OnAcquireInfo(uint32_t acquire)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplCoAuth OnAcquireInfo enter");
|
||||
|
||||
auto task = std::bind(&UserAuthCallbackImplCoAuth::OnAcquireInfoHandle, this, acquire);
|
||||
bool ret = ContextThreadPool::GetInstance().AddTask(callbackContextID_, task);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "OnAcquireInfoHandle ContextThreadPool is BUSY");
|
||||
callbackResultFlag_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
void UserAuthCallbackImplCoAuth::OnFinishHandle(uint32_t resultCode, std::vector<uint8_t> scheduleToken)
|
||||
{
|
||||
UserAuthToken authToken;
|
||||
std::vector<uint64_t> sessionIds;
|
||||
SetPropertyRequest setPropertyRequest;
|
||||
GetPropertyRequest getPropertyRequest;
|
||||
AuthResult authResult;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "OnFinishHandle scheduleTokensize:%{public}d, resultCode:%{public}d",
|
||||
scheduleToken.size(), resultCode);
|
||||
callbackNowCount_++;
|
||||
if (callbackResultFlag_) {
|
||||
return;
|
||||
}
|
||||
int32_t ret = UserAuthAdapter::GetInstance().RequestAuthResult(callbackContextID_,
|
||||
scheduleToken, authToken, sessionIds);
|
||||
if (resultCode != LOCKED) {
|
||||
if (ret == E_RET_UNDONE) {
|
||||
if (callbackNowCount_ == callbackCount_) {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplCoAuth E_RET_UNDONE");
|
||||
UserAuthDataMgr::GetInstance().DeleteContextID(callbackContextID_);
|
||||
UserAuthCallbackImplCoAuth::DeleteCoauthCallback(callbackContextID_);
|
||||
callback_->onResult(GENERAL_ERROR, authResult);
|
||||
callbackResultFlag_ = true;
|
||||
}
|
||||
return ;
|
||||
} else if (ret == SUCCESS) {
|
||||
if (authType_ == UserAuth::PIN) {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "RequestAuthResult SUCCESS");
|
||||
setPropertyRequest.authType = authType_;
|
||||
setPropertyRequest.key = SetPropertyType::THAW_TEMPLATE;
|
||||
UserAuthAdapter::GetInstance().CoauthSetPropAuthInfo(ret, callerUid_, pkgName_,
|
||||
authToken, setPropertyRequest, callback_);
|
||||
} else {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "RequestAuthResult SUCCESS NOT INFO");
|
||||
authResult.token.resize(sizeof(UserAuthToken));
|
||||
if (memcpy_s(&authResult.token[0], authResult.token.size(), &authToken, sizeof(UserAuthToken)) != EOK) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "copy authToken error");
|
||||
}
|
||||
authResult.remainTimes = 0;
|
||||
authResult.freezingTime = 0;
|
||||
callback_->onResult(ret, authResult);
|
||||
}
|
||||
} else {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "RequestAuthResult NOT SUCCESS");
|
||||
getPropertyRequest.authType = authType_;
|
||||
getPropertyRequest.keys.push_back(UserAuth::REMAIN_TIMES);
|
||||
getPropertyRequest.keys.push_back(UserAuth::FREEZING_TIME);
|
||||
UserAuthAdapter::GetInstance().GetPropAuthInfoCoauth(callerUid_, pkgName_, ret,
|
||||
authToken, getPropertyRequest, callback_);
|
||||
}
|
||||
} else {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplCoAuth resultCode == LOCKED");
|
||||
setPropertyRequest.authType = authType_;
|
||||
setPropertyRequest.key = SetPropertyType::FREEZE_TEMPLATE;
|
||||
UserAuthAdapter::GetInstance().CoauthSetPropAuthInfo(ret, callerUid_, pkgName_, authToken, setPropertyRequest,
|
||||
callback_);
|
||||
}
|
||||
if (sessionIds.size() != 0) {
|
||||
for (std::vector<uint64_t>::iterator iter = sessionIds.begin(); iter != sessionIds.end(); ++iter) {
|
||||
UserAuthAdapter::GetInstance().Cancel(*iter);
|
||||
}
|
||||
}
|
||||
UserAuthDataMgr::GetInstance().DeleteContextID(callbackContextID_);
|
||||
UserAuthCallbackImplCoAuth::DeleteCoauthCallback(callbackContextID_);
|
||||
callbackResultFlag_ = true;
|
||||
}
|
||||
|
||||
void UserAuthCallbackImplCoAuth::OnAcquireInfoHandle(uint32_t acquire)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplCoAuth OnAcquireInfoHandle");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (callbackResultFlag_) {
|
||||
return;
|
||||
}
|
||||
int32_t module = static_cast<int32_t>(authType_);
|
||||
uint32_t acquireInfo = acquire;
|
||||
int32_t extraInfo = 0;
|
||||
callback_->onAcquireInfo(module, acquireInfo, extraInfo);
|
||||
}
|
||||
|
||||
int32_t UserAuthCallbackImplCoAuth::SaveCoauthCallback(uint64_t contextId, std::shared_ptr<CoAuth::CoAuthCallback> coauthCallback)
|
||||
{
|
||||
int32_t resultCode = SUCCESS;
|
||||
std::lock_guard<std::mutex> lock(coauthCallbackmutex_);
|
||||
saveCoauthCallback_.insert(std::make_pair(contextId, coauthCallback));
|
||||
if (saveCoauthCallback_.begin() != saveCoauthCallback_.end()) {
|
||||
resultCode = SUCCESS;
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "Save coauth callback success");
|
||||
} else {
|
||||
resultCode = FAIL;
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Save coauth callback failed");
|
||||
}
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
int32_t UserAuthCallbackImplCoAuth::DeleteCoauthCallback(uint64_t contextId)
|
||||
{
|
||||
int32_t resultCode = SUCCESS;
|
||||
std::lock_guard<std::mutex> lock(coauthCallbackmutex_);
|
||||
std::map<uint64_t, std::shared_ptr<CoAuth::CoAuthCallback>> ::iterator iter = saveCoauthCallback_.find(contextId);
|
||||
if (iter != saveCoauthCallback_.end()) {
|
||||
saveCoauthCallback_.erase(iter);
|
||||
resultCode = SUCCESS;
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "contextId XXXX%{public}04llx is deleted", contextId);
|
||||
} else {
|
||||
resultCode = FAIL;
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "contextId is not found and do not delete callback");
|
||||
}
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
UserAuthCallbackImplIDMGetPorp::UserAuthCallbackImplIDMGetPorp(const sptr<IUserAuthCallback>& impl,
|
||||
GetPropertyRequest requst, uint64_t callerUID,
|
||||
std::string pkgName)
|
||||
{
|
||||
if (impl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplIDMGetPorp impl callback is Null");
|
||||
return ;
|
||||
}
|
||||
callback_ = impl;
|
||||
requst_.authType = requst.authType;
|
||||
requst_.keys.clear();
|
||||
requst_.keys.assign(requst.keys.begin(), requst.keys.end());
|
||||
pkgName_ = pkgName;
|
||||
callerUid_ = callerUID;
|
||||
}
|
||||
void UserAuthCallbackImplIDMGetPorp::OnGetInfo(std::vector<UserIDM::CredentialInfo>& info)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplIDMGetPorp OnGetInfo enter");
|
||||
ExecutorProperty executorProperty;
|
||||
if (info.size() == 0) {
|
||||
executorProperty.result = GENERAL_ERROR;
|
||||
callback_->onExecutorPropertyInfo(executorProperty);
|
||||
return;
|
||||
}
|
||||
uint64_t tmp = info.begin()->templateId;
|
||||
UserAuthAdapter::GetInstance().GetExecutorProp(callerUid_, pkgName_, tmp, requst_, executorProperty);
|
||||
callback_->onExecutorPropertyInfo(executorProperty);
|
||||
}
|
||||
|
||||
UserAuthCallbackImplIDMCothGetPorpFreez::UserAuthCallbackImplIDMCothGetPorpFreez(
|
||||
const sptr<IUserAuthCallback>& impl, uint64_t callerUid, std::string pkgName, int32_t resultCode,
|
||||
UserAuthToken authToken, SetPropertyRequest requset)
|
||||
{
|
||||
if (impl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplIDMCothGetPorpFreez impl callback is Null");
|
||||
return ;
|
||||
}
|
||||
callback_ = impl;
|
||||
authToken_ = authToken;
|
||||
resultCode_ = resultCode;
|
||||
requset_ = requset;
|
||||
pkgName_ = pkgName;
|
||||
callerUid_ = callerUid;
|
||||
}
|
||||
void UserAuthCallbackImplIDMCothGetPorpFreez::OnGetInfo(std::vector<UserIDM::CredentialInfo>& info)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplIDMCothGetPorpFreez OnGetInfo enter");
|
||||
std::vector<uint64_t> templateIds;
|
||||
AuthResult authResult;
|
||||
if (info.size() == 0) {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplIDMCothGetPorpFreez OnGetInfo error");
|
||||
authResult.token.resize(sizeof(UserAuthToken));
|
||||
if (memcpy_s(&authResult.token[0], authResult.token.size(), &authToken_, sizeof(UserAuthToken)) != EOK) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "copy authToken_ error");
|
||||
}
|
||||
authResult.freezingTime = 0;
|
||||
authResult.remainTimes = 0;
|
||||
callback_->onResult(resultCode_, authResult);
|
||||
return;
|
||||
}
|
||||
templateIds.clear();
|
||||
for (std::vector<UserIDM::CredentialInfo>::const_iterator iter = info.begin(); iter != info.end(); ++iter) {
|
||||
templateIds.push_back((*iter).templateId);
|
||||
}
|
||||
UserAuthAdapter::GetInstance().SetPropAuthInfo(callerUid_, pkgName_, resultCode_, authToken_, requset_,
|
||||
templateIds, callback_);
|
||||
}
|
||||
|
||||
UserAuthCallbackImplIDMGetPorpCoauth::UserAuthCallbackImplIDMGetPorpCoauth(
|
||||
const sptr<IUserAuthCallback>& impl, uint64_t callerUid, std::string pkgName, int32_t resultCode,
|
||||
UserAuthToken authToken, GetPropertyRequest requset)
|
||||
{
|
||||
if (impl == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthCallbackImplIDMGetPorpCoauth impl callback is Null");
|
||||
return ;
|
||||
}
|
||||
callback_ = impl;
|
||||
authToken_ = authToken;
|
||||
resultCode_ = resultCode;
|
||||
requset_ = requset;
|
||||
pkgName_ = pkgName;
|
||||
callerUid_ = callerUid;
|
||||
}
|
||||
void UserAuthCallbackImplIDMGetPorpCoauth::OnGetInfo(std::vector<UserIDM::CredentialInfo>& info)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplIDMGetPorpCoauth OnGetInfo enter");
|
||||
int32_t ret = 0;
|
||||
ExecutorProperty executorProperty;
|
||||
AuthResult authResult;
|
||||
if (info.size() == 0) {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthCallbackImplIDMGetPorpCoauth OnGetInfo error");
|
||||
executorProperty.result = GENERAL_ERROR;
|
||||
authResult.token.resize(sizeof(UserAuthToken));
|
||||
if (memcpy_s(&authResult.token[0], authResult.token.size(), &authToken_, sizeof(UserAuthToken)) != EOK) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "copy authToken_ error");
|
||||
}
|
||||
authResult.freezingTime = 0;
|
||||
authResult.remainTimes = 0;
|
||||
callback_->onResult(resultCode_, authResult);
|
||||
return;
|
||||
}
|
||||
uint64_t tmp = info.begin()->templateId;
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "GetPropertyRequest requset key is %{public}u!", requset_.keys.front());
|
||||
ret = UserAuthAdapter::GetInstance().GetExecutorProp(callerUid_, pkgName_, tmp, requset_, executorProperty);
|
||||
if (ret != SUCCESS) {
|
||||
executorProperty.freezingTime = 0;
|
||||
executorProperty.remainTimes = 0;
|
||||
}
|
||||
authResult.freezingTime = executorProperty.freezingTime;
|
||||
authResult.remainTimes = executorProperty.remainTimes;
|
||||
authResult.token.resize(sizeof(UserAuthToken));
|
||||
if (memcpy_s(&authResult.token[0], authResult.token.size(), &authToken_, sizeof(UserAuthToken)) != EOK) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "copy authToken_ error");
|
||||
}
|
||||
callback_->onResult(resultCode_, authResult);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,362 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <file_ex.h>
|
||||
#include <string_ex.h>
|
||||
#include "userauth_common.h"
|
||||
#include "useriam_common.h"
|
||||
#include "userauth_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
REGISTER_SYSTEM_ABILITY_BY_ID(UserAuthService, USERAUTH_SERVICE_SA_ID, true);
|
||||
|
||||
UserAuthService::UserAuthService(int32_t systemAbilityId, bool runOnCreate)
|
||||
: SystemAbility(systemAbilityId, runOnCreate)
|
||||
{
|
||||
}
|
||||
|
||||
UserAuthService::~UserAuthService()
|
||||
{
|
||||
}
|
||||
|
||||
void UserAuthService::OnStart()
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "Start service");
|
||||
if (!Publish(this)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to publish service");
|
||||
}
|
||||
ContextThreadPool::GetInstance().Start(THREADPOOLMAXSTART);
|
||||
ContextThreadPool::GetInstance().SetMaxTaskNum(THREADPOOLMAXSTART);
|
||||
bool ret = OHOS::UserIAM::Common::IsIAMInited();
|
||||
if (!ret) {
|
||||
OHOS::UserIAM::Common::Init();
|
||||
}
|
||||
}
|
||||
|
||||
void UserAuthService::OnStop()
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "Stop service");
|
||||
ContextThreadPool::GetInstance().Stop();
|
||||
bool ret = OHOS::UserIAM::Common::IsIAMInited();
|
||||
if (ret) {
|
||||
int32_t iret = OHOS::UserIAM::Common::Close();
|
||||
if (iret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to Stop service");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t UserAuthService::GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService GetAvailableStatus is start");
|
||||
int ret = GENERAL_ERROR;
|
||||
int result = TRUST_LEVEL_NOT_SUPPORT;
|
||||
int32_t userID = 0;
|
||||
uint32_t authTurstLevelFromSys = 1;
|
||||
if (authTurstLevel > ATL4 || authTurstLevel < ATL1) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetAvailableStatus AuthTurstLevel is NOT SUPPORT!");
|
||||
return result;
|
||||
}
|
||||
|
||||
ret = userauthController_.GetUserID(userID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetAvailableStatus GetUserID is ERROR!");
|
||||
return result;
|
||||
}
|
||||
ret = userauthController_.GetAuthTrustLevel(userID, authType, authTurstLevelFromSys);
|
||||
if (ret == SUCCESS) {
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthService iAuthTurstLevel_:%{public}d", authTurstLevelFromSys);
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthService authTurstLevel:%{public}d", authTurstLevel);
|
||||
if (authTurstLevelFromSys < authTurstLevel) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService authTurstLevel is ERROR!");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UserAuthService::GetProperty(const GetPropertyRequest request, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService GetProperty is start");
|
||||
int ret = GENERAL_ERROR;
|
||||
uint64_t callerID = 0;
|
||||
std::string callerName;
|
||||
ExecutorProperty executorProperty;
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetProperty IUserAuthCallback is NULL!");
|
||||
return ;
|
||||
}
|
||||
|
||||
ret = userauthController_.GetCallerUid(callerID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetProperty getUserID is ERROR!");
|
||||
callback->onSetExecutorProperty(ret);
|
||||
return ;
|
||||
}
|
||||
ret = userauthController_.GetPkgName(callerName);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth GetPkgName is ERROR!");
|
||||
executorProperty.result = ret;
|
||||
callback->onExecutorPropertyInfo(executorProperty);
|
||||
return ;
|
||||
}
|
||||
sptr<IRemoteObject::DeathRecipient> dr = new UserAuthServiceCallbackDeathRecipient(callback);
|
||||
if ((!callback->AsObject()->AddDeathRecipient(dr))) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient UserAuthServiceCallbackDeathRecipient");
|
||||
}
|
||||
|
||||
userauthController_.GetPropAuthInfo(callerName, callerID, request, callback);
|
||||
}
|
||||
|
||||
void UserAuthService::SetProperty(const SetPropertyRequest request, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService SetProperty is start");
|
||||
int ret = GENERAL_ERROR;
|
||||
uint64_t callerID = 0;
|
||||
std::string callerName = "";
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService SetProperty IUserAuthCallback is NULL!");
|
||||
return ;
|
||||
}
|
||||
|
||||
ret = userauthController_.GetCallerUid(callerID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetProperty getUserID is ERROR!");
|
||||
callback->onSetExecutorProperty(ret);
|
||||
return ;
|
||||
}
|
||||
ret = userauthController_.GetPkgName(callerName);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth GetPkgName is ERROR!");
|
||||
callback->onSetExecutorProperty(ret);
|
||||
return ;
|
||||
}
|
||||
sptr<IRemoteObject::DeathRecipient> dr = new UserAuthServiceCallbackDeathRecipient(callback);
|
||||
if ((!callback->AsObject()->AddDeathRecipient(dr))) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient UserAuthServiceCallbackDeathRecipient");
|
||||
}
|
||||
ret = userauthController_.SetExecutorProp(callerID, callerName, request, callback);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService SetExecutorProp getUserID is ERROR!");
|
||||
callback->onSetExecutorProperty(ret);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService Auth is start");
|
||||
int ret = SUCCESS;
|
||||
int result = SUCCESS;
|
||||
int32_t userID = 0;
|
||||
uint64_t callerID = 0;
|
||||
std::string callerName = "";
|
||||
uint64_t contextID = 0;
|
||||
AuthSolution authSolutionParam;
|
||||
CoAuthInfo coAuthInfo;
|
||||
AuthResult extraInfo;
|
||||
if (GetControllerData(callback, extraInfo, authTurstLevel, callerID, callerName, contextID) == FAIL) {
|
||||
return ret;
|
||||
}
|
||||
result = userauthController_.GetUserID(userID);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth GetUserID is ERROR!");
|
||||
callback->onResult(FAIL, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
authSolutionParam.contextId = contextID;
|
||||
authSolutionParam.userId = userID;
|
||||
authSolutionParam.authTrustLevel = authTurstLevel;
|
||||
authSolutionParam.challenge = challenge;
|
||||
authSolutionParam.authType = authType;
|
||||
result = userauthController_.GenerateSolution(authSolutionParam, coAuthInfo.sessionIds);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth GenerateSolution is ERROR!");
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
coAuthInfo.authType = authType;
|
||||
coAuthInfo.callerID = callerID;
|
||||
coAuthInfo.contextID = contextID;
|
||||
coAuthInfo.pkgName = callerName;
|
||||
sptr<IRemoteObject::DeathRecipient> dr = new UserAuthServiceCallbackDeathRecipient(callback);
|
||||
if ((!callback->AsObject()->AddDeathRecipient(dr))) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient UserAuthServiceCallbackDeathRecipient");
|
||||
}
|
||||
result = userauthController_.coAuth(coAuthInfo, callback);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth coAuth is ERROR!");
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
return contextID;
|
||||
}
|
||||
|
||||
uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challenge,
|
||||
const AuthType authType, const AuthTurstLevel authTurstLevel,
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService AuthUser is start");
|
||||
int ret = SUCCESS;
|
||||
int result = SUCCESS;
|
||||
uint64_t callerID = 0;
|
||||
std::string callerName = "";
|
||||
uint64_t contextID = 0;
|
||||
AuthSolution authSolutionParam;
|
||||
CoAuthInfo coAuthInfo;
|
||||
AuthResult extraInfo;
|
||||
if (GetControllerData(callback, extraInfo, authTurstLevel, callerID, callerName, contextID) == FAIL) {
|
||||
return ret;
|
||||
}
|
||||
authSolutionParam.contextId = contextID;
|
||||
authSolutionParam.userId = userId;
|
||||
authSolutionParam.authTrustLevel = authTurstLevel;
|
||||
authSolutionParam.challenge = challenge;
|
||||
authSolutionParam.authType = authType;
|
||||
result = userauthController_.GenerateSolution(authSolutionParam, coAuthInfo.sessionIds);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser GenerateSolution is ERROR!");
|
||||
userauthController_.DeleteContextID(contextID);
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
coAuthInfo.authType = authType;
|
||||
coAuthInfo.callerID = callerID;
|
||||
coAuthInfo.contextID = contextID;
|
||||
coAuthInfo.pkgName = callerName;
|
||||
sptr<IRemoteObject::DeathRecipient> dr = new UserAuthServiceCallbackDeathRecipient(callback);
|
||||
if ((!callback->AsObject()->AddDeathRecipient(dr))) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient UserAuthServiceCallbackDeathRecipient");
|
||||
}
|
||||
result = userauthController_.coAuth(coAuthInfo, callback);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser coAuth is ERROR!");
|
||||
userauthController_.DeleteContextID(contextID);
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
}
|
||||
return contextID;
|
||||
}
|
||||
|
||||
int32_t UserAuthService::GetControllerData(sptr<IUserAuthCallback>& callback, AuthResult &extraInfo,
|
||||
const AuthTurstLevel authTurstLevel, uint64_t &callerID,
|
||||
std::string &callerName, uint64_t &contextID)
|
||||
{
|
||||
int ret = SUCCESS;
|
||||
int result = SUCCESS;
|
||||
if (callback == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser IUserAuthCallback is NULL!");
|
||||
callback->onResult(INVALID_PARAMETERS, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
}
|
||||
if (ATL4 < authTurstLevel || authTurstLevel < ATL1) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser AuthTurstLevel is NOT SUPPORT!");
|
||||
callback->onResult(TRUST_LEVEL_NOT_SUPPORT, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
result = userauthController_.GetCallerUid(callerID);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser GetCallerUid is ERROR!");
|
||||
callback->onResult(FAIL, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
}
|
||||
result = userauthController_.GetPkgName(callerName);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser GetPkgName is ERROR!");
|
||||
callback->onResult(FAIL, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
}
|
||||
result = userauthController_.GenerateContextID(contextID);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser GenerateContextID is ERROR!");
|
||||
callback->onResult(GENERAL_ERROR, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
}
|
||||
result = userauthController_.AddContextID(contextID);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser AddContextID is ERROR!");
|
||||
callback->onResult(GENERAL_ERROR, extraInfo);
|
||||
ret = FAIL;
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t UserAuthService::CancelAuth(const uint64_t contextId)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService CancelAuth is start");
|
||||
int result = INVALID_CONTEXTID;
|
||||
std::vector<uint64_t> sessionIds;
|
||||
|
||||
int ret = userauthController_.IsContextIDExist(contextId);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService CancelAuth IsContextIDExist is ERROR!");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = userauthController_.CancelContext(contextId, sessionIds);
|
||||
if (result == SUCCESS) {
|
||||
for (std::vector<uint64_t>::iterator iter = sessionIds.begin(); iter != sessionIds.end(); ++iter) {
|
||||
result = userauthController_.Cancel(*iter);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService CancelAuth Cancel is ERROR!");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
userauthController_.DeleteContextID(contextId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t UserAuthService::GetVersion()
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService GetVersion is start");
|
||||
return userauthController_.GetVersion();
|
||||
}
|
||||
UserAuthService::UserAuthServiceCallbackDeathRecipient::UserAuthServiceCallbackDeathRecipient(
|
||||
sptr<IUserAuthCallback>& impl)
|
||||
{
|
||||
if (impl != nullptr) {
|
||||
callback_ = impl;
|
||||
} else {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthServiceCallbackDeathRecipient is error");
|
||||
}
|
||||
}
|
||||
void UserAuthService::UserAuthServiceCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
if (remote == nullptr) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,
|
||||
"UserAuthServiceCallbackDeathRecipient OnRemoteDied failed, remote is nullptr");
|
||||
return;
|
||||
}
|
||||
callback_ = nullptr;
|
||||
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthServiceCallbackDeathRecipient::Recv death notice.");
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
Executable
+269
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <message_parcel.h>
|
||||
#include "userauth_common.h"
|
||||
#include "userauth_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
int32_t UserAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub::OnRemoteRequest, cmd = %d, flags= %d",
|
||||
code, option.GetFlags());
|
||||
std::u16string descripter = UserAuthStub::GetDescriptor();
|
||||
std::u16string remoteDescripter = data.ReadInterfaceToken();
|
||||
if (descripter != remoteDescripter) {
|
||||
USERAUTH_HILOGD(MODULE_SERVICE,
|
||||
"DisplayMgrStub::OnRemoteRequest failed, descriptor is not matched!");
|
||||
return E_GET_POWER_SERVICE_FAILED;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_GET_AVAILABLE_STATUS):
|
||||
return GetAvailableStatusStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_GET_PROPERTY):
|
||||
return GetPropertyStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_SET_PROPERTY):
|
||||
return SetPropertyStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_AUTH):
|
||||
return AuthStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_AUTH_USER):
|
||||
return AuthUserStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_CANCEL_AUTH):
|
||||
return CancelAuthStub(data, reply);
|
||||
case static_cast<int32_t>(IUserAuth::USER_AUTH_GET_VERSION):
|
||||
return GetVersionStub(data, reply);
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t UserAuthStub::GetAvailableStatusStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub GetAvailableStatusStub is start");
|
||||
uint32_t authType;
|
||||
uint32_t authTurstLevel;
|
||||
int32_t ret = GENERAL_ERROR;
|
||||
|
||||
if (!data.ReadUint32(authType)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authType).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(authTurstLevel)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authTurstLevel).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
ret = GetAvailableStatus(static_cast<AuthType>(authType), static_cast<AuthTurstLevel>(authTurstLevel));
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to write GetAvailableStatus return value");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthStub::GetPropertyStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub GetPropertyStub is start");
|
||||
GetPropertyRequest getPropertyRequest;
|
||||
uint32_t authType;
|
||||
std::vector<uint32_t> keys;
|
||||
|
||||
if (!data.ReadUint32(authType)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authType).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt32Vector(&keys)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUInt32Vector(&keys).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
getPropertyRequest.authType = static_cast<AuthType>(authType);
|
||||
getPropertyRequest.keys = keys;
|
||||
|
||||
sptr<IRemoteObject> obj = data.ReadRemoteObject();
|
||||
if (obj == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
sptr<IUserAuthCallback> callback = iface_cast<IUserAuthCallback>(obj);
|
||||
if (callback == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
GetProperty(getPropertyRequest, callback);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t UserAuthStub::SetPropertyStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub SetPropertyStub is start");
|
||||
SetPropertyRequest setPropertyRequest;
|
||||
uint32_t authType;
|
||||
uint32_t key;
|
||||
std::vector<uint8_t> setInfo;
|
||||
|
||||
if (!data.ReadUint32(authType)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authType).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(key)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(key).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUInt8Vector(&setInfo)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUInt8Vector(&setInfo).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
setPropertyRequest.authType = static_cast<AuthType>(authType);
|
||||
setPropertyRequest.key = static_cast<SetPropertyType>(key);
|
||||
setPropertyRequest.setInfo.assign(setInfo.begin(), setInfo.end());
|
||||
|
||||
sptr<IRemoteObject> obj = data.ReadRemoteObject();
|
||||
if (obj == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
sptr<IUserAuthCallback> callback = iface_cast<IUserAuthCallback>(obj);
|
||||
if (callback == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
SetProperty(setPropertyRequest, callback);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
int32_t UserAuthStub::AuthStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub AuthStub is start");
|
||||
uint64_t challenge;
|
||||
uint32_t authType;
|
||||
uint32_t authTurstLevel;
|
||||
uint64_t ret = SUCCESS;
|
||||
|
||||
if (!data.ReadUint64(challenge)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint64(challenge).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(authType)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authType).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(authTurstLevel)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authTurstLevel).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> obj = data.ReadRemoteObject();
|
||||
if (obj == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
sptr<IUserAuthCallback> callback = iface_cast<IUserAuthCallback>(obj);
|
||||
if (callback == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
ret = Auth(challenge, static_cast<AuthType>(authType), static_cast<AuthTurstLevel>(authTurstLevel), callback);
|
||||
if (!reply.WriteUint64(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to write Auth return value");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
int32_t UserAuthStub::AuthUserStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub AuthUserStub is start");
|
||||
int32_t userID;
|
||||
uint64_t challenge;
|
||||
uint32_t authType;
|
||||
uint32_t authTurstLevel;
|
||||
uint64_t ret = SUCCESS;
|
||||
|
||||
if (!data.ReadInt32(userID)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(userID).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint64(challenge)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint64(challenge).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(authType)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authType).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.ReadUint32(authTurstLevel)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(authTurstLevel).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> obj = data.ReadRemoteObject();
|
||||
if (obj == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
sptr<IUserAuthCallback> callback = iface_cast<IUserAuthCallback>(obj);
|
||||
if (callback == nullptr) {
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
ret = AuthUser(userID, challenge, static_cast<AuthType>(authType),
|
||||
static_cast<AuthTurstLevel>(authTurstLevel), callback);
|
||||
if (!reply.WriteUint64(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to write AuthUser return value");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
int32_t UserAuthStub::GetVersionStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub GetVersionStub is start");
|
||||
|
||||
int32_t ret = GetVersion();
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to write GetVersion return value");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
int32_t UserAuthStub::CancelAuthStub(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthStub CancelAuthStub is start");
|
||||
uint64_t contextID;
|
||||
int32_t ret = GENERAL_ERROR;
|
||||
|
||||
if (!data.ReadUint64(contextID)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint64(contextID).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
ret = CancelAuth(contextID);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "Failed to write CancelAuth return value");
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
group("userauth_native_test") {
|
||||
testonly = true
|
||||
deps = [ "unittest:unittest_test" ]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
|
||||
|
||||
module_output_path = "${userauth_native_part_name}/UserAuth_test"
|
||||
|
||||
###############################################################################
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//utils/system/safwk/native/include",
|
||||
#"//base/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
]
|
||||
}
|
||||
|
||||
##############################unittest##########################################
|
||||
ohos_unittest("unittest_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [ "src/userauth_test.cpp" ]
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
#"//base/useriam/useridm/unittest/include",
|
||||
"//out/hi3516dv300/innerkits/ohos-arm/ipc/ipc_single/include",
|
||||
"//base/useriam/userauth/interfaces/innerkits/include",
|
||||
#"//base/useriam/useridm/services/include",
|
||||
]
|
||||
|
||||
configs = [
|
||||
#"${userauth_utils_path}:utils_config",
|
||||
":module_private_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${userauth_innerkits_path}/native:userauth_framework",
|
||||
"//drivers/peripheral/display/hal:hdi_display_device",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
#"//base/useriam/userauth/interfaces/innerkits/userauth:userauth_inner",
|
||||
#"//base/useriam/userauth/services/userauthservice/adapter:userauth_adapter",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_TEST_H
|
||||
#define USERAUTH_TEST_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
void UseriamUtTest_001();
|
||||
void UseriamUtTest_002();
|
||||
void UseriamUtTest_003();
|
||||
void UseriamUtTest_004();
|
||||
void UseriamUtTest_005();
|
||||
void UseriamUtTest_006();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // USERAUTH_TEST_H
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 <memory>
|
||||
#include <iostream>
|
||||
#include <gtest/gtest.h>
|
||||
#include "user_auth.h"
|
||||
#include "userauth_callback.h"
|
||||
#include "userauth_info.h"
|
||||
#include "userauth_test.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
class UseriamUtTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
|
||||
static void TearDownTestCase(void);
|
||||
|
||||
void SetUp();
|
||||
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void UseriamUtTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void UseriamUtTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void UseriamUtTest::SetUp()
|
||||
{
|
||||
}
|
||||
void UseriamUtTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
class TestUserAuthCallback : public UserAuthCallback {
|
||||
public:
|
||||
TestUserAuthCallback() = default;
|
||||
virtual ~TestUserAuthCallback() = default;
|
||||
|
||||
void onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) override;
|
||||
void onResult(const int32_t result, const AuthResult extraInfo) override;
|
||||
void onExecutorPropertyInfo(const ExecutorProperty result) override;
|
||||
void onSetExecutorProperty(const int32_t result) override;
|
||||
};
|
||||
|
||||
void TestUserAuthCallback::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo)
|
||||
{
|
||||
std::cout << "onAcquireInfo callback" << std::endl;
|
||||
}
|
||||
void TestUserAuthCallback::onResult(const int32_t result, const AuthResult extraInfo)
|
||||
{
|
||||
std::cout << "onResult callback" << std::endl;
|
||||
}
|
||||
void TestUserAuthCallback::onExecutorPropertyInfo(const ExecutorProperty result)
|
||||
{
|
||||
std::cout << "onExecutorPropertyInfo callback" << std::endl;
|
||||
}
|
||||
void TestUserAuthCallback::onSetExecutorProperty(const int32_t result)
|
||||
{
|
||||
std::cout << "onSetExecutorProperty callback" << std::endl;
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_001, TestSize.Level1)
|
||||
{
|
||||
AuthType authType = FACE;
|
||||
AuthTurstLevel authTurstLevel = ATL1;
|
||||
EXPECT_EQ(0, UserAuth::GetInstance().GetAvailableStatus(authType, authTurstLevel));
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_002, TestSize.Level1)
|
||||
{
|
||||
GetPropertyRequest request;
|
||||
request.authType = FACE;
|
||||
request.keys.push_back(1);
|
||||
request.keys.push_back(3);
|
||||
std::shared_ptr<UserAuthCallback> callback = std::make_shared<TestUserAuthCallback>();
|
||||
UserAuth::GetInstance().GetProperty(request, callback);
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_003, TestSize.Level1)
|
||||
{
|
||||
SetPropertyRequest request;
|
||||
request.authType = FACE;
|
||||
request.key = INIT_ALGORITHM;
|
||||
uint8_t i = 123;
|
||||
request.setInfo.push_back(i);
|
||||
std::shared_ptr<UserAuthCallback> callback = std::make_shared<TestUserAuthCallback>();
|
||||
UserAuth::GetInstance().SetProperty(request, callback);
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_004, TestSize.Level1)
|
||||
{
|
||||
uint64_t challenge = 001;
|
||||
AuthType authType = FACE;
|
||||
AuthTurstLevel authTurstLevel = ATL1;
|
||||
std::shared_ptr<UserAuthCallback> callback = std::make_shared<TestUserAuthCallback>();
|
||||
EXPECT_EQ(123, UserAuth::GetInstance().Auth(challenge, authType, authTurstLevel, callback));
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_005, TestSize.Level1)
|
||||
{
|
||||
int32_t userId = 100;
|
||||
uint64_t challenge = 001;
|
||||
AuthType authType = FACE;
|
||||
AuthTurstLevel authTurstLevel = ATL1;
|
||||
std::shared_ptr<UserAuthCallback> callback = std::make_shared<TestUserAuthCallback>();
|
||||
EXPECT_EQ(123, UserAuth::GetInstance().AuthUser(userId, challenge, authType, authTurstLevel, callback));
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_006, TestSize.Level1)
|
||||
{
|
||||
uint64_t contextId = 123;
|
||||
EXPECT_EQ(0, UserAuth::GetInstance().CancelAuth(contextId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
userauth_native_part_name = "userauth"
|
||||
|
||||
userauth_root_path = "//base/useriam/userauth"
|
||||
|
||||
userauth_service_path = "${userauth_root_path}/services"
|
||||
|
||||
userauth_frameworks_path = "${userauth_root_path}/frameworks"
|
||||
|
||||
userauth_interfaces_path = "${userauth_root_path}/interfaces"
|
||||
|
||||
userauth_kits_path = "${userauth_interfaces_path}/kits"
|
||||
|
||||
userauth_innerkits_path = "${userauth_interfaces_path}/innerkits"
|
||||
|
||||
userauth_utils_path = "${userauth_root_path}/utils"
|
||||
@@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/useriam/userauth/userauth.gni")
|
||||
|
||||
config("utils_config") {
|
||||
include_dirs = [
|
||||
"native/include",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_COMMON_H
|
||||
#define USERAUTH_COMMON_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "userauth_hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
#define RETURN_IF_WITH_RET(cond, retval) if (cond) {return (retval);}
|
||||
#define RETURN_IF(cond) if (cond) {return;}
|
||||
#define RETURN_IF_WITH_LOG(cond, loginfo) \
|
||||
do { \
|
||||
if (cond) { \
|
||||
USERAUTH_HILOGE(MODULE_COMMON, "%{public}s "#loginfo" ", __func__); \
|
||||
return; \
|
||||
} \
|
||||
} while (0) \
|
||||
|
||||
#define READ_PARCEL_NO_RET(parcel, type, out) \
|
||||
do { \
|
||||
if (!(parcel).Read##type(out)) { \
|
||||
USERAUTH_HILOGE(MODULE_COMMON, "%{public}s read "#out" failed", __func__); \
|
||||
return; \
|
||||
} \
|
||||
} while (0) \
|
||||
|
||||
#define WRITE_PARCEL_NO_RET(parcel, type, data) \
|
||||
do { \
|
||||
if (!(parcel).Write##type(data)) { \
|
||||
USERAUTH_HILOGE(MODULE_COMMON, "%{public}s write "#data" failed", __func__); \
|
||||
return; \
|
||||
} \
|
||||
} while (0) \
|
||||
|
||||
#define READ_PARCEL_WITH_RET(parcel, type, out, retval) \
|
||||
do { \
|
||||
if (!(parcel).Read##type(out)) { \
|
||||
USERAUTH_HILOGE(MODULE_COMMON, "%{public}s read "#out" failed", __func__); \
|
||||
return (retval); \
|
||||
} \
|
||||
} while (0) \
|
||||
|
||||
#define WRITE_PARCEL_WITH_RET(parcel, type, data, retval) \
|
||||
do { \
|
||||
if (!(parcel).Write##type(data)) { \
|
||||
USERAUTH_HILOGE(MODULE_COMMON, "%{public}s write "#data" failed", __func__); \
|
||||
return (retval); \
|
||||
} \
|
||||
} while (0) \
|
||||
|
||||
template<typename E>
|
||||
constexpr auto ToUnderlying(E e) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<E>>(e);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // USERAUTH_COMMON_H
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_ERRORS_H
|
||||
#define USERAUTH_ERRORS_H
|
||||
|
||||
#include <errors.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
enum {
|
||||
E_WRITE_PARCEL_ERROR = 0,
|
||||
E_READ_PARCEL_ERROR,
|
||||
E_GET_SYSTEM_ABILITY_MANAGER_FAILED,
|
||||
E_GET_POWER_SERVICE_FAILED,
|
||||
E_ADD_DEATH_RECIPIENT_FAILED,
|
||||
E_INNER_ERR
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // USERAUTH_ERRORS_H
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 USERAUTH_HILOG_WRAPPER_H
|
||||
#define USERAUTH_HILOG_WRAPPER_H
|
||||
|
||||
#define CONFIG_HILOG
|
||||
#ifdef CONFIG_HILOG
|
||||
#include "hilog/log.h"
|
||||
namespace OHOS {
|
||||
namespace UserIAM {
|
||||
namespace UserAuth {
|
||||
#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
#define FORMATED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__
|
||||
|
||||
#ifdef USERAUTH_HILOGF
|
||||
#undef USERAUTH_HILOGF
|
||||
#endif
|
||||
|
||||
#ifdef USERAUTH_HILOGE
|
||||
#undef USERAUTH_HILOGE
|
||||
#endif
|
||||
|
||||
#ifdef USERAUTH_HILOGW
|
||||
#undef USERAUTH_HILOGW
|
||||
#endif
|
||||
|
||||
#ifdef USERAUTH_HILOGI
|
||||
#undef USERAUTH_HILOGI
|
||||
#endif
|
||||
|
||||
#ifdef USERAUTH_HILOGD
|
||||
#undef USERAUTH_HILOGD
|
||||
#endif
|
||||
|
||||
// param of log interface, such as DISTRIBUTED_GALLERY_HILOGF.
|
||||
enum UserAuthSubModule {
|
||||
MODULE_INNERKIT = 0,
|
||||
MODULE_SERVICE,
|
||||
MODULE_COMMON,
|
||||
MODULE_JS_NAPI,
|
||||
USERAUTHS_MODULE_BUTT,
|
||||
};
|
||||
|
||||
// 0xD002900: subsystem:distributeddatamgr module:distributedgallery, 8 bits reserved.
|
||||
static constexpr unsigned int BASE_USERAUTH_DOMAIN_ID = 0xD002910;
|
||||
|
||||
enum UserAuthDomainId {
|
||||
USERAUTH_INNERKIT_DOMAIN = BASE_USERAUTH_DOMAIN_ID + MODULE_INNERKIT,
|
||||
USERAUTH_SERVICE_DOMAIN,
|
||||
COMMON_DOMAIN,
|
||||
USERAUTH_JS_NAPI
|
||||
};
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel USERAUTH_LABEL[USERAUTHS_MODULE_BUTT] = {
|
||||
{LOG_CORE, USERAUTH_INNERKIT_DOMAIN, "UserAuthClient"},
|
||||
{LOG_CORE, USERAUTH_SERVICE_DOMAIN, "UserAuthService"},
|
||||
{LOG_CORE, COMMON_DOMAIN, "UserAuthCommon"},
|
||||
{LOG_CORE, USERAUTH_JS_NAPI, "UserAuthJSNAPI"},
|
||||
};
|
||||
|
||||
// In order to improve performance, do not check the module range.
|
||||
// Besides, make sure module is less than DISTRIBUTED_GALLERY_MODULE_BUTT.
|
||||
#define USERAUTH_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(USERAUTH_LABEL[module], FORMATED(__VA_ARGS__))
|
||||
#define USERAUTH_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(USERAUTH_LABEL[module], FORMATED(__VA_ARGS__))
|
||||
#define USERAUTH_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(USERAUTH_LABEL[module], FORMATED(__VA_ARGS__))
|
||||
#define USERAUTH_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(USERAUTH_LABEL[module], FORMATED(__VA_ARGS__))
|
||||
#define USERAUTH_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(USERAUTH_LABEL[module], FORMATED(__VA_ARGS__))
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
||||
#else
|
||||
|
||||
#define USERAUTH_HILOGF(...)
|
||||
#define USERAUTH_HILOGE(...)
|
||||
#define USERAUTH_HILOGW(...)
|
||||
#define USERAUTH_HILOGI(...)
|
||||
#define USERAUTH_HILOGD(...)
|
||||
|
||||
#endif // CONFIG_HILOG
|
||||
|
||||
#endif // USERAUTH_HILOG_WRAPPER_H
|
||||
Reference in New Issue
Block a user