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 USER_AUTH_FUNCS_H
17 #define USER_AUTH_FUNCS_H
18 
19 #include "buffer.h"
20 
21 #include "context_manager.h"
22 #include "idm_common.h"
23 #include "user_sign_centre.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define REUSED_UNLOCK_TOKEN_PERIOD (5 * 60 * 1000)
30 #define NO_SET_PIN_EXPIRED_PERIOD (-1)
31 
32 typedef struct AuthResult {
33     int32_t userId;
34     uint32_t authType;
35     int32_t freezingTime;
36     int32_t remainTimes;
37     int32_t result;
38     Buffer *rootSecret;
39     uint64_t credentialDigest;
40     uint16_t credentialCount;
41     int64_t pinExpiredInfo;
42     Buffer *remoteAuthResultMsg;
43     uint64_t credentialId;
44 } AuthResult;
45 
46 typedef struct {
47     int32_t userId;
48     uint32_t authTrustLevel;
49     uint32_t authTypes[MAX_AUTH_TYPE_LEN];
50     uint32_t authTypeSize;
51     uint8_t challenge[CHALLENGE_LEN];
52     uint64_t reuseUnlockResultDuration;
53     uint32_t reuseUnlockResultMode;
54 } ReuseUnlockParamHal;
55 
56 typedef struct {
57     int32_t authType;
58     uint8_t token[AUTH_TOKEN_LEN];
59     EnrolledStateHal enrolledState;
60 } ReuseUnlockResult;
61 
62 typedef enum ReuseMode {
63     AUTH_TYPE_RELEVANT = 1,
64     AUTH_TYPE_IRRELEVANT = 2,
65     CALLER_IRRELEVANT_AUTH_TYPE_RELEVANT = 3,
66     CALLER_IRRELEVANT_AUTH_TYPE_IRRELEVANT = 4,
67 } ReuseMode;
68 
69 typedef struct {
70     bool isCached;
71     int32_t userId;
72     UserAuthTokenHal authToken;
73 } __attribute__((__packed__)) UnlockAuthResultCache;
74 
75 ResultCode GenerateSolutionFunc(AuthParamHal param, LinkedList **schedules);
76 ResultCode RequestAuthResultFunc(uint64_t contextId, const Buffer *scheduleResult, UserAuthTokenHal *authToken,
77     AuthResult *result);
78 ResultCode GetEnrolledStateFunc(int32_t userId, uint32_t authType, EnrolledStateHal *enrolledStateHal);
79 ResultCode CheckReuseUnlockResultFunc(const ReuseUnlockParamHal *info, ReuseUnlockResult *reuseResult);
80 ResultCode SetGlobalConfigParamFunc(GlobalConfigParamHal *param);
81 void GetAvailableStatusFunc(int32_t userId, int32_t authType, uint32_t authTrustLevel, int32_t *checkResult);
82 
83 ResultCode GenerateScheduleFunc(const Buffer *tlv, Uint8Array remoteUdid, ScheduleInfoParam *scheduleInfo);
84 ResultCode GenerateAuthResultFunc(const Buffer *tlv, AuthResultParam *authResultInfo);
85 ResultCode GetExecutorInfoLinkedList(uint32_t authType, uint32_t executorRole, LinkedList *allExecutorInfoList);
86 Buffer *GetSignExecutorInfoFunc(Uint8Array peerUdid, LinkedList *executorList);
87 void DestroyAuthResult(AuthResult *authResult);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif // USER_AUTH_FUNCS_H