improved error handling, and ensures that keyring is always kept consistent

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6395 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-05-31 19:16:04 +00:00
parent 4b21232beb
commit e11f60150c
5 changed files with 32 additions and 13 deletions

View File

@ -1610,6 +1610,13 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
continue ; continue ;
} }
if(res->second._key_index >= _pubring->nkeys || PGPIdType(_pubring->keys[res->second._key_index].key_id) != *it)
{
std::cerr << "(EE) PGPHandler:: can't remove key " << (*it).toStdString() << ". Inconsistency found." << std::endl;
error_code = PGP_KEYRING_REMOVAL_ERROR_DATA_INCONSISTENCY ;
return false ;
}
// Move the last key to the freed place. This deletes the key in place. // Move the last key to the freed place. This deletes the key in place.
// //
ops_keyring_remove_key(_pubring,res->second._key_index) ; ops_keyring_remove_key(_pubring,res->second._key_index) ;
@ -1631,13 +1638,6 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list<PGPIdType>& keys_to_re
} }
} }
if(_public_keyring_map.size() != _pubring->nkeys)
{
std::cerr << "Error after removing keys. Operation cancelled." << std::endl;
// todo
}
// Everything went well, sync back the keyring on disk // Everything went well, sync back the keyring on disk
_pubring_changed = true ; _pubring_changed = true ;

View File

@ -108,6 +108,7 @@ const uint32_t PGP_KEYRING_REMOVAL_ERROR_NO_ERROR = 0x20 ;
const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANT_REMOVE_SECRET_KEYS = 0x21 ; const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANT_REMOVE_SECRET_KEYS = 0x21 ;
const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANNOT_CREATE_BACKUP = 0x22 ; const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANNOT_CREATE_BACKUP = 0x22 ;
const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANNOT_WRITE_BACKUP = 0x23 ; const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANNOT_WRITE_BACKUP = 0x23 ;
const uint32_t PGP_KEYRING_REMOVAL_ERROR_DATA_INCONSISTENCY = 0x24 ;
/* LinkType Flags */ /* LinkType Flags */
@ -253,6 +254,8 @@ class RsPeers
/* Peer Details (Net & Auth) */ /* Peer Details (Net & Auth) */
virtual std::string getOwnId() = 0; virtual std::string getOwnId() = 0;
virtual bool haveSecretKey(const std::string& gpg_id) = 0 ;
virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0; virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0;
virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0; virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0;
//virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0; //virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0;

View File

@ -237,6 +237,10 @@ bool p3Peers::isFriend(const std::string &ssl_id)
return mPeerMgr->isFriend(ssl_id); return mPeerMgr->isFriend(ssl_id);
} }
bool p3Peers::haveSecretKey(const std::string& id)
{
return AuthGPG::getAuthGPG()->haveSecretKey(id) ;
}
/* There are too many dependancies of this function /* There are too many dependancies of this function
* to shift it immeidately * to shift it immeidately

View File

@ -46,6 +46,7 @@ virtual bool OthersChanged();
/* Peer Details (Net & Auth) */ /* Peer Details (Net & Auth) */
virtual std::string getOwnId(); virtual std::string getOwnId();
virtual bool haveSecretKey(const std::string& gpg_id) ;
virtual bool getOnlineList(std::list<std::string> &ids); virtual bool getOnlineList(std::list<std::string> &ids);

View File

@ -250,6 +250,11 @@ void NetworkDialog::removeUnusedKeys()
{ {
rsPeers->getPeerDetails(*it,details) ; rsPeers->getPeerDetails(*it,details) ;
if(rsPeers->haveSecretKey(*it))
{
std::cerr << "Skipping public/secret key pair " << *it << std::endl;
continue ;
}
if(now > THREE_MONTHS + details.lastUsed) if(now > THREE_MONTHS + details.lastUsed)
{ {
std::cerr << "Adding " << *it << " to pre-selection." << std::endl; std::cerr << "Adding " << *it << " to pre-selection." << std::endl;
@ -269,6 +274,9 @@ void NetworkDialog::removeUnusedKeys()
std::string backup_file ; std::string backup_file ;
uint32_t error_code ; uint32_t error_code ;
if(selected.empty())
return ;
if( rsPeers->removeKeysFromPGPKeyring(selected,backup_file,error_code) ) if( rsPeers->removeKeysFromPGPKeyring(selected,backup_file,error_code) )
QMessageBox::information(NULL,tr("Keyring info"),tr("%1 keys have been deleted from your keyring. \nFor security, your keyring was previously backed-up to file \n\n").arg(selected.size())+QString::fromStdString(backup_file) ) ; QMessageBox::information(NULL,tr("Keyring info"),tr("%1 keys have been deleted from your keyring. \nFor security, your keyring was previously backed-up to file \n\n").arg(selected.size())+QString::fromStdString(backup_file) ) ;
else else
@ -285,10 +293,13 @@ void NetworkDialog::removeUnusedKeys()
case PGP_KEYRING_REMOVAL_ERROR_CANNOT_WRITE_BACKUP: case PGP_KEYRING_REMOVAL_ERROR_CANNOT_WRITE_BACKUP:
case PGP_KEYRING_REMOVAL_ERROR_CANNOT_CREATE_BACKUP: error_string = tr("Cannot create backup file. Check for permissions in pgp directory, disk space, etc.") ; case PGP_KEYRING_REMOVAL_ERROR_CANNOT_CREATE_BACKUP: error_string = tr("Cannot create backup file. Check for permissions in pgp directory, disk space, etc.") ;
break ; break ;
case PGP_KEYRING_REMOVAL_ERROR_DATA_INCONSISTENCY: error_string = tr("Data iconsistency in the keyring. This is most probably a bug. Please contact the developers.") ;
break ;
} }
QMessageBox::warning(NULL,tr("Keyring info"),tr("Key removal has failed. Your keyring remains intact.\n\nReported error: ")+error_string ) ; QMessageBox::warning(NULL,tr("Keyring info"),tr("Key removal has failed. Your keyring remains intact.\n\nReported error: ")+error_string ) ;
} }
insertConnect() ;
} }
void NetworkDialog::denyFriend() void NetworkDialog::denyFriend()
@ -355,7 +366,7 @@ void NetworkDialog::updateDisplay()
/* get the list of Neighbours from the RsIface. */ /* get the list of Neighbours from the RsIface. */
void NetworkDialog::insertConnect() void NetworkDialog::insertConnect()
{ {
static time_t last_time = 0 ; // static time_t last_time = 0 ;
if (!rsPeers) if (!rsPeers)
return; return;
@ -366,12 +377,12 @@ void NetworkDialog::insertConnect()
ui.unvalidGPGkeyWidget->hide(); ui.unvalidGPGkeyWidget->hide();
} }
// Because this is called from a qt signal, there's no limitation between calls. // // Because this is called from a qt signal, there's no limitation between calls.
time_t now = time(NULL); time_t now = time(NULL);
if(last_time + 5 > now) // never update more often then every 5 seconds. // if(last_time + 5 > now) // never update more often then every 5 seconds.
return ; // return ;
//
last_time = now ; // last_time = now ;
std::list<std::string> neighs; //these are GPG ids std::list<std::string> neighs; //these are GPG ids
std::list<std::string>::iterator it; std::list<std::string>::iterator it;