5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2006 - 2014 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(SilcNetStatus 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_NET_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_NET_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_NET_HOST_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_NET_CONNECTION_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_NET_CONNECTION_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_NET_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);
266 /* Close connection */
267 silc_client_close_connection(client, conn);
271 silc_ske_free_rekey_material(conn->internal->rekey);
272 conn->internal->rekey = rekey;
274 silc_ske_free(conn->internal->ske);
275 conn->internal->ske = NULL;
277 SILC_LOG_DEBUG(("Rekey completed conn %p", conn));
280 silc_fsm_finish(fsm);
283 /* Callback called by application to return authentication data */
285 static void silc_client_connect_auth_method(SilcAuthMethod auth_meth,
290 SilcFSMThread fsm = context;
291 SilcClientConnection conn = silc_fsm_get_context(fsm);
293 conn->internal->params.auth_method = auth_meth;
294 if (auth_meth == SILC_AUTH_PASSWORD)
295 conn->internal->params.auth = silc_memdup(auth, auth_len);
297 conn->internal->params.auth = (void *)auth;
298 conn->internal->params.auth_len = auth_len;
300 SILC_FSM_CALL_CONTINUE(fsm);
303 /* Connection authentication completion callback */
305 static void silc_client_connect_auth_completion(SilcConnAuth connauth,
309 SilcFSMThread fsm = context;
310 SilcClientConnection conn = silc_fsm_get_context(fsm);
311 SilcClient client = conn->client;
313 conn->internal->op = NULL;
314 silc_connauth_free(connauth);
317 if (conn->internal->verbose)
318 client->internal->ops->say(
319 client, conn, SILC_CLIENT_MESSAGE_ERROR,
320 "Authentication failed");
322 conn->internal->status = SILC_CLIENT_CONN_ERROR_AUTH;
323 conn->internal->error = SILC_STATUS_ERR_AUTH_FAILED;
324 silc_fsm_next(fsm, silc_client_st_connect_error);
327 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
330 /********************** CONNECTION_AUTH_REQUEST packet **********************/
332 /* Received connection authentication request packet. We get the
333 required authentication method here. */
335 SILC_FSM_STATE(silc_client_connect_auth_request)
337 SilcClientConnection conn = fsm_context;
338 SilcPacket packet = state_context;
339 SilcUInt16 conn_type, auth_meth;
341 if (!conn->internal->auth_request) {
342 silc_packet_free(packet);
343 return SILC_FSM_FINISH;
346 /* Parse the payload */
347 if (silc_buffer_unformat(&packet->buffer,
348 SILC_STR_UI_SHORT(&conn_type),
349 SILC_STR_UI_SHORT(&auth_meth),
351 auth_meth = SILC_AUTH_NONE;
353 silc_packet_free(packet);
355 SILC_LOG_DEBUG(("Resolved authentication method: %s",
356 (auth_meth == SILC_AUTH_NONE ? "none" :
357 auth_meth == SILC_AUTH_PASSWORD ? "passphrase" :
359 conn->internal->params.auth_method = auth_meth;
361 /* Continue authentication */
362 silc_fsm_continue_sync(&conn->internal->event_thread);
363 return SILC_FSM_FINISH;
366 /*************************** Connect remote host ****************************/
368 /* Connection timeout callback */
370 SILC_TASK_CALLBACK(silc_client_connect_timeout)
372 SilcClientConnection conn = context;
374 SILC_LOG_DEBUG(("Connection timeout"));
376 conn->internal->status = SILC_CLIENT_CONN_ERROR_TIMEOUT;
377 conn->internal->error = SILC_STATUS_ERR_TIMEDOUT;
379 silc_fsm_next(&conn->internal->event_thread, silc_client_st_connect_error);
380 silc_fsm_continue_sync(&conn->internal->event_thread);
383 /* Creates a connection to remote host */
385 SILC_FSM_STATE(silc_client_st_connect)
387 SilcClientConnection conn = fsm_context;
389 SILC_LOG_DEBUG(("Connecting to %s:%d", conn->remote_host,
393 silc_fsm_next(fsm, silc_client_st_connect_set_stream);
395 /* Add connection timeout */
396 if (conn->internal->params.timeout_secs)
397 silc_schedule_task_add_timeout(conn->internal->schedule,
398 silc_client_connect_timeout, conn,
399 conn->internal->params.timeout_secs, 0);
401 if (conn->internal->params.udp) {
404 if (!conn->internal->params.local_ip) {
405 /** IP address not given */
406 SILC_LOG_ERROR(("Local UDP IP address not specified"));
407 conn->internal->status = SILC_CLIENT_CONN_ERROR;
408 silc_fsm_next(fsm, silc_client_st_connect_error);
409 return SILC_FSM_CONTINUE;
413 stream = silc_net_udp_connect(conn->internal->params.bind_ip ?
414 conn->internal->params.bind_ip :
415 conn->internal->params.local_ip,
416 conn->internal->params.local_port,
417 conn->remote_host, conn->remote_port,
418 conn->internal->schedule);
420 SILC_FSM_CALL(silc_client_connect_callback(stream ? SILC_NET_OK :
421 SILC_NET_HOST_UNREACHABLE,
425 SILC_FSM_CALL(conn->internal->op = silc_net_tcp_connect(
426 NULL, conn->remote_host,
428 conn->internal->schedule,
429 silc_client_connect_callback, fsm));
433 /* Sets the new connection stream into use and creates packet stream */
435 SILC_FSM_STATE(silc_client_st_connect_set_stream)
437 SilcClientConnection conn = fsm_context;
438 SilcClient client = conn->client;
440 if (conn->internal->disconnected) {
442 silc_fsm_next(fsm, silc_client_st_connect_error);
443 return SILC_FSM_CONTINUE;
446 /* Create packet stream */
447 conn->stream = silc_packet_stream_create(client->internal->packet_engine,
448 conn->internal->schedule,
449 conn->internal->user_stream);
451 /** Cannot create packet stream */
452 SILC_LOG_DEBUG(("Could not create packet stream"));
453 conn->internal->status = SILC_CLIENT_CONN_ERROR;
454 silc_fsm_next(fsm, silc_client_st_connect_error);
455 return SILC_FSM_CONTINUE;
458 silc_packet_set_context(conn->stream, conn);
460 /** Start key exchange */
461 silc_fsm_next(fsm, silc_client_st_connect_key_exchange);
462 return SILC_FSM_CONTINUE;
465 /* Starts key exchange protocol with remote host */
467 SILC_FSM_STATE(silc_client_st_connect_key_exchange)
469 SilcClientConnection conn = fsm_context;
470 SilcClient client = conn->client;
471 SilcSKEParamsStruct params = {};
473 SILC_LOG_DEBUG(("Starting key exchange protocol"));
476 conn->internal->ske =
477 silc_ske_alloc(client->rng, conn->internal->schedule,
478 conn->internal->params.repository,
479 conn->public_key, conn->private_key, fsm);
480 if (!conn->internal->ske) {
482 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
483 silc_fsm_next(fsm, silc_client_st_connect_error);
484 return SILC_FSM_CONTINUE;
487 /* Set SKE callbacks */
488 silc_ske_set_callbacks(conn->internal->ske, silc_client_ke_verify_key,
489 silc_client_ke_completion, fsm);
491 /* Set up key exchange parameters */
492 params.version = client->internal->silc_client_version;
493 params.timeout_secs = conn->internal->params.timeout_secs;
494 params.flags = SILC_SKE_SP_FLAG_MUTUAL;
495 if (conn->internal->params.pfs)
496 params.flags |= SILC_SKE_SP_FLAG_PFS;
497 if (conn->internal->params.udp) {
498 params.flags |= SILC_SKE_SP_FLAG_IV_INCLUDED;
499 params.session_port = conn->internal->params.local_port;
502 if (conn->internal->params.no_authentication)
503 /** Run key exchange (no auth) */
504 silc_fsm_next(fsm, silc_client_st_connected);
505 else if (conn->internal->params.udp)
506 /** Run key exchange (UDP)*/
507 silc_fsm_next(fsm, silc_client_st_connect_setup_udp);
509 /** Run key exchange (TCP) */
510 silc_fsm_next(fsm, silc_client_st_connect_auth_resolve);
512 SILC_FSM_CALL(conn->internal->op = silc_ske_initiator(conn->internal->ske,
517 /* For UDP/IP connections, set up the UDP session after successful key
520 SILC_FSM_STATE(silc_client_st_connect_setup_udp)
522 SilcClientConnection conn = fsm_context;
523 SilcStream stream, old;
524 SilcSKESecurityProperties prop;
526 SILC_LOG_DEBUG(("Setup UDP SILC session"));
528 if (conn->internal->disconnected) {
530 silc_fsm_next(fsm, silc_client_st_connect_error);
531 return SILC_FSM_CONTINUE;
534 /* Create new UDP stream */
535 prop = silc_ske_get_security_properties(conn->internal->ske);
536 stream = silc_net_udp_connect(conn->internal->params.local_ip,
537 conn->internal->params.local_port,
538 conn->remote_host, prop->remote_port,
539 conn->internal->schedule);
541 /** Cannot create UDP stream */
542 conn->internal->status = SILC_CLIENT_CONN_ERROR;
543 silc_fsm_next(fsm, silc_client_st_connect_error);
544 return SILC_FSM_CONTINUE;
547 /* Set the new stream to packet stream */
548 old = silc_packet_stream_get_stream(conn->stream);
549 silc_packet_stream_set_stream(conn->stream, stream);
550 silc_packet_stream_set_iv_included(conn->stream);
551 silc_packet_set_sid(conn->stream, 0);
553 /* Delete the old stream */
554 silc_stream_destroy(old);
556 /** Start authentication */
557 silc_fsm_next(fsm, silc_client_st_connect_auth_resolve);
558 return SILC_FSM_CONTINUE;
561 /* Resolve authentication method to be used in authentication protocol */
563 SILC_FSM_STATE(silc_client_st_connect_auth_resolve)
565 SilcClientConnection conn = fsm_context;
567 SILC_LOG_DEBUG(("Resolve authentication method"));
569 if (conn->internal->disconnected) {
571 silc_fsm_next(fsm, silc_client_st_connect_error);
572 return SILC_FSM_CONTINUE;
575 /* If authentication method and data is set, use them */
576 if (conn->internal->params.auth_set) {
577 /** Got authentication data */
578 silc_fsm_next(fsm, silc_client_st_connect_auth_start);
579 return SILC_FSM_CONTINUE;
582 /* Send connection authentication request packet */
583 silc_packet_send_va(conn->stream,
584 SILC_PACKET_CONNECTION_AUTH_REQUEST, 0,
585 SILC_STR_UI_SHORT(SILC_CONN_CLIENT),
586 SILC_STR_UI_SHORT(SILC_AUTH_NONE),
589 /** Wait for authentication method */
590 conn->internal->auth_request = TRUE;
591 conn->internal->params.auth_method = SILC_AUTH_NONE;
592 silc_fsm_next_later(fsm, silc_client_st_connect_auth_data, 2, 0);
593 return SILC_FSM_WAIT;
596 /* Get authentication data to be used in authentication protocol */
598 SILC_FSM_STATE(silc_client_st_connect_auth_data)
600 SilcClientConnection conn = fsm_context;
601 SilcClient client = conn->client;
603 SILC_LOG_DEBUG(("Get authentication data"));
605 if (conn->internal->disconnected) {
607 silc_fsm_next(fsm, silc_client_st_connect_error);
608 return SILC_FSM_CONTINUE;
611 conn->internal->auth_request = FALSE;
613 /** Get authentication data */
614 silc_fsm_next(fsm, silc_client_st_connect_auth_start);
615 SILC_FSM_CALL(client->internal->ops->get_auth_method(
619 conn->internal->params.auth_method,
620 silc_client_connect_auth_method, fsm));
623 /* Start connection authentication with remote host */
625 SILC_FSM_STATE(silc_client_st_connect_auth_start)
627 SilcClientConnection conn = fsm_context;
628 SilcConnAuth connauth;
630 SILC_LOG_DEBUG(("Starting connection authentication protocol"));
632 if (conn->internal->disconnected) {
634 silc_fsm_next(fsm, silc_client_st_connect_error);
635 return SILC_FSM_CONTINUE;
638 /* We always use the same key for connection authentication and SKE */
639 if (conn->internal->params.auth_method == SILC_AUTH_PUBLIC_KEY)
640 conn->internal->params.auth = conn->private_key;
642 /* Allocate connection authentication protocol */
643 connauth = silc_connauth_alloc(conn->internal->schedule,
645 conn->internal->params.rekey_secs);
648 conn->internal->status = SILC_CLIENT_CONN_ERROR_AUTH;
649 conn->internal->error = SILC_STATUS_ERR_AUTH_FAILED;
650 silc_fsm_next(fsm, silc_client_st_connect_error);
651 return SILC_FSM_CONTINUE;
654 /** Start connection authentication */
655 silc_fsm_next(fsm, silc_client_st_connected);
656 SILC_FSM_CALL(conn->internal->op = silc_connauth_initiator(
657 connauth, SILC_CONN_CLIENT,
658 conn->internal->params.auth_method,
659 conn->internal->params.auth,
660 conn->internal->params.auth_len,
661 silc_client_connect_auth_completion,
665 /* Connection fully established */
667 SILC_FSM_STATE(silc_client_st_connected)
669 SilcClientConnection conn = fsm_context;
670 SilcClient client = conn->client;
672 /* Get SILC protocol version remote supports */
673 silc_ske_parse_version(conn->internal->ske, &conn->internal->remote_version,
674 NULL, NULL, NULL, NULL);
676 silc_ske_free(conn->internal->ske);
677 conn->internal->ske = NULL;
679 if (!conn->internal->params.auth_set &&
680 conn->internal->params.auth_method == SILC_AUTH_PASSWORD &&
681 conn->internal->params.auth) {
682 silc_free(conn->internal->params.auth);
683 conn->internal->params.auth = NULL;
686 if (conn->internal->disconnected) {
688 silc_fsm_next(fsm, silc_client_st_connect_error);
689 return SILC_FSM_CONTINUE;
692 SILC_LOG_DEBUG(("Connection established"));
694 /* Install rekey timer */
695 if (conn->type != SILC_CONN_CLIENT)
696 silc_schedule_task_add_timeout(conn->internal->schedule,
697 silc_client_rekey_timer, conn,
698 conn->internal->params.rekey_secs, 0);
700 /* If we connected to server, now register to network. */
701 if (conn->type == SILC_CONN_SERVER &&
702 !conn->internal->params.no_authentication) {
704 /* If detach data is provided, resume the session. */
705 if (conn->internal->params.detach_data &&
706 conn->internal->params.detach_data_len) {
707 /** Resume detached session */
708 silc_fsm_next(fsm, silc_client_st_resume);
710 /** Register to network */
711 silc_fsm_next(fsm, silc_client_st_register);
714 return SILC_FSM_CONTINUE;
717 silc_schedule_task_del_by_all(conn->internal->schedule, 0,
718 silc_client_connect_timeout, conn);
720 /* Call connection callback */
721 conn->callback(client, conn, SILC_CLIENT_CONN_SUCCESS, 0, NULL,
722 conn->callback_context);
724 silc_async_free(conn->internal->cop);
725 conn->internal->cop = NULL;
727 return SILC_FSM_FINISH;
730 /* Error during connecting */
732 SILC_FSM_STATE(silc_client_st_connect_error)
734 SilcClientConnection conn = fsm_context;
736 if (conn->internal->ske) {
737 silc_ske_free(conn->internal->ske);
738 conn->internal->ske = NULL;
741 /* Signal to close connection */
742 if (!conn->internal->disconnected) {
743 conn->internal->disconnected = TRUE;
744 SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
747 silc_schedule_task_del_by_all(conn->internal->schedule, 0,
748 silc_client_connect_timeout, conn);
750 return SILC_FSM_FINISH;
753 /****************************** Connect rekey *******************************/
755 /* Connection rekey timer callback */
757 SILC_TASK_CALLBACK(silc_client_rekey_timer)
759 SilcClientConnection conn = context;
761 /* Signal to start rekey */
762 if (!silc_fsm_is_started(&conn->internal->event_thread)) {
763 conn->internal->rekey_responder = FALSE;
764 conn->internal->rekeying = TRUE;
765 SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
768 /* Reinstall rekey timer */
769 silc_schedule_task_add_timeout(conn->internal->schedule,
770 silc_client_rekey_timer, conn,
771 conn->internal->params.rekey_secs, 0);
776 SILC_FSM_STATE(silc_client_st_rekey)
778 SilcClientConnection conn = fsm_context;
779 SilcClient client = conn->client;
781 SILC_LOG_DEBUG(("Rekey conn %p", conn));
783 if (conn->internal->disconnected)
784 return SILC_FSM_FINISH;
787 conn->internal->ske =
788 silc_ske_alloc(client->rng, conn->internal->schedule, NULL,
789 conn->public_key, NULL, fsm);
790 if (!conn->internal->ske)
791 return SILC_FSM_FINISH;
793 /* Set SKE callbacks */
794 silc_ske_set_callbacks(conn->internal->ske, NULL,
795 silc_client_rekey_completion, fsm);
798 if (!conn->internal->rekey_responder)
799 SILC_FSM_CALL(conn->internal->op = silc_ske_rekey_initiator(
802 conn->internal->rekey));
804 SILC_FSM_CALL(conn->internal->op = silc_ske_rekey_responder(
807 conn->internal->rekey,