1 /** 2 * Copyright (c) 2020 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 MBEDTLS_CLIENT_H 17 #define MBEDTLS_CLIENT_H 18 19 #include "mbedtls/platform.h" 20 #include "mbedtls/net_sockets" 21 #include "mbedtls/ssl.h" 22 #include "mbedtls/entropy.h" 23 #include "mbedtls/ctr_drbg.h" 24 #include "test/certs.h" 25 26 #define RET_ERROR -1; 27 #define RET_EOK 0 28 29 typedef struct MbedTLSSession { 30 char *host; 31 char *port; 32 33 unsigned char *buffer; 34 size_t buffer_len; 35 36 mbedtls_ssl_context ssl; 37 mbedtls_ssl_config conf; 38 mbedtls_entropy_context entropy; 39 mbedtls_ctr_drbg_context ctr_drbg; 40 mbedtls_net_context server_fd; 41 mbedtls_x509_crt cacert; 42 } MbedTLSSession; 43 44 int MbedtlsClientInit(MbedTLSSession *session, void *entropy, size_t entropyLen); 45 int MbedtlsClientClose(MbedTLSSession *session); 46 int MbedtlsClientContext(MbedTLSSession *session); 47 int MbedtlsClientConnect(MbedTLSSession *session); 48 int MbedtlsClientRead(MbedTLSSession *session, unsigned char *buf, size_t len); 49 int MbedtlsClientWrite(MbedTLSSession *session, const unsigned char *buf, size_t len); 50 51 #endif 52