From 4f608fd9574101e46ad5e5d1b2d1e8c7b0048ee2 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 10 Dec 2008 09:25:22 -0700 Subject: [PATCH] First pass at fixing up OpenSSL support. It now seems to work. --- SConstruct | 16 +++++++--- src/tls_openssl.c | 79 ++++++++++------------------------------------- 2 files changed, 28 insertions(+), 67 deletions(-) diff --git a/SConstruct b/SConstruct index 0e4250b..f697c13 100644 --- a/SConstruct +++ b/SConstruct @@ -17,6 +17,9 @@ # invoke with 'scons' to build the library +# change this to one of openssl or schannel if you want TLS support +TLS_PLUGIN = 'dummy' + LIBSTROPHE_VERSION_MAJOR=0 LIBSTROPHE_VERSION_MINOR=7 @@ -48,11 +51,10 @@ Sources = Split(""" util.c thread.c snprintf.c - tls_dummy.c - oocontext.cpp - oostanza.cpp """) +Sources += ' tls_%s.c' % TLS_PLUGIN + Headers = Split(""" strophe.h common.h @@ -99,6 +101,8 @@ Default(strophe) exenv = env.Clone() exenv.Append(CPPPATH=['.']) exenv.Append(LIBS=["strophe", "expat"]) +if TLS_PLUGIN == 'openssl': + exenv.Append(LIBS=["ssl"]) exenv.Append(LIBPATH=["."]) if exenv["PLATFORM"] == "win32": exenv.Append(LIBS=["ws2_32", "winmm"]) @@ -140,9 +144,13 @@ def testcase_runner(target, source, env): testenv = env.Clone() testenv.Append(CPPPATH=['.', 'src', join('expat','lib')]) -testenv.Append(LIBS=['strophe', 'expat']) +testenv.Append(LIBS=["strophe", "expat"]) +if TLS_PLUGIN == 'openssl': + testenv.Append(LIBS=["ssl"]) if testenv["PLATFORM"] == "win32": testenv.Append(LIBS=["winmm", "ws2_32"]) +if testenv["PLATFORM"] != "win32": + testenv.Append(LIBS=["resolv"]) testenv.Append(LIBPATH=['.']) import SCons.Node diff --git a/src/tls_openssl.c b/src/tls_openssl.c index c567fe9..4abf706 100644 --- a/src/tls_openssl.c +++ b/src/tls_openssl.c @@ -16,8 +16,16 @@ * TLS implementation with OpenSSL. */ +#include + +#ifndef _WIN32 +#include +#else +#include +#endif + #include -#include +#include #include "common.h" #include "tls.h" @@ -33,24 +41,8 @@ struct _tls { void tls_initialize(void) { -#ifdef _WIN32 - RAND_screen (); -#else - { - char filename[512]; - char *file; - - filename[0] = '\0'; - file = RAND_file_name(filename, 512); - - if (file && strlen(file) != 0) { - RAND_load_file(filename, /*It's over */9000); - } - } -#endif SSL_library_init(); SSL_load_error_strings(); - return; } void tls_shutdown(void) @@ -58,44 +50,9 @@ void tls_shutdown(void) return; } -void tls_logerror(tls_t *tls) +int tls_error(tls_t *tls) { - char *texterror = NULL; - - switch(tls->lasterror) { - case SSL_ERROR_NONE: - texterror = "No error."; - break; - case SSL_ERROR_ZERO_RETURN: - texterror = "Connection closed."; - break; - case SSL_ERROR_WANT_READ: - texterror = "Data waiting to read."; - break; - case SSL_ERROR_WANT_WRITE: - texterror = "Data waiting to write."; - break; - case SSL_ERROR_WANT_CONNECT: - texterror = "Not yet connected."; - break; - case SSL_ERROR_WANT_ACCEPT: - texterror = "Not yet accepted."; - break; - case SSL_ERROR_WANT_X509_LOOKUP: - texterror = "No certification."; - break; - case SSL_ERROR_SYSCALL: - texterror = "I/O error."; - break; - case SSL_ERROR_SSL: - texterror = "SSL library internal error"; - break; - default: - texterror = "Unknown error"; - break; - } - - xmpp_debug(tls->ctx, "xmpp", "SSL error: %s", texterror); + return tls->lasterror; } tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock) @@ -166,7 +123,6 @@ int tls_start(tls_t *tls) if (ret <= 0) { tls->lasterror = SSL_get_error(tls->ssl, ret); - tls_logerror(tls); return 0; } @@ -182,18 +138,12 @@ int tls_stop(tls_t *tls) if (ret <= 0) { tls->lasterror = SSL_get_error(tls->ssl, ret); - tls_logerror(tls); return 0; } return 1; } -int tls_error(tls_t *tls) -{ - return tls->lasterror; -} - int tls_is_recoverable(int error) { return (error == SSL_ERROR_NONE || error == SSL_ERROR_WANT_READ @@ -208,7 +158,6 @@ int tls_read(tls_t *tls, void * const buff, const size_t len) if (ret <= 0) { tls->lasterror = SSL_get_error(tls->ssl, ret); - tls_logerror(tls); } return ret; @@ -220,8 +169,12 @@ int tls_write(tls_t *tls, const void * const buff, const size_t len) if (ret <= 0) { tls->lasterror = SSL_get_error(tls->ssl, ret); - tls_logerror(tls); } return ret; } + +int tls_clear_pending_write(tls_t *tls) +{ + return 0; +}