1 /* 2 * Copyright (c) 2022 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 DSLM_CRED_H 17 #define DSLM_CRED_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #include "device_security_defines.h" 23 24 #define CRED_INFO_VERSION_LEN 32 25 #define CRED_INFO_TYPE_LEN 32 26 #define CRED_INFO_SIGNTIME_LEN 32 27 #define CRED_INFO_UDID_LEN 80 28 #define CRED_INFO_MANU_LEN 64 29 #define CRED_INFO_MODEL_LEN 64 30 #define CRED_INFO_BRAND_LEN 64 31 #define CRED_INFO_LEVEL_LEN 16 32 #define CRED_INFO_SOFTVERSION_LEN 64 33 34 typedef enum { 35 CRED_TYPE_MINI = 1000, 36 CRED_TYPE_SMALL = 2000, 37 CRED_TYPE_STANDARD = 3000, 38 CRED_TYPE_LARGE = 4000, 39 } CredType; 40 41 typedef struct DslmCredInfo { 42 char version[CRED_INFO_VERSION_LEN]; // the cred version 43 char releaseType[CRED_INFO_TYPE_LEN]; // debug or release 44 char signTime[CRED_INFO_SIGNTIME_LEN]; 45 char udid[CRED_INFO_UDID_LEN]; 46 char manufacture[CRED_INFO_MANU_LEN]; 47 char model[CRED_INFO_MODEL_LEN]; 48 char brand[CRED_INFO_BRAND_LEN]; 49 char securityLevel[CRED_INFO_LEVEL_LEN]; 50 char softwareVersion[CRED_INFO_SOFTVERSION_LEN]; 51 CredType credType; // the parsed and validated type value, assigned only after verification. 52 uint32_t credLevel; // the parsed level value, assigned only after verification. 53 } DslmCredInfo; 54 55 #define MAX_CRED_ARRAY_SIZE 48 56 typedef struct RequestObject { 57 uint32_t version; 58 uint64_t challenge; 59 uint32_t arraySize; 60 CredType credArray[MAX_CRED_ARRAY_SIZE]; 61 } RequestObject; 62 63 typedef struct DslmCredBuff { 64 CredType type; 65 uint32_t credLen; 66 uint8_t *credVal; 67 } DslmCredBuff; 68 69 typedef int32_t InitDslmCredFunc(DslmCredInfo *credInfo); 70 71 typedef int32_t RequestDslmCredFunc(const DeviceIdentify *device, const RequestObject *obj, DslmCredBuff **credBuff); 72 typedef int32_t VerifyDslmCredFunc(const DeviceIdentify *device, uint64_t challenge, const DslmCredBuff *credBuff, 73 DslmCredInfo *credInfo); 74 75 typedef struct ProcessDslmCredFunctions { 76 InitDslmCredFunc *initFunc; 77 RequestDslmCredFunc *requestFunc; 78 VerifyDslmCredFunc *verifyFunc; 79 uint32_t credTypeCnt; 80 CredType credTypeArray[MAX_CRED_ARRAY_SIZE]; 81 } ProcessDslmCredFunctions; 82 83 #ifdef __cplusplus 84 extern "C" { 85 #endif 86 87 bool InitDslmCredentialFunctions(const ProcessDslmCredFunctions *func); 88 89 DslmCredBuff *CreateDslmCred(CredType type, uint32_t len, uint8_t *value); 90 91 void DestroyDslmCred(DslmCredBuff *credBuff); 92 93 #ifdef __cplusplus 94 } 95 #endif 96 #endif // DSLM_CRED_H 97