1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _COMMON_CRYPTO_X509_H 8 #define _COMMON_CRYPTO_X509_H 9 10 #include <stdint.h> 11 #include "cc_crypto_x509_defs.h" 12 #include "cc_crypto_x509_common_defs.h" 13 14 15 typedef struct { 16 uint8_t setSerialNum; 17 uint32_t serialNum; 18 uint8_t setNotBefore; 19 long notBefore; 20 uint8_t setNotAfter; 21 long notAfter; 22 uint8_t setIssuerName; 23 char IssuerName[X509_ISSUER_NAME_MAX_STRING_SIZE+1]; 24 uint8_t setSubjectName; 25 char SubjectName[X509_SUBJECT_NAME_MAX_STRING_SIZE+1]; 26 }CCX509CertHeaderParamsIn_t; 27 28 /** 29 * @brief free X509 certificate 30 * 31 * @param[in/out] ppCertBuff - x.509 certificate 32 */ 33 /*********************************************************/ 34 void CC_CommonX509Free(uint8_t **ppCertBuff); 35 36 37 /** 38 * @brief Creates X509 certificate and set its header fields 39 * 40 * @param[in/out] ppCertBuff - x.509 certificate 41 * @param[in] certType - certificate type 42 */ 43 /*********************************************************/ 44 int32_t CC_CommonX509CreateAndSetHeader(uint8_t **ppCertBuff, 45 CCX509CertType_t certType,CCX509CertHeaderParamsIn_t *pCertHeaderParams); 46 47 48 /** 49 * @brief Add ASN.1 critical integer extension to X.509V3 certificate 50 * 51 * @param[in/out] pCertBuff - x.509 certificate 52 * @param[in] certType - certificate type 53 * @param[in] extType - extension type 54 * @param[in] val - Extension value 55 */ 56 /*********************************************************/ 57 int32_t CC_CommonX509AddIntegerExtension(uint8_t *pCertBuff, 58 CCX509CertType_t certType, 59 CCX509ExtType_t extType, 60 int32_t val); 61 62 63 /** 64 * @brief Add critical DER extension to X.509V3 certificate 65 * 66 * @param[in/out] pCertBuff - x.509 certificate 67 * @param[in] certType - certificate tyoes 68 * @param[in] extType - extension type 69 * @param[in] pVal - Extension data 70 * @param[in] valLen - extension data length 71 */ 72 /*********************************************************/ 73 int32_t CC_CommonX509AddStringExtension(uint8_t *pCertBuff, 74 CCX509CertType_t certType, 75 CCX509ExtType_t extType, 76 uint8_t *pVal, 77 uint32_t valLen); 78 79 /** 80 * @brief Add subject public key to the X509 certificate 81 * and sign the certificate 82 * 83 * @param[in/out] pCertBuff - x.509 certificate 84 * @param[in] pKeyPairFileName - key pair file name in PEM format 85 * @param[in] pKeyPairPwd - passphrase of key pair 86 */ 87 /*********************************************************/ 88 int32_t CC_CommonX509SetKeyAndSign(uint8_t *pCertBuff, 89 uint8_t *pKeyPairFileName, 90 uint8_t *pKeyPairPwd); 91 92 93 94 /** 95 * @brief convert the x.509 certificate to DER format 96 * 97 * @param[in/out] ppCertBuff - x.509 certificate 98 * @param[out] pOutCertSize - certificate size in DER format 99 /*********************************************************/ 100 int32_t CC_CommonX509ToDer(uint8_t **pCertBuff, 101 uint32_t *pOutCertSize); 102 103 104 /** 105 * @brief build package for the certificate 106 * 107 * @param[in] ppCertBuff - the x509 certificate in PEM format 108 * @param[in] certSize - certificate size 109 * @param[in] certType - certificate type 110 * @param[in] encFlag - indicates whether images were encrypted 111 * @param[in] hbkType - hbk type to use by target, in the verification 112 * @param[in] pAddData - additional data to add to package 113 * @param[in] addDataSize - length of additional data 114 * @param[in] outPkgFile - package file name to write the package to 115 */ 116 /*********************************************************/ 117 #ifdef CC_SB_SUPPORT_IOT 118 int32_t CC_CommonX509BuildCertPkg(uint8_t **ppCertBuff, 119 uint32_t certSize, 120 uint8_t *pAddData, 121 uint32_t addDataSize, 122 uint8_t *outPkgFile); 123 124 #else 125 int32_t CC_CommonX509BuildCertPkg(uint8_t **ppCertBuff, 126 uint32_t certSize, 127 CCX509CertType_t certType, 128 uint8_t encFlag, 129 uint8_t hbkType, 130 uint8_t *pAddData, 131 uint32_t addDataSize, 132 uint8_t *outPkgFile); 133 134 #endif 135 136 #endif 137