Handle special packet processing correctly.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 30 Nov 2006 14:55:37 +0000 (14:55 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 30 Nov 2006 14:55:37 +0000 (14:55 +0000)
lib/silccore/silcmessage.c
lib/silccore/silcmessage.h
lib/silccore/silcpacket.c
lib/silccore/silcpacket.h

index 19fb22f34376b6e5fdf62c71f32e9be2e4c844d6..e7f06c0ee2f158b0ab979c50e649ac2103019743 100644 (file)
@@ -281,7 +281,7 @@ SilcBool silc_message_payload_decrypt(unsigned char *data,
   if (!private_message || (private_message && static_key))
     iv_len = block_len;
 
-  if (data_len <= (mac_len + iv_len + block_len))
+  if (data_len < (mac_len + iv_len + block_len))
     return FALSE;
 
   if (check_mac) {
@@ -306,8 +306,10 @@ SilcBool silc_message_payload_decrypt(unsigned char *data,
         silc_cipher_get_iv(cipher));
 
   /* Decrypt block */
-  if (!silc_cipher_decrypt(cipher, data, data, block_len, ivp))
+  if (!silc_cipher_decrypt(cipher, data, data, block_len, ivp)) {
+    SILC_ASSERT(FALSE);
     return FALSE;
+  }
 
   /* Get the payload length and decrypt rest */
   totlen = 2;
@@ -319,8 +321,10 @@ SilcBool silc_message_payload_decrypt(unsigned char *data,
   if (totlen >= block_len)
     if (!silc_cipher_decrypt(cipher, data + block_len, data + block_len,
                             (totlen - block_len) + SILC_MESSAGE_PAD(totlen),
-                            ivp))
+                            ivp)) {
+      SILC_ASSERT(FALSE);
       return FALSE;
+    }
 
   return TRUE;
 }
@@ -648,9 +652,9 @@ unsigned char *silc_message_get_mac(SilcMessagePayload payload)
 
 /* Verify the signature in SILC_MESSAGE_FLAG_SIGNED Payload */
 
-int silc_message_signed_verify(SilcMessagePayload message,
-                              SilcPublicKey remote_public_key,
-                              SilcHash hash)
+SilcAuthResult silc_message_signed_verify(SilcMessagePayload message,
+                                         SilcPublicKey remote_public_key,
+                                         SilcHash hash)
 {
   int ret = SILC_AUTH_FAILED;
   SilcBuffer sign, tmp;
index 09ca21aa8bc2bbff0dca4c71da69ef27f920257a..e51c3009028a21254e7106b1fd85fdf7a75ed0a1 100644 (file)
@@ -329,9 +329,10 @@ unsigned char *silc_message_get_mac(SilcMessagePayload payload);
  *
  * SYNOPSIS
  *
- *    int silc_message_signed_verify(SilcMessagePayload message,
- *                                   SilcPublicKey remote_public_key,
- *                                   SilcHash hash);
+ *    SilcAuthResult
+ *    silc_message_signed_verify(SilcMessagePayload message,
+ *                               SilcPublicKey remote_public_key,
+ *                               SilcHash hash);
  *
  * DESCRIPTION
  *
@@ -341,9 +342,9 @@ unsigned char *silc_message_get_mac(SilcMessagePayload payload);
  *    returns SILC_AUTH_OK if the signature verification was successful.
  *
  ***/
-int silc_message_signed_verify(SilcMessagePayload message,
-                              SilcPublicKey remote_public_key,
-                              SilcHash hash);
+SilcAuthResult silc_message_signed_verify(SilcMessagePayload message,
+                                         SilcPublicKey remote_public_key,
+                                         SilcHash hash);
 
 /****f* silccore/SilcMessageAPI/silc_message_signed_get_public_key
  *
index 2a2b9af18345a2079f7403b83c25dc48cd5c1b05..39ca67c4148f356a7a0e53e03cdaf2ad91030dc1 100644 (file)
@@ -1434,7 +1434,7 @@ static void silc_packet_read_process(SilcPacketStream stream)
   SilcUInt32 paddedlen, mac_len, block_len, ivlen, psnlen;
   unsigned char tmp[SILC_PACKET_MIN_HEADER_LEN], *header;
   unsigned char iv[SILC_CIPHER_MAX_IV_SIZE], *packet_seq = NULL;
-  SilcBool normal = TRUE;
+  SilcBool normal;
   int ret;
 
   /* Parse the packets from the data */
@@ -1442,6 +1442,7 @@ static void silc_packet_read_process(SilcPacketStream stream)
     ivlen = psnlen = 0;
     cipher = stream->receive_key[0];
     hmac = stream->receive_hmac[0];
+    normal = FALSE;
 
     if (silc_buffer_len(&stream->inbuf) <
        (stream->iv_included ? SILC_PACKET_MIN_HEADER_LEN_IV :
@@ -1547,6 +1548,7 @@ static void silc_packet_read_process(SilcPacketStream stream)
       silc_buffer_reset(&stream->inbuf);
       return;
     }
+    packet->stream = stream;
 
     /* Allocate more space to packet buffer, if needed */
     if (silc_buffer_truelen(&packet->buffer) < paddedlen) {
@@ -1616,7 +1618,6 @@ static void silc_packet_read_process(SilcPacketStream stream)
     silc_buffer_pull(&stream->inbuf, paddedlen + mac_len);
 
     /* Dispatch the packet to application */
-    packet->stream = stream;
     silc_packet_dispatch(packet);
   }
 
index d926bcb3ce5f99097c92baae40efb94139842c7d..89d0da9b0ec14283906b0023fd837512940fb226 100644 (file)
@@ -415,7 +415,7 @@ SilcPacketStream silc_packet_stream_create(SilcPacketEngine engine,
  * DESCRIPTION
  *
  *    Destroy packet stream and the underlaying stream.  This will also
- *    send end of stream to the underlaying stream.
+ *    close and destroy the underlaying stream.
  *
  ***/
 void silc_packet_stream_destroy(SilcPacketStream stream);