int is_responder)
{
SilcUnknownEntry conn_data;
+ SilcIDListData idata;
SilcHash nhash;
SILC_LOG_DEBUG(("Setting new key into use"));
conn_data = silc_calloc(1, sizeof(*conn_data));
+ idata = (SilcIDListData)conn_data;
/* Allocate cipher to be used in the communication */
- silc_cipher_alloc(cipher->cipher->name, &conn_data->send_key);
- silc_cipher_alloc(cipher->cipher->name, &conn_data->receive_key);
+ silc_cipher_alloc(cipher->cipher->name, &idata->send_key);
+ silc_cipher_alloc(cipher->cipher->name, &idata->receive_key);
if (is_responder == TRUE) {
- conn_data->send_key->cipher->set_key(conn_data->send_key->context,
- keymat->receive_enc_key,
- keymat->enc_key_len);
- conn_data->send_key->set_iv(conn_data->send_key, keymat->receive_iv);
- conn_data->receive_key->cipher->set_key(conn_data->receive_key->context,
- keymat->send_enc_key,
- keymat->enc_key_len);
- conn_data->receive_key->set_iv(conn_data->receive_key, keymat->send_iv);
+ idata->send_key->cipher->set_key(idata->send_key->context,
+ keymat->receive_enc_key,
+ keymat->enc_key_len);
+ idata->send_key->set_iv(idata->send_key, keymat->receive_iv);
+ idata->receive_key->cipher->set_key(idata->receive_key->context,
+ keymat->send_enc_key,
+ keymat->enc_key_len);
+ idata->receive_key->set_iv(idata->receive_key, keymat->send_iv);
} else {
- conn_data->send_key->cipher->set_key(conn_data->send_key->context,
- keymat->send_enc_key,
- keymat->enc_key_len);
- conn_data->send_key->set_iv(conn_data->send_key, keymat->send_iv);
- conn_data->receive_key->cipher->set_key(conn_data->receive_key->context,
- keymat->receive_enc_key,
- keymat->enc_key_len);
- conn_data->receive_key->set_iv(conn_data->receive_key, keymat->receive_iv);
+ idata->send_key->cipher->set_key(idata->send_key->context,
+ keymat->send_enc_key,
+ keymat->enc_key_len);
+ idata->send_key->set_iv(idata->send_key, keymat->send_iv);
+ idata->receive_key->cipher->set_key(idata->receive_key->context,
+ keymat->receive_enc_key,
+ keymat->enc_key_len);
+ idata->receive_key->set_iv(idata->receive_key, keymat->receive_iv);
}
/* Allocate PKCS to be used */
/* XXX Do we ever need to allocate PKCS for the connection??
If yes, we need to change KE protocol to get the initiators
public key. */
- silc_pkcs_alloc(pkcs->pkcs->name, &conn_data->pkcs);
- conn_data->public_key = silc_pkcs_public_key_alloc(XXX);
- silc_pkcs_set_public_key(conn_data->pkcs, ske->ke2_payload->pk_data,
+ silc_pkcs_alloc(pkcs->pkcs->name, &idata->pkcs);
+ idata->public_key = silc_pkcs_public_key_alloc(XXX);
+ silc_pkcs_set_public_key(idata->pkcs, ske->ke2_payload->pk_data,
ske->ke2_payload->pk_len);
#endif
/* Save HMAC key to be used in the communication. */
silc_hash_alloc(hash->hash->name, &nhash);
- silc_hmac_alloc(nhash, &conn_data->hmac);
- silc_hmac_set_key(conn_data->hmac, keymat->hmac_key, keymat->hmac_key_len);
+ 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;
}
-/* XXX TODO */
+/* Check remote host version string */
SilcSKEStatus silc_ske_check_version(SilcSKE ske, unsigned char *version,
unsigned int len)
{
- return SILC_SKE_STATUS_OK;
+ SilcSKEStatus status = SILC_SKE_STATUS_OK;
+
+ /* Check for initial version string */
+ if (!strstr(version, "SILC-1.0-"))
+ status = SILC_SKE_STATUS_BAD_VERSION;
+
+ /* Check software version */
+
+ if (len < strlen(silc_version_string))
+ status = SILC_SKE_STATUS_BAD_VERSION;
+
+ /* XXX for now there is no other tests due to the abnormal version
+ string that is used */
+
+ return status;
}
/* Performs key exchange protocol. This is used for both initiator
properties packet from initiator. */
status = silc_ske_responder_start(ske, ctx->rng, ctx->sock,
silc_version_string,
- ctx->packet, NULL, NULL);
+ ctx->packet->buffer, NULL, NULL);
} else {
SilcSKEStartPayload *start_payload;
paylaod reply we just got from the responder. The callback
function will receive the processed payload where we will
save it. */
- status =
- silc_ske_initiator_phase_1(ctx->ske,
- ctx->packet,
- NULL, NULL);
+ status = silc_ske_initiator_phase_1(ctx->ske, ctx->packet->buffer,
+ NULL, NULL);
}
if (status != SILC_SKE_STATUS_OK) {
/* Process the received Key Exchange 1 Payload packet from
the initiator. This also creates our parts of the Diffie
Hellman algorithm. */
- status =
- silc_ske_responder_phase_2(ctx->ske, ctx->packet, NULL, NULL);
+ status = silc_ske_responder_phase_2(ctx->ske, ctx->packet->buffer,
+ NULL, NULL);
} else {
/* Call the Phase-2 function. This creates Diffie Hellman
key exchange parameters and sends our public part inside
} else {
/* Finish the protocol. This verifies the Key Exchange 2 payload
sent by responder. */
- status =
- silc_ske_initiator_finish(ctx->ske,
- ctx->packet, NULL, NULL, NULL, NULL);
+ status = silc_ske_initiator_finish(ctx->ske, ctx->packet->buffer,
+ NULL, NULL, NULL, NULL);
}
if (status != SILC_SKE_STATUS_OK) {
/* Parse the received authentication data packet. The received
payload is Connection Auth Payload. */
- silc_buffer_unformat(ctx->packet,
+ silc_buffer_unformat(ctx->packet->buffer,
SILC_STR_UI_SHORT(&payload_len),
SILC_STR_UI_SHORT(&conn_type),
SILC_STR_END);
- if (payload_len != ctx->packet->len) {
+ 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;
if (payload_len > 0) {
/* Get authentication data */
- silc_buffer_pull(ctx->packet, 4);
- silc_buffer_unformat(ctx->packet,
+ 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);