diff --git a/src/dhtproxy.cpp b/src/dhtproxy.cpp index 2baf84f0..6e45729c 100644 --- a/src/dhtproxy.cpp +++ b/src/dhtproxy.cpp @@ -252,11 +252,49 @@ namespace DhtProxy libtorrent::error_code ec; if (lazy_bdecode(reply.vchBencodedData.data(), reply.vchBencodedData.data() + reply.vchBencodedData.size(), v, ec, &pos) == 0 && v.type() == lazy_entry::list_t ) { - entry lst; - lst = v; + // check signatures as we append to a libtorrent::entry list + entry::list_type values_list; + for (int i = 0; i < v.list_size(); ++i) + { + lazy_entry const* e = v.list_at(i); + if (e->type() != lazy_entry::dict_t) continue; + + lazy_entry const* p = e->dict_find("p"); + if( !p || p->type() != lazy_entry::dict_t ) continue; + + lazy_entry const* target = p->dict_find("target"); + if( !target || target->type() != lazy_entry::dict_t ) continue; + + lazy_entry const* r = target->dict_find("r"); + lazy_entry const* t = target->dict_find("t"); + if( !r || r->type() != lazy_entry::string_t ) continue; + if( !t || t->type() != lazy_entry::string_t ) continue; + + if( r->string_value() == "tracker" && t->string_value() == "m" ) { + // tracker reply has no signature + } else { + lazy_entry const* sig_p = e->dict_find("sig_p"); + lazy_entry const* sig_user = e->dict_find("sig_user"); + if (!sig_p || !sig_user) continue; + if (sig_p->type() != lazy_entry::string_t) continue; + if (sig_user->type() != lazy_entry::string_t) continue; + + std::pair buf = p->data_section(); + if (!verifySignature(std::string(buf.first,buf.second), + sig_user->string_value(), + sig_p->string_value())) { + dbgprintf("DhtProxy::dhtgetReplyReceived: verifySignature failed\n"); + continue; + } + } + + values_list.push_back(entry()); + values_list.back() = *e; + } + dbgprintf("DhtProxy::dhtgetReplyReceived: %zd entries from %s\n", - lst.list().size(), pfrom->addr.ToString().c_str()); - dht_reply_data_alert rd(lst.list()); + values_list.size(), pfrom->addr.ToString().c_str()); + dht_reply_data_alert rd(values_list); dhtgetMapPost(ih, rd); } else { dbgprintf("DhtProxy::dhtgetReplyReceived: parsing error (data from %s)\n", diff --git a/src/twister.cpp b/src/twister.cpp index 75102afd..2aaff17a 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -482,6 +482,8 @@ void torrentManualTrackerUpdate(const std::string &username) } else { torrent_handle h = getTorrentUser(username); for( size_t i = 0; i < res.size(); i++ ) { + if( res.at(i).type() != obj_type ) + continue; Object resDict = res.at(i).get_obj(); BOOST_FOREACH(const Pair& item, resDict) {