5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 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; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 * Server side of the protocols.
26 * Revision 1.6 2000/07/12 05:59:41 priikone
27 * Major rewrite of ID Cache system. Support added for the new
28 * ID cache system. Major rewrite of ID List stuff on server. All
29 * SilcXXXList's are now called SilcXXXEntry's and they are pointers
30 * by default. A lot rewritten ID list functions.
32 * Revision 1.5 2000/07/10 05:42:14 priikone
33 * Support for public key encoding functions added.
35 * Revision 1.4 2000/07/07 06:55:59 priikone
36 * Added SILC style public key support and made server to use
39 * Revision 1.3 2000/07/06 07:15:31 priikone
40 * Cleaner code fro password and public key authentication.
41 * Deprecated old `channel_auth' protocol.
43 * Revision 1.2 2000/07/05 06:13:04 priikone
44 * Support for SILC style public keys added.
46 * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
47 * Imported from internal CVS/Added Log headers.
52 #include "serverincludes.h"
53 #include "server_internal.h"
55 SILC_TASK_CALLBACK(silc_server_protocol_connection_auth);
56 SILC_TASK_CALLBACK(silc_server_protocol_key_exchange);
58 /* SILC client protocol list */
59 const SilcProtocolObject silc_protocol_list[] =
61 { SILC_PROTOCOL_SERVER_CONNECTION_AUTH,
62 silc_server_protocol_connection_auth },
63 { SILC_PROTOCOL_SERVER_KEY_EXCHANGE,
64 silc_server_protocol_key_exchange },
66 { SILC_PROTOCOL_SERVER_NONE, NULL },
70 * Key Exhange protocol functions
73 /* Packet sending callback. This function is provided as packet sending
74 routine to the Key Exchange functions. */
76 static void silc_server_protocol_ke_send_packet(SilcSKE ske,
81 SilcProtocol protocol = (SilcProtocol)context;
82 SilcServerKEInternalContext *ctx =
83 (SilcServerKEInternalContext *)protocol->context;
84 SilcServer server = (SilcServer)ctx->server;
86 /* Send the packet immediately */
87 silc_server_packet_send(server, ske->sock,
88 type, 0, packet->data, packet->len, TRUE);
91 /* Sets the negotiated key material into use for particular connection. */
93 static void silc_server_protocol_ke_set_keys(SilcSKE ske,
94 SilcSocketConnection sock,
95 SilcSKEKeyMaterial *keymat,
101 SilcUnknownEntry conn_data;
104 SILC_LOG_DEBUG(("Setting new key into use"));
106 conn_data = silc_calloc(1, sizeof(*conn_data));
108 /* Allocate cipher to be used in the communication */
109 silc_cipher_alloc(cipher->cipher->name, &conn_data->send_key);
110 silc_cipher_alloc(cipher->cipher->name, &conn_data->receive_key);
112 if (is_responder == TRUE) {
113 conn_data->send_key->cipher->set_key(conn_data->send_key->context,
114 keymat->receive_enc_key,
115 keymat->enc_key_len);
116 conn_data->send_key->set_iv(conn_data->send_key, keymat->receive_iv);
117 conn_data->receive_key->cipher->set_key(conn_data->receive_key->context,
118 keymat->send_enc_key,
119 keymat->enc_key_len);
120 conn_data->receive_key->set_iv(conn_data->receive_key, keymat->send_iv);
123 conn_data->send_key->cipher->set_key(conn_data->send_key->context,
124 keymat->send_enc_key,
125 keymat->enc_key_len);
126 conn_data->send_key->set_iv(conn_data->send_key, keymat->send_iv);
127 conn_data->receive_key->cipher->set_key(conn_data->receive_key->context,
128 keymat->receive_enc_key,
129 keymat->enc_key_len);
130 conn_data->receive_key->set_iv(conn_data->receive_key, keymat->receive_iv);
133 /* Allocate PKCS to be used */
135 /* XXX Do we ever need to allocate PKCS for the connection??
136 If yes, we need to change KE protocol to get the initiators
138 silc_pkcs_alloc(pkcs->pkcs->name, &conn_data->pkcs);
139 conn_data->public_key = silc_pkcs_public_key_alloc(XXX);
140 silc_pkcs_set_public_key(conn_data->pkcs, ske->ke2_payload->pk_data,
141 ske->ke2_payload->pk_len);
144 /* Save HMAC key to be used in the communication. */
145 silc_hash_alloc(hash->hash->name, &nhash);
146 silc_hmac_alloc(nhash, &conn_data->hmac);
147 conn_data->hmac_key_len = keymat->hmac_key_len;
148 conn_data->hmac_key = silc_calloc(conn_data->hmac_key_len,
149 sizeof(unsigned char));
150 memcpy(conn_data->hmac_key, keymat->hmac_key, keymat->hmac_key_len);
152 sock->user_data = (void *)conn_data;
155 /* Performs key exchange protocol. This is used for both initiator
156 and responder key exchange. This is performed always when accepting
157 new connection to the server. This may be called recursively. */
159 SILC_TASK_CALLBACK(silc_server_protocol_key_exchange)
161 SilcProtocol protocol = (SilcProtocol)context;
162 SilcServerKEInternalContext *ctx =
163 (SilcServerKEInternalContext *)protocol->context;
164 SilcServer server = (SilcServer)ctx->server;
165 SilcSKEStatus status = 0;
167 SILC_LOG_DEBUG(("Start"));
169 if (protocol->state == SILC_PROTOCOL_STATE_UNKNOWN)
170 protocol->state = SILC_PROTOCOL_STATE_START;
172 SILC_LOG_DEBUG(("State=%d", protocol->state));
174 switch(protocol->state) {
175 case SILC_PROTOCOL_STATE_START:
182 /* Allocate Key Exchange object */
183 ske = silc_ske_alloc();
186 if (ctx->responder == TRUE) {
187 /* Start the key exchange by processing the received security
188 properties packet from initiator. */
189 status = silc_ske_responder_start(ske, ctx->rng, ctx->sock,
190 ctx->packet, NULL, NULL);
192 SilcSKEStartPayload *start_payload;
194 /* Assemble security properties. */
195 silc_ske_assemble_security_properties(ske, &start_payload);
197 /* Start the key exchange by sending our security properties
198 to the remote end. */
199 status = silc_ske_initiator_start(ske, ctx->rng, ctx->sock,
201 silc_server_protocol_ke_send_packet,
205 if (status != SILC_SKE_STATUS_OK) {
206 SILC_LOG_WARNING(("Error (type %d) during Key Exchange protocol",
208 SILC_LOG_DEBUG(("Error (type %d) during Key Exchange protocol",
211 protocol->state = SILC_PROTOCOL_STATE_ERROR;
212 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
216 /* Advance protocol state and call the next state if we are responder */
218 if (ctx->responder == TRUE)
219 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 100000);
227 if (ctx->responder == TRUE) {
228 /* Sends the selected security properties to the initiator. */
230 silc_ske_responder_phase_1(ctx->ske,
231 ctx->ske->start_payload,
232 silc_server_protocol_ke_send_packet,
235 /* Call Phase-1 function. This processes the Key Exchange Start
236 paylaod reply we just got from the responder. The callback
237 function will receive the processed payload where we will
240 silc_ske_initiator_phase_1(ctx->ske,
245 if (status != SILC_SKE_STATUS_OK) {
246 SILC_LOG_WARNING(("Error (type %d) during Key Exchange protocol",
248 SILC_LOG_DEBUG(("Error (type %d) during Key Exchange protocol",
251 protocol->state = SILC_PROTOCOL_STATE_ERROR;
252 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
256 /* Advance protocol state and call next state if we are initiator */
258 if (ctx->responder == FALSE)
259 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 100000);
267 if (ctx->responder == TRUE) {
268 /* Process the received Key Exchange 1 Payload packet from
269 the initiator. This also creates our parts of the Diffie
270 Hellman algorithm. */
272 silc_ske_responder_phase_2(ctx->ske, ctx->packet, NULL, NULL);
274 /* Call the Phase-2 function. This creates Diffie Hellman
275 key exchange parameters and sends our public part inside
276 Key Exhange 1 Payload to the responder. */
278 silc_ske_initiator_phase_2(ctx->ske,
279 silc_server_protocol_ke_send_packet,
283 if (status != SILC_SKE_STATUS_OK) {
284 SILC_LOG_WARNING(("Error (type %d) during Key Exchange protocol",
286 SILC_LOG_DEBUG(("Error (type %d) during Key Exchange protocol",
289 protocol->state = SILC_PROTOCOL_STATE_ERROR;
290 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
294 /* Advance protocol state and call the next state if we are responder */
296 if (ctx->responder == TRUE)
297 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 100000);
305 if (ctx->responder == TRUE) {
306 /* This creates the key exchange material and sends our
307 public parts to the initiator inside Key Exchange 2 Payload. */
309 silc_ske_responder_finish(ctx->ske,
310 server->public_key, server->private_key,
311 SILC_SKE_PK_TYPE_SILC,
312 silc_server_protocol_ke_send_packet,
315 /* Finish the protocol. This verifies the Key Exchange 2 payload
316 sent by responder. */
318 silc_ske_initiator_finish(ctx->ske,
319 ctx->packet, NULL, NULL, NULL, NULL);
322 if (status != SILC_SKE_STATUS_OK) {
323 SILC_LOG_WARNING(("Error (type %d) during Key Exchange protocol",
325 SILC_LOG_DEBUG(("Error (type %d) during Key Exchange protocol",
328 protocol->state = SILC_PROTOCOL_STATE_ERROR;
329 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
333 /* Send Ok to the other end. We will end the protocol as responder
334 sends Ok to us when we will take the new keys into use. */
335 if (ctx->responder == FALSE)
336 silc_ske_end(ctx->ske, silc_server_protocol_ke_send_packet, context);
338 /* End the protocol on the next round */
339 protocol->state = SILC_PROTOCOL_STATE_END;
342 case SILC_PROTOCOL_STATE_END:
347 SilcSKEKeyMaterial *keymat;
349 /* Send Ok to the other end if we are responder. If we are
350 initiator we have sent this already. */
351 if (ctx->responder == TRUE)
352 silc_ske_end(ctx->ske, silc_server_protocol_ke_send_packet, context);
354 /* Process the key material */
355 keymat = silc_calloc(1, sizeof(*keymat));
356 silc_ske_process_key_material(ctx->ske, 16, (16 * 8), 16, keymat);
358 /* Take the new keys into use. */
359 silc_server_protocol_ke_set_keys(ctx->ske, ctx->sock, keymat,
360 ctx->ske->prop->cipher,
361 ctx->ske->prop->pkcs,
362 ctx->ske->prop->hash,
365 /* Unregister the timeout task since the protocol has ended.
366 This was the timeout task to be executed if the protocol is
367 not completed fast enough. */
368 if (ctx->timeout_task)
369 silc_task_unregister(server->timeout_queue, ctx->timeout_task);
371 /* Call the final callback */
372 if (protocol->final_callback)
373 protocol->execute_final(server->timeout_queue, 0, protocol, fd);
375 silc_protocol_free(protocol);
378 case SILC_PROTOCOL_STATE_ERROR:
383 /* Unregister the timeout task since the protocol has ended.
384 This was the timeout task to be executed if the protocol is
385 not completed fast enough. */
386 if (ctx->timeout_task)
387 silc_task_unregister(server->timeout_queue, ctx->timeout_task);
389 /* On error the final callback is always called. */
390 if (protocol->final_callback)
391 protocol->execute_final(server->timeout_queue, 0, protocol, fd);
393 silc_protocol_free(protocol);
395 case SILC_PROTOCOL_STATE_UNKNOWN:
401 * Connection Authentication protocol functions
404 /* XXX move these to somehwere else */
406 int silc_server_password_authentication(SilcServer server, char *auth1,
409 if (!auth1 || !auth2)
412 if (!memcmp(auth1, auth2, strlen(auth1)))
418 int silc_server_public_key_authentication(SilcServer server,
421 unsigned int sign_len,
424 SilcPublicKey pub_key;
429 if (!pkfile || !sign)
432 /* Load public key from file */
433 if (!silc_pkcs_load_public_key(pkfile, &pub_key, SILC_PKCS_FILE_PEM))
434 if (!silc_pkcs_load_public_key(pkfile, &pub_key, SILC_PKCS_FILE_BIN))
437 silc_pkcs_alloc(pub_key->name, &pkcs);
438 if (!silc_pkcs_public_key_set(pkcs, pub_key)) {
439 silc_pkcs_free(pkcs);
443 /* Make the authentication data. Protocol says it is HASH plus
445 len = ske->hash_len + ske->start_payload_copy->len;
446 auth = silc_buffer_alloc(len);
447 silc_buffer_pull_tail(auth, len);
448 silc_buffer_format(auth,
449 SILC_STR_UI_XNSTRING(ske->hash, ske->hash_len),
450 SILC_STR_UI_XNSTRING(ske->start_payload_copy->data,
451 ske->start_payload_copy->len),
454 /* Verify signature */
455 if (pkcs->pkcs->verify(pkcs->context, sign, sign_len,
456 auth->data, auth->len))
458 silc_pkcs_free(pkcs);
459 silc_pkcs_public_key_free(pub_key);
460 silc_buffer_free(auth);
464 silc_pkcs_free(pkcs);
465 silc_pkcs_public_key_free(pub_key);
466 silc_buffer_free(auth);
470 /* Performs connection authentication protocol. If responder, we
471 authenticate the remote data received. If initiator, we will send
472 authentication data to the remote end. */
474 SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
476 SilcProtocol protocol = (SilcProtocol)context;
477 SilcServerConnAuthInternalContext *ctx =
478 (SilcServerConnAuthInternalContext *)protocol->context;
479 SilcServer server = (SilcServer)ctx->server;
481 SILC_LOG_DEBUG(("Start"));
483 if (protocol->state == SILC_PROTOCOL_STATE_UNKNOWN)
484 protocol->state = SILC_PROTOCOL_STATE_START;
486 SILC_LOG_DEBUG(("State=%d", protocol->state));
488 switch(protocol->state) {
489 case SILC_PROTOCOL_STATE_START:
495 if (ctx->responder == TRUE) {
497 * We are receiving party
500 unsigned short payload_len;
501 unsigned short conn_type;
502 unsigned char *auth_data;
504 SILC_LOG_INFO(("Performing authentication protocol for %s",
505 ctx->sock->hostname ? ctx->sock->hostname :
508 /* Parse the received authentication data packet. The received
509 payload is Connection Auth Payload. */
510 silc_buffer_unformat(ctx->packet,
511 SILC_STR_UI_SHORT(&payload_len),
512 SILC_STR_UI_SHORT(&conn_type),
515 if (payload_len != ctx->packet->len) {
516 SILC_LOG_ERROR(("Bad payload in authentication packet"));
517 SILC_LOG_DEBUG(("Bad payload in authentication packet"));
518 protocol->state = SILC_PROTOCOL_STATE_ERROR;
519 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
525 if (conn_type < SILC_SOCKET_TYPE_CLIENT ||
526 conn_type > SILC_SOCKET_TYPE_ROUTER) {
527 SILC_LOG_ERROR(("Bad connection type %d", conn_type));
528 SILC_LOG_DEBUG(("Bad connection type %d", conn_type));
529 protocol->state = SILC_PROTOCOL_STATE_ERROR;
530 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000);
534 if (payload_len > 0) {
535 /* Get authentication data */
536 silc_buffer_pull(ctx->packet, 4);
537 silc_buffer_unformat(ctx->packet,
538 SILC_STR_UI_XNSTRING_ALLOC(&auth_data,
546 * Check the remote connection type and make sure that we have
547 * configured this connection. If we haven't allowed this connection
548 * the authentication must be failed.
551 SILC_LOG_DEBUG(("Remote connection type %d", conn_type));
553 /* Remote end is client */
554 if (conn_type == SILC_SOCKET_TYPE_CLIENT) {
555 SilcConfigServerSectionClientConnection *client = NULL;
557 silc_config_server_find_client_conn(server->config,
562 silc_config_server_find_client_conn(server->config,
567 switch(client->auth_meth) {
568 case SILC_PROTOCOL_CONN_AUTH_NONE:
569 /* No authentication required */
570 SILC_LOG_DEBUG(("No authentication required"));
573 case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
574 /* Password authentication */
575 SILC_LOG_DEBUG(("Password authentication"));
576 ret = silc_server_password_authentication(server, auth_data,
580 memset(auth_data, 0, payload_len);
581 silc_free(auth_data);
586 /* Authentication failed */
587 SILC_LOG_ERROR(("Authentication failed"));
588 SILC_LOG_DEBUG(("Authentication failed"));
589 protocol->state = SILC_PROTOCOL_STATE_ERROR;
590 protocol->execute(server->timeout_queue, 0,
591 protocol, fd, 0, 300000);
595 case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
596 /* Public key authentication */
597 SILC_LOG_DEBUG(("Public key authentication"));
598 ret = silc_server_public_key_authentication(server,
605 memset(auth_data, 0, payload_len);
606 silc_free(auth_data);
611 SILC_LOG_ERROR(("Authentication failed"));
612 SILC_LOG_DEBUG(("Authentication failed"));
613 protocol->state = SILC_PROTOCOL_STATE_ERROR;
614 protocol->execute(server->timeout_queue, 0,
615 protocol, fd, 0, 300000);
619 SILC_LOG_DEBUG(("No configuration for remote connection"));
620 SILC_LOG_ERROR(("Remote connection not configured"));
621 SILC_LOG_ERROR(("Authentication failed"));
622 memset(auth_data, 0, payload_len);
623 silc_free(auth_data);
625 protocol->state = SILC_PROTOCOL_STATE_ERROR;
626 protocol->execute(server->timeout_queue, 0,
627 protocol, fd, 0, 300000);
632 /* Remote end is server */
633 if (conn_type == SILC_SOCKET_TYPE_SERVER) {
634 SilcConfigServerSectionServerConnection *serv = NULL;
636 silc_config_server_find_server_conn(server->config,
641 silc_config_server_find_server_conn(server->config,
646 switch(serv->auth_meth) {
647 case SILC_PROTOCOL_CONN_AUTH_NONE:
648 /* No authentication required */
649 SILC_LOG_DEBUG(("No authentication required"));
652 case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
653 /* Password authentication */
654 SILC_LOG_DEBUG(("Password authentication"));
655 ret = silc_server_password_authentication(server, auth_data,
659 memset(auth_data, 0, payload_len);
660 silc_free(auth_data);
665 /* Authentication failed */
666 SILC_LOG_ERROR(("Authentication failed"));
667 SILC_LOG_DEBUG(("Authentication failed"));
668 protocol->state = SILC_PROTOCOL_STATE_ERROR;
669 protocol->execute(server->timeout_queue, 0,
670 protocol, fd, 0, 300000);
674 case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
675 /* Public key authentication */
676 SILC_LOG_DEBUG(("Public key authentication"));
677 ret = silc_server_public_key_authentication(server,
684 memset(auth_data, 0, payload_len);
685 silc_free(auth_data);
690 SILC_LOG_ERROR(("Authentication failed"));
691 SILC_LOG_DEBUG(("Authentication failed"));
692 protocol->state = SILC_PROTOCOL_STATE_ERROR;
693 protocol->execute(server->timeout_queue, 0,
694 protocol, fd, 0, 300000);
698 SILC_LOG_DEBUG(("No configuration for remote connection"));
699 SILC_LOG_ERROR(("Remote connection not configured"));
700 SILC_LOG_ERROR(("Authentication failed"));
701 memset(auth_data, 0, payload_len);
702 silc_free(auth_data);
704 protocol->state = SILC_PROTOCOL_STATE_ERROR;
705 protocol->execute(server->timeout_queue, 0,
706 protocol, fd, 0, 300000);
711 /* Remote end is router */
712 if (conn_type == SILC_SOCKET_TYPE_ROUTER) {
713 SilcConfigServerSectionServerConnection *serv = NULL;
715 silc_config_server_find_router_conn(server->config,
720 silc_config_server_find_router_conn(server->config,
725 switch(serv->auth_meth) {
726 case SILC_PROTOCOL_CONN_AUTH_NONE:
727 /* No authentication required */
728 SILC_LOG_DEBUG(("No authentication required"));
731 case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
732 /* Password authentication */
733 SILC_LOG_DEBUG(("Password authentication"));
734 ret = silc_server_password_authentication(server, auth_data,
738 memset(auth_data, 0, payload_len);
739 silc_free(auth_data);
744 /* Authentication failed */
745 SILC_LOG_ERROR(("Authentication failed"));
746 SILC_LOG_DEBUG(("Authentication failed"));
747 protocol->state = SILC_PROTOCOL_STATE_ERROR;
748 protocol->execute(server->timeout_queue, 0,
749 protocol, fd, 0, 300000);
753 case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
754 /* Public key authentication */
755 SILC_LOG_DEBUG(("Public key authentication"));
756 ret = silc_server_public_key_authentication(server,
763 memset(auth_data, 0, payload_len);
764 silc_free(auth_data);
769 SILC_LOG_ERROR(("Authentication failed"));
770 SILC_LOG_DEBUG(("Authentication failed"));
771 protocol->state = SILC_PROTOCOL_STATE_ERROR;
772 protocol->execute(server->timeout_queue, 0,
773 protocol, fd, 0, 300000);
777 SILC_LOG_DEBUG(("No configuration for remote connection"));
778 SILC_LOG_ERROR(("Remote connection not configured"));
779 SILC_LOG_ERROR(("Authentication failed"));
780 memset(auth_data, 0, payload_len);
781 silc_free(auth_data);
783 protocol->state = SILC_PROTOCOL_STATE_ERROR;
784 protocol->execute(server->timeout_queue, 0,
785 protocol, fd, 0, 300000);
791 memset(auth_data, 0, payload_len);
792 silc_free(auth_data);
795 /* Save connection type. This is later used to create the
796 ID for the connection. */
797 ctx->conn_type = conn_type;
799 /* Advance protocol state. */
800 protocol->state = SILC_PROTOCOL_STATE_END;
801 protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 0);
805 * We are initiator. We are authenticating ourselves to a
806 * remote server. We will send the authentication data to the
807 * other end for verify.
811 unsigned char *auth_data = NULL;
812 unsigned int auth_data_len = 0;
814 switch(ctx->auth_meth) {
815 case SILC_PROTOCOL_CONN_AUTH_NONE:
816 /* No authentication required */
819 case SILC_PROTOCOL_CONN_AUTH_PASSWORD:
820 /* Password authentication */
821 if (ctx->auth_data && ctx->auth_data_len) {
822 auth_data = ctx->auth_data;
823 auth_data_len = ctx->auth_data_len;
827 /* No authentication data exits. Ask interactively from user. */
832 case SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY:
833 /* Public key authentication */
838 payload_len = 4 + auth_data_len;
839 packet = silc_buffer_alloc(payload_len);
840 silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
841 silc_buffer_format(packet,
842 SILC_STR_UI_SHORT(payload_len),
843 SILC_STR_UI_SHORT(server->server_type
845 SILC_SOCKET_TYPE_SERVER :
846 SILC_SOCKET_TYPE_ROUTER),
847 SILC_STR_UI_XNSTRING(auth_data, auth_data_len),
850 /* Send the packet to server */
851 silc_server_packet_send(server, ctx->sock,
852 SILC_PACKET_CONNECTION_AUTH, 0,
853 packet->data, packet->len, TRUE);
856 memset(auth_data, 0, auth_data_len);
857 silc_free(auth_data);
859 silc_buffer_free(packet);
861 /* Next state is end of protocol */
862 protocol->state = SILC_PROTOCOL_STATE_END;
867 case SILC_PROTOCOL_STATE_END:
873 /* Succesfully authenticated */
874 silc_server_packet_send(server, ctx->sock, SILC_PACKET_SUCCESS,
877 /* Unregister the timeout task since the protocol has ended.
878 This was the timeout task to be executed if the protocol is
879 not completed fast enough. */
880 if (ctx->timeout_task)
881 silc_task_unregister(server->timeout_queue, ctx->timeout_task);
883 /* Protocol has ended, call the final callback */
884 if (protocol->final_callback)
885 protocol->execute_final(server->timeout_queue, 0, protocol, fd);
887 silc_protocol_free(protocol);
890 case SILC_PROTOCOL_STATE_ERROR:
896 /* Authentication failed */
897 silc_server_packet_send(server, ctx->sock, SILC_PACKET_FAILURE,
900 /* Unregister the timeout task since the protocol has ended.
901 This was the timeout task to be executed if the protocol is
902 not completed fast enough. */
903 if (ctx->timeout_task)
904 silc_task_unregister(server->timeout_queue, ctx->timeout_task);
906 /* On error the final callback is always called. */
907 if (protocol->final_callback)
908 protocol->execute_final(server->timeout_queue, 0, protocol, fd);
910 silc_protocol_free(protocol);
913 case SILC_PROTOCOL_STATE_UNKNOWN: