#include "silcincludes.h"
#include "silcclient.h"
#include "client_internal.h"
+#include "silcversion.h"
/* Static task callback prototypes */
SILC_TASK_CALLBACK(silc_client_connect_to_server_start);
new_client->internal->ops = ops;
new_client->internal->params =
silc_calloc(1, sizeof(*new_client->internal->params));
+ if (!silc_version)
+ silc_version = silc_version_string;
new_client->internal->silc_client_version = strdup(silc_version);
if (params)
{
SILC_LOG_DEBUG(("Initializing client"));
+ /* Initialize the crypto library. If application has done this already
+ this has no effect. Also, we will not be overriding something
+ application might have registered earlier. */
+ silc_cipher_register_default();
+ silc_pkcs_register_default();
+ silc_hash_register_default();
+ silc_hmac_register_default();
+
/* Initialize hash functions for client to use */
- silc_hash_alloc("md5", &client->internal->md5hash);
- silc_hash_alloc("sha1", &client->internal->sha1hash);
+ silc_hash_alloc("md5", &client->md5hash);
+ silc_hash_alloc("sha1", &client->sha1hash);
/* Initialize none cipher */
silc_cipher_alloc("none", &client->internal->none_cipher);
(void *)ctx, 0, 0,
SILC_TASK_FD,
SILC_TASK_PRI_NORMAL);
- silc_schedule_set_listen_fd(ctx->client->schedule, sock, SILC_TASK_WRITE);
+ silc_schedule_set_listen_fd(ctx->client->schedule, sock, SILC_TASK_WRITE,
+ FALSE);
ctx->sock = sock;
conn, client->schedule);
}
-/* Callback called when error has occurred during connecting to the server.
- The `connect' client operation will be called. */
+/* Callback called when error has occurred during connecting (KE) to
+ the server. The `connect' client operation will be called. */
SILC_TASK_CALLBACK(silc_client_connect_failure)
{
silc_free(ctx);
}
+/* Callback called when error has occurred during connecting (auth) to
+ the server. The `connect' client operation will be called. */
+
+SILC_TASK_CALLBACK(silc_client_connect_failure_auth)
+{
+ SilcClientConnAuthInternalContext *ctx =
+ (SilcClientConnAuthInternalContext *)context;
+ SilcClient client = (SilcClient)ctx->client;
+
+ client->internal->ops->connect(client, ctx->sock->user_data,
+ SILC_CLIENT_CONN_ERROR);
+ silc_free(ctx);
+}
+
/* Start of the connection to the remote server. This is called after
succesful TCP/IP connection has been established to the remote host. */
silc_protocol_free(protocol);
if (ctx->packet)
silc_packet_context_free(ctx->packet);
+ ctx->packet = NULL;
silc_free(ctx);
sock->protocol = NULL;
proto_ctx->auth_meth = auth_meth;
- if (auth_data && auth_data_len) {
+ if (success && auth_data && auth_data_len) {
+
+ /* Passphrase must be UTF-8 encoded, if it isn't encode it */
+ if (auth_meth == SILC_AUTH_PASSWORD &&
+ !silc_utf8_valid(auth_data, auth_data_len)) {
+ int payload_len = 0;
+ unsigned char *autf8 = NULL;
+ 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;
+ }
+
proto_ctx->auth_data = silc_memdup(auth_data, auth_data_len);
proto_ctx->auth_data_len = auth_data_len;
}
/* Notify application of failure */
silc_schedule_task_add(client->schedule, ctx->sock->sock,
- silc_client_connect_failure, ctx,
+ silc_client_connect_failure_auth, ctx,
0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
}
SilcHmac hmac,
unsigned char *data,
SilcUInt32 data_len,
- int force_send)
+ bool force_send)
{
SilcPacketContext packetdata;
const SilcBufferStruct packet;