mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-12-04 14:12:19 +00:00
commit
33195ad089
@ -61,7 +61,8 @@
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_extension/user_auth_extension:userauthextensionability_napi",
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_extension/module_loader:user_auth_extension",
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_extension/module_loader:user_auth_extension_module",
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_icon:userauthicon"
|
||||
"//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_icon:userauthicon",
|
||||
"//base/useriam/user_auth_framework/frameworks/cj/user_auth:cj_userauth_ffi"
|
||||
],
|
||||
"service_group": [
|
||||
"//base/useriam/user_auth_framework/sa_profile:useriam.init",
|
||||
|
47
frameworks/cj/user_auth/BUILD.gn
Normal file
47
frameworks/cj/user_auth/BUILD.gn
Normal file
@ -0,0 +1,47 @@
|
||||
# Copyright (C) 2024 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")
|
||||
|
||||
ohos_shared_library("cj_userauth_ffi") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
remove_configs = [ "//build/config/compiler:no_exceptions" ]
|
||||
|
||||
include_dirs = [
|
||||
"inc",
|
||||
"../../native/client/inc",
|
||||
"../../native/ipc/common_defines",
|
||||
"../../../interfaces/inner_api",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/user_auth_callback_cj.cpp",
|
||||
"src/user_auth_ffi.cpp",
|
||||
]
|
||||
|
||||
deps = [ "../../native/client:userauth_client" ]
|
||||
|
||||
external_deps = [ "napi:cj_bind_native" ]
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "useriam"
|
||||
part_name = "user_auth_framework"
|
||||
}
|
47
frameworks/cj/user_auth/inc/user_auth_ffi.h
Normal file
47
frameworks/cj/user_auth/inc/user_auth_ffi.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2024 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 USER_AUTH_FFI_H
|
||||
#define USER_AUTH_FFI_H
|
||||
|
||||
#include "user_auth_ffi_struct.h"
|
||||
|
||||
#include "user_auth_common_defines.h"
|
||||
|
||||
using OHOS::UserIam::UserAuth::CAuthParam;
|
||||
using OHOS::UserIam::UserAuth::CUserAuthResult;
|
||||
using OHOS::UserIam::UserAuth::CWidgetParam;
|
||||
using OHOS::UserIam::UserAuth::EnrolledState;
|
||||
using OHOS::UserIam::UserAuth::UserAuthCallbackCj;
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int32_t FfiUserAuthGetAvailableStatus(uint32_t authType, uint32_t authTrustLevel);
|
||||
|
||||
FFI_EXPORT int32_t FfiUserAuthGetEnrolledState(uint32_t authType, EnrolledState *enrolledState);
|
||||
|
||||
FFI_EXPORT UserAuthCallbackCj *FfiUserAuthNewCb(void (*callback)(CUserAuthResult));
|
||||
|
||||
FFI_EXPORT void FfiUserAuthDeleteCb(const UserAuthCallbackCj *callbackPtr);
|
||||
|
||||
FFI_EXPORT uint64_t FfiUserAuthStart(const CAuthParam &authParam, const CWidgetParam &widgetParam,
|
||||
UserAuthCallbackCj *callbackPtr);
|
||||
|
||||
FFI_EXPORT int32_t FfiUserAuthCancel(uint64_t contextId);
|
||||
}
|
||||
|
||||
|
||||
#endif // USER_AUTH_FFI_H
|
67
frameworks/cj/user_auth/inc/user_auth_ffi_struct.h
Normal file
67
frameworks/cj/user_auth/inc/user_auth_ffi_struct.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2024 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 USER_AUTH_FFI_STRUCT_H
|
||||
#define USER_AUTH_FFI_STRUCT_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "user_auth_client_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
struct CAuthParam {
|
||||
uint8_t *challenge;
|
||||
int64_t challengeLen;
|
||||
uint32_t *authTypes;
|
||||
int64_t authTypesLen;
|
||||
uint32_t authTrustLevel;
|
||||
bool isReuse;
|
||||
uint32_t reuseMode;
|
||||
uint64_t reuseDuration;
|
||||
};
|
||||
|
||||
struct CWidgetParam {
|
||||
const char *title;
|
||||
const char *navigationButtonText;
|
||||
};
|
||||
|
||||
struct CUserAuthResult {
|
||||
int32_t result;
|
||||
uint8_t *token;
|
||||
int64_t tokenLen;
|
||||
uint32_t authType;
|
||||
uint64_t credentialDigest;
|
||||
uint16_t credentialCount;
|
||||
};
|
||||
|
||||
class UserAuthCallbackCj final : public AuthenticationCallback {
|
||||
public:
|
||||
UserAuthCallbackCj() = default;
|
||||
explicit UserAuthCallbackCj(const std::function<void(CUserAuthResult)> &onResult) : onResult_(onResult) {}
|
||||
virtual ~UserAuthCallbackCj() = default;
|
||||
void OnResult(int32_t result, const Attributes &extraInfo) override;
|
||||
void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override;
|
||||
|
||||
private:
|
||||
std::function<void(CUserAuthResult)> onResult_;
|
||||
};
|
||||
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // USER_AUTH_FFI_STRUCT_H
|
49
frameworks/cj/user_auth/src/user_auth_callback_cj.cpp
Normal file
49
frameworks/cj/user_auth/src/user_auth_callback_cj.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2024 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_ffi.h"
|
||||
|
||||
using namespace OHOS::UserIam::UserAuth;
|
||||
|
||||
void UserAuthCallbackCj::OnAcquireInfo(const int32_t module, const uint32_t acquireInfo, const Attributes &extraInfo)
|
||||
{
|
||||
(void) module;
|
||||
(void) acquireInfo;
|
||||
(void) extraInfo;
|
||||
}
|
||||
|
||||
void UserAuthCallbackCj::OnResult(const int32_t result, const Attributes &extraInfo)
|
||||
{
|
||||
if (this->onResult_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> token;
|
||||
extraInfo.GetUint8ArrayValue(Attributes::ATTR_SIGNATURE, token);
|
||||
int32_t authType{0};
|
||||
extraInfo.GetInt32Value(Attributes::ATTR_AUTH_TYPE, authType);
|
||||
|
||||
CUserAuthResult ret = {
|
||||
.result = result,
|
||||
.token = token.data(),
|
||||
.tokenLen = static_cast<int64_t>(token.size()),
|
||||
.authType = static_cast<uint32_t>(authType),
|
||||
};
|
||||
|
||||
extraInfo.GetUint64Value(Attributes::ATTR_CREDENTIAL_DIGEST, ret.credentialDigest);
|
||||
extraInfo.GetUint16Value(Attributes::ATTR_CREDENTIAL_COUNT, ret.credentialCount);
|
||||
|
||||
this->onResult_(ret);
|
||||
}
|
85
frameworks/cj/user_auth/src/user_auth_ffi.cpp
Normal file
85
frameworks/cj/user_auth/src/user_auth_ffi.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2024 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 "cj_lambda.h"
|
||||
#include "user_auth_client_impl.h"
|
||||
|
||||
#include "user_auth_ffi.h"
|
||||
|
||||
using namespace OHOS::UserIam::UserAuth;
|
||||
|
||||
int32_t FfiUserAuthGetAvailableStatus(const uint32_t authType, const uint32_t authTrustLevel)
|
||||
{
|
||||
constexpr int32_t API_VERSION_9 = 9;
|
||||
return UserAuthClientImpl::Instance().GetAvailableStatus(API_VERSION_9, AuthType(authType),
|
||||
AuthTrustLevel(authTrustLevel));
|
||||
}
|
||||
|
||||
int32_t FfiUserAuthGetEnrolledState(const uint32_t authType, EnrolledState *enrolledState)
|
||||
{
|
||||
constexpr int32_t API_VERSION_12 = 12;
|
||||
return UserAuthClientImpl::Instance().GetEnrolledState(API_VERSION_12, AuthType(authType), *enrolledState);
|
||||
}
|
||||
|
||||
UserAuthCallbackCj *FfiUserAuthNewCb(void (*const callback)(CUserAuthResult))
|
||||
{
|
||||
return new UserAuthCallbackCj(CJLambda::Create(callback));
|
||||
}
|
||||
|
||||
void FfiUserAuthDeleteCb(const UserAuthCallbackCj *callbackPtr)
|
||||
{
|
||||
delete callbackPtr;
|
||||
}
|
||||
|
||||
uint64_t FfiUserAuthStart(const CAuthParam &authParam, const CWidgetParam &widgetParam,
|
||||
UserAuthCallbackCj *callbackPtr)
|
||||
{
|
||||
constexpr int32_t API_VERSION_10 = 10;
|
||||
std::vector<AuthType> authTypes;
|
||||
for (int i = 0; i < authParam.authTypesLen; ++i) {
|
||||
authTypes.push_back(AuthType(authParam.authTypes[i]));
|
||||
}
|
||||
AuthParamInner authParamInner{
|
||||
.challenge = std::vector<uint8_t>(authParam.challenge, authParam.challenge + authParam.challengeLen),
|
||||
.authTypes = authTypes,
|
||||
.authTrustLevel = AuthTrustLevel(authParam.authTrustLevel),
|
||||
};
|
||||
if (authParam.isReuse) {
|
||||
authParamInner.reuseUnlockResult = {
|
||||
.isReuse = true,
|
||||
.reuseMode = ReuseMode(authParam.reuseMode),
|
||||
.reuseDuration = authParam.reuseDuration,
|
||||
};
|
||||
}
|
||||
WidgetParam widgetInner = {
|
||||
.title = widgetParam.title,
|
||||
.navigationButtonText = widgetParam.navigationButtonText ? widgetParam.navigationButtonText : nullptr,
|
||||
.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE,
|
||||
};
|
||||
if (callbackPtr == nullptr) {
|
||||
return UserAuthClientImpl::Instance().BeginWidgetAuth(API_VERSION_10, authParamInner, widgetInner,
|
||||
std::make_shared<UserAuthCallbackCj>());
|
||||
}
|
||||
const auto callback = std::shared_ptr<UserAuthCallbackCj>(
|
||||
callbackPtr, [](UserAuthCallbackCj *) {
|
||||
/* don't free, resource will be freed in FfiUserAuthDeleteCb */
|
||||
});
|
||||
return UserAuthClientImpl::Instance().BeginWidgetAuth(API_VERSION_10, authParamInner, widgetInner, callback);
|
||||
}
|
||||
|
||||
int32_t FfiUserAuthCancel(const uint64_t contextId)
|
||||
{
|
||||
return UserAuthClientImpl::GetInstance().CancelAuthentication(contextId);
|
||||
}
|
Loading…
Reference in New Issue
Block a user