diff --git a/TODO b/TODO index fcea3716..95a9353a 100644 --- a/TODO +++ b/TODO @@ -1,17 +1,3 @@ -- Take care of posts using older public key when key is replaced. - -notes: not very difficult, GetTransaction must receive a maximum block number to search the -transaction (we get this from post["height"]). another txIndex should be set to speedup lookup -(key in db includes the number of the block that changed tx so previous one can be found). -pseudocode: - getTxIndex( key = "userX" ) => block h contains this tx; - while( h > max_h ) - getTxIndex( "userX_h" ) => block h contains the previous tx -=> GetTransation: new parameter maxHeight done! - -- Until old public key is properly used, disable banning torrent peers due to bad piece hashes. -note: torrent.cpp line 3286 (function piece_failed), iteration to ban peers is disabled (continue). - - Count UTF8 chars in acceptSignedPost to proper limit the 140 characters. - Encrypt user_data (which contains all DMs) diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index ac76de61..3b7f62a8 100644 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -3308,9 +3308,6 @@ namespace libtorrent for (std::set::iterator i = peers.begin() , end(peers.end()); i != end; ++i) { - // [MF] FIXME FIXME: BANNING BY FAILED HASH DISABLED - READ TODO! - continue; - policy::peer* p = static_cast(*i); if (p == 0) continue; TORRENT_ASSERT(p->in_use); diff --git a/src/twister.cpp b/src/twister.cpp index 8784e6f5..f36515df 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -606,44 +606,33 @@ std::string createSignature(std::string const &strMessage, std::string const &st } -bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey) +bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey, int maxHeight) { - { - CKeyID keyID; - if( pwalletMain->GetKeyIdFromUsername(strUsername, keyID) ) { - if( !pwalletMain->GetPubKey(keyID, pubkey) ) { - // error? should not have failed. - } - } + CTransaction txOut; + uint256 hashBlock; + if( !GetTransaction(strUsername, txOut, hashBlock, maxHeight) ) { + //printf("getUserPubKey: user unknown '%s'\n", strUsername.c_str()); + return false; } + std::vector< std::vector > vData; + if( !txOut.pubKey.ExtractPushData(vData) || vData.size() < 1 ) { + printf("getUserPubKey: broken pubkey for user '%s'\n", strUsername.c_str()); + return false; + } + pubkey = CPubKey(vData[0]); if( !pubkey.IsValid() ) { - CTransaction txOut; - uint256 hashBlock; - if( !GetTransaction(strUsername, txOut, hashBlock) ) { - //printf("getUserPubKey: user unknown '%s'\n", strUsername.c_str()); - return false; - } - - std::vector< std::vector > vData; - if( !txOut.pubKey.ExtractPushData(vData) || vData.size() < 1 ) { - printf("getUserPubKey: broken pubkey for user '%s'\n", strUsername.c_str()); - return false; - } - pubkey = CPubKey(vData[0]); - if( !pubkey.IsValid() ) { - printf("getUserPubKey: invalid pubkey for user '%s'\n", strUsername.c_str()); - return false; - } + printf("getUserPubKey: invalid pubkey for user '%s'\n", strUsername.c_str()); + return false; } return true; } -bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign) +bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign, int maxHeight) { CPubKey pubkey; - if( !getUserPubKey(strUsername, pubkey) ) { + if( !getUserPubKey(strUsername, pubkey, maxHeight) ) { printf("verifySignature: no pubkey for user '%s'\n", strUsername.c_str()); return false; } @@ -761,7 +750,7 @@ bool acceptSignedPost(char const *data, int data_size, std::string username, int std::pair postbuf = post->data_section(); ret = verifySignature( std::string(postbuf.first,postbuf.second), - username, sig); + username, sig, height); if( !ret ) { sprintf(errbuf,"bad post signature"); } else { @@ -771,11 +760,12 @@ bool acceptSignedPost(char const *data, int data_size, std::string username, int if( rt ) { if( flags ) (*flags) |= USERPOST_FLAG_RT; std::string username_rt = rt->dict_find_string_value("n"); + int height_rt = rt->dict_find_int_value("height",-1); std::pair rtbuf = rt->data_section(); ret = verifySignature( std::string(rtbuf.first,rtbuf.second), - username_rt, sig_rt); + username_rt, sig_rt, height_rt); if( !ret ) { sprintf(errbuf,"bad RT signature"); } diff --git a/src/twister.h b/src/twister.h index 913b985d..a2b29e58 100644 --- a/src/twister.h +++ b/src/twister.h @@ -23,10 +23,10 @@ public: void startSessionTorrent(boost::thread_group& threadGroup); void stopSessionTorrent(); -bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey); +bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey, int maxHeight = -1); std::string createSignature(std::string const &strMessage, CKeyID &keyID); std::string createSignature(std::string const &strMessage, std::string const &strUsername); -bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign); +bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign, int maxHeight = -1); bool acceptSignedPost(char const *data, int data_size, std::string username, int seq, std::string &errmsg, boost::uint32_t *flags); bool validatePostNumberForUser(std::string const &username, int k);