/*
* Server side of the protocols.
*/
-/*
- * $Id$
- * $Log$
- * Revision 1.5 2000/07/10 05:42:14 priikone
- * Support for public key encoding functions added.
- *
- * Revision 1.4 2000/07/07 06:55:59 priikone
- * Added SILC style public key support and made server to use
- * it at all time.
- *
- * Revision 1.3 2000/07/06 07:15:31 priikone
- * Cleaner code fro password and public key authentication.
- * Deprecated old `channel_auth' protocol.
- *
- * Revision 1.2 2000/07/05 06:13:04 priikone
- * Support for SILC style public keys added.
- *
- * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
- * Imported from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
#include "serverincludes.h"
#include "server_internal.h"
SILC_TASK_CALLBACK(silc_server_protocol_connection_auth);
SILC_TASK_CALLBACK(silc_server_protocol_key_exchange);
-/* SILC client protocol list */
-const SilcProtocolObject silc_protocol_list[] =
-{
- { SILC_PROTOCOL_SERVER_CONNECTION_AUTH,
- silc_server_protocol_connection_auth },
- { SILC_PROTOCOL_SERVER_KEY_EXCHANGE,
- silc_server_protocol_key_exchange },
-
- { SILC_PROTOCOL_SERVER_NONE, NULL },
-};
+extern char *silc_version_string;
/*
* Key Exhange protocol functions
SilcHash hash,
int is_responder)
{
- SilcIDListUnknown *conn_data;
+ SilcUnknownEntry conn_data;
SilcHash nhash;
SILC_LOG_DEBUG(("Setting new key into use"));
/* Save HMAC key to be used in the communication. */
silc_hash_alloc(hash->hash->name, &nhash);
silc_hmac_alloc(nhash, &conn_data->hmac);
- conn_data->hmac_key_len = keymat->hmac_key_len;
- conn_data->hmac_key = silc_calloc(conn_data->hmac_key_len,
- sizeof(unsigned char));
- memcpy(conn_data->hmac_key, keymat->hmac_key, keymat->hmac_key_len);
+ silc_hmac_set_key(conn_data->hmac, keymat->hmac_key, keymat->hmac_key_len);
sock->user_data = (void *)conn_data;
}
+/* XXX TODO */
+
+SilcSKEStatus silc_ske_check_version(SilcSKE ske, unsigned char *version,
+ unsigned int len)
+{
+ return SILC_SKE_STATUS_OK;
+}
+
/* Performs key exchange protocol. This is used for both initiator
and responder key exchange. This is performed always when accepting
new connection to the server. This may be called recursively. */
/* Allocate Key Exchange object */
ske = silc_ske_alloc();
ctx->ske = ske;
+ ske->rng = server->rng;
if (ctx->responder == TRUE) {
/* Start the key exchange by processing the received security
properties packet from initiator. */
status = silc_ske_responder_start(ske, ctx->rng, ctx->sock,
+ silc_version_string,
ctx->packet, NULL, NULL);
} else {
SilcSKEStartPayload *start_payload;
/* Assemble security properties. */
- silc_ske_assemble_security_properties(ske, &start_payload);
+ silc_ske_assemble_security_properties(ske, SILC_SKE_SP_FLAG_NONE,
+ silc_version_string,
+ &start_payload);
/* Start the key exchange by sending our security properties
to the remote end. */
Key Exhange 1 Payload to the responder. */
status =
silc_ske_initiator_phase_2(ctx->ske,
+ server->public_key,
silc_server_protocol_ke_send_packet,
context);
}
protocol->state = SILC_PROTOCOL_STATE_END;
}
break;
+
case SILC_PROTOCOL_STATE_END:
{
/*
silc_protocol_free(protocol);
}
break;
+
case SILC_PROTOCOL_STATE_ERROR:
/*
* Error occured
*/
+ /* Send abort notification */
+ silc_ske_abort(ctx->ske, ctx->ske->status,
+ silc_server_protocol_ke_send_packet,
+ context);
+
/* Unregister the timeout task since the protocol has ended.
This was the timeout task to be executed if the protocol is
not completed fast enough. */
else
silc_protocol_free(protocol);
break;
+
+ case SILC_PROTOCOL_STATE_FAILURE:
+ /*
+ * We have received failure from remote
+ */
+
+ /* Unregister the timeout task since the protocol has ended.
+ This was the timeout task to be executed if the protocol is
+ not completed fast enough. */
+ if (ctx->timeout_task)
+ silc_task_unregister(server->timeout_queue, ctx->timeout_task);
+
+ /* On error the final callback is always called. */
+ if (protocol->final_callback)
+ protocol->execute_final(server->timeout_queue, 0, protocol, fd);
+ else
+ silc_protocol_free(protocol);
+ break;
+
case SILC_PROTOCOL_STATE_UNKNOWN:
break;
}
/*
* End protocol
*/
+ unsigned char ok[4];
- /* Succesfully authenticated */
- silc_server_packet_send(server, ctx->sock, SILC_PACKET_SUCCESS,
- 0, NULL, 0, TRUE);
+ SILC_PUT32_MSB(SILC_CONN_AUTH_OK, ok);
+
+ /* Authentication failed */
+ silc_server_packet_send(server, ctx->sock, SILC_PACKET_FAILURE,
+ 0, ok, 4, TRUE);
/* Unregister the timeout task since the protocol has ended.
This was the timeout task to be executed if the protocol is
case SILC_PROTOCOL_STATE_ERROR:
{
/*
- * Error
+ * Error. Send notify to remote.
*/
+ unsigned char error[4];
+
+ SILC_PUT32_MSB(SILC_CONN_AUTH_FAILED, error);
/* Authentication failed */
silc_server_packet_send(server, ctx->sock, SILC_PACKET_FAILURE,
- 0, NULL, 0, TRUE);
+ 0, error, 4, TRUE);
/* Unregister the timeout task since the protocol has ended.
This was the timeout task to be executed if the protocol is
silc_protocol_free(protocol);
}
break;
+
+ case SILC_PROTOCOL_STATE_FAILURE:
+ /*
+ * We have received failure from remote
+ */
+
+ /* Unregister the timeout task since the protocol has ended.
+ This was the timeout task to be executed if the protocol is
+ not completed fast enough. */
+ if (ctx->timeout_task)
+ silc_task_unregister(server->timeout_queue, ctx->timeout_task);
+
+ /* On error the final callback is always called. */
+ if (protocol->final_callback)
+ protocol->execute_final(server->timeout_queue, 0, protocol, fd);
+ else
+ silc_protocol_free(protocol);
+ break;
+
case SILC_PROTOCOL_STATE_UNKNOWN:
break;
}
}
+
+/* Registers protocols used in server. */
+
+void silc_server_protocols_register(void)
+{
+ silc_protocol_register(SILC_PROTOCOL_SERVER_CONNECTION_AUTH,
+ silc_server_protocol_connection_auth);
+ silc_protocol_register(SILC_PROTOCOL_SERVER_KEY_EXCHANGE,
+ silc_server_protocol_key_exchange);
+}
+
+/* Unregisters protocols */
+
+void silc_server_protocols_unregister(void)
+{
+ silc_protocol_unregister(SILC_PROTOCOL_SERVER_CONNECTION_AUTH,
+ silc_server_protocol_connection_auth);
+ silc_protocol_unregister(SILC_PROTOCOL_SERVER_KEY_EXCHANGE,
+ silc_server_protocol_key_exchange);
+}