EHS Embedded HTTP Server
1.5.0.132
|
00001 /* $Id: securesocket.h 95 2012-03-31 21:08:13Z felfert $ 00002 * 00003 * EHS is a library for embedding HTTP(S) support into a C++ application 00004 * 00005 * Copyright (C) 2004 Zachary J. Hansen 00006 * 00007 * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License version 2.1 as published by the Free Software Foundation; 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * This can be found in the 'COPYING' file. 00023 * 00024 */ 00025 00026 #ifndef SECURE_SOCKET_H 00027 #define SECURE_SOCKET_H 00028 00029 #ifdef COMPILE_WITH_SSL 00030 00031 #include <openssl/ssl.h> 00032 #include <openssl/rand.h> 00033 00034 #include <cstring> 00035 #include <string> 00036 #include <iostream> 00037 00038 #include "socket.h" 00039 #include "dynamicssllocking.h" 00040 #include "staticssllocking.h" 00041 #include "sslerror.h" 00042 00043 00048 #define CIPHER_LIST "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH" 00049 00050 class PassphraseHandler; 00051 00053 class SecureSocket : public Socket 00054 { 00055 private: 00056 SecureSocket(const SecureSocket &); 00057 00058 SecureSocket & operator=(const SecureSocket &); 00059 00060 public: 00061 00062 virtual void Init(int port); 00063 00069 SecureSocket(const std::string & certfile = "", 00070 PassphraseHandler *handler = NULL); 00071 00073 virtual ~SecureSocket(); 00074 00075 virtual NetworkAbstraction *Accept(); 00076 00079 virtual bool IsSecure() const { return true; } 00080 00081 virtual int Read(void *buf, int bufsize); 00082 00083 virtual int Send(const void *buf, size_t buflen, int flags = 0); 00084 00085 virtual void Close(); 00086 00087 virtual void ThreadCleanup(); 00088 00089 private: 00090 00101 static int PassphraseCallback(char * buf, int bufsize, int rwflag, void * userdata); 00102 00109 SecureSocket(SSL *ssl, ehs_socket_t fd, sockaddr_in *peer); 00110 00112 SSL_CTX *InitializeCertificates(); 00113 00114 protected: 00115 00117 SSL *m_pSsl; 00118 00120 std::string m_sCertFile; 00121 00123 PassphraseHandler * m_poPassphraseHandler; 00124 00125 private: 00126 00128 static DynamicSslLocking * s_pDynamicSslLocking; 00129 00131 static StaticSslLocking * s_pStaticSslLocking; 00132 00134 static SslError * s_pSslError; 00135 00137 static SSL_CTX * s_pSslCtx; 00138 00140 static int s_refcount; 00141 00143 static pthread_mutex_t s_mutex; 00144 }; 00145 00146 #endif // COMPILE_WITH_SSL 00147 00148 #endif // SECURE_SOCKET_H