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 31 typedef struct AuthResult { 32 int32_t userId; 33 uint32_t authType; 34 int32_t freezingTime; 35 int32_t remainTimes; 36 int32_t result; 37 Buffer *rootSecret; 38 uint64_t credentialDigest; 39 uint16_t credentialCount; 40 int64_t pinExpiredInfo; 41 Buffer *remoteAuthResultMsg; 42 uint64_t credentialId; 43 } AuthResult; 44 45 typedef struct { 46 int32_t userId; 47 uint32_t authTrustLevel; 48 uint32_t authTypes[MAX_AUTH_TYPE_LEN]; 49 uint32_t authTypeSize; 50 uint8_t challenge[CHALLENGE_LEN]; 51 uint64_t reuseUnlockResultDuration; 52 uint32_t reuseUnlockResultMode; 53 } ReuseUnlockParamHal; 54 55 typedef struct { 56 int32_t authType; 57 uint8_t token[AUTH_TOKEN_LEN]; 58 EnrolledStateHal enrolledState; 59 } ReuseUnlockResult; 60 61 typedef enum ReuseMode { 62 AUTH_TYPE_RELEVANT = 1, 63 AUTH_TYPE_IRRELEVANT = 2, 64 CALLER_IRRELEVANT_AUTH_TYPE_RELEVANT = 3, 65 CALLER_IRRELEVANT_AUTH_TYPE_IRRELEVANT = 4, 66 } ReuseMode; 67 68 typedef struct { 69 bool isCached; 70 int32_t userId; 71 uint64_t secureUid; 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 ResultCode GetAvailableStatusFunc(int32_t userId, int32_t authType, uint32_t authTrustLevel); 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