+/* Continues the connection authentication protocol. This funtion may
+ be called directly or used as SilcAskPassphrase callback. */
+
+static void
+silc_client_conn_auth_continue(unsigned char *auth_data,
+ SilcUInt32 auth_data_len, void *context)
+{
+ SilcProtocol protocol = (SilcProtocol)context;
+ SilcClientConnAuthInternalContext *ctx =
+ (SilcClientConnAuthInternalContext *)protocol->context;
+ SilcClient client = (SilcClient)ctx->client;
+ SilcBuffer packet;
+ int payload_len = 0;
+ unsigned char *autf8 = NULL;
+
+ SILC_LOG_DEBUG(("Sending authentication to server"));
+
+ /* Passphrase must be UTF-8 encoded, if it isn't encode it */
+ if (ctx->auth_meth == SILC_AUTH_PASSWORD &&
+ !silc_utf8_valid(auth_data, auth_data_len)) {
+ payload_len = silc_utf8_encoded_len(auth_data, auth_data_len,
+ SILC_STRING_ASCII);
+ autf8 = silc_calloc(payload_len, sizeof(*autf8));
+ auth_data_len = silc_utf8_encode(auth_data, auth_data_len,
+ SILC_STRING_ASCII, autf8, payload_len);
+ auth_data = autf8;
+ }
+
+ payload_len = 4 + auth_data_len;
+ packet = silc_buffer_alloc(payload_len);
+ silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
+ silc_buffer_format(packet,
+ SILC_STR_UI_SHORT(payload_len),
+ SILC_STR_UI_SHORT(SILC_SOCKET_TYPE_CLIENT),
+ SILC_STR_UI_XNSTRING(auth_data, auth_data_len),
+ SILC_STR_END);
+
+ /* Send the packet to server */
+ silc_client_packet_send(client, ctx->sock,
+ SILC_PACKET_CONNECTION_AUTH,
+ NULL, 0, NULL, NULL,
+ packet->data, packet->len, TRUE);
+ silc_buffer_free(packet);
+ silc_free(autf8);
+
+ /* Next state is end of protocol */
+ protocol->state = SILC_PROTOCOL_STATE_END;
+}
+