From e7871b598bc24336730cbc743d33dcbd5b0a0d73 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 13 Apr 2013 22:40:17 +0000 Subject: [PATCH] added code to create/paste/read private chat and msg links git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6305 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3chatservice.cc | 3 +- .../src/gui/CreateMsgLinkDialog.cpp | 80 ++++- retroshare-gui/src/gui/CreateMsgLinkDialog.h | 3 + retroshare-gui/src/gui/CreateMsgLinkDialog.ui | 320 ++++++++++++------ retroshare-gui/src/gui/RetroShareLink.cpp | 23 +- .../src/gui/common/FriendSelectionWidget.cpp | 13 +- .../src/gui/common/FriendSelectionWidget.h | 7 +- 7 files changed, 334 insertions(+), 115 deletions(-) diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 263618325..641b0a7c8 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -2957,7 +2957,7 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim unsigned char hash_bytes[16] ; RAND_bytes( hash_bytes, 16) ; - std::string hash = SSLIdType(hash_bytes).toStdString() ; + std::string hash = SSLIdType(hash_bytes).toStdString(false) ; std::cerr << "Created new distant chat invite: " << std::endl; std::cerr << " creation time stamp = " << invite.time_of_creation << std::endl; @@ -3009,6 +3009,7 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim _distant_chat_invites[hash] = invite ; } + encrypted_radix64_string = invite.encrypted_radix64_string ; std::cerr << "Encrypted radix64 string: " << invite.encrypted_radix64_string << std::endl; return true ; diff --git a/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp b/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp index 565e4a2e6..b7936f97d 100644 --- a/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp +++ b/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp @@ -19,8 +19,11 @@ ****************************************************************/ #include +#include +#include #include "CreateMsgLinkDialog.h" #include +#include CreateMsgLinkDialog::CreateMsgLinkDialog(QWidget *parent) :QDialog(NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint) @@ -28,39 +31,104 @@ CreateMsgLinkDialog::CreateMsgLinkDialog(QWidget *parent) /* Invoke the Qt Designer generated object setup routine */ setupUi(this); - setAttribute(Qt::WA_DeleteOnClose, true); + setAttribute(Qt::WA_DeleteOnClose, false); _info_GB->layout()->addWidget( _gpg_selection = new FriendSelectionWidget(this) ) ; QObject::connect(_link_type_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(update())) ; - QObject::connect(_create_link_PB,SIGNAL(clicked()),this,SLOT(create())) ; + QObject::connect(_create_link_PB,SIGNAL(clicked()),this,SLOT(createLink())) ; + QObject::connect(_create_new_PB,SIGNAL(toggled(bool)),this,SLOT(toggleCreateLink(bool))) ; + _gpg_selection->setModus(FriendSelectionWidget::MODUS_SINGLE) ; + _gpg_selection->setShowType(FriendSelectionWidget::SHOW_NON_FRIEND_GPG | FriendSelectionWidget::SHOW_GPG) ; + _gpg_selection->setHeaderText(QObject::tr("Select who can contact you:")) ; + _gpg_selection->start() ; + + toggleCreateLink(false) ; update() ; } +void CreateMsgLinkDialog::toggleCreateLink(bool b) +{ + _new_link_F->setHidden(!b) ; +} void CreateMsgLinkDialog::update() { if(_link_type_CB->currentIndex() == 0) { QString s ; - s += "A private chat invite allows a specific peer to contact you\nusing encrypted private chat. You need to select a destination peer from your PGP keyring\nbefore creating the link. The link contains the encryption code and your PGP signature, so that the peer can authenticate you." ; + s += "A private chat invite allows a specific peer to contact you using encrypted private chat. You need to select a destination peer from your PGP keyring before creating the link. The link contains the encryption code and your PGP signature, so that the peer can authenticate you." ; - _info_LB->setText(s) ; + _info_TB->setHtml(s) ; _gpg_selection->setHidden(false) ; } else { QString s ; - s += "A private chat invite allows a specific peer to contact you\nusing encrypted private chat. You need to select a destination peer from your PGP keyring\nbefore creating the link. The link contains the encryption code and your PGP signature, so that the peer can authenticate you." ; + s += "A public message link allows any peer in the nearby network to send a private message to you. The message is encrypted and only you can read it." ; - _info_LB->setText(s) ; + _info_TB->setHtml(s) ; _gpg_selection->setHidden(true) ; } } +time_t CreateMsgLinkDialog::computeValidityDuration() const +{ + time_t unit ; + + switch(_validity_time_CB->currentIndex()) + { + default: + case 0: unit = 3600 ; + break ; + case 1: unit = 3600*24 ; + break ; + case 2: unit = 3600*24*7 ; + break ; + case 3: unit = 3600*24*30 ; + break ; + case 4: unit = 3600*24*365 ; + break ; + } + + return unit * _validity_time_SB->value() ; +} + void CreateMsgLinkDialog::createLink() { std::cerr << "Creating link!" << std::endl; + + if(_link_type_CB->currentIndex() == 0) + { + time_t validity_duration = computeValidityDuration() ; + FriendSelectionWidget::IdType type ; + std::string current_pgp_id = _gpg_selection->selectedId(type) ; + + std::string encrypted_string ; + + bool res = rsMsgs->createDistantChatInvite(current_pgp_id,validity_duration,encrypted_string) ; + + RetroShareLink link ; + + if(!link.createPrivateChatInvite(validity_duration + time(NULL),QString::fromStdString(current_pgp_id),QString::fromStdString(encrypted_string)) ) + std::cerr << "Cannot create link." << std::endl; + + QList links ; + links.push_back(link) ; + + RSLinkClipboard::copyLinks(links) ; + + if(!res) + QMessageBox::critical(NULL,tr("Private chat invite creation failed"),tr("The creation of the chat invite failed")) ; + else + QMessageBox::information(NULL,tr("Private chat invite created"),tr("Your new chat invite has been copied to clipboard. You can now paste it as a Retroshare link.")) ; + + } + else + { + std::cerr << "Private msg links not yet implemented." << std::endl; + } } + diff --git a/retroshare-gui/src/gui/CreateMsgLinkDialog.h b/retroshare-gui/src/gui/CreateMsgLinkDialog.h index ed366177d..709a9935a 100644 --- a/retroshare-gui/src/gui/CreateMsgLinkDialog.h +++ b/retroshare-gui/src/gui/CreateMsgLinkDialog.h @@ -37,8 +37,11 @@ class CreateMsgLinkDialog : public QDialog, public Ui::CreateMsgLinkDialog /* actions to take.... */ void createLink(); void update() ; + void toggleCreateLink(bool) ; private: + time_t computeValidityDuration() const ; + /** Qt Designer generated object */ FriendSelectionWidget *_gpg_selection ; }; diff --git a/retroshare-gui/src/gui/CreateMsgLinkDialog.ui b/retroshare-gui/src/gui/CreateMsgLinkDialog.ui index d637c66c6..a0cf98e8e 100644 --- a/retroshare-gui/src/gui/CreateMsgLinkDialog.ui +++ b/retroshare-gui/src/gui/CreateMsgLinkDialog.ui @@ -6,131 +6,253 @@ 0 0 - 497 - 174 + 565 + 465 Dialog - + - + - - - Invite type: - - + - + - - Private chat - + + + + + + + Valid until: + + + + + + + Type: + + + + + + + Hash: + + + + + + + Usable by: + + + + + + + + + + + + + + + + + + + + + + - - Public message - + + + + + Copy to clipboard + + + + + + + Create new + + + true + + + + - - - - - - Valid until: - - - - - + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - - Information + + + QFrame::StyledPanel - + + QFrame::Raised + + - - - TextLabel + + + + + Invite type: + + + + + + + + Private chat + + + + + Public message + + + + + + + + Validity time : + + + + + + + 1 + + + 30 + + + 5 + + + + + + + + hour + + + + + day + + + + + week + + + + + month + + + + + year + + + + + + + + + + Information + + + + + + + + + + + Create! + + + + + + + Link: + + + + + + + + - - - - - - Create! - - - - - - - Link: - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - + _link_type_CB + label + dateTimeEdit + label_2 + label_4 + lineEdit + _create_link_PB + label_2 + _existing_links_LV + _current_link_date_DE + label_3 + label_5 + label_6 + label_7 + pushButton + _current_link_type_LE + _current_link_dst_LE + _current_link_hash_LE + verticalSpacer + _create_new_PB + _new_link_F - - - buttonBox - accepted() - CreateMsgLinkDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - CreateMsgLinkDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 74f99737f..c58631c30 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -91,6 +91,7 @@ #define PRIVATE_CHAT_TIME_STAMP "time_stamp" #define PRIVATE_CHAT_STRING "encrypted_data" +#define PRIVATE_CHAT_GPG_ID "gpgid" #define PUBLIC_MSG_TIME_STAMP "time_stamp" #define PUBLIC_MSG_SRC_PGP_ID "gpgid" @@ -116,7 +117,8 @@ void RetroShareLink::fromString(const QString& url) #endif if ((url.startsWith(QString(RSLINK_SCHEME) + "://" + QString(HOST_FILE)) && url.count("|") == 3) || - (url.startsWith(QString(RSLINK_SCHEME) + "://" + QString(HOST_PERSON)) && url.count("|") == 2)) { + (url.startsWith(QString(RSLINK_SCHEME) + "://" + QString(HOST_PERSON)) && url.count("|") == 2)) + { /* Old link, we try it */ QStringList list = url.split ("|"); @@ -196,6 +198,7 @@ void RetroShareLink::fromUrl(const QUrl& url) _type = TYPE_PRIVATE_CHAT ; _time_stamp = url.queryItemValue(PRIVATE_CHAT_TIME_STAMP).toUInt(&ok) ; _encrypted_chat_info = url.queryItemValue(PRIVATE_CHAT_STRING) ; + _GPGid = url.queryItemValue(PRIVATE_CHAT_GPG_ID) ; check() ; return; @@ -334,8 +337,10 @@ bool RetroShareLink::createPrivateChatInvite(time_t time_stamp,const QString& gp { clear() ; + _type = TYPE_PRIVATE_CHAT ; _time_stamp = time_stamp ; _encrypted_chat_info = encrypted_chat_info ; + _GPGid = gpg_id ; check() ; @@ -345,6 +350,7 @@ bool RetroShareLink::createPublicMsgInvite(time_t time_stamp,const QString& pgp_ { clear() ; + _type = TYPE_PUBLIC_MSG ; _time_stamp = time_stamp ; _hash = hash ; _GPGid = pgp_id ; @@ -575,6 +581,7 @@ void RetroShareLink::check() case TYPE_PRIVATE_CHAT: if(!checkRadix64(_encrypted_chat_info)) _valid = false ; + if(!checkPGPId(_GPGid)) _valid = false ; break ; case TYPE_PUBLIC_MSG: @@ -709,6 +716,7 @@ QString RetroShareLink::toString() const url.setScheme(RSLINK_SCHEME) ; url.setHost(HOST_PRIVATE_CHAT) ; url.addQueryItem(PRIVATE_CHAT_TIME_STAMP,QString::number(_time_stamp)) ; + url.addQueryItem(PRIVATE_CHAT_GPG_ID,_GPGid) ; url.addQueryItem(PRIVATE_CHAT_STRING,_encrypted_chat_info) ; return url.toString() ; @@ -830,6 +838,12 @@ QString RetroShareLink::niceName() const return PeerDefs::rsid(name().toUtf8().constData(), hash().toStdString()); } + if(type() == TYPE_PRIVATE_CHAT) { + return QString("Private chat invite (Valid only for key %1)").arg(_GPGid); + } + if(type() == TYPE_PUBLIC_MSG) { + return QString("Click this line to contact %1 (%2)").arg(_GPGid) ; + } if(type() == TYPE_CERTIFICATE) { if (_location.isEmpty()) { return QString("RetroShare Certificate (%1)").arg(_name); @@ -945,9 +959,13 @@ bool RetroShareLink::checkRadix64(const QString& s) { unsigned char b(qb[i]) ; - if(!( (b > 46 && b < 58) || (b > 64 && b < 91) || (b > 96 && b < 123) || b=='+')) + if(!( (b > 46 && b < 58) || (b > 64 && b < 91) || (b > 96 && b < 123) || b=='+' || b=='=')) + { + std::cerr << "Character not allowed in radix: " << b << std::endl; return false; + } } + std::cerr << "Radix check: passed" << std::endl; return true ; } @@ -1178,6 +1196,7 @@ static void processList(const QStringList &list, const QString &textSingular, co std::cerr << "Opening a private chat window " << std::endl; std::cerr << " time_stamp = " << link._time_stamp << std::endl; std::cerr << " enc-string = " << link._encrypted_chat_info.toStdString() << std::endl; + std::cerr << " PGP Id = " << link._GPGid.toStdString() << std::endl; } break ; diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index f64129526..dc1d52d88 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -221,7 +221,7 @@ void FriendSelectionWidget::fillList() } std::list gpgIdsSelected; - if (mShowTypes & SHOW_GPG) { + if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) { selectedGpgIds(gpgIdsSelected, true); } @@ -235,10 +235,15 @@ void FriendSelectionWidget::fillList() std::list gpgIds; std::list::iterator gpgIt; - rsPeers->getGPGAcceptedList(gpgIds); + + if(mShowTypes & SHOW_NON_FRIEND_GPG) + rsPeers->getGPGAllList(gpgIds); + else + rsPeers->getGPGAcceptedList(gpgIds); std::list sslIds; std::list::iterator sslIt; + if ((mShowTypes & (SHOW_SSL | SHOW_GPG)) == SHOW_SSL) { rsPeers->getFriendList(sslIds); } @@ -295,7 +300,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 +471,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)) { diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.h b/retroshare-gui/src/gui/common/FriendSelectionWidget.h index 422da9716..742fb5c28 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.h +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.h @@ -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)