diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-13 15:29:44 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-13 15:29:44 +0000 |
commit | 3889e3c1941394df561ad4cb0b16a4e6b0eb69d9 (patch) | |
tree | b908c6a9305dc37df9b4105f42e7a0a1f5df7af7 | |
parent | c04d50e9c8c9375e2bba39c2de9fe864fdb17572 (diff) | |
download | gnunet-3889e3c1941394df561ad4cb0b16a4e6b0eb69d9.tar.gz gnunet-3889e3c1941394df561ad4cb0b16a4e6b0eb69d9.zip |
Check that you are not present in trail twice
Check that sender peer is a valid peer
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 214 | ||||
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 24 |
2 files changed, 122 insertions, 116 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 3d6d6f85e..b1435f248 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -1585,6 +1585,7 @@ GDS_NEIGHBOURS_send_trail_compression (struct GNUNET_PeerIdentity source_peer, | |||
1585 | * trail (can happen during trail setup), then return my lowest index. | 1585 | * trail (can happen during trail setup), then return my lowest index. |
1586 | * @param trail List of peers | 1586 | * @param trail List of peers |
1587 | * @return my_index if found | 1587 | * @return my_index if found |
1588 | * trail_length + 1 if an entry is present twice, It is an error. | ||
1588 | * -1 if no entry found. | 1589 | * -1 if no entry found. |
1589 | */ | 1590 | */ |
1590 | static int | 1591 | static int |
@@ -1592,14 +1593,28 @@ search_my_index (const struct GNUNET_PeerIdentity *trail, | |||
1592 | int trail_length) | 1593 | int trail_length) |
1593 | { | 1594 | { |
1594 | int i; | 1595 | int i; |
1595 | 1596 | int index_seen = trail_length + 1; | |
1597 | int flag = 0; | ||
1598 | |||
1596 | for (i = 0; i < trail_length; i++) | 1599 | for (i = 0; i < trail_length; i++) |
1597 | { | 1600 | { |
1598 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) | 1601 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i])) |
1599 | return i; | 1602 | { |
1603 | flag = 1; | ||
1604 | if(index_seen == (trail_length + 1)) | ||
1605 | index_seen = i; | ||
1606 | else | ||
1607 | { | ||
1608 | DEBUG("Entry is present twice in trail. Its not allowed\n"); | ||
1609 | } | ||
1610 | break; | ||
1611 | } | ||
1600 | } | 1612 | } |
1601 | 1613 | ||
1602 | return -1; | 1614 | if (1 == flag) |
1615 | return index_seen; | ||
1616 | else | ||
1617 | return -1; | ||
1603 | } | 1618 | } |
1604 | 1619 | ||
1605 | 1620 | ||
@@ -2425,6 +2440,12 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key, | |||
2425 | GNUNET_break (0); | 2440 | GNUNET_break (0); |
2426 | return; | 2441 | return; |
2427 | } | 2442 | } |
2443 | if ((get_path_length + 1) == current_path_index) | ||
2444 | { | ||
2445 | DEBUG ("Peer found twice in get path. Not allowed \n"); | ||
2446 | GNUNET_break (0); | ||
2447 | return; | ||
2448 | } | ||
2428 | } | 2449 | } |
2429 | if (0 == current_path_index) | 2450 | if (0 == current_path_index) |
2430 | { | 2451 | { |
@@ -3909,6 +3930,13 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3909 | current_path_index = search_my_index (get_path, getlen); | 3930 | current_path_index = search_my_index (get_path, getlen); |
3910 | if (-1 == current_path_index ) | 3931 | if (-1 == current_path_index ) |
3911 | { | 3932 | { |
3933 | DEBUG ("No entry found in get path.\n"); | ||
3934 | GNUNET_break (0); | ||
3935 | return GNUNET_SYSERR; | ||
3936 | } | ||
3937 | if((getlen + 1) == current_path_index) | ||
3938 | { | ||
3939 | DEBUG("Present twice in get path. Not allowed. \n"); | ||
3912 | GNUNET_break (0); | 3940 | GNUNET_break (0); |
3913 | return GNUNET_SYSERR; | 3941 | return GNUNET_SYSERR; |
3914 | } | 3942 | } |
@@ -3985,6 +4013,7 @@ get_local_best_known_next_hop (uint64_t final_dest_finger_val, | |||
3985 | return peer; | 4013 | return peer; |
3986 | } | 4014 | } |
3987 | 4015 | ||
4016 | |||
3988 | /* | 4017 | /* |
3989 | * Core handle for PeerTrailSetupMessage. | 4018 | * Core handle for PeerTrailSetupMessage. |
3990 | * @param cls closure | 4019 | * @param cls closure |
@@ -4050,18 +4079,7 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4050 | 4079 | ||
4051 | /* If I was the source and got the message back, then set trail length to 0.*/ | 4080 | /* If I was the source and got the message back, then set trail length to 0.*/ |
4052 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | 4081 | if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) |
4053 | { | 4082 | { |
4054 | /* IF (!) the peers know the destinations of the trails in their routing | ||
4055 | * table, then: | ||
4056 | * | ||
4057 | * This shoud only happen after 1 hop, since the first message is sent | ||
4058 | * to random friend, and we can happen to be on the best trail to the dest. | ||
4059 | * If the first friend selects someone else, the request should never come | ||
4060 | * back to us. | ||
4061 | * | ||
4062 | * (TODO) | ||
4063 | */ | ||
4064 | // GNUNET_break_op (1 == trail_length); | ||
4065 | trail_length = 0; | 4083 | trail_length = 0; |
4066 | } | 4084 | } |
4067 | 4085 | ||
@@ -4070,12 +4088,11 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4070 | { | 4088 | { |
4071 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) | 4089 | if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity)) |
4072 | { | 4090 | { |
4073 | trail_length = i; | 4091 | trail_length = i; /* Check that you add yourself again */ |
4074 | break; | 4092 | break; |
4075 | } | 4093 | } |
4076 | } | 4094 | } |
4077 | 4095 | ||
4078 | |||
4079 | /* Is my routing table full? */ | 4096 | /* Is my routing table full? */ |
4080 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) | 4097 | if (GNUNET_YES == GDS_ROUTING_threshold_reached()) |
4081 | { | 4098 | { |
@@ -4117,9 +4134,13 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4117 | } | 4134 | } |
4118 | 4135 | ||
4119 | if (trail_length > 0) | 4136 | if (trail_length > 0) |
4120 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &trail_peer_list[trail_length-1]); | 4137 | target_friend = |
4138 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
4139 | &trail_peer_list[trail_length-1]); | ||
4121 | else | 4140 | else |
4122 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source); | 4141 | target_friend = |
4142 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, &source); | ||
4143 | |||
4123 | if (NULL == target_friend) | 4144 | if (NULL == target_friend) |
4124 | { | 4145 | { |
4125 | GNUNET_break_op (0); | 4146 | GNUNET_break_op (0); |
@@ -4136,9 +4157,9 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4136 | else /* I'm not the final destination. */ | 4157 | else /* I'm not the final destination. */ |
4137 | { | 4158 | { |
4138 | GNUNET_assert (NULL != | 4159 | GNUNET_assert (NULL != |
4139 | (target_friend = | 4160 | (target_friend = |
4140 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 4161 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, |
4141 | &next_peer.next_hop))); | 4162 | &next_peer.next_hop))); |
4142 | 4163 | ||
4143 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) | 4164 | if (0 != GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source)) |
4144 | { | 4165 | { |
@@ -4167,83 +4188,8 @@ handle_dht_p2p_trail_setup (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4167 | return GNUNET_OK; | 4188 | return GNUNET_OK; |
4168 | } | 4189 | } |
4169 | 4190 | ||
4170 | #if 0 | ||
4171 | /* FIXME: here we are calculating my_index and comparing also in this function. | ||
4172 | And we are doing it again here in this function. Re factor the code. */ | ||
4173 | /** | ||
4174 | * FIXME: Should we call this function everywhere in all the handle functions | ||
4175 | * where we have a trail to verify from or a trail id. something like | ||
4176 | * if prev hop is not same then drop the message. | ||
4177 | * Check if sender_peer and peer from which we should receive the message are | ||
4178 | * same or different. | ||
4179 | * @param trail_peer_list List of peers in trail | ||
4180 | * @param trail_length Total number of peers in @a trail_peer_list | ||
4181 | * @param sender_peer Peer from which we got the message. | ||
4182 | * @param finger_identity Finger to which trail is setup. It is not part of trail. | ||
4183 | * @return #GNUNET_YES if sender_peer and peer from which we should receive the | ||
4184 | * message are different. | ||
4185 | * #GNUNET_NO if sender_peer and peer from which we should receive the | ||
4186 | * message are different. | ||
4187 | */ | ||
4188 | static int | ||
4189 | is_sender_peer_correct (const struct GNUNET_PeerIdentity *trail_peer_list, | ||
4190 | unsigned int trail_length, | ||
4191 | const struct GNUNET_PeerIdentity *sender_peer, | ||
4192 | struct GNUNET_PeerIdentity finger_identity, | ||
4193 | struct GNUNET_PeerIdentity source_peer) | ||
4194 | { | ||
4195 | int my_index; | ||
4196 | |||
4197 | /* I am the source peer. */ | ||
4198 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&source_peer, | ||
4199 | &my_identity))) | ||
4200 | { | ||
4201 | /* Is the first element of the trail is sender_peer.*/ | ||
4202 | if (trail_length > 0) | ||
4203 | { | ||
4204 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[0], | ||
4205 | sender_peer)) | ||
4206 | return GNUNET_NO; | ||
4207 | } | ||
4208 | else | ||
4209 | { | ||
4210 | /* Is finger the sender peer? */ | ||
4211 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (sender_peer, | ||
4212 | &finger_identity)) | ||
4213 | return GNUNET_NO; | ||
4214 | } | ||
4215 | } | ||
4216 | else | ||
4217 | { | ||
4218 | /* Get my current location in the trail. */ | ||
4219 | my_index = search_my_index (trail_peer_list, trail_length); | ||
4220 | if (-1 == my_index) | ||
4221 | return GNUNET_NO; | ||
4222 | |||
4223 | /* I am the last element in the trail. */ | ||
4224 | if ((trail_length - 1) == my_index) | ||
4225 | { | ||
4226 | /* Is finger the sender_peer? */ | ||
4227 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (sender_peer, | ||
4228 | &finger_identity)) | ||
4229 | return GNUNET_NO; | ||
4230 | } | ||
4231 | else | ||
4232 | { | ||
4233 | /* Is peer after me in trail the sender peer? */ | ||
4234 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (sender_peer, | ||
4235 | &trail_peer_list[my_index + 1])) | ||
4236 | return GNUNET_NO; | ||
4237 | } | ||
4238 | } | ||
4239 | return GNUNET_YES; | ||
4240 | } | ||
4241 | #endif | ||
4242 | |||
4243 | 4191 | ||
4244 | /** | 4192 | /** |
4245 | * FIXME: we should also add a case where we search if we are present in the trail | ||
4246 | * twice. | ||
4247 | * Core handle for p2p trail setup result messages. | 4193 | * Core handle for p2p trail setup result messages. |
4248 | * @param closure | 4194 | * @param closure |
4249 | * @param message message | 4195 | * @param message message |
@@ -4297,28 +4243,28 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4297 | ulitmate_destination_finger_value = | 4243 | ulitmate_destination_finger_value = |
4298 | GNUNET_ntohll (trail_result->ulitmate_destination_finger_value); | 4244 | GNUNET_ntohll (trail_result->ulitmate_destination_finger_value); |
4299 | 4245 | ||
4300 | /* Ensure that sender peer is the peer from which we were expecting the message. */ | ||
4301 | #if 0 | ||
4302 | if (GNUNET_NO == is_sender_peer_correct (trail_peer_list, | ||
4303 | trail_length, | ||
4304 | peer, finger_identity, querying_peer)) | ||
4305 | { | ||
4306 | GNUNET_break_op (0); | ||
4307 | return GNUNET_SYSERR; | ||
4308 | } | ||
4309 | #endif | ||
4310 | |||
4311 | /*TODO:URGENT Check if I am already present in the trail. If yes then its an error, | ||
4312 | as in trail setup we ensure that it should never happen. */ | ||
4313 | /* Am I the one who initiated the query? */ | 4246 | /* Am I the one who initiated the query? */ |
4314 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) | 4247 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity))) |
4315 | { | 4248 | { |
4249 | /* Check that you got the message from the correct peer. */ | ||
4250 | if (trail_length > 0) | ||
4251 | { | ||
4252 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[0], | ||
4253 | peer)); | ||
4254 | } | ||
4255 | else | ||
4256 | { | ||
4257 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | ||
4258 | peer)); | ||
4259 | } | ||
4260 | |||
4316 | /* If I am my own finger identity, error. */ | 4261 | /* If I am my own finger identity, error. */ |
4317 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | 4262 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) |
4318 | { | 4263 | { |
4319 | GNUNET_break_op (0); | 4264 | GNUNET_break_op (0); |
4320 | return GNUNET_SYSERR; | 4265 | return GNUNET_SYSERR; |
4321 | } | 4266 | } |
4267 | |||
4322 | GDS_ROUTING_add (trail_id, my_identity, *peer); | 4268 | GDS_ROUTING_add (trail_id, my_identity, *peer); |
4323 | finger_table_add (finger_identity, trail_peer_list, trail_length, | 4269 | finger_table_add (finger_identity, trail_peer_list, trail_length, |
4324 | is_predecessor, ulitmate_destination_finger_value, trail_id); | 4270 | is_predecessor, ulitmate_destination_finger_value, trail_id); |
@@ -4329,31 +4275,56 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p | |||
4329 | my_index = search_my_index (trail_peer_list, trail_length); | 4275 | my_index = search_my_index (trail_peer_list, trail_length); |
4330 | if (-1 == my_index) | 4276 | if (-1 == my_index) |
4331 | { | 4277 | { |
4278 | DEBUG ("Not found in trail\n"); | ||
4332 | GNUNET_break_op(0); | 4279 | GNUNET_break_op(0); |
4333 | return GNUNET_SYSERR; | 4280 | return GNUNET_SYSERR; |
4334 | } | 4281 | } |
4335 | 4282 | ||
4283 | if ((trail_length + 1) == my_index) | ||
4284 | { | ||
4285 | DEBUG ("Found twice in trail.\n"); | ||
4286 | GNUNET_break_op(0); | ||
4287 | return GNUNET_SYSERR; | ||
4288 | } | ||
4289 | |||
4336 | if (my_index == 0) | 4290 | if (my_index == 0) |
4291 | { | ||
4292 | if(trail_length > 1) | ||
4293 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[1], | ||
4294 | peer)); | ||
4295 | else | ||
4296 | GNUNET_assert(0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | ||
4297 | peer)); | ||
4337 | next_hop = trail_result->querying_peer; | 4298 | next_hop = trail_result->querying_peer; |
4299 | } | ||
4338 | else | 4300 | else |
4301 | { | ||
4302 | if(my_index == trail_length - 1) | ||
4303 | { | ||
4304 | GNUNET_assert(0 == | ||
4305 | GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, | ||
4306 | peer)); | ||
4307 | } | ||
4308 | else | ||
4309 | GNUNET_assert(0 == | ||
4310 | GNUNET_CRYPTO_cmp_peer_identity (&trail_peer_list[my_index + 1], | ||
4311 | peer)); | ||
4339 | next_hop = trail_peer_list[my_index - 1]; | 4312 | next_hop = trail_peer_list[my_index - 1]; |
4340 | 4313 | } | |
4314 | |||
4341 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); | 4315 | target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, &next_hop); |
4342 | if (NULL == target_friend) | 4316 | if (NULL == target_friend) |
4343 | { | 4317 | { |
4344 | GNUNET_break_op (0); | 4318 | GNUNET_break_op (0); |
4345 | return GNUNET_SYSERR; | 4319 | return GNUNET_SYSERR; |
4346 | } | 4320 | } |
4347 | |||
4348 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer), | 4321 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&(trail_result->querying_peer), |
4349 | &(trail_result->finger_identity)))) | 4322 | &(trail_result->finger_identity)))) |
4350 | { | 4323 | { |
4351 | GNUNET_break_op (0); | 4324 | GNUNET_break_op (0); |
4352 | return GNUNET_SYSERR; | 4325 | return GNUNET_SYSERR; |
4353 | } | 4326 | } |
4354 | |||
4355 | GDS_ROUTING_add (trail_id, next_hop, *peer); | 4327 | GDS_ROUTING_add (trail_id, next_hop, *peer); |
4356 | |||
4357 | GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, | 4328 | GDS_NEIGHBOURS_send_trail_setup_result (querying_peer, finger_identity, |
4358 | target_friend, trail_length, trail_peer_list, | 4329 | target_friend, trail_length, trail_peer_list, |
4359 | is_predecessor, | 4330 | is_predecessor, |
@@ -5197,10 +5168,16 @@ handle_dht_p2p_notify_new_successor(void *cls, | |||
5197 | my_index = search_my_index (trail, trail_length); | 5168 | my_index = search_my_index (trail, trail_length); |
5198 | if (-1 == my_index) | 5169 | if (-1 == my_index) |
5199 | { | 5170 | { |
5171 | DEBUG ("No entry found in trail\n"); | ||
5172 | GNUNET_break_op (0); | ||
5173 | return GNUNET_SYSERR; | ||
5174 | } | ||
5175 | if((trail_length + 1) == my_index) | ||
5176 | { | ||
5177 | DEBUG ("Found twice in trail.\n"); | ||
5200 | GNUNET_break_op (0); | 5178 | GNUNET_break_op (0); |
5201 | return GNUNET_SYSERR; | 5179 | return GNUNET_SYSERR; |
5202 | } | 5180 | } |
5203 | |||
5204 | if ((trail_length-1) == my_index) | 5181 | if ((trail_length-1) == my_index) |
5205 | next_hop = new_successor; | 5182 | next_hop = new_successor; |
5206 | else | 5183 | else |
@@ -5582,7 +5559,12 @@ handle_dht_p2p_add_trail (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
5582 | GNUNET_break_op (0); | 5559 | GNUNET_break_op (0); |
5583 | return GNUNET_SYSERR; | 5560 | return GNUNET_SYSERR; |
5584 | } | 5561 | } |
5585 | 5562 | if((trail_length + 1) == my_index) | |
5563 | { | ||
5564 | DEBUG ("Found twice in trail.\n"); | ||
5565 | GNUNET_break_op (0); | ||
5566 | return GNUNET_SYSERR; | ||
5567 | } | ||
5586 | if ((trail_length - 1) == my_index) | 5568 | if ((trail_length - 1) == my_index) |
5587 | { | 5569 | { |
5588 | next_hop = destination_peer; | 5570 | next_hop = destination_peer; |
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 00668c8fb..acc0453ac 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -85,6 +85,30 @@ struct Context | |||
85 | }; | 85 | }; |
86 | 86 | ||
87 | 87 | ||
88 | #if ENABLE_MALICIOUS | ||
89 | /** | ||
90 | * Context for a peer which should act maliciously. | ||
91 | */ | ||
92 | struct MaliciousContext | ||
93 | { | ||
94 | /** | ||
95 | * The linked peer context | ||
96 | */ | ||
97 | struct Context *ctx; | ||
98 | |||
99 | /** | ||
100 | * Handler to the DHT service | ||
101 | */ | ||
102 | struct GNUNET_DHT_Handle *dht; | ||
103 | }; | ||
104 | |||
105 | /** | ||
106 | * List of all the malicious peers contexts. | ||
107 | */ | ||
108 | struct Context **malicious_peer_contexts = NULL; | ||
109 | |||
110 | #endif | ||
111 | |||
88 | /** | 112 | /** |
89 | * Context for a peer which actively does DHT PUT/GET | 113 | * Context for a peer which actively does DHT PUT/GET |
90 | */ | 114 | */ |