From ba9edaa568088900145bbd1004c864b7d408c38d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 10 May 2006 19:34:46 +0200 Subject: Moved everything to the BitlBee event handling API. --- protocols/ssl_openssl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'protocols/ssl_openssl.c') diff --git a/protocols/ssl_openssl.c b/protocols/ssl_openssl.c index b79088cc..df4aea2b 100644 --- a/protocols/ssl_openssl.c +++ b/protocols/ssl_openssl.c @@ -51,7 +51,7 @@ struct scd SSL_CTX *ssl_ctx; }; -static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ); +static void ssl_connected( gpointer data, gint source, b_input_condition cond ); @@ -94,9 +94,9 @@ void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data return( conn ); } -static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ); +static void ssl_handshake( gpointer data, gint source, b_input_condition cond ); -static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ) +static void ssl_connected( gpointer data, gint source, b_input_condition cond ) { struct scd *conn = data; @@ -110,7 +110,7 @@ static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ) return ssl_handshake( data, source, cond ); } -static void ssl_handshake( gpointer data, gint source, GaimInputCondition cond ) +static void ssl_handshake( gpointer data, gint source, b_input_condition cond ) { struct scd *conn = data; int st; @@ -220,7 +220,7 @@ int ssl_getfd( void *conn ) return( ((struct scd*)conn)->fd ); } -GaimInputCondition ssl_getdirection( void *conn ) +b_input_condition ssl_getdirection( void *conn ) { return( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ? GAIM_INPUT_WRITE : GAIM_INPUT_READ ); } -- cgit v1.2.3 From 309cb9e19395261d020f7ea649807ff1adbe76de Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 13 May 2006 16:20:32 +0200 Subject: OpenSSL support. --- protocols/ssl_openssl.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'protocols/ssl_openssl.c') diff --git a/protocols/ssl_openssl.c b/protocols/ssl_openssl.c index df4aea2b..54788ec3 100644 --- a/protocols/ssl_openssl.c +++ b/protocols/ssl_openssl.c @@ -51,8 +51,7 @@ struct scd SSL_CTX *ssl_ctx; }; -static void ssl_connected( gpointer data, gint source, b_input_condition cond ); - +static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond ); void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) @@ -94,30 +93,30 @@ void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data return( conn ); } -static void ssl_handshake( gpointer data, gint source, b_input_condition cond ); +static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond ); -static void ssl_connected( gpointer data, gint source, b_input_condition cond ) +static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond ) { struct scd *conn = data; if( source == -1 ) return ssl_handshake( data, -1, cond ); - /* Make it non-blocking at least during the handshake... */ + /* We can do at least the handshake with non-blocking I/O */ sock_make_nonblocking( conn->fd ); SSL_set_fd( conn->ssl, conn->fd ); return ssl_handshake( data, source, cond ); } -static void ssl_handshake( gpointer data, gint source, b_input_condition cond ) +static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond ) { struct scd *conn = data; int st; if( conn->inpa != -1 ) { - gaim_input_remove( conn->inpa ); + b_event_remove( conn->inpa ); conn->inpa = -1; } @@ -127,14 +126,14 @@ static void ssl_handshake( gpointer data, gint source, b_input_condition cond ) if( conn->lasterr != SSL_ERROR_WANT_READ && conn->lasterr != SSL_ERROR_WANT_WRITE ) goto ssl_connected_failure; - conn->inpa = gaim_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data ); - return; + conn->inpa = b_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data ); + return FALSE; } conn->established = TRUE; sock_make_blocking( conn->fd ); /* For now... */ conn->func( conn->data, conn, cond ); - return; + return FALSE; ssl_connected_failure: conn->func( conn->data, NULL, cond ); @@ -150,6 +149,8 @@ ssl_connected_failure: } if( source >= 0 ) closesocket( source ); g_free( conn ); + + return FALSE; } int ssl_read( void *conn, char *buf, int len ) @@ -203,7 +204,7 @@ void ssl_disconnect( void *conn_ ) struct scd *conn = conn_; if( conn->inpa != -1 ) - gaim_input_remove( conn->inpa ); + b_event_remove( conn->inpa ); if( conn->established ) SSL_shutdown( conn->ssl ); -- cgit v1.2.3 From 782d988a88582a0f3dd6539664d535fb790df024 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 13 May 2006 21:01:14 +0200 Subject: libevent code works better with epoll() now in some (pretty common) situations. --- protocols/ssl_openssl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols/ssl_openssl.c') diff --git a/protocols/ssl_openssl.c b/protocols/ssl_openssl.c index 54788ec3..5aa0263e 100644 --- a/protocols/ssl_openssl.c +++ b/protocols/ssl_openssl.c @@ -114,7 +114,7 @@ static gboolean ssl_handshake( gpointer data, gint source, b_input_condition con struct scd *conn = data; int st; - if( conn->inpa != -1 ) + if( 0 && conn->inpa != -1 ) { b_event_remove( conn->inpa ); conn->inpa = -1; -- cgit v1.2.3 From 19ac9c5c98a8d5adf22bcf5b8e2d4141c82a3275 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 13 May 2006 21:44:59 +0200 Subject: Timeouts are now persistent. --- protocols/ssl_openssl.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'protocols/ssl_openssl.c') diff --git a/protocols/ssl_openssl.c b/protocols/ssl_openssl.c index 5aa0263e..b6f6c520 100644 --- a/protocols/ssl_openssl.c +++ b/protocols/ssl_openssl.c @@ -114,12 +114,6 @@ static gboolean ssl_handshake( gpointer data, gint source, b_input_condition con struct scd *conn = data; int st; - if( 0 && conn->inpa != -1 ) - { - b_event_remove( conn->inpa ); - conn->inpa = -1; - } - if( ( st = SSL_connect( conn->ssl ) ) < 0 ) { conn->lasterr = SSL_get_error( conn->ssl, st ); -- cgit v1.2.3 From df1694b9559d4abec748b0506b5f44e684d022a8 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 25 Jun 2006 14:15:42 +0200 Subject: Moving all generic files to lib/ instead of having some in / and some in protocols/, and adding RC4 code. --- protocols/ssl_openssl.c | 221 ------------------------------------------------ 1 file changed, 221 deletions(-) delete mode 100644 protocols/ssl_openssl.c (limited to 'protocols/ssl_openssl.c') diff --git a/protocols/ssl_openssl.c b/protocols/ssl_openssl.c deleted file mode 100644 index b6f6c520..00000000 --- a/protocols/ssl_openssl.c +++ /dev/null @@ -1,221 +0,0 @@ - /********************************************************************\ - * BitlBee -- An IRC to other IM-networks gateway * - * * - * Copyright 2002-2004 Wilmer van der Gaast and others * - \********************************************************************/ - -/* SSL module - OpenSSL version */ - -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License with - the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; - if not, write to the Free Software Foundation, Inc., 59 Temple Place, - Suite 330, Boston, MA 02111-1307 USA -*/ - -#include -#include -#include -#include -#include -#include - -#include "proxy.h" -#include "ssl_client.h" -#include "sock.h" - -int ssl_errno = 0; - -static gboolean initialized = FALSE; - -struct scd -{ - ssl_input_function func; - gpointer data; - int fd; - gboolean established; - - int inpa; - int lasterr; /* Necessary for SSL_get_error */ - SSL *ssl; - SSL_CTX *ssl_ctx; -}; - -static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond ); - - -void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) -{ - struct scd *conn = g_new0( struct scd, 1 ); - SSL_METHOD *meth; - - conn->fd = proxy_connect( host, port, ssl_connected, conn ); - conn->func = func; - conn->data = data; - - if( conn->fd < 0 ) - { - g_free( conn ); - return( NULL ); - } - - if( !initialized ) - { - initialized = TRUE; - SSLeay_add_ssl_algorithms(); - } - - meth = TLSv1_client_method(); - conn->ssl_ctx = SSL_CTX_new( meth ); - if( conn->ssl_ctx == NULL ) - { - conn->fd = -1; - return( NULL ); - } - - conn->ssl = SSL_new( conn->ssl_ctx ); - if( conn->ssl == NULL ) - { - conn->fd = -1; - return( NULL ); - } - - return( conn ); -} - -static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond ); - -static gboolean ssl_connected( gpointer data, gint source, b_input_condition cond ) -{ - struct scd *conn = data; - - if( source == -1 ) - return ssl_handshake( data, -1, cond ); - - /* We can do at least the handshake with non-blocking I/O */ - sock_make_nonblocking( conn->fd ); - SSL_set_fd( conn->ssl, conn->fd ); - - return ssl_handshake( data, source, cond ); -} - -static gboolean ssl_handshake( gpointer data, gint source, b_input_condition cond ) -{ - struct scd *conn = data; - int st; - - if( ( st = SSL_connect( conn->ssl ) ) < 0 ) - { - conn->lasterr = SSL_get_error( conn->ssl, st ); - if( conn->lasterr != SSL_ERROR_WANT_READ && conn->lasterr != SSL_ERROR_WANT_WRITE ) - goto ssl_connected_failure; - - conn->inpa = b_input_add( conn->fd, ssl_getdirection( conn ), ssl_handshake, data ); - return FALSE; - } - - conn->established = TRUE; - sock_make_blocking( conn->fd ); /* For now... */ - conn->func( conn->data, conn, cond ); - return FALSE; - -ssl_connected_failure: - conn->func( conn->data, NULL, cond ); - - if( conn->ssl ) - { - SSL_shutdown( conn->ssl ); - SSL_free( conn->ssl ); - } - if( conn->ssl_ctx ) - { - SSL_CTX_free( conn->ssl_ctx ); - } - if( source >= 0 ) closesocket( source ); - g_free( conn ); - - return FALSE; -} - -int ssl_read( void *conn, char *buf, int len ) -{ - int st; - - if( !((struct scd*)conn)->established ) - { - ssl_errno = SSL_NOHANDSHAKE; - return -1; - } - - st = SSL_read( ((struct scd*)conn)->ssl, buf, len ); - - ssl_errno = SSL_OK; - if( st <= 0 ) - { - ((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st ); - if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ) - ssl_errno = SSL_AGAIN; - } - - return st; -} - -int ssl_write( void *conn, const char *buf, int len ) -{ - int st; - - if( !((struct scd*)conn)->established ) - { - ssl_errno = SSL_NOHANDSHAKE; - return -1; - } - - st = SSL_write( ((struct scd*)conn)->ssl, buf, len ); - - ssl_errno = SSL_OK; - if( st <= 0 ) - { - ((struct scd*)conn)->lasterr = SSL_get_error( ((struct scd*)conn)->ssl, st ); - if( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_READ || ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ) - ssl_errno = SSL_AGAIN; - } - - return st; -} - -void ssl_disconnect( void *conn_ ) -{ - struct scd *conn = conn_; - - if( conn->inpa != -1 ) - b_event_remove( conn->inpa ); - - if( conn->established ) - SSL_shutdown( conn->ssl ); - - closesocket( conn->fd ); - - SSL_free( conn->ssl ); - SSL_CTX_free( conn->ssl_ctx ); - g_free( conn ); -} - -int ssl_getfd( void *conn ) -{ - return( ((struct scd*)conn)->fd ); -} - -b_input_condition ssl_getdirection( void *conn ) -{ - return( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ? GAIM_INPUT_WRITE : GAIM_INPUT_READ ); -} -- cgit v1.2.3