Skip to content

Commit

Permalink
NetDb: handle LeaseSets unsupported signatures
Browse files Browse the repository at this point in the history
Reject DatabaseLookup messages for LeaseSets with signature types other
than EDDSA_SHA512_ED25519.

Referencing monero-project#755
  • Loading branch information
coneiric committed Feb 1, 2018
1 parent d216e0b commit 0db45ba
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/core/router/net_db/impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -710,37 +710,54 @@ void NetDb::HandleDatabaseLookupMsg(
lookup_type == DATABASE_LOOKUP_TYPE_NORMAL_LOOKUP) {
auto router = FindRouter(ident);
if (router) {
if (router->GetRouterIdentity().GetSigningKeyType() == SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) {
if (router->GetRouterIdentity().GetSigningKeyType() == SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519) {
LOG(debug) << "NetDb: requested RouterInfo " << key.data() << " found";
router->LoadBuffer();
if (router->GetBuffer())
reply_msg = CreateDatabaseStoreMsg(router);
} else {
LOG(debug) << "NetDb: requested RouterInfo " << key.data() << " unreachable with unsupported signature type";
// Set router as unreachable
router->SetCaps(core::RouterInfoTraits::Cap::Unreachable);
// Get list of excluded routers
} else {
LOG(debug) << "NetDb: requested RouterInfo " << key.data() << " unreachable with unsupported signature type";
// Set router as unreachable
router->SetCaps(core::RouterInfoTraits::Cap::Unreachable);
// Get list of excluded routers
std::set<IdentHash> excluded_routers;
for (std::uint16_t i = 0; i < num_excluded; i++) {
excluded_routers.insert(excluded);
excluded += 32;
}
// Set DatabaseSearchReply message with floodfill routers closest to the destination
reply_msg = CreateDatabaseSearchReply(
ident,
GetClosestFloodfills(
ident,
3, // TODO(anonimal): enumerate or algorithm
excluded_routers));
}
// Set DatabaseSearchReply message with floodfill routers closest to the destination
reply_msg = CreateDatabaseSearchReply(
ident,
GetClosestFloodfills(
ident,
3, // TODO(anonimal): enumerate or algorithm
excluded_routers));
}
}
}
if (!reply_msg && (lookup_type == DATABASE_LOOKUP_TYPE_LEASESET_LOOKUP ||
lookup_type == DATABASE_LOOKUP_TYPE_NORMAL_LOOKUP)) {
auto lease_set = FindLeaseSet(ident);
if (lease_set) { // we don't send back our LeaseSets
LOG(debug) << "NetDb: requested LeaseSet " << key.data() << " found";
reply_msg = CreateDatabaseStoreMsg(lease_set);
if (lease_set->GetIdentity().GetSigningKeyType() == SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519){
LOG(debug) << "NetDb: requested LeaseSet " << key.data() << " found";
reply_msg = CreateDatabaseStoreMsg(lease_set);
} else {
LOG(debug) << "NetDb: requested LeaseSet " << key.data() << " found with unsupported signature type";
// Get list of excluded routers
std::set<IdentHash> excluded_routers;
for (std::uint16_t i = 0; i < num_excluded; i++) {
excluded_routers.insert(excluded);
excluded += 32;
}
// Set DatabaseSearchReply message with floodfill routers closest to the destination
reply_msg = CreateDatabaseSearchReply(
ident,
GetClosestFloodfills(
ident,
3, // TODO(anonimal): enumerate or algorithm
excluded_routers));
}
}
}
if (!reply_msg) {
Expand Down

0 comments on commit 0db45ba

Please sign in to comment.