1 /* 2 * Copyright (C) 2022-2023 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_COAUTH_H 17 #define USERIAM_COAUTH_H 18 19 #include "c_array.h" 20 #include "defines.h" 21 #include "pool.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define INVALID_SESSION_ID 0 28 #define MAX_EXECUTOR_SIZE 2 29 #define MAX_SCHEDULE_NUM 51 30 31 typedef union AssociateId { 32 uint64_t contextId; 33 int32_t userId; 34 } AssociateId; 35 36 typedef struct ScheduleParam { 37 uint32_t authType; 38 ScheduleMode scheduleMode; 39 AssociateId associateId; 40 Uint64Array *templateIds; 41 uint32_t collectorSensorHint; 42 uint32_t verifierSensorHint; 43 uint32_t executorMatcher; 44 int32_t userType; 45 uint8_t localUdid[UDID_LEN]; 46 uint8_t collectorUdid[UDID_LEN]; 47 } ScheduleParam; 48 49 typedef struct CoAuthSchedule { 50 uint64_t scheduleId; 51 uint32_t authType; 52 ScheduleMode scheduleMode; 53 AssociateId associateId; 54 Uint64Array templateIds; 55 uint32_t executorSize; 56 ExecutorInfoHal executors[MAX_EXECUTOR_SIZE]; 57 int32_t userType; 58 } CoAuthSchedule; 59 60 typedef struct ScheduleInfoParam { 61 uint64_t scheduleId; 62 uint32_t authType; 63 uint32_t executorMatcher; 64 int32_t scheduleMode; 65 uint64_t executorIndex; 66 Buffer *executorMessages; 67 uint8_t localUdid[UDID_LEN]; 68 uint8_t remoteUdid[UDID_LEN]; 69 } ScheduleInfoParam; 70 71 typedef struct AuthResultParam { 72 int32_t result; 73 int32_t lockoutDuration; 74 int32_t remainAttempts; 75 int32_t userId; 76 Buffer *token; 77 Buffer *remoteAuthResultMsg; 78 uint8_t localUdid[UDID_LEN]; 79 uint8_t remoteUdid[UDID_LEN]; 80 } AuthResultParam; 81 82 ResultCode InitCoAuth(void); 83 void DestoryCoAuth(void); 84 85 CoAuthSchedule *GenerateSchedule(const ScheduleParam *param); 86 87 ResultCode AddCoAuthSchedule(const CoAuthSchedule *coAuthSchedule); 88 ResultCode RemoveCoAuthSchedule(uint64_t scheduleId); 89 const CoAuthSchedule *GetCoAuthSchedule(uint64_t scheduleId); 90 uint32_t GetScheduleVerifierSensorHint(const CoAuthSchedule *coAuthSchedule); 91 void DestroyCoAuthSchedule(CoAuthSchedule *coAuthSchedule); 92 CoAuthSchedule *CopyCoAuthSchedule(const CoAuthSchedule *coAuthSchedule); 93 void DestroyScheduleNode(void *data); 94 bool IsTemplateArraysValid(const Uint64Array *templateIds); 95 ResultCode CopyTemplateArrays(const Uint64Array *in, Uint64Array *out); 96 97 #ifdef __cplusplus 98 } 99 #endif 100 101 #endif 102