1 /* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_HDI_PIN_AUTH_ALL_IN_ONE_IMPL_H 17 #define OHOS_HDI_PIN_AUTH_ALL_IN_ONE_IMPL_H 18 19 #include <list> 20 #include <mutex> 21 #include <vector> 22 23 #include "nocopyable.h" 24 #include "thread_pool.h" 25 26 #include "pin_auth_hdi.h" 27 #include "pin_auth.h" 28 29 namespace OHOS { 30 namespace HDI { 31 namespace PinAuth { 32 class AllInOneImpl : public HdiIAllInOneExecutor, public NoCopyable { 33 public: 34 explicit AllInOneImpl(std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi); 35 ~AllInOneImpl() override; 36 37 int32_t GetExecutorInfo(HdiExecutorInfo &info) override; 38 int32_t OnRegisterFinish(const std::vector<uint64_t> &templateIdList, 39 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override; 40 int32_t Cancel(uint64_t scheduleId) override; 41 int32_t SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t>& msg) override; 42 int32_t SetData(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data, uint32_t pinLength, 43 int32_t resultCode) override; 44 int32_t Enroll(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, 45 const sptr<HdiIExecutorCallback> &callbackObj) override; 46 int32_t Authenticate(uint64_t scheduleId, const std::vector<uint64_t>& templateIdList, 47 const std::vector<uint8_t> &extraInfo, const sptr<HdiIExecutorCallback> &callbackObj) override; 48 int32_t Delete(uint64_t templateId) override; 49 int32_t GetProperty(const std::vector<uint64_t> &templateIdList, const std::vector<int32_t> &propertyTypes, 50 HdiProperty &property) override; 51 int32_t SendCommand(int32_t commandId, const std::vector<uint8_t> &extraInfo, 52 const sptr<HdiIExecutorCallback> &callbackObj) override; 53 int32_t Abandon(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo, 54 const sptr<HdiIExecutorCallback> &callbackObj) override; 55 56 private: 57 struct ScheduleInfo { 58 uint64_t scheduleId{0}; 59 uint32_t commandId{0}; 60 sptr<HdiIExecutorCallback> callback; 61 uint64_t templateId{0}; 62 std::vector<uint8_t> algoParameter; 63 std::vector<uint8_t> extraInfo; 64 }; 65 66 class ScheduleList { 67 public: 68 bool AddScheduleInfo(const ScheduleInfo &scheduleInfo); 69 bool GetAndDelScheduleInfo(uint64_t scheduleId, ScheduleInfo &scheduleInfo); 70 void DelScheduleInfo(uint64_t scheduleId); 71 private: 72 std::mutex mutex_; 73 std::list<struct ScheduleInfo> scheduleInfoList_; 74 }; 75 76 private: 77 int32_t AuthPin(PinAuthParam &pinAuthParam, 78 const std::vector<uint8_t> &extraInfo, std::vector<uint8_t> &resultTlv); 79 int32_t AuthenticateInner(uint64_t scheduleId, uint64_t templateId, std::vector<uint8_t> &algoParameter, 80 const sptr<HdiIExecutorCallback> &callbackObj, const std::vector<uint8_t> &extraInfo); 81 int32_t EnrollInner(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, 82 const sptr<HdiIExecutorCallback> &callbackObj, std::vector<uint8_t> &algoParameter, uint32_t &algoVersion); 83 int32_t FillPinEnrollParam(PinEnrollParam &pinEnrollParam, uint64_t subType, const std::vector<uint8_t> 84 &salt, const std::vector<uint8_t> &pinData, uint32_t pinLength); 85 int32_t FillPinAuthParam(PinAuthParam &pinAuthParam, uint64_t scheduleId, uint64_t templateId, 86 const std::vector<uint8_t> &pinData, uint32_t pinLength); 87 int32_t EnrollPinInner(ScheduleInfo &scheduleInfo, uint64_t authSubType, const std::vector<uint8_t> &pinData, 88 uint32_t pinLength, std::vector<uint8_t> &resultTlv); 89 int32_t AuthPinInner(ScheduleInfo &scheduleInfo, uint64_t authSubType, const std::vector<uint8_t> &pinData, 90 uint32_t pinLength, std::vector<uint8_t> &resultTlv); 91 92 std::shared_ptr<OHOS::UserIam::PinAuth::PinAuth> pinHdi_; 93 ScheduleList scheduleList_; 94 OHOS::ThreadPool threadPool_; 95 }; 96 } // PinAuth 97 } // HDI 98 } // OHOS 99 100 #endif // OHOS_HDI_PIN_AUTH_ALL_IN_ONE_IMPL_H 101