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 HKS_ATTEST_KEY_TEST_COMMON_H 17 #define HKS_ATTEST_KEY_TEST_COMMON_H 18 19 #include <securec.h> 20 21 #include "hks_api.h" 22 #include "hks_log.h" 23 #include "hks_mem.h" 24 #include "hks_param.h" 25 #include "hks_type.h" 26 27 enum ParamType { 28 IDS_PARAM, 29 NON_IDS_PARAM, 30 NON_IDS_BASE64_PARAM, 31 }; 32 33 struct HksTestCertChain { 34 bool certChainExist; 35 bool certCountValid; 36 bool certDataExist; 37 uint32_t certDataSize; 38 }; 39 40 static uint32_t g_size = 4096; 41 static uint32_t CERT_COUNT = 4; 42 43 namespace Unittest::AttestKey { 44 #define SEC_INFO_DATA "hi_security_level_info" 45 #define CHALLENGE_DATA "hi_challenge_data" 46 #define VERSION_DATA "hi_os_version_data" 47 #define ALIAS "testKey" 48 #define UDID_DATA "hi_udid_data" 49 #define SN_DATA "hi_sn_data" 50 #define DEVICE_ID "test_device_id" 51 #define APP_ID "test_app_id" 52 #define ATTEST_BRAND "brand" 53 54 void FreeCertChain(struct HksCertChain **certChain, const uint32_t pos); 55 56 int32_t TestGenerateKey(const struct HksBlob *keyAlias, uint32_t keyPadding); 57 58 int32_t TestGenerateKeyCommon(const struct HksBlob *keyAlias, const struct HksParam tmpParams[], uint32_t paramCount); 59 60 int32_t ConstructDataToCertChain(struct HksCertChain **certChain, 61 const struct HksTestCertChain *certChainParam); 62 63 int32_t GenerateParamSet(struct HksParamSet **paramSet, const struct HksParam tmpParams[], uint32_t paramCount); 64 65 int32_t ValidateCertChainTest(const struct HksCertChain *certChain, const struct HksParam tmpParam[], 66 ParamType type); 67 } 68 69 #endif 70