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
This commit is contained in:
csoler 2013-04-10 21:21:52 +00:00
parent 43b9117293
commit d0703df7e3
8 changed files with 78 additions and 23 deletions

View File

@ -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)

View File

@ -211,7 +211,8 @@ class RsMsgs
virtual ~RsMsgs() { return; }
/****************************************/
/* Message Items */
/* Message Items */
/****************************************/
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &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<std::string>& 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 ;
};

View File

@ -330,5 +330,9 @@ void p3Msgs::getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& 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) ;
}

View File

@ -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<std::string>& 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;

View File

@ -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 ;
}
}

View File

@ -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<std::string,DistantChatPeerInfo> _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) ;

View File

@ -28,6 +28,7 @@
#include <retroshare/rsiface.h>
#include <retroshare/rspeers.h>
#include <retroshare/rsdisc.h>
#include <retroshare/rsmsgs.h>
#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()
{

View File

@ -68,6 +68,7 @@ private slots:
void makeFriend() ;
void denyFriend() ;
void createChatLink() ;
void deleteCert() ;
void peerdetails();
void copyLink();