implement dummy friend for a gpg key, improve PersDialog ui

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2018 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2010-01-13 21:25:18 +00:00
parent 9976b80566
commit e50dc4e3b9
9 changed files with 212 additions and 83 deletions

View File

@ -1031,6 +1031,19 @@ bool AuthGPG::isGPGValid(GPG_id id)
}
bool AuthGPG::isGPGId(GPG_id id)
{
RsStackMutex stack(pgpMtx); /******* LOCKED ******/
storeAllKeys_locked();
certmap::iterator it;
if (mKeyList.end() != (it = mKeyList.find(id))) {
return true;
} else {
return false;
}
}
bool AuthGPG::isGPGSigned(GPG_id id)
{
@ -1657,8 +1670,8 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
else if (status == GPGME_STATUS_ALREADY_SIGNED)
{
/* The key has already been signed with this key */
params->state = SIGN_ERROR;
params->err = gpg_error (GPG_ERR_CONFLICT);
params->state = SIGN_QUIT;
result = "quit";
}
else if (status == GPGME_STATUS_GET_LINE &&
(!std::string("keyedit.prompt").compare(args)))

View File

@ -164,6 +164,7 @@ class AuthGPG
bool isGPGValid(std::string id);
bool isGPGSigned(std::string id);
bool isGPGAccepted(std::string id);
bool isGPGId(GPG_id id);
/*********************************************************************************/
/************************* STAGE 4 ***********************************************/

View File

@ -1355,8 +1355,15 @@ bool p3ConnectMgr::getOwnNetStatus(peerConnectState &state)
bool p3ConnectMgr::isFriend(std::string id)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
return (mFriendList.end() != mFriendList.find(id));
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::isFriend(" << id << ") called" << std::endl;
#endif
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
bool ret = (mFriendList.end() != mFriendList.find(id));
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::isFriend(" << id << ") returning : " << ret << std::endl;
#endif
return ret;
}
bool p3ConnectMgr::isOnline(std::string id)
@ -1990,7 +1997,7 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMode, uint32_t visState, time_t lastContact)
{
/* so three possibilities
/* so four possibilities
* (1) already exists as friend -> do nothing.
* (2) is in others list -> move over.
* (3) is non-existant -> create new one.
@ -2000,6 +2007,12 @@ bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMod
std::cerr << "p3ConnectMgr::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl;
#endif
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::addFriend() removing dummy friend" << std::endl;
#endif
//remove any dummy friend because we just add a real ssl friend
removeFriend("dummy"+ gpg_id);
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
@ -2101,7 +2114,8 @@ bool p3ConnectMgr::removeFriend(std::string id)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::removeFriend() " << id << std::endl;
std::cerr << "p3ConnectMgr::removeFriend() for id : " << id << std::endl;
std::cerr << "p3ConnectMgr::removeFriend() mFriendList.size() : " << mFriendList.size() << std::endl;
#endif
netAssistFriend(id, false);
@ -2114,7 +2128,10 @@ bool p3ConnectMgr::removeFriend(std::string id)
if (mFriendList.end() != (it = mFriendList.find(id)))
{
peerConnectState peer = it->second;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::removeFriend() friend found in the list." << id << std::endl;
#endif
peerConnectState peer = it->second;
mFriendList.erase(it);
@ -2123,13 +2140,16 @@ bool p3ConnectMgr::removeFriend(std::string id)
peer.state &= (~RS_PEER_S_ONLINE);
peer.actions = RS_PEER_MOVED;
peer.inConnAttempt = false;
mOthersList[id] = peer;
//mOthersList[id] = peer;
mStatusChanged = true;
success = true;
}
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::removeFriend() new mFriendList.size() : " << mFriendList.size() << std::endl;
#endif
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return success;
}

View File

@ -147,7 +147,7 @@ virtual bool getPeerDetails(std::string ssl_or_gpg_id, RsPeerDetails &d) = 0; //
/* Using PGP Ids */
virtual std::string getGPGOwnId() = 0;
virtual std::string getGPGId(std::string ssl_id) = 0;
virtual std::string getGPGId(std::string sslid_or_gpgid) = 0; //return the gpg id of the given gpg or ssl id
virtual bool getGPGAcceptedList(std::list<std::string> &gpg_ids) = 0;
virtual bool getGPGSignedList(std::list<std::string> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key
virtual bool getGPGValidList(std::list<std::string> &gpg_ids) = 0;

View File

@ -243,21 +243,15 @@ bool p3Peers::isOnline(std::string id)
return false;
}
bool p3Peers::isFriend(std::string id)
bool p3Peers::isFriend(std::string ssl_id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::isFriend() " << id;
std::cerr << "p3Peers::isFriend() " << ssl_id;
std::cerr << std::endl;
#endif
/* get from mConnectMgr */
peerConnectState state;
if (mConnMgr->getFriendNetStatus(id, state) &&
(state.state & RS_PEER_S_FRIEND))
{
return true;
}
return false;
/* get from mConnectMgr */
return mConnMgr->isFriend(ssl_id);
}
static struct sockaddr_in getPreferredAddress( const struct sockaddr_in& addr1,time_t ts1,
@ -562,7 +556,7 @@ std::string p3Peers::getGPGOwnId()
return AuthGPG::getAuthGPG()->getGPGOwnId();
}
std::string p3Peers::getGPGId(std::string ssl_id)
std::string p3Peers::getGPGId(std::string sslid_or_gpgid)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getPGPId()";
@ -570,15 +564,22 @@ std::string p3Peers::getGPGId(std::string ssl_id)
#endif
/* get from mAuthMgr */
if (ssl_id == AuthSSL::getAuthSSL()->OwnId()) {
if (sslid_or_gpgid == AuthSSL::getAuthSSL()->OwnId()) {
return AuthGPG::getAuthGPG()->getGPGOwnId();
}
peerConnectState pcs;
if (mConnMgr->getFriendNetStatus(ssl_id, pcs)) {
if (mConnMgr->getFriendNetStatus(sslid_or_gpgid, pcs)) {
return pcs.gpg_id;
} else {
return "";
if ( AuthGPG::getAuthGPG()->isGPGValid(sslid_or_gpgid)) {
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getPGPId() given id is already an gpg id : " << sslid_or_gpgid;
std::cerr << std::endl;
#endif
return sslid_or_gpgid;
}
}
return "";
}
@ -599,10 +600,18 @@ bool p3Peers::addFriend(std::string id, std::string gpg_id)
bool p3Peers::addDummyFriend(std::string gpg_id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::addDummyFriend() not implemented yet" << std::endl;
std::cerr << "p3Peers::addDummyFriend() called" << std::endl;
#endif
return false;
std::string dummy_ssl_id = "dummy"+ gpg_id;
//check if this gpg_id already got a dummy friend
if (!mConnMgr->isFriend(dummy_ssl_id)) {
return mConnMgr->addFriend(dummy_ssl_id, gpg_id);
} else {
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::addDummyFriend() dummy friend already exists for gpg_id : " << gpg_id << std::endl;
#endif
return false;
}
}
bool p3Peers::removeFriend(std::string id)
@ -934,12 +943,9 @@ bool p3Peers::signGPGCertificate(std::string id)
std::cerr << std::endl;
#endif
if (AuthGPG::getAuthGPG()->SignCertificateLevel0(id)) {
//by default, set the GPG to accept connection
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(id, true);
return true;
}
return false;
AuthGPG::getAuthGPG()->SignCertificateLevel0(id);
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(id, true);
return true;
}
bool p3Peers::setAcceptToConnectGPGCertificate(std::string gpg_id, bool acceptance)

View File

@ -275,7 +275,7 @@ void PeersDialog::insertPeers()
rsPeers->getGPGAcceptedList(gpgFriends);
/* get a link to the table */
QTreeWidget *peerWidget = ui.peertreeWidget;
QTreeWidget *peertreeWidget = ui.peertreeWidget;
// add self nick and Avatar to Friends.
RsPeerDetails pd ;
@ -285,6 +285,18 @@ void PeersDialog::insertPeers()
ui.nicklabel->setText(titleStr.arg(QString::fromStdString(pd.name) + tr(" (me)"))) ;
}
//remove items that are not fiends anymore
int index = 0;
while (index < peertreeWidget->topLevelItemCount()) {
std::string gpg_id = (peertreeWidget->topLevelItem(index))->text(3).toStdString();
if (!rsPeers->isGPGAccepted(gpg_id)) {
peertreeWidget->takeTopLevelItem(index);
} else {
index++;
}
}
//add the gpg friends
for(it = gpgFriends.begin(); it != gpgFriends.end(); it++) {
std::cerr << "" << *it << std::endl;
@ -292,54 +304,72 @@ void PeersDialog::insertPeers()
continue;
}
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(*it, detail)) {
continue; /* BAD */
}
/* make a widget per friend */
QTreeWidgetItem *item;
QList<QTreeWidgetItem *> list = peerWidget->findItems (QString::fromStdString(detail.gpg_id), Qt::MatchExactly, 3);
QTreeWidgetItem *gpg_item;
QList<QTreeWidgetItem *> list = peertreeWidget->findItems(QString::fromStdString(*it), Qt::MatchExactly, 3);
if (list.size() == 1) {
item = list.front();
gpg_item = list.front();
} else {
item = new QTreeWidgetItem(0);
item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
gpg_item = new QTreeWidgetItem(0);
gpg_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
}
item -> setText(0, QString::fromStdString(detail.name));
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(*it, detail) || !detail.accept_connection) {
//don't accept anymore connection, remove from the view
peertreeWidget->takeTopLevelItem(peertreeWidget->indexOfTopLevelItem(gpg_item));
continue;
}
item -> setTextAlignment(0, Qt::AlignLeft | Qt::AlignVCenter );
//use to mark item as updated
gpg_item->setData(0, Qt::UserRole, true);
gpg_item -> setText(0, QString::fromStdString(detail.name));
//item -> setText( 1, QString::fromStdString(detail.name));
gpg_item -> setTextAlignment(0, Qt::AlignLeft | Qt::AlignVCenter );
//gpg_item -> setText( 1, QString::fromStdString(detail.name));
/* not displayed, used to find back the item */
item -> setText(3, QString::fromStdString(detail.id));
gpg_item -> setText(3, QString::fromStdString(detail.id));
/* add to the list. If item is already in the list, it won't be duplicated thanks to Qt */
peerWidget->addTopLevelItem(item);
//add the childs (ssl certs)
//item->takeChildren();
//remove items that are not friends anymore
int childIndex = 0;
while (childIndex < gpg_item->childCount()) {
std::string ssl_id = (gpg_item->child(childIndex))->text(3).toStdString();
if (!rsPeers->isFriend(ssl_id)) {
gpg_item->takeChild(childIndex);
} else {
childIndex++;
}
}
//update the childs (ssl certs)
std::list<std::string> sslContacts;
rsPeers->getSSLChildListOfGPGId(detail.gpg_id, sslContacts);
for(std::list<std::string>::iterator sslIt = sslContacts.begin(); sslIt != sslContacts.end(); sslIt++) {
RsPeerDetails sslDetail;
if (!rsPeers->getPeerDetails(*sslIt, sslDetail)) {
continue; /* BAD */
}
/* find the sslItem */
QTreeWidgetItem *sslItem = new QTreeWidgetItem(1);
bool gotToExpandBecauseNewChild = true;
for (int childIndex = 0; childIndex < item->childCount(); childIndex++) {
if (item->child(childIndex)->text(3).toStdString() == sslDetail.id) {
sslItem = item->child(childIndex);
gotToExpandBecauseNewChild = false;
QTreeWidgetItem *sslItem;
//find the corresponding sslItem child item of the gpg item
bool newChild = true;
for (int childIndex = 0; childIndex < gpg_item->childCount(); childIndex++) {
if (gpg_item->child(childIndex)->text(3).toStdString() == *sslIt) {
sslItem = gpg_item->child(childIndex);
newChild = false;
break;
}
}
if (newChild) {
sslItem = new QTreeWidgetItem(1);
}
RsPeerDetails sslDetail;
if (!rsPeers->getPeerDetails(*sslIt, sslDetail) || !rsPeers->isFriend(*sslIt)) {
std::cerr << "Removing widget from the view : id : " << *sslIt << std::endl;
//child has disappeared, remove it from the gpg_item
gpg_item->removeChild(sslItem);
}
/* not displayed, used to find back the item */
sslItem -> setText(3, QString::fromStdString(sslDetail.id));
@ -399,11 +429,15 @@ void PeersDialog::insertPeers()
std::cerr << "PeersDialog::insertPeers() inserting sslItem." << std::endl;
#endif
/* add to the list. If item is already in the list, it won't be duplicated thanks to Qt */
item->addChild(sslItem);
if (gotToExpandBecauseNewChild) {
item->setExpanded(true);
gpg_item->addChild(sslItem);
if (newChild) {
gpg_item->setExpanded(true);
}
}
/* add to the list. If item is already in the list, it won't be duplicated thanks to Qt */
peertreeWidget->addTopLevelItem(gpg_item);
}

View File

@ -155,7 +155,7 @@ signals:
QAction* exportfriendAct;
QAction* removefriendAct;
QTreeWidget *peertreeWidget;
//QTreeWidget *peertreeWidget;
IMHistoryKeeper historyKeeper;

View File

@ -47,7 +47,7 @@ ConfCertDialog::ConfCertDialog(QWidget *parent, Qt::WFlags flags)
connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyDialog()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(closeinfodlg()));
connect(ui.sign_button, SIGNAL(clicked()), this, SLOT(makeFriend()));
connect(ui.make_friend_button, SIGNAL(clicked()), this, SLOT(makeFriend()));
ui.applyButton->setToolTip(tr("Apply and Close"));
@ -151,11 +151,29 @@ void ConfCertDialog::loadDialog()
ui.groupBox->hide();
}
if (detail.ownsign) {
ui.sign_button->hide();
ui.signed_already_label->show();
if (detail.accept_connection) {
//connection already accepted, propose to sign gpg key
if (!detail.ownsign) {
ui.signGPGKeyCheckBox->setChecked(true);
ui.signGPGKeyCheckBox->hide();
ui.signed_already_label->setText(tr("Peer is already a friend"));
ui.make_friend_button->setText(tr("Sign GPG key"));
ui.make_friend_button->show();
} else {
ui.signGPGKeyCheckBox->hide();
ui.signed_already_label->setText(tr("Peer is a friend and GPG key is signed"));
ui.signed_already_label->show();
ui.make_friend_button->hide();
}
} else {
ui.sign_button->show();
ui.make_friend_button->show();
ui.make_friend_button->setText(tr("Make Friend"));
if (!detail.ownsign) {
ui.signGPGKeyCheckBox->show();
ui.signGPGKeyCheckBox->setChecked(true);
} else {
ui.signGPGKeyCheckBox->hide();
}
ui.signed_already_label->hide();
}
@ -177,13 +195,13 @@ void ConfCertDialog::loadDialog()
ui.radioButton_trust_marginnaly->show();
ui.radioButton_trust_never->show();
if (detail.trustLvl == 4) {
ui.web_of_trust_label->setText(tr("Your trust in this peer is full, it means he has an excellent understanding of key signing, and his signature on a key would be as good as your own."));
ui.web_of_trust_label->setText(tr("Your trust in this peer is full."));
ui.radioButton_trust_fully->setChecked(true);
} else if (detail.trustLvl == 3) {
ui.web_of_trust_label->setText(tr("Your trust in this peer is marginal, it means he understands the implications of key signing and properly check keys before signing them."));
ui.web_of_trust_label->setText(tr("Your trust in this peer is marginal."));
ui.radioButton_trust_marginnaly->setChecked(true);
} else if (detail.trustLvl == 2) {
ui.web_of_trust_label->setText(tr("Your trust in this peer is none, it means he is known to improperly sign other keys."));
ui.web_of_trust_label->setText(tr("Your trust in this peer is none."));
ui.radioButton_trust_never->setChecked(true);
} else {
ui.web_of_trust_label->setText(tr("Your trust in this peer is not set."));
@ -256,6 +274,12 @@ void ConfCertDialog::applyDialog()
void ConfCertDialog::makeFriend()
{
rsPeers->signGPGCertificate(mId);
loadDialog();
std::string gpg_id = rsPeers->getGPGId(mId);
if (ui.signGPGKeyCheckBox->isChecked()) {
rsPeers->signGPGCertificate(gpg_id);
} else {
rsPeers->setAcceptToConnectGPGCertificate(gpg_id, true);
}
rsPeers->addFriend(mId, gpg_id);
loadDialog();
}

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>506</width>
<width>459</width>
<height>529</height>
</rect>
</property>
@ -21,7 +21,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="stabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="icon">
@ -286,15 +286,37 @@
</item>
<item>
<widget class="QLabel" name="signed_already_label">
<property name="maximumSize">
<size>
<width>450</width>
<height>50</height>
</size>
</property>
<property name="text">
<string>Peer is already a friend of me (his GPG key is signed by me)</string>
<string>Not filled</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="sign_button">
<widget class="QCheckBox" name="signGPGKeyCheckBox">
<property name="text">
<string>Make friend (Sign his GPG key)</string>
<string>Sign GPG key (Default)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="make_friend_button">
<property name="text">
<string>Make Friends</string>
</property>
</widget>
</item>
@ -332,6 +354,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="radioButton_trust_never">
<property name="toolTip">
<string>Your trust in this peer is none, it means he is known to improperly sign other keys.</string>
</property>
<property name="text">
<string>None</string>
</property>
@ -339,6 +364,9 @@
</item>
<item>
<widget class="QRadioButton" name="radioButton_trust_marginnaly">
<property name="toolTip">
<string>Your trust in this peer is marginal, it means he understands the implications of key signing and properly check keys before signing them.</string>
</property>
<property name="text">
<string>Marginnaly</string>
</property>
@ -346,6 +374,9 @@
</item>
<item>
<widget class="QRadioButton" name="radioButton_trust_fully">
<property name="toolTip">
<string>Your trust in this peer is full, it means he has an excellent understanding of key signing, and his signature on a key would be as good as your own.</string>
</property>
<property name="text">
<string>Fully</string>
</property>