Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2005 Pekka Riikonen
+ Copyright (C) 2005 - 2007 Pekka Riikonen
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
struct SilcConnAuthStruct {
SilcSKE ske;
SilcFSM fsm;
+ SilcAsyncOperationStruct op;
SilcConnectionType conn_type;
SilcAuthMethod auth_method;
void *auth_data;
/* Compute signature */
if (!silc_pkcs_sign(private_key, auth->data, silc_buffer_len(auth),
- *auth_data, len, auth_data_len, ske->prop->hash)) {
+ *auth_data, len, auth_data_len, TRUE, ske->prop->hash)) {
silc_free(*auth_data);
silc_buffer_free(auth);
return FALSE;
connauth->timeout_secs = timeout_secs;
connauth->ske = ske;
+ ske->refcnt++;
return connauth;
}
{
if (connauth->public_keys)
silc_dlist_uninit(connauth->public_keys);
+
+ /* Free reference */
+ silc_ske_free(connauth->ske);
+
silc_free(connauth);
}
int payload_len = 0;
unsigned char *auth_data = NULL;
SilcUInt32 auth_data_len = 0;
+ SilcPacketFlags flags = 0;
SILC_LOG_DEBUG(("Start"));
return SILC_FSM_CONTINUE;
}
auth_data_len = connauth->auth_data_len;
+ flags = SILC_PACKET_FLAG_LONG_PAD;
break;
case SILC_AUTH_PUBLIC_KEY:
SILC_STR_END);
/* Send the packet */
- if (!silc_packet_send(connauth->ske->stream, SILC_PACKET_CONNECTION_AUTH, 0,
- packet->data, silc_buffer_len(packet))) {
+ if (!silc_packet_send(connauth->ske->stream, SILC_PACKET_CONNECTION_AUTH,
+ flags, packet->data, silc_buffer_len(packet))) {
/** Error sending packet */
silc_fsm_next(fsm, silc_connauth_st_initiator_failure);
return SILC_FSM_CONTINUE;
SILC_LOG_DEBUG(("Authentication successful"));
connauth->success = TRUE;
} else {
- SILC_LOG_DEBUG(("Authentication failed"));
+ SILC_LOG_DEBUG(("Authentication failed, packet %s received",
+ silc_get_packet_name(connauth->packet->type)));
connauth->success = FALSE;
}
silc_packet_free(connauth->packet);
SILC_LOG_DEBUG(("Start"));
- /* Send FAILURE packet */
- SILC_PUT32_MSB(SILC_AUTH_FAILED, error);
- silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4);
+ if (!connauth->aborted) {
+ /* Send FAILURE packet */
+ SILC_PUT32_MSB(SILC_AUTH_FAILED, error);
+ silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4);
- /* Call completion callback */
- connauth->completion(connauth, FALSE, connauth->context);
+ silc_packet_stream_unlink(connauth->ske->stream,
+ &silc_connauth_stream_cbs, connauth);
+ silc_schedule_task_del_by_context(silc_fsm_get_schedule(fsm), connauth);
+
+ /* Call completion callback */
+ connauth->completion(connauth, FALSE, connauth->context);
+ return SILC_FSM_FINISH;
+ }
silc_packet_stream_unlink(connauth->ske->stream,
&silc_connauth_stream_cbs, connauth);
SilcConnAuthCompletion completion,
void *context)
{
- SilcAsyncOperation op;
-
SILC_LOG_DEBUG(("Connection authentication as initiator"));
if (auth_method == SILC_AUTH_PASSWORD && !auth_data) {
SILC_PACKET_FAILURE, -1);
/* Start the protocol */
- op = silc_async_alloc(silc_connauth_abort, NULL, connauth);
+ silc_async_init(&connauth->op, silc_connauth_abort, NULL, connauth);
silc_fsm_start(connauth->fsm, silc_connauth_st_initiator_start);
- return op;
+ return &connauth->op;
}
if (connauth->aborted) {
/** Aborted */
- silc_packet_free(connauth->packet);
+ if (connauth->packet)
+ silc_packet_free(connauth->packet);
silc_fsm_next(fsm, silc_connauth_st_responder_failure);
return SILC_FSM_CONTINUE;
}
/* Passphrase authentication */
if (passphrase && passphrase_len) {
SILC_LOG_DEBUG(("Passphrase authentication"));
- if (!memcmp(auth_data, passphrase, passphrase_len)) {
+ if (!auth_data || payload_len != passphrase_len ||
+ memcmp(auth_data, passphrase, passphrase_len)) {
/** Authentication failed */
silc_fsm_next(fsm, silc_connauth_st_responder_failure);
return SILC_FSM_CONTINUE;
SILC_LOG_DEBUG(("Digital signature authentication"));
+ if (!auth_data) {
+ /** Authentication failed */
+ silc_fsm_next(fsm, silc_connauth_st_responder_failure);
+ return SILC_FSM_CONTINUE;
+ }
+
connauth->auth_data = silc_memdup(auth_data, payload_len);
connauth->auth_data_len = payload_len;
/** Find public key */
silc_fsm_next(fsm, silc_connauth_st_responder_authenticate_pk);
- SILC_FSM_CALL(silc_skr_find(repository, find, silc_connauth_skr_callback,
+ SILC_FSM_CALL(silc_skr_find(repository, silc_fsm_get_schedule(fsm),
+ find, silc_connauth_skr_callback,
connauth));
/* NOT REACHED */
}
SILC_PUT32_MSB(SILC_AUTH_OK, tmp);
silc_packet_send(connauth->ske->stream, SILC_PACKET_SUCCESS, 0, tmp, 4);
- /* Call completion callback */
- connauth->completion(connauth, TRUE, connauth->context);
-
silc_packet_stream_unlink(connauth->ske->stream,
&silc_connauth_stream_cbs, connauth);
silc_schedule_task_del_by_context(silc_fsm_get_schedule(fsm), connauth);
+ /* Call completion callback */
+ connauth->completion(connauth, TRUE, connauth->context);
+
return SILC_FSM_FINISH;
}
SILC_LOG_ERROR(("Authentication failed"));
- /* Send FAILURE packet */
- SILC_PUT32_MSB(SILC_AUTH_FAILED, error);
- silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4);
+ if (!connauth->aborted) {
+ /* Send FAILURE packet */
+ SILC_PUT32_MSB(SILC_AUTH_FAILED, error);
+ silc_packet_send(connauth->ske->stream, SILC_PACKET_FAILURE, 0, error, 4);
- /* Call completion callback */
- connauth->completion(connauth, FALSE, connauth->context);
+ silc_packet_stream_unlink(connauth->ske->stream,
+ &silc_connauth_stream_cbs, connauth);
+ silc_schedule_task_del_by_context(silc_fsm_get_schedule(fsm), connauth);
+
+ /* Call completion callback */
+ connauth->completion(connauth, FALSE, connauth->context);
+
+ return SILC_FSM_FINISH;
+ }
silc_packet_stream_unlink(connauth->ske->stream,
&silc_connauth_stream_cbs, connauth);
SilcConnAuthCompletion completion,
void *context)
{
- SilcAsyncOperation op;
-
SILC_LOG_DEBUG(("Connection authentication as responder"));
connauth->get_auth_data = get_auth_data;
SILC_PACKET_FAILURE, -1);
/* Start the protocol */
- op = silc_async_alloc(silc_connauth_abort, NULL, connauth);
+ silc_async_init(&connauth->op, silc_connauth_abort, NULL, connauth);
silc_fsm_start(connauth->fsm, silc_connauth_st_responder_start);
- return op;
+ return &connauth->op;
}