mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-08 22:08:00 +00:00
implement piece verification using old signatures. now i can reenable banning peers due to bad pieces.
This commit is contained in:
parent
8ec4b3e16e
commit
2c256b6edb
14
TODO
14
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)
|
||||
|
@ -3308,9 +3308,6 @@ namespace libtorrent
|
||||
for (std::set<void*>::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<policy::peer*>(*i);
|
||||
if (p == 0) continue;
|
||||
TORRENT_ASSERT(p->in_use);
|
||||
|
@ -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<unsigned char> > 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<unsigned char> > 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<char const*, int> 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<char const*, int> 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");
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user