Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2001 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
/* Sets the negotiated key material into use for particular connection. */
-static void silc_server_protocol_ke_set_keys(SilcSKE ske,
- SilcSocketConnection sock,
- SilcSKEKeyMaterial *keymat,
- SilcCipher cipher,
- SilcPKCS pkcs,
- SilcHash hash,
- int is_responder)
+static int silc_server_protocol_ke_set_keys(SilcSKE ske,
+ SilcSocketConnection sock,
+ SilcSKEKeyMaterial *keymat,
+ SilcCipher cipher,
+ SilcPKCS pkcs,
+ SilcHash hash,
+ int is_responder)
{
SilcUnknownEntry conn_data;
SilcIDListData idata;
idata = (SilcIDListData)conn_data;
/* Allocate cipher to be used in the communication */
- silc_cipher_alloc(cipher->cipher->name, &idata->send_key);
- silc_cipher_alloc(cipher->cipher->name, &idata->receive_key);
+ if (!silc_cipher_alloc(cipher->cipher->name, &idata->send_key)) {
+ silc_free(conn_data);
+ return FALSE;
+ }
+ if (!silc_cipher_alloc(cipher->cipher->name, &idata->receive_key)) {
+ silc_free(conn_data);
+ return FALSE;
+ }
if (is_responder == TRUE) {
idata->send_key->cipher->set_key(idata->send_key->context,
#endif
/* Save HMAC key to be used in the communication. */
- silc_hash_alloc(hash->hash->name, &nhash);
+ if (!silc_hash_alloc(hash->hash->name, &nhash)) {
+ silc_cipher_free(idata->send_key);
+ silc_cipher_free(idata->receive_key);
+ silc_free(conn_data);
+ return FALSE;
+ }
silc_hmac_alloc(nhash, &idata->hmac);
silc_hmac_set_key(idata->hmac, keymat->hmac_key, keymat->hmac_key_len);
sock->user_data = (void *)conn_data;
+
+ return TRUE;
}
/* Check remote host version string */
* End protocol
*/
SilcSKEKeyMaterial *keymat;
+ int key_len = silc_cipher_get_key_len(ctx->ske->prop->cipher, NULL);
+ int hash_len = ctx->ske->prop->hash->hash->hash_len;
/* Send Ok to the other end if we are responder. If we are
initiator we have sent this already. */
/* Process the key material */
keymat = silc_calloc(1, sizeof(*keymat));
- silc_ske_process_key_material(ctx->ske, 16, (16 * 8), 16, keymat);
+ silc_ske_process_key_material(ctx->ske, 16, key_len, hash_len,
+ keymat);
/* Take the new keys into use. */
- silc_server_protocol_ke_set_keys(ctx->ske, ctx->sock, keymat,
- ctx->ske->prop->cipher,
- ctx->ske->prop->pkcs,
- ctx->ske->prop->hash,
- ctx->responder);
+ if (!silc_server_protocol_ke_set_keys(ctx->ske, ctx->sock, keymat,
+ ctx->ske->prop->cipher,
+ ctx->ske->prop->pkcs,
+ ctx->ske->prop->hash,
+ ctx->responder)) {
+ protocol->state = SILC_PROTOCOL_STATE_ERROR;
+ protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
+ silc_ske_free_key_material(keymat);
+ return;
+ }
+
+ silc_ske_free_key_material(keymat);
/* Unregister the timeout task since the protocol has ended.
This was the timeout task to be executed if the protocol is
/* Parse the received authentication data packet. The received
payload is Connection Auth Payload. */
- silc_buffer_unformat(ctx->packet->buffer,
- SILC_STR_UI_SHORT(&payload_len),
- SILC_STR_UI_SHORT(&conn_type),
- SILC_STR_END);
+ ret = silc_buffer_unformat(ctx->packet->buffer,
+ SILC_STR_UI_SHORT(&payload_len),
+ SILC_STR_UI_SHORT(&conn_type),
+ SILC_STR_END);
+ if (ret == -1) {
+ SILC_LOG_DEBUG(("Bad payload in authentication packet"));
+ protocol->state = SILC_PROTOCOL_STATE_ERROR;
+ protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
+ return;
+ }
if (payload_len != ctx->packet->buffer->len) {
- SILC_LOG_ERROR(("Bad payload in authentication packet"));
SILC_LOG_DEBUG(("Bad payload in authentication packet"));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
if (conn_type < SILC_SOCKET_TYPE_CLIENT ||
conn_type > SILC_SOCKET_TYPE_ROUTER) {
SILC_LOG_ERROR(("Bad connection type %d", conn_type));
- SILC_LOG_DEBUG(("Bad connection type %d", conn_type));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
return;
if (payload_len > 0) {
/* Get authentication data */
silc_buffer_pull(ctx->packet->buffer, 4);
- silc_buffer_unformat(ctx->packet->buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&auth_data,
- payload_len),
- SILC_STR_END);
+ ret = silc_buffer_unformat(ctx->packet->buffer,
+ SILC_STR_UI_XNSTRING_ALLOC(&auth_data,
+ payload_len),
+ SILC_STR_END);
+ if (ret == -1) {
+ SILC_LOG_DEBUG(("Bad payload in authentication packet"));
+ protocol->state = SILC_PROTOCOL_STATE_ERROR;
+ protocol->execute(server->timeout_queue, 0,
+ protocol, fd, 0, 300000);
+ return;
+ }
} else {
auth_data = NULL;
}
/* Remote end is client */
if (conn_type == SILC_SOCKET_TYPE_CLIENT) {
- SilcConfigServerSectionClientConnection *client = NULL;
+ SilcServerConfigSectionClientConnection *client = NULL;
client =
- silc_config_server_find_client_conn(server->config,
+ silc_server_config_find_client_conn(server->config,
ctx->sock->ip,
ctx->sock->port);
if (!client)
client =
- silc_config_server_find_client_conn(server->config,
+ silc_server_config_find_client_conn(server->config,
ctx->sock->hostname,
ctx->sock->port);
if (client) {
switch(client->auth_meth) {
- case SILC_PROTOCOL_CONN_AUTH_NONE:
+ case SILC_AUTH_NONE:
/* No authentication required */
SILC_LOG_DEBUG(("No authentication required"));
break;
- case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
+ case SILC_AUTH_PASSWORD:
/* Password authentication */
SILC_LOG_DEBUG(("Password authentication"));
ret = silc_server_password_authentication(server, auth_data,
return;
break;
- case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
+ case SILC_AUTH_PUBLIC_KEY:
/* Public key authentication */
SILC_LOG_DEBUG(("Public key authentication"));
ret = silc_server_public_key_authentication(server,
/* Remote end is server */
if (conn_type == SILC_SOCKET_TYPE_SERVER) {
- SilcConfigServerSectionServerConnection *serv = NULL;
+ SilcServerConfigSectionServerConnection *serv = NULL;
serv =
- silc_config_server_find_server_conn(server->config,
+ silc_server_config_find_server_conn(server->config,
ctx->sock->ip,
ctx->sock->port);
if (!serv)
serv =
- silc_config_server_find_server_conn(server->config,
+ silc_server_config_find_server_conn(server->config,
ctx->sock->hostname,
ctx->sock->port);
if (serv) {
switch(serv->auth_meth) {
- case SILC_PROTOCOL_CONN_AUTH_NONE:
+ case SILC_AUTH_NONE:
/* No authentication required */
SILC_LOG_DEBUG(("No authentication required"));
break;
- case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
+ case SILC_AUTH_PASSWORD:
/* Password authentication */
SILC_LOG_DEBUG(("Password authentication"));
ret = silc_server_password_authentication(server, auth_data,
return;
break;
- case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
+ case SILC_AUTH_PUBLIC_KEY:
/* Public key authentication */
SILC_LOG_DEBUG(("Public key authentication"));
ret = silc_server_public_key_authentication(server,
/* Remote end is router */
if (conn_type == SILC_SOCKET_TYPE_ROUTER) {
- SilcConfigServerSectionServerConnection *serv = NULL;
+ SilcServerConfigSectionServerConnection *serv = NULL;
serv =
- silc_config_server_find_router_conn(server->config,
+ silc_server_config_find_router_conn(server->config,
ctx->sock->ip,
ctx->sock->port);
if (!serv)
serv =
- silc_config_server_find_router_conn(server->config,
+ silc_server_config_find_router_conn(server->config,
ctx->sock->hostname,
ctx->sock->port);
if (serv) {
switch(serv->auth_meth) {
- case SILC_PROTOCOL_CONN_AUTH_NONE:
+ case SILC_AUTH_NONE:
/* No authentication required */
SILC_LOG_DEBUG(("No authentication required"));
break;
- case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
+ case SILC_AUTH_PASSWORD:
/* Password authentication */
SILC_LOG_DEBUG(("Password authentication"));
ret = silc_server_password_authentication(server, auth_data,
return;
break;
- case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
+ case SILC_AUTH_PUBLIC_KEY:
/* Public key authentication */
SILC_LOG_DEBUG(("Public key authentication"));
ret = silc_server_public_key_authentication(server,
unsigned int auth_data_len = 0;
switch(ctx->auth_meth) {
- case SILC_PROTOCOL_CONN_AUTH_NONE:
+ case SILC_AUTH_NONE:
/* No authentication required */
break;
- case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
+ case SILC_AUTH_PASSWORD:
/* Password authentication */
if (ctx->auth_data && ctx->auth_data_len) {
auth_data = ctx->auth_data;
break;
- case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
+ case SILC_AUTH_PUBLIC_KEY:
/* Public key authentication */
/* XXX TODO */
break;
*/
unsigned char ok[4];
- SILC_PUT32_MSB(SILC_CONN_AUTH_OK, ok);
+ SILC_PUT32_MSB(SILC_AUTH_OK, ok);
/* Authentication failed */
silc_server_packet_send(server, ctx->sock, SILC_PACKET_SUCCESS,
*/
unsigned char error[4];
- SILC_PUT32_MSB(SILC_CONN_AUTH_FAILED, error);
+ SILC_PUT32_MSB(SILC_AUTH_FAILED, error);
/* Authentication failed */
silc_server_packet_send(server, ctx->sock, SILC_PACKET_FAILURE,