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(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 conn->internal->error = status;
180 silc_ske_free_rekey_material(rekey);
182 silc_fsm_next(fsm, silc_client_st_connect_error);
183 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
187 SILC_LOG_DEBUG(("Setting keys into use"));
189 /* Allocate the cipher and HMAC contexts */
190 if (!silc_ske_set_keys(ske, keymat, prop, &send_key, &receive_key,
191 &hmac_send, &hmac_receive, &conn->internal->hash)) {
192 /* Error setting keys */
193 SILC_LOG_DEBUG(("Could not set keys into use"));
195 if (conn->internal->verbose)
196 client->internal->ops->say(
197 client, conn, SILC_CLIENT_MESSAGE_ERROR,
198 "Error during key exchange with %s: cannot use keys",
201 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
202 silc_ske_free_rekey_material(rekey);
204 silc_fsm_next(fsm, silc_client_st_connect_error);
205 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
209 /* Set the keys into the packet stream. After this call packets will be
210 encrypted with these keys. */
211 if (!silc_packet_set_keys(conn->stream, send_key, receive_key, hmac_send,
212 hmac_receive, FALSE)) {
213 /* Error setting keys */
214 SILC_LOG_DEBUG(("Could not set keys into use"));
216 if (conn->internal->verbose)
217 client->internal->ops->say(
218 client, conn, SILC_CLIENT_MESSAGE_ERROR,
219 "Error during key exchange with %s: cannot use keys",
222 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
223 silc_ske_free_rekey_material(rekey);
225 silc_fsm_next(fsm, silc_client_st_connect_error);
226 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
230 conn->internal->rekey = rekey;
232 SILC_LOG_DEBUG(("Key Exchange completed"));
234 /* Key exchange done */
235 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
238 /* Rekey protocol completion callback */
240 static void silc_client_rekey_completion(SilcSKE ske,
241 SilcSKEStatus status,
242 SilcSKESecurityProperties prop,
243 SilcSKEKeyMaterial keymat,
244 SilcSKERekeyMaterial rekey,
247 SilcFSMThread fsm = context;
248 SilcClientConnection conn = silc_fsm_get_context(fsm);
249 SilcClient client = conn->client;
251 conn->internal->op = NULL;
252 if (status != SILC_SKE_STATUS_OK) {
254 SILC_LOG_DEBUG(("Error during rekey with %s: %s (%d)",
255 conn->remote_host, silc_ske_map_status(status), status));
257 if (conn->internal->verbose)
258 client->internal->ops->say(client, conn, SILC_CLIENT_MESSAGE_ERROR,
259 "Error during rekey with %s: %s",
261 silc_ske_map_status(status));
263 silc_ske_free(conn->internal->ske);
264 conn->internal->ske = NULL;
265 silc_fsm_finish(fsm);
269 silc_ske_free_rekey_material(conn->internal->rekey);
270 conn->internal->rekey = rekey;
272 silc_ske_free(conn->internal->ske);
273 conn->internal->ske = NULL;
275 SILC_LOG_DEBUG(("Rekey completed conn %p", conn));
278 silc_fsm_finish(fsm);
281 /* Callback called by application to return authentication data */
283 static void silc_client_connect_auth_method(SilcAuthMethod auth_meth,
284 void *auth, SilcUInt32 auth_len,
287 SilcFSMThread fsm = context;
288 SilcClientConnection conn = silc_fsm_get_context(fsm);
290 conn->internal->params.auth_method = auth_meth;
291 conn->internal->params.auth = auth;
292 conn->internal->params.auth_len = auth_len;
294 SILC_FSM_CALL_CONTINUE(fsm);
297 /* Connection authentication completion callback */
299 static void silc_client_connect_auth_completion(SilcConnAuth connauth,
303 SilcFSMThread fsm = context;
304 SilcClientConnection conn = silc_fsm_get_context(fsm);
305 SilcClient client = conn->client;
307 conn->internal->op = NULL;
308 silc_connauth_free(connauth);
311 if (conn->internal->verbose)
312 client->internal->ops->say(
313 client, conn, SILC_CLIENT_MESSAGE_ERROR,
314 "Authentication failed");
316 conn->internal->status = SILC_CLIENT_CONN_ERROR_AUTH;
317 conn->internal->error = SILC_STATUS_ERR_AUTH_FAILED;
318 silc_fsm_next(fsm, silc_client_st_connect_error);
321 SILC_FSM_CALL_CONTINUE_SYNC(fsm);
324 /********************** CONNECTION_AUTH_REQUEST packet **********************/
326 /* Received connection authentication request packet. We get the
327 required authentication method here. */
329 SILC_FSM_STATE(silc_client_connect_auth_request)
331 SilcClientConnection conn = fsm_context;
332 SilcPacket packet = state_context;
333 SilcUInt16 conn_type, auth_meth;
335 if (!conn->internal->auth_request) {
336 silc_packet_free(packet);
337 return SILC_FSM_FINISH;
340 /* Parse the payload */
341 if (silc_buffer_unformat(&packet->buffer,
342 SILC_STR_UI_SHORT(&conn_type),
343 SILC_STR_UI_SHORT(&auth_meth),
345 auth_meth = SILC_AUTH_NONE;
347 silc_packet_free(packet);
349 SILC_LOG_DEBUG(("Resolved authentication method: %s",
350 (auth_meth == SILC_AUTH_NONE ? "none" :
351 auth_meth == SILC_AUTH_PASSWORD ? "passphrase" :
353 conn->internal->params.auth_method = auth_meth;
355 /* Continue authentication */
356 silc_fsm_continue_sync(&conn->internal->event_thread);
357 return SILC_FSM_FINISH;
360 /*************************** Connect remote host ****************************/
362 /* Connection timeout callback */
364 SILC_TASK_CALLBACK(silc_client_connect_timeout)
366 SilcClientConnection conn = context;
368 SILC_LOG_DEBUG(("Connection timeout"));
370 conn->internal->status = SILC_CLIENT_CONN_ERROR_TIMEOUT;
371 conn->internal->error = SILC_STATUS_ERR_TIMEDOUT;
373 silc_fsm_next(&conn->internal->event_thread, silc_client_st_connect_error);
374 silc_fsm_continue_sync(&conn->internal->event_thread);
377 /* Creates a connection to remote host */
379 SILC_FSM_STATE(silc_client_st_connect)
381 SilcClientConnection conn = fsm_context;
383 SILC_LOG_DEBUG(("Connecting to %s:%d", conn->remote_host,
387 silc_fsm_next(fsm, silc_client_st_connect_set_stream);
389 /* Add connection timeout */
390 if (conn->internal->params.timeout_secs)
391 silc_schedule_task_add_timeout(conn->internal->schedule,
392 silc_client_connect_timeout, conn,
393 conn->internal->params.timeout_secs, 0);
395 if (conn->internal->params.udp) {
398 if (!conn->internal->params.local_ip) {
399 /** IP address not given */
400 SILC_LOG_ERROR(("Local UDP IP address not specified"));
401 conn->internal->status = SILC_CLIENT_CONN_ERROR;
402 silc_fsm_next(fsm, silc_client_st_connect_error);
403 return SILC_FSM_CONTINUE;
407 stream = silc_net_udp_connect(conn->internal->params.bind_ip ?
408 conn->internal->params.bind_ip :
409 conn->internal->params.local_ip,
410 conn->internal->params.local_port,
411 conn->remote_host, conn->remote_port,
412 conn->internal->schedule);
414 SILC_FSM_CALL(silc_client_connect_callback(stream ? SILC_NET_OK :
415 SILC_NET_HOST_UNREACHABLE,
419 SILC_FSM_CALL(conn->internal->op = silc_net_tcp_connect(
420 NULL, conn->remote_host,
422 conn->internal->schedule,
423 silc_client_connect_callback, fsm));
427 /* Sets the new connection stream into use and creates packet stream */
429 SILC_FSM_STATE(silc_client_st_connect_set_stream)
431 SilcClientConnection conn = fsm_context;
432 SilcClient client = conn->client;
434 if (conn->internal->disconnected) {
436 silc_fsm_next(fsm, silc_client_st_connect_error);
437 return SILC_FSM_CONTINUE;
440 /* Create packet stream */
441 conn->stream = silc_packet_stream_create(client->internal->packet_engine,
442 conn->internal->schedule,
443 conn->internal->user_stream);
445 /** Cannot create packet stream */
446 SILC_LOG_DEBUG(("Could not create packet stream"));
447 conn->internal->status = SILC_CLIENT_CONN_ERROR;
448 silc_fsm_next(fsm, silc_client_st_connect_error);
449 return SILC_FSM_CONTINUE;
452 silc_packet_set_context(conn->stream, conn);
454 /** Start key exchange */
455 silc_fsm_next(fsm, silc_client_st_connect_key_exchange);
456 return SILC_FSM_CONTINUE;
459 /* Starts key exchange protocol with remote host */
461 SILC_FSM_STATE(silc_client_st_connect_key_exchange)
463 SilcClientConnection conn = fsm_context;
464 SilcClient client = conn->client;
465 SilcSKEParamsStruct params;
468 SILC_LOG_DEBUG(("Starting key exchange protocol"));
471 conn->internal->ske =
472 silc_ske_alloc(client->rng, conn->internal->schedule,
473 conn->internal->params.repository,
474 conn->public_key, conn->private_key, fsm);
475 if (!conn->internal->ske) {
477 conn->internal->status = SILC_CLIENT_CONN_ERROR_KE;
478 silc_fsm_next(fsm, silc_client_st_connect_error);
479 return SILC_FSM_CONTINUE;
482 /* Set SKE callbacks */
483 silc_ske_set_callbacks(conn->internal->ske, silc_client_ke_verify_key,
484 silc_client_ke_completion, fsm);
486 /* Set up key exchange parameters */
487 params.version = client->internal->silc_client_version;
488 params.timeout_secs = conn->internal->params.timeout_secs;
489 params.flags = SILC_SKE_SP_FLAG_MUTUAL;
490 if (conn->internal->params.pfs)
491 params.flags |= SILC_SKE_SP_FLAG_PFS;
492 if (conn->internal->params.udp) {
493 params.flags |= SILC_SKE_SP_FLAG_IV_INCLUDED;
494 params.session_port = conn->internal->params.local_port;
497 if (conn->internal->params.no_authentication)
498 /** Run key exchange (no auth) */
499 silc_fsm_next(fsm, silc_client_st_connected);
500 else if (conn->internal->params.udp)
501 /** Run key exchange (UDP)*/
502 silc_fsm_next(fsm, silc_client_st_connect_setup_udp);
504 /** Run key exchange (TCP) */
505 silc_fsm_next(fsm, silc_client_st_connect_auth_resolve);
507 /* Old server version requires empty Client ID in packets. Remove this
508 backwards support somepoint after 1.1 server is released. */
509 memset(&cid, 0, sizeof(cid));
511 silc_packet_set_ids(conn->stream, SILC_ID_CLIENT, &cid, 0, NULL);
513 SILC_FSM_CALL(conn->internal->op = silc_ske_initiator(conn->internal->ske,
518 /* For UDP/IP connections, set up the UDP session after successful key
521 SILC_FSM_STATE(silc_client_st_connect_setup_udp)
523 SilcClientConnection conn = fsm_context;
524 SilcStream stream, old;
525 SilcSKESecurityProperties prop;
527 SILC_LOG_DEBUG(("Setup UDP SILC session"));
529 if (conn->internal->disconnected) {
531 silc_fsm_next(fsm, silc_client_st_connect_error);
532 return SILC_FSM_CONTINUE;
535 /* Create new UDP stream */
536 prop = silc_ske_get_security_properties(conn->internal->ske);
537 stream = silc_net_udp_connect(conn->internal->params.local_ip,
538 conn->internal->params.local_port,
539 conn->remote_host, prop->remote_port,
540 conn->internal->schedule);
542 /** Cannot create UDP stream */
543 conn->internal->status = SILC_CLIENT_CONN_ERROR;
544 silc_fsm_next(fsm, silc_client_st_connect_error);
545 return SILC_FSM_CONTINUE;
548 /* Set the new stream to packet stream */
549 old = silc_packet_stream_get_stream(conn->stream);
550 silc_packet_stream_set_stream(conn->stream, stream);
551 silc_packet_stream_set_iv_included(conn->stream);
552 silc_packet_set_sid(conn->stream, 0);
554 /* Delete the old stream */
555 silc_stream_destroy(old);
557 /** Start authentication */
558 silc_fsm_next(fsm, silc_client_st_connect_auth_resolve);
559 return SILC_FSM_CONTINUE;
562 /* Resolve authentication method to be used in authentication protocol */
564 SILC_FSM_STATE(silc_client_st_connect_auth_resolve)
566 SilcClientConnection conn = fsm_context;
568 SILC_LOG_DEBUG(("Resolve authentication method"));
570 if (conn->internal->disconnected) {
572 silc_fsm_next(fsm, silc_client_st_connect_error);
573 return SILC_FSM_CONTINUE;
576 /* If authentication method and data is set, use them */
577 if (conn->internal->params.auth_set) {
578 /** Got authentication data */
579 silc_fsm_next(fsm, silc_client_st_connect_auth_start);
580 return SILC_FSM_CONTINUE;
583 /* Send connection authentication request packet */
584 silc_packet_send_va(conn->stream,
585 SILC_PACKET_CONNECTION_AUTH_REQUEST, 0,
586 SILC_STR_UI_SHORT(SILC_CONN_CLIENT),
587 SILC_STR_UI_SHORT(SILC_AUTH_NONE),
590 /** Wait for authentication method */
591 conn->internal->auth_request = TRUE;
592 conn->internal->params.auth_method = SILC_AUTH_NONE;
593 silc_fsm_next_later(fsm, silc_client_st_connect_auth_data, 2, 0);
594 return SILC_FSM_WAIT;
597 /* Get authentication data to be used in authentication protocol */
599 SILC_FSM_STATE(silc_client_st_connect_auth_data)
601 SilcClientConnection conn = fsm_context;
602 SilcClient client = conn->client;
604 SILC_LOG_DEBUG(("Get authentication data"));
606 if (conn->internal->disconnected) {
608 silc_fsm_next(fsm, silc_client_st_connect_error);
609 return SILC_FSM_CONTINUE;
612 conn->internal->auth_request = FALSE;
614 /** Get authentication data */
615 silc_fsm_next(fsm, silc_client_st_connect_auth_start);
616 SILC_FSM_CALL(client->internal->ops->get_auth_method(
620 conn->internal->params.auth_method,
621 silc_client_connect_auth_method, fsm));
624 /* Start connection authentication with remote host */
626 SILC_FSM_STATE(silc_client_st_connect_auth_start)
628 SilcClientConnection conn = fsm_context;
629 SilcConnAuth connauth;
631 SILC_LOG_DEBUG(("Starting connection authentication protocol"));
633 if (conn->internal->disconnected) {
635 silc_fsm_next(fsm, silc_client_st_connect_error);
636 return SILC_FSM_CONTINUE;
639 /* We always use the same key for connection authentication and SKE */
640 if (conn->internal->params.auth_method == SILC_AUTH_PUBLIC_KEY)
641 conn->internal->params.auth = conn->private_key;
643 /* Allocate connection authentication protocol */
644 connauth = silc_connauth_alloc(conn->internal->schedule,
646 conn->internal->params.rekey_secs);
649 conn->internal->status = SILC_CLIENT_CONN_ERROR_AUTH;
650 conn->internal->error = SILC_STATUS_ERR_AUTH_FAILED;
651 silc_fsm_next(fsm, silc_client_st_connect_error);
652 return SILC_FSM_CONTINUE;
655 /** Start connection authentication */
656 silc_fsm_next(fsm, silc_client_st_connected);
657 SILC_FSM_CALL(conn->internal->op = silc_connauth_initiator(
658 connauth, SILC_CONN_CLIENT,
659 conn->internal->params.auth_method,
660 conn->internal->params.auth,
661 conn->internal->params.auth_len,
662 silc_client_connect_auth_completion,
666 /* Connection fully established */
668 SILC_FSM_STATE(silc_client_st_connected)
670 SilcClientConnection conn = fsm_context;
671 SilcClient client = conn->client;
673 /* Get SILC protocol version remote supports */
674 silc_ske_parse_version(conn->internal->ske, &conn->internal->remote_version,
675 NULL, NULL, NULL, NULL);
677 silc_ske_free(conn->internal->ske);
678 conn->internal->ske = NULL;
680 if (conn->internal->disconnected) {
682 silc_fsm_next(fsm, silc_client_st_connect_error);
683 return SILC_FSM_CONTINUE;
686 SILC_LOG_DEBUG(("Connection established"));
688 /* Install rekey timer */
689 if (conn->type != SILC_CONN_CLIENT)
690 silc_schedule_task_add_timeout(conn->internal->schedule,
691 silc_client_rekey_timer, conn,
692 conn->internal->params.rekey_secs, 0);
694 /* If we connected to server, now register to network. */
695 if (conn->type == SILC_CONN_SERVER &&
696 !conn->internal->params.no_authentication) {
698 /* If detach data is provided, resume the session. */
699 if (conn->internal->params.detach_data &&
700 conn->internal->params.detach_data_len) {
701 /** Resume detached session */
702 silc_fsm_next(fsm, silc_client_st_resume);
704 /** Register to network */
705 silc_fsm_next(fsm, silc_client_st_register);
708 return SILC_FSM_CONTINUE;
711 silc_schedule_task_del_by_all(conn->internal->schedule, 0,
712 silc_client_connect_timeout, conn);
714 /* Call connection callback */
715 conn->callback(client, conn, SILC_CLIENT_CONN_SUCCESS, 0, NULL,
716 conn->callback_context);
718 silc_async_free(conn->internal->cop);
719 conn->internal->cop = NULL;
721 return SILC_FSM_FINISH;
724 /* Error during connecting */
726 SILC_FSM_STATE(silc_client_st_connect_error)
728 SilcClientConnection conn = fsm_context;
730 if (conn->internal->ske) {
731 silc_ske_free(conn->internal->ske);
732 conn->internal->ske = NULL;
735 /* Signal to close connection */
736 if (!conn->internal->disconnected) {
737 conn->internal->disconnected = TRUE;
738 SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
741 silc_schedule_task_del_by_all(conn->internal->schedule, 0,
742 silc_client_connect_timeout, conn);
744 return SILC_FSM_FINISH;
747 /****************************** Connect rekey *******************************/
749 /* Connection rekey timer callback */
751 SILC_TASK_CALLBACK(silc_client_rekey_timer)
753 SilcClientConnection conn = context;
755 /* Signal to start rekey */
756 if (!silc_fsm_is_started(&conn->internal->event_thread)) {
757 conn->internal->rekey_responder = FALSE;
758 conn->internal->rekeying = TRUE;
759 SILC_FSM_EVENT_SIGNAL(&conn->internal->wait_event);
762 /* Reinstall rekey timer */
763 silc_schedule_task_add_timeout(conn->internal->schedule,
764 silc_client_rekey_timer, conn,
765 conn->internal->params.rekey_secs, 0);
770 SILC_FSM_STATE(silc_client_st_rekey)
772 SilcClientConnection conn = fsm_context;
773 SilcClient client = conn->client;
775 SILC_LOG_DEBUG(("Rekey conn %p", conn));
777 if (conn->internal->disconnected)
778 return SILC_FSM_FINISH;
781 conn->internal->ske =
782 silc_ske_alloc(client->rng, conn->internal->schedule,
783 conn->internal->params.repository,
784 conn->public_key, conn->private_key, fsm);
785 if (!conn->internal->ske)
786 return SILC_FSM_FINISH;
788 /* Set SKE callbacks */
789 silc_ske_set_callbacks(conn->internal->ske, NULL,
790 silc_client_rekey_completion, fsm);
793 if (!conn->internal->rekey_responder)
794 SILC_FSM_CALL(conn->internal->op = silc_ske_rekey_initiator(
797 conn->internal->rekey));
799 SILC_FSM_CALL(conn->internal->op = silc_ske_rekey_responder(
802 conn->internal->rekey,