From 15d8e3397c4c853b34ea6ec5d04cb4748514ed73 Mon Sep 17 00:00:00 2001 From: miguel Date: Sun, 18 Aug 2013 10:51:46 -0300 Subject: [PATCH] more consistency checks of userpost --- libtorrent/src/disk_io_thread.cpp | 33 +++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/libtorrent/src/disk_io_thread.cpp b/libtorrent/src/disk_io_thread.cpp index ccb9b1ac..dd842c7d 100644 --- a/libtorrent/src/disk_io_thread.cpp +++ b/libtorrent/src/disk_io_thread.cpp @@ -1086,14 +1086,39 @@ namespace libtorrent + piece_size, v, ec, &pos) == 0) { if( v.type() == lazy_entry::dict_t ) { - lazy_entry const* post = v.dict_find("userpost"); + lazy_entry const* post = v.dict_find_dict("userpost"); std::string sig = v.dict_find_string_value("sig_userpost"); std::string username = j.storage->info()->name(); - if( post && sig.size() ) { - std::pair postbuf = post->data_section(); - *hash_ok = verifySignature( + + if( !post || !sig.size() ) { +#ifdef TORRENT_DEBUG + printf("r_p_f_c_a_h: missing post or signature\n"); +#endif + } else { + std::string n = post->dict_find_string_value("n"); + int k = post->dict_find_int_value("k",-1); + + if( n != username ) { +#ifdef TORRENT_DEBUG + printf("r_p_f_c_a_h: expected username '%s' got '%s'\n", + username.c_str(), n.c_str()); +#endif + } else if( k != j.piece ) { +#ifdef TORRENT_DEBUG + printf("r_p_f_c_a_h: expected piece '%d' got '%d'\n", + j.piece, k); +#endif + } else { + std::pair postbuf = post->data_section(); + *hash_ok = verifySignature( std::string(postbuf.first,postbuf.second), username, sig); +#ifdef TORRENT_DEBUG + if( !(*hash_ok) ) { + printf("r_p_f_c_a_h: bad signature\n"); + } +#endif + } } } }