Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2001 Pekka Riikonen
+ Copyright (C) 1997 - 2002 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
if (silc_verify_public_key_internal(server, ctx->sock,
(ctx->responder == FALSE ?
SILC_SOCKET_TYPE_ROUTER:
- ctx->sconfig ? SILC_SOCKET_TYPE_SERVER :
- ctx->rconfig ? SILC_SOCKET_TYPE_ROUTER :
+ ctx->sconfig.ref_ptr ? SILC_SOCKET_TYPE_SERVER :
+ ctx->rconfig.ref_ptr ? SILC_SOCKET_TYPE_ROUTER :
SILC_SOCKET_TYPE_CLIENT),
pk_data, pk_len, pk_type))
completion(ske, SILC_SKE_STATUS_OK, completion_context);
sock->user_data = (void *)conn_data;
- SILC_LOG_INFO(("%s (%s) security properties: %s %s %s",
+ SILC_LOG_INFO(("%s (%s) security properties: %s %s %s %s",
sock->hostname, sock->ip,
idata->send_key->cipher->name,
(char *)silc_hmac_get_name(idata->hmac_send),
- idata->hash->hash->name));
+ idata->hash->hash->name,
+ ske->prop->flags & SILC_SKE_SP_FLAG_PFS ? "PFS" : ""));
return TRUE;
}
SilcSKEStatus silc_ske_check_version(SilcSKE ske, unsigned char *version,
SilcUInt32 len, void *context)
{
- SilcSKEStatus status = SILC_SKE_STATUS_OK;
- char *cp;
- int maj = 0, min = 0, build = 0, maj2 = 0, min2 = 0, build2 = 0;
+ SilcUInt32 l_protocol_version = 0, r_protocol_version = 0;
SILC_LOG_INFO(("%s (%s) is version %s", ske->sock->hostname,
ske->sock->ip, version));
- /* Check for initial version string */
- if (!strstr(version, "SILC-1.0-"))
- status = SILC_SKE_STATUS_BAD_VERSION;
-
- /* Check software version */
-
- cp = version + 9;
- if (!cp)
- status = SILC_SKE_STATUS_BAD_VERSION;
-
- maj = atoi(cp);
- cp = strchr(cp, '.');
- if (cp) {
- min = atoi(cp + 1);
- cp++;
- }
- if (cp) {
- cp = strchr(cp, '.');
- if (cp)
- build = atoi(cp + 1);
+ if (!silc_parse_version_string(version, &r_protocol_version, NULL, NULL,
+ NULL, NULL)) {
+ SILC_LOG_ERROR(("%s (%s) %s is not allowed/supported version",
+ ske->sock->hostname, ske->sock->ip, version));
+ return SILC_SKE_STATUS_BAD_VERSION;
}
- cp = silc_version_string + 9;
- if (!cp)
- status = SILC_SKE_STATUS_BAD_VERSION;
-
- maj2 = atoi(cp);
- cp = strchr(cp, '.');
- if (cp) {
- min2 = atoi(cp + 1);
- cp++;
- }
- if (cp) {
- cp = strchr(cp, '.');
- if (cp)
- build2 = atoi(cp + 1);
+ if (!silc_parse_version_string(silc_version_string,
+ &l_protocol_version, NULL, NULL,
+ NULL, NULL)) {
+ SILC_LOG_ERROR(("%s (%s) %s is not allowed/supported version",
+ ske->sock->hostname, ske->sock->ip, version));
+ return SILC_SKE_STATUS_BAD_VERSION;
}
- if (maj != maj2)
- status = SILC_SKE_STATUS_BAD_VERSION;
-#if 0
- if (min > min2)
- status = SILC_SKE_STATUS_BAD_VERSION;
-#endif
-
- /* XXX < 0.6 is not allowed */
- if (maj == 0 && min < 5)
- status = SILC_SKE_STATUS_BAD_VERSION;
-
- if (status == SILC_SKE_STATUS_BAD_VERSION)
+ /* If remote is too new, don't connect */
+ if (l_protocol_version < r_protocol_version) {
SILC_LOG_ERROR(("%s (%s) %s is not allowed/supported version",
ske->sock->hostname, ske->sock->ip, version));
+ return SILC_SKE_STATUS_BAD_VERSION;
+ }
- return status;
+ ske->sock->version = r_protocol_version;
+
+ return SILC_SKE_STATUS_OK;
}
/* Callback that is called by the SKE to indicate that it is safe to
if (ske->status != SILC_SKE_STATUS_OK) {
SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
silc_ske_map_status(ske->status)));
- SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
- silc_ske_map_status(ske->status)));
-
+
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
if (status != SILC_SKE_STATUS_OK) {
SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
silc_ske_map_status(status)));
- SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
- silc_ske_map_status(status)));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
if (status != SILC_SKE_STATUS_OK) {
SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
silc_ske_map_status(status)));
- SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
- silc_ske_map_status(status)));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
if (status != SILC_SKE_STATUS_OK) {
SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
silc_ske_map_status(status)));
- SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
- silc_ske_map_status(status)));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
if (status != SILC_SKE_STATUS_OK) {
SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
silc_ske_map_status(status)));
- SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
- silc_ske_map_status(status)));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
static bool
silc_server_get_authentication(SilcServerConnAuthInternalContext *ctx,
char *local_passphrase,
- void *local_publickey,
+ SilcHashTable local_publickeys,
unsigned char *remote_auth,
SilcUInt32 remote_auth_len)
{
/* If we don't have authentication data set at all we do not require
authentication at all */
- if (!local_passphrase && !local_publickey) {
+ if (!local_passphrase && (!local_publickeys ||
+ !silc_hash_table_count(local_publickeys))) {
SILC_LOG_DEBUG(("No authentication required"));
return TRUE;
}
}
/* Try public key authenetication */
- if (!result && local_publickey) {
+ if (!result && local_publickeys) {
+ SilcPublicKey cached_key;
+ SilcPublicKey remote_key =
+ ((SilcIDListData)ctx->sock->user_data)->public_key;
+
SILC_LOG_DEBUG(("Public key authentication"));
- result = silc_server_public_key_authentication(server,
- local_publickey,
+
+ /* Find the public key to be used in authentication */
+ cached_key = silc_server_find_public_key(server, local_publickeys,
+ remote_key);
+ if (!cached_key)
+ return FALSE;
+
+ result = silc_server_public_key_authentication(server, cached_key,
remote_auth,
- remote_auth_len,
- ske);
+ remote_auth_len, ske);
}
return result;
/* Remote end is client */
if (conn_type == SILC_SOCKET_TYPE_CLIENT) {
- SilcServerConfigClient *client = ctx->cconfig;
-
+ SilcServerConfigClient *client = ctx->cconfig.ref_ptr;
+
if (client) {
ret = silc_server_get_authentication(ctx, client->passphrase,
- client->publickey,
+ client->publickeys,
auth_data, payload_len);
if (!ret) {
/* Authentication failed */
SILC_LOG_ERROR(("Authentication failed"));
- SILC_LOG_DEBUG(("Authentication failed"));
silc_free(auth_data);
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
}
} else {
- SILC_LOG_DEBUG(("No configuration for remote client connection"));
SILC_LOG_ERROR(("Remote client connection not configured"));
SILC_LOG_ERROR(("Authentication failed"));
silc_free(auth_data);
/* Remote end is server */
if (conn_type == SILC_SOCKET_TYPE_SERVER) {
- SilcServerConfigServer *serv = ctx->sconfig;
-
+ SilcServerConfigServer *serv = ctx->sconfig.ref_ptr;
+
if (serv) {
ret = silc_server_get_authentication(ctx, serv->passphrase,
- serv->publickey,
+ serv->publickeys,
auth_data, payload_len);
if (!ret) {
/* Authentication failed */
SILC_LOG_ERROR(("Authentication failed"));
- SILC_LOG_DEBUG(("Authentication failed"));
silc_free(auth_data);
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
}
} else {
- SILC_LOG_DEBUG(("No configuration for remote server connection"));
SILC_LOG_ERROR(("Remote server connection not configured"));
SILC_LOG_ERROR(("Authentication failed"));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
/* Remote end is router */
if (conn_type == SILC_SOCKET_TYPE_ROUTER) {
- SilcServerConfigRouter *serv = ctx->rconfig;
+ SilcServerConfigRouter *serv = ctx->rconfig.ref_ptr;
if (serv) {
ret = silc_server_get_authentication(ctx, serv->passphrase,
- serv->publickey,
+ serv->publickeys,
auth_data, payload_len);
if (!ret) {
/* Authentication failed */
SILC_LOG_ERROR(("Authentication failed"));
- SILC_LOG_DEBUG(("Authentication failed"));
silc_free(auth_data);
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
}
} else {
- SILC_LOG_DEBUG(("No configuration for remote router connection"));
SILC_LOG_ERROR(("Remote router connection not configured"));
SILC_LOG_ERROR(("Authentication failed"));
silc_free(auth_data);
*/
if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_1) {
- SILC_LOG_ERROR(("Error during Re-key (PFS): re-key state is "
- "incorrect (received %d, expected %d packet)",
- ctx->packet->type, SILC_PACKET_KEY_EXCHANGE_1));
+ SILC_LOG_ERROR(("Error during Re-key (R PFS): re-key state is "
+ "incorrect (received %d, expected %d packet), "
+ "with %s (%s)", ctx->packet->type,
+ SILC_PACKET_KEY_EXCHANGE_1, ctx->sock->hostname,
+ ctx->sock->ip));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
status = silc_ske_responder_phase_2(ctx->ske, ctx->packet->buffer);
if (status != SILC_SKE_STATUS_OK) {
- SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
- silc_ske_map_status(status)));
+ SILC_LOG_ERROR(("Error (%s) during Re-key (R PFS), with %s (%s)",
+ silc_ske_map_status(status), ctx->sock->hostname,
+ ctx->sock->ip));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
status = silc_ske_initiator_phase_2(ctx->ske, NULL, NULL, 0);
if (status != SILC_SKE_STATUS_OK) {
- SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
- silc_ske_map_status(status)));
+ SILC_LOG_ERROR(("Error (%s) during Re-key (I PFS), with %s (%s)",
+ silc_ske_map_status(status), ctx->sock->hostname,
+ ctx->sock->ip));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
status = silc_ske_responder_finish(ctx->ske, NULL, NULL,
SILC_SKE_PK_TYPE_SILC);
if (status != SILC_SKE_STATUS_OK) {
- SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
- silc_ske_map_status(status)));
+ SILC_LOG_ERROR(("Error (%s) during Re-key (R PFS), with %s (%s)",
+ silc_ske_map_status(status), ctx->sock->hostname,
+ ctx->sock->ip));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
* The packet type must be KE packet
*/
if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_2) {
- SILC_LOG_ERROR(("Error during Re-key (PFS): re-key state is "
- "incorrect (received %d, expected %d packet)",
- ctx->packet->type, SILC_PACKET_KEY_EXCHANGE_2));
+ SILC_LOG_ERROR(("Error during Re-key (I PFS): re-key state is "
+ "incorrect (received %d, expected %d packet), "
+ "with %s (%s)", ctx->packet->type,
+ SILC_PACKET_KEY_EXCHANGE_2, ctx->sock->hostname,
+ ctx->sock->ip));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
status = silc_ske_initiator_finish(ctx->ske, ctx->packet->buffer);
if (status != SILC_SKE_STATUS_OK) {
- SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
- silc_ske_map_status(status)));
+ SILC_LOG_ERROR(("Error (%s) during Re-key (I PFS), with %s (%s)",
+ silc_ske_map_status(status), ctx->sock->hostname,
+ ctx->sock->ip));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
*/
if (ctx->packet->type != SILC_PACKET_REKEY_DONE) {
- SILC_LOG_ERROR(("Error during Re-key (PFS): re-key state is "
- "incorrect (received %d, expected %d packet)",
- ctx->packet->type, SILC_PACKET_REKEY_DONE));
+ SILC_LOG_ERROR(("Error during Re-key (%s PFS): re-key state is "
+ "incorrect (received %d, expected %d packet), "
+ "with %s (%s)", ctx->responder ? "R" : "I",
+ ctx->packet->type, SILC_PACKET_REKEY_DONE,
+ ctx->sock->hostname, ctx->sock->ip));
protocol->state = SILC_PROTOCOL_STATE_ERROR;
silc_protocol_execute(protocol, server->schedule, 0, 300000);
return;
/* We received the REKEY_DONE packet and all packets after this is
encrypted with the new key so set the decryption key to the new key */
- silc_server_protocol_rekey_generate(server, ctx, FALSE);
+ if (ctx->pfs == TRUE)
+ silc_server_protocol_rekey_generate_pfs(server, ctx, FALSE);
+ else
+ silc_server_protocol_rekey_generate(server, ctx, FALSE);
/* Assure that after calling final callback there cannot be pending
executions for this protocol anymore. This just unregisters any