gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35570 - gnunet/src/cadet


From: gnunet
Subject: [GNUnet-SVN] r35570 - gnunet/src/cadet
Date: Mon, 27 Apr 2015 21:14:03 +0200

Author: bartpolot
Date: 2015-04-27 21:14:03 +0200 (Mon, 27 Apr 2015)
New Revision: 35570

Modified:
   gnunet/src/cadet/gnunet-service-cadet_connection.c
   gnunet/src/cadet/gnunet-service-cadet_tunnel.c
   gnunet/src/cadet/gnunet-service-cadet_tunnel.h
Log:
- refactor to use same function to decrypt based on tunnel's enc method

Modified: gnunet/src/cadet/gnunet-service-cadet_connection.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_connection.c  2015-04-27 19:14:01 UTC 
(rev 35569)
+++ gnunet/src/cadet/gnunet-service-cadet_connection.c  2015-04-27 19:14:03 UTC 
(rev 35570)
@@ -2221,7 +2221,7 @@
       GNUNET_break (GNUNET_NO != c->destroy);
       return GNUNET_OK;
     }
-    GCT_handle_encrypted (c->t, msg);
+    GCT_handle_encrypted (c->t, &msg->header);
     GCC_send_ack (c, fwd, GNUNET_NO);
     return GNUNET_OK;
   }
@@ -2528,7 +2528,7 @@
       GNUNET_break (GNUNET_NO != c->destroy);
       return GNUNET_OK;
     }
-    GCT_handle_ax (c->t, msg); //FIXME ax
+    GCT_handle_encrypted (c->t, message);
     GCC_send_ack (c, fwd, GNUNET_NO);
     return GNUNET_OK;
   }

Modified: gnunet/src/cadet/gnunet-service-cadet_tunnel.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_tunnel.c      2015-04-27 19:14:01 UTC 
(rev 35569)
+++ gnunet/src/cadet/gnunet-service-cadet_tunnel.c      2015-04-27 19:14:03 UTC 
(rev 35570)
@@ -845,7 +845,27 @@
   return -1;
 }
 
+/**
+ * Decrypt and verify data with the appropriate tunnel key and verify that the
+ * data has not been altered since it was sent by the remote peer.
+ *
+ * @param t Tunnel whose key to use.
+ * @param dst Destination for the plaintext.
+ * @param src Source of the encrypted data. Can overlap with @c dst.
+ * @param size Size of the encrypted data.
+ * @param msg_hmac HMAC of the message, cannot be NULL.
+ *
+ * @return Size of the decrypted data, -1 if an error was encountered.
+ */
+static int
+t_ax_decrypt_and_validate (struct CadetTunnel *t,
+                           void *dst, const void *src, size_t size,
+                           const struct GNUNET_CADET_Hash *msg_hmac)
+{
+  return 0;
+}
 
+
 /**
  * Create key material by doing ECDH on the local and remote ephemeral keys.
  *
@@ -2122,18 +2142,35 @@
  */
 void
 GCT_handle_encrypted (struct CadetTunnel *t,
-                      const struct GNUNET_CADET_Encrypted *msg)
+                      const struct GNUNET_MessageHeader *msg)
 {
-  size_t size = ntohs (msg->header.size);
-  size_t payload_size = size - sizeof (struct GNUNET_CADET_Encrypted);
+  size_t size = ntohs (msg->size);
+  size_t payload_size;
   int decrypted_size;
-  char cbuf [payload_size];
+  char cbuf [size];
+  uint16_t type = ntohs (msg->type);
   struct GNUNET_MessageHeader *msgh;
   unsigned int off;
 
-  decrypted_size = t_decrypt_and_validate (t, cbuf, &msg[1], payload_size,
-                                           msg->iv, &msg->hmac);
+  if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == type)
+  {
+    const struct GNUNET_CADET_Encrypted *emsg;
 
+    emsg = (struct GNUNET_CADET_Encrypted *) msg;
+    payload_size = size - sizeof (struct GNUNET_CADET_Encrypted);
+    decrypted_size = t_decrypt_and_validate (t, cbuf, &emsg[1], payload_size,
+                                             emsg->iv, &emsg->hmac);
+  }
+  else if (GNUNET_MESSAGE_TYPE_CADET_AX == type)
+  {
+    const struct GNUNET_CADET_AX *emsg;
+
+    emsg = (struct GNUNET_CADET_AX *) msg;
+    payload_size = size - sizeof (struct GNUNET_CADET_AX);
+    decrypted_size = t_ax_decrypt_and_validate (t, cbuf, &emsg[1],
+                                                payload_size, &emsg->hmac);
+  }
+
   if (-1 == decrypted_size)
   {
     GNUNET_break_op (0);
@@ -2159,21 +2196,6 @@
 
 
 /**
- * Decrypt axolotl and demultiplex by message type. Call appropriate handler
- * for a message towards a channel of a local tunnel.
- *
- * @param t Tunnel this message came on.
- * @param msg Message header.
- */
-void
-GCT_handle_ax (struct CadetTunnel *t,
-               const struct GNUNET_CADET_AX *msg)
-{
-  //FIXME ax
-}
-
-
-/**
  * Demultiplex an encapsulated KX message by message type.
  *
  * @param t Tunnel on which the message came.

Modified: gnunet/src/cadet/gnunet-service-cadet_tunnel.h
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_tunnel.h      2015-04-27 19:14:01 UTC 
(rev 35569)
+++ gnunet/src/cadet/gnunet-service-cadet_tunnel.h      2015-04-27 19:14:03 UTC 
(rev 35570)
@@ -270,7 +270,7 @@
 GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid);
 
 /**
- * Decrypt old format and demultiplex by message type. Call appropriate handler
+ * Decrypt and demultiplex by message type. Call appropriate handler
  * for a message towards a channel of a local tunnel.
  *
  * @param t Tunnel this message came on.
@@ -278,20 +278,9 @@
  */
 void
 GCT_handle_encrypted (struct CadetTunnel *t,
-                      const struct GNUNET_CADET_Encrypted *msg);
+                      const struct GNUNET_MessageHeader *msg);
 
-/**
- * Decrypt axolotl and demultiplex by message type. Call appropriate handler
- * for a message towards a channel of a local tunnel.
- *
- * @param t Tunnel this message came on.
- * @param msg Message header.
- */
-void
-GCT_handle_ax (struct CadetTunnel *t,
-               const struct GNUNET_CADET_AX *msg);
 
-
 /**
  * Demultiplex an encapsulated KX message by message type.
  *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]