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 USERIAM_CONTEXT_MANAGER_H
17 #define USERIAM_CONTEXT_MANAGER_H
18 
19 #include "coauth.h"
20 #include "executor_message.h"
21 #include "linked_list.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define AUTH_MAX_SCHEDULING_NUM 5
28 
29 typedef struct UserAuthContext {
30     uint64_t contextId;
31     int32_t userId;
32     uint8_t challenge[CHALLENGE_LEN];
33     uint32_t authType;
34     uint32_t authTrustLevel;
35     uint32_t collectorSensorHint;
36     LinkedList *scheduleList;
37     uint64_t authExpiredSysTime;
38     int32_t authIntent;
39     bool isExpiredReturnSuccess;
40     uint8_t localUdid[UDID_LEN];
41     uint8_t collectorUdid[UDID_LEN];
42 } UserAuthContext;
43 
44 typedef struct {
45     uint64_t contextId;
46     int32_t userId;
47     uint8_t challenge[CHALLENGE_LEN];
48     uint32_t authType;
49     uint32_t authTrustLevel;
50     uint32_t executorSensorHint;
51     int32_t authIntent;
52     bool isExpiredReturnSuccess;
53     uint8_t localUdid[UDID_LEN];
54     uint8_t collectorUdid[UDID_LEN];
55 } AuthParamHal;
56 
57 typedef struct IdentifyParam {
58     uint64_t contextId;
59     uint8_t challenge[CHALLENGE_LEN];
60     uint32_t authType;
61     uint32_t executorSensorHint;
62 } IdentifyParam;
63 
64 typedef struct {
65     uint64_t scheduleId;
66     uint32_t scheduleMode;
67     uint64_t authExpiredSysTime;
68 } ExecutorExpiredInfo;
69 
70 ResultCode InitUserAuthContextList(void);
71 void DestoryUserAuthContextList(void);
72 ResultCode GenerateAuthContext(AuthParamHal params, UserAuthContext **context);
73 UserAuthContext *GenerateIdentifyContext(IdentifyParam params);
74 
75 UserAuthContext *GetContext(uint64_t contextId);
76 ResultCode ScheduleOnceFinish(UserAuthContext *context, uint64_t scheduleId);
77 void DestroyContext(UserAuthContext *context);
78 ResultCode DestroyContextbyId(uint64_t contextId);
79 ResultCode CopySchedules(UserAuthContext *context, LinkedList **schedules);
80 ResultCode FillInContext(UserAuthContext *context, uint64_t *credentialId, ExecutorResultInfo *info,
81     uint32_t authMode);
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif // USERIAM_CONTEXT_MANAGER_H