1a8e1175bSopenharmony_ci/** 2a8e1175bSopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd. 3a8e1175bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a8e1175bSopenharmony_ci * you may not use this file except in compliance with the License. 5a8e1175bSopenharmony_ci * You may obtain a copy of the License at 6a8e1175bSopenharmony_ci * 7a8e1175bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a8e1175bSopenharmony_ci * 9a8e1175bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a8e1175bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a8e1175bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a8e1175bSopenharmony_ci * See the License for the specific language governing permissions and 13a8e1175bSopenharmony_ci * limitations under the License. 14a8e1175bSopenharmony_ci */ 15a8e1175bSopenharmony_ci 16a8e1175bSopenharmony_ci#ifndef MBEDTLS_CLIENT_H 17a8e1175bSopenharmony_ci#define MBEDTLS_CLIENT_H 18a8e1175bSopenharmony_ci 19a8e1175bSopenharmony_ci#include "mbedtls/platform.h" 20a8e1175bSopenharmony_ci#include "mbedtls/net_sockets.h" 21a8e1175bSopenharmony_ci#include "mbedtls/ssl.h" 22a8e1175bSopenharmony_ci#include "mbedtls/entropy.h" 23a8e1175bSopenharmony_ci#include "mbedtls/ctr_drbg.h" 24a8e1175bSopenharmony_ci#include "test/certs.h" 25a8e1175bSopenharmony_ci 26a8e1175bSopenharmony_ci#define RET_ERROR -1; 27a8e1175bSopenharmony_ci#define RET_EOK 0 28a8e1175bSopenharmony_ci#ifndef LOG_CORE 29a8e1175bSopenharmony_ci#define LOG_CORE 3 30a8e1175bSopenharmony_ci#endif 31a8e1175bSopenharmony_ci 32a8e1175bSopenharmony_citypedef struct MbedTLSSession { 33a8e1175bSopenharmony_ci char *host; 34a8e1175bSopenharmony_ci char *port; 35a8e1175bSopenharmony_ci 36a8e1175bSopenharmony_ci unsigned char *buffer; 37a8e1175bSopenharmony_ci size_t buffer_len; 38a8e1175bSopenharmony_ci 39a8e1175bSopenharmony_ci mbedtls_ssl_context ssl; 40a8e1175bSopenharmony_ci mbedtls_ssl_config conf; 41a8e1175bSopenharmony_ci mbedtls_entropy_context entropy; 42a8e1175bSopenharmony_ci mbedtls_ctr_drbg_context ctr_drbg; 43a8e1175bSopenharmony_ci mbedtls_net_context server_fd; 44a8e1175bSopenharmony_ci mbedtls_x509_crt cacert; 45a8e1175bSopenharmony_ci} MbedTLSSession; 46a8e1175bSopenharmony_ci 47a8e1175bSopenharmony_ciint MbedtlsClientInit(MbedTLSSession *session, void *entropy, size_t entropyLen); 48a8e1175bSopenharmony_ciint MbedtlsClientClose(MbedTLSSession *session); 49a8e1175bSopenharmony_ciint MbedtlsClientContext(MbedTLSSession *session); 50a8e1175bSopenharmony_ciint MbedtlsClientConnect(MbedTLSSession *session); 51a8e1175bSopenharmony_ciint MbedtlsClientRead(MbedTLSSession *session, unsigned char *buf, size_t len); 52a8e1175bSopenharmony_ciint MbedtlsClientWrite(MbedTLSSession *session, const unsigned char *buf, size_t len); 53a8e1175bSopenharmony_ci 54a8e1175bSopenharmony_ci#endif 55