diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index 8e5b793a5..6962e30c4 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -1610,6 +1610,13 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list& keys_to_re 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. // ops_keyring_remove_key(_pubring,res->second._key_index) ; @@ -1631,13 +1638,6 @@ bool PGPHandler::removeKeysFromPGPKeyring(const std::list& 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 _pubring_changed = true ; diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index e8673b2f0..cf6be359f 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -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_CANNOT_CREATE_BACKUP = 0x22 ; const uint32_t PGP_KEYRING_REMOVAL_ERROR_CANNOT_WRITE_BACKUP = 0x23 ; +const uint32_t PGP_KEYRING_REMOVAL_ERROR_DATA_INCONSISTENCY = 0x24 ; /* LinkType Flags */ @@ -253,6 +254,8 @@ class RsPeers /* Peer Details (Net & Auth) */ virtual std::string getOwnId() = 0; + virtual bool haveSecretKey(const std::string& gpg_id) = 0 ; + virtual bool getOnlineList(std::list &ssl_ids) = 0; virtual bool getFriendList(std::list &ssl_ids) = 0; //virtual bool getOthersList(std::list &ssl_ids) = 0; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 4d33f5b01..2c7a560b0 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -237,6 +237,10 @@ bool p3Peers::isFriend(const std::string &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 * to shift it immeidately diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index f99064a45..482154adc 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -46,6 +46,7 @@ virtual bool OthersChanged(); /* Peer Details (Net & Auth) */ virtual std::string getOwnId(); + virtual bool haveSecretKey(const std::string& gpg_id) ; virtual bool getOnlineList(std::list &ids); diff --git a/retroshare-gui/src/gui/NetworkDialog.cpp b/retroshare-gui/src/gui/NetworkDialog.cpp index 99bdfa940..a1842d89d 100644 --- a/retroshare-gui/src/gui/NetworkDialog.cpp +++ b/retroshare-gui/src/gui/NetworkDialog.cpp @@ -250,6 +250,11 @@ void NetworkDialog::removeUnusedKeys() { 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) { std::cerr << "Adding " << *it << " to pre-selection." << std::endl; @@ -269,6 +274,9 @@ void NetworkDialog::removeUnusedKeys() std::string backup_file ; uint32_t error_code ; + if(selected.empty()) + return ; + 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) ) ; else @@ -285,10 +293,13 @@ void NetworkDialog::removeUnusedKeys() 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.") ; 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 ) ; } + insertConnect() ; } void NetworkDialog::denyFriend() @@ -355,7 +366,7 @@ void NetworkDialog::updateDisplay() /* get the list of Neighbours from the RsIface. */ void NetworkDialog::insertConnect() { - static time_t last_time = 0 ; +// static time_t last_time = 0 ; if (!rsPeers) return; @@ -366,12 +377,12 @@ void NetworkDialog::insertConnect() 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); - if(last_time + 5 > now) // never update more often then every 5 seconds. - return ; - - last_time = now ; +// if(last_time + 5 > now) // never update more often then every 5 seconds. +// return ; +// +// last_time = now ; std::list neighs; //these are GPG ids std::list::iterator it;