1 /******************************************************************************* 2 * Copyright (c) 2009, 2022 IBM Corp., Ian Craggs 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License v2.0 6 * and Eclipse Distribution License v1.0 which accompany this distribution. 7 * 8 * The Eclipse Public License is available at 9 * https://www.eclipse.org/legal/epl-2.0/ 10 * and the Eclipse Distribution License is available at 11 * http://www.eclipse.org/org/documents/edl-v10.php. 12 * 13 * Contributors: 14 * Ian Craggs, Allan Stockdill-Mander - initial implementation 15 * Ian Craggs - SNI support 16 * Ian Craggs - post connect checks and CApath 17 *******************************************************************************/ 18 #if !defined(SSLSOCKET_H) 19 #define SSLSOCKET_H 20 21 #if defined(_WIN32) || defined(_WIN64) 22 #define ssl_mutex_type HANDLE 23 #elif defined(COMPAT_CMSIS) 24 #include "cmsis_os2.h" 25 typedef osMutexId_t ssl_mutex_type; 26 #else 27 #include <pthread.h> 28 #include <semaphore.h> 29 #define ssl_mutex_type pthread_mutex_t 30 #endif 31 32 #if defined(OPENSSL) 33 #include <openssl/ssl.h> 34 #endif 35 #include "SocketBuffer.h" 36 #include "Clients.h" 37 38 #define URI_SSL "ssl://" 39 #define URI_MQTTS "mqtts://" 40 41 /** if we should handle openssl initialization (bool_value == 1) or depend on it to be initalized externally (bool_value == 0) */ 42 void SSLSocket_handleOpensslInit(int bool_value); 43 44 int SSLSocket_initialize(void); 45 void SSLSocket_terminate(void); 46 int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts, const char* hostname, size_t hostname_len); 47 48 int SSLSocket_getch(SSL* ssl, SOCKET socket, char* c); 49 char *SSLSocket_getdata(SSL* ssl, SOCKET socket, size_t bytes, size_t* actual_len, int* rc); 50 51 int SSLSocket_close(networkHandles* net); 52 int SSLSocket_putdatas(SSL* ssl, SOCKET socket, char* buf0, size_t buf0len, PacketBuffers bufs); 53 int SSLSocket_connect(SSL* ssl, SOCKET sock, const char* hostname, int verify, int (*cb)(const char *str, size_t len, void *u), void* u); 54 55 SOCKET SSLSocket_getPendingRead(void); 56 int SSLSocket_continueWrite(pending_writes* pw); 57 int SSLSocket_abortWrite(pending_writes* pw); 58 59 #endif 60