fixed a few bugs in NetworkDialog

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7134 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-02-19 21:37:03 +00:00
parent b90cc5ffea
commit 1edc3c083f
11 changed files with 177 additions and 105 deletions

View file

@ -600,6 +600,12 @@ bool PGPHandler::exportPublicKey(const PGPIdType& id,unsigned char *& mem_block,
const ops_keydata_t *key = locked_getPublicKey(id,false) ;
mem_block = NULL ;
if(armoured)
{
std::cerr << __PRETTY_FUNCTION__ << ": should not be used with armoured=true, because there's a bug in the armoured export of OPS" << std::endl;
return false ;
}
if(key == NULL)
{
std::cerr << "Cannot output key " << id.toStdString() << ": not found in keyring." << std::endl;

View file

@ -102,8 +102,7 @@ peerAddrInfo::peerAddrInfo()
}
peerConnectState::peerConnectState()
:id("unknown"),
connecttype(0),
: connecttype(0),
lastavailable(0),
lastattempt(0),
name(""),

View file

@ -83,9 +83,7 @@ static const std::string kConfigKeyProxyServerPort = "PROXY_SERVER_PORT";
void printConnectState(std::ostream &out, peerState &peer);
peerState::peerState()
:id("unknown"),
gpg_id("unknown"),
netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0),
:netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0),
hiddenNode(false), hiddenPort(0)
{
sockaddr_storage_clear(localaddr);

View file

@ -187,7 +187,7 @@ class RsPeerDetails
/* Auth details */
bool isOnlyGPGdetail;
SSLIdType id;
RsPeerId id;
PGPIdType gpg_id;
std::string name;
@ -295,49 +295,49 @@ class RsPeers
virtual bool haveSecretKey(const PGPIdType& gpg_id) = 0 ;
virtual bool getOnlineList(std::list<SSLIdType> &ssl_ids) = 0;
virtual bool getFriendList(std::list<SSLIdType> &ssl_ids) = 0;
virtual bool getOnlineList(std::list<RsPeerId> &ssl_ids) = 0;
virtual bool getFriendList(std::list<RsPeerId> &ssl_ids) = 0;
virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0;
virtual bool isOnline(const SSLIdType &ssl_id) = 0;
virtual bool isFriend(const SSLIdType &ssl_id) = 0;
virtual bool isOnline(const RsPeerId &ssl_id) = 0;
virtual bool isFriend(const RsPeerId &ssl_id) = 0;
virtual bool isGPGAccepted(const PGPIdType &gpg_id_is_friend) = 0; //
virtual std::string getPeerName(const SSLIdType &ssl_id) = 0;
virtual std::string getPeerName(const RsPeerId &ssl_id) = 0;
virtual std::string getGPGName(const PGPIdType& gpg_id) = 0;
virtual bool getPeerDetails(const SSLIdType& ssl_id, RsPeerDetails &d) = 0;
virtual bool getPeerDetails(const RsPeerId& ssl_id, RsPeerDetails &d) = 0;
virtual bool getGPGDetails(const PGPIdType& gpg_id, RsPeerDetails &d) = 0;
/* Using PGP Ids */
virtual const PGPIdType& getGPGOwnId() = 0;
virtual PGPIdType getGPGId(const SSLIdType& sslid) = 0; //return the gpg id of the given ssl id
virtual PGPIdType getGPGId(const RsPeerId& sslid) = 0; //return the gpg id of the given ssl id
virtual bool isKeySupported(const PGPIdType& gpg_ids) = 0;
virtual bool getGPGAcceptedList(std::list<PGPIdType> &gpg_ids) = 0;
virtual bool getGPGSignedList(std::list<PGPIdType> &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<PGPIdType> &gpg_ids) = 0;
virtual bool getGPGAllList(std::list<PGPIdType> &gpg_ids) = 0;
virtual bool getAssociatedSSLIds(const PGPIdType& gpg_id, std::list<SSLIdType>& ids) = 0;
virtual bool getAssociatedSSLIds(const PGPIdType& gpg_id, std::list<RsPeerId>& ids) = 0;
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) = 0;
/* Add/Remove Friends */
virtual bool addFriend(const SSLIdType &ssl_id, const PGPIdType &gpg_id,ServicePermissionFlags flags = RS_SERVICE_PERM_ALL) = 0;
virtual bool addFriend(const RsPeerId &ssl_id, const PGPIdType &gpg_id,ServicePermissionFlags flags = RS_SERVICE_PERM_ALL) = 0;
virtual bool removeFriend(const PGPIdType& pgp_id) = 0;
virtual bool removeFriendLocation(const SSLIdType& sslId) = 0;
virtual bool removeFriendLocation(const RsPeerId& sslId) = 0;
/* keyring management */
virtual bool removeKeysFromPGPKeyring(const std::list<PGPIdType>& pgp_ids,std::string& backup_file,uint32_t& error_code)=0 ;
/* Network Stuff */
virtual bool connectAttempt(const SSLIdType& ssl_id) = 0;
virtual bool setLocation(const SSLIdType &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs
virtual bool connectAttempt(const RsPeerId& ssl_id) = 0;
virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location) = 0;//location is shown in the gui to differentiate ssl certs
virtual bool setHiddenNode(const SSLIdType &id, const std::string &hidden_node_address) = 0;
virtual bool setHiddenNode(const SSLIdType &id, const std::string &address, uint16_t port) = 0;
virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address) = 0;
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port) = 0;
virtual bool setLocalAddress(const SSLIdType &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setExtAddress( const SSLIdType &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setDynDNS(const SSLIdType &id, const std::string &addr) = 0;
virtual bool setNetworkMode(const SSLIdType &ssl_id, uint32_t netMode) = 0;
virtual bool setVisState(const SSLIdType &ssl_id, uint16_t vs_disc, uint16_t vs_dht) = 0;
virtual bool setLocalAddress(const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setExtAddress( const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setDynDNS(const RsPeerId &id, const std::string &addr) = 0;
virtual bool setNetworkMode(const RsPeerId &ssl_id, uint32_t netMode) = 0;
virtual bool setVisState(const RsPeerId &ssl_id, uint16_t vs_disc, uint16_t vs_dht) = 0;
virtual bool getProxyServer(std::string &addr, uint16_t &port) = 0;
virtual bool setProxyServer(const std::string &addr, const uint16_t port) = 0;
@ -347,21 +347,22 @@ class RsPeers
virtual bool getAllowServerIPDetermination() = 0 ;
/* Auth Stuff */
virtual std::string GetRetroshareInvite(const SSLIdType& ssl_id,bool include_signatures) = 0;
virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures) = 0;
virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) = 0;
virtual bool GetPGPBase64StringAndCheckSum(const PGPIdType& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0 ;
virtual std::string GetRetroshareInvite(bool include_signatures) = 0;
virtual bool hasExportMinimal() = 0 ;
// Add keys to the keyring
virtual bool loadCertificateFromString(const std::string& cert, SSLIdType& ssl_id,PGPIdType& pgp_id, std::string& error_string) = 0;
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,PGPIdType& pgp_id, std::string& error_string) = 0;
// Gets the GPG details, but does not add the key to the keyring.
virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,uint32_t& error_code) = 0;
// Certificate utils
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0;
virtual bool saveCertificateToFile(const SSLIdType& id, const std::string &fname) = 0;
virtual std::string saveCertificateToString(const SSLIdType &id) = 0;
virtual bool saveCertificateToFile(const RsPeerId& id, const std::string &fname) = 0;
virtual std::string saveCertificateToString(const RsPeerId &id) = 0;
virtual bool signGPGCertificate(const PGPIdType &gpg_id) = 0;
virtual bool trustGPGCertificate(const PGPIdType &gpg_id, uint32_t trustlvl) = 0;
@ -392,7 +393,7 @@ class RsPeers
/* Service permission flags */
virtual ServicePermissionFlags servicePermissionFlags(const PGPIdType& gpg_id) = 0;
virtual ServicePermissionFlags servicePermissionFlags(const SSLIdType& ssl_id) = 0;
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) = 0;
virtual void setServicePermissionFlags(const PGPIdType& gpg_id,const ServicePermissionFlags& flags) = 0;
};

View file

@ -554,7 +554,10 @@ bool p3Peers::getGPGDetails(const PGPIdType &id, RsPeerDetails &d)
#endif
/* get from mAuthMgr */
return AuthGPG::getAuthGPG()->getGPGDetails(id, d);
bool res = AuthGPG::getAuthGPG()->getGPGDetails(id, d);
d.isOnlyGPGdetail = true ;
return res ;
}
const PGPIdType& p3Peers::getGPGOwnId()
@ -946,11 +949,31 @@ bool p3Peers::setProxyServer(const std::string &addr_str, const uint16_t port)
//===========================================================================
/* Auth Stuff */
std::string
p3Peers::GetRetroshareInvite(bool include_signatures)
std::string p3Peers::GetRetroshareInvite(bool include_signatures)
{
return GetRetroshareInvite(getOwnId(),include_signatures);
}
std::string p3Peers::getPGPKey(const RsPgpId& pgp_id,bool include_signatures)
{
unsigned char *mem_block = NULL;
size_t mem_block_size = 0;
if(!AuthGPG::getAuthGPG()->exportPublicKey(PGPIdType(pgp_id),mem_block,mem_block_size,false,include_signatures))
{
std::cerr << "Cannot output certificate for id \"" << pgp_id << "\". Sorry." << std::endl;
return "" ;
}
RsPeerDetails Detail ;
if(!getGPGDetails(pgp_id,Detail) )
return "" ;
RsCertificate cert( Detail,mem_block,mem_block_size ) ;
return cert.armouredPGPKey() ;
}
bool p3Peers::GetPGPBase64StringAndCheckSum( const PGPIdType& gpg_id,
std::string& gpg_base64_string,
@ -962,7 +985,7 @@ bool p3Peers::GetPGPBase64StringAndCheckSum( const PGPIdType& gpg_id,
unsigned char *mem_block ;
size_t mem_block_size ;
if(!AuthGPG::getAuthGPG()->exportPublicKey(PGPIdType(gpg_id),mem_block,mem_block_size,false,false))
if(!AuthGPG::getAuthGPG()->exportPublicKey(gpg_id,mem_block,mem_block_size,false,false))
return false ;
Radix64::encode((const char *)mem_block,mem_block_size,gpg_base64_string) ;
@ -1255,9 +1278,8 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
RsPeerDetails::RsPeerDetails()
:isOnlyGPGdetail(false),
id(""),gpg_id(""),
name(""),email(""),location(""),
org(""),issuer(""),fpr(""),authcode(""),
org(""),authcode(""),
trustLvl(0), validLvl(0),ownsign(false),
hasSignedMe(false),accept_connection(false),
state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),vs_disc(0), vs_dht(0),

View file

@ -103,6 +103,8 @@ virtual bool getAllowServerIPDetermination() ;
/* Auth Stuff */
// Get the invitation (GPG cert + local/ext address + SSL id for the given peer)
virtual std::string GetRetroshareInvite(const RsPeerId& ssl_id,bool include_signatures);
virtual std::string getPGPKey(const RsPgpId& pgp_id,bool include_signatures) ;
// same but for own id
virtual std::string GetRetroshareInvite(bool include_signatures);
virtual bool GetPGPBase64StringAndCheckSum(const PGPIdType& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) ;

View file

@ -451,7 +451,7 @@ void NetworkDialog::insertConnect()
item -> setText(COLUMN_PEERNAME, QString::fromUtf8(detail.name.c_str()));
/* (4) key id */
item -> setText(COLUMN_PEERID, QString::fromStdString(detail.id.toStdString()));
item -> setText(COLUMN_PEERID, QString::fromStdString(detail.gpg_id.toStdString()));
}
//QString TrustLevelString ;
@ -559,7 +559,7 @@ void NetworkDialog::insertConnect()
self_item->setIcon(COLUMN_CHECK,(QIcon(IMAGE_AUTHED)));
self_item->setText(COLUMN_PEERNAME, QString::fromUtf8(ownGPGDetails.name.c_str()) + " (" + tr("yourself") + ")");
self_item->setText(COLUMN_I_AUTH_PEER,"N/A");
self_item->setText(COLUMN_PEERID, QString::fromStdString(ownGPGDetails.id.toStdString()));
self_item->setText(COLUMN_PEERID, QString::fromStdString(ownGPGDetails.gpg_id.toStdString()));
// Color each Background column in the Network Tab except the first one => 1-9
for(int i=0;i<COLUMN_COUNT;++i)

View file

@ -698,7 +698,7 @@ QString RetroShareLink::title() const
case TYPE_FILE:
return QString("%1 (%2)").arg(hash()).arg(misc::friendlyUnit(size()));
case TYPE_PERSON:
return PeerDefs::rsidFromId(RsPeerId(hash().toStdString()));
return PeerDefs::rsidFromId(RsPgpId(hash().toStdString()));
case TYPE_FORUM:
case TYPE_CHANNEL:
case TYPE_SEARCH:

View file

@ -55,7 +55,6 @@ const QString PeerDefs::rsid(const RsPeerDetails &details)
{
return rsid(details.name, details.id);
}
const QString PeerDefs::rsidFromId(const RsPeerId &id, QString *name /* = NULL*/)
{
QString rsid;
@ -90,6 +89,30 @@ const QString PeerDefs::rsidFromId(const RsPeerId &id, QString *name /* = NULL*/
return rsid;
}
const QString PeerDefs::rsidFromId(const RsPgpId &id, QString *name /* = NULL*/)
{
QString rsid;
std::string peerName = rsPeers->getGPGName(id);
if(!peerName.empty())
{
rsid = PeerDefs::rsid(peerName, id);
if (name) {
*name = QString::fromUtf8(peerName.c_str());
}
}
else
{
rsid = PeerDefs::rsid("", id);
if (name)
*name = qApp->translate("PeerDefs", "Unknown");
}
return rsid;
}
RsPeerId PeerDefs::idFromRsid(const QString &rsid, bool check)
{

View file

@ -35,6 +35,7 @@ public:
static const QString rsid(const RsPeerDetails &details);
static const QString rsid(const std::string &name, const RsPeerId &id);
static const QString rsid(const std::string &name, const RsPgpId &id);
static const QString rsidFromId(const RsPgpId &id, QString *name = NULL);
static const QString rsidFromId(const RsPeerId &id, QString *name = NULL);
static RsPeerId idFromRsid(const QString &rsid, bool check);
};

View file

@ -84,7 +84,13 @@ ConfCertDialog::ConfCertDialog(const RsPeerId& id, const RsPgpId &pgp_id, QWidge
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
ui._useOldFormat_CB->setChecked(true) ;
if(id.isNull())
ui._useOldFormat_CB->setChecked(true) ;
else
{
ui._useOldFormat_CB->setChecked(false) ;
ui._useOldFormat_CB->setEnabled(false) ;
}
ui.headerFrame->setHeaderImage(QPixmap(":/images/user/identityinfo64.png"));
ui.headerFrame->setHeaderText(tr("Friend Details"));
@ -189,76 +195,82 @@ void ConfCertDialog::load()
ui.pgpfingerprint->setText(misc::fingerPrintStyleSplit(QString::fromStdString(detail.fpr.toStdString())));
ui.rsid->setToolTip(link.title());
if (!detail.isOnlyGPGdetail) {
ui.avatar->setId(peerId);
if (!detail.isOnlyGPGdetail)
{
ui.avatar->setId(peerId);
ui.loc->setText(QString::fromUtf8(detail.location.c_str()));
// Dont Show a timestamp in RS calculate the day
ui.lastcontact->setText(DateTime::formatLongDateTime(detail.lastConnect));
ui.loc->setText(QString::fromUtf8(detail.location.c_str()));
// Dont Show a timestamp in RS calculate the day
ui.lastcontact->setText(DateTime::formatLongDateTime(detail.lastConnect));
/* set retroshare version */
std::string version;
rsDisc->getPeerVersion(detail.id, version);
ui.version->setText(QString::fromStdString(version));
/* set retroshare version */
std::string version;
rsDisc->getPeerVersion(detail.id, version);
ui.version->setText(QString::fromStdString(version));
RsPeerCryptoParams cdet ;
if(RsControl::instance()->getPeerCryptoDetails(detail.id,cdet) && cdet.connexion_state!=0)
{
QString ct ;
ct += QString::fromStdString(cdet.cipher_name) ;
ct += QString::number(cdet.cipher_bits_1) ;
ct += "-"+QString::fromStdString(cdet.cipher_version) ;
ui.crypto_info->setText(ct) ;
}
else
ui.crypto_info->setText(tr("Not connected")) ;
RsPeerCryptoParams cdet ;
if(RsControl::instance()->getPeerCryptoDetails(detail.id,cdet) && cdet.connexion_state!=0)
{
QString ct ;
ct += QString::fromStdString(cdet.cipher_name) ;
ct += QString::number(cdet.cipher_bits_1) ;
ct += "-"+QString::fromStdString(cdet.cipher_version) ;
ui.crypto_info->setText(ct) ;
}
else
ui.crypto_info->setText(tr("Not connected")) ;
if (detail.isHiddenNode)
{
/* set local address */
ui.localAddress->setText("hidden");
ui.localPort -> setValue(0);
/* set the server address */
ui.extAddress->setText("hidden");
ui.extPort -> setValue(0);
if (detail.isHiddenNode)
{
/* set local address */
ui.localAddress->setText("hidden");
ui.localPort -> setValue(0);
/* set the server address */
ui.extAddress->setText("hidden");
ui.extPort -> setValue(0);
ui.dynDNS->setText(QString::fromStdString(detail.hiddenNodeAddress));
}
else
{
/* set local address */
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
ui.localPort -> setValue(detail.localPort);
/* set the server address */
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
ui.extPort -> setValue(detail.extPort);
ui.dynDNS->setText(QString::fromStdString(detail.dyndns));
}
ui.statusline->setText(StatusDefs::connectStateString(detail));
ui.dynDNS->setText(QString::fromStdString(detail.hiddenNodeAddress));
}
else
{
/* set local address */
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
ui.localPort -> setValue(detail.localPort);
/* set the server address */
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
ui.extPort -> setValue(detail.extPort);
ui.ipAddressList->clear();
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
ui.ipAddressList->addItem(QString::fromStdString(*it));
ui.dynDNS->setText(QString::fromStdString(detail.dyndns));
}
ui.loc->show();
ui.label_loc->show();
ui.statusline->show();
ui.label_status->show();
ui.lastcontact->show();
ui.label_last_contact->show();
ui.version->show();
ui.label_version->show();
ui.statusline->setText(StatusDefs::connectStateString(detail));
ui.groupBox->show();
ui.groupBox_4->show();
ui.tabWidget->show();
ui.rsid->hide();
ui.label_rsid->hide();
ui.pgpfingerprint->show();
ui.pgpfingerprint_label->show();
} else {
ui.ipAddressList->clear();
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
ui.ipAddressList->addItem(QString::fromStdString(*it));
ui.loc->show();
ui.label_loc->show();
ui.statusline->show();
ui.label_status->show();
ui.lastcontact->show();
ui.label_last_contact->show();
ui.version->show();
ui.label_version->show();
ui.groupBox->show();
ui.groupBox_4->show();
ui.tabWidget->show();
ui.rsid->hide();
ui.label_rsid->hide();
ui.pgpfingerprint->show();
ui.pgpfingerprint_label->show();
ui.stabWidget->setTabEnabled(2,true) ;
ui.stabWidget->setTabEnabled(3,true) ;
}
else
{
//ui.avatar->setId(pgpId.toStdString(), true);
ui.rsid->show();
@ -281,6 +293,10 @@ void ConfCertDialog::load()
ui.groupBox->hide();
ui.tabWidget->hide();
ui.stabWidget->setTabEnabled(2,true) ;
ui.stabWidget->setTabEnabled(3,false) ;
ui._useOldFormat_CB->setEnabled(false) ;
}
if (detail.gpg_id == rsPeers->getGPGOwnId()) {
@ -401,7 +417,7 @@ void ConfCertDialog::load()
void ConfCertDialog::loadInvitePage()
{
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(peerId, detail))
if (!rsPeers->getPeerDetails(peerId, detail) && !rsPeers->getGPGDetails(pgpId,detail))
{
QMessageBox::information(this,
tr("RetroShare"),
@ -409,8 +425,12 @@ void ConfCertDialog::loadInvitePage()
close();
return;
}
std::string invite ;
std::string invite = rsPeers->GetRetroshareInvite(detail.id,ui._shouldAddSignatures_CB->isChecked()) ; // this needs to be a SSL id
if(detail.isOnlyGPGdetail)
invite = rsPeers->getPGPKey(detail.gpg_id,ui._shouldAddSignatures_CB->isChecked()) ; // this needs to be a SSL id
else
invite = rsPeers->GetRetroshareInvite(detail.id,ui._shouldAddSignatures_CB->isChecked()) ; // this needs to be a SSL id
ui.userCertificateText->setReadOnly(true);
ui.userCertificateText->setMinimumHeight(200);