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.h" 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#ifndef LOG_CORE 29#define LOG_CORE 3 30#endif 31 32typedef struct MbedTLSSession { 33 char *host; 34 char *port; 35 36 unsigned char *buffer; 37 size_t buffer_len; 38 39 mbedtls_ssl_context ssl; 40 mbedtls_ssl_config conf; 41 mbedtls_entropy_context entropy; 42 mbedtls_ctr_drbg_context ctr_drbg; 43 mbedtls_net_context server_fd; 44 mbedtls_x509_crt cacert; 45} MbedTLSSession; 46 47int MbedtlsClientInit(MbedTLSSession *session, void *entropy, size_t entropyLen); 48int MbedtlsClientClose(MbedTLSSession *session); 49int MbedtlsClientContext(MbedTLSSession *session); 50int MbedtlsClientConnect(MbedTLSSession *session); 51int MbedtlsClientRead(MbedTLSSession *session, unsigned char *buf, size_t len); 52int MbedtlsClientWrite(MbedTLSSession *session, const unsigned char *buf, size_t len); 53 54#endif 55