mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-06 08:05:18 -04:00
added message decryption on right-click for distant messages
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6356 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6f769b3b54
commit
ec7f992834
7 changed files with 95 additions and 12 deletions
|
@ -58,6 +58,7 @@
|
|||
#define RS_MSG_USER_REQUEST 0x0400 /* user request */
|
||||
#define RS_MSG_FRIEND_RECOMMENDATION 0x0800 /* friend recommendation */
|
||||
#define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_FRIEND_RECOMMENDATION)
|
||||
#define RS_MSG_ENCRYPTED 0x1000 /* message is encrypted */
|
||||
|
||||
#define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01
|
||||
#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02
|
||||
|
@ -244,6 +245,7 @@ virtual ~RsMsgs() { return; }
|
|||
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0;
|
||||
virtual bool getMessage(const std::string &mId, MessageInfo &msg) = 0;
|
||||
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox) = 0;
|
||||
virtual bool decryptMessage(const std::string& mId) = 0 ;
|
||||
|
||||
virtual bool MessageSend(MessageInfo &info) = 0;
|
||||
virtual bool SystemMessage(const std::wstring &title, const std::wstring &message, uint32_t systemFlag) = 0;
|
||||
|
|
|
@ -96,6 +96,10 @@ bool p3Msgs::MessageSend(MessageInfo &info)
|
|||
return mMsgSrv->MessageSend(info);
|
||||
}
|
||||
|
||||
bool p3Msgs::decryptMessage(const std::string& mId)
|
||||
{
|
||||
return mMsgSrv->decryptMessage(mId);
|
||||
}
|
||||
bool p3Msgs::createDistantOfflineMessengingInvite(time_t ts, std::string& hash)
|
||||
{
|
||||
return mMsgSrv->createDistantOfflineMessengingInvite(ts,hash) ;
|
||||
|
|
|
@ -58,6 +58,7 @@ class p3Msgs: public RsMsgs
|
|||
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox);
|
||||
|
||||
virtual bool MessageSend(MessageInfo &info);
|
||||
virtual bool decryptMessage(const std::string& mid);
|
||||
virtual bool SystemMessage(const std::wstring &title, const std::wstring &message, uint32_t systemFlag);
|
||||
virtual bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
|
||||
virtual bool MessageToTrash(const std::string &mid, bool bTrash);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "util/rsdebug.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/radix64.h"
|
||||
#include "util/rsrandom.h"
|
||||
|
||||
#include <iomanip>
|
||||
|
@ -125,7 +126,7 @@ void p3MsgService::processMsg(RsMsgItem *mi, bool incoming)
|
|||
{
|
||||
/* from a peer */
|
||||
|
||||
mi->msgFlags &= RS_MSG_FLAGS_SYSTEM; // remove flags
|
||||
mi->msgFlags &= (RS_MSG_FLAGS_ENCRYPTED | RS_MSG_FLAGS_SYSTEM); // remove flags except those
|
||||
mi->msgFlags |= RS_MSG_FLAGS_NEW;
|
||||
|
||||
pqiNotify *notify = getPqiNotify();
|
||||
|
@ -1382,6 +1383,10 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
|||
{
|
||||
mi.msgflags |= RS_MSG_NEW;
|
||||
}
|
||||
|
||||
if (msg->msgFlags & RS_MSG_FLAGS_ENCRYPTED)
|
||||
mi.msgflags |= RS_MSG_ENCRYPTED ;
|
||||
|
||||
if (msg->msgFlags & RS_MSG_FLAGS_TRASH)
|
||||
{
|
||||
mi.msgflags |= RS_MSG_TRASH;
|
||||
|
@ -1467,6 +1472,9 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
|
|||
{
|
||||
mis.msgflags = 0;
|
||||
|
||||
if (msg->msgFlags & RS_MSG_FLAGS_ENCRYPTED)
|
||||
mis.msgflags |= RS_MSG_ENCRYPTED ;
|
||||
|
||||
/* translate flags, if we sent it... outgoing */
|
||||
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||
/*|| (msg->PeerId() == mLinkMgr->getOwnId())*/)
|
||||
|
@ -1631,7 +1639,8 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||
|
||||
// Now turn the binary encrypted chunk into a readable radix string.
|
||||
//
|
||||
std::string armoured_data = PGPKeyManagement::makeArmouredKey(encrypted_data,encrypted_size,"Retroshare encrypted message") ;
|
||||
std::string armoured_data ;
|
||||
Radix64::encode((char *)encrypted_data,encrypted_size,armoured_data) ;
|
||||
delete[] encrypted_data ;
|
||||
|
||||
std::wstring encrypted_msg ;
|
||||
|
@ -1651,9 +1660,47 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool p3MsgService::decryptMessage(RsMsgItem *item)
|
||||
bool p3MsgService::decryptMessage(const std::string& mId)
|
||||
{
|
||||
std::cerr << "Not implemented!!" << std::endl;
|
||||
uint32_t msgId = atoi(mId.c_str());
|
||||
std::string encrypted_string ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<uint32_t, RsMsgItem *>::iterator mit = imsg.find(msgId);
|
||||
|
||||
if(mit == imsg.end() || !librs::util::ConvertUtf16ToUtf8(mit->second->message,encrypted_string))
|
||||
return false;
|
||||
}
|
||||
|
||||
char *encrypted_data ;
|
||||
size_t encrypted_size ;
|
||||
|
||||
Radix64::decode(encrypted_string,encrypted_data,encrypted_size) ;
|
||||
|
||||
uint32_t decrypted_size = encrypted_size + 500 ;
|
||||
unsigned char *decrypted_data = new unsigned char[decrypted_size] ;
|
||||
|
||||
if(!AuthGPG::getAuthGPG()->decryptDataBin(encrypted_data,encrypted_size,decrypted_data,&decrypted_size))
|
||||
{
|
||||
delete[] encrypted_data ;
|
||||
delete[] decrypted_data ;
|
||||
std::cerr << "decryption failed!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsMsgItem *item = dynamic_cast<RsMsgItem*>(_serialiser->deserialise(decrypted_data,&decrypted_size)) ;
|
||||
|
||||
if(item == NULL)
|
||||
return false ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
*imsg[msgId] = *item ;
|
||||
}
|
||||
delete item ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
|||
bool getMessage(const std::string &mid, MessageInfo &msg);
|
||||
void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox);
|
||||
|
||||
bool decryptMessage(const std::string& mid) ;
|
||||
bool removeMsgId(const std::string &mid);
|
||||
bool markMsgIdRead(const std::string &mid, bool bUnreadByUser);
|
||||
bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask);
|
||||
|
@ -138,7 +139,6 @@ int checkOutgoingMessages();
|
|||
// Utility functions
|
||||
|
||||
bool encryptMessage(const std::string& pgp_id,RsMsgItem *msg) ;
|
||||
bool decryptMessage(RsMsgItem *msg) ;
|
||||
|
||||
void manageDistantPeers() ;
|
||||
void sendTurtleData(const std::string& hash,RsMsgItem *) ;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue