1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 #ifndef FRAME_TLS_H 17 #define FRAME_TLS_H 18 19 #include "bsl_uio.h" 20 #include "hs_ctx.h" 21 #include "frame_msg.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct FRAME_LinkObj_ FRAME_LinkObj; 28 29 typedef struct FRAME_CertInfo_ FRAME_CertInfo; 30 31 typedef struct SSL_LINK_OBJ_ SSL_LINK_OBJ; 32 33 HITLS_Ctx *FRAME_CreateDefaultDtlsObj(void); 34 35 /** 36 * @brief Load the certificate to the connection configuration context resource. 37 * 38 * @return If the value 0 is returned, the certificate is loaded successfully. 39 * Otherwise, the certificate fails to be loaded 40 */ 41 int32_t FRAME_LoadCertToConfig(HITLS_Config *config, const char *verifyCert, const char *chainCert, const char *eeCert, 42 const char *prvKey); 43 44 /** 45 * @brief Create a TLCP connection. 46 This interface loads the certificate, applies for SSL CTX, and creates the underlying UIO 47 * 48 * @return Return the connection object, which can be used by the test framework to perform operations 49 */ 50 FRAME_LinkObj *FRAME_CreateTLCPLink(HITLS_Config *config, BSL_UIO_TransportType type, bool isClient); 51 52 /** 53 * @brief Create an SSL connection. This interface will complete the SSL CTX application, 54 bottom-layer UIO creation, and load the default certificate 55 * 56 * @return Return the connection object, which can be used by the test framework to perform operations 57 */ 58 FRAME_LinkObj *FRAME_CreateLink(HITLS_Config *config, BSL_UIO_TransportType type); 59 60 // This interface is used to create an SSL connection. 61 // The SSL CTX application and bottom-layer UIO creation are completed. The default certificate is not loaded. 62 FRAME_LinkObj *FRAME_CreateLinkEx(HITLS_Config *config, BSL_UIO_TransportType type); 63 64 FRAME_LinkObj *FRAME_CreateLinkWithCert( 65 HITLS_Config *config, BSL_UIO_TransportType type, const FRAME_CertInfo *certInfo); 66 67 /** 68 * @brief Releases an SSL connection, which corresponds to Frame_CreateLink 69 * 70 * @return 71 */ 72 void FRAME_FreeLink(FRAME_LinkObj *linkObj); 73 74 /** 75 * @brief Obtain the TLS ctx from the Frame_LinkObj to facilitate the test of HiTLS APIs because HiTLS APIs use 76 * HITLS_Ctx as the input parameter. 77 * Do not call HiTLS_Free to release the return values of this API. 78 * The values will be released in the Frame_FreeLink. 79 * 80 * @return Return the CTX object of the TLS 81 */ 82 HITLS_Ctx *FRAME_GetTlsCtx(const FRAME_LinkObj *linkObj); 83 84 /* 85 * @brief Simulate link establishment or simulate an SSL link in a certain state. 86 * For example, if state is TRY_RECV_SERVER_HELLO, the client is ready to receive the SERVER Hello message, 87 * and The server link is just sent SERVER_HELLO. 88 * 89 * @return If the operation is successful, HITLS_SUCCESS is returned. 90 */ 91 int32_t FRAME_CreateConnection(FRAME_LinkObj *client, FRAME_LinkObj *server, bool isClient, HITLS_HandshakeState state); 92 93 /** 94 * @brief Simulate renegotiation 95 * @attention Internally invokes HITLS_Write and HITLS_Read to perform renegotiation. 96 * Ensure that linkA is the initiator of the renegotiation request and 97 * linkB is the receiver of the renegotiation request 98 * 99 * @param server [IN] Initiator of the renegotiation request 100 * @param client [IN] Recipient of the renegotiation request 101 * 102 * @return If the operation is successful, HITLS_SUCCESS is returned 103 */ 104 int32_t FRAME_CreateRenegotiationServer(FRAME_LinkObj *server, FRAME_LinkObj *client); 105 106 /* 107 * @ingroup Simulate connection establishment or an SSL connection in a certain state. 108 * For example, if the value of state is TRY_RECV_SERVER_HELLO, 109 * the client is ready to receive the SERVER Hello message, 110 * and the server connection is SERVER_HELLO has just been sent. 111 * 112 * 113 * @return If the operation is successful, HITLS_SUCCESS is returned 114 */ 115 int32_t FRAME_CreateRenegotiationState(FRAME_LinkObj *client, FRAME_LinkObj *server, bool isClient, HITLS_HandshakeState state); 116 117 /** 118 * @brief Simulate renegotiation 119 120 * @attention Internally invokes HITLS_Write and HITLS_Read to perform renegotiation. 121 * Ensure that linkA is the initiator of the renegotiation request and 122 * linkB is the receiver of the renegotiation request 123 * 124 * @param linkA [IN] Initiator of the renegotiation request 125 * @param linkB [IN] Recipient of the renegotiation request 126 * 127 * @return If the operation is successful, HITLS_SUCCESS is returned 128 */ 129 int32_t FRAME_CreateRenegotiation(FRAME_LinkObj *linkA, FRAME_LinkObj *linkB); 130 131 /** 132 * @brief Obtain a message from the I/O receiving buffer of the connection 133 * 134 * @return If the operation is successful, HITLS_SUCCESS is returned 135 */ 136 int32_t FRAME_GetLinkRecMsg(FRAME_LinkObj *link, uint8_t *buffer, uint32_t len, uint32_t *msgLen); 137 138 /** 139 * @brief Obtain a message from the I/O sending buffer of the connection. 140 * 141 * @return If the operation is successful, HITLS_SUCCESS is returned. 142 */ 143 int32_t FRAME_GetLinkSndMsg(FRAME_LinkObj *link, uint8_t *buffer, uint32_t len, uint32_t *msgLen); 144 145 /** 146 * @brief Generate a framework message based on the content in the message buffer 147 * 148 * @return Return the Constructed Frame_Msg object 149 */ 150 FRAME_Msg *FRAME_GenerateMsgFromBuffer(const FRAME_LinkObj *linkObj, const uint8_t *buffer, uint32_t len); 151 152 /** 153 * @brief Send data from connection A to connection B 154 * 155 * @return If the operation is successful, HITLS_SUCCESS is returned 156 */ 157 int32_t FRAME_TrasferMsgBetweenLink(FRAME_LinkObj *linkA, FRAME_LinkObj *linkB); 158 159 /** 160 * @brief Initialize the framework 161 */ 162 163 void FRAME_Init(void); 164 165 /** 166 * @brief Deinitialize the framework 167 */ 168 void FRAME_DeInit(void); 169 170 #ifdef __cplusplus 171 } 172 #endif 173 174 #endif // FRAME_TLS_H 175