From d0703df7e34f073457b8f2d74f31c393800b3cd8 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 10 Apr 2013 21:21:52 +0000 Subject: [PATCH] basic gui entry for creating a chat link. Fixed a few bugs git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6302 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pgp/pgphandler.cc | 36 +++++++++++++++++---- libretroshare/src/retroshare/rsmsgs.h | 13 ++++++-- libretroshare/src/rsserver/p3msgs.cc | 4 +++ libretroshare/src/rsserver/p3msgs.h | 2 ++ libretroshare/src/services/p3chatservice.cc | 16 ++++----- libretroshare/src/services/p3chatservice.h | 10 +++--- retroshare-gui/src/gui/NetworkDialog.cpp | 19 +++++++++++ retroshare-gui/src/gui/NetworkDialog.h | 1 + 8 files changed, 78 insertions(+), 23 deletions(-) diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index f9ee25bf4..2b0472476 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -980,13 +980,24 @@ bool PGPHandler::encryptDataBin(const PGPIdType& key_id,const void *data, const ops_create_info_delete(info); int tlen = ops_memory_get_length(buf) ; - memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ; - *encrypted_data_len = tlen ; + bool res ; + + if(*encrypted_data_len >= tlen) + { + memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ; + *encrypted_data_len = tlen ; + res = true ; + } + else + { + std::cerr << "Not enough room to fit encrypted data. Size given=" << *encrypted_data_len << ", required=" << tlen << std::endl; + res = false ; + } ops_memory_release(buf) ; free(buf) ; - return true ; + return res ; } bool PGPHandler::decryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *encrypted_data, unsigned int *encrypted_data_len) @@ -1071,10 +1082,21 @@ bool PGPHandler::SignDataBin(const PGPIdType& id,const void *data, const uint32_ if(!memres) return false ; - uint32_t tlen = std::min(*signlen,(uint32_t)ops_memory_get_length(memres)) ; + bool res ; + uint32_t slen = (uint32_t)ops_memory_get_length(memres); - memcpy(sign,ops_memory_get_data(memres),tlen) ; - *signlen = tlen ; + if(*signlen >= slen) + { + *signlen = slen ; + + memcpy(sign,ops_memory_get_data(memres),*signlen) ; + res = true ; + } + else + { + std::cerr << "(EE) memory chunk is not large enough for signature packet. Requred size: " << slen << " bytes." << std::endl; + res = false ; + } ops_memory_release(memres) ; free(memres) ; @@ -1090,7 +1112,7 @@ bool PGPHandler::SignDataBin(const PGPIdType& id,const void *data, const uint32_ hexdump( (unsigned char *)sign,*signlen) ; std::cerr << std::endl; #endif - return true ; + return res ; } bool PGPHandler::privateSignCertificate(const PGPIdType& ownId,const PGPIdType& id_of_key_to_sign) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index a600fe6dc..1957e87e0 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -211,7 +211,8 @@ class RsMsgs virtual ~RsMsgs() { return; } /****************************************/ - /* Message Items */ +/* Message Items */ +/****************************************/ virtual bool getMessageSummaries(std::list &msgList) = 0; virtual bool getMessage(const std::string &mId, MessageInfo &msg) = 0; @@ -242,7 +243,8 @@ virtual bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set) = virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0; /****************************************/ - /* Chat */ +/* Chat */ +/****************************************/ virtual bool sendPublicChat(const std::wstring& msg) = 0; virtual bool sendPrivateChat(const std::string& id, const std::wstring& msg) = 0; virtual int getPublicChatQueueCount() = 0; @@ -265,6 +267,10 @@ virtual void getAvatarData(const std::string& pid,unsigned char *& data,int& siz virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ; virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ; +/****************************************/ +/* Chat lobbies */ +/****************************************/ + virtual bool joinVisibleChatLobby(const ChatLobbyId& lobby_id) = 0 ; virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) = 0; virtual bool getVirtualPeerId(const ChatLobbyId& lobby_id,std::string& vpid) = 0; @@ -281,8 +287,11 @@ virtual bool setDefaultNickNameForChatLobby(const std::string& nick) = 0; virtual bool getDefaultNickNameForChatLobby(std::string& nick) = 0 ; virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t lobby_privacy_type) = 0 ; +/****************************************/ +/* Distant chat */ /****************************************/ +virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) = 0 ; }; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index f95567a4a..e05166885 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -330,5 +330,9 @@ void p3Msgs::getPendingChatLobbyInvites(std::list& invites) { mChatSrv->getPendingChatLobbyInvites(invites) ; } +bool p3Msgs::createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) +{ + return mChatSrv->createDistantChatInvite(pgp_id,time_of_validity,encrypted_string) ; +} diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 4da5b74ed..63e72c05d 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -183,6 +183,8 @@ class p3Msgs: public RsMsgs virtual bool getDefaultNickNameForChatLobby(std::string& nick) ; virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_type) ; + virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) ; + private: p3MsgService *mMsgSrv; diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index ea60117c4..263618325 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -2939,7 +2939,7 @@ void p3ChatService::sendTurtleData(RsChatItem *item, const std::string& virtual_ mTurtle->sendTurtleData(virtual_peer_id,gitem) ; } -bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) +bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_radix64_string) { // create the invite @@ -2957,12 +2957,12 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim unsigned char hash_bytes[16] ; RAND_bytes( hash_bytes, 16) ; - hash = SSLIdType(hash_bytes).toStdString() ; + std::string hash = SSLIdType(hash_bytes).toStdString() ; std::cerr << "Created new distant chat invite: " << std::endl; std::cerr << " creation time stamp = " << invite.time_of_creation << std::endl; std::cerr << " validity time stamp = " << invite.time_of_validity << std::endl; - std::cerr << " hash = " ; + std::cerr << " hash = " << hash << std::endl; std::cerr << " encryption key = " ; static const char outl[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' } ; for(uint32_t j = 0; j < 16; j++) { std::cerr << outl[ (invite.aes_key[j]>>4) ] ; std::cerr << outl[ invite.aes_key[j] & 0xf ] ; } @@ -2984,26 +2984,24 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim memcpy(data ,hash_bytes ,16) ; memcpy(data+16,invite.aes_key ,16) ; - PGPIdType own_gpg_id( rsPeers->getOwnId() ) ; + std::cerr << "Performing signature " << std::endl; uint32_t signlen = 400; if(!AuthGPG::getAuthGPG()->SignDataBin(data,32,data+32,&signlen)) return false ; - std::cerr << "Performing signature with id = " << own_gpg_id.toStdString() << std::endl; std::cerr << "Signature length = " << signlen << std::endl; // Then encrypt the whole data into a single string. - unsigned char *encrypted_data = NULL ; - uint32_t encrypted_size = 0 ; + unsigned char *encrypted_data = new unsigned char[2000] ; + uint32_t encrypted_size = 2000 ; if(!AuthGPG::getAuthGPG()->encryptDataBin(pgp_id,(unsigned char *)data,signlen+32,encrypted_data,&encrypted_size)) return false ; std::cerr << "Encrypted data size: " << encrypted_size << std::endl; - std::string encrypted_radix64_string ; Radix64::encode((const char *)encrypted_data,encrypted_size,invite.encrypted_radix64_string) ; { @@ -3035,8 +3033,8 @@ void p3ChatService::cleanDistantChatInvites() } else { - ++it ; std::cerr << " Keeping hash " << it->first << std::endl; + ++it ; } } diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 9f1c07dbe..f3e2d9f13 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -306,6 +306,11 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi public: void connectToTurtleRouter(p3turtle *) ; + // Creates the invite if the public key of the distant peer is available. + // Om success, stores the invite in the map above, so that we can respond to tunnel requests. + // + bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ; + private: struct DistantChatInvite { @@ -330,11 +335,6 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi // std::map _distant_chat_peers ; - // Creates the invite if the public key of the distant peer is available. - // Om success, stores the invite in the map above, so that we can respond to tunnel requests. - // - bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ; - // Overloaded from RsTurtleClientService virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id,std::string& description_info_string) ; diff --git a/retroshare-gui/src/gui/NetworkDialog.cpp b/retroshare-gui/src/gui/NetworkDialog.cpp index 44e58d12f..81c9d968b 100644 --- a/retroshare-gui/src/gui/NetworkDialog.cpp +++ b/retroshare-gui/src/gui/NetworkDialog.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "common/vmessagebox.h" #include "common/RSTreeWidgetItem.h" @@ -230,6 +231,11 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint /*point*/ ) connect( makefriendAct , SIGNAL( triggered() ), this, SLOT( makeFriend() ) ); contextMnu->addAction( makefriendAct); + + QAction* createChatLinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Create a distant chat invitation..." ), contextMnu ); + + connect( createChatLinkAct , SIGNAL( triggered() ), this, SLOT( createChatLink() ) ); + contextMnu->addAction( createChatLinkAct); #ifdef TODO if(detail.validLvl > RS_TRUST_LVL_MARGINAL) // it's a denied old friend. { @@ -285,6 +291,19 @@ void NetworkDialog::makeFriend() ConfCertDialog::showIt(getCurrentNeighbour()->text(COLUMN_PEERID).toStdString(), ConfCertDialog::PageTrust); } +void NetworkDialog::createChatLink() +{ + std::string pgp_id = getCurrentNeighbour()->text(COLUMN_PEERID).toStdString() ; + + std::cerr << "Creating chat link for pgp id " << pgp_id << std::endl; + + std::string hash,estr ; + rsMsgs->createDistantChatInvite(pgp_id,time(NULL)+3600,estr) ; + + std::cerr << "Created invite:" << std::endl; + std::cerr << " estr = " << estr << std::endl; +} + /** Shows Peer Information/Auth Dialog */ void NetworkDialog::peerdetails() { diff --git a/retroshare-gui/src/gui/NetworkDialog.h b/retroshare-gui/src/gui/NetworkDialog.h index 7aa68ce01..000708fbc 100644 --- a/retroshare-gui/src/gui/NetworkDialog.h +++ b/retroshare-gui/src/gui/NetworkDialog.h @@ -68,6 +68,7 @@ private slots: void makeFriend() ; void denyFriend() ; + void createChatLink() ; void deleteCert() ; void peerdetails(); void copyLink();