From 7e47a55d5c2de079b5a9c458bd4174f834935110 Mon Sep 17 00:00:00 2001 From: Tianshi Liu Date: Mon, 15 May 2023 00:01:52 +0800 Subject: [PATCH] update useriam idl doc Signed-off-by: Tianshi Liu Change-Id: Ia658a457a8acf6af1ed4d916fce775f11dde3660 Signed-off-by: Tianshi Liu --- .../driver-peripherals-face_auth-des.md | 129 ++++++++++----- ...driver-peripherals-fingerprint_auth-des.md | 117 +++++++++----- .../driver/driver-peripherals-pinauth-des.md | 150 +++++++++++------- .../driver-peripherals-user-auth-des.md | 114 ++++++++----- 4 files changed, 336 insertions(+), 174 deletions(-) diff --git a/zh-cn/device-dev/driver/driver-peripherals-face_auth-des.md b/zh-cn/device-dev/driver/driver-peripherals-face_auth-des.md index 48ffbf0f52..a876de3164 100644 --- a/zh-cn/device-dev/driver/driver-peripherals-face_auth-des.md +++ b/zh-cn/device-dev/driver/driver-peripherals-face_auth-des.md @@ -90,7 +90,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 ### 接口说明 -注:以下接口列举的为IDL接口描述生成的对应C++语言函数接口,接口声明见idl文件(/drivers/interface/face_auth/v1_0/)。 +注:以下接口列举的为IDL接口描述生成的对应C++语言函数接口,接口声明见idl文件(/drivers/interface/face_auth)。 在本文中,人脸凭据的录入、认证、识别和删除相关的HDI接口如表1所示,表2中的回调函数分别用于人脸执行器返回操作结果给框架和返回操作过程中的提示信息给上层应用。 @@ -98,23 +98,29 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 | 接口名称 | 功能介绍 | | ----------------------------------- | ---------------------------------- | -| GetExecutorList(std::vector>& executorList) | 获取执行器列表。 | +| GetExecutorList(std::vector\>& executorList) | 获取V1_0版本执行器列表。 | +| GetExecutorListV1_1(std::vector\>& executorList) | 获取V1_1版本执行器列表。 | | GetExecutorInfo(ExecutorInfo& info) | 获取执行器信息,包括执行器类型、执行器角色、认证类型、安全等级、执行器公钥等信息,用于向用户认证框架注册执行器。 | | GetTemplateInfo(uint64_t templateId, TemplateInfo& info) | 获取指定人脸模板ID的模板信息。 | -| OnRegisterFinish(const std::vector& templateIdList,
const std::vector& frameworkPublicKey, const std::vector& extraInfo) | 执行器注册成功后,获取用户认证框架的公钥信息;获取用户认证框架的人脸模板列表用于对账。 | -| Enroll(uint64_t scheduleId, const std::vector& extraInfo,
const sptr& callbackObj) | 录入人脸模板。 | -| Authenticate(uint64_t scheduleId, const std::vector& templateIdList,
const std::vector& extraInfo, const sptr& callbackObj) | 认证人脸模板。 | -| Identify(uint64_t scheduleId, const std::vector& extraInfo,
const sptr& callbackObj) | 识别人脸模板。 | -| Delete(const std::vector& templateIdList) | 删除人脸模板。 | +| OnRegisterFinish(const std::vector\& templateIdList,
const std::vector\& frameworkPublicKey, const std::vector\& extraInfo) | 执行器注册成功后,获取用户认证框架的公钥信息;获取用户认证框架的人脸模板列表用于对账。 | +| Enroll(uint64_t scheduleId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 录入人脸模板。 | +| Authenticate(uint64_t scheduleId, const std::vector\& templateIdList,
const std::vector\& extraInfo, const sptr\& callbackObj) | 认证人脸模板。 | +| Identify(uint64_t scheduleId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 识别人脸模板。 | +| Delete(const std::vector\& templateIdList) | 删除人脸模板。 | | Cancel(uint64_t scheduleId) | 通过scheduleId取消指定录入、认证、识别操作。 | -| SendCommand(int32_t commandId, const std::vector& extraInfo,
const sptr& callbackObj) | 人脸认证服务向Face_auth驱动传递参数的通用接口。 | +| SendCommand(int32_t commandId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 人脸认证服务向Face_auth驱动传递参数的通用接口。 | +| SetBufferProducer(const sptr\ &bufferProducer) | 设置预览流缓冲区。 | +| GetProperty(const std::vector\& templateIdList,
const std::vector\& propertyTypes, Property& property) | 获取执行器属性信息。 | +| SetCachedTemplates(const std::vector\ &templateIdList) | 设置需缓存模板列表。 | +| RegisterSaCommandCallback(const sptr\ &callbackObj) | 注册SA命令回调。 | **表2** 回调函数介绍 | 接口名称 | 功能介绍 | | ------------------------------------------------------------ | ------------------------ | -| IExecutorCallback::OnResult(int32_t code, const std::vector& extraInfo) | 返回操作的最终结果。 | -| IExecutorCallback::OnTip(int32_t code, const std::vector& extraInfo) | 返回操作的过程交互信息。 | +| IExecutorCallback::OnResult(int32_t code, const std::vector\& extraInfo) | 返回操作的最终结果。 | +| IExecutorCallback::OnTip(int32_t code, const std::vector\& extraInfo) | 返回操作的过程交互信息。 | +| ISaCommandCallback::OnSaCommands(const std::vector\& commands) | 发送命令列表。 | ### 开发步骤 @@ -143,7 +149,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 struct IDeviceIoService ioService; OHOS::sptr stub; }; - + // 服务接口调用响应接口 static int32_t FaceAuthInterfaceDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) @@ -151,11 +157,11 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGI("start"); auto *hdfFaceAuthInterfaceHost = CONTAINER_OF(client->device->service, struct HdfFaceAuthInterfaceHost, ioService); - + OHOS::MessageParcel *dataParcel = nullptr; OHOS::MessageParcel *replyParcel = nullptr; OHOS::MessageOption option; - + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) { IAM_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; @@ -164,10 +170,10 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; } - + return hdfFaceAuthInterfaceHost->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option); } - + // 初始化接口 int HdfFaceAuthInterfaceDriverInit(struct HdfDeviceObject *deviceObject) { @@ -178,7 +184,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 } return HDF_SUCCESS; } - + // Face_auth驱动对外提供的服务绑定到HDF框架 int HdfFaceAuthInterfaceDriverBind(struct HdfDeviceObject *deviceObject) { @@ -188,29 +194,29 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGE("%{public}s: failed to create HdfFaceAuthInterfaceHost object", __func__); return HDF_FAILURE; } - + hdfFaceAuthInterfaceHost->ioService.Dispatch = FaceAuthInterfaceDriverDispatch; hdfFaceAuthInterfaceHost->ioService.Open = NULL; hdfFaceAuthInterfaceHost->ioService.Release = NULL; - + auto serviceImpl = IFaceAuthInterface::Get(true); if (serviceImpl == nullptr) { IAM_LOGE("%{public}s: failed to implement service", __func__); return HDF_FAILURE; } - + hdfFaceAuthInterfaceHost->stub = OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, IFaceAuthInterface::GetDescriptor()); if (hdfFaceAuthInterfaceHost->stub == nullptr) { IAM_LOGE("%{public}s: failed to get stub object", __func__); return HDF_FAILURE; } - + deviceObject->service = &hdfFaceAuthInterfaceHost->ioService; IAM_LOGI("success"); return HDF_SUCCESS; } - + // 释放Face_auth驱动中的资源 void HdfFaceAuthInterfaceDriverRelease(struct HdfDeviceObject *deviceObject) { @@ -220,7 +226,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 delete hdfFaceAuthInterfaceHost; IAM_LOGI("success"); } - + // 注册Face_auth驱动入口数据结构体对象 struct HdfDriverEntry g_faceAuthInterfaceDriverEntry = { .moduleVersion = 1, @@ -229,7 +235,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 .Init = HdfFaceAuthInterfaceDriverInit, .Release = HdfFaceAuthInterfaceDriverRelease, }; - + // 调用HDF_INIT将驱动入口注册到HDF框架中。在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出 HDF_INIT(g_faceAuthInterfaceDriverEntry); ``` @@ -238,19 +244,19 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 ```c++ // 执行器实现类 - class ExecutorImpl : public IExecutor { + class ExecutorImpl : public V1_1::IExecutor { public: ExecutorImpl(struct ExecutorInfo executorInfo); virtual ~ExecutorImpl() {} - + private: struct ExecutorInfo executorInfo_; // 执行器信息 }; - + static constexpr uint16_t SENSOR_ID = 123; // 执行器sensorID static constexpr uint32_t EXECUTOR_TYPE = 123; // 执行器类型 static constexpr size_t PUBLIC_KEY_LEN = 32; // 执行器32字节公钥 - + // 创建HDI服务对象 extern "C" IFaceAuthInterface *FaceAuthInterfaceImplGetInstance(void) { @@ -261,9 +267,9 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 } return faceAuthInterfaceService; } - + // 获取执行器列表实现,创建执行器 - int32_t GetExecutorList(std::vector>& executorList) + int32_t GetExecutorListV1_1(std::vector>& executorList) { IAM_LOGI("interface mock start"); executorList.clear(); @@ -281,10 +287,21 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGE("executor is nullptr"); return HDF_FAILURE; } - executorList.push_back(sptr(executor)); + executorList.push_back(sptr(executor)); IAM_LOGI("interface mock success"); return HDF_SUCCESS; } + + // 获取V1_0执行器列表实现,使用V1_1版本执行器实现V1_0版本执行器的功能 + int32_t GetExecutorList(std::vector> &executorList) + { + std::vector> executorListV1_1; + int32_t result = GetExecutorListV1_1(executorListV1_1); + for (auto &executor : executorListV1_1) { + executorList.push_back(executor); + } + return result; + } ``` 3. 实现执行器每个功能接口,详细代码参见[executor_impl.cpp](https://gitee.com/openharmony/drivers_peripheral/blob/master/face_auth/hdi_service/src/executor_impl.cpp)文件。 @@ -298,7 +315,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGI("get executor information success"); return HDF_SUCCESS; } - + // 实现获取指定模板ID的模板信息接口 int32_t GetTemplateInfo(uint64_t templateId, TemplateInfo& info) { @@ -308,7 +325,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGI("get template information success"); return HDF_SUCCESS; } - + // 实现执行器注册成功后,获取用户认证框架的公钥信息、获取用户认证框架的模板列表接口。将公钥信息保持,模板列表用于和本地的模板做对账 int32_t OnRegisterFinish(const std::vector& templateIdList, const std::vector& frameworkPublicKey, const std::vector& extraInfo) @@ -320,7 +337,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGI("register finish"); return HDF_SUCCESS; } - + // 实现人脸录入接口 int32_t Enroll(uint64_t scheduleId, const std::vector& extraInfo, const sptr& callbackObj) @@ -336,7 +353,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 } return HDF_SUCCESS; } - + // 实现人脸认证接口 int32_t Authenticate(uint64_t scheduleId, const std::vector& templateIdList, const std::vector& extraInfo, const sptr& callbackObj) @@ -353,7 +370,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 } return HDF_SUCCESS; } - + // 实现人脸识别接口 int32_t Identify(uint64_t scheduleId, const std::vector& extraInfo, const sptr& callbackObj) @@ -369,7 +386,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 } return HDF_SUCCESS; } - + // 实现删除人脸模板接口 int32_t Delete(const std::vector& templateIdList) { @@ -378,7 +395,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGI("delete success"); return HDF_SUCCESS; } - + // 实现通过scheduleId取消指定操作接口 int32_t Cancel(uint64_t scheduleId) { @@ -387,7 +404,7 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 IAM_LOGI("cancel success"); return HDF_SUCCESS; } - + // 实现人脸认证服务向Face_auth驱动传递参数的通用接口,当前需要实现冻结与解锁模板命令 int32_t SendCommand(int32_t commandId, const std::vector& extraInfo, const sptr& callbackObj) @@ -422,8 +439,42 @@ Face_auth驱动的主要工作是为上层用户认证框架和Face_auth服务 } return HDF_SUCCESS; } + + // 实现设置预览流缓冲区接口 + int32_t ExecutorImpl::SetBufferProducer(const sptr &bufferProducer) + { + IAM_LOGI("interface mock start set buffer producer %{public}s", + UserIam::Common::GetPointerNullStateString(bufferProducer.GetRefPtr()).c_str()); + return HDF_SUCCESS; + } + + // 实现获取执行器属性接口 + int32_t ExecutorImpl::GetProperty( + const std::vector &templateIdList, const std::vector &propertyTypes, Property &property) + { + IAM_LOGI("interface mock start"); + property = {}; + IAM_LOGI("get property success"); + return HDF_SUCCESS; + } + + // 实现设置需缓存模板列表接口 + int32_t ExecutorImpl::SetCachedTemplates(const std::vector &templateIdList) + { + IAM_LOGI("interface mock start"); + IAM_LOGI("set cached templates success"); + return HDF_SUCCESS; + } + + // 实现注册SA命令回调接口 + int32_t ExecutorImpl::RegisterSaCommandCallback(const sptr &callbackObj) + { + IAM_LOGI("interface mock start"); + IAM_LOGI("register sa command callback success"); + return HDF_SUCCESS; + } ``` - + 4. 用户身份认证框架支持多driver,当增加driver或者修改driver信息,需要修改如下文件中serviceName2Config。 ```c++ diff --git a/zh-cn/device-dev/driver/driver-peripherals-fingerprint_auth-des.md b/zh-cn/device-dev/driver/driver-peripherals-fingerprint_auth-des.md index 0f593ed75d..4d9def9e5e 100644 --- a/zh-cn/device-dev/driver/driver-peripherals-fingerprint_auth-des.md +++ b/zh-cn/device-dev/driver/driver-peripherals-fingerprint_auth-des.md @@ -95,23 +95,27 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin | 接口名称 | 功能介绍 | | -------------------------------- | ----------------------------------- | -| GetExecutorList(std::vector>& executorList) | 获取执行器列表。 | +| GetExecutorList(std::vector\>& executorList) | 获取V1_0版本执行器列表。 | +| GetExecutorListV1_1(std::vector\>& executorList) | 获取V1_1版本执行器列表。 | | GetExecutorInfo(ExecutorInfo& info) | 获取执行器信息,包括执行器类型、执行器角色、认证类型、安全等级、执行器公钥等信息,用于向用户认证框架注册执行器。 | | GetTemplateInfo(uint64_t templateId, TemplateInfo& info) | 获取指定模板ID的模板信息。 | -| OnRegisterFinish(const std::vector& templateIdList,
const std::vector& frameworkPublicKey, const std::vector& extraInfo) | 执行器注册成功后,获取用户认证框架的公钥信息;获取用户认证框架的模板列表用于对账。 | -| Enroll(uint64_t scheduleId, const std::vector& extraInfo,
const sptr& callbackObj) | 录入指纹模板。 | -| Authenticate(uint64_t scheduleId, const std::vector& templateIdList,
const std::vector& extraInfo, const sptr& callbackObj) | 认证指纹模板。 | -| Identify(uint64_t scheduleId, const std::vector& extraInfo,
const sptr& callbackObj) | 识别指纹模板。 | -| Delete(const std::vector& templateIdList) | 删除指纹模板。 | +| OnRegisterFinish(const std::vector\& templateIdList,
const std::vector\& frameworkPublicKey, const std::vector\& extraInfo) | 执行器注册成功后,获取用户认证框架的公钥信息;获取用户认证框架的模板列表用于对账。 | +| Enroll(uint64_t scheduleId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 录入指纹模板。 | +| Authenticate(uint64_t scheduleId, const std::vector\& templateIdList,
const std::vector\& extraInfo, const sptr\& callbackObj) | 认证指纹模板。 | +| Identify(uint64_t scheduleId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 识别指纹模板。 | +| Delete(const std::vector\& templateIdList) | 删除指纹模板。 | | Cancel(uint64_t scheduleId) | 通过scheduleId取消指定录入、认证、识别操作。 | -| SendCommand(int32_t commandId, const std::vector& extraInfo,
const sptr& callbackObj) | 指纹认证服务向Fingerprint_auth驱动传递参数的通用接口。 | - +| SendCommand(int32_t commandId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 指纹认证服务向Fingerprint_auth驱动传递参数的通用接口。 | +| GetProperty(const std::vector\& templateIdList,
const std::vector\& propertyTypes, Property& property) | 获取执行器属性信息。 | +| SetCachedTemplates(const std::vector\ &templateIdList) | 设置需缓存模板列表。 | +| RegisterSaCommandCallback(const sptr\ &callbackObj) | 注册SA命令回调。 | **表2** 回调函数介绍 | 接口名称 | 功能介绍 | | ------------------------------------------------------------ | ------------------------ | -| IExecutorCallback::OnResult(int32_t code, const std::vector& extraInfo) | 返回操作的最终结果。 | -| IExecutorCallback::OnTip(int32_t code, const std::vector& extraInfo) | 返回操作的过程交互信息。 | +| IExecutorCallback::OnResult(int32_t code, const std::vector\& extraInfo) | 返回操作的最终结果。 | +| IExecutorCallback::OnTip(int32_t code, const std::vector\& extraInfo) | 返回操作的过程交互信息。 | +| ISaCommandCallback::OnSaCommands(const std::vector\& commands) | 发送命令列表。 | ### 开发步骤 @@ -140,7 +144,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin struct IDeviceIoService ioService; OHOS::sptr stub; }; - + // 服务接口调用响应接口 static int32_t FingerprintAuthInterfaceDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) @@ -148,11 +152,11 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGI("start"); auto *hdfFingerprintAuthInterfaceHost = CONTAINER_OF(client->device->service, struct HdfFingerprintAuthInterfaceHost, ioService); - + OHOS::MessageParcel *dataParcel = nullptr; OHOS::MessageParcel *replyParcel = nullptr; OHOS::MessageOption option; - + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) { IAM_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; @@ -161,10 +165,10 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; } - + return hdfFingerprintAuthInterfaceHost->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option); } - + // 初始化接口 int HdfFingerprintAuthInterfaceDriverInit(struct HdfDeviceObject *deviceObject) { @@ -175,7 +179,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin } return HDF_SUCCESS; } - + // Fingerprint_auth驱动对外提供的服务绑定到HDF框架 int HdfFingerprintAuthInterfaceDriverBind(struct HdfDeviceObject *deviceObject) { @@ -185,29 +189,29 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGE("%{public}s: failed to create HdfFaceAuthInterfaceHost object", __func__); return HDF_FAILURE; } - + hdfFingerprintAuthInterfaceHost->ioService.Dispatch = FingerprintAuthInterfaceDriverDispatch; hdfFingerprintAuthInterfaceHost->ioService.Open = NULL; hdfFingerprintAuthInterfaceHost->ioService.Release = NULL; - + auto serviceImpl = IFingerprintAuthInterface::Get(true); if (serviceImpl == nullptr) { IAM_LOGE("%{public}s: failed to implement service", __func__); return HDF_FAILURE; } - + hdfFingerprintAuthInterfaceHost->stub = OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, IFaceAuthInterface::GetDescriptor()); if (hdfFingerprintAuthInterfaceHost->stub == nullptr) { IAM_LOGE("%{public}s: failed to get stub object", __func__); return HDF_FAILURE; } - + deviceObject->service = &hdfFingerprintAuthInterfaceHost->ioService; IAM_LOGI("success"); return HDF_SUCCESS; } - + // 释放Fingerprint_auth驱动中的资源 void HdfFingerprintAuthInterfaceDriverRelease(struct HdfDeviceObject *deviceObject) { @@ -217,7 +221,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin delete hdfFaceAuthInterfaceHost; IAM_LOGI("success"); } - + // 注册Fingerprint_auth驱动入口数据结构体对象 struct HdfDriverEntry g_fingerprintAuthInterfaceDriverEntry = { .moduleVersion = 1, @@ -226,7 +230,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin .Init = HdfFingerprintAuthInterfaceDriverInit, .Release = HdfFingerprintAuthInterfaceDriverRelease, }; - + // 调用HDF_INIT将驱动入口注册到HDF框架中。在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出 HDF_INIT(g_fingerprintAuthInterfaceDriverEntry); ``` @@ -239,15 +243,15 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin public: ExecutorImpl(struct ExecutorInfo executorInfo); virtual ~ExecutorImpl() {} - + private: struct ExecutorInfo executorInfo_; // 执行器信息 }; - + static constexpr uint16_t SENSOR_ID = 123; // 执行器sensorID static constexpr uint32_t EXECUTOR_TYPE = 123; // 执行器类型 static constexpr size_t PUBLIC_KEY_LEN = 32; // 执行器32字节公钥 - + // 创建HDI服务对象 extern "C" IFaceAuthInterface *FingerprintAuthInterfaceImplGetInstance(void) { @@ -258,9 +262,9 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin } return fingerprintAuthInterfaceService; } - + // 获取执行器列表实现,创建执行器 - int32_t GetExecutorList(std::vector>& executorList) + int32_t GetExecutorListV1_1(std::vector>& executorList) { IAM_LOGI("interface mock start"); executorList.clear(); @@ -278,10 +282,21 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGE("executor is nullptr"); return HDF_FAILURE; } - executorList.push_back(sptr(executor)); + executorList.push_back(sptr(executor)); IAM_LOGI("interface mock success"); return HDF_SUCCESS; } + + // 获取V1_0执行器列表实现,使用V1_1版本执行器实现V1_0版本执行器的功能 + int32_t GetExecutorList(std::vector> &executorList) + { + std::vector> executorListV1_1; + int32_t result = GetExecutorListV1_1(executorListV1_1); + for (auto &executor : executorListV1_1) { + executorList.push_back(executor); + } + return result; + } ``` 3. 步骤1、2完成后基本实现了Fingerprint_auth驱动和Fingerprint_auth服务对接。接下来需实现执行器每个功能接口,来完成指纹认证基础能力。关键代码如下,详细代码请参见[executor_impl.cpp](https://gitee.com/openharmony/drivers_peripheral/blob/master/fingerprint_auth/hdi_service/src/executor_impl.cpp)文件。 @@ -295,7 +310,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGI("get executor information success"); return HDF_SUCCESS; } - + // 实现获取指定模板ID的模板信息接口 int32_t GetTemplateInfo(uint64_t templateId, TemplateInfo& info) { @@ -305,7 +320,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGI("get template information success"); return HDF_SUCCESS; } - + // 实现执行器注册成功后,获取用户认证框架的公钥信息、获取用户认证框架的模板列表接口。将公钥信息保持,模板列表用于和本地的模板做对账 int32_t OnRegisterFinish(const std::vector& templateIdList, const std::vector& frameworkPublicKey, const std::vector& extraInfo) @@ -317,7 +332,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGI("register finish"); return HDF_SUCCESS; } - + // 实现指纹录入接口 int32_t Enroll(uint64_t scheduleId, const std::vector& extraInfo, const sptr& callbackObj) @@ -333,7 +348,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin } return HDF_SUCCESS; } - + // 实现指纹认证接口 int32_t Authenticate(uint64_t scheduleId, const std::vector& templateIdList, const std::vector& extraInfo, const sptr& callbackObj) @@ -350,7 +365,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin } return HDF_SUCCESS; } - + // 实现指纹识别接口 int32_t Identify(uint64_t scheduleId, const std::vector& extraInfo, const sptr& callbackObj) @@ -366,7 +381,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin } return HDF_SUCCESS; } - + // 实现删除指纹模板接口 int32_t Delete(const std::vector& templateIdList) { @@ -375,7 +390,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGI("delete success"); return HDF_SUCCESS; } - + // 实现通过scheduleId取消指定操作接口 int32_t Cancel(uint64_t scheduleId) { @@ -384,7 +399,7 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin IAM_LOGI("cancel success"); return HDF_SUCCESS; } - + // 实现指纹认证服务向Fingerprint_auth驱动传递参数的通用接口,当前需要实现冻结与解锁模板命令 int32_t SendCommand(int32_t commandId, const std::vector& extraInfo, const sptr& callbackObj) @@ -419,8 +434,34 @@ Fingerprint_auth驱动的主要工作是为上层用户认证框架和Fingerprin } return HDF_SUCCESS; } + + // 实现获取执行器属性接口 + int32_t ExecutorImpl::GetProperty( + const std::vector &templateIdList, const std::vector &propertyTypes, Property &property) + { + IAM_LOGI("interface mock start"); + property = {}; + IAM_LOGI("get property success"); + return HDF_SUCCESS; + } + + // 实现设置需缓存模板列表接口 + int32_t ExecutorImpl::SetCachedTemplates(const std::vector &templateIdList) + { + IAM_LOGI("interface mock start"); + IAM_LOGI("set cached templates success"); + return HDF_SUCCESS; + } + + // 实现注册SA命令回调接口 + int32_t ExecutorImpl::RegisterSaCommandCallback(const sptr &callbackObj) + { + IAM_LOGI("interface mock start"); + IAM_LOGI("register sa command callback success"); + return HDF_SUCCESS; + } ``` - + 4. 用户身份认证框架支持多driver,当增加driver或者修改driver信息,需要修改如下文件中serviceName2Config。 ```c++ diff --git a/zh-cn/device-dev/driver/driver-peripherals-pinauth-des.md b/zh-cn/device-dev/driver/driver-peripherals-pinauth-des.md index d7fb953346..cd26d990f3 100644 --- a/zh-cn/device-dev/driver/driver-peripherals-pinauth-des.md +++ b/zh-cn/device-dev/driver/driver-peripherals-pinauth-des.md @@ -81,30 +81,32 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 ### 接口说明 -注:以下接口列举的为IDL接口描述生成的对应C++语言函数接口,接口声明见idl文件(/drivers/interface/pin_auth/v1_0/)。 +注:以下接口列举的为IDL接口描述生成的对应C++语言函数接口,接口声明见idl文件(/drivers/interface/pin_auth)。 在本文中,口令凭据的录入、认证和删除相关的HDI接口如表1所示,表2中的回调函数分别用于口令执行器返回操作结果给框架和获取用户输入的口令信息。 **表1** 接口功能介绍 | 接口名称 | 功能介绍 | | ------------------------------- | ------------------------------------------- | -| GetExecutorList(std::vector>& executorList) | 获取执行器列表。 | -| GetExecutorInfo(ExecutorInfo& info) | 获取执行器信息。 | +| GetExecutorList(std::vector\>& executorList) | 获取V1_0执行器列表。 | +| GetExecutorListV1_1(std::vector\>& executorList) | 获取V1_1版本执行器列表。 | | GetTemplateInfo(uint64_t templateId, TemplateInfo& info) | 获取指定templateId的模板信息。 | -| OnRegisterFinish(const std::vector& templateIdList,
const std::vector& frameworkPublicKey,
const std::vector& extraInfo) | 执行器注册成功后,获取用户认证框架的公钥信息;获取用户认证框架的template 列表用于对账。 | -| OnSetData(uint64_t scheduleId, uint64_t authSubType,
const std::vector &data) | 回调函数,返回用户录入的口令子类型和录入的口令脱敏数据。 | -| Enroll(uint64_t scheduleId, const std::vector& extraInfo,
const sptr& callbackObj) | 录入pin码。 | -| Authenticate(uint64_t scheduleId, uint64_t templateId, const std::vector& extraInfo, const sptr& callbackObj) | pin码认证。 | +| OnRegisterFinish(const std::vector\& templateIdList,
const std::vector\& frameworkPublicKey,
const std::vector\& extraInfo) | 执行器注册成功后,获取用户认证框架的公钥信息;获取用户认证框架的template 列表用于对账。 | +| OnSetData(uint64_t scheduleId, uint64_t authSubType,
const std::vector\ &data) | 回调函数,返回用户录入的口令子类型和录入的口令脱敏数据。 | +| Enroll(uint64_t scheduleId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 录入pin码。 | +| Authenticate(uint64_t scheduleId, uint64_t templateId, const std::vector\& extraInfo, const sptr\& callbackObj) | pin码认证。 | | Delete(uint64_t templateId) | 删除pin码模板。 | | Cancel(uint64_t scheduleId) | 通过scheduleId取消指定操作。 | -| SendCommand(int32_t commandId, const std::vector& extraInfo,
const sptr& callbackObj) | 预留接口。 | +| SendCommand(int32_t commandId, const std::vector\& extraInfo,
const sptr\& callbackObj) | 预留接口。 | +| GetProperty(const std::vector\& templateIdList,
const std::vector\& propertyTypes, Property& property) | 获取执行器属性信息。 | + **表2** 回调函数介绍 | 接口名称 | 功能介绍 | | ------------------------------------------------------------ | -------------------- | -| IExecutorCallback::OnResult(int32_t code, const std::vector& extraInfo) | 返回操作的最终结果。 | -| IExecutorCallback::OnGetData(uint64_t scheduleId, const std::vector& salt,
uint64_t authSubType)| 返回获取pin码数据信息。 | +| IExecutorCallback::OnResult(int32_t code, const std::vector\& extraInfo) | 返回操作的最终结果。 | +| IExecutorCallback::OnGetData(uint64_t scheduleId, const std::vector\& salt,
uint64_t authSubType)| 返回获取pin码数据信息。 | ### 开发步骤 @@ -139,18 +141,18 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 struct IDeviceIoService ioService; OHOS::sptr stub; }; - + // 服务接口调用响应接口 static int32_t PinAuthInterfaceDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) { IAM_LOGI("start"); auto *hdfPinAuthInterfaceHost = CONTAINER_OF(client->device->service, struct HdfPinAuthInterfaceHost, ioService); - + OHOS::MessageParcel *dataParcel = nullptr; OHOS::MessageParcel *replyParcel = nullptr; OHOS::MessageOption option; - + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) { IAM_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; @@ -159,10 +161,10 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 IAM_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; } - + return hdfPinAuthInterfaceHost->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option); } - + // 初始化接口 static int HdfPinAuthInterfaceDriverInit(struct HdfDeviceObject *deviceObject) { @@ -176,7 +178,7 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 } return HDF_SUCCESS; } - + // PinAuth驱动对外提供的服务绑定到HDF框架 static int HdfPinAuthInterfaceDriverBind(struct HdfDeviceObject *deviceObject) { @@ -186,29 +188,29 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 IAM_LOGE("%{public}s: failed to create create HdfPinAuthInterfaceHost object", __func__); return HDF_FAILURE; } - + hdfPinAuthInterfaceHost->ioService.Dispatch = PinAuthInterfaceDriverDispatch; hdfPinAuthInterfaceHost->ioService.Open = NULL; hdfPinAuthInterfaceHost->ioService.Release = NULL; - + auto serviceImpl = IPinAuthInterface::Get(true); if (serviceImpl == nullptr) { IAM_LOGE("%{public}s: failed to get of implement service", __func__); return HDF_FAILURE; } - + hdfPinAuthInterfaceHost->stub = OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, IPinAuthInterface::GetDescriptor()); if (hdfPinAuthInterfaceHost->stub == nullptr) { IAM_LOGE("%{public}s: failed to get stub object", __func__); return HDF_FAILURE; } - + deviceObject->service = &hdfPinAuthInterfaceHost->ioService; IAM_LOGI("success"); return HDF_SUCCESS; } - + // 释放PinAuth驱动中的资源 static void HdfPinAuthInterfaceDriverRelease(struct HdfDeviceObject *deviceObject) { @@ -218,7 +220,7 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 delete hdfPinAuthInterfaceHost; IAM_LOGI("success"); } - + static struct HdfDriverEntry g_pinAuthInterfaceDriverEntry = { .moduleVersion = 1, .moduleName = "pinauth_interface_service", @@ -226,18 +228,18 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 .Init = HdfPinAuthInterfaceDriverInit, .Release = HdfPinAuthInterfaceDriverRelease, }; - + // 调用HDF_INIT将驱动入口注册到HDF框架中,在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动,当Init调用异常时,HDF框架会调用Release释放驱动资源并退出 HDF_INIT(g_pinauthinterfaceDriverEntry); ``` - - + + 1. 完成获取执行器列表接口实现,详细代码参见[pin_auth_interface_service.cpp](https://gitee.com/openharmony/drivers_peripheral/blob/master/pin_auth/hdi_service/service/src/pin_auth_interface_service.cpp)文件。 ```c++ // 执行器实现类 - class ExecutorImpl : public IExecutor, public NoCopyable { + class ExecutorImpl : public V1_1::IExecutor, public NoCopyable { public: explicit ExecutorImpl(std::shared_ptr pinHdi); virtual ~ExecutorImpl() {} @@ -254,7 +256,9 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 int32_t Cancel(uint64_t scheduleId) override; int32_t SendCommand(int32_t commandId, const std::vector &extraInfo, const sptr &callbackObj) override; - + int32_t GetProperty(const std::vector &templateIdList, const std::vector &propertyTypes, + Property &property) override; + private: class ScheduleMap { public: @@ -263,7 +267,7 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 uint32_t GetScheduleInfo(const uint64_t scheduleId, uint32_t &commandId, sptr &callback, uint64_t &templateId, std::vector &salt); uint32_t DeleteScheduleId(const uint64_t scheduleId); - + private: struct ScheduleInfo { uint32_t commandId; @@ -271,20 +275,20 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 uint64_t templateId; std::vector salt; }; - + std::mutex mutex_; std::map scheduleInfo_; }; - + private: uint32_t NewSalt(std::vector &salt); void CallError(const sptr &callbackObj, const uint32_t errorCode); std::shared_ptr pinHdi_; ScheduleMap scheduleMap_; }; - - // 获取执行器列表实现,创建执行器(仅作示例) - int32_t PinAuthInterfaceService::GetExecutorList(std::vector> &executorList) + + // 获取V1_1执行器列表实现,创建执行器(仅作示例) + int32_t PinAuthInterfaceService::GetExecutorListV1_1(std::vector> &executorList) { IAM_LOGI("start"); std::shared_ptr pinHdi = @@ -302,10 +306,21 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 IAM_LOGI("end"); return HDF_SUCCESS; } + + // 获取V1_0执行器列表实现,使用V1_1版本执行器实现V1_0版本执行器的功能 + int32_t PinAuthInterfaceService::GetExecutorList(std::vector> &executorList) + { + std::vector> executorListV1_1; + int32_t result = GetExecutorListV1_1(executorListV1_1); + for (auto &executor : executorListV1_1) { + executorList.push_back(executor); + } + return result; + } ``` - - - + + + 1. 完成执行器每个功能接口实现,详细代码参见[executor_impl.cpp](https://gitee.com/openharmony/drivers_peripheral/blob/master/pin_auth/hdi_service/service/src/executor_impl.cpp)文件。 ```c++ @@ -329,10 +344,10 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 return result; } info.esl = static_cast(eslRet); - + return HDF_SUCCESS; } - + // 实现获取指定templateId的模板信息接口 int32_t ExecutorImpl::GetTemplateInfo(uint64_t templateId, TemplateInfo &info) { @@ -353,14 +368,14 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 IAM_LOGE("copy subType to extraInfo fail!"); return HDF_FAILURE; } - + info.executorType = EXECUTOR_TYPE; info.remainAttempts = infoRet.remainTimes; info.lockoutDuration = infoRet.freezingTime; - + return HDF_SUCCESS; } - + // 实现执行器注册成功后,获取用户认证框架的公钥信息、获取用户认证框架的template 列表接口,将公钥信息保存,template列表用于和本地的template做对账 int32_t ExecutorImpl::OnRegisterFinish(const std::vector &templateIdList, const std::vector &frameworkPublicKey, const std::vector &extraInfo) @@ -377,10 +392,10 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 IAM_LOGE("Verify templateData failed"); return result; } - + return HDF_SUCCESS; } - + // 实现口令录入接口 int32_t ExecutorImpl::Enroll(uint64_t scheduleId, const std::vector &extraInfo, const sptr &callbackObj) @@ -412,10 +427,10 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 } return result; } - + return HDF_SUCCESS; } - + // 实现回调数据获取的接口 int32_t ExecutorImpl::OnSetData(uint64_t scheduleId, uint64_t authSubType, const std::vector &data) { @@ -451,7 +466,7 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 default: IAM_LOGE("Error commandId"); } - + if (callback->OnResult(result, resultTlv) != SUCCESS) { IAM_LOGE("callbackObj Pin failed"); } @@ -459,7 +474,7 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 if (scheduleMap_.DeleteScheduleId(scheduleId) != HDF_SUCCESS) { IAM_LOGI("delete scheduleId failed"); } - + return HDF_SUCCESS; } // 实现口令认证接口 @@ -499,10 +514,10 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 } return result; } - + return HDF_SUCCESS; } - + // 实现删除口令模板接口 int32_t ExecutorImpl::Delete(uint64_t templateId) { @@ -516,10 +531,10 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 IAM_LOGE("Verify templateData failed, fail code : %{public}d", result); return result; } - + return HDF_SUCCESS; } - + // 实现通过scheduleId取消指定操作接口 int32_t ExecutorImpl::Cancel(uint64_t scheduleId) { @@ -530,7 +545,7 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 } return HDF_SUCCESS; } - + // 口令预留接口 int32_t ExecutorImpl::SendCommand(int32_t commandId, const std::vector &extraInfo, const sptr &callbackObj) @@ -541,8 +556,37 @@ Pin_auth驱动的主要工作是为上层用户认证框架和Pin_auth服务提 static_cast(callbackObj); return HDF_SUCCESS; } + + // 获取执行器属性信息接口 + int32_t ExecutorImpl::GetProperty( + const std::vector &templateIdList, const std::vector &propertyTypes, Property &property) + { + IAM_LOGI("start"); + if (pinHdi_ == nullptr) { + IAM_LOGE("pinHdi_ is nullptr"); + return HDF_FAILURE; + } + + if (templateIdList.size() != 1) { + IAM_LOGE("templateIdList size is not 1"); + return HDF_FAILURE; + } + + uint64_t templateId = templateIdList[0]; + OHOS::UserIam::PinAuth::PinCredentialInfo infoRet = {}; + int32_t result = pinHdi_->QueryPinInfo(templateId, infoRet); + if (result != SUCCESS) { + IAM_LOGE("Get TemplateInfo failed, fail code : %{public}d", result); + return HDF_FAILURE; + } + + property.authSubType = infoRet.subType; + property.remainAttempts = infoRet.remainTimes; + property.lockoutDuration = infoRet.freezingTime; + return HDF_SUCCESS; + } ``` - + ### 调测验证 驱动开发完成后,可基于RK3568平台验证, 通过设备的设置和锁屏功能验证口令认证功能是否正常,测试步骤如下: diff --git a/zh-cn/device-dev/driver/driver-peripherals-user-auth-des.md b/zh-cn/device-dev/driver/driver-peripherals-user-auth-des.md index 57c11bc604..9ad49967ae 100644 --- a/zh-cn/device-dev/driver/driver-peripherals-user-auth-des.md +++ b/zh-cn/device-dev/driver/driver-peripherals-user-auth-des.md @@ -71,7 +71,7 @@ - Kit OpenHarmony系统向第三方应用提供的基础应用编程接口。 - + - Inner API OpenHarmony系统向系统应用提供的应用编程接口。 @@ -117,26 +117,30 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 | 接口名称 | 功能介绍 | | --------------------------- | --------------------------- | | Init() | 初始化缓存信息。 | -| AddExecutor(const ExecutorRegisterInfo& info, uint64_t& index, std::vector& publicKey,
std::vector& templateIds) | 添加认证执行器,获得此认证能力。 | +| AddExecutor(const ExecutorRegisterInfo& info, uint64_t& index, std::vector\& publicKey,
std::vector\& templateIds) | 添加认证执行器,获得此认证能力。 | | DeleteExecutor(uint64_t index) | 根据索引值index删除认证执行器。 | -| OpenSession(int32_t userId, std::vector& challenge) | 开启认证凭据管理Session。 | +| OpenSession(int32_t userId, std::vector\& challenge) | 开启认证凭据管理Session。 | | CloseSession(int32_t userId) | 关闭认证凭据管理Session。 | -| BeginEnrollment(int32_t userId, const std::vector& authToken, const EnrollParam& param,
ScheduleInfo& info) | 发起用户的认证凭据的录入,当录入类型为PIN码且当前用户已录入PIN码的情况下会更新PIN码。 | -| UpdateEnrollmentResult(int32_t userId, const std::vector& scheduleResult, uint64_t& credentialId,
CredentialInfo& oldInfo) | 更新录入结果,完成此次录入。 | +| BeginEnrollment(int32_t userId, const std::vector\& authToken, const EnrollParam& param,
ScheduleInfo& info) | 发起用户的认证凭据的录入,当录入类型为PIN码且当前用户已录入PIN码的情况下会更新PIN码(V1_0版本)。 | +| UpdateEnrollmentResult(int32_t userId, const std::vector\& scheduleResult, uint64_t& credentialId,
CredentialInfo& oldInfo) | 更新录入结果,完成此次录入。 | | CancelEnrollment(int32_t userId) | 取消此次录入。 | -| DeleteCredential(int32_t userId, uint64_t credentialId, const std::vector& authToken,
CredentialInfo& info) | 根据credentialId删除凭据信息。 | -| DeleteUser(int32_t userId, const std::vector& authToken,
std::vector& deletedInfos) | 删除PIN码即在用户认证框架中删除用户。 | -| EnforceDeleteUser(int32_t userId, std::vector& deletedInfos) | 强制删除用户,当系统内此用户被删除时强制调用。 | -| GetCredential(int32_t userId, AuthType authType, std::vector& infos) | 查询用户某种认证类型下的凭据信息。 | -| GetSecureInfo(int32_t userId, uint64_t& secureUid, std::vector& infos) | 查询用户的安全用户Id和每种认证类型的录入标记Id。 | -| BeginAuthentication(uint64_t contextId, const AuthSolution& param,
std::vector& scheduleInfos) | 发起认证,生成认证方案和调度信息。 | -| UpdateAuthenticationResult(uint64_t contextId, const std::vector& scheduleResult,
AuthResultInfo& info) | 更新认证结果,进行此次认证方案结果的评估。 | +| DeleteCredential(int32_t userId, uint64_t credentialId, const std::vector\& authToken,
CredentialInfo& info) | 根据credentialId删除凭据信息。 | +| DeleteUser(int32_t userId, const std::vector\& authToken,
std::vector\& deletedInfos) | 删除PIN码即在用户认证框架中删除用户。 | +| EnforceDeleteUser(int32_t userId, std::vector\& deletedInfos) | 强制删除用户,当系统内此用户被删除时强制调用。 | +| GetCredential(int32_t userId, AuthType authType, std::vector\& infos) | 查询用户某种认证类型下的凭据信息。 | +| GetSecureInfo(int32_t userId, uint64_t& secureUid, std::vector\& infos) | 查询用户的安全用户Id和每种认证类型的录入标记Id。 | +| BeginAuthentication(uint64_t contextId, const AuthSolution& param,
std::vector\& scheduleInfos) | 发起认证,生成认证方案和调度信息(V1_0版本)。 | +| UpdateAuthenticationResult(uint64_t contextId, const std::vector\& scheduleResult,
AuthResultInfo& info) | 更新认证结果,进行此次认证方案结果的评估。 | | CancelAuthentication(uint64_t contextId) | 取消此次认证。 | -| BeginIdentification(uint64_t contextId, AuthType authType, const std::vector& challenge,
uint32_t executorId, ScheduleInfo& scheduleInfo) | 发起识别,生成识别方案和调度信息。 | -| UpdateIdentificationResult(uint64_t contextId, const std::vector& scheduleResult,
IdentifyResultInfo& info) | 更新识别结果,进行此次识别方案结果的评估。 | +| BeginIdentification(uint64_t contextId, AuthType authType, const std::vector\& challenge,
uint32_t executorId, ScheduleInfo& scheduleInfo) | 发起识别,生成识别方案和调度信息(V1_0版本)。 | +| UpdateIdentificationResult(uint64_t contextId, const std::vector\& scheduleResult,
IdentifyResultInfo& info) | 更新识别结果,进行此次识别方案结果的评估。 | | CancelIdentification(uint64_t contextId) | 取消此次识别。 | | GetAuthTrustLevel(int32_t userId, AuthType authType, uint32_t& authTrustLevel) | 获取此用户当前认证类型的认证可信等级。 | -| GetValidSolution(int32_t userId, const std::vector& authTypes, uint32_t authTrustLevel,
std::vector& validTypes) | 筛选此用户当前认证可信等级下可用的认证方式。 | +| GetValidSolution(int32_t userId, const std::vector\& authTypes, uint32_t authTrustLevel,
std::vector\& validTypes) | 筛选此用户当前认证可信等级下可用的认证方式。 | +| BeginEnrollmentV1_1(int32_t userId, const std::vector\& authToken, const EnrollParam& param, ScheduleInfoV1_1& info) | 发起用户的认证凭据的录入,当录入类型为PIN码且当前用户已录入PIN码的情况下会更新PIN码(V1_1版本)。 | +| BeginAuthenticationV1_1(uint64_t contextId, const AuthSolution& param, std::vector\& scheduleInfos) | 发起认证,生成认证方案和调度信息(V1_1版本)。 | +| BeginIdentificationV1_1(uint64_t contextId, AuthType authType, + const std::vector\& challenge, uint32_t executorSensorHint, ScheduleInfoV1_1& scheduleInfo)| 发起识别,生成识别方案和调度信息(V1_1版本)。 | ### 开发步骤 @@ -164,17 +168,17 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 struct IDeviceIoService ioService; OHOS::sptr stub; }; - + // 服务接口调用响应接口 static int32_t UserAuthInterfaceDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) { auto *hdfUserAuthInterfaceHost = CONTAINER_OF(client->device->service, struct HdfUserAuthInterfaceHost, ioService); - + OHOS::MessageParcel *dataParcel = nullptr; OHOS::MessageParcel *replyParcel = nullptr; OHOS::MessageOption option; - + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) { HDF_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; @@ -183,10 +187,10 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 HDF_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__); return HDF_ERR_INVALID_PARAM; } - + return hdfUserAuthInterfaceHost->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option); } - + // 初始化接口 int HdfUserAuthInterfaceDriverInit(struct HdfDeviceObject *deviceObject) { @@ -194,46 +198,46 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 OHOS::UserIAM::Common::Init(); return HDF_SUCCESS; } - + // User_auth驱动对外提供的服务绑定到HDF框架 int HdfUserAuthInterfaceDriverBind(struct HdfDeviceObject *deviceObject) { HDF_LOGI("HdfUserAuthInterfaceDriverBind enter"); - + auto *hdfUserAuthInterfaceHost = new (std::nothrow) HdfUserAuthInterfaceHost; if (hdfUserAuthInterfaceHost == nullptr) { HDF_LOGE("%{public}s: failed to create HdfUserAuthInterfaceHost object", __func__); return HDF_FAILURE; } - + hdfUserAuthInterfaceHost->ioService.Dispatch = UserAuthInterfaceDriverDispatch; hdfUserAuthInterfaceHost->ioService.Open = NULL; hdfUserAuthInterfaceHost->ioService.Release = NULL; - + auto serviceImpl = IUserAuthInterface::Get(true); if (serviceImpl == nullptr) { HDF_LOGE("%{public}s: failed to implement service", __func__); return HDF_FAILURE; } - + hdfUserAuthInterfaceHost->stub = OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, IUserAuthInterface::GetDescriptor()); if (hdfUserAuthInterfaceHost->stub == nullptr) { HDF_LOGE("%{public}s: failed to get stub object", __func__); return HDF_FAILURE; } - + deviceObject->service = &hdfUserAuthInterfaceHost->ioService; return HDF_SUCCESS; } - + // 释放User_auth驱动中的资源 void HdfUserAuthInterfaceDriverRelease(struct HdfDeviceObject *deviceObject){ HDF_LOGI("HdfUserAuthInterfaceDriverRelease enter"); auto *hdfUserAuthInterfaceHost = CONTAINER_OF(deviceObject->service, struct HdfUserAuthInterfaceHost, ioService); delete hdfUserAuthInterfaceHost; } - + // 注册User_auth驱动入口数据结构体对象 struct HdfDriverEntry g_userAuthInterfaceDriverEntry = { .moduleVersion = 1, @@ -242,7 +246,7 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 .Init = HdfUserAuthInterfaceDriverInit, .Release = HdfUserAuthInterfaceDriverRelease, }; - + // 调用HDF_INIT将驱动入口注册到HDF框架中,在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动,当Init调用异常时,HDF框架会调用Release释放驱动资源并退出 #ifndef __cplusplus extern "C" { @@ -267,14 +271,14 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 GlobalUnLock(); return ret; } - + // 删除执行器 int32_t UserAuthInterfaceService::DeleteExecutor(uint64_t index) { return UnRegisterExecutor(index); } ``` - + 3. 录入接口举例实现,详细代码参见[user_auth_interface_service.cpp](https://gitee.com/openharmony/drivers_peripheral/blob/master/user_auth/hdi_service/service/user_auth_interface_service.cpp)文件。 ```c++ @@ -292,7 +296,7 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 GlobalUnLock(); return ret; } - + // 关闭认证凭据管理会话 int32_t UserAuthInterfaceService::CloseSession(int32_t userId) { @@ -301,10 +305,10 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 GlobalUnLock(); return ret; } - - // 发起认证,生成录入调度信息 - int32_t UserAuthInterfaceService::BeginEnrollment(int32_t userId, const std::vector& authToken, - const EnrollParam& param, ScheduleInfo& info) + + // 发起录入,生成录入调度信息(V1_1版本) + int32_t UserAuthInterfaceService::BeginEnrollmentV1_1(int32_t userId, const std::vector& authToken, + const EnrollParam& param, ScheduleInfoV1_1& info) { IAM_LOGI("start"); GlobalLock(); @@ -342,7 +346,18 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 GlobalUnLock(); return ret; } - + + // 发起录入,生成录入调度信息(V1_0版本),通过调用 V1_1 版本相应接口实现功能 + int32_t UserAuthInterfaceService::BeginEnrollment(int32_t userId, const std::vector &authToken, + const EnrollParam ¶m, ScheduleInfo &info) + { + IAM_LOGI("start"); + ScheduleInfoV1_1 infoV1_1; + int32_t ret = BeginEnrollmentV1_1(userId, authToken, param, infoV1_1); + CopyScheduleInfoV1_1ToV1_0(infoV1_1, info); + return ret; + } + // 取消录入接口实现 int32_t UserAuthInterfaceService::CancelEnrollment(int32_t userId) { @@ -350,7 +365,7 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 BreakOffCoauthSchedule(userId); return RESULT_SUCCESS; } - + // 录入凭据信息存储接口实现 int32_t UserAuthInterfaceService::UpdateEnrollmentResult(int32_t userId, const std::vector& scheduleResult, uint64_t& credentialId, CredentialInfo& oldInfo) @@ -405,10 +420,10 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 } return userAuthInterfaceService; } - + // 发起认证,生成认证方案和调度信息 - int32_t UserAuthInterfaceService::BeginAuthentication(uint64_t contextId, const AuthSolution& param, - std::vector& infos) + int32_t UserAuthInterfaceService::BeginAuthenticationV1_1(uint64_t contextId, const AuthSolution& param, + std::vector& infos) { IAM_LOGI("start"); if (param.challenge.size() != sizeof(uint64_t)) { @@ -436,7 +451,7 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 return ret; } for (uint32_t i = 0; i < scheduleIdNum; i++) { - ScheduleInfo temp; + ScheduleInfoV1_1 temp; if (!CopyScheduleInfo(schedulesGet + i, &temp)) { infos.clear(); ret = RESULT_GENERAL_ERROR; @@ -448,7 +463,18 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 GlobalUnLock(); return ret; } - + + // 发起认证,生成认证方案和调度信息(V1_0版本),通过调用 V1_1 版本相应接口实现功能 + int32_t UserAuthInterfaceService::BeginAuthentication(uint64_t contextId, const AuthSolution ¶m, + std::vector &infos) + { + IAM_LOGI("start"); + std::vector infosV1_1; + int32_t ret = BeginAuthenticationV1_1(contextId, param, infosV1_1); + CopyScheduleInfosV1_1ToV1_0(infosV1_1, infos); + return ret; + } + // 更新认证结果,进行此次认证方案结果的评估 int32_t UserAuthInterfaceService::UpdateAuthenticationResult(uint64_t contextId, const std::vector& scheduleResult, AuthResultInfo& info) @@ -487,7 +513,7 @@ User_auth驱动的主要工作是为User_auth服务提供稳定的用户凭据 GlobalUnLock(); return RESULT_SUCCESS; } - + // 取消认证 int32_t UserAuthInterfaceService::CancelAuthentication(uint64_t contextId) { -- GitLab