diff options
author | Julius Bünger <buenger@mytum.de> | 2015-02-23 14:35:02 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-02-23 14:35:02 +0000 |
commit | 7f424af3f7d3d3271feafecc6330185e76f95ee2 (patch) | |
tree | 548341830a1648620a0697533136423ef5ca95a9 /src/rps | |
parent | f63e66fdbf2b8f066b2cf447e5291cbaa898cb87 (diff) | |
download | gnunet-7f424af3f7d3d3271feafecc6330185e76f95ee2.tar.gz gnunet-7f424af3f7d3d3271feafecc6330185e76f95ee2.zip |
- sending act malicious message
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/Makefile.am | 19 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps.c | 108 | ||||
-rw-r--r-- | src/rps/rps.h | 2 | ||||
-rw-r--r-- | src/rps/rps_api.c | 57 | ||||
-rw-r--r-- | src/rps/test_rps.conf | 2 | ||||
-rw-r--r-- | src/rps/test_rps_malicious_1.c | 9 |
6 files changed, 156 insertions, 41 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index 488cea152..fe086e59c 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am | |||
@@ -58,9 +58,17 @@ gnunet_service_rps_LDADD = \ | |||
58 | 58 | ||
59 | if HAVE_TESTING | 59 | if HAVE_TESTING |
60 | check_PROGRAMS = \ | 60 | check_PROGRAMS = \ |
61 | test_rps_multipeer | 61 | test_rps_multipeer \ |
62 | test_rps_malicious_1 | ||
62 | endif | 63 | endif |
63 | 64 | ||
65 | ld_rps_test_lib = \ | ||
66 | libgnunetrps.la \ | ||
67 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
68 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
69 | -lm | ||
70 | |||
71 | |||
64 | if ENABLE_TEST_RUN | 72 | if ENABLE_TEST_RUN |
65 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 73 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
66 | TESTS = $(check_PROGRAMS) | 74 | TESTS = $(check_PROGRAMS) |
@@ -68,12 +76,11 @@ endif | |||
68 | 76 | ||
69 | test_rps_multipeer_SOURCES = \ | 77 | test_rps_multipeer_SOURCES = \ |
70 | test_rps_multipeer.c | 78 | test_rps_multipeer.c |
71 | test_rps_multipeer_LDADD = \ | 79 | test_rps_multipeer_LDADD = $(ld_rps_test_lib) |
72 | libgnunetrps.la \ | ||
73 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
74 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
75 | -lm | ||
76 | 80 | ||
81 | test_rps_malicious_1_SOURCES = \ | ||
82 | test_rps_malicious_1.c | ||
83 | test_rps_malicious_1_LDADD = $(ld_rps_test_lib) | ||
77 | 84 | ||
78 | EXTRA_DIST = \ | 85 | EXTRA_DIST = \ |
79 | test_rps.conf | 86 | test_rps.conf |
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 5b564da1b..4ff5ca5e6 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -356,6 +356,33 @@ uint32_t pending_pull_reply_list_size; | |||
356 | uint32_t num_hist_update_tasks; | 356 | uint32_t num_hist_update_tasks; |
357 | 357 | ||
358 | 358 | ||
359 | #if ENABLE_MALICIOUS | ||
360 | /** | ||
361 | * Type of malicious peer | ||
362 | * | ||
363 | * 0 Don't act malicious at all - Default | ||
364 | * 1 Try to maximise representation | ||
365 | * 2 Try to partition the network | ||
366 | */ | ||
367 | uint32_t mal_type = 0; | ||
368 | |||
369 | /** | ||
370 | * Other malicious peers | ||
371 | */ | ||
372 | static struct GNUNET_PeerIdentity *mal_peers; | ||
373 | |||
374 | /** | ||
375 | * Number of other malicious peers | ||
376 | */ | ||
377 | static uint32_t num_mal_peers; | ||
378 | |||
379 | /** | ||
380 | * If type is 2 this is the attacked peer | ||
381 | */ | ||
382 | struct struct GNUNET_PeerIdentity attacked_peer; | ||
383 | #endif /* ENABLE_MALICIOUS */ | ||
384 | |||
385 | |||
359 | /*********************************************************************** | 386 | /*********************************************************************** |
360 | * /Globals | 387 | * /Globals |
361 | ***********************************************************************/ | 388 | ***********************************************************************/ |
@@ -1239,6 +1266,7 @@ handle_peer_pull_reply (void *cls, | |||
1239 | GNUNET_break_op (0); | 1266 | GNUNET_break_op (0); |
1240 | return GNUNET_SYSERR; | 1267 | return GNUNET_SYSERR; |
1241 | } | 1268 | } |
1269 | |||
1242 | in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg; | 1270 | in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg; |
1243 | if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | 1271 | if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / |
1244 | sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers)) | 1272 | sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers)) |
@@ -1309,42 +1337,64 @@ handle_peer_act_malicious (void *cls, | |||
1309 | void **channel_ctx, | 1337 | void **channel_ctx, |
1310 | const struct GNUNET_MessageHeader *msg) | 1338 | const struct GNUNET_MessageHeader *msg) |
1311 | { | 1339 | { |
1340 | struct GNUNET_PeerIdentity *peers; | ||
1341 | |||
1312 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received\n"); | 1342 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received\n"); |
1313 | 1343 | ||
1314 | /* Check for protocol violation */ | 1344 | /* Check for protocol violation */ |
1315 | //if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size)) | 1345 | if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size)) |
1316 | //{ | 1346 | { |
1317 | // GNUNET_break_op (0); | 1347 | GNUNET_break_op (0); |
1318 | // return GNUNET_SYSERR; | 1348 | return GNUNET_SYSERR; |
1319 | //} | 1349 | } |
1320 | //in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg; | ||
1321 | //if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | ||
1322 | // sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers)) | ||
1323 | //{ | ||
1324 | // LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1325 | // "message says it sends %" PRIu64 " peers, have space for %i peers\n", | ||
1326 | // ntohl (in_msg->num_peers), | ||
1327 | // (ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | ||
1328 | // sizeof (struct GNUNET_PeerIdentity)); | ||
1329 | // GNUNET_break_op (0); | ||
1330 | // return GNUNET_SYSERR; | ||
1331 | //} | ||
1332 | 1350 | ||
1333 | //sender = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info ( | 1351 | in_msg = (struct GNUNET_RPS_CS_ActMaliciousMessage *) msg; |
1334 | // (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER); | 1352 | if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) / |
1335 | // // Guess simply casting isn't the nicest way... | 1353 | sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers)) |
1336 | // // FIXME wait for cadet to change this function | 1354 | { |
1337 | //sender_ctx = get_peer_ctx (peer_map, sender); | 1355 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1356 | "message says it sends %" PRIu64 " peers, have space for %i peers\n", | ||
1357 | ntohl (in_msg->num_peers), | ||
1358 | (ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) / | ||
1359 | sizeof (struct GNUNET_PeerIdentity)); | ||
1360 | GNUNET_break_op (0); | ||
1361 | return GNUNET_SYSERR; | ||
1362 | } | ||
1338 | 1363 | ||
1339 | //if (GNUNET_YES == get_peer_flag (sender_ctx, PULL_REPLY_PENDING)) | 1364 | sender = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info ( |
1340 | //{ | 1365 | (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER); |
1341 | // GNUNET_break_op (0); | 1366 | // Guess simply casting isn't the nicest way... |
1342 | // return GNUNET_OK; | 1367 | // FIXME wait for cadet to change this function |
1343 | //} | 1368 | sender_ctx = get_peer_ctx (peer_map, sender); |
1369 | |||
1370 | if (GNUNET_YES == get_peer_flag (sender_ctx, PULL_REPLY_PENDING)) | ||
1371 | { | ||
1372 | GNUNET_break_op (0); | ||
1373 | return GNUNET_OK; | ||
1374 | } | ||
1344 | 1375 | ||
1345 | /* Do actual logic */ | 1376 | /* Do actual logic */ |
1377 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1378 | num_peers = ntohl (in_msg->num_peers); | ||
1379 | mal_type = ntohl (in_msg->type); | ||
1380 | |||
1381 | if (1 == mal_type) | ||
1382 | { /* Try to maximise representation */ | ||
1383 | num_mal_peers = ntohl (in_msg->num_peers); | ||
1384 | mal_peers = GNUNET_new_array (num_mal_peers, | ||
1385 | struct GNUNET_PeerIdentity); | ||
1386 | memcpy (mal_peers, peers, num_mal_peers); | ||
1387 | } | ||
1388 | else if (2 == mal_type) | ||
1389 | { /* Try to partition the network */ | ||
1390 | num_mal_peers = ntohl (in_msg->num_peers) - 1; | ||
1391 | mal_peers = GNUNET_new_array (num_mal_peers, | ||
1392 | struct GNUNET_PeerIdentity); | ||
1393 | memcpy (mal_peers, peers, num_mal_peers); | ||
1394 | attacked_peer = peers[num_mal_peers]; | ||
1395 | } | ||
1346 | } | 1396 | } |
1347 | #endif | 1397 | #endif /* ENABLE_MALICIOUS */ |
1348 | 1398 | ||
1349 | 1399 | ||
1350 | /** | 1400 | /** |
@@ -1940,7 +1990,7 @@ run (void *cls, | |||
1940 | {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0}, | 1990 | {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0}, |
1941 | #if ENABLE_MALICIOUS | 1991 | #if ENABLE_MALICIOUS |
1942 | {&handle_peer_act_malicious, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0}, | 1992 | {&handle_peer_act_malicious, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0}, |
1943 | #endif | 1993 | #endif /* ENABLE_MALICIOUS */ |
1944 | {NULL, 0, 0} | 1994 | {NULL, 0, 0} |
1945 | }; | 1995 | }; |
1946 | 1996 | ||
diff --git a/src/rps/rps.h b/src/rps/rps.h index 9aaa19a0c..eace8d5f1 100644 --- a/src/rps/rps.h +++ b/src/rps/rps.h | |||
@@ -124,6 +124,7 @@ struct GNUNET_RPS_CS_SeedMessage | |||
124 | /* Followed by num_peers * GNUNET_PeerIdentity */ | 124 | /* Followed by num_peers * GNUNET_PeerIdentity */ |
125 | }; | 125 | }; |
126 | 126 | ||
127 | #if ENABLE_MALICIOUS | ||
127 | /** | 128 | /** |
128 | * Message from client to service to turn service malicious. | 129 | * Message from client to service to turn service malicious. |
129 | */ | 130 | */ |
@@ -150,5 +151,6 @@ struct GNUNET_RPS_CS_ActMaliciousMessage | |||
150 | 151 | ||
151 | /* Followed by num_peers * GNUNET_PeerIdentity */ | 152 | /* Followed by num_peers * GNUNET_PeerIdentity */ |
152 | }; | 153 | }; |
154 | #endif /* ENABLE_MALICIOUS */ | ||
153 | 155 | ||
154 | GNUNET_NETWORK_STRUCT_END | 156 | GNUNET_NETWORK_STRUCT_END |
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 42102eef7..30f0a75c5 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -311,8 +311,61 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | |||
311 | uint32_t num_peers, | 311 | uint32_t num_peers, |
312 | const struct GNUNET_PeerIdentity *ids) | 312 | const struct GNUNET_PeerIdentity *ids) |
313 | { | 313 | { |
314 | uint32_t size_needed; | ||
315 | uint32_t num_peers_max; | ||
316 | const struct GNUNET_PeerIdentity *tmp_peer_pointer; | ||
317 | struct GNUNET_MQ_Envelope *ev; | ||
318 | struct GNUNET_RPS_CS_ActMaliciousMessage *msg; | ||
319 | |||
320 | unsigned int i; | ||
321 | |||
322 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
323 | "Client turns malicious with %" PRIX32 " other peers:\n", | ||
324 | n); | ||
325 | for (i = 0 ; i < n ; i++) | ||
326 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
327 | "%u. peer: %s\n", | ||
328 | i, | ||
329 | GNUNET_i2s (&ids[i])); | ||
330 | |||
331 | /* The actual size the message occupies */ | ||
332 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | ||
333 | n * sizeof (struct GNUNET_PeerIdentity); | ||
334 | /* The number of peers that fits in one message together with | ||
335 | * the respective header */ | ||
336 | num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE - | ||
337 | sizeof (struct GNUNET_RPS_CS_SeedMessage)) / | ||
338 | sizeof (struct GNUNET_PeerIdentity); | ||
339 | tmp_peer_pointer = ids; | ||
340 | |||
341 | while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed) | ||
342 | { | ||
343 | ev = GNUNET_MQ_msg_extra (msg, | ||
344 | num_peers_max * sizeof (struct GNUNET_PeerIdentity), | ||
345 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); | ||
346 | msg->type = ntohl (type); | ||
347 | msg->num_peers = ntohl (num_peers_max); | ||
348 | memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct GNUNET_PeerIdentity)); | ||
349 | GNUNET_MQ_send (h->mq, ev); | ||
350 | |||
351 | n -= num_peers_max; | ||
352 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | ||
353 | n * sizeof (struct GNUNET_PeerIdentity); | ||
354 | /* Set pointer to beginning of next block of num_peers_max peers */ | ||
355 | tmp_peer_pointer = &ids[num_peers_max]; | ||
356 | } | ||
357 | |||
358 | ev = GNUNET_MQ_msg_extra (msg, | ||
359 | n * sizeof (struct GNUNET_PeerIdentity), | ||
360 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); | ||
361 | msg->type = htonl (type); | ||
362 | msg->num_peers = htonl (n); | ||
363 | memcpy (&msg[1], tmp_peer_pointer, n * sizeof (struct GNUNET_PeerIdentity)); | ||
364 | |||
365 | GNUNET_MQ_send (h->mq, ev); | ||
366 | |||
314 | } | 367 | } |
315 | #endif | 368 | #endif /* ENABLE_MALICIOUS */ |
316 | 369 | ||
317 | 370 | ||
318 | /** | 371 | /** |
@@ -335,7 +388,7 @@ GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) | |||
335 | void | 388 | void |
336 | GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) | 389 | GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) |
337 | { | 390 | { |
338 | if ( NULL != h->conn ) | 391 | if (NULL != h->conn) |
339 | GNUNET_CLIENT_disconnect (h->conn); | 392 | GNUNET_CLIENT_disconnect (h->conn); |
340 | } | 393 | } |
341 | 394 | ||
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf index 1d8df0878..9db6711ea 100644 --- a/src/rps/test_rps.conf +++ b/src/rps/test_rps.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | [rps] | 1 | [rps] |
2 | #PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p | 2 | #PREFIX = valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p |
3 | #BINARY = gnunet-service-rps | 3 | #BINARY = gnunet-service-rps |
4 | UNIXPATH = /tmp/gnunet-service-rps.sock | 4 | UNIXPATH = /tmp/gnunet-service-rps.sock |
5 | HOME = $SERVICEHOME | 5 | HOME = $SERVICEHOME |
diff --git a/src/rps/test_rps_malicious_1.c b/src/rps/test_rps_malicious_1.c index 9e05e707a..304e46973 100644 --- a/src/rps/test_rps_malicious_1.c +++ b/src/rps/test_rps_malicious_1.c | |||
@@ -235,14 +235,17 @@ rps_connect_adapter (void *cls, | |||
235 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 235 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
236 | { | 236 | { |
237 | struct GNUNET_RPS_Handle *h; | 237 | struct GNUNET_RPS_Handle *h; |
238 | #if ENABLE_MALICIOUS | ||
238 | uint64_t num_mal_peers; | 239 | uint64_t num_mal_peers; |
239 | 240 | #endif /* ENABLE_MALICIOUS */ | |
240 | num_mal_peers = round (portion * NUM_PEERS); | ||
241 | 241 | ||
242 | h = GNUNET_RPS_connect (cfg); | 242 | h = GNUNET_RPS_connect (cfg); |
243 | |||
243 | #if ENABLE_MALICIOUS | 244 | #if ENABLE_MALICIOUS |
245 | num_mal_peers = round (portion * NUM_PEERS); | ||
244 | GNUNET_RPS_act_malicious (h, htonl (1), htonl (num_mal_peers), rps_peer_ids); | 246 | GNUNET_RPS_act_malicious (h, htonl (1), htonl (num_mal_peers), rps_peer_ids); |
245 | #endif | 247 | #endif /* ENABLE_MALICIOUS */ |
248 | |||
246 | return h; | 249 | return h; |
247 | } | 250 | } |
248 | 251 | ||