mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added retroshare certificate links: allows to paste certificates everywhere. Users need to click on them to launch the make friend wizard on the certificate. Certificates can be copied from each location of the Friends list
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4812 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
912e5339ca
commit
51cfb0c5fe
@ -37,6 +37,7 @@
|
||||
#include "util/misc.h"
|
||||
#include "common/PeerDefs.h"
|
||||
#include "common/RsCollectionFile.h"
|
||||
#include "gui/connect/ConnectFriendWizard.h"
|
||||
#include "gui/connect/ConfCertDialog.h"
|
||||
|
||||
#include <retroshare/rsfiles.h>
|
||||
@ -44,14 +45,16 @@
|
||||
#include <retroshare/rsforums.h>
|
||||
#include <retroshare/rschannels.h>
|
||||
|
||||
//#define DEBUG_RSLINK 1
|
||||
#define DEBUG_RSLINK 1
|
||||
|
||||
#define HOST_FILE "file"
|
||||
#define HOST_PERSON "person"
|
||||
#define HOST_FORUM "forum"
|
||||
#define HOST_CHANNEL "channel"
|
||||
#define HOST_MESSAGE "message"
|
||||
#define HOST_REGEXP "file|person|forum|channel|search|message"
|
||||
#define HOST_SEARCH "search"
|
||||
#define HOST_CERTIFICATE "certificate"
|
||||
#define HOST_REGEXP "file|person|forum|channel|search|message|certificate"
|
||||
|
||||
#define FILE_NAME "name"
|
||||
#define FILE_SIZE "size"
|
||||
@ -71,9 +74,15 @@
|
||||
#define MESSAGE_ID "id"
|
||||
#define MESSAGE_SUBJECT "subject"
|
||||
|
||||
#define HOST_SEARCH "search"
|
||||
#define SEARCH_KEYWORDS "keywords"
|
||||
|
||||
#define CERTIFICATE_SSLID "sslid"
|
||||
#define CERTIFICATE_GPG_ID "gpgid"
|
||||
#define CERTIFICATE_GPG_BASE64 "gpgbase64"
|
||||
#define CERTIFICATE_GPG_CHECKSUM "gpgchecksum"
|
||||
#define CERTIFICATE_LOCATION "location"
|
||||
#define CERTIFICATE_NAME "name"
|
||||
|
||||
RetroShareLink::RetroShareLink(const QUrl& url)
|
||||
{
|
||||
fromUrl(url);
|
||||
@ -208,6 +217,18 @@ void RetroShareLink::fromUrl(const QUrl& url)
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.host() == HOST_CERTIFICATE) {
|
||||
_type = TYPE_CERTIFICATE;
|
||||
_SSLid = url.queryItemValue(CERTIFICATE_SSLID);
|
||||
_name = url.queryItemValue(CERTIFICATE_NAME);
|
||||
_location = url.queryItemValue(CERTIFICATE_LOCATION);
|
||||
_GPGBase64String = url.queryItemValue(CERTIFICATE_GPG_BASE64);
|
||||
_GPGid = url.queryItemValue(CERTIFICATE_GPG_ID);
|
||||
_GPGBase64CheckSum = url.queryItemValue(CERTIFICATE_GPG_CHECKSUM);
|
||||
std::cerr << "Got a certificate link!!" << std::endl;
|
||||
check() ;
|
||||
return;
|
||||
}
|
||||
// bad link
|
||||
|
||||
#ifdef DEBUG_RSLINK
|
||||
@ -256,6 +277,51 @@ bool RetroShareLink::createPerson(const std::string& id)
|
||||
return valid();
|
||||
}
|
||||
|
||||
bool RetroShareLink::createCertificate(const std::string& ssl_id)
|
||||
{
|
||||
std::string invite = rsPeers->GetRetroshareInvite(ssl_id,false) ;
|
||||
|
||||
if(invite == "")
|
||||
{
|
||||
std::cerr << "RetroShareLink::createPerson() Couldn't get retroshare invite for ssl id: " << ssl_id << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsPeerDetails detail;
|
||||
if (rsPeers->getPeerDetails(ssl_id, detail) == false) {
|
||||
std::cerr << "RetroShareLink::createPerson() Couldn't find peer id " << ssl_id << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//_ssl_id = QString::fromStdString(id);
|
||||
_name = QString::fromUtf8(detail.name.c_str());
|
||||
QString gpg_cert = QString::fromStdString(invite) ;
|
||||
QString gpg_base_64 = QString::fromStdString(invite).section("\n\n",1).section("-----",0,0) ;
|
||||
|
||||
_GPGBase64CheckSum = gpg_base_64.section("=",-1,-1).section("\n",0,0) ;
|
||||
gpg_base_64 = gpg_base_64.section("\n=",0,0) ;
|
||||
|
||||
_type = TYPE_CERTIFICATE;
|
||||
|
||||
_GPGid = QString::fromStdString(detail.gpg_id).right(8);
|
||||
_SSLid = QString::fromStdString(ssl_id) ;
|
||||
_GPGBase64String = gpg_base_64.replace("\n","") ;
|
||||
_location = QString::fromStdString(detail.location) ;
|
||||
_name = QString::fromStdString(detail.name) ;
|
||||
|
||||
//_external_ipp = QString::fromStdString(invite).section("--EXT--",1,1) ;
|
||||
QString lst = QString::fromStdString(invite).section("--EXT--",0,0) ;
|
||||
//_local_ipp = lst.section("--LOCAL--",1,1) ;
|
||||
|
||||
std::cerr << "Found gpg base 64 string = " << _GPGBase64String.toStdString() << std::endl;
|
||||
std::cerr << "Found gpg base 64 checksum = " << _GPGBase64CheckSum.toStdString() << std::endl;
|
||||
std::cerr << "Found SSLId = " << _SSLid.toStdString() << std::endl;
|
||||
std::cerr << "Found GPGId = " << _GPGid.toStdString() << std::endl;
|
||||
//std::cerr << "Found External IP+Port = " << _external_ipp.toStdString() << std::endl;
|
||||
//std::cerr << "Found External IP+Port = " << _local_ipp.toStdString() << std::endl;
|
||||
std::cerr << "Found Location = " << _location.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
bool RetroShareLink::createForum(const std::string& id, const std::string& msgId)
|
||||
{
|
||||
clear();
|
||||
@ -440,6 +506,8 @@ QString RetroShareLink::title() const
|
||||
break;
|
||||
case TYPE_MESSAGE:
|
||||
return PeerDefs::rsidFromId(hash().toStdString());
|
||||
case TYPE_CERTIFICATE:
|
||||
return QObject::tr("Click to add this RetroShare cert to your GPG keyring\nand open the Make Friend Wizard.\n") + QString("GPG Id = ") + GPGId() + QString("\nSSLId = ")+SSLId();
|
||||
}
|
||||
|
||||
return "";
|
||||
@ -521,6 +589,20 @@ QString RetroShareLink::toString() const
|
||||
url.addQueryItem(MESSAGE_SUBJECT, encodeItem(_subject));
|
||||
}
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
case TYPE_CERTIFICATE:
|
||||
{
|
||||
QUrl url ;
|
||||
url.setScheme(RSLINK_SCHEME);
|
||||
url.setHost(HOST_CERTIFICATE) ;
|
||||
url.addQueryItem(CERTIFICATE_SSLID, _SSLid);
|
||||
url.addQueryItem(CERTIFICATE_GPG_ID, _GPGid);
|
||||
url.addQueryItem(CERTIFICATE_GPG_BASE64, _GPGBase64String);
|
||||
url.addQueryItem(CERTIFICATE_GPG_CHECKSUM, _GPGBase64CheckSum);
|
||||
url.addQueryItem(CERTIFICATE_LOCATION, encodeItem(_location));
|
||||
url.addQueryItem(CERTIFICATE_NAME, encodeItem(_name));
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
}
|
||||
@ -534,6 +616,9 @@ QString RetroShareLink::niceName() const
|
||||
return PeerDefs::rsid(name().toUtf8().constData(), hash().toStdString());
|
||||
}
|
||||
|
||||
if(type() == TYPE_CERTIFICATE)
|
||||
return QString("RetroShare Certificate (") + _name + ", @ " + _location + ")" ; // should add SSL id there
|
||||
|
||||
return name();
|
||||
}
|
||||
|
||||
@ -743,6 +828,10 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
||||
QStringList messageReceipientNotAccepted;
|
||||
QStringList messageReceipientUnknown;
|
||||
|
||||
// Certificate
|
||||
QStringList GPGBase64Strings ;
|
||||
QStringList SSLIds ;
|
||||
|
||||
// summary
|
||||
QList<QStringList*> processedList;
|
||||
QList<QStringList*> errorList;
|
||||
@ -760,11 +849,44 @@ static void processList(QStringList &list, const QString &textSingular, const QS
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (link.type()) {
|
||||
switch (link.type())
|
||||
{
|
||||
case TYPE_UNKNOWN:
|
||||
countUnknown++;
|
||||
break;
|
||||
|
||||
case TYPE_CERTIFICATE:
|
||||
{
|
||||
#ifdef DEBUG_RSLINK
|
||||
std::cerr << " RetroShareLink::process certificate." << std::endl;
|
||||
#endif
|
||||
needNotifySuccess = true;
|
||||
|
||||
QString RS_Certificate ;
|
||||
RS_Certificate += "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" ;
|
||||
RS_Certificate += "Version: Retroshare Generated cert.\n" ;
|
||||
RS_Certificate += "\n" ;
|
||||
|
||||
QString radix = link.GPGRadix64Key() ;
|
||||
|
||||
while(radix.size() > 64)
|
||||
{
|
||||
RS_Certificate += radix.left(64) + "\n" ;
|
||||
radix = radix.right(radix.size() - 64) ;
|
||||
}
|
||||
RS_Certificate += radix.left(64) + "\n" ;
|
||||
RS_Certificate += "=" + link.GPGBase64CheckSum() + "\n" ;
|
||||
RS_Certificate += "-----END PGP PUBLIC KEY BLOCK-----\n" ;
|
||||
RS_Certificate += "--SSLID--" + link.SSLId() + ";--LOCATION--" + link.location() + ";\n" ;
|
||||
|
||||
std::cerr << "Usign this certificate:" << std::endl;
|
||||
std::cerr << RS_Certificate.toStdString() << std::endl;
|
||||
|
||||
ConnectFriendWizard(NULL,RS_Certificate).exec() ;
|
||||
needNotifySuccess = false;
|
||||
}
|
||||
break ;
|
||||
|
||||
case TYPE_FILE:
|
||||
{
|
||||
#ifdef DEBUG_RSLINK
|
||||
@ -1219,3 +1341,4 @@ bool RSLinkClipboard::empty(RetroShareLink::enumType type /*= RetroShareLink::TY
|
||||
|
||||
return RetroShareLink::process(linksToProcess, flag);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@
|
||||
class RetroShareLink
|
||||
{
|
||||
public:
|
||||
enum enumType { TYPE_UNKNOWN, TYPE_FILE, TYPE_PERSON, TYPE_FORUM, TYPE_CHANNEL, TYPE_SEARCH, TYPE_MESSAGE };
|
||||
enum enumType { TYPE_UNKNOWN, TYPE_FILE, TYPE_PERSON, TYPE_FORUM, TYPE_CHANNEL, TYPE_SEARCH, TYPE_MESSAGE, TYPE_CERTIFICATE };
|
||||
|
||||
public:
|
||||
RetroShareLink();
|
||||
@ -61,6 +61,7 @@ class RetroShareLink
|
||||
bool createChannel(const std::string& id, const std::string& msgId);
|
||||
bool createSearch(const QString& keywords);
|
||||
bool createMessage(const std::string& peerId, const QString& subject);
|
||||
bool createCertificate(const std::string& peerId) ;
|
||||
|
||||
enumType type() const {return _type; }
|
||||
uint64_t size() const { return _size ; }
|
||||
@ -69,6 +70,11 @@ class RetroShareLink
|
||||
const QString& id() const { return _hash ; }
|
||||
const QString& msgId() const { return _msgId ; }
|
||||
const QString& subject() const { return _subject ; }
|
||||
const QString& GPGRadix64Key() const { return _GPGBase64String ; }
|
||||
const QString& GPGBase64CheckSum() const { return _GPGBase64CheckSum ; }
|
||||
const QString& SSLId() const { return _SSLid ; }
|
||||
const QString& GPGId() const { return _GPGid ; }
|
||||
const QString& location() const { return _location ; }
|
||||
QString title() const;
|
||||
|
||||
// get nice name for anchor
|
||||
@ -110,6 +116,11 @@ class RetroShareLink
|
||||
QString _hash; // or id (forum, channel, message)
|
||||
QString _msgId; // id of the message (forum, channel)
|
||||
QString _subject;
|
||||
QString _SSLid ; // ssl id for rs links
|
||||
QString _GPGid ; // ssl id for rs links
|
||||
QString _GPGBase64String ; // GPG Cert
|
||||
QString _GPGBase64CheckSum ; // GPG Cert
|
||||
QString _location ; // location
|
||||
};
|
||||
|
||||
/// This class handles the copy/paste of links. Every member is static to ensure unicity.
|
||||
|
@ -382,6 +382,9 @@ void FriendList::peerTreeWidgetCostumPopupMenu()
|
||||
|
||||
contextMnu.addAction(QIcon(IMAGE_CONNECT), tr("Connect To Friend"), this, SLOT(connectfriend()));
|
||||
|
||||
if (type == TYPE_SSL) {
|
||||
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy certificate link"), this, SLOT(copyFullCertificate()));
|
||||
}
|
||||
if (type == TYPE_GPG) {
|
||||
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink()));
|
||||
}
|
||||
@ -1254,6 +1257,20 @@ void FriendList::pastePerson()
|
||||
RSLinkClipboard::process(RetroShareLink::TYPE_PERSON);
|
||||
}
|
||||
|
||||
void FriendList::copyFullCertificate()
|
||||
{
|
||||
QTreeWidgetItem *c = getCurrentPeer();
|
||||
QList<RetroShareLink> urls;
|
||||
RetroShareLink link ;
|
||||
link.createCertificate(getRsId(c)) ;
|
||||
urls.push_back(link);
|
||||
|
||||
std::cerr << "link: " << std::endl;
|
||||
|
||||
std::cerr<< link.toString().toStdString() << std::endl;
|
||||
RSLinkClipboard::copyLinks(urls);
|
||||
}
|
||||
|
||||
void FriendList::copyLink()
|
||||
{
|
||||
QTreeWidgetItem *c = getCurrentPeer();
|
||||
|
@ -107,6 +107,7 @@ private slots:
|
||||
void chatfriend(QTreeWidgetItem *);
|
||||
void chatfriendproxy();
|
||||
void copyLink();
|
||||
void copyFullCertificate();
|
||||
// void exportfriend();
|
||||
void addFriend();
|
||||
void msgfriend();
|
||||
|
@ -64,7 +64,7 @@
|
||||
|
||||
//============================================================================
|
||||
//!
|
||||
ConnectFriendWizard::ConnectFriendWizard(QWidget *parent)
|
||||
ConnectFriendWizard::ConnectFriendWizard(QWidget *parent,const QString& cert)
|
||||
: QWizard(parent)
|
||||
{
|
||||
setPage(Page_Intro, new IntroPage);
|
||||
@ -77,8 +77,38 @@ ConnectFriendWizard::ConnectFriendWizard(QWidget *parent)
|
||||
setPage(Page_ErrorMessage, new ErrorMessagePage);
|
||||
setPage(Page_Conclusion, new ConclusionPage);
|
||||
|
||||
if(cert.isNull())
|
||||
setStartId(Page_Intro);
|
||||
else
|
||||
{
|
||||
RsPeerDetails pd;
|
||||
std::string error_string ;
|
||||
|
||||
if ( rsPeers->loadDetailsFromStringCert(cert.toUtf8().constData(), pd,error_string) )
|
||||
{
|
||||
#ifdef FRIEND_WIZARD_DEBUG
|
||||
std::cerr << "ConnectFriendWizard got id : " << pd.id << "; gpg_id : " << pd.gpg_id << std::endl;
|
||||
#endif
|
||||
setField(SSL_ID_FIELD_CONNECT_FRIEND_WIZARD, QString::fromStdString(pd.id));
|
||||
setField(GPG_ID_FIELD_CONNECT_FRIEND_WIZARD, QString::fromStdString(pd.gpg_id));
|
||||
setField(LOCATION_FIELD_CONNECT_FRIEND_WIZARD, QString::fromUtf8(pd.location.c_str()));
|
||||
setField(CERT_STRING_FIELD_CONNECT_FRIEND_WIZARD, cert);
|
||||
|
||||
setField("ext_friend_ip", QString::fromStdString(pd.extAddr));
|
||||
setField("ext_friend_port", QString::number(pd.extPort));
|
||||
setField("local_friend_ip", QString::fromStdString(pd.localAddr));
|
||||
setField("local_friend_port", QString::number(pd.localPort));
|
||||
setField("dyndns", QString::fromStdString(pd.dyndns));
|
||||
|
||||
setStartId(Page_Conclusion) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// error message
|
||||
setField("errorMessage", tr("Certificate Load Failed")+": "+QString::fromStdString(error_string) );
|
||||
setStartId(Page_ErrorMessage) ;
|
||||
}
|
||||
}
|
||||
|
||||
// this define comes from Qt example. I don't have mac, so it wasn't tested
|
||||
#ifndef Q_WS_MAC
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
|
||||
enum { Page_Intro, Page_Text, Page_Cert, Page_ErrorMessage, Page_Conclusion,Page_Foff, Page_Rsid, Page_Email };
|
||||
|
||||
ConnectFriendWizard(QWidget *parent = 0);
|
||||
ConnectFriendWizard(QWidget *parent = 0,const QString& cert = QString());
|
||||
|
||||
void setGroup(const std::string &groupId);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user