aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-11 14:07:47 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-11 14:07:47 +0000
commit4248b31f8dd35814514b279701c2483d05c132b8 (patch)
tree65e68211ed9ad01caafd63b33d3fc1541f95640c /src/mesh
parentfd6abc8eccbbf839d877062ff63cab510f3ae707 (diff)
downloadgnunet-4248b31f8dd35814514b279701c2483d05c132b8.tar.gz
gnunet-4248b31f8dd35814514b279701c2483d05c132b8.zip
- fix encryption/decryption visisbility
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c24
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c131
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.h14
3 files changed, 103 insertions, 66 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 369704171..07e75ab87 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -438,7 +438,7 @@ message_sent (void *cls,
438 * @return Previous peer in the connection. 438 * @return Previous peer in the connection.
439 */ 439 */
440static struct MeshPeer * 440static struct MeshPeer *
441get_prev_hop (struct MeshConnection *c) 441get_prev_hop (const struct MeshConnection *c)
442{ 442{
443 GNUNET_PEER_Id id; 443 GNUNET_PEER_Id id;
444 444
@@ -459,7 +459,7 @@ get_prev_hop (struct MeshConnection *c)
459 * @return Next peer in the connection. 459 * @return Next peer in the connection.
460 */ 460 */
461static struct MeshPeer * 461static struct MeshPeer *
462get_next_hop (struct MeshConnection *c) 462get_next_hop (const struct MeshConnection *c)
463{ 463{
464 GNUNET_PEER_Id id; 464 GNUNET_PEER_Id id;
465 465
@@ -1305,7 +1305,6 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1305 int fwd) 1305 int fwd)
1306{ 1306{
1307 struct MeshConnection *c; 1307 struct MeshConnection *c;
1308 struct MeshTunnel3 *t;
1309 struct MeshPeer *neighbor; 1308 struct MeshPeer *neighbor;
1310 struct MeshFlowControl *fc; 1309 struct MeshFlowControl *fc;
1311 uint32_t pid; 1310 uint32_t pid;
@@ -1335,7 +1334,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1335 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING connection unknown\n"); 1334 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING connection unknown\n");
1336 return GNUNET_OK; 1335 return GNUNET_OK;
1337 } 1336 }
1338 t = c->t; 1337
1339 fc = fwd ? &c->bck_fc : &c->fwd_fc; 1338 fc = fwd ? &c->bck_fc : &c->fwd_fc;
1340 1339
1341 /* Check if origin is as expected */ 1340 /* Check if origin is as expected */
@@ -1372,24 +1371,17 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1372 /* Is this message for us? */ 1371 /* Is this message for us? */
1373 if (GMC_is_terminal (c, fwd)) 1372 if (GMC_is_terminal (c, fwd))
1374 { 1373 {
1375 size_t dsize = size - sizeof (struct GNUNET_MESH_Encrypted);
1376 char cbuf[dsize];
1377 struct GNUNET_MessageHeader *msgh;
1378 unsigned int off;
1379
1380 /* TODO signature verification */ 1374 /* TODO signature verification */
1381 LOG (GNUNET_ERROR_TYPE_DEBUG, " message for us!\n"); 1375 LOG (GNUNET_ERROR_TYPE_DEBUG, " message for us!\n");
1382 GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO); 1376 GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO);
1383 1377
1384 fc->last_pid_recv = pid; 1378 if (NULL == c->t)
1385 tunnel_decrypt (t, cbuf, &msg[1], dsize, msg->iv, fwd);
1386 off = 0;
1387 while (off < dsize)
1388 { 1379 {
1389 msgh = (struct GNUNET_MessageHeader *) &cbuf[off]; 1380 GNUNET_break (0);
1390 handle_decrypted (t, msgh, fwd); 1381 return GNUNET_OK;
1391 off += ntohs (msgh->size);
1392 } 1382 }
1383 fc->last_pid_recv = pid;
1384 GMT_handle_encrypted (c->t, msg, fwd);
1393 send_ack (c, NULL, fwd); 1385 send_ack (c, NULL, fwd);
1394 return GNUNET_OK; 1386 return GNUNET_OK;
1395 } 1387 }
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 634a4d7f1..51baebf9b 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -257,6 +257,48 @@ tunnel_get_connection (struct MeshTunnel3 *t, int fwd)
257} 257}
258 258
259 259
260/**
261 * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
262 * Encrypt data with the tunnel key.
263 * Make static?
264 *
265 * @param t Tunnel whose key to use.
266 * @param dst Destination for the GMT_encrypted data.
267 * @param src Source of the plaintext.
268 * @param size Size of the plaintext.
269 * @param iv Initialization Vector to use.
270 * @param fwd Is this a fwd message?
271 */
272static void
273GMT_encrypt (struct MeshTunnel3 *t,
274 void *dst, const void *src,
275 size_t size, uint64_t iv, int fwd)
276{
277 memcpy (dst, src, size);
278}
279
280
281/**
282 * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
283 * Decrypt data with the tunnel key.
284 * Make static?
285 *
286 * @param t Tunnel whose key to use.
287 * @param dst Destination for the plaintext.
288 * @param src Source of the GMT_encrypted data.
289 * @param size Size of the GMT_encrypted data.
290 * @param iv Initialization Vector to use.
291 * @param fwd Is this a fwd message?
292 */
293static void
294GMT_decrypt (struct MeshTunnel3 *t,
295 void *dst, const void *src,
296 size_t size, uint64_t iv, int fwd)
297{
298 memcpy (dst, src, size);
299}
300
301
260void 302void
261handle_data (struct MeshTunnel3 *t, 303handle_data (struct MeshTunnel3 *t,
262 const struct GNUNET_MESH_Data *msg, 304 const struct GNUNET_MESH_Data *msg,
@@ -417,9 +459,6 @@ handle_ch_destroy (struct MeshTunnel3 *t,
417 GMCH_handle_destroy (ch, msg, fwd); 459 GMCH_handle_destroy (ch, msg, fwd);
418} 460}
419 461
420/******************************************************************************/
421/******************************** API ***********************************/
422/******************************************************************************/
423 462
424/** 463/**
425 * Demultiplex by message type and call appropriate handler for a message 464 * Demultiplex by message type and call appropriate handler for a message
@@ -429,10 +468,10 @@ handle_ch_destroy (struct MeshTunnel3 *t,
429 * @param msgh Message header. 468 * @param msgh Message header.
430 * @param fwd Is this message fwd? 469 * @param fwd Is this message fwd?
431 */ 470 */
432void 471static void
433GMT_handle_decrypted (struct MeshTunnel3 *t, 472handle_GMT_decrypted (struct MeshTunnel3 *t,
434 const struct GNUNET_MessageHeader *msgh, 473 const struct GNUNET_MessageHeader *msgh,
435 int fwd) 474 int fwd)
436{ 475{
437 uint16_t type; 476 uint16_t type;
438 477
@@ -478,6 +517,40 @@ GMT_handle_decrypted (struct MeshTunnel3 *t,
478 } 517 }
479} 518}
480 519
520/******************************************************************************/
521/******************************** API ***********************************/
522/******************************************************************************/
523
524
525/**
526 * Decrypt and demultiplex by message type. Call appropriate handler
527 * for every message.
528 *
529 * @param t Tunnel this message came on.
530 * @param msgh Encrypted message.
531 * @param fwd Is this message fwd?
532 */
533void
534GMT_handle_GMT_encrypted (struct MeshTunnel3 *t,
535 const struct GNUNET_MESH_Encrypted *msg,
536 int fwd)
537{
538 size_t size = ntohs (msg->header.size);
539 size_t payload_size = size - sizeof (struct GNUNET_MESH_Encrypted);
540 char cbuf[payload_size];
541 struct GNUNET_MessageHeader *msgh;
542 unsigned int off;
543
544 GMT_decrypt (t, cbuf, &msg[1], payload_size, msg->iv, fwd);
545 off = 0;
546 while (off < payload_size)
547 {
548 msgh = (struct GNUNET_MessageHeader *) &cbuf[off];
549 handle_GMT_decrypted (t, msgh, fwd);
550 off += ntohs (msgh->size);
551 }
552}
553
481 554
482/** 555/**
483 * Cache a message to be sent once tunnel is online. 556 * Cache a message to be sent once tunnel is online.
@@ -868,48 +941,6 @@ GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p)
868 941
869 942
870/** 943/**
871 * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
872 * Encrypt data with the tunnel key.
873 * Make static?
874 *
875 * @param t Tunnel whose key to use.
876 * @param dst Destination for the encrypted data.
877 * @param src Source of the plaintext.
878 * @param size Size of the plaintext.
879 * @param iv Initialization Vector to use.
880 * @param fwd Is this a fwd message?
881 */
882void
883GMT_encrypt (struct MeshTunnel3 *t,
884 void *dst, const void *src,
885 size_t size, uint64_t iv, int fwd)
886{
887 memcpy (dst, src, size);
888}
889
890
891/**
892 * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
893 * Decrypt data with the tunnel key.
894 * Make static?
895 *
896 * @param t Tunnel whose key to use.
897 * @param dst Destination for the plaintext.
898 * @param src Source of the encrypted data.
899 * @param size Size of the encrypted data.
900 * @param iv Initialization Vector to use.
901 * @param fwd Is this a fwd message?
902 */
903void
904GMT_decrypt (struct MeshTunnel3 *t,
905 void *dst, const void *src,
906 size_t size, uint64_t iv, int fwd)
907{
908 memcpy (dst, src, size);
909}
910
911
912/**
913 * Count established (ready) connections of a tunnel. 944 * Count established (ready) connections of a tunnel.
914 * 945 *
915 * @param t Tunnel on which to count. 946 * @param t Tunnel on which to count.
@@ -1056,7 +1087,7 @@ GMT_get_next_chid (struct MeshTunnel3 *t)
1056 1087
1057 1088
1058/** 1089/**
1059 * Sends an already built message on a tunnel, encrypting it and 1090 * Sends an already built message on a tunnel, GMT_encrypting it and
1060 * choosing the best connection. 1091 * choosing the best connection.
1061 * 1092 *
1062 * @param message Message to send. Function modifies it. 1093 * @param message Message to send. Function modifies it.
diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h
index 49533edf6..c5c13b28b 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.h
+++ b/src/mesh/gnunet-service-mesh_tunnel.h
@@ -79,6 +79,7 @@ struct MeshTunnel3;
79 79
80#include "gnunet-service-mesh_channel.h" 80#include "gnunet-service-mesh_channel.h"
81#include "gnunet-service-mesh_connection.h" 81#include "gnunet-service-mesh_connection.h"
82#include "gnunet-service-mesh_peer.h"
82 83
83 84
84/******************************************************************************/ 85/******************************************************************************/
@@ -197,6 +198,19 @@ GMT_remove_channel (struct MeshTunnel3 *t, struct MeshChannel *ch);
197struct MeshChannel * 198struct MeshChannel *
198GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid); 199GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
199 200
201/**
202 * Decrypt and demultiplex by message type. Call appropriate handler
203 * for a message
204 * towards a channel of a local tunnel.
205 *
206 * @param t Tunnel this message came on.
207 * @param msgh Message header.
208 * @param fwd Is this message fwd?
209 */
210void
211GMT_handle_encrypted (struct MeshTunnel3 *t,
212 const struct GNUNET_MESH_Encrypted *msg,
213 int fwd);
200 214
201/** 215/**
202 * Cache a message to be sent once tunnel is online. 216 * Cache a message to be sent once tunnel is online.