int serverSupportsSSL(void) { #if defined(HAVE_OPENSSL) && !defined(HAVE_DLOPEN) return SSL_library_init(); #else #if defined(HAVE_OPENSSL) // We want to call loadSSL() exactly once. For single-threaded applications, // this is straight-forward. For threaded applications, we need to call // pthread_once(), instead. We perform run-time checks for whether we are // single- or multi-threaded, so that the same code can be used. // This currently only works on Linux. #if defined(HAVE_PTHREAD_H) && defined(__linux__) && defined(__i386__) if (!!&pthread_once) { static pthread_once_t once = PTHREAD_ONCE_INIT; pthread_once(&once, loadSSL); } else #endif { static int initialized; if (!initialized) { initialized = 1; loadSSL(); } } return !!SSL_library_init; #else return 0; #endif #endif }
SSLSocket::SSLSocket(const char *host, uint16_t port, const char *CAfile, const char *CRTfile, const char *KEYfile, void *passwd, int timeout, bool verify) { loadSSL(); ctx = sslCreateCtx(true, verify, CAfile, CRTfile, KEYfile, passwd); m_sock = sslConnect(host, port, timeout); buffer = new SocketBuffer(this); clientName = getCommonName(SSL_get_certificate(conn.sslHandle)); serverName = getCommonName(SSL_get_peer_certificate(conn.sslHandle)); }
SSLSocket::SSLSocket(connection c) { loadSSL(); ctx = NULL; m_sock = c.socket; conn.socket = c.socket; conn.sslHandle = c.sslHandle; buffer = new SocketBuffer(this); clientName = getCommonName(SSL_get_peer_certificate(conn.sslHandle)); serverName = getCommonName(SSL_get_certificate(conn.sslHandle)); }
SSLSocket::SSLSocket() { loadSSL(); clientName = NULL; serverName = NULL; }