diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-10 14:22:35 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-01-10 14:22:35 +0100 |
commit | 8ee3c5121e87d8f25193ae6044d5818f4629fa1e (patch) | |
tree | eb0dd0250f11fb5f9bc788cef8ba55da90160698 /src/dht/gnunet-service-dht_neighbours.c | |
parent | d4641d36b885ba764945d6353ed71b7bc485c6ac (diff) | |
download | gnunet-8ee3c5121e87d8f25193ae6044d5818f4629fa1e.tar.gz gnunet-8ee3c5121e87d8f25193ae6044d5818f4629fa1e.zip |
-DHT: add path signature verification logic; tests pass, but logic remains dead
Diffstat (limited to 'src/dht/gnunet-service-dht_neighbours.c')
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 74 |
1 files changed, 66 insertions, 8 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 95d8bb032..cf150ea0c 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -1308,6 +1308,21 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd, | |||
1308 | unsigned int put_path_length = bd->put_path_length; | 1308 | unsigned int put_path_length = bd->put_path_length; |
1309 | 1309 | ||
1310 | GNUNET_assert (NULL != bf); | 1310 | GNUNET_assert (NULL != bf); |
1311 | #if SANITY_CHECKS | ||
1312 | if (0 != | ||
1313 | GNUNET_DHT_verify_path (&bd->key, | ||
1314 | bd->data, | ||
1315 | bd->data_size, | ||
1316 | bd->expiration_time, | ||
1317 | bd->put_path, | ||
1318 | bd->put_path_length, | ||
1319 | NULL, 0, /* get_path */ | ||
1320 | &my_identity)) | ||
1321 | { | ||
1322 | GNUNET_break_op (0); | ||
1323 | put_path_length = 0; | ||
1324 | } | ||
1325 | #endif | ||
1311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1312 | "Adding myself (%s) to PUT bloomfilter for %s\n", | 1327 | "Adding myself (%s) to PUT bloomfilter for %s\n", |
1313 | GNUNET_i2s (&my_identity), | 1328 | GNUNET_i2s (&my_identity), |
@@ -1564,13 +1579,43 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, | |||
1564 | struct PeerResultMessage *prm; | 1579 | struct PeerResultMessage *prm; |
1565 | struct GNUNET_DHT_PathElement *paths; | 1580 | struct GNUNET_DHT_PathElement *paths; |
1566 | size_t msize; | 1581 | size_t msize; |
1582 | unsigned int ppl = bd->put_path_length; | ||
1567 | 1583 | ||
1568 | msize = bd->data_size + (get_path_length + bd->put_path_length) | 1584 | #if SANITY_CHECKS |
1585 | if (0 != | ||
1586 | GNUNET_DHT_verify_path (&bd->key, | ||
1587 | bd->data, | ||
1588 | bd->data_size, | ||
1589 | bd->expiration_time, | ||
1590 | bd->put_path, | ||
1591 | bd->put_path_length, | ||
1592 | get_path, | ||
1593 | get_path_length, | ||
1594 | &my_identity)) | ||
1595 | { | ||
1596 | GNUNET_break_op (0); | ||
1597 | get_path_length = 0; | ||
1598 | ppl = 0; | ||
1599 | } | ||
1600 | #endif | ||
1601 | msize = bd->data_size + (get_path_length + ppl) | ||
1569 | * sizeof(struct GNUNET_DHT_PathElement); | 1602 | * sizeof(struct GNUNET_DHT_PathElement); |
1570 | if ( (msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || | 1603 | if ( (msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || |
1571 | (get_path_length > | 1604 | (get_path_length > |
1572 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || | 1605 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || |
1573 | (bd->put_path_length > | 1606 | (ppl > |
1607 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || | ||
1608 | (bd->data_size > GNUNET_MAX_MESSAGE_SIZE)) | ||
1609 | { | ||
1610 | ppl = 0; | ||
1611 | get_path_length = 0; | ||
1612 | msize = bd->data_size + (get_path_length + ppl) | ||
1613 | * sizeof(struct GNUNET_DHT_PathElement); | ||
1614 | } | ||
1615 | if ( (msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) || | ||
1616 | (get_path_length > | ||
1617 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || | ||
1618 | (ppl > | ||
1574 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || | 1619 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || |
1575 | (bd->data_size > GNUNET_MAX_MESSAGE_SIZE)) | 1620 | (bd->data_size > GNUNET_MAX_MESSAGE_SIZE)) |
1576 | { | 1621 | { |
@@ -1602,15 +1647,15 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, | |||
1602 | msize, | 1647 | msize, |
1603 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); | 1648 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT); |
1604 | prm->type = htonl (bd->type); | 1649 | prm->type = htonl (bd->type); |
1605 | prm->put_path_length = htonl (bd->put_path_length); | 1650 | prm->put_path_length = htonl (ppl); |
1606 | prm->get_path_length = htonl (get_path_length); | 1651 | prm->get_path_length = htonl (get_path_length); |
1607 | prm->expiration_time = GNUNET_TIME_absolute_hton (bd->expiration_time); | 1652 | prm->expiration_time = GNUNET_TIME_absolute_hton (bd->expiration_time); |
1608 | prm->key = *query_hash; | 1653 | prm->key = *query_hash; |
1609 | paths = (struct GNUNET_DHT_PathElement *) &prm[1]; | 1654 | paths = (struct GNUNET_DHT_PathElement *) &prm[1]; |
1610 | GNUNET_memcpy (paths, | 1655 | GNUNET_memcpy (paths, |
1611 | bd->put_path, | 1656 | bd->put_path, |
1612 | bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement)); | 1657 | ppl * sizeof(struct GNUNET_DHT_PathElement)); |
1613 | GNUNET_memcpy (&paths[bd->put_path_length], | 1658 | GNUNET_memcpy (&paths[ppl], |
1614 | get_path, | 1659 | get_path, |
1615 | get_path_length * sizeof(struct GNUNET_DHT_PathElement)); | 1660 | get_path_length * sizeof(struct GNUNET_DHT_PathElement)); |
1616 | /* 0 == get_path_length means path is not being tracked */ | 1661 | /* 0 == get_path_length means path is not being tracked */ |
@@ -1622,11 +1667,11 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, | |||
1622 | bd->data, | 1667 | bd->data, |
1623 | bd->data_size, | 1668 | bd->data_size, |
1624 | bd->expiration_time, | 1669 | bd->expiration_time, |
1625 | &paths[bd->put_path_length + get_path_length - 1].pred, | 1670 | &paths[ppl + get_path_length - 1].pred, |
1626 | pi->id, | 1671 | pi->id, |
1627 | &paths[bd->put_path_length + get_path_length - 1].sig); | 1672 | &paths[ppl + get_path_length - 1].sig); |
1628 | } | 1673 | } |
1629 | GNUNET_memcpy (&paths[bd->put_path_length + get_path_length], | 1674 | GNUNET_memcpy (&paths[ppl + get_path_length], |
1630 | bd->data, | 1675 | bd->data, |
1631 | bd->data_size); | 1676 | bd->data_size); |
1632 | GNUNET_MQ_send (pi->mq, | 1677 | GNUNET_MQ_send (pi->mq, |
@@ -1798,6 +1843,19 @@ handle_dht_p2p_put (void *cls, | |||
1798 | GNUNET_memcmp (&pp[i].pred, | 1843 | GNUNET_memcmp (&pp[i].pred, |
1799 | peer->id)); | 1844 | peer->id)); |
1800 | } | 1845 | } |
1846 | if (0 != | ||
1847 | GNUNET_DHT_verify_path (&bd.key, | ||
1848 | bd.data, | ||
1849 | bd.data_size, | ||
1850 | bd.expiration_time, | ||
1851 | bd.put_path, | ||
1852 | putlen, | ||
1853 | NULL, 0, /* get_path */ | ||
1854 | &my_identity)) | ||
1855 | { | ||
1856 | GNUNET_break_op (0); | ||
1857 | putlen = 0; | ||
1858 | } | ||
1801 | #endif | 1859 | #endif |
1802 | GNUNET_memcpy (pp, | 1860 | GNUNET_memcpy (pp, |
1803 | put_path, | 1861 | put_path, |