1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 #ifndef PERM_SRV_SET_CONFIG_H 13 #define PERM_SRV_SET_CONFIG_H 14 15 #include <tee_defines.h> 16 #include "permission_service.h" 17 #include "tee_elf_verify.h" 18 19 #define TA_CONFIG_SEGMENT_MAGIC 0xABCDABCD 20 #define TA_CONFIG_SEGMENT_VERSION 0x1 21 #define CONFIG_HEADER_V1 1 22 #define CONFIG_HEADER_V2 2 23 #define TYPE_PUB_KEY 0 24 #define TYPE_CERT 1 25 #define TYPE_CERT_CHAIN 2 26 #define SIGN_TYPE_RSA_SHA256_PKCS1 1 27 #define SIGN_TYPE_ECDSA_SHA256 2 28 #define SIGN_TYPE_RSA_SHA256_PSS 3 29 #define CA_PUBLIC 1 30 #define CA_PRIVATE 2 31 #define SIGN_CONFIG_ALG_BITS 30 32 #define CONFIG_SIGNATURE_LEN_MASK 0x3FFFFFFF 33 #define CONFIG_SIGN_ALG_RSA_PKCS1 1 34 #define CONFIG_SIGN_ALG_RSA_PSS 2 35 #define CONFIG_SIGN_ALG_RSA_ECDSA 3 36 37 #define POLICY_VER_VALID_INDEX 0 /* this bits always is 1, check policy version is invalid */ 38 #define POLICY_VER_XML2TLV_PARSE_INDEX 1 /* tool type for parse xml */ 39 #define POLICY_VER_PRODUCT_INDEX 2 /* policy version for product */ 40 41 #define BASE_POLICY_VERSION_TEE 0b001 42 #define BASE_POLICY_VERSION_OH 0b101 43 44 #define PRODUCT_BIT_MAP (1 << POLICY_VER_PRODUCT_INDEX) 45 #define CONFIG_POLICY_OH (BASE_POLICY_VERSION_OH & PRODUCT_BIT_MAP) 46 47 48 struct ta_identity { 49 TEE_UUID uuid; 50 uint8_t *service_name; 51 uint32_t service_name_len; 52 }; 53 54 #define V1_RESERVED_LEN 4 55 struct config_header_v1 { 56 uint32_t magic_num; 57 uint16_t version; 58 uint16_t policy_version; 59 uint32_t context_len; 60 uint32_t ta_cert_len; 61 uint32_t config_len; 62 uint32_t signature_len; 63 uint32_t config_cert_len; 64 uint32_t reserved[V1_RESERVED_LEN]; 65 }; 66 67 #define V2_RESERVED_LEN 5 68 struct config_header_v2 { 69 uint32_t magic_num; 70 uint16_t version; 71 uint16_t policy_version; 72 uint32_t context_len; 73 uint32_t ta_cert_len; 74 uint32_t config_len; 75 uint32_t config_verify_len; 76 uint32_t reserved[V2_RESERVED_LEN]; 77 }; 78 79 union header_union { 80 struct config_header_v1 v1; 81 struct config_header_v2 v2; 82 }; 83 84 struct config_header { 85 uint32_t version; 86 union header_union header; 87 }; 88 89 struct secure_img_data { 90 const uint8_t *cert; 91 uint32_t cert_size; 92 uint8_t *cn; 93 uint32_t cn_size; 94 }; 95 96 struct sign_verify_data { 97 uint32_t type; 98 uint32_t sign_alg; 99 uint8_t *cert; 100 uint32_t cert_len; 101 uint8_t *signature; 102 uint32_t signature_len; 103 }; 104 105 struct ta_cert_info { 106 uint32_t type; 107 uint8_t *cert; 108 uint32_t cert_len; 109 }; 110 111 struct ta_package { 112 const uint8_t *config_package; 113 uint32_t package_size; 114 const uint8_t *name; 115 uint32_t name_len; 116 }; 117 118 struct tlv_config { 119 uint8_t *data; 120 uint32_t len; 121 }; 122 123 struct ta_config_info { 124 struct config_header header; 125 struct ta_cert_info ta_cert; 126 struct tlv_config tlv_config; 127 struct sign_verify_data verify_data; 128 }; 129 130 uint32_t get_ca_pubkey_size(void); 131 const uint8_t *get_ca_pubkey(void); 132 uint32_t get_pub_ca_key_size(uint32_t alg); 133 uint32_t get_priv_ca_key_size(uint32_t alg); 134 const uint8_t *get_pub_ca_key(uint32_t alg); 135 const uint8_t *get_priv_ca_key(uint32_t alg); 136 const char *get_config_cert_cn(void); 137 const char *get_config_cert_ou_prod(void); 138 const char *get_config_cert_ou_dev(void); 139 const rsa_pub_key_t *get_config_pub_key(void); 140 uint32_t get_ca_type(void); 141 uint8_t* get_g_ta_cert(void); 142 TEE_Result tee_ext_set_config(const uint8_t *conf, uint32_t conf_len, const TEE_UUID *uuid, const uint8_t *service_name, 143 const uint32_t service_name_len, void *cert_param); 144 #endif 145