From d339246a6ff38e43b76607915b501334ad89ff34 Mon Sep 17 00:00:00 2001 From: James Canete Date: Wed, 14 May 2008 20:46:35 +0000 Subject: [PATCH] Handle situations where tls doesn't init. --- src/auth.c | 25 ++++++++++++++++++++----- src/common.h | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/auth.c b/src/auth.c index 19449f7..be2d7d1 100644 --- a/src/auth.c +++ b/src/auth.c @@ -206,8 +206,6 @@ static int _handle_features(xmpp_conn_t * const conn, } } - /* TODO: Implement TLS */ - _auth(conn); return 0; @@ -240,19 +238,22 @@ static int _handle_proceedtls_default(xmpp_conn_t * const conn, if (strcmp(name, "proceed") == 0) { xmpp_debug(conn->ctx, "xmpp", "proceeding with TLS"); - parser_prepare_reset(conn, _handle_open_tls); - conn->tls = tls_new(conn->ctx, conn->sock); if (!tls_start(conn->tls)) { - xmpp_debug(conn->ctx, "xmpp", "Couldn't start TLS!"); + xmpp_debug(conn->ctx, "xmpp", "Couldn't start TLS! error %d", tls_error(conn->tls)); tls_free(conn->tls); conn->tls = NULL; + conn->tls_failed = 1; + + /* failed tls spoils the connection, so disconnect */ xmpp_disconnect(conn); } else { + parser_prepare_reset(conn, _handle_open_tls); + conn_open_stream(conn); } } @@ -473,6 +474,20 @@ static void _auth(xmpp_conn_t * const conn) if (conn->tls_support) { + tls_t *tls = tls_new(conn->ctx, conn->sock); + + /* If we couldn't init tls, it isn't there, so go on */ + if (!tls) + { + conn->tls_support = 0; + _auth(conn); + return; + } + else + { + tls_free(tls); + } + auth = _make_starttls(conn); if (!auth) { diff --git a/src/common.h b/src/common.h index 24ecb21..2af7d09 100644 --- a/src/common.h +++ b/src/common.h @@ -160,7 +160,8 @@ struct _xmpp_conn_t { sock_t sock; tls_t *tls; - int tls_support; + int tls_support; + int tls_failed; /* set when tls fails, so we don't try again */ int sasl_support; /* if true, field is a bitfield of supported mechanisms */