Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
arm_uc_mmDerManifestParser.h
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // SPDX-License-Identifier: Apache-2.0 00005 // 00006 // Licensed under the Apache License, Version 2.0 (the "License"); 00007 // you may not use this file except in compliance with the License. 00008 // You may obtain a copy of the License at 00009 // 00010 // http://www.apache.org/licenses/LICENSE-2.0 00011 // 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 00017 // ---------------------------------------------------------------------------- 00018 00019 #ifndef ARM_UC_MM_DERPARSE_H 00020 #define ARM_UC_MM_DERPARSE_H 00021 00022 #include "update-client-common/arm_uc_types.h" 00023 #include <stdint.h> 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /** 00029 * \name DER constants 00030 * These constants comply with DER encoded the ANS1 type tags. 00031 * DER encoding uses hexadecimal representation. 00032 * An example DER sequence is:\n 00033 * - 0x02 -- tag indicating INTEGER 00034 * - 0x01 -- length in octets 00035 * - 0x05 -- value 00036 * Such sequences are typically read into \c ::mbedtls_x509_buf. 00037 * \{ 00038 */ 00039 #define ARM_UC_MM_ASN1_BOOLEAN 0x01 00040 #define ARM_UC_MM_ASN1_INTEGER 0x02 00041 #define ARM_UC_MM_ASN1_BIT_STRING 0x03 00042 #define ARM_UC_MM_ASN1_OCTET_STRING 0x04 00043 #define ARM_UC_MM_ASN1_NULL 0x05 00044 #define ARM_UC_MM_ASN1_OID 0x06 00045 #define ARM_UC_MM_ASN1_ENUMERATED 0x0A 00046 #define ARM_UC_MM_ASN1_UTF8_STRING 0x0C 00047 #define ARM_UC_MM_ASN1_SEQUENCE 0x10 00048 #define ARM_UC_MM_ASN1_SET 0x11 00049 #define ARM_UC_MM_ASN1_PRINTABLE_STRING 0x13 00050 #define ARM_UC_MM_ASN1_T61_STRING 0x14 00051 #define ARM_UC_MM_ASN1_IA5_STRING 0x16 00052 #define ARM_UC_MM_ASN1_UTC_TIME 0x17 00053 #define ARM_UC_MM_ASN1_GENERALIZED_TIME 0x18 00054 #define ARM_UC_MM_ASN1_UNIVERSAL_STRING 0x1C 00055 #define ARM_UC_MM_ASN1_BMP_STRING 0x1E 00056 #define ARM_UC_MM_ASN1_PRIMITIVE 0x00 00057 #define ARM_UC_MM_ASN1_CONSTRUCTED 0x20 00058 #define ARM_UC_MM_ASN1_CONTEXT_SPECIFIC 0x80 00059 #define ARM_UC_MM_ASN1_CHOICE 0xFF // NOTE: This is not a real ASN1 number; it is a marker for choices 00060 00061 /* \} name */ 00062 00063 /** 00064 * \name ASN1 Error codes 00065 * These error codes are OR'ed to X509 error codes for 00066 * higher error granularity. 00067 * ASN1 is a standard to specify data structures. 00068 * \{ 00069 */ 00070 #define ARM_UC_DP_ERR_ASN1_OUT_OF_DATA -0x0060 /**< Out of data when parsing an ASN1 data structure. */ 00071 #define ARM_UC_DP_ERR_ASN1_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */ 00072 #define ARM_UC_DP_ERR_ASN1_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */ 00073 #define ARM_UC_DP_ERR_ASN1_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */ 00074 #define ARM_UC_DP_ERR_ASN1_INVALID_DATA -0x0068 /**< Data is invalid. (not used) */ 00075 #define ARM_UC_DP_ERR_ASN1_ALLOC_FAILED -0x006A /**< Memory allocation failed */ 00076 #define ARM_UC_DP_ERR_ASN1_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing ASN.1 data structure. */ 00077 00078 /* \} name */ 00079 00080 00081 #define ARM_UC_MM_DER_ID_LIST \ 00082 ENUM_AUTO(ARM_UC_MM_DER_UNINIT)\ 00083 ENUM_AUTO(ARM_UC_MM_DER_ROOT)\ 00084 ENUM_AUTO(ARM_UC_MM_DER_RESOURCE)\ 00085 ENUM_AUTO(ARM_UC_MM_DER_RESOURCE_URL)\ 00086 ENUM_AUTO(ARM_UC_MM_DER_RESOURCE_TYPE)\ 00087 ENUM_AUTO(ARM_UC_MM_DER_RESOURCE_CHOICE)\ 00088 ENUM_AUTO(ARM_UC_MM_DER_MFST)\ 00089 ENUM_AUTO(ARM_UC_MM_DER_MFST_VERSION)\ 00090 ENUM_AUTO(ARM_UC_MM_DER_MFST_DESC)\ 00091 ENUM_AUTO(ARM_UC_MM_DER_MFST_TIMESTAMP)\ 00092 ENUM_AUTO(ARM_UC_MM_DER_MFST_UUIDS)\ 00093 ENUM_AUTO(ARM_UC_MM_DER_MFST_VENDOR_UUID)\ 00094 ENUM_AUTO(ARM_UC_MM_DER_MFST_CLASS_UUID)\ 00095 ENUM_AUTO(ARM_UC_MM_DER_MFST_DEVICE_UUID)\ 00096 ENUM_AUTO(ARM_UC_MM_DER_MFST_NONCE)\ 00097 ENUM_AUTO(ARM_UC_MM_DER_MFST_VENDOR_INFO)\ 00098 ENUM_AUTO(ARM_UC_MM_DER_MFST_APPLY_PERIOD)\ 00099 ENUM_AUTO(ARM_UC_MM_DER_MFST_VALID_FROM)\ 00100 ENUM_AUTO(ARM_UC_MM_DER_MFST_VALID_TO)\ 00101 ENUM_AUTO(ARM_UC_MM_DER_MFST_APPLY_IMMEDIATELY)\ 00102 ENUM_AUTO(ARM_UC_MM_DER_MFST_ENCRYPTION_MODE_CHOICE)\ 00103 ENUM_AUTO(ARM_UC_MM_DER_MFST_ENC_ENUM)\ 00104 ENUM_AUTO(ARM_UC_MM_DER_MFST_ENC_OID)\ 00105 ENUM_AUTO(ARM_UC_MM_DER_MFST_RESOURCE_ALIASES)\ 00106 ENUM_AUTO(ARM_UC_MM_DER_MFST_RESOURCE_ALIAS)\ 00107 ENUM_AUTO(ARM_UC_MM_DER_MFST_RESOURCE_ALIAS_HASH)\ 00108 ENUM_AUTO(ARM_UC_MM_DER_MFST_RESOURCE_ALIAS_URL)\ 00109 ENUM_AUTO(ARM_UC_MM_DER_MFST_FIRMWARE)\ 00110 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_FMT_CHOICE)\ 00111 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_FMT_ENUM)\ 00112 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_FMT_OID)\ 00113 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_INFO)\ 00114 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_IV)\ 00115 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_ID_CHOICE)\ 00116 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_ID_LOCAL)\ 00117 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_ID_CERT_REF)\ 00118 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_ID_CERT_FINGERPRINT)\ 00119 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_ID_CERT_URL)\ 00120 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_KEY_CHOICE)\ 00121 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_KEY_CIPHERKEY)\ 00122 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_CRYPT_KEY_KEYTABLE_REF)\ 00123 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_STRG_ID)\ 00124 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_RSRC_REF)\ 00125 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_RSRC_REF_HASH)\ 00126 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_RSRC_REF_URL)\ 00127 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_RSRC_REF_SIZE)\ 00128 ENUM_AUTO(ARM_UC_MM_DER_MFST_FW_VER)\ 00129 ENUM_AUTO(ARM_UC_MM_DER_MFST_DEPS)\ 00130 ENUM_AUTO(ARM_UC_MM_DER_MFST_DEP)\ 00131 ENUM_AUTO(ARM_UC_MM_DER_MFST_DEP_REF_HASH)\ 00132 ENUM_AUTO(ARM_UC_MM_DER_MFST_DEP_REF_URL)\ 00133 ENUM_AUTO(ARM_UC_MM_DER_MFST_DEP_REF_SIZE)\ 00134 ENUM_AUTO(ARM_UC_MM_DER_FW_IMAGE)\ 00135 ENUM_AUTO(ARM_UC_MM_DER_SIG)\ 00136 ENUM_AUTO(ARM_UC_MM_DER_SIG_HASH)\ 00137 ENUM_AUTO(ARM_UC_MM_DER_SIG_SIGNATURES)\ 00138 ENUM_AUTO(ARM_UC_MM_DER_SIG_SIGNATURE_BLOCK)\ 00139 ENUM_AUTO(ARM_UC_MM_DER_SIG_SIGNATURE)\ 00140 ENUM_AUTO(ARM_UC_MM_DER_SIG_CERTS)\ 00141 ENUM_AUTO(ARM_UC_MM_DER_SIG_CERT)\ 00142 ENUM_AUTO(ARM_UC_MM_DER_SIG_CERT_FINGERPRINT)\ 00143 ENUM_AUTO(ARM_UC_MM_DER_SIG_CERT_URL)\ 00144 00145 enum derIDs { 00146 #define ENUM_AUTO(X) X, 00147 ARM_UC_MM_DER_ID_LIST 00148 #undef ENUM_AUTO 00149 }; 00150 00151 #define ARM_UC_DER_PARSER_ERROR_PREFIX TWO_CC('D', 'P') 00152 00153 struct arm_uc_mmDerElement 00154 { 00155 uint32_t id; 00156 const struct arm_uc_mmDerElement* subElements; 00157 uint8_t tag; 00158 uint8_t optional; 00159 uint8_t nSubElements; 00160 }; 00161 00162 extern const struct arm_uc_mmDerElement arm_uc_mmManifestUUID[]; 00163 extern const struct arm_uc_mmDerElement arm_uc_mmManifestDependencies[]; 00164 extern const struct arm_uc_mmDerElement arm_uc_mmManifestFirmwareDescription[]; 00165 extern const struct arm_uc_mmDerElement arm_uc_mmResourceSignature[]; 00166 extern const struct arm_uc_mmDerElement arm_uc_mmSignatures[]; 00167 extern const struct arm_uc_mmDerElement arm_uc_mmSignatureCertificateReferences[]; 00168 00169 int32_t ARM_UC_mmDERGetSignedResourceValues(arm_uc_buffer_t* buffer, uint32_t nValues, const int32_t* valueIDs, arm_uc_buffer_t* buffers); 00170 uint32_t ARM_UC_mmDerBuf2Uint(arm_uc_buffer_t* buf); 00171 uint64_t ARM_UC_mmDerBuf2Uint64(arm_uc_buffer_t* buf); 00172 int32_t ARM_UC_mmDERGetSequenceElement(arm_uc_buffer_t* buffer, uint32_t index, arm_uc_buffer_t* element); 00173 int32_t ARM_UC_mmDERParseTree(const struct arm_uc_mmDerElement* desc, arm_uc_buffer_t* buffer, uint32_t nValues, const int32_t* valueIDs, arm_uc_buffer_t* buffers); 00174 00175 00176 #ifdef __cplusplus 00177 } 00178 #endif 00179 00180 00181 #endif // ARM_UC_MM_DERPARSE_H
Generated on Tue Jul 12 2022 19:12:11 by 1.7.2