updates.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 17 Jul 2001 14:58:18 +0000 (14:58 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 17 Jul 2001 14:58:18 +0000 (14:58 +0000)
CHANGES
TODO
lib/silcske/silcske.c
lib/silcske/silcske.h
lib/silcutil/silcnet.h
lib/silcutil/win32/silcwin32net.c
lib/silcutil/win32/silcwin32sockconn.c

diff --git a/CHANGES b/CHANGES
index 43d3dcbdff08841b5dd197f6b3a1e48bf99749c0..a7a908a641aecaf1a4d5e2cd738d31505996d47f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,21 @@
+Tue Jul 17 16:53:30 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
+
+       * 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 <priikone@silcnet.org>
 
        * Fixed various compilation problems under WIN32.  Affected
diff --git a/TODO b/TODO
index c6fce455fad2c4b66b3c61f710d7add4be9fee4c..1bb758dc0e0c8a211d595a9a403700236307ba77 100644 (file)
--- 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
 =====================
 
index b9d45b4b4919d2d6a55e97b0c092fe189fa85a60..958b7f439c0db590865b159a252602df5d7fd9bc 100644 (file)
@@ -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) {
index d9556cb2d74a2bbb10452002be0ef71efa905351..eb98f6e625210de9a7267fd75166606d897e2e76 100644 (file)
@@ -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;
index 68ef081434fbbc87b268421f02734242fdbc47df..d5b8a6bae0d53e1d85226f56ee06614ebac4c329 100644 (file)
@@ -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
index 30620bf0ff1ca0a4b3408b0a62e7edbf1c1a6175..98b80a19bf3cfffe81f2d95a56c9bca1b1774a98 100644 (file)
@@ -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();
+}
index ba8a5d7e14ddc7596acf74fd90c3c8a249dd6e9c..c78640308398c344bde074d1226a055db1d60693 100644 (file)
@@ -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;