• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PIN_AUTH_H
17 #define PIN_AUTH_H
18 
19 #include <cstdint>
20 #include <mutex>
21 #include <vector>
22 #include "nocopyable.h"
23 #include "all_in_one_func.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace PinAuth {
28 struct PinCredentialInfo {
29     uint64_t subType;
30     uint32_t remainTimes;
31     uint32_t freezingTime;
32     int32_t nextFailLockoutDuration;
33     uint32_t credentialLength;
34 };
35 
36 struct PinAlgoParam {
37     uint32_t algoVersion;
38     uint64_t subType;
39     std::vector<uint8_t> algoParameter;
40     std::vector<uint8_t> challenge;
41 };
42 
43 class PinAuth {
44 public:
45     DISALLOW_COPY_AND_MOVE(PinAuth);
46     PinAuth() = default;
47     ~PinAuth() = default;
48     int32_t Init();
49     int32_t Close();
50 
51     int32_t GetExecutorInfo(int32_t executorRole, std::vector<uint8_t> &pubKey, uint32_t &esl,
52         uint32_t &maxTemplateAcl);
53 
54     // for all in one executor
55     int32_t SetAllInOneFwkParam(
56         const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey);
57     int32_t EnrollPin(PinEnrollParam &pinEnrollParam, std::vector<uint8_t> &result);
58     int32_t AuthPin(PinAuthParam &pinAuthParam,
59         const std::vector<uint8_t> &extraInfo, std::vector<uint8_t> &resultTlv);
60     void WriteAntiBrute(uint64_t templateId);
61     int32_t QueryPinInfo(uint64_t templateId, PinCredentialInfo &pinCredentialInfoRet);
62     int32_t DeleteTemplate(uint64_t templateId);
63     int32_t GenerateAlgoParameter(std::vector<uint8_t> &algoParameter, uint32_t &algoVersion);
64     int32_t AllInOneAuth(
65         uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo, PinAlgoParam &pinAlgoParam);
66     int32_t Abandon(uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo,
67             std::vector<uint8_t> &resultTlv);
68 
69     // for collector executor
70     int32_t SetCollectorFwkParam(const std::vector<uint8_t> &frameworkPublicKey);
71     int32_t Collect(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, std::vector<uint8_t> &msg);
72     int32_t CancelCollect();
73     int32_t SendMessageToCollector(uint64_t scheduleId, const std::vector<uint8_t> &msg, PinAlgoParam &pinAlgoParam);
74     int32_t SetDataToCollector(uint64_t scheduleId, const std::vector<uint8_t> &data, std::vector<uint8_t> &msg);
75 
76     // for collector executor
77     int32_t SetVerifierFwkParam(const std::vector<uint8_t> &frameworkPublicKey);
78     int32_t VerifierAuth(
79         uint64_t scheduleId, uint64_t templateId, const std::vector<uint8_t> &extraInfo, std::vector<uint8_t> &msgOut);
80     int32_t CancelVerifierAuth();
81     int32_t SendMessageToVerifier(uint64_t scheduleId,
82         const std::vector<uint8_t> &msgIn, std::vector<uint8_t> &msgOut, bool &isAuthEnd, int32_t &compareResult);
83     int32_t RestartLockoutDuration(const std::vector<uint8_t> &extraInfo);
84     int32_t PinResultToCoAuthResult(int32_t resultCode);
85 
86 private:
87     int32_t SetVectorByBuffer(std::vector<uint8_t> &vec, const uint8_t *buf, uint32_t bufSize);
88     std::mutex mutex_;
89 };
90 } // namespace PinAuth
91 } // namespace UserIam
92 } // namespace OHOS
93 #endif // PIN_AUTH_H
94