From a7601ab5c506445b276487dc2ed3c2081e4c85a8 Mon Sep 17 00:00:00 2001 From: wangxu43 Date: Sun, 23 Jan 2022 14:49:15 +0800 Subject: [PATCH] code update Signed-off-by: wangxu43 --- bundle.json | 4 +- frameworks/kitsimpl/src/userauth.cpp | 6 +- .../kitsimpl/src/userauth_async_stub.cpp | 10 +- frameworks/kitsimpl/src/userauth_proxy.cpp | 112 +++++--- .../innerkits/js/ohos.UserIAM.userAuth.d.ts | 192 ++++++++++---- .../innerkits/napi/include/auth_build.h | 13 +- .../innerkits/napi/include/auth_common.h | 42 +-- .../innerkits/napi/include/auth_object.h | 6 +- .../innerkits/napi/include/authapi_callback.h | 8 +- .../innerkits/napi/include/result_convert.h | 16 +- .../innerkits/napi/include/user_auth_impl.h | 13 +- interfaces/innerkits/napi/src/auth_build.cpp | 203 ++------------ .../innerkits/napi/src/auth_native_module.cpp | 3 +- .../innerkits/napi/src/authapi_callback.cpp | 248 +++++++++++------- .../innerkits/napi/src/result_convert.cpp | 193 ++------------ .../innerkits/napi/src/user_auth_helper.cpp | 9 +- .../innerkits/napi/src/user_auth_impl.cpp | 138 ++++------ .../innerkits/native/include/userauth_info.h | 2 +- services/include/userauth_adapter.h | 2 - services/include/userauth_controller.h | 2 - services/include/userauth_datamgr.h | 4 +- services/include/userauth_excallback_impl.h | 2 + services/src/context_thread_pool.cpp | 4 +- services/src/userauth_adapter.cpp | 33 +-- services/src/userauth_async_proxy.cpp | 83 +++--- services/src/userauth_controller.cpp | 8 - services/src/userauth_datamgr.cpp | 32 +-- services/src/userauth_excallback_impl.cpp | 51 ++-- services/src/userauth_service.cpp | 54 +--- services/src/userauth_stub.cpp | 32 +-- utils/native/include/userauth_common.h | 77 ------ 31 files changed, 637 insertions(+), 965 deletions(-) delete mode 100644 utils/native/include/userauth_common.h diff --git a/bundle.json b/bundle.json index 6b043c706..9112a9ba8 100644 --- a/bundle.json +++ b/bundle.json @@ -38,7 +38,7 @@ "sub_component": [ "//base/user_iam/user_auth/sa_profile:userauth_sa_profile", "//base/user_iam/user_auth/services:userauthservice", - "//base/user_iam/user_auth/interfaces/kits/napi:userauthnorth" + "//base/user_iam/user_auth/interfaces/kits/napi:userauthnorth" ], "inner_kits": [ { @@ -73,7 +73,7 @@ ], "header_base": "//base/user_iam/user_auth/interfaces/innerkits/napi/include" } - } + } ], "test": [ "//base/user_iam/user_auth/test:userauth_native_test" diff --git a/frameworks/kitsimpl/src/userauth.cpp b/frameworks/kitsimpl/src/userauth.cpp index 2d9f56358..9715e7090 100644 --- a/frameworks/kitsimpl/src/userauth.cpp +++ b/frameworks/kitsimpl/src/userauth.cpp @@ -17,7 +17,7 @@ #include #include "system_ability_definition.h" -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "user_auth.h" namespace OHOS { @@ -60,7 +60,9 @@ void UserAuth::ResetProxy(const wptr& remote) { USERAUTH_HILOGD(MODULE_INNERKIT, "userauth ResetProxy is start"); std::lock_guard lock(mutex_); - RETURN_IF(proxy_ == nullptr); + if (proxy_ == nullptr) { + return; + } auto serviceRemote = proxy_->AsObject(); if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) { diff --git a/frameworks/kitsimpl/src/userauth_async_stub.cpp b/frameworks/kitsimpl/src/userauth_async_stub.cpp index 048b6648b..3e2fbaf65 100644 --- a/frameworks/kitsimpl/src/userauth_async_stub.cpp +++ b/frameworks/kitsimpl/src/userauth_async_stub.cpp @@ -15,7 +15,7 @@ #include -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "iuser_auth.h" #include "userauth_async_stub.h" @@ -130,7 +130,7 @@ int32_t UserAuthAsyncStub::onExecutorPropertyInfoStub(MessageParcel& data, Messa int32_t ret = SUCCESS; int32_t result; - uint32_t authSubType; + uint64_t authSubType; uint32_t remainTimes; uint32_t freezingTime; ExecutorProperty executorProperty; @@ -139,8 +139,8 @@ int32_t UserAuthAsyncStub::onExecutorPropertyInfoStub(MessageParcel& data, Messa 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)."); + if (!data.ReadUint64(authSubType)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to ReadUint64(authSubType)."); return E_READ_PARCEL_ERROR; } if (!data.ReadUint32(remainTimes)) { @@ -223,7 +223,7 @@ void UserAuthAsyncStub::onExecutorPropertyInfo(const ExecutorProperty result) 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 authSubType:%{public}llu", 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); diff --git a/frameworks/kitsimpl/src/userauth_proxy.cpp b/frameworks/kitsimpl/src/userauth_proxy.cpp index 6dce65153..65c9093ac 100644 --- a/frameworks/kitsimpl/src/userauth_proxy.cpp +++ b/frameworks/kitsimpl/src/userauth_proxy.cpp @@ -14,7 +14,7 @@ */ #include #include -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "userauth_proxy.h" namespace OHOS { @@ -34,10 +34,14 @@ int32_t UserAuthProxy::GetAvailableStatus(const AuthType authType, const AuthTur USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!"); return result; } - - WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(authType), E_READ_PARCEL_ERROR); - WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(authTurstLevel), E_READ_PARCEL_ERROR); - + if (!data.WriteUint32(static_cast(authType))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(authType))."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteUint32(static_cast(authTurstLevel))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(authTurstLevel))."); + return E_READ_PARCEL_ERROR; + } bool ret = SendRequest(static_cast(IUserAuth::USER_AUTH_GET_AVAILABLE_STATUS), data, reply, option); if (!ret) { USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %d", ret); @@ -61,11 +65,18 @@ void UserAuthProxy::GetProperty(const GetPropertyRequest request, sptr(request.authType)); - WRITE_PARCEL_NO_RET(data, UInt32Vector, (request.keys)); - WRITE_PARCEL_NO_RET(data, RemoteObject, callback->AsObject()); - + if (!data.WriteUint32(static_cast(request.authType))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(request.authType))."); + return; + } + if (!data.WriteUInt32Vector(request.keys)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUInt32Vector(request.keys))."); + return; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback->AsObject())."); + return; + } bool ret = SendRequest(static_cast(IUserAuth::USER_AUTH_GET_PROPERTY), data, reply, option); if (!ret) { ExecutorProperty result; @@ -86,12 +97,22 @@ void UserAuthProxy::SetProperty(const SetPropertyRequest request, sptr(request.authType)); - WRITE_PARCEL_NO_RET(data, Uint32, static_cast(request.key)); - WRITE_PARCEL_NO_RET(data, UInt8Vector, request.setInfo); - WRITE_PARCEL_NO_RET(data, RemoteObject, callback->AsObject()); - + if (!data.WriteUint32(static_cast(request.authType))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(request.authType))."); + return; + } + if (!data.WriteUint32(static_cast(request.key))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(request.key))."); + return; + } + if (!data.WriteUInt8Vector(request.setInfo)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUInt8Vector(request.setInfo)."); + return; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback->AsObject())."); + return; + } bool ret = SendRequest(IUserAuth::USER_AUTH_SET_PROPERTY, data, reply, option); if (!ret) { int32_t result = IPC_ERROR; @@ -114,12 +135,23 @@ uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType, 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(authType), E_READ_PARCEL_ERROR); - WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(authTurstLevel), E_READ_PARCEL_ERROR); - WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), E_READ_PARCEL_ERROR); - + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthProxy::Auth challenge = %{public}llu", challenge); + if (!data.WriteUint64(challenge)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(challenge)."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteUint32(static_cast(authType))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(authType))."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteUint32(static_cast(authTurstLevel))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(authTurstLevel))."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback->AsObject())."); + return 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); @@ -146,13 +178,26 @@ uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge, 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(authType), E_READ_PARCEL_ERROR); - WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(authTurstLevel), E_READ_PARCEL_ERROR); - WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), E_READ_PARCEL_ERROR); - + if (!data.WriteInt32(userId)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(userId)."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteUint64(challenge)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(challenge)."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteUint32(static_cast(authType))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(authType))."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteUint32(static_cast(authTurstLevel))) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast(authTurstLevel))."); + return E_READ_PARCEL_ERROR; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback->AsObject())."); + return 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); @@ -178,9 +223,10 @@ int32_t UserAuthProxy::CancelAuth(const uint64_t contextId) USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); return result; } - - WRITE_PARCEL_WITH_RET(data, Uint64, contextId, E_READ_PARCEL_ERROR); - + if (!data.WriteUint64(contextId)) { + USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(contextId)."); + return 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); @@ -235,4 +281,4 @@ bool UserAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParce } } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/innerkits/js/ohos.UserIAM.userAuth.d.ts b/interfaces/innerkits/js/ohos.UserIAM.userAuth.d.ts index dafdc1f29..527826a6d 100755 --- a/interfaces/innerkits/js/ohos.UserIAM.userAuth.d.ts +++ b/interfaces/innerkits/js/ohos.UserIAM.userAuth.d.ts @@ -15,132 +15,148 @@ import{AsyncCallback} from './basic'; +/** + * User authentication + * @since 8 + * @sysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @devices phone, tablet + * @permission ohos.permission.ACCESS_USER_AUTH_INTERNAL + */ declare namespace userIAM { - class UserAuth + class UserAuth { /** - * constructor. - * - * @return Constructor to get the userauth class instance + * Constructor to get the userauth class instance + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @return Returns the userauth class instance */ constructor(); /** - * getVersion. - * - * @return Get version information + * Get version information. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + * @return Returns version information */ getVersion() : number; /** - * getAvailabeStatus. - * - *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH} - * + * Check whether the certification capability is available. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH_INTERNAL} * @param authType Credential type for authentication. * @param authTrustLevel Credibility level of certification results. - * @return number. + * @return Returns a check result, which is specified by getAvailabeStatus. */ - getAvailabeStatus(authType : AuthType, authTrustLevel : AuthTurstLevel) : number; + getAvailabeStatus(authType : AuthType, authTrustLevel : AuthTrustLevel) : number; + /** - * getProperty. - * - *

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) + * Get the attribute, pass in the credential type and the key to get, and return the value corresponding to the key. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH_INTERNAL} + * @param request the attribute field list, authentication credential type, and credential information. + * @return Returns a support to query subclasses / remaining authentication times / remaining freezing time. */ getProperty(request : GetPropertyRequest) : Promise; getProperty(request: GetPropertyRequest, callback: AsyncCallback): void /** - * getProperty. - * - *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH} - * + * Set properties: can be used to initialize algorithms. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH_INTERNAL} * @param request pass in the credential type and the key value to be set. - * @return number. + * @return Returns a number value indicating whether the property setting was successful. */ setProperty(request: SetPropertyRequest): Promise; setProperty(request: SetPropertyRequest, callback: AsyncCallback): void /** - * auth - * - *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH} - * + * Authentication: pass in challenge value, authentication method, trust level and callback + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH_INTERNAL} * @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. + * @return Returns and return results and acquireinfo through callback. */ - auth(challenge: BigInt, authMethod: number, authTrustLevel: AuthTurstLevel, callback: IUserAuthCallback): BigInt; + auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; /** - * authUser - * - *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH} - * + * Specify user authentication: pass in the user ID, challenge value, authentication method, trust level and callback + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH_INTERNAL} * @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. + * @return Returns the result and acquireinfo through the callback. */ - authUser(userId: number, challenge: BigInt, authMethod: number, authTrustLevel: AuthTurstLevel, callback : IUserAuthCallback): BigInt; + authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback : IUserAuthCallback): Uint8Array; /** - * getProperty. - * - *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH} - * + * Cancel authentication and pass in ContextID. + * @since 8 + * @SysCap SystemCapability.UserIAM.UserAuth.BiometricAuth + *

Permissions required: {@code ohos.permission.ACCESS_USER_AUTH_INTERNAL} * @param contextID Cancel authentication and pass in ContextID. - * @return number. + * @return Returns a number value indicating whether Cancel authentication was successful. */ - cancelAuth(contextID : BigInt) : number; + cancelAuth(contextID : Uint8Array) : number; } - + /** * Credential type for authentication */ enum AuthType { /** * Authentication type pin. + * @since 8 */ PIN = 1, /** * Authentication type face. + * @since 8 */ FACE = 2 } - + /** - * Credential subtype: 6-digit digital password, user-defined digital password, + * 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. + * @since 8 */ PIN_SIX = 10000, /** * Authentication sub type self defined number pin. + * @since 8 */ PIN_NUMBER = 10001, /** * Authentication sub type 2D face. + * @since 8 */ PIN_MIXED = 10002, /** * Authentication sub type 2D face. + * @since 8 */ FACE_2D = 20000, /** * Authentication sub type 3D face. + * @since 8 */ FACE_3D = 20001 } @@ -148,21 +164,25 @@ declare namespace userIAM /** * Credibility level of certification results */ - enum AuthTurstLevel { + enum AuthTrustLevel { /** * Authentication result trusted level 1. + * @since 8 */ ATL1 = 10000, /** * Authentication result trusted level 2. + * @since 8 */ ATL2 = 20000, /** * Authentication result trusted level 3. + * @since 8 */ ATL3 = 30000, /** * Authentication result trusted level 4. + * @since 8 */ ATL4 = 40000 } @@ -173,14 +193,17 @@ declare namespace userIAM enum GetPropertyType { /** * Authentication remain times. + * @since 8 */ AUTH_SUB_TYPE = 1, /** * Authentication remain times. + * @since 8 */ REMAIN_TIMES = 2, /** * Authentication freezing time. + * @since 8 */ FREEZING_TIME = 3 } @@ -188,6 +211,7 @@ declare namespace userIAM /** * Get attribute request: the attribute field list, authentication credential type, and credential subclass * requested to be obtained + * @since 8 */ interface GetPropertyRequest { authType : AuthType; @@ -196,6 +220,7 @@ declare namespace userIAM /** * Actuator attribute: subclass, remaining authentication times, freezing time + * @since 8 */ interface ExecutorProperty { result: number; @@ -206,16 +231,19 @@ declare namespace userIAM /** * Actuator attribute list + * @since 8 */ enum SetPropertyType { /** * init algorithm. + * @since 8 */ INIT_ALGORITHM = 1, } /** * Set attribute request: pass in the credential type and the key value to be set + * @since 8 */ interface SetPropertyRequest { authType : AuthType; @@ -224,6 +252,7 @@ declare namespace userIAM } /** * Actuator attribute: subclass, remaining authentication times, freezing time + * @since 8 */ interface ExecutorProperty { result : number; @@ -233,14 +262,17 @@ declare namespace userIAM } /** * Authentication method and priority: currently only faces are supported + * @since 8 */ enum AuthMethod { /** * Authentication method PIN. + * @since 8 */ PIN_ONLY = 0xF, /** * Authentication method face. + * @since 8 */ FACE_ONLY = 0xF0 } @@ -249,6 +281,7 @@ declare namespace userIAM * 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 + * @since 8 */ interface IUserAuthCallback { onResult: (result : number, extraInfo : AuthResult) => void; @@ -257,16 +290,19 @@ declare namespace userIAM /** * Returns the module of acquireinfo + * @since 8 */ enum Module { /** * Acquire information from FaceAuth. + * @since 8 */ FACE_AUTH = 1 } /** * Authentication result: authentication token, remaining authentication times, freezing time + * @since 8 */ interface AuthResult { token ?: Uint8Array; @@ -276,14 +312,17 @@ declare namespace userIAM /** * Result code + * @since 8 */ enum ResultCode { /** * Indicates that authentication is success or ability is supported. + * @since 8 */ SUCCESS = 0, /** * Indicates the authenticator fails to identify user. + * @since 8 */ FAIL = 1, /** @@ -292,88 +331,143 @@ declare namespace userIAM GENERAL_ERROR = 2, /** * Indicates that authentication has been canceled. + * @since 8 */ CANCELED = 3, /** * Indicates that authentication has timed out. + * @since 8 */ TIMEOUT = 4, /** * Indicates that this authentication type is not supported. + * @since 8 */ TYPE_NOT_SUPPORT = 5, /** * Indicates that the authentication trust level is not supported. + * @since 8 */ TRUST_LEVEL_NOT_SUPPORT = 6, /** * Indicates that the authentication task is busy. Wait for a few seconds and try again. + * @since 8 */ BUSY = 7, /** * Indicates incorrect parameters. + * @since 8 */ INVALID_PARAMETERS = 8, /** * Indicates that the authenticator is locked. + * @since 8 */ LOCKED = 9, /** * Indicates that the user has not enrolled the authenticator. + * @since 8 */ NOT_ENROLLED = 10 } /** * Enumeration of prompt codes during authentication + * @since 8 */ enum FaceTipsCode { /** * Indicates that the obtained facial image is too bright due to high illumination. + * @since 8 */ FACE_AUTH_TIP_TOO_BRIGHT = 1, /** * Indicates that the obtained facial image is too dark due to low illumination. + * @since 8 */ FACE_AUTH_TIP_TOO_DARK = 2, /** * Indicates that the face is too close to the device. + * @since 8 */ FACE_AUTH_TIP_TOO_CLOSE = 3, /** * Indicates that the face is too far away from the device. + * @since 8 */ FACE_AUTH_TIP_TOO_FAR = 4, /** * Indicates that the device is too high, and that only the upper part of the face is captured. + * @since 8 */ FACE_AUTH_TIP_TOO_HIGH = 5, /** * Indicates that the device is too low, and that only the lower part of the face is captured. + * @since 8 */ 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. + * @since 8 */ 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. + * @since 8 */ FACE_AUTH_TIP_TOO_LEFT = 8, /** * Indicates that the face moves too fast during facial information collection. + * @since 8 */ FACE_AUTH_TIP_TOO_MUCH_MOTION = 9, /** * Indicates that the face is not facing the device. + * @since 8 */ FACE_AUTH_TIP_POOR_GAZE = 10, /** * Indicates that no face is detected. + * @since 8 */ FACE_AUTH_TIP_NOT_DETECTED = 11, } + /** + * Indicates the enumeration of prompt codes in the process of fingerprint authentication + * @since 8 + */ + enum FingerprintTips { + /** + * Indicates that the image acquired is good. + * @since 8 + */ + FINGERPRINT_TIP_GOOD = 0, + /** + * Indicates that the fingerprint image is too noisy due to suspected or detected dirt on the sensor. + * @since 8 + */ + FINGERPRINT_TIP_IMAGER_DIRTY = 1, + /** + * Indicates that the fingerprint image is too noisy to process due to a detected condition. + * @since 8 + */ + FINGERPRINT_TIP_INSUFFICIENT = 2, + /** + * Indicates that only a partial fingerprint image is detected. + * @since 8 + */ + FINGERPRINT_TIP_PARTIAL = 3, + /** + * Indicates that the fingerprint image is incomplete due to quick motion. + * @since 8 + */ + FINGERPRINT_TIP_TOO_FAST = 4, + /** + * Indicates that the fingerprint image is unreadable due to lack of motion. + * @since 8 + */ + FINGERPRINT_TIP_TOO_SLOW = 5 + } } - -export default userIAM; \ No newline at end of file +export default userIAM; diff --git a/interfaces/innerkits/napi/include/auth_build.h b/interfaces/innerkits/napi/include/auth_build.h index 34050e5a0..701ba9058 100755 --- a/interfaces/innerkits/napi/include/auth_build.h +++ b/interfaces/innerkits/napi/include/auth_build.h @@ -19,9 +19,8 @@ #include "napi/native_common.h" #include "napi/native_node_api.h" -#include "userauth_info.h" - #include "auth_common.h" +#include "result_convert.h" namespace OHOS { namespace UserIAM { @@ -30,18 +29,12 @@ class AuthBuild { public: AuthBuild(); ~AuthBuild(); + ResultConvert convert; 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); @@ -49,4 +42,4 @@ public: } // namespace UserAuth } // namespace UserIAM } // namespace OHOS -#endif // FACERECOGNITION_AUTH_BUILD_H \ No newline at end of file +#endif // FACERECOGNITION_AUTH_BUILD_H diff --git a/interfaces/innerkits/napi/include/auth_common.h b/interfaces/innerkits/napi/include/auth_common.h index d45e2eb3f..d8794218e 100755 --- a/interfaces/innerkits/napi/include/auth_common.h +++ b/interfaces/innerkits/napi/include/auth_common.h @@ -15,17 +15,10 @@ #ifndef OHOS_USERAUTH_COMMON_H #define OHOS_USERAUTH_COMMON_H -#include "napi/native_common.h" -#include "napi/native_node_api.h" - -#include -#include -#include -#include #include -#include "auth_object.h" -#include "userauth_info.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" namespace OHOS { namespace UserIAM { @@ -64,19 +57,12 @@ struct CallBackInfo { 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 keys; }; @@ -85,7 +71,7 @@ struct SetPropertyInfo { CallBackInfo callBackInfo; napi_async_work asyncWork; napi_value result; - int authType; + int32_t authType; int32_t key; std::vector setInfo; }; @@ -96,19 +82,15 @@ struct AuthInfo { napi_callback_info info; napi_async_work asyncWork; napi_value jsFunction; - napi_ref onResultCallBack; - napi_ref onAcquireInfoCallBack; + napi_value onResultCallBack; + napi_value onAcquireInfoCallBack; + napi_ref onResult; + napi_ref onAcquireInfo; 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 { @@ -117,6 +99,8 @@ struct AuthUserInfo { napi_callback_info info; napi_async_work asyncWork; napi_value jsFunction; + napi_ref onResult; + napi_ref onAcquireInfo; napi_value onResultCallBack; napi_value onAcquireInfoCallBack; napi_value onResultData[ARGS_TWO]; @@ -125,14 +109,8 @@ struct AuthUserInfo { 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 */ \ No newline at end of file +#endif /* OHOS_USERAUTH_COMMON_H */ diff --git a/interfaces/innerkits/napi/include/auth_object.h b/interfaces/innerkits/napi/include/auth_object.h index 7842eb985..c1fbf65c9 100755 --- a/interfaces/innerkits/napi/include/auth_object.h +++ b/interfaces/innerkits/napi/include/auth_object.h @@ -16,7 +16,7 @@ #ifndef AUTH_OBJECT_H #define AUTH_OBJECT_H -#include +#include namespace OHOS { namespace UserIAM { @@ -24,7 +24,7 @@ namespace UserAuth { class Napi_ExecutorProperty { public: int32_t result_ = 0; - int32_t authSubType_ = 0; + uint64_t authSubType_ = 0; uint32_t remainTimes_ = 0; uint32_t freezingTime_ = 0; }; @@ -51,4 +51,4 @@ public: } // namespace UserAuth } // namespace UserIAM } // namespace OHOS -#endif // AUTH_OBJECT_H \ No newline at end of file +#endif // AUTH_OBJECT_H diff --git a/interfaces/innerkits/napi/include/authapi_callback.h b/interfaces/innerkits/napi/include/authapi_callback.h index a081b25ea..a361b8cc0 100755 --- a/interfaces/innerkits/napi/include/authapi_callback.h +++ b/interfaces/innerkits/napi/include/authapi_callback.h @@ -31,7 +31,6 @@ class AuthApiCallback : public UserAuthCallback { public: AuthApiCallback(); virtual ~AuthApiCallback(); - Napi_ExecutorProperty peoperty_; GetPropertyInfo *getPropertyInfo_; SetPropertyInfo *setPropertyInfo_; AuthInfo *authInfo_; @@ -40,6 +39,13 @@ public: 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; + +private: + napi_value BuildExecutorProperty( + napi_env env, int32_t result, uint32_t remainTimes, uint32_t freezingTime, uint64_t authSubType); + napi_value Uint64ToNapi(napi_env env, uint64_t value); + napi_value BuildOnResult(napi_env env, uint32_t remainTimes, uint32_t freezingTime, std::vector token); + napi_value Uint8ArrayToNapi(napi_env env, std::vector value); }; } // namespace UserAuth } // namespace UserIAM diff --git a/interfaces/innerkits/napi/include/result_convert.h b/interfaces/innerkits/napi/include/result_convert.h index fd7829c66..bda603b97 100755 --- a/interfaces/innerkits/napi/include/result_convert.h +++ b/interfaces/innerkits/napi/include/result_convert.h @@ -22,6 +22,8 @@ #include "napi/native_common.h" #include "napi/native_node_api.h" +#include "userauth_info.h" + #include "auth_common.h" #include "auth_object.h" @@ -32,27 +34,19 @@ class ResultConvert { public: ResultConvert(); ~ResultConvert(); + napi_value Uint64ToUint8Napi(napi_env env, uint64_t value); std::vector 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 GetInt32ValueByKey(napi_env env, napi_value jsObject, std::string key); int32_t NapiGetValueInt32(napi_env env, napi_value value); std::vector 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 value, std::string key); - std::vector ConvertUint8(uint64_t value); - napi_value BuildNapiUint8Array(napi_env env, std::vector 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::vector GetCppArrayUint32(napi_env env, napi_value value); std::string NapiGetValueString(napi_env env, napi_value value); napi_value GetNapiValue(napi_env env, const std::string keyChar, napi_value object); - std::vector GetCppArrayUint32(napi_env env, napi_value value); }; } // namespace UserAuth } // namespace UserIAM diff --git a/interfaces/innerkits/napi/include/user_auth_impl.h b/interfaces/innerkits/napi/include/user_auth_impl.h index 416275719..2c7e55a72 100755 --- a/interfaces/innerkits/napi/include/user_auth_impl.h +++ b/interfaces/innerkits/napi/include/user_auth_impl.h @@ -15,10 +15,12 @@ #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" +#include "auth_build.h" +#include "auth_common.h" + namespace OHOS { namespace UserIAM { namespace UserAuth { @@ -26,9 +28,8 @@ class UserAuthImpl { public: UserAuthImpl(); ~UserAuthImpl(); - + AuthBuild authBuild; 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); @@ -46,13 +47,7 @@ private: 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); diff --git a/interfaces/innerkits/napi/src/auth_build.cpp b/interfaces/innerkits/napi/src/auth_build.cpp index ff107c6ec..cd5c85bda 100755 --- a/interfaces/innerkits/napi/src/auth_build.cpp +++ b/interfaces/innerkits/napi/src/auth_build.cpp @@ -15,11 +15,9 @@ #include "auth_build.h" -#include "securec.h" #include "auth_common.h" #include "auth_hilog_wrapper.h" #include "auth_object.h" -#include "result_convert.h" namespace OHOS { namespace UserIAM { @@ -38,7 +36,6 @@ Napi_SetPropertyRequest AuthBuild::SetPropertyRequestBuild(napi_env env, napi_va 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"); @@ -54,25 +51,17 @@ Napi_GetPropertyRequest AuthBuild::GetPropertyRequestBuild(napi_env env, napi_va 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; @@ -80,25 +69,11 @@ bool AuthBuild::NapiTypeObject(napi_env env, napi_value value) 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; @@ -106,145 +81,6 @@ bool AuthBuild::NapiTypeNumber(napi_env env, napi_value value) 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; @@ -254,42 +90,39 @@ uint64_t AuthBuild::GetUint8ArrayTo64(napi_env env, napi_value value) 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"); + if (!isTypedArray) { + HILOG_ERROR("GetUint8ArrayTo64 value is not typedarray"); + return 0; } napi_get_typedarray_info(env, value, &arraytype, &length, reinterpret_cast(&data), &buffer, &offset); - if (arraytype == napi_uint8_array) { - HILOG_INFO("InputerImpl, OnSetData get uint8 array "); - } else { - HILOG_ERROR("InputerImpl, OnSetData get uint8 array error"); + if (arraytype != napi_uint8_array) { + HILOG_ERROR("GetUint8ArrayTo64 js value is not uint8Array"); return 0; - } + } if (offset != 0) { - HILOG_INFO(" offset is =============>%{public}d", offset); + HILOG_ERROR("offset is %{public}d", offset); return 0; } - uint64_t resultUint64; - HILOG_INFO("data len = %{public}u", length); - if (memcpy_s(&resultUint64, sizeof(resultUint64), data, length) != EOK) { - HILOG_INFO("memcpy_s fail"); - return 0; + std::vector result(data, data + length); + uint8_t tmp[sizeof(uint64_t)]; + for (uint32_t i = 0; i < sizeof(uint64_t); i++) { + tmp[i] = result[i]; + HILOG_INFO("GetUint8ArrayTo64 result is %{public}d", (unsigned)result[i]); } - HILOG_INFO("resultUint64 = %{public}llu", resultUint64); - return resultUint64; + uint64_t *re = static_cast(static_cast(tmp)); + HILOG_INFO("GetUint8ArrayTo64 resultUint64 is %{public}llu", *re); + return *re; } 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)); + return convert.Uint64ToUint8Napi(env, value); } } // namespace UserAuth } // namespace UserIAM -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/innerkits/napi/src/auth_native_module.cpp b/interfaces/innerkits/napi/src/auth_native_module.cpp index 35a5d7722..d6277d4a0 100755 --- a/interfaces/innerkits/napi/src/auth_native_module.cpp +++ b/interfaces/innerkits/napi/src/auth_native_module.cpp @@ -14,6 +14,7 @@ */ #include + #include "user_auth_helper.h" namespace OHOS { @@ -37,4 +38,4 @@ extern "C" __attribute__((constructor)) void RegisterModule(void) } } // namespace UserAuth } // namespace UserIAM -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/innerkits/napi/src/authapi_callback.cpp b/interfaces/innerkits/napi/src/authapi_callback.cpp index 89f8a2fb3..4e6b4741a 100755 --- a/interfaces/innerkits/napi/src/authapi_callback.cpp +++ b/interfaces/innerkits/napi/src/authapi_callback.cpp @@ -15,7 +15,8 @@ #include "authapi_callback.h" -#include "auth_build.h" +#include "securec.h" + #include "auth_hilog_wrapper.h" namespace OHOS { @@ -29,46 +30,111 @@ AuthApiCallback::~AuthApiCallback() { } +napi_value AuthApiCallback::BuildExecutorProperty( + napi_env env, int32_t result, uint32_t remainTimes, uint32_t freezingTime, uint64_t authSubType) +{ + napi_value jsObject = nullptr; + NAPI_CALL(env, napi_create_object(env, &jsObject)); + + napi_value resultValue = 0; + NAPI_CALL(env, napi_create_int32(env, result, &resultValue)); + NAPI_CALL(env, napi_set_named_property(env, jsObject, "result", resultValue)); + + napi_value remainTimesValue = 0; + NAPI_CALL(env, napi_create_uint32(env, remainTimes, &remainTimesValue)); + NAPI_CALL(env, napi_set_named_property(env, jsObject, "remainTimes", remainTimesValue)); + + napi_value freezingTimeValue = 0; + NAPI_CALL(env, napi_create_uint32(env, freezingTime, &freezingTimeValue)); + NAPI_CALL(env, napi_set_named_property(env, jsObject, "freezingTime", freezingTimeValue)); + + napi_value jsType = Uint64ToNapi(env, authSubType); + NAPI_CALL(env, napi_set_named_property(env, jsObject, "authSubType", jsType)); + return jsObject; +} + +napi_value AuthApiCallback::Uint64ToNapi(napi_env env, uint64_t value) +{ + size_t length = sizeof(value); + napi_value out = nullptr; + void *data = nullptr; + napi_value arrayBuffer = nullptr; + size_t bufferSize = length; + NAPI_CALL(env, napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer)); + memcpy_s(data, bufferSize, reinterpret_cast(&value), bufferSize); + NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, bufferSize, arrayBuffer, 0, &out)); + return out; +} + +napi_value AuthApiCallback::Uint8ArrayToNapi(napi_env env, std::vector value) +{ + int size = value.size(); + HILOG_INFO("Uint8ArrayToNapi size = %{public}d", size); + napi_value out = nullptr; + 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_ERROR("AuthApiCallback Uint8ArrayToNapi error"); + } + NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, value.size(), buffer, 0, &out)); + return out; +} + +napi_value AuthApiCallback::BuildOnResult( + napi_env env, uint32_t remainTimes, uint32_t freezingTime, std::vector token) +{ + napi_value jsObject = nullptr; + NAPI_CALL(env, napi_create_object(env, &jsObject)); + + napi_value remainTimesValue = 0; + NAPI_CALL(env, napi_create_uint32(env, remainTimes, &remainTimesValue)); + NAPI_CALL(env, napi_set_named_property(env, jsObject, "remainTimes", remainTimesValue)); + + napi_value freezingTimeValue = 0; + NAPI_CALL(env, napi_create_uint32(env, freezingTime, &freezingTimeValue)); + NAPI_CALL(env, napi_set_named_property(env, jsObject, "freezingTime", freezingTimeValue)); + + napi_value jsToken = Uint8ArrayToNapi(env, token); + NAPI_CALL(env, napi_set_named_property(env, jsObject, "token", jsToken)); + return jsObject; +} + 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 2 = %{public}llu", 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; + napi_env env = getPropertyInfo_->callBackInfo.env; HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 5 "); - getPropertyInfo_->result = authBuild.GetNapiExecutorProperty(getPropertyInfo_->callBackInfo.env, peoperty_); + napi_value resultData[PARAM1]; + resultData[PARAM0] = BuildExecutorProperty( + env, result.result, result.remainTimes, result.freezingTime, static_cast(result.authSubType)); if (getPropertyInfo_->callBackInfo.callBack != nullptr) { - HILOG_INFO("AuthApiCallback onExecutorPropertyInfo 6 "); + HILOG_INFO("AuthApiCallback onExecutorPropertyInfo async 6"); napi_value global = nullptr; - status = napi_get_global(getPropertyInfo_->callBackInfo.env, &global); + status = napi_get_global(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 resultValue = nullptr; napi_value callBack = nullptr; - status = napi_get_reference_value( - getPropertyInfo_->callBackInfo.env, getPropertyInfo_->callBackInfo.callBack, &callBack); + status = napi_get_reference_value(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); + status = napi_call_function(env, global, callBack, PARAM1, resultData, &resultValue); if (status != napi_ok) { HILOG_INFO("napi_call_function faild "); } } else { - napi_value result = getPropertyInfo_->result; + HILOG_INFO("AuthApiCallback onExecutorPropertyInfo promise 6"); + napi_value resultValue = resultData[PARAM0]; napi_deferred deferred = getPropertyInfo_->callBackInfo.deferred; - status = napi_resolve_deferred(getPropertyInfo_->callBackInfo.env, deferred, result); + status = napi_resolve_deferred(env, deferred, resultValue); if (status != napi_ok) { HILOG_INFO("napi_resolve_deferred faild "); } @@ -76,29 +142,27 @@ void AuthApiCallback::onExecutorPropertyInfo(const ExecutorProperty result) delete getPropertyInfo_; getPropertyInfo_ = nullptr; } else { - HILOG_INFO("AuthApiCallback onExecutorPropertyInfo getPropertyInfo_ is nullptr"); + HILOG_ERROR("AuthApiCallback onExecutorPropertyInfo getPropertyInfo_ is nullptr"); } } void AuthApiCallback::onAcquireInfo(const int32_t module, const uint32_t acquireInfo, const int32_t extraInfo) { napi_status status; + napi_value callback; + napi_value params[PARAM3]; if (userInfo_ != nullptr) { + napi_env env = userInfo_->callBackInfo.env; 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); + status = napi_get_reference_value(env, userInfo_->onAcquireInfo, &callback); + if (status != napi_ok) { + HILOG_INFO("napi_get_reference_value faild "); + } + napi_create_int32(env, module, ¶ms[PARAM0]); + napi_create_uint32(env, acquireInfo, ¶ms[PARAM1]); + napi_create_int32(env, extraInfo, ¶ms[PARAM2]); + status = napi_call_function(env, userInfo_->jsFunction, callback, PARAM3, params, &returnOnAcquire); if (status != napi_ok) { HILOG_ERROR("napi_call_function faild"); } @@ -108,26 +172,16 @@ void AuthApiCallback::onAcquireInfo(const int32_t module, const uint32_t acquire } 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); + napi_env env = authInfo_->callBackInfo.env; + napi_value returnOnAcquire = nullptr; + status = napi_get_reference_value(env, authInfo_->onAcquireInfo, &callback); if (status != napi_ok) { - HILOG_ERROR("napi_get_reference_value faild %{public}d", status); + HILOG_INFO("napi_get_reference_value faild "); } - napi_value returnOnAcquire = nullptr; - status = napi_call_function(authInfo_->callBackInfo.env, authInfo_->jsFunction, - callbackRef, ARGS_THREE, authInfo_->onAcquireInfoData, &returnOnAcquire); + napi_create_int32(env, module, ¶ms[PARAM0]); + napi_create_uint32(env, acquireInfo, ¶ms[PARAM1]); + napi_create_int32(env, extraInfo, ¶ms[PARAM2]); + status = napi_call_function(env, authInfo_->jsFunction, callback, PARAM3, params, &returnOnAcquire); if (status != napi_ok) { HILOG_ERROR("napi_call_function faild"); } @@ -140,88 +194,94 @@ void AuthApiCallback::onAcquireInfo(const int32_t module, const uint32_t acquire void AuthApiCallback::onResult(const int32_t result, const AuthResult extraInfo) { - HILOG_INFO("AuthApiCallback onResult enter"); + HILOG_INFO("AuthApiCallback onResult start result = %{public}d", result); + HILOG_INFO("AuthApiCallback onResult start token.length = %{public}d", extraInfo.token.size()); + HILOG_INFO("AuthApiCallback onResult start extraInfo.remainTimes = %{public}u", extraInfo.remainTimes); + HILOG_INFO("AuthApiCallback onResult start extraInfo.freezingTime = %{public}u", extraInfo.freezingTime); napi_status status; + napi_value callback; 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); + napi_env env = userInfo_->callBackInfo.env; + status = napi_get_reference_value(env, userInfo_->onResult, &callback); if (status != napi_ok) { - HILOG_ERROR("napi_call_function faild"); + HILOG_INFO("napi_get_reference_value faild "); } + napi_value params[PARAM2]; + napi_create_int32(env, result, ¶ms[PARAM0]); + params[PARAM1] = BuildOnResult(env, extraInfo.remainTimes, extraInfo.freezingTime, extraInfo.token); + napi_value return_val = nullptr; + HILOG_INFO("AuthApiCallback onResult userInfo_ 5"); + napi_call_function(env, userInfo_->jsFunction, callback, PARAM2, params, &return_val); + delete userInfo_; + userInfo_ = nullptr; } else { - HILOG_INFO("AuthApiCallback onResult userInfo_ is nullptr "); + HILOG_ERROR("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); + HILOG_INFO("AuthApiCallback onResult authInfo_ 1"); + napi_env env = authInfo_->callBackInfo.env; + HILOG_INFO("AuthApiCallback onResult authInfo_ 2"); + status = napi_get_reference_value(authInfo_->callBackInfo.env, authInfo_->onResult, &callback); if (status != napi_ok) { - HILOG_ERROR("napi_call_function faild %{public}d", status); + HILOG_INFO("napi_get_reference_value faild "); } + napi_value params[PARAM2]; + napi_create_int32(env, result, ¶ms[PARAM0]); + params[PARAM1] = BuildOnResult(env, extraInfo.remainTimes, extraInfo.freezingTime, extraInfo.token); + napi_value return_val = nullptr; + HILOG_INFO("AuthApiCallback onResult userInfo_ 5"); + napi_call_function(env, authInfo_->jsFunction, callback, PARAM2, params, &return_val); + HILOG_INFO("AuthApiCallback onResult authInfo_ 6"); delete authInfo_; authInfo_ = nullptr; } else { - HILOG_INFO("AuthApiCallback onResult authInfo_ is nullptr "); + HILOG_ERROR("AuthApiCallback onResult authInfo_ is nullptr "); } HILOG_INFO("AuthApiCallback onResult end"); } void AuthApiCallback::onSetExecutorProperty(const int32_t result) { - HILOG_INFO("onSetExecutorProperty 1 = %{public}d", result); + HILOG_INFO("onSetExecutorProperty start = %{public}d", result); napi_status status; if (setPropertyInfo_ != nullptr) { - status = napi_create_int32(setPropertyInfo_->callBackInfo.env, result, &setPropertyInfo_->result); + napi_env env = setPropertyInfo_->callBackInfo.env; + status = napi_create_int32(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); + status = napi_get_global(env, &global); if (status != napi_ok) { - HILOG_ERROR("napi_get_global faild"); + HILOG_ERROR("napi_get_global faild"); } - napi_value resultData[1]; - resultData[0] = setPropertyInfo_->result; + napi_value resultData[PARAM1]; + resultData[PARAM0] = 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); + status = napi_get_reference_value(env, setPropertyInfo_->callBackInfo.callBack, &callBack); if (status != napi_ok) { - HILOG_ERROR("napi_get_reference_value faild"); + HILOG_ERROR("napi_get_reference_value faild"); } - status = napi_call_function(setPropertyInfo_->callBackInfo.env, global, callBack, 1, resultData, &result); + status = napi_call_function(env, global, callBack, PARAM1, resultData, &result); if (status != napi_ok) { - HILOG_ERROR("napi_call_function faild"); + 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); + status = napi_resolve_deferred(env, deferred, result); + if (status != napi_ok) { + HILOG_ERROR("napi_call_function faild"); + } } + delete setPropertyInfo_; + setPropertyInfo_ = nullptr; } + HILOG_INFO("onSetExecutorProperty end"); } } // namespace UserAuth } // namespace UserIAM -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/innerkits/napi/src/result_convert.cpp b/interfaces/innerkits/napi/src/result_convert.cpp index df8649b53..77abb2f6d 100644 --- a/interfaces/innerkits/napi/src/result_convert.cpp +++ b/interfaces/innerkits/napi/src/result_convert.cpp @@ -13,9 +13,11 @@ * limitations under the License. */ +#include "result_convert.h" + #include "securec.h" + #include "auth_hilog_wrapper.h" -#include "result_convert.h" namespace OHOS { namespace UserIAM { @@ -28,164 +30,21 @@ 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 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 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 value) +napi_value ResultConvert::Uint64ToUint8Napi(napi_env env, uint64_t value) { - HILOG_INFO("ResultConvert SetPropertyUint8ArrayTest strat "); + HILOG_INFO("ResultConvert Uint64ToUint8Napi uint64_t %{public}llu", value); + size_t length = sizeof(value); 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 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(); + size_t bufferSize = length; + NAPI_CALL(env, napi_create_arraybuffer(env, bufferSize, &data, &arrayBuffer)); + memcpy_s(data, bufferSize, reinterpret_cast(&value), bufferSize); napi_value result = nullptr; - NAPI_CALL(env, napi_create_arraybuffer(env, bufefersize, &cdata, &arrayBuffer)); - if (memcpy_s(cdata, bufefersize, reinterpret_cast(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"); + NAPI_CALL(env, napi_create_typedarray(env, napi_uint8_array, bufferSize, arrayBuffer, 0, &result)); 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 ResultConvert::NapiGetValueUint8Array(napi_env env, napi_value jsObject, std::string key) +std::vector ResultConvert::NapiGetValueUint8Array(napi_env env, napi_value jsObject, std::string key) { napi_value jsValue = GetNapiValue(env, key.c_str(), jsObject); std::vector RetNull; @@ -199,23 +58,20 @@ std::vector ResultConvert::NapiGetValueUint8Array(napi_env env, na 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"); + if (!isTypedArray) { + HILOG_ERROR("NapiGetValueUint8Array jsValue is not typedarray"); + return RetNull; } napi_get_typedarray_info(env, jsValue, &arraytype, &length, reinterpret_cast(&data), &buffer, &offset); - if (arraytype == napi_uint8_array) { - HILOG_INFO("InputerImpl, OnSetData get uint8 array "); - } else { - HILOG_ERROR("InputerImpl, OnSetData get uint8 array error"); + if (arraytype != napi_uint8_array) { + HILOG_ERROR("NapiGetValueUint8Array js jsValue is not uint8Array"); return RetNull; - } + } if (offset != 0) { - HILOG_INFO(" offset is =============>%{public}d", offset); + HILOG_ERROR("offset is %{public}d", offset); return RetNull; } - std::vector result(data, data+length); + std::vector result(data, data + length); return result; } @@ -248,9 +104,10 @@ int32_t ResultConvert::GetInt32ValueByKey(napi_env env, napi_value jsObject, std std::vector ResultConvert::GetCppArrayUint32(napi_env env, napi_value value) { + napi_status status; uint32_t arrayLength = 0; napi_get_array_length(env, value, &arrayLength); - if (arrayLength == 0) { + if (arrayLength <= 0) { HILOG_ERROR("%{public}s The array is empty.", __func__); return std::vector(); } @@ -258,7 +115,6 @@ std::vector ResultConvert::GetCppArrayUint32(napi_env env, napi_value for (size_t i = 0; i < arrayLength; i++) { napi_value napiElement = nullptr; napi_get_element(env, value, i, &napiElement); - napi_valuetype napiValueType = napi_undefined; napi_typeof(env, napiElement, &napiValueType); if (napiValueType != napi_number) { @@ -266,7 +122,10 @@ std::vector ResultConvert::GetCppArrayUint32(napi_env env, napi_value return std::vector(); } uint32_t napiValue = 0; - napi_get_value_uint32(env, napiElement, &napiValue); + status = napi_get_value_uint32(env, napiElement, &napiValue); + if (status != napi_ok) { + return std::vector(); + } paramArrays.push_back(napiValue); } return paramArrays; @@ -305,7 +164,7 @@ std::string ResultConvert::NapiGetValueString(napi_env env, napi_value value) 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); + status = napi_get_value_string_utf8(env, value, valueString, valueSize, &resultSize); if (status != napi_ok) { HILOG_ERROR("napi_get_value_string_utf8 faild"); } diff --git a/interfaces/innerkits/napi/src/user_auth_helper.cpp b/interfaces/innerkits/napi/src/user_auth_helper.cpp index a28ec55d7..e5982a1be 100755 --- a/interfaces/innerkits/napi/src/user_auth_helper.cpp +++ b/interfaces/innerkits/napi/src/user_auth_helper.cpp @@ -33,11 +33,10 @@ napi_value UserAuthServiceConstructor(napi_env env, napi_callback_info info) std::shared_ptr userAuthImpl; userAuthImpl.reset(new UserAuthImpl()); napi_value thisVar = nullptr; - size_t argc = 1; - napi_value argv[1] = {nullptr}; + size_t argc = ARGS_ONE; + napi_value argv[ARGS_ONE] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); - NAPI_CALL(env, napi_wrap( - env, thisVar, userAuthImpl.get(), + NAPI_CALL(env, napi_wrap(env, thisVar, userAuthImpl.get(), [](napi_env env, void *data, void *hint) { UserAuthImpl *userAuthImpl = static_cast(data); if (userAuthImpl != nullptr) { @@ -229,4 +228,4 @@ napi_value GetCtor(napi_env env) } } // namespace UserAuth } // namespace UserIAM -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/innerkits/napi/src/user_auth_impl.cpp b/interfaces/innerkits/napi/src/user_auth_impl.cpp index cc44846c2..ceeb649a9 100755 --- a/interfaces/innerkits/napi/src/user_auth_impl.cpp +++ b/interfaces/innerkits/napi/src/user_auth_impl.cpp @@ -19,7 +19,6 @@ #include "userauth_callback.h" #include "userauth_info.h" -#include "auth_build.h" #include "auth_hilog_wrapper.h" #include "authapi_callback.h" @@ -36,7 +35,6 @@ 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; @@ -46,7 +44,6 @@ napi_value UserAuthImpl::GetVersion(napi_env env, napi_callback_info info) 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)); @@ -54,12 +51,20 @@ napi_value UserAuthImpl::GetAvailabeStatus(napi_env env, napi_callback_info info 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"); + int type = authBuild.NapiGetValueInt(env, argv[PARAM0]); + if (type == GET_VALUE_ERROR) { + HILOG_ERROR("%{public}s, argv[PARAM0] error.", __func__); + return nullptr; + } + int level = authBuild.NapiGetValueInt(env, argv[PARAM1]); + if (level == GET_VALUE_ERROR) { + HILOG_ERROR("%{public}s, argv[PARAM1] error.", __func__); + return nullptr; + } + AuthType authType = AuthType(type); + AuthTurstLevel authTurstLevel = AuthTurstLevel(level); int32_t result = UserAuth::GetInstance().GetAvailableStatus(authType, authTurstLevel); + HILOG_INFO("GetAvailabeStatus result = %{public}d", result); napi_value ret = 0; NAPI_CALL(env, napi_create_int32(env, result, &ret)); return ret; @@ -92,9 +97,7 @@ napi_value UserAuthImpl::GetPropertyWrap(napi_env env, napi_callback_info info, } } - // C++ need js parms get - AuthBuild authBuild; - if (authBuild.NapiTypeObject(env, args[0])) { + if (authBuild.NapiTypeObject(env, args[PARAM0])) { Napi_GetPropertyRequest request = authBuild.GetPropertyRequestBuild(env, args[0]); getPropertyInfo->authType = request.authType_; getPropertyInfo->keys = request.keys_; @@ -115,8 +118,6 @@ void UserAuthImpl::GetPropertyExecute(napi_env env, void *data) HILOG_INFO("GetPropertyExecute, worker pool thread execute."); GetPropertyInfo *getPropertyInfo = static_cast(data); if (getPropertyInfo != nullptr) { - // do something C++ - AuthBuild authBuild; AuthType authTypeGet = AuthType(getPropertyInfo->authType); GetPropertyRequest request; @@ -137,10 +138,6 @@ void UserAuthImpl::GetPropertyExecute(napi_env env, void *data) 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(data); napi_delete_async_work(env, getPropertyInfo->asyncWork); HILOG_INFO("GetPropertyPromiseExecuteDone, end"); @@ -148,13 +145,10 @@ void UserAuthImpl::GetPropertyPromiseExecuteDone(napi_env env, napi_status statu void UserAuthImpl::GetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data) { - if (status != napi_ok) { - HILOG_ERROR("SetPropertyAsyncExecuteDone status is not ok===>"); - return; - } + HILOG_INFO("GetPropertyAsyncExecuteDone, start"); GetPropertyInfo *getPropertyInfo = static_cast(data); napi_delete_async_work(env, getPropertyInfo->asyncWork); - HILOG_INFO("GetPropertyPromiseExecuteDone, end"); + HILOG_INFO("GetPropertyAsyncExecuteDone, end"); } napi_value UserAuthImpl::GetPropertyAsync(napi_env env, GetPropertyInfo *getPropertyInfo) @@ -185,7 +179,7 @@ napi_value UserAuthImpl::GetPropertyPromise(napi_env env, GetPropertyInfo *getPr 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_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); getPropertyInfo->callBackInfo.callBack = nullptr; getPropertyInfo->callBackInfo.deferred = deferred; @@ -224,9 +218,7 @@ napi_value UserAuthImpl::SetPropertyWrap(napi_env env, napi_callback_info info, } } - // C++ need js parms get - AuthBuild authBuild; - if (authBuild.NapiTypeObject(env, args[0])) { + if (authBuild.NapiTypeObject(env, args[PARAM0])) { Napi_SetPropertyRequest request = authBuild.SetPropertyRequestBuild(env, args[0]); setPropertyInfo->authType = request.authType_; setPropertyInfo->key = request.key_; @@ -248,20 +240,16 @@ void UserAuthImpl::SetPropertyExecute(napi_env env, void *data) HILOG_INFO("setPropertyExecute, worker pool thread execute."); SetPropertyInfo *setPropertyInfo = static_cast(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 callback; callback.reset(object); - callback->setPropertyInfo_ = setPropertyInfo; UserAuth::GetInstance().SetProperty(request, callback); } else { HILOG_ERROR("setPropertyExecute, asynccallBackInfo == nullptr"); @@ -272,30 +260,17 @@ void UserAuthImpl::SetPropertyExecute(napi_env env, void *data) 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(data); napi_delete_async_work(env, setPropertyInfo->asyncWork); - delete setPropertyInfo; - setPropertyInfo = nullptr; - HILOG_INFO("SetPropertyPromiseExecuteDone, start"); + HILOG_INFO("SetPropertyPromiseExecuteDone, end"); } 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(data); - if (setPropertyInfo->asyncWork != nullptr) { - napi_delete_async_work(env, setPropertyInfo->asyncWork); - } - delete setPropertyInfo; - } + HILOG_INFO("SetPropertyAsyncExecuteDone, start"); + SetPropertyInfo *setPropertyInfo = static_cast(data); + napi_delete_async_work(env, setPropertyInfo->asyncWork); + HILOG_INFO("SetPropertyAsyncExecuteDone, end"); } napi_value UserAuthImpl::SetPropertyAsync(napi_env env, SetPropertyInfo *setPropertyInfo) @@ -351,29 +326,26 @@ napi_value UserAuthImpl::Auth(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, parms error.", __func__); return nullptr; } - AuthBuild authBuild; authInfo->challenge = authBuild.GetUint8ArrayTo64(env, argv[0]); - if (authBuild.NapiTypeNumber(env, argv[1])) { + if (authBuild.NapiTypeNumber(env, argv[PARAM1])) { int64_t type; - NAPI_CALL(env, napi_get_value_int64(env, argv[1], &type)); + NAPI_CALL(env, napi_get_value_int64(env, argv[PARAM1], &type)); authInfo->authType = type; } - if (authBuild.NapiTypeNumber(env, argv[ARGS_TWO])) { + if (authBuild.NapiTypeNumber(env, argv[PARAM2])) { int64_t level; - NAPI_CALL(env, napi_get_value_int64(env, argv[ARGS_TWO], &level)); + NAPI_CALL(env, napi_get_value_int64(env, argv[PARAM2], &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)); + if (authBuild.NapiTypeObject(env, argv[PARAM3])) { + authInfo->jsFunction = argv[PARAM3]; + NAPI_CALL(env, napi_get_named_property(env, argv[PARAM3], "onResult", &authInfo->onResultCallBack)); + NAPI_CALL(env, napi_create_reference(env, authInfo->onResultCallBack, PARAM1, &authInfo->onResult)); + NAPI_CALL(env, napi_get_named_property(env, argv[PARAM3], "onAcquireInfo", &authInfo->onAcquireInfoCallBack)); + NAPI_CALL(env, napi_create_reference(env, authInfo->onAcquireInfoCallBack, PARAM1, &authInfo->onAcquireInfo)); } return AuthWrap(env, authInfo); } @@ -385,7 +357,6 @@ napi_value UserAuthImpl::AuthWrap(napi_env env, AuthInfo *authInfo) HILOG_ERROR("%{public}s, param == nullptr.", __func__); return nullptr; } - AuthBuild authBuild; AuthApiCallback *object = new AuthApiCallback(); object->authInfo_ = authInfo; object->userInfo_ = nullptr; @@ -394,12 +365,8 @@ napi_value UserAuthImpl::AuthWrap(napi_env env, AuthInfo *authInfo) 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; } @@ -416,32 +383,29 @@ napi_value UserAuthImpl::AuthUser(napi_env env, napi_callback_info info) HILOG_ERROR("%{public}s, parms error.", __func__); return nullptr; } - AuthBuild authBuild; - if (authBuild.NapiTypeNumber(env, argv[0])) { + if (authBuild.NapiTypeNumber(env, argv[PARAM0])) { int32_t id = 0; - NAPI_CALL(env, napi_get_value_int32(env, argv[0], &id)); + NAPI_CALL(env, napi_get_value_int32(env, argv[PARAM0], &id)); userInfo->userId = id; } - - userInfo->challenge = authBuild.GetUint8ArrayTo64(env, argv[1]); - - if (authBuild.NapiTypeNumber(env, argv[ARGS_TWO])) { + userInfo->challenge = authBuild.GetUint8ArrayTo64(env, argv[PARAM1]); + if (authBuild.NapiTypeNumber(env, argv[PARAM2])) { int32_t type = 0; - napi_get_value_int32(env, argv[ARGS_TWO], &type); + napi_get_value_int32(env, argv[PARAM2], &type); userInfo->authType = type; } - - if (authBuild.NapiTypeNumber(env, argv[ARGS_THREE])) { + if (authBuild.NapiTypeNumber(env, argv[PARAM3])) { int32_t level = 0; - NAPI_CALL(env, napi_get_value_int32(env, argv[ARGS_THREE], &level)); + NAPI_CALL(env, napi_get_value_int32(env, argv[PARAM3], &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)); + if (authBuild.NapiTypeObject(env, argv[PARAM4])) { + HILOG_INFO("AuthUser is Object"); + userInfo->jsFunction = argv[PARAM4]; + NAPI_CALL(env, napi_get_named_property(env, argv[PARAM4], "onResult", &userInfo->onResultCallBack)); + NAPI_CALL(env, napi_create_reference(env, userInfo->onResultCallBack, PARAM1, &userInfo->onResult)); + NAPI_CALL(env, napi_get_named_property(env, argv[PARAM4], "onAcquireInfo", &userInfo->onAcquireInfoCallBack)); + NAPI_CALL(env, napi_create_reference(env, userInfo->onAcquireInfoCallBack, PARAM1, &userInfo->onAcquireInfo)); } return AuthUserWrap(env, userInfo); } @@ -461,11 +425,8 @@ napi_value UserAuthImpl::AuthUserWrap(napi_env env, AuthUserInfo *userInfo) 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; } @@ -475,10 +436,11 @@ napi_value UserAuthImpl::CancelAuth(napi_env env, napi_callback_info info) 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); - + if (contextId == 0) { + return nullptr; + } int32_t result = UserAuth::GetInstance().CancelAuth(contextId); HILOG_INFO("CancelAuth result = %{public}d", result); napi_value key = 0; diff --git a/interfaces/innerkits/native/include/userauth_info.h b/interfaces/innerkits/native/include/userauth_info.h index c293b8a05..4284e9b69 100755 --- a/interfaces/innerkits/native/include/userauth_info.h +++ b/interfaces/innerkits/native/include/userauth_info.h @@ -29,7 +29,7 @@ enum AuthType: uint32_t { FACE = 2, }; // 认证子类型(2D人脸,3D人脸...) -enum AuthSubType: uint32_t { +enum AuthSubType: uint64_t { /** * Authentication sub type six number pin. */ diff --git a/services/include/userauth_adapter.h b/services/include/userauth_adapter.h index 320902953..3f2b5a61f 100644 --- a/services/include/userauth_adapter.h +++ b/services/include/userauth_adapter.h @@ -52,8 +52,6 @@ public: void GetPropAuthInfoCoauth(uint64_t callerUID, std::string pkgName, int32_t resultCode, UserAuthToken authToken, GetPropertyRequest requset, sptr& 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 &sessionIds); int32_t RequestAuthResult(uint64_t contextId, std::vector scheduleToken, UserAuthToken &authToken, std::vector &sessionIds); diff --git a/services/include/userauth_controller.h b/services/include/userauth_controller.h index 28e4b13b1..079c765d7 100644 --- a/services/include/userauth_controller.h +++ b/services/include/userauth_controller.h @@ -32,8 +32,6 @@ public: int32_t SetExecutorProp(uint64_t callerUID, std::string pkgName, SetPropertyRequest setPropertyrequest, sptr& 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); diff --git a/services/include/userauth_datamgr.h b/services/include/userauth_datamgr.h index cf4bf08d9..73e60ae37 100755 --- a/services/include/userauth_datamgr.h +++ b/services/include/userauth_datamgr.h @@ -22,19 +22,19 @@ #include "userauth_adapter.h" #include "singleton.h" +#define OPENSSLSUCCESS 1 namespace OHOS { namespace UserIAM { namespace UserAuth { class UserAuthDataMgr : public Singleton { public: - static UserAuthDataMgr &GetInstance(); + 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_; diff --git a/services/include/userauth_excallback_impl.h b/services/include/userauth_excallback_impl.h index f1d28158c..65a2a9c44 100644 --- a/services/include/userauth_excallback_impl.h +++ b/services/include/userauth_excallback_impl.h @@ -53,6 +53,8 @@ private: std::mutex mutex_; static std::mutex coauthCallbackmutex_; static std::map> saveCoauthCallback_; + void OnFinishHandleExtend(SetPropertyRequest setPropertyRequest, AuthResult authResult, int32_t ret, + UserAuthToken authToken); }; class UserAuthCallbackImplSetProp : public CoAuth::SetPropCallback { diff --git a/services/src/context_thread_pool.cpp b/services/src/context_thread_pool.cpp index 24aa655e9..09f153a8b 100755 --- a/services/src/context_thread_pool.cpp +++ b/services/src/context_thread_pool.cpp @@ -14,7 +14,7 @@ */ #include "context_thread_pool.h" -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" namespace OHOS { namespace UserIAM { @@ -101,4 +101,4 @@ void ContextThreadPool::ContextTask::AddTask(const ThreadPool::Task& f) } } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/src/userauth_adapter.cpp b/services/src/userauth_adapter.cpp index 47cad8775..4dff5c26e 100644 --- a/services/src/userauth_adapter.cpp +++ b/services/src/userauth_adapter.cpp @@ -14,7 +14,7 @@ */ #include "userauth_adapter.h" -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "userauth_info.h" #include "auth_attributes.h" #include "co_auth.h" @@ -27,7 +27,6 @@ namespace OHOS { namespace UserIAM { namespace UserAuth { const int32_t cUserId = 0; -const uint64_t cCallerUID = 0; UserAuthAdapter &UserAuthAdapter::GetInstance() { @@ -176,22 +175,6 @@ int32_t UserAuthAdapter::GetUserID(int32_t &userID) 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 &sessionIds) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GenerateSolution is start!"); @@ -299,17 +282,20 @@ int32_t UserAuthAdapter::GetEachExecutorProp(GetPropertyRequest &requset, Execut { uint64_t tmpValue; int32_t ret = SUCCESS; + + result.freezingTime = 0; + result.remainTimes = 0; + result.authSubType = UserAuth::PIN_SIX; for (std::vector::const_iterator iter = requset.keys.begin(); iter != requset.keys.end(); ++iter) { switch (*iter) { case AUTH_SUB_TYPE: ret = pAuthAttributes->GetUint64Value(AUTH_SUBTYPE, tmpValue); if (ret != SUCCESS) { - USERAUTH_HILOGE(MODULE_SERVICE, "GetUint32Value->AUTH_SUBTYPE ERROR!"); + USERAUTH_HILOGE(MODULE_SERVICE, "GetUint64Value->AUTH_SUBTYPE ERROR!"); result.result = ret; return ret; } - value = static_cast(tmpValue); - result.authSubType = static_cast(value); + result.authSubType = static_cast(tmpValue); break; case REMAIN_TIMES: ret = pAuthAttributes->GetUint32Value(AUTH_REMAIN_COUNT, result.remainTimes); @@ -329,10 +315,11 @@ int32_t UserAuthAdapter::GetEachExecutorProp(GetPropertyRequest &requset, Execut break; default: USERAUTH_HILOGE(MODULE_SERVICE, "The key to get ExecutorProp is invalid."); - break; + result.result = INVALID_PARAMETERS; + return INVALID_PARAMETERS; } } - USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthAdapter::GetEachExecutorProp %{public}ull:%{public}u:%{public}u", + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthAdapter::GetEachExecutorProp %{public}llu:%{public}u:%{public}u", result.authSubType, result.remainTimes, result.freezingTime); return ret; } diff --git a/services/src/userauth_async_proxy.cpp b/services/src/userauth_async_proxy.cpp index 86bf8bb8f..da472454d 100755 --- a/services/src/userauth_async_proxy.cpp +++ b/services/src/userauth_async_proxy.cpp @@ -14,7 +14,7 @@ */ #include "userauth_async_proxy.h" -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "iuser_auth.h" namespace OHOS { @@ -32,15 +32,15 @@ void UserAuthAsyncProxy::onAcquireInfo(const int32_t module, const uint32_t acqu return ; } if (!data.WriteInt32(module)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(module)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteInt32(module)."); return; } if (!data.WriteUint32(acquireInfo)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(acquireInfo)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint32(acquireInfo)."); return; } if (!data.WriteInt32(extraInfo)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(extraInfo)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteInt32(extraInfo)."); return; } @@ -51,52 +51,31 @@ void UserAuthAsyncProxy::onAcquireInfo(const int32_t module, const uint32_t acqu } 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; - } + 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) { @@ -120,19 +99,19 @@ void UserAuthAsyncProxy::onExecutorPropertyInfo(const ExecutorProperty result) WriteFailResult(result, resultFail, data); } else { if (!data.WriteInt32(result.result)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to 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)."); + if (!data.WriteUint64(result.authSubType)) { + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint64(result.authSubType)."); return; } if (!data.WriteUint32(result.remainTimes)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to 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)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint32(result.freezingTime)."); return; } } @@ -151,19 +130,19 @@ void UserAuthAsyncProxy::WriteFailResult(const ExecutorProperty &result, Executo resultFail.freezingTime = 0; resultFail.remainTimes = 0; if (!data.WriteInt32(result.result)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to 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)."); + if (!data.WriteUint64(resultFail.authSubType)) { + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint64(resultFail.authSubType)."); return; } if (!data.WriteUint32(resultFail.remainTimes)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to 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)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint32(resultFail.freezingTime)."); return; } } @@ -179,7 +158,7 @@ void UserAuthAsyncProxy::onSetExecutorProperty(const int32_t result) return ; } if (!data.WriteInt32(result)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(result)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteInt32(result)."); return; } diff --git a/services/src/userauth_controller.cpp b/services/src/userauth_controller.cpp index 40bce1d2b..2beb1145f 100644 --- a/services/src/userauth_controller.cpp +++ b/services/src/userauth_controller.cpp @@ -39,14 +39,6 @@ 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 &sessionIds) { return UserAuthAdapter::GetInstance().GenerateSolution(param, sessionIds); diff --git a/services/src/userauth_datamgr.cpp b/services/src/userauth_datamgr.cpp index 834599332..caeb7f69c 100644 --- a/services/src/userauth_datamgr.cpp +++ b/services/src/userauth_datamgr.cpp @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "userauth_datamgr.h" -#include "userauth_common.h" +#include -#include +#include "userauth_hilog_wrapper.h" +#include "userauth_datamgr.h" namespace OHOS { namespace UserIAM { @@ -27,7 +27,6 @@ UserAuthDataMgr &UserAuthDataMgr::GetInstance() } int32_t UserAuthDataMgr::AddContextID(uint64_t contextID) { - int32_t ret = SUCCESS; USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth AddContextID is start"); std::lock_guard lock(mutex_); if (contextIDs_.count(contextID) == 1) { @@ -35,8 +34,8 @@ int32_t UserAuthDataMgr::AddContextID(uint64_t contextID) return GENERAL_ERROR; } contextIDs_.insert(contextID); - - return ret; + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth AddContextID is end"); + return SUCCESS; } int32_t UserAuthDataMgr::IsContextIDExist(uint64_t contextID) { @@ -45,30 +44,25 @@ int32_t UserAuthDataMgr::IsContextIDExist(uint64_t contextID) if (contextIDs_.count(contextID) == 1) { return SUCCESS; } + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth IsContextIDExist is end"); 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 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; + if (RAND_bytes(reinterpret_cast(&contextID), (int)sizeof(contextID)) != OPENSSLSUCCESS) { + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth GenerateContextID Error"); + continue; } - char *tmprand = BN_bn2dec(btmp); - contextID = std::atoll(tmprand); - } while ((contextIDs_.count(contextID) == 1) || (contextID == 0)); - BN_free(btmp); - + } while ((contextIDs_.count(contextID) > 0) || (contextID == 0)); + USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth GenerateContextID is end"); return SUCCESS; } + int32_t UserAuthDataMgr::DeleteContextID(uint64_t contextID) { USERAUTH_HILOGD(MODULE_SERVICE, "UserAuth DeleteContextID is start"); diff --git a/services/src/userauth_excallback_impl.cpp b/services/src/userauth_excallback_impl.cpp index 95e2eea71..6f15a822c 100644 --- a/services/src/userauth_excallback_impl.cpp +++ b/services/src/userauth_excallback_impl.cpp @@ -14,7 +14,7 @@ */ #include "userauth_excallback_impl.h" -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "userauth_datamgr.h" #include "coauth_info_define.h" #include "userauth_async_proxy.h" @@ -142,9 +142,29 @@ void UserAuthCallbackImplCoAuth::OnAcquireInfo(uint32_t acquire) return; } } +void UserAuthCallbackImplCoAuth::OnFinishHandleExtend(SetPropertyRequest setPropertyRequest, AuthResult authResult, + int32_t ret, UserAuthToken authToken) +{ + 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); + } +} void UserAuthCallbackImplCoAuth::OnFinishHandle(uint32_t resultCode, std::vector scheduleToken) { - UserAuthToken authToken; + UserAuthToken authToken = {}; std::vector sessionIds; SetPropertyRequest setPropertyRequest; GetPropertyRequest getPropertyRequest; @@ -169,22 +189,7 @@ void UserAuthCallbackImplCoAuth::OnFinishHandle(uint32_t resultCode, std::vector } 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); - } + OnFinishHandleExtend(setPropertyRequest, authResult, ret, authToken); } else { USERAUTH_HILOGD(MODULE_SERVICE, "RequestAuthResult NOT SUCCESS"); getPropertyRequest.authType = authType_; @@ -201,7 +206,7 @@ void UserAuthCallbackImplCoAuth::OnFinishHandle(uint32_t resultCode, std::vector callback_); } if (sessionIds.size() != 0) { - for (std::vector::iterator iter = sessionIds.begin(); iter != sessionIds.end(); ++iter) { + for (std::vector::iterator iter = sessionIds.begin(); iter != sessionIds.end(); iter++) { UserAuthAdapter::GetInstance().Cancel(*iter); } } @@ -223,7 +228,8 @@ void UserAuthCallbackImplCoAuth::OnAcquireInfoHandle(uint32_t acquire) callback_->onAcquireInfo(module, acquireInfo, extraInfo); } -int32_t UserAuthCallbackImplCoAuth::SaveCoauthCallback(uint64_t contextId, std::shared_ptr coauthCallback) +int32_t UserAuthCallbackImplCoAuth::SaveCoauthCallback(uint64_t contextId, + std::shared_ptr coauthCallback) { int32_t resultCode = SUCCESS; std::lock_guard lock(coauthCallbackmutex_); @@ -279,7 +285,10 @@ void UserAuthCallbackImplIDMGetPorp::OnGetInfo(std::vectortemplateId; - UserAuthAdapter::GetInstance().GetExecutorProp(callerUid_, pkgName_, tmp, requst_, executorProperty); + int32_t ret = UserAuthAdapter::GetInstance().GetExecutorProp(callerUid_, pkgName_, tmp, requst_, executorProperty); + if (ret != SUCCESS) { + USERAUTH_HILOGE(MODULE_SERVICE, "UserAuth UserAuthCallbackImplIDMGetPorp ERROR!"); + } callback_->onExecutorPropertyInfo(executorProperty); } diff --git a/services/src/userauth_service.cpp b/services/src/userauth_service.cpp index 68475ae19..4f827b150 100644 --- a/services/src/userauth_service.cpp +++ b/services/src/userauth_service.cpp @@ -15,7 +15,7 @@ #include #include -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "useriam_common.h" #include "userauth_service.h" @@ -93,28 +93,16 @@ int32_t UserAuthService::GetAvailableStatus(const AuthType authType, const AuthT void UserAuthService::GetProperty(const GetPropertyRequest request, sptr& 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 ; - } + callerID = this->GetCallingUid(); + callerName = std::to_string(callerID); + sptr dr = new UserAuthServiceCallbackDeathRecipient(callback); if ((!callback->AsObject()->AddDeathRecipient(dr))) { USERAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient UserAuthServiceCallbackDeathRecipient"); @@ -134,18 +122,9 @@ void UserAuthService::SetProperty(const SetPropertyRequest request, sptronSetExecutorProperty(ret); - return ; - } - ret = userauthController_.GetPkgName(callerName); - if (ret != SUCCESS) { - USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth GetPkgName is ERROR!"); - callback->onSetExecutorProperty(ret); - return ; - } + callerID = this->GetCallingUid(); + callerName = std::to_string(callerID); + sptr dr = new UserAuthServiceCallbackDeathRecipient(callback); if ((!callback->AsObject()->AddDeathRecipient(dr))) { USERAUTH_HILOGE(MODULE_SERVICE, "Failed to add death recipient UserAuthServiceCallbackDeathRecipient"); @@ -274,20 +253,9 @@ int32_t UserAuthService::GetControllerData(sptr& callback, Au 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; - } + callerID = this->GetCallingUid(); + callerName = std::to_string(callerID); + result = userauthController_.GenerateContextID(contextID); if (result != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser GenerateContextID is ERROR!"); @@ -319,7 +287,7 @@ int32_t UserAuthService::CancelAuth(const uint64_t contextId) result = userauthController_.CancelContext(contextId, sessionIds); if (result == SUCCESS) { - for (std::vector::iterator iter = sessionIds.begin(); iter != sessionIds.end(); ++iter) { + for (std::vector::iterator iter = sessionIds.begin(); iter != sessionIds.end(); iter++) { result = userauthController_.Cancel(*iter); if (result != SUCCESS) { USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService CancelAuth Cancel is ERROR!"); diff --git a/services/src/userauth_stub.cpp b/services/src/userauth_stub.cpp index 063222ed3..ee2345a3a 100644 --- a/services/src/userauth_stub.cpp +++ b/services/src/userauth_stub.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ #include -#include "userauth_common.h" +#include "userauth_hilog_wrapper.h" #include "userauth_stub.h" namespace OHOS { @@ -60,11 +60,11 @@ int32_t UserAuthStub::GetAvailableStatusStub(MessageParcel& data, MessageParcel& int32_t ret = GENERAL_ERROR; if (!data.ReadUint32(authType)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(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)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint32(authTurstLevel)."); return E_READ_PARCEL_ERROR; } @@ -85,11 +85,11 @@ int32_t UserAuthStub::GetPropertyStub(MessageParcel& data, MessageParcel& reply) std::vector keys; if (!data.ReadUint32(authType)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(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)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUInt32Vector(&keys)."); return E_READ_PARCEL_ERROR; } @@ -119,15 +119,15 @@ int32_t UserAuthStub::SetPropertyStub(MessageParcel& data, MessageParcel& reply) std::vector setInfo; if (!data.ReadUint32(authType)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint32(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)."); + 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)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUInt8Vector(&setInfo)."); return E_READ_PARCEL_ERROR; } @@ -158,15 +158,15 @@ int32_t UserAuthStub::AuthStub(MessageParcel& data, MessageParcel& reply) uint64_t ret = SUCCESS; if (!data.ReadUint64(challenge)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint64(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)."); + 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)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint32(authTurstLevel)."); return E_READ_PARCEL_ERROR; } @@ -198,19 +198,19 @@ int32_t UserAuthStub::AuthUserStub(MessageParcel& data, MessageParcel& reply) uint64_t ret = SUCCESS; if (!data.ReadInt32(userID)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteInt32(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)."); + 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)."); + 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)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint32(authTurstLevel)."); return E_READ_PARCEL_ERROR; } @@ -252,7 +252,7 @@ int32_t UserAuthStub::CancelAuthStub(MessageParcel& data, MessageParcel& reply) int32_t ret = GENERAL_ERROR; if (!data.ReadUint64(contextID)) { - USERAUTH_HILOGE(MODULE_SERVICE,"failed to WriteUint64(contextID)."); + USERAUTH_HILOGE(MODULE_SERVICE, "failed to WriteUint64(contextID)."); return E_READ_PARCEL_ERROR; } diff --git a/utils/native/include/userauth_common.h b/utils/native/include/userauth_common.h deleted file mode 100644 index cb90090a6..000000000 --- a/utils/native/include/userauth_common.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 - -#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 -constexpr auto ToUnderlying(E e) noexcept -{ - return static_cast>(e); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -#endif // USERAUTH_COMMON_H -- Gitee