5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2006 - 2007 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
21 #include "silcclient.h"
22 #include "client_internal.h"
24 /************************ Static utility functions **************************/
26 /* Callback called after connected to remote host */
28 static void silc_client_connect_callback(SilcResult status,
29 SilcStream stream, void *context)
31 SilcFSMThread fsm = context;
32 SilcClientConnection conn = silc_fsm_get_context(fsm);
33 SilcClient client = conn->client;
35 conn->internal->op = NULL;
36 if (conn->internal->verbose) {
40 case SILC_ERR_UNKNOWN_IP:
41 client->internal->ops->say(
42 client, conn, SILC_CLIENT_MESSAGE_ERROR,
43 "Could not connect to host %s: unknown IP address",
46 case SILC_ERR_UNKNOWN_HOST:
47 client->internal->ops->say(
48 client, conn, SILC_CLIENT_MESSAGE_ERROR,
49 "Could not connect to host %s: unknown host name",
52 case SILC_ERR_UNREACHABLE:
53 client->internal->ops->say(
54 client, conn, SILC_CLIENT_MESSAGE_ERROR,
55 "Could not connect to host %s: network unreachable",
58 case SILC_ERR_REFUSED:
59 client->internal->ops->say(
60 client, conn, SILC_CLIENT_MESSAGE_ERROR,
61 "Could not connect to host %s: connection refused",
64 case SILC_ERR_TIMEOUT:
65 client->internal->ops->say(
66 client, conn, SILC_CLIENT_MESSAGE_ERROR,
67 "Could not connect to host %s: connection timeout",
71 client->internal->ops->say(
72 client, conn, SILC_CLIENT_MESSAGE_ERROR,
73 "Could not connect to host %s",
79 if (status != SILC_OK) {
80 /* Notify application of failure */
81 SILC_LOG_DEBUG(("Connecting failed"));
82 conn->internal->status = SILC_CLIENT_CONN_ERROR;
83 silc_fsm_next(fsm, silc_client_st_connect_error);
84 SILC_FSM_CALL_CONTINUE(fsm);
88 /* Connection created successfully */
89 SILC_LOG_DEBUG(("Connected"));
90 conn->internal->user_stream = stream;
91 SILC_FSM_CALL_CONTINUE(fsm);
94 /* Called after application has verified remote host's public key */
96 static void silc_client_ke_verify_key_cb(SilcBool success, void *context)
98 SilcVerifyKeyContext verify = context;
100 SILC_LOG_DEBUG(("Start"));
102 /* Call the completion callback back to the SKE */
103 verify->completion(verify->ske, success ? SILC_SKE_STATUS_OK :
104 SILC_SKE_STATUS_UNSUPPORTED_PUBLIC_KEY,
105 verify->completion_context);
110 /* Verify remote host's public key */
112 static void silc_client_ke_verify_key(SilcSKE ske,
113 SilcPublicKey public_key,
115 SilcSKEVerifyCbCompletion completion,
116 void *completion_context)
118 SilcFSMThread fsm = context;
119 SilcClientConnection conn = silc_fsm_get_context(fsm);
120 SilcClient client = conn->client;
121 SilcVerifyKeyContext verify;
123 /* If we provided repository for SKE and we got here the key was not
124 found from the repository. */
125 if (conn->internal->params.repository &&
126 !conn->internal->params.verify_notfound) {
127 completion(ske, SILC_SKE_STATUS_UNSUPPORTED_PUBLIC_KEY,
132 SILC_LOG_DEBUG(("Verify remote public key"));
134 verify = silc_calloc(1, sizeof(*verify));
136 completion(ske, SILC_SKE_STATUS_UNSUPPORTED_PUBLIC_KEY,
141 verify->completion = completion;
142 verify->completion_context = completion_context;
144 /* Verify public key in application */
145 client->internal->ops->verify_public_key(client, conn,
146 conn->type, public_key,
147 silc_client_ke_verify_key_cb,
151 /* Key exchange protocol completion callback */
153 static void silc_client_ke_completion(SilcSKE ske,
154 SilcSKEStatus status,
155 SilcSKESecurityProperties prop,
156 SilcSKEKeyMaterial keymat,
157 SilcSKERekeyMaterial rekey,
160 SilcFSMThread fsm = context;
161 SilcClientConnection conn = silc_fsm_get_context(fsm);
162 SilcClient client = conn->client;
163 SilcCipher send_key, receive_key;
164 SilcHmac hmac_send, hmac_receive;
166 conn->internal->op = NULL;
167 if (status != SILC_SKE_STATUS_OK) {
168 /* Key exchange failed */
169 SILC_LOG_DEBUG(("Error during key exchange with %s: %s (%d)",
170 conn->remote_host, silc_ske_map_status(status), status));
172 if (conn->internal->verbose)
173 client->internal->ops->say(client, conn, SILC_CLIENT_MESSAGE_ERROR,
174 "Error during key exchange with %s: %s",
176 silc_ske_map_status(status));
178 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
179 silc_ske_free_rekey_material(rekey);
181 silc_fsm_next(fsm, silc_client_st_connect_error);
182 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
186 SILC_LOG_DEBUG(("Setting keys into use"));
188 /* Allocate the cipher and HMAC contexts */
189 if (!silc_ske_set_keys(ske, keymat, prop, &send_key, &receive_key,
190 &hmac_send, &hmac_receive, &conn->internal->hash)) {
191 /* Error setting keys */
192 SILC_LOG_DEBUG(("Could not set keys into use"));
194 if (conn->internal->verbose)
195 client->internal->ops->say(
196 client, conn, SILC_CLIENT_MESSAGE_ERROR,
197 "Error during key exchange with %s: cannot use keys",
200 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
201 silc_ske_free_rekey_material(rekey);
203 silc_fsm_next(fsm, silc_client_st_connect_error);
204 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
208 /* Set the keys into the packet stream. After this call packets will be
209 encrypted with these keys. */
210 if (!silc_packet_set_keys(conn->stream, send_key, receive_key, hmac_send,
211 hmac_receive, FALSE)) {
212 /* Error setting keys */
213 SILC_LOG_DEBUG(("Could not set keys into use"));
215 if (conn->internal->verbose)
216 client->internal->ops->say(
217 client, conn, SILC_CLIENT_MESSAGE_ERROR,
218 "Error during key exchange with %s: cannot use keys",
221 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
222 silc_ske_free_rekey_material(rekey);
224 silc_fsm_next(fsm, silc_client_st_connect_error);
225 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
229 conn->internal->rekey = rekey;
231 SILC_LOG_DEBUG(("Key Exchange completed"));
233 /* Key exchange done */
234 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
237 /* Rekey protocol completion callback */
239 static void silc_client_rekey_completion(SilcSKE ske,
240 SilcSKEStatus status,
241 SilcSKESecurityProperties prop,
242 SilcSKEKeyMaterial keymat,
243 SilcSKERekeyMaterial rekey,
246 SilcFSMThread fsm = context;
247 SilcClientConnection conn = silc_fsm_get_context(fsm);
248 SilcClient client = conn->client;
250 conn->internal->op = NULL;
251 if (status != SILC_SKE_STATUS_OK) {
253 SILC_LOG_DEBUG(("Error during rekey with %s: %s (%d)",
254 conn->remote_host, silc_ske_map_status(status), status));
256 if (conn->internal->verbose)
257 client->internal->ops->say(client, conn, SILC_CLIENT_MESSAGE_ERROR,
258 "Error during rekey with %s: %s",
260 silc_ske_map_status(status));
262 silc_ske_free(conn->internal->ske);
263 conn->internal->ske = NULL;
264 silc_fsm_finish(fsm);
268 silc_ske_free_rekey_material(conn->internal->rekey);
269 conn->internal->rekey = rekey;
271 silc_ske_free(conn->internal->ske);
272 conn->internal->ske = NULL;
274 SILC_LOG_DEBUG(("Rekey completed conn %p", conn));
277 silc_fsm_finish(fsm);
280 /* Callback called by application to return authentication data */
282 static void silc_client_connect_auth_method(SilcAuthMethod auth_meth,
287 SilcFSMThread fsm = context;
288 SilcClientConnection conn = silc_fsm_get_context(fsm);
290 conn->internal->params.auth_method = auth_meth;
291 if (auth_meth == SILC_AUTH_PASSWORD)
292 conn->internal->params.auth = silc_memdup(auth, auth_len);
294 conn->internal->params.auth = (void *)auth;
295 conn->internal->params.auth_len = auth_len;
297 SILC_FSM_CALL_CONTINUE(fsm);
300 /* Connection authentication completion callback */
302 static void silc_client_connect_auth_completion(SilcConnAuth connauth,
306 SilcFSMThread fsm = context;
307 SilcClientConnection conn = silc_fsm_get_context(fsm);
308 SilcClient client = conn->client;
310 conn->internal->op = NULL;
311 silc_connauth_free(connauth);
314 if (conn->internal->verbose)
315 client->internal->ops->say(
316 client, conn, SILC_CLIENT_MESSAGE_ERROR,
317 "Authentication failed");
319 conn->internal->status = SILC_CLIENT_CONN_ERROR_AUTH;
320 conn->internal->error = SILC_STATUS_ERR_AUTH_FAILED;
321 silc_fsm_next(fsm, silc_client_st_connect_error);
324 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
327 /********************** CONNECTION_AUTH_REQUEST packet **********************/
329 /* Received connection authentication request packet. We get the
330 required authentication method here. */
332 SILC_FSM_STATE(silc_client_connect_auth_request)
334 SilcClientConnection conn = fsm_context;
335 SilcPacket packet = state_context;
336 SilcUInt16 conn_type, auth_meth;
338 if (!conn->internal->auth_request) {
339 silc_packet_free(packet);
340 return SILC_FSM_FINISH;
343 /* Parse the payload */
344 if (silc_buffer_unformat(&packet->buffer,
345 SILC_STR_UI_SHORT(&conn_type),
346 SILC_STR_UI_SHORT(&auth_meth),
348 auth_meth = SILC_AUTH_NONE;
350 silc_packet_free(packet);
352 SILC_LOG_DEBUG(("Resolved authentication method: %s",
353 (auth_meth == SILC_AUTH_NONE ? "none" :
354 auth_meth == SILC_AUTH_PASSWORD ? "passphrase" :
356 conn->internal->params.auth_method = auth_meth;
358 /* Continue authentication */
359 silc_fsm_continue_sync(&conn->internal->event_thread);
360 return SILC_FSM_FINISH;
363 /*************************** Connect remote host ****************************/
365 /* Connection timeout callback */
367 SILC_TASK_CALLBACK(silc_client_connect_timeout)
369 SilcClientConnection conn = context;
371 SILC_LOG_DEBUG(("Connection timeout"));
373 conn->internal->status = SILC_CLIENT_CONN_ERROR_TIMEOUT;
374 conn->internal->error = SILC_STATUS_ERR_TIMEDOUT;
376 silc_fsm_next(&conn->internal->event_thread, silc_client_st_connect_error);
377 silc_fsm_continue_sync(&conn->internal->event_thread);
380 /* Creates a connection to remote host */
382 SILC_FSM_STATE(silc_client_st_connect)
384 SilcClientConnection conn = fsm_context;
386 SILC_LOG_DEBUG(("Connecting to %s:%d", conn->remote_host,
390 silc_fsm_next(fsm, silc_client_st_connect_set_stream);
392 /* Add connection timeout */
393 if (conn->internal->params.timeout_secs)
394 silc_schedule_task_add_timeout(conn->internal->schedule,
395 silc_client_connect_timeout, conn,
396 conn->internal->params.timeout_secs, 0);
398 if (conn->internal->params.udp) {
401 if (!conn->internal->params.local_ip) {
402 /** IP address not given */
403 SILC_LOG_ERROR(("Local UDP IP address not specified"));
404 conn->internal->status = SILC_CLIENT_CONN_ERROR;
405 silc_fsm_next(fsm, silc_client_st_connect_error);
406 return SILC_FSM_CONTINUE;
410 stream = silc_net_udp_connect(conn->internal->params.bind_ip ?
411 conn->internal->params.bind_ip :
412 conn->internal->params.local_ip,
413 conn->internal->params.local_port,
414 conn->remote_host, conn->remote_port,
415 conn->internal->schedule);
417 SILC_FSM_CALL(silc_client_connect_callback(stream ? SILC_OK :
418 SILC_ERR_UNREACHABLE,
422 SILC_FSM_CALL(conn->internal->op = silc_net_tcp_connect(
423 NULL, conn->remote_host,
425 conn->internal->schedule,
426 silc_client_connect_callback, fsm));
430 /* Sets the new connection stream into use and creates packet stream */
432 SILC_FSM_STATE(silc_client_st_connect_set_stream)
434 SilcClientConnection conn = fsm_context;
435 SilcClient client = conn->client;
437 if (conn->internal->disconnected) {
439 silc_fsm_next(fsm, silc_client_st_connect_error);
440 return SILC_FSM_CONTINUE;
443 /* Create packet stream */
444 conn->stream = silc_packet_stream_create(client->internal->packet_engine,
445 conn->internal->schedule,
446 conn->internal->user_stream);
448 /** Cannot create packet stream */
449 SILC_LOG_DEBUG(("Could not create packet stream"));
450 conn->internal->status = SILC_CLIENT_CONN_ERROR;
451 silc_fsm_next(fsm, silc_client_st_connect_error);
452 return SILC_FSM_CONTINUE;
455 silc_packet_set_context(conn->stream, conn);
457 /** Start key exchange */
458 silc_fsm_next(fsm, silc_client_st_connect_key_exchange);
459 return SILC_FSM_CONTINUE;
462 /* Starts key exchange protocol with remote host */
464 SILC_FSM_STATE(silc_client_st_connect_key_exchange)
466 SilcClientConnection conn = fsm_context;
467 SilcClient client = conn->client;
468 SilcSKEParamsStruct params;
471 SILC_LOG_DEBUG(("Starting key exchange protocol"));
474 conn->internal->ske =
475 silc_ske_alloc(client->rng, conn->internal->schedule,
476 conn->internal->params.repository,
477 conn->public_key, conn->private_key, fsm);
478 if (!conn->internal->ske) {
480 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
481 silc_fsm_next(fsm, silc_client_st_connect_error);
482 return SILC_FSM_CONTINUE;
485 /* Set SKE callbacks */
486 silc_ske_set_callbacks(conn->internal->ske, silc_client_ke_verify_key,
487 silc_client_ke_completion, fsm);
489 /* Set up key exchange parameters */
490 params.version = client->internal->silc_client_version;
491 params.timeout_secs = conn->internal->params.timeout_secs;
492 params.flags = SILC_SKE_SP_FLAG_MUTUAL;
493 if (conn->internal->params.pfs)
494 params.flags |= SILC_SKE_SP_FLAG_PFS;
495 if (conn->internal->params.udp) {
496 params.flags |= SILC_SKE_SP_FLAG_IV_INCLUDED;
497 params.session_port = conn->internal->params.local_port;
500 if (conn->internal->params.no_authentication)
501 /** Run key exchange (no auth) */
502 silc_fsm_next(fsm, silc_client_st_connected);
503 else if (conn->internal->params.udp)
504 /** Run key exchange (UDP)*/
505 silc_fsm_next(fsm, silc_client_st_connect_setup_udp);
507 /** Run key exchange (TCP) */
508 silc_fsm_next(fsm, silc_client_st_connect_auth_resolve);
510 /* Old server version requires empty Client ID in packets. Remove this
511 backwards support somepoint after 1.1 server is released. */
512 memset(&cid, 0, sizeof(cid));
514 silc_packet_set_ids(conn->stream, SILC_ID_CLIENT, &cid, 0, NULL);
516 SILC_FSM_CALL(conn->internal->op = silc_ske_initiator(conn->internal->ske,
521 /* For UDP/IP connections, set up the UDP session after successful key
524 SILC_FSM_STATE(silc_client_st_connect_setup_udp)
526 SilcClientConnection conn = fsm_context;
527 SilcStream stream, old;
528 SilcSKESecurityProperties prop;
530 SILC_LOG_DEBUG(("Setup UDP SILC session"));
532 if (conn->internal->disconnected) {
534 silc_fsm_next(fsm, silc_client_st_connect_error);
535 return SILC_FSM_CONTINUE;
538 /* Create new UDP stream */
539 prop = silc_ske_get_security_properties(conn->internal->ske);
540 stream = silc_net_udp_connect(conn->internal->params.local_ip,
541 conn->internal->params.local_port,
542 conn->remote_host, prop->remote_port,
543 conn->internal->schedule);
545 /** Cannot create UDP stream */
546 conn->internal->status = SILC_CLIENT_CONN_ERROR;
547 silc_fsm_next(fsm, silc_client_st_connect_error);
548 return SILC_FSM_CONTINUE;
551 /* Set the new stream to packet stream */
552 old = silc_packet_stream_get_stream(conn->stream);
553 silc_packet_stream_set_stream(conn->stream, stream);
554 silc_packet_stream_set_iv_included(conn->stream);
555 silc_packet_set_sid(conn->stream, 0);
557 /* Delete the old stream */
558 silc_stream_destroy(old);
560 /** Start authentication */
561 silc_fsm_next(fsm, silc_client_st_connect_auth_resolve);
562 return SILC_FSM_CONTINUE;
565 /* Resolve authentication method to be used in authentication protocol */
567 SILC_FSM_STATE(silc_client_st_connect_auth_resolve)
569 SilcClientConnection conn = fsm_context;
571 SILC_LOG_DEBUG(("Resolve authentication method"));
573 if (conn->internal->disconnected) {
575 silc_fsm_next(fsm, silc_client_st_connect_error);
576 return SILC_FSM_CONTINUE;
579 /* If authentication method and data is set, use them */
580 if (conn->internal->params.auth_set) {
581 /** Got authentication data */
582 silc_fsm_next(fsm, silc_client_st_connect_auth_start);
583 return SILC_FSM_CONTINUE;
586 /* Send connection authentication request packet */
587 silc_packet_send_va(conn->stream,
588 SILC_PACKET_CONNECTION_AUTH_REQUEST, 0,
589 SILC_STR_UI_SHORT(SILC_CONN_CLIENT),
590 SILC_STR_UI_SHORT(SILC_AUTH_NONE),
593 /** Wait for authentication method */
594 conn->internal->auth_request = TRUE;
595 conn->internal->params.auth_method = SILC_AUTH_NONE;
596 silc_fsm_next_later(fsm, silc_client_st_connect_auth_data, 2, 0);
597 return SILC_FSM_WAIT;
600 /* Get authentication data to be used in authentication protocol */
602 SILC_FSM_STATE(silc_client_st_connect_auth_data)
604 SilcClientConnection conn = fsm_context;
605 SilcClient client = conn->client;
607 SILC_LOG_DEBUG(("Get authentication data"));
609 if (conn->internal->disconnected) {
611 silc_fsm_next(fsm, silc_client_st_connect_error);
612 return SILC_FSM_CONTINUE;
615 conn->internal->auth_request = FALSE;
617 /** Get authentication data */
618 silc_fsm_next(fsm, silc_client_st_connect_auth_start);
619 SILC_FSM_CALL(client->internal->ops->get_auth_method(
623 conn->internal->params.auth_method,
624 silc_client_connect_auth_method, fsm));
627 /* Start connection authentication with remote host */
629 SILC_FSM_STATE(silc_client_st_connect_auth_start)
631 SilcClientConnection conn = fsm_context;
632 SilcConnAuth connauth;
634 SILC_LOG_DEBUG(("Starting connection authentication protocol"));
636 if (conn->internal->disconnected) {
638 silc_fsm_next(fsm, silc_client_st_connect_error);
639 return SILC_FSM_CONTINUE;
642 /* We always use the same key for connection authentication and SKE */
643 if (conn->internal->params.auth_method == SILC_AUTH_PUBLIC_KEY)
644 conn->internal->params.auth = conn->private_key;
646 /* Allocate connection authentication protocol */
647 connauth = silc_connauth_alloc(conn->internal->schedule,
649 conn->internal->params.rekey_secs);
652 conn->internal->status = SILC_CLIENT_CONN_ERROR_AUTH;
653 conn->internal->error = SILC_STATUS_ERR_AUTH_FAILED;
654 silc_fsm_next(fsm, silc_client_st_connect_error);
655 return SILC_FSM_CONTINUE;
658 /** Start connection authentication */
659 silc_fsm_next(fsm, silc_client_st_connected);
660 SILC_FSM_CALL(conn->internal->op = silc_connauth_initiator(
661 connauth, SILC_CONN_CLIENT,
662 conn->internal->params.auth_method,
663 conn->internal->params.auth,
664 conn->internal->params.auth_len,
665 silc_client_connect_auth_completion,
669 /* Connection fully established */
671 SILC_FSM_STATE(silc_client_st_connected)
673 SilcClientConnection conn = fsm_context;
674 SilcClient client = conn->client;
676 /* Get SILC protocol version remote supports */
677 silc_ske_parse_version(conn->internal->ske, &conn->internal->remote_version,
678 NULL, NULL, NULL, NULL);
680 silc_ske_free(conn->internal->ske);
681 conn->internal->ske = NULL;
683 if (!conn->internal->params.auth_set &&
684 conn->internal->params.auth_method == SILC_AUTH_PASSWORD &&
685 conn->internal->params.auth) {
686 silc_free(conn->internal->params.auth);
687 conn->internal->params.auth = NULL;
690 if (conn->internal->disconnected) {
692 silc_fsm_next(fsm, silc_client_st_connect_error);
693 return SILC_FSM_CONTINUE;
696 SILC_LOG_DEBUG(("Connection established"));
698 /* Install rekey timer */
699 if (conn->type != SILC_CONN_CLIENT)
700 silc_schedule_task_add_timeout(conn->internal->schedule,
701 silc_client_rekey_timer, conn,
702 conn->internal->params.rekey_secs, 0);
704 /* If we connected to server, now register to network. */
705 if (conn->type == SILC_CONN_SERVER &&
706 !conn->internal->params.no_authentication) {
708 /* If detach data is provided, resume the session. */
709 if (conn->internal->params.detach_data &&
710 conn->internal->params.detach_data_len) {
711 /** Resume detached session */
712 silc_fsm_next(fsm, silc_client_st_resume);
714 /** Register to network */
715 silc_fsm_next(fsm, silc_client_st_register);
718 return SILC_FSM_CONTINUE;
721 silc_schedule_task_del_by_all(conn->internal->schedule, 0,
722 silc_client_connect_timeout, conn);
724 /* Call connection callback */
725 conn->callback(client, conn, SILC_CLIENT_CONN_SUCCESS, 0, NULL,
726 conn->callback_context);
728 silc_async_free(conn->internal->cop);
729 conn->internal->cop = NULL;
731 return SILC_FSM_FINISH;
734 /* Error during connecting */
736 SILC_FSM_STATE(silc_client_st_connect_error)
738 SilcClientConnection conn = fsm_context;
740 if (conn->internal->ske) {
741 silc_ske_free(conn->internal->ske);
742 conn->internal->ske = NULL;
745 /* Signal to close connection */
746 if (!conn->internal->disconnected) {
747 conn->internal->disconnected = TRUE;
748 SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
751 silc_schedule_task_del_by_all(conn->internal->schedule, 0,
752 silc_client_connect_timeout, conn);
754 return SILC_FSM_FINISH;
757 /****************************** Connect rekey *******************************/
759 /* Connection rekey timer callback */
761 SILC_TASK_CALLBACK(silc_client_rekey_timer)
763 SilcClientConnection conn = context;
765 /* Signal to start rekey */
766 if (!silc_fsm_is_started(&conn->internal->event_thread)) {
767 conn->internal->rekey_responder = FALSE;
768 conn->internal->rekeying = TRUE;
769 SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
772 /* Reinstall rekey timer */
773 silc_schedule_task_add_timeout(conn->internal->schedule,
774 silc_client_rekey_timer, conn,
775 conn->internal->params.rekey_secs, 0);
780 SILC_FSM_STATE(silc_client_st_rekey)
782 SilcClientConnection conn = fsm_context;
783 SilcClient client = conn->client;
785 SILC_LOG_DEBUG(("Rekey conn %p", conn));
787 if (conn->internal->disconnected)
788 return SILC_FSM_FINISH;
791 conn->internal->ske =
792 silc_ske_alloc(client->rng, conn->internal->schedule, NULL,
793 conn->public_key, NULL, fsm);
794 if (!conn->internal->ske)
795 return SILC_FSM_FINISH;
797 /* Set SKE callbacks */
798 silc_ske_set_callbacks(conn->internal->ske, NULL,
799 silc_client_rekey_completion, fsm);
802 if (!conn->internal->rekey_responder)
803 SILC_FSM_CALL(conn->internal->op = silc_ske_rekey_initiator(
806 conn->internal->rekey));
808 SILC_FSM_CALL(conn->internal->op = silc_ske_rekey_responder(
811 conn->internal->rekey,