From 306ec7a94a1097ccd432c9dd022efe234605fa38 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 17 Jul 2001 14:58:18 +0000 Subject: [PATCH] updates. --- CHANGES | 18 ++++++++++++ TODO | 7 +++++ lib/silcske/silcske.c | 27 +++++++++--------- lib/silcske/silcske.h | 5 ---- lib/silcutil/silcnet.h | 39 ++++++++++++++++++++++++++ lib/silcutil/win32/silcwin32net.c | 35 +++++++++++++++++++++-- lib/silcutil/win32/silcwin32sockconn.c | 7 +++++ 7 files changed, 117 insertions(+), 21 deletions(-) diff --git a/CHANGES b/CHANGES index 43d3dcbd..a7a908a6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,21 @@ +Tue Jul 17 16:53:30 EEST 2001 Pekka Riikonen + + * Found a bug in the SKE implementation. The HASH value, + specified by the protocol, was not computed correctly. The + public key of the responder was not added to the computation + even though it is mandatory. Affected file lib/silcske/silcske.c. + This unfortunately causes incompatibilities with older + clients and servers. + + * Added WIN32 specific network init and uninit functions: + silc_net_win32_init and silc_net_win32_uninit to init and uninit + the Winsock2. Affected file lib/silcutil/silcnet.h and + lib/silcutil/win32/silcwin32net.c. + + * Set the socket always to nonblocking mode on WIN32 after + reading data or writing data. Affected file is + lib/silcutil/win32/silcwin32sockconn.c. + Mon Jul 16 22:55:26 EEST 2001 Pekka Riikonen * Fixed various compilation problems under WIN32. Affected diff --git a/TODO b/TODO index c6fce455..1bb758dc 100644 --- a/TODO +++ b/TODO @@ -103,6 +103,13 @@ TODO/bugs In SILC Libraries in separately. +TODO/Bugs in native WIN32 support (libraries) +============================================= + + o silc_net_create_connection_async does not work the same way than on + Unix. Do it with threads on WIN32. + + TODO In SILC Protocol ===================== diff --git a/lib/silcske/silcske.c b/lib/silcske/silcske.c index b9d45b4b..958b7f43 100644 --- a/lib/silcske/silcske.c +++ b/lib/silcske/silcske.c @@ -86,8 +86,6 @@ void silc_ske_free(SilcSKE ske) } if (ske->start_payload_copy) silc_buffer_free(ske->start_payload_copy); - if (ske->pk) - silc_free(ske->pk); if (ske->x) { silc_mp_uninit(ske->x); silc_free(ske->x); @@ -382,8 +380,8 @@ SilcSKEStatus silc_ske_initiator_phase_2(SilcSKE ske, /* Send the packet. */ if (ske->callbacks->send_packet) (*ske->callbacks->send_packet)(ske, payload_buf, - SILC_PACKET_KEY_EXCHANGE_1, - ske->callbacks->context); + SILC_PACKET_KEY_EXCHANGE_1, + ske->callbacks->context); silc_buffer_free(payload_buf); @@ -912,10 +910,10 @@ SilcSKEStatus silc_ske_responder_phase_2(SilcSKE ske, ske->users++; (*ske->callbacks->verify_key)(ske, recv_payload->pk_data, - recv_payload->pk_len, - recv_payload->pk_type, - ske->callbacks->context, - silc_ske_responder_phase2_final, NULL); + recv_payload->pk_len, + recv_payload->pk_type, + ske->callbacks->context, + silc_ske_responder_phase2_final, NULL); /* We will continue to the final state after the public key has been verified by the caller. */ @@ -1562,15 +1560,17 @@ SilcSKEStatus silc_ske_make_hash(SilcSKE ske, KEY = silc_mp_mp2bin(ske->KEY, 0, &KEY_len); buf = silc_buffer_alloc(ske->start_payload_copy->len + - ske->pk_len + e_len + f_len + KEY_len); + ske->ke2_payload->pk_len + e_len + + f_len + KEY_len); silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf)); - + /* Format the buffer used to compute the hash value */ ret = silc_buffer_format(buf, SILC_STR_UI_XNSTRING(ske->start_payload_copy->data, ske->start_payload_copy->len), - SILC_STR_UI_XNSTRING(ske->pk, ske->pk_len), + SILC_STR_UI_XNSTRING(ske->ke2_payload->pk_data, + ske->ke2_payload->pk_len), SILC_STR_UI_XNSTRING(e, e_len), SILC_STR_UI_XNSTRING(f, f_len), SILC_STR_UI_XNSTRING(KEY, KEY_len), @@ -1596,7 +1596,7 @@ SilcSKEStatus silc_ske_make_hash(SilcSKE ske, e = silc_mp_mp2bin(&ske->ke1_payload->x, 0, &e_len); buf = silc_buffer_alloc(ske->start_payload_copy->len + - ske->pk_len + e_len); + ske->ke1_payload->pk_len + e_len); silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf)); /* Format the buffer used to compute the hash value */ @@ -1604,7 +1604,8 @@ SilcSKEStatus silc_ske_make_hash(SilcSKE ske, silc_buffer_format(buf, SILC_STR_UI_XNSTRING(ske->start_payload_copy->data, ske->start_payload_copy->len), - SILC_STR_UI_XNSTRING(ske->pk, ske->pk_len), + SILC_STR_UI_XNSTRING(ske->ke1_payload->pk_data, + ske->ke1_payload->pk_len), SILC_STR_UI_XNSTRING(e, e_len), SILC_STR_END); if (ret == -1) { diff --git a/lib/silcske/silcske.h b/lib/silcske/silcske.h index d9556cb2..eb98f6e6 100644 --- a/lib/silcske/silcske.h +++ b/lib/silcske/silcske.h @@ -150,11 +150,6 @@ struct SilcSKEStruct { HASH computation. */ SilcBuffer start_payload_copy; - /* If initiator, this is responders public key. If responder this - is our own public key. */ - unsigned char *pk; - uint32 pk_len; - /* Random number x, 1 < x < q. This is the secret exponent used in Diffie Hellman computations. */ SilcMPInt *x; diff --git a/lib/silcutil/silcnet.h b/lib/silcutil/silcnet.h index 68ef0814..d5b8a6ba 100644 --- a/lib/silcutil/silcnet.h +++ b/lib/silcutil/silcnet.h @@ -255,4 +255,43 @@ uint16 silc_net_get_local_port(int sock); ***/ char *silc_net_localhost(); +#ifdef WIN32 + +/****f* silcutil/SilcNetAPI/silc_net_win32_init + * + * SYNOPSIS + * + * bool silc_net_win32_init(void); + * + * DESCRIPTION + * + * This is WIN32 system specific function and is used to initialize + * the network. This must be called by all WIN32 applications. It + * is usually called at the application's main() or WinMain() before + * calling any other SILC routine. The application must also call + * the silc_net_win32_uninit when exiting the application. Returns + * FALSE on error. The network will not work if this function returns + * FALSE. + * + ***/ +bool silc_net_win32_init(void); + +/****f* silcutil/SilcNetAPI/silc_net_win32_uninit + * + * SYNOPSIS + * + * void silc_net_win32_init(void); + * + * DESCRIPTION + * + * This is WIN32 system specific function and is used to uninitialize + * the network. This must be called by all WIN32 applications. It + * is usually called when the application is exiting. After calling + * this function the SILC Net API routines will not work anymore. + * + ***/ +void silc_net_win32_init(void); + +#endif + #endif diff --git a/lib/silcutil/win32/silcwin32net.c b/lib/silcutil/win32/silcwin32net.c index 30620bf0..98b80a19 100644 --- a/lib/silcutil/win32/silcwin32net.c +++ b/lib/silcutil/win32/silcwin32net.c @@ -182,9 +182,6 @@ int silc_net_create_connection_async(int port, char *host) return -1; } - /* Set socket to nonblocking mode */ - silc_net_set_socket_nonblock(sock); - /* Connect to the host */ rval = connect(sock, (struct sockaddr *)&desthost, sizeof(desthost)); err = WSAGetLastError(); @@ -195,6 +192,9 @@ int silc_net_create_connection_async(int port, char *host) return -1; } + /* Set socket to nonblocking mode */ + silc_net_set_socket_nonblock(sock); + /* Set appropriate options */ silc_net_set_socket_opt(sock, IPPROTO_TCP, TCP_NODELAY, 1); silc_net_set_socket_opt(sock, SOL_SOCKET, SO_KEEPALIVE, 1); @@ -236,3 +236,32 @@ int silc_net_set_socket_nonblock(int sock) unsigned long on = 1; return ioctlsocket(sock, FIONBIO, &on); } + +/* Init Winsock2. */ + +bool silc_net_win32_init(void) +{ + int ret, sopt = SO_SYNCHRONOUS_NONALERT; + WSADATA wdata; + WORD ver = MAKEWORD(1, 1); + + ret = WSAStartup(ver, &wdata); + if (ret) + return FALSE; + + /* Allow using the SOCKET's as file descriptors so that we can poll + them with SILC Scheduler. */ + ret = setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sopt, + sizeof(sopt)); + if (ret) + return FALSE; + + return TRUE; +} + +/* Uninit Winsock2 */ + +void silc_net_win32_uninit(void) +{ + WSACleanup(); +} diff --git a/lib/silcutil/win32/silcwin32sockconn.c b/lib/silcutil/win32/silcwin32sockconn.c index ba8a5d7e..c7864030 100644 --- a/lib/silcutil/win32/silcwin32sockconn.c +++ b/lib/silcutil/win32/silcwin32sockconn.c @@ -41,9 +41,11 @@ int silc_socket_write(SilcSocketConnection sock) err = WSAGetLastError(); if (err == WSAEWOULDBLOCK) { SILC_LOG_DEBUG(("Could not write immediately, will do it later")); + silc_net_set_socket_nonblock(fd); return -2; } SILC_LOG_ERROR(("Cannot write to socket: %d", (int)fd)); + silc_net_set_socket_nonblock(fd); return -1; } @@ -52,6 +54,7 @@ int silc_socket_write(SilcSocketConnection sock) SILC_LOG_DEBUG(("Wrote data %d bytes", ret)); + silc_net_set_socket_nonblock(fd); return ret; } @@ -74,12 +77,16 @@ int silc_socket_read(SilcSocketConnection sock) err = WSAGetLastError(); if (err == WSAEWOULDBLOCK || err == WSAEINTR) { SILC_LOG_DEBUG(("Could not read immediately, will do it later")); + silc_net_set_socket_nonblock(fd); return -2; } SILC_LOG_ERROR(("Cannot read from socket: %d", (int)fd)); + silc_net_set_socket_nonblock(fd); return -1; } + silc_net_set_socket_nonblock(fd); + if (!len) return 0; -- 2.24.0