Browse Source

more consistency checks to dhtproxy (client)

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
7f0f1a96af
  1. 46
      src/dhtproxy.cpp
  2. 2
      src/twister.cpp

46
src/dhtproxy.cpp

@ -252,11 +252,49 @@ namespace DhtProxy
libtorrent::error_code ec; libtorrent::error_code ec;
if (lazy_bdecode(reply.vchBencodedData.data(), reply.vchBencodedData.data() + if (lazy_bdecode(reply.vchBencodedData.data(), reply.vchBencodedData.data() +
reply.vchBencodedData.size(), v, ec, &pos) == 0 && v.type() == lazy_entry::list_t ) { reply.vchBencodedData.size(), v, ec, &pos) == 0 && v.type() == lazy_entry::list_t ) {
entry lst; // check signatures as we append to a libtorrent::entry list
lst = v; 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<char const*, int> 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", dbgprintf("DhtProxy::dhtgetReplyReceived: %zd entries from %s\n",
lst.list().size(), pfrom->addr.ToString().c_str()); values_list.size(), pfrom->addr.ToString().c_str());
dht_reply_data_alert rd(lst.list()); dht_reply_data_alert rd(values_list);
dhtgetMapPost(ih, rd); dhtgetMapPost(ih, rd);
} else { } else {
dbgprintf("DhtProxy::dhtgetReplyReceived: parsing error (data from %s)\n", dbgprintf("DhtProxy::dhtgetReplyReceived: parsing error (data from %s)\n",

2
src/twister.cpp

@ -482,6 +482,8 @@ void torrentManualTrackerUpdate(const std::string &username)
} else { } else {
torrent_handle h = getTorrentUser(username); torrent_handle h = getTorrentUser(username);
for( size_t i = 0; i < res.size(); i++ ) { for( size_t i = 0; i < res.size(); i++ ) {
if( res.at(i).type() != obj_type )
continue;
Object resDict = res.at(i).get_obj(); Object resDict = res.at(i).get_obj();
BOOST_FOREACH(const Pair& item, resDict) { BOOST_FOREACH(const Pair& item, resDict) {

Loading…
Cancel
Save