1 /******************************************************************************* 2 * Copyright (c) 2009, 2018 IBM Corp. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License v1.0 6 * and Eclipse Distribution License v1.0 which accompany this distribution. 7 * 8 * The Eclipse Public License is available at 9 * http://www.eclipse.org/legal/epl-v10.html 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 #else 24 #include <pthread.h> 25 #include <semaphore.h> 26 #define ssl_mutex_type pthread_mutex_t 27 #endif 28 29 #if defined(OPENSSL) 30 #include <openssl/ssl.h> 31 #endif 32 33 #include "SocketBuffer.h" 34 #include "Clients.h" 35 36 #define URI_SSL "ssl://" 37 38 /** if we should handle openssl initialization (bool_value == 1) or depend on it to be initalized externally (bool_value == 0) */ 39 void SSLSocket_handleOpensslInit(int bool_value); 40 41 int SSLSocket_initialize(void); 42 void SSLSocket_terminate(void); 43 int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts, const char* hostname, size_t hostname_len); 44 45 int SSLSocket_getch(SSL* ssl, int socket, char* c); 46 char *SSLSocket_getdata(SSL* ssl, int socket, size_t bytes, size_t* actual_len); 47 48 int SSLSocket_close(networkHandles* net); 49 int SSLSocket_putdatas(SSL* ssl, int socket, char* buf0, size_t buf0len, int count, char** buffers, size_t* buflens, int* frees); 50 int SSLSocket_connect(SSL* ssl, int sock, const char* hostname, int verify, int (*cb)(const char *str, size_t len, void *u), void* u); 51 52 int SSLSocket_getPendingRead(void); 53 int SSLSocket_continueWrite(pending_writes* pw); 54 55 #endif 56