improved the logic of certificate handling in UI

This commit is contained in:
csoler 2022-02-11 15:10:28 +01:00
parent 5270459a5c
commit c3c171125d
7 changed files with 58 additions and 67 deletions

@ -1 +1 @@
Subproject commit 5a6f09ee11a34f1c52b5be3f0a440f185b9b2a89
Subproject commit d26821b891d7b3e72da475896814a82716574e56

View File

@ -229,7 +229,7 @@ void GetStartedDialog::inviteFriends()
{
RsAutoUpdatePage::lockAllEvents();
cert = rsPeers->GetRetroshareInvite(RsPeerId(),RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::FULL_IP_HISTORY);
cert = rsPeers->GetRetroshareInvite(RsPeerId(),RsPeers::defaultCertificateFlags | RetroshareInviteFlags::FULL_IP_HISTORY);
RsAutoUpdatePage::unlockAllEvents() ;
}

View File

@ -50,14 +50,10 @@
HomePage::HomePage(QWidget *parent) :
MainPage(parent),
ui(new Ui::HomePage),
mIncludeAllIPs(false),
mUseShortFormat(true)
ui(new Ui::HomePage)
{
ui->setupUi(this);
updateCertificate();
connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addFriend()));
connect(ui->copyIDButton, SIGNAL(clicked()), this, SLOT(copyId()));
@ -73,29 +69,36 @@ HomePage::HomePage(QWidget *parent) :
QAction *CopyIdAction = new QAction(QIcon(),tr("Copy your Retroshare ID to Clipboard"), this);
connect(CopyIdAction, SIGNAL(triggered()), this, SLOT(copyId()));
QMenu *menu = new QMenu();
QMenu *menu = new QMenu();
menu->addAction(CopyIdAction);
if(!RsAccounts::isHiddenNode())
{
QAction *includeIPsAct = new QAction(QIcon(), tr("Include all your known IPs"),this);
connect(includeIPsAct, SIGNAL(triggered()), this, SLOT(toggleIncludeAllIPs()));
includeIPsAct->setCheckable(true);
includeIPsAct->setChecked(mIncludeAllIPs);
menu->addAction(includeIPsAct);
}
QAction *useOldFormatAct = new QAction(QIcon(), tr("Use old certificate format"),this);
useOldFormatAct->setToolTip(tr("Displays the certificate format used up to version 0.6.5\nOld Retroshare nodes will not understand the\nnew short format"));
connect(useOldFormatAct, SIGNAL(triggered()), this, SLOT(toggleUseOldFormat()));
useOldFormatAct->setCheckable(true);
useOldFormatAct->setChecked(!mUseShortFormat);
menu->addAction(useOldFormatAct);
menu->addSeparator();
menu->addAction(SendAction);
menu->addAction(WebMailAction);
menu->addAction(RecAction);
menu->addSeparator();
if(!RsAccounts::isHiddenNode())
{
mIncludeDNSact = new QAction(QIcon(), tr("Include my DNS"),this);
connect(mIncludeDNSact, SIGNAL(triggered()), this, SLOT(updateOwnCert()));
mIncludeDNSact->setCheckable(true);
mIncludeDNSact->setChecked(true);
menu->addAction(mIncludeDNSact);
mIncludeIPsAct = new QAction(QIcon(), tr("Include all your known IPs"),this);
connect(mIncludeIPsAct, SIGNAL(triggered()), this, SLOT(updateOwnCert()));
mIncludeIPsAct->setCheckable(true);
mIncludeIPsAct->setChecked(false);
menu->addAction(mIncludeIPsAct);
}
QAction *useOldFormatAct = new QAction(QIcon(), tr("Use old certificate format"),this);
useOldFormatAct->setToolTip(tr("Displays the certificate format used up to version 0.6.5\nOld Retroshare nodes will not understand the\nnew short format"));
connect(useOldFormatAct, SIGNAL(triggered()), this, SLOT(updateOwnCert()));
useOldFormatAct->setCheckable(true);
useOldFormatAct->setChecked(false);
menu->addAction(useOldFormatAct);
ui->shareButton->setMenu(menu);
@ -118,6 +121,8 @@ HomePage::HomePage(QWidget *parent) :
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId, RsEventType::NETWORK );
updateOwnCert();
}
void HomePage::handleEvent(std::shared_ptr<const RsEvent> e)
@ -139,13 +144,15 @@ void HomePage::handleEvent(std::shared_ptr<const RsEvent> e)
case RsNetworkEventCode::DNS_UPDATED: // [fallthrough]
RsQThreadUtils::postToObject( [=]()
{
updateCertificate();
updateOwnCert();
},this);
break;
default:
break;
}
}
#ifdef DEAD_CODE
void HomePage::certContextMenu(QPoint /*point*/)
{
QMenu menu(this) ;
@ -178,17 +185,7 @@ void HomePage::certContextMenu(QPoint /*point*/)
menu.exec(QCursor::pos());
}
void HomePage::toggleUseShortFormat()
{
mUseShortFormat = !mUseShortFormat;
updateCertificate();
}
void HomePage::toggleIncludeAllIPs()
{
mIncludeAllIPs = !mIncludeAllIPs;
updateCertificate();
}
#endif
HomePage::~HomePage()
{
@ -196,14 +193,9 @@ HomePage::~HomePage()
delete ui;
}
void HomePage::updateCertificate()
{
updateOwnCert();
}
void HomePage::updateOwnCert()
{
bool include_extra_locators = mIncludeAllIPs;
bool include_extra_locators = mIncludeIPsAct->isChecked();
RsPeerDetails detail;
@ -214,12 +206,12 @@ void HomePage::updateOwnCert()
}
QString invite ;
RetroshareInviteFlags invite_flags = RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::DNS;
RetroshareInviteFlags invite_flags = RsPeers::defaultCertificateFlags;
if(mIncludeAllIPs)
if(mIncludeIPsAct->isChecked())
invite_flags |= RetroshareInviteFlags::FULL_IP_HISTORY;
if(mUseShortFormat)
if(!mUseOldFormatAct->isChecked())
{
std::string short_invite;
rsPeers->getShortInvite(short_invite,rsPeers->getOwnId(),invite_flags | RetroshareInviteFlags::RADIX_FORMAT);
@ -245,7 +237,7 @@ void HomePage::updateOwnCert()
ui->retroshareid->setText("\n"+invite+"\n");
QString description = ConfCertDialog::getCertificateDescription(detail,false,mUseShortFormat,include_extra_locators);
QString description = ConfCertDialog::getCertificateDescription(detail,false,!mUseOldFormatAct->isChecked(),include_extra_locators);
ui->retroshareid->setToolTip(description);
}
@ -348,9 +340,3 @@ void HomePage::openWebHelp()
{
QDesktopServices::openUrl(QUrl(QString("https://retrosharedocs.readthedocs.io/en/latest/")));
}
void HomePage::toggleUseOldFormat()
{
mUseShortFormat = !mUseShortFormat;
updateCertificate();
}

View File

@ -47,27 +47,25 @@ public:
virtual QString helpText() const { return ""; } //MainPage
private slots:
void certContextMenu(QPoint);
#ifdef DEAD_CODE
void certContextMenu(QPoint);
#endif
void updateOwnCert();
void updateCertificate();
void runEmailClient();
void copyCert();
void copyId();
void saveCert();
void addFriend();
void webMail();
//void loadCert();
void openWebHelp() ;
void toggleUseOldFormat() ;
void recommendFriends();
void toggleIncludeAllIPs();
void toggleUseShortFormat();
private:
Ui::HomePage *ui;
bool mIncludeAllIPs;
bool mUseShortFormat;
QAction *mIncludeDNSact;
QAction *mIncludeIPsAct;
QAction *mUseOldFormatAct;
RsEventsHandlerId_t mEventHandlerId;

View File

@ -1361,7 +1361,7 @@ bool NewFriendList::exportFriendlist(QString &fileName)
if (!rsPeers->getPeerDetails(*list_iter2, detailSSL))
continue;
std::string certificate = rsPeers->GetRetroshareInvite(detailSSL.id, RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::DNS | RetroshareInviteFlags::RADIX_FORMAT);
std::string certificate = rsPeers->GetRetroshareInvite(detailSSL.id, RsPeers::defaultCertificateFlags | RetroshareInviteFlags::RADIX_FORMAT);
// remove \n from certificate
certificate.erase(std::remove(certificate.begin(), certificate.end(), '\n'), certificate.end());

View File

@ -264,7 +264,7 @@ void ConfCertDialog::loadInvitePage()
ui._shouldAddSignatures_CB->setEnabled(detail.gpgSigners.size() > 1) ;
std::string invite ;
RetroshareInviteFlags flags = RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP | RetroshareInviteFlags::RADIX_FORMAT;
RetroshareInviteFlags flags = RsPeers::defaultCertificateFlags | RetroshareInviteFlags::RADIX_FORMAT;
if(!detail.isHiddenNode && ui._includeIPHistory_CB->isChecked())
flags |= RetroshareInviteFlags::FULL_IP_HISTORY;
@ -346,13 +346,20 @@ QString ConfCertDialog::getCertificateDescription(const RsPeerDetails& detail,bo
infotext += "</li>" ;
}
if(!detail.dyndns.empty())
{
infotext += "<li>" ;
infotext += tr("<b>DNS:</b> : ") + QString::fromStdString(detail.dyndns);
infotext += "</li>" ;
}
infotext += QString("</p>") ;
if(rsPeers->getOwnId() == detail.id)
if(use_short_format)
infotext += tr("<p>You can use this Retroshare ID to make new friends. Send it by email, or give it hand to hand.</p>") ;
else
infotext += tr("<p>You can use this certificate to make new friends. Send it by email, or give it hand to hand.</p>") ;
infotext += tr("<p>You can use this Retroshare ID to make new friends. Send it by email, or give it hand to hand.</p>") ;
else
infotext += tr("<p>You can use this certificate to make new friends. Send it by email, or give it hand to hand.</p>") ;
return infotext;
}

View File

@ -103,7 +103,7 @@ void CryptoPage::showEvent ( QShowEvent * /*event*/ )
ui.pgpfingerprint->setText(misc::fingerPrintStyleSplit(QString::fromStdString(detail.fpr.toStdString())));
std::string invite ;
rsPeers->getShortInvite(invite,rsPeers->getOwnId(),RetroshareInviteFlags::RADIX_FORMAT | RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP);
rsPeers->getShortInvite(invite,rsPeers->getOwnId(),RetroshareInviteFlags::RADIX_FORMAT | RsPeers::defaultCertificateFlags);
ui.retroshareid->setText(QString::fromUtf8(invite.c_str()));
/* set retroshare version */
@ -139,7 +139,7 @@ void
CryptoPage::load()
{
std::string cert ;
RetroshareInviteFlags flags = RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_IP;
RetroshareInviteFlags flags = RetroshareInviteFlags::DNS | RetroshareInviteFlags::CURRENT_LOCAL_IP | RetroshareInviteFlags::CURRENT_EXTERNAL_IP;
if(ui._shortFormat_CB->isChecked())
{