From 24af4356b33e158769af764df4ae8e74728256b4 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Fri, 18 Oct 2002 07:55:32 +0000 Subject: [PATCH] Added support for auto-passphrase authentication from the config file during connecting. Fixed auth protocol failure handling in Client library. --- CHANGES | 10 ++++++++ TODO | 6 ----- apps/irssi/src/silc/core/client_ops.c | 20 ++++++++++----- lib/silcclient/client.c | 37 ++++++++++++++++++++++++--- lib/silcclient/protocol.c | 2 +- 5 files changed, 58 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index 398b47dd..96a78a9a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,13 @@ +Fri Oct 18 10:51:04 EEST 2002 Pekka Riikonen + + * Added support for auto-passphrase authentication from the + config file during connecting which was not implemented + yet. Affected file irssi/src/silc/core/client_ops.c. + + * Fixed a bug in authentication protocol failure handling which + was processing wrong callback context. Affected files + are lib/silcclient/client.c and protocol.c. + Thu Oct 17 23:45:12 EEST 2002 Pekka Riikonen * Fixed string formatting crashbug in lib/silccore/silcattrs.c. diff --git a/TODO b/TODO index 15a34e5b..d1af4714 100644 --- a/TODO +++ b/TODO @@ -1,12 +1,6 @@ TODO/bugs in Irssi SILC client ============================== - o Server password is not used at all. It is not possible to automize - the password authentication currently. The silc_get_auth_method - in irssi/src/silc/core/client_ops.c should find the connection's - password, only if not found then continue resolving the auth method. - Alternatively it can do it after resolving in the callback. - o UTF-8 encode/decode WHOIS userinfos, topic, etc. o Manaul file for silc(1) and silc.conf. diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index c450af86..297272ef 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -2072,9 +2072,20 @@ static void silc_get_auth_method_callback(SilcClient client, (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context); break; case SILC_AUTH_PASSWORD: - /* Do not ask the passphrase from user, the library will ask it if - we do not provide it here. */ - (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context); + { + /* Check whether we find the password for this server in our + configuration. If not, then don't provide so library will ask + it from the user. */ + SERVER_SETUP_REC *setup = server_setup_find_port(conn->remote_host, + conn->remote_port); + if (!setup || !setup->password) { + (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context); + break; + } + + (*internal->completion)(TRUE, auth_meth, setup->password, + strlen(setup->password), internal->context); + } break; case SILC_AUTH_PUBLIC_KEY: /* Do not get the authentication data now, the library will generate @@ -2102,9 +2113,6 @@ void silc_get_auth_method(SilcClient client, SilcClientConnection conn, SILC_LOG_DEBUG(("Start")); - /* XXX must resolve from configuration whether this connection has - any specific authentication data */ - /* If we do not have this connection configured by the user in a configuration file then resolve the authentication method from the server for this session. */ diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 8b50fa4a..e5ad7fed 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -461,8 +461,8 @@ void silc_client_start_key_exchange(SilcClient client, conn, client->schedule); } -/* Callback called when error has occurred during connecting to the server. - The `connect' client operation will be called. */ +/* Callback called when error has occurred during connecting (KE) to + the server. The `connect' client operation will be called. */ SILC_TASK_CALLBACK(silc_client_connect_failure) { @@ -477,6 +477,20 @@ SILC_TASK_CALLBACK(silc_client_connect_failure) silc_free(ctx); } +/* Callback called when error has occurred during connecting (auth) to + the server. The `connect' client operation will be called. */ + +SILC_TASK_CALLBACK(silc_client_connect_failure_auth) +{ + SilcClientConnAuthInternalContext *ctx = + (SilcClientConnAuthInternalContext *)context; + SilcClient client = (SilcClient)ctx->client; + + client->internal->ops->connect(client, ctx->sock->user_data, + SILC_CLIENT_CONN_ERROR); + silc_free(ctx); +} + /* Start of the connection to the remote server. This is called after succesful TCP/IP connection has been established to the remote host. */ @@ -593,6 +607,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_second) silc_protocol_free(protocol); if (ctx->packet) silc_packet_context_free(ctx->packet); + ctx->packet = NULL; silc_free(ctx); sock->protocol = NULL; @@ -625,7 +640,21 @@ void silc_client_resolve_auth_method(bool success, proto_ctx->auth_meth = auth_meth; - if (auth_data && auth_data_len) { + if (success && auth_data && auth_data_len) { + + /* Passphrase must be UTF-8 encoded, if it isn't encode it */ + if (auth_meth == SILC_AUTH_PASSWORD && + !silc_utf8_valid(auth_data, auth_data_len)) { + int payload_len = 0; + unsigned char *autf8 = NULL; + payload_len = silc_utf8_encoded_len(auth_data, auth_data_len, + SILC_STRING_ASCII); + autf8 = silc_calloc(payload_len, sizeof(*autf8)); + auth_data_len = silc_utf8_encode(auth_data, auth_data_len, + SILC_STRING_ASCII, autf8, payload_len); + auth_data = autf8; + } + proto_ctx->auth_data = silc_memdup(auth_data, auth_data_len); proto_ctx->auth_data_len = auth_data_len; } @@ -761,7 +790,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_final) /* Notify application of failure */ silc_schedule_task_add(client->schedule, ctx->sock->sock, - silc_client_connect_failure, ctx, + silc_client_connect_failure_auth, ctx, 0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); } diff --git a/lib/silcclient/protocol.c b/lib/silcclient/protocol.c index e2f6454c..b8d4c3df 100644 --- a/lib/silcclient/protocol.c +++ b/lib/silcclient/protocol.c @@ -574,7 +574,7 @@ silc_client_conn_auth_continue(unsigned char *auth_data, int payload_len = 0; unsigned char *autf8 = NULL; - SILC_LOG_DEBUG(("Start")); + SILC_LOG_DEBUG(("Sending authentication to server")); /* Passphrase must be UTF-8 encoded, if it isn't encode it */ if (ctx->auth_meth == SILC_AUTH_PASSWORD && -- 2.24.0