- Added a drop-down item to allow removing unused keys, in the Network dialog.

- added key removal method in OpenPGP-SDK
- improved FriendSelectionDialog/Widget to enable select all/none keys, and show non friend keys
- added safe key removal method in PGPHandler. Removed keys from other locations will not cause errors.
- added backup system to public keyring, impossibility to remove public parts of owned secret keys, etc.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6382 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-05-29 21:32:02 +00:00
parent 02890c737a
commit 0266329dc8
17 changed files with 314 additions and 81 deletions

View file

@ -31,6 +31,7 @@
#include "common/vmessagebox.h"
#include "common/RSTreeWidgetItem.h"
#include <gui/common/FriendSelectionDialog.h>
#include "NetworkDialog.h"
//#include "TrustView.h"
#include "NetworkView.h"
@ -45,6 +46,7 @@
#define IMAGE_LOADCERT ":/images/loadcert16.png"
#define IMAGE_PEERDETAILS ":/images/peerdetails_16x16.png"
#define IMAGE_AUTH ":/images/encrypted16.png"
#define IMAGE_CLEAN_UNUSED ":/images/deletemail24.png"
#define IMAGE_MAKEFRIEND ":/images/user/add_user16.png"
#define IMAGE_EXPORT ":/images/exportpeers_16x16.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png"
@ -218,45 +220,77 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint /*point*/ )
if(peer_id != rsPeers->getGPGOwnId())
{
if(detail.accept_connection)
{
QAction* denyFriendAct = new QAction(QIcon(IMAGE_DENIED), tr( "Deny friend" ), contextMnu );
connect( denyFriendAct , SIGNAL( triggered() ), this, SLOT( denyFriend() ) );
contextMnu->addAction( denyFriendAct);
}
contextMnu->addAction(QIcon(IMAGE_DENIED), tr("Deny friend"), this, SLOT(denyFriend()));
else // not a friend
{
QAction* makefriendAct = new QAction(QIcon(IMAGE_MAKEFRIEND), tr( "Make friend" ), contextMnu );
connect( makefriendAct , SIGNAL( triggered() ), this, SLOT( makeFriend() ) );
contextMnu->addAction( makefriendAct);
#ifdef TODO
if(detail.validLvl > RS_TRUST_LVL_MARGINAL) // it's a denied old friend.
{
QAction* deleteCertAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Delete certificate" ), contextMnu );
connect( deleteCertAct, SIGNAL( triggered() ), this, SLOT( deleteCert() ) );
contextMnu->addAction( deleteCertAct );
}
#endif
}
contextMnu->addAction(QIcon(IMAGE_MAKEFRIEND), tr("Make friend"), this, SLOT(makeFriend()));
}
if(peer_id == rsPeers->getGPGOwnId())
{
QAction* exportcertAct = new QAction(QIcon(IMAGE_EXPORT), tr( "Export my Cert" ), contextMnu );
connect( exportcertAct , SIGNAL( triggered() ), this, SLOT( on_actionExportKey_activated() ) );
contextMnu->addAction( exportcertAct);
}
QAction* peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Peer details..." ), contextMnu );
connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( peerdetails() ) );
contextMnu->addAction( peerdetailsAct);
contextMnu->addAction(QIcon(IMAGE_EXPORT), tr("Export my certificate..."), this, SLOT(on_actionExportKey_activated()));
contextMnu->addAction(QIcon(IMAGE_PEERDETAILS), tr("Peer details..."), this, SLOT(peerdetails()));
contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
contextMnu->addSeparator() ;
contextMnu->addAction(QIcon(IMAGE_CLEAN_UNUSED), tr("Remove unused keys..."), this, SLOT(removeUnusedKeys()));
contextMnu->exec(QCursor::pos());
}
void NetworkDialog::removeUnusedKeys()
{
std::list<std::string> pre_selected ;
std::list<std::string> ids ;
rsPeers->getGPGAllList(ids) ;
RsPeerDetails details ;
time_t now = time(NULL) ;
time_t THREE_MONTHS = 86400*31*3 ;
for(std::list<std::string>::const_iterator it(ids.begin());it!=ids.end();++it)
{
rsPeers->getPeerDetails(*it,details) ;
if(now > THREE_MONTHS + details.lastUsed)
{
std::cerr << "Adding " << *it << " to pre-selection." << std::endl;
pre_selected.push_back(*it) ;
}
}
std::list<std::string> selected = FriendSelectionDialog::selectFriends(NULL,
tr("Clean keyring"),
tr("The selected keys below haven't been used in the last 3 months. \nDo you want to delete them permanently ? \n\nNotes: Your old keyring will be backed up.\n The removal may fail when running multiple Retroshare instances on the same machine."),FriendSelectionWidget::MODUS_CHECK,FriendSelectionWidget::SHOW_GPG | FriendSelectionWidget::SHOW_NON_FRIEND_GPG,
FriendSelectionWidget::IDTYPE_GPG, pre_selected) ;
std::cerr << "Removing these keys from the keyring: " << std::endl;
for(std::list<std::string>::const_iterator it(selected.begin());it!=selected.end();++it)
std::cerr << " " << *it << std::endl;
std::string backup_file ;
uint32_t 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) ) ;
else
{
QString error_string ;
switch(error_code)
{
default:
case PGP_KEYRING_REMOVAL_ERROR_NO_ERROR: error_string = tr("Unknown error") ;
break ;
case PGP_KEYRING_REMOVAL_ERROR_CANT_REMOVE_SECRET_KEYS: error_string = tr("Cannot delete secret keys") ;
break ;
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 ;
}
QMessageBox::warning(NULL,tr("Keyring info"),tr("Key removal has failed. Your keyring remains intact.\n\nReported error: ")+error_string ) ;
}
}
void NetworkDialog::denyFriend()
{
QTreeWidgetItem *wi = getCurrentNeighbour();

View file

@ -66,6 +66,7 @@ protected:
private slots:
void removeUnusedKeys() ;
void makeFriend() ;
void denyFriend() ;
void deleteCert() ;

View file

@ -106,7 +106,7 @@ void ChatLobbyDialog::inviteFriends()
{
std::cerr << "Inviting friends" << std::endl;
std::list<std::string> ids = FriendSelectionDialog::selectFriends() ;
std::list<std::string> ids = FriendSelectionDialog::selectFriends(NULL,tr("Invite friends"),tr("Select friends to invite:")) ;
std::cerr << "Inviting these friends:" << std::endl;

View file

@ -4,29 +4,40 @@
#include <QDialogButtonBox>
#include "FriendSelectionDialog.h"
std::list<std::string> FriendSelectionDialog::selectFriends()
std::list<std::string> FriendSelectionDialog::selectFriends(QWidget *parent,const QString& caption,const QString& header_text,
FriendSelectionWidget::Modus modus,
FriendSelectionWidget::ShowTypes show_type,
FriendSelectionWidget::IdType pre_selected_id_type,
const std::list<std::string>& pre_selected_ids)
{
FriendSelectionDialog dialog ;
FriendSelectionDialog dialog(parent,header_text,modus,show_type,pre_selected_id_type,pre_selected_ids) ;
dialog.friends_widget->start() ;
dialog.setWindowTitle(tr("Choose some friends")) ;
dialog.friends_widget->setSelectedIds(pre_selected_id_type,pre_selected_ids,true) ;
dialog.setWindowTitle(caption) ;
if(QDialog::Rejected == dialog.exec())
return std::list<std::string>() ;
std::list<std::string> ids ;
dialog.friends_widget->selectedSslIds(ids,false) ;
dialog.friends_widget->selectedIds(pre_selected_id_type,ids,false) ;
return ids ;
}
FriendSelectionDialog::FriendSelectionDialog(QWidget *parent)
FriendSelectionDialog::FriendSelectionDialog(QWidget *parent,const QString& header_text,
FriendSelectionWidget::Modus modus,
FriendSelectionWidget::ShowTypes show_type,
FriendSelectionWidget::IdType pre_selected_id_type,
const std::list<std::string>& pre_selected_ids)
: QDialog(parent)
{
friends_widget = new FriendSelectionWidget(this) ;
friends_widget->setHeaderText(tr("Contacts:"));
friends_widget->setModus(FriendSelectionWidget::MODUS_CHECK);
friends_widget->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL);
friends_widget->setHeaderText(header_text);
friends_widget->setModus(modus) ;
friends_widget->setShowType(show_type) ;
QLayout *l = new QVBoxLayout ;
setLayout(l) ;

View file

@ -6,11 +6,16 @@
class FriendSelectionDialog : public QDialog
{
public:
static std::list<std::string> selectFriends() ;
static std::list<std::string> selectFriends(QWidget *parent,const QString& caption,const QString& header_string,
FriendSelectionWidget::Modus modus = FriendSelectionWidget::MODUS_MULTI,
FriendSelectionWidget::ShowTypes = FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL,
FriendSelectionWidget::IdType pre_selected_id_type = FriendSelectionWidget::IDTYPE_SSL,
const std::list<std::string>& pre_selected_ids = std::list<std::string>()) ;
private:
virtual ~FriendSelectionDialog() ;
FriendSelectionDialog(QWidget *parent = NULL) ;
FriendSelectionDialog(QWidget *parent,const QString& header_string,FriendSelectionWidget::Modus modus,FriendSelectionWidget::ShowTypes show_type,
FriendSelectionWidget::IdType pre_selected_id_type,
const std::list<std::string>& pre_selected_ids) ;
FriendSelectionWidget *friends_widget ;
};

View file

@ -89,6 +89,8 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) :
connect(ui->friendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
connect(ui->friendList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int)));
connect(ui->friendList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int)));
connect(ui->selectAll_PB, SIGNAL(clicked()), this, SLOT(selectAll()));
connect(ui->deselectAll_PB, SIGNAL(clicked()), this, SLOT(deselectAll()));
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString)));
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillList()));
@ -148,6 +150,17 @@ void FriendSelectionWidget::setModus(Modus modus)
break;
}
if(modus == MODUS_CHECK)
{
ui->selectAll_PB->setHidden(false) ;
ui->deselectAll_PB->setHidden(false) ;
}
else
{
ui->selectAll_PB->setHidden(true) ;
ui->deselectAll_PB->setHidden(true) ;
}
fillList();
}
@ -221,7 +234,7 @@ void FriendSelectionWidget::fillList()
}
std::list<std::string> gpgIdsSelected;
if (mShowTypes & SHOW_GPG) {
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) {
selectedGpgIds(gpgIdsSelected, true);
}
@ -235,10 +248,15 @@ void FriendSelectionWidget::fillList()
std::list<std::string> gpgIds;
std::list<std::string>::iterator gpgIt;
rsPeers->getGPGAcceptedList(gpgIds);
if(mShowTypes & SHOW_NON_FRIEND_GPG)
rsPeers->getGPGAllList(gpgIds);
else
rsPeers->getGPGAcceptedList(gpgIds);
std::list<std::string> sslIds;
std::list<std::string>::iterator sslIt;
if ((mShowTypes & (SHOW_SSL | SHOW_GPG)) == SHOW_SSL) {
rsPeers->getFriendList(sslIds);
}
@ -295,7 +313,7 @@ void FriendSelectionWidget::fillList()
}
}
if (mShowTypes & SHOW_GPG) {
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) {
// iterate through gpg ids
for (gpgIt = gpgIds.begin(); gpgIt != gpgIds.end(); gpgIt++) {
if (groupInfo) {
@ -466,7 +484,7 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status)
QString gpgId;
int gpgStatus = RS_STATUS_OFFLINE;
if (mShowTypes & SHOW_GPG) {
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) {
/* need gpg id and online state */
RsPeerDetails detail;
if (rsPeers->getPeerDetails(peerId.toStdString(), detail)) {
@ -763,6 +781,17 @@ void FriendSelectionWidget::selectedIds(IdType idType, std::list<std::string> &i
}
}
void FriendSelectionWidget::deselectAll()
{
for(QTreeWidgetItemIterator itemIterator(ui->friendList);*itemIterator!=NULL;++itemIterator)
setSelected(mListModus, *itemIterator, false);
}
void FriendSelectionWidget::selectAll()
{
for(QTreeWidgetItemIterator itemIterator(ui->friendList);*itemIterator!=NULL;++itemIterator)
setSelected(mListModus, *itemIterator, true);
}
void FriendSelectionWidget::setSelectedIds(IdType idType, const std::list<std::string> &ids, bool add)
{
QTreeWidgetItemIterator itemIterator(ui->friendList);

View file

@ -56,9 +56,10 @@ public:
};
enum ShowType {
SHOW_GROUP = 1,
SHOW_GPG = 2,
SHOW_SSL = 4
SHOW_GROUP = 1,
SHOW_GPG = 2,
SHOW_SSL = 4,
SHOW_NON_FRIEND_GPG = 8,
};
Q_DECLARE_FLAGS(ShowTypes, ShowType)
@ -110,6 +111,8 @@ private slots:
void contextMenuRequested(const QPoint &pos);
void itemDoubleClicked(QTreeWidgetItem *item, int column);
void itemChanged(QTreeWidgetItem *item, int column);
void selectAll() ;
void deselectAll() ;
private:
bool filterItem(QTreeWidgetItem *item, const QString &text);
@ -130,6 +133,8 @@ private:
QColor mTextColorOnline;
Ui::FriendSelectionWidget *ui;
friend class FriendSelectionDialog ;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(FriendSelectionWidget::ShowTypes)

View file

@ -6,37 +6,11 @@
<rect>
<x>0</x>
<y>0</y>
<width>211</width>
<height>358</height>
<width>446</width>
<height>320</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>2</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="filterLabel">
<property name="text">
<string>Search for Name:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="friendList">
<property name="minimumSize">
@ -67,6 +41,34 @@
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="filterLabel">
<property name="text">
<string>Search :</string>
</property>
</widget>
</item>
<item>
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="selectAll_PB">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deselectAll_PB">
<property name="text">
<string>None</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>