mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-03-01 11:21:25 -05: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
@ -58,6 +58,7 @@
|
|||||||
#define RS_MSG_USER_REQUEST 0x0400 /* user request */
|
#define RS_MSG_USER_REQUEST 0x0400 /* user request */
|
||||||
#define RS_MSG_FRIEND_RECOMMENDATION 0x0800 /* friend recommendation */
|
#define RS_MSG_FRIEND_RECOMMENDATION 0x0800 /* friend recommendation */
|
||||||
#define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_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_LEFT 0x01
|
||||||
#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02
|
#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 getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0;
|
||||||
virtual bool getMessage(const std::string &mId, MessageInfo &msg) = 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 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 MessageSend(MessageInfo &info) = 0;
|
||||||
virtual bool SystemMessage(const std::wstring &title, const std::wstring &message, uint32_t systemFlag) = 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);
|
return mMsgSrv->MessageSend(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool p3Msgs::decryptMessage(const std::string& mId)
|
||||||
|
{
|
||||||
|
return mMsgSrv->decryptMessage(mId);
|
||||||
|
}
|
||||||
bool p3Msgs::createDistantOfflineMessengingInvite(time_t ts, std::string& hash)
|
bool p3Msgs::createDistantOfflineMessengingInvite(time_t ts, std::string& hash)
|
||||||
{
|
{
|
||||||
return mMsgSrv->createDistantOfflineMessengingInvite(ts,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 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 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 SystemMessage(const std::wstring &title, const std::wstring &message, uint32_t systemFlag);
|
||||||
virtual bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
|
virtual bool MessageToDraft(MessageInfo &info, const std::string &msgParentId);
|
||||||
virtual bool MessageToTrash(const std::string &mid, bool bTrash);
|
virtual bool MessageToTrash(const std::string &mid, bool bTrash);
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
#include "util/rsstring.h"
|
#include "util/rsstring.h"
|
||||||
|
#include "util/radix64.h"
|
||||||
#include "util/rsrandom.h"
|
#include "util/rsrandom.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -125,7 +126,7 @@ void p3MsgService::processMsg(RsMsgItem *mi, bool incoming)
|
|||||||
{
|
{
|
||||||
/* from a peer */
|
/* 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;
|
mi->msgFlags |= RS_MSG_FLAGS_NEW;
|
||||||
|
|
||||||
pqiNotify *notify = getPqiNotify();
|
pqiNotify *notify = getPqiNotify();
|
||||||
@ -1382,6 +1383,10 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
|||||||
{
|
{
|
||||||
mi.msgflags |= RS_MSG_NEW;
|
mi.msgflags |= RS_MSG_NEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg->msgFlags & RS_MSG_FLAGS_ENCRYPTED)
|
||||||
|
mi.msgflags |= RS_MSG_ENCRYPTED ;
|
||||||
|
|
||||||
if (msg->msgFlags & RS_MSG_FLAGS_TRASH)
|
if (msg->msgFlags & RS_MSG_FLAGS_TRASH)
|
||||||
{
|
{
|
||||||
mi.msgflags |= RS_MSG_TRASH;
|
mi.msgflags |= RS_MSG_TRASH;
|
||||||
@ -1467,6 +1472,9 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
|
|||||||
{
|
{
|
||||||
mis.msgflags = 0;
|
mis.msgflags = 0;
|
||||||
|
|
||||||
|
if (msg->msgFlags & RS_MSG_FLAGS_ENCRYPTED)
|
||||||
|
mis.msgflags |= RS_MSG_ENCRYPTED ;
|
||||||
|
|
||||||
/* translate flags, if we sent it... outgoing */
|
/* translate flags, if we sent it... outgoing */
|
||||||
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||||
/*|| (msg->PeerId() == mLinkMgr->getOwnId())*/)
|
/*|| (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.
|
// 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 ;
|
delete[] encrypted_data ;
|
||||||
|
|
||||||
std::wstring encrypted_msg ;
|
std::wstring encrypted_msg ;
|
||||||
@ -1651,9 +1660,47 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
return true ;
|
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 ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
|||||||
bool getMessage(const std::string &mid, MessageInfo &msg);
|
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);
|
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 removeMsgId(const std::string &mid);
|
||||||
bool markMsgIdRead(const std::string &mid, bool bUnreadByUser);
|
bool markMsgIdRead(const std::string &mid, bool bUnreadByUser);
|
||||||
bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask);
|
bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask);
|
||||||
@ -138,7 +139,6 @@ int checkOutgoingMessages();
|
|||||||
// Utility functions
|
// Utility functions
|
||||||
|
|
||||||
bool encryptMessage(const std::string& pgp_id,RsMsgItem *msg) ;
|
bool encryptMessage(const std::string& pgp_id,RsMsgItem *msg) ;
|
||||||
bool decryptMessage(RsMsgItem *msg) ;
|
|
||||||
|
|
||||||
void manageDistantPeers() ;
|
void manageDistantPeers() ;
|
||||||
void sendTurtleData(const std::string& hash,RsMsgItem *) ;
|
void sendTurtleData(const std::string& hash,RsMsgItem *) ;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include "MessagesDialog.h"
|
#include "MessagesDialog.h"
|
||||||
@ -118,8 +119,8 @@ MessagesDialog::MessagesDialog(QWidget *parent)
|
|||||||
inChange = false;
|
inChange = false;
|
||||||
lockUpdate = 0;
|
lockUpdate = 0;
|
||||||
|
|
||||||
connect(ui.messagestreeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(messageslistWidgetCostumPopupMenu(QPoint)));
|
connect(ui.messagestreeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(messageslistWidgetCustomPopupMenu(QPoint)));
|
||||||
connect(ui.listWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(folderlistWidgetCostumPopupMenu(QPoint)));
|
connect(ui.listWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(folderlistWidgetCustomPopupMenu(QPoint)));
|
||||||
connect(ui.messagestreeView, SIGNAL(clicked(const QModelIndex&)) , this, SLOT(clicked(const QModelIndex&)));
|
connect(ui.messagestreeView, SIGNAL(clicked(const QModelIndex&)) , this, SLOT(clicked(const QModelIndex&)));
|
||||||
connect(ui.messagestreeView, SIGNAL(doubleClicked(const QModelIndex&)) , this, SLOT(doubleClicked(const QModelIndex&)));
|
connect(ui.messagestreeView, SIGNAL(doubleClicked(const QModelIndex&)) , this, SLOT(doubleClicked(const QModelIndex&)));
|
||||||
connect(ui.listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(changeBox(int)));
|
connect(ui.listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(changeBox(int)));
|
||||||
@ -507,7 +508,7 @@ bool MessagesDialog::hasMessageStar(int nRow)
|
|||||||
return item->data(ROLE_MSGFLAGS).toInt() & RS_MSG_STAR;
|
return item->data(ROLE_MSGFLAGS).toInt() & RS_MSG_STAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint /*point*/ )
|
void MessagesDialog::messageslistWidgetCustomPopupMenu( QPoint /*point*/ )
|
||||||
{
|
{
|
||||||
std::string cid;
|
std::string cid;
|
||||||
std::string mid;
|
std::string mid;
|
||||||
@ -587,6 +588,9 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint /*point*/ )
|
|||||||
action->setDisabled(true);
|
action->setDisabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(nCount==1 && (msgInfo.msgflags & RS_MSG_ENCRYPTED))
|
||||||
|
action = contextMnu.addAction(QIcon(IMAGE_SYSTEM), tr("Decrypt Message"), this, SLOT(decryptSelectedMsg()));
|
||||||
|
|
||||||
int listrow = ui.listWidget->currentRow();
|
int listrow = ui.listWidget->currentRow();
|
||||||
if (listrow == ROW_TRASHBOX) {
|
if (listrow == ROW_TRASHBOX) {
|
||||||
action = contextMnu.addAction(tr("Undelete"), this, SLOT(undeletemessage()));
|
action = contextMnu.addAction(tr("Undelete"), this, SLOT(undeletemessage()));
|
||||||
@ -605,7 +609,7 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint /*point*/ )
|
|||||||
contextMnu.exec(QCursor::pos());
|
contextMnu.exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesDialog::folderlistWidgetCostumPopupMenu(QPoint /*point*/)
|
void MessagesDialog::folderlistWidgetCustomPopupMenu(QPoint /*point*/)
|
||||||
{
|
{
|
||||||
if (ui.listWidget->currentRow() != ROW_TRASHBOX) {
|
if (ui.listWidget->currentRow() != ROW_TRASHBOX) {
|
||||||
/* Context menu only neede for trash box */
|
/* Context menu only neede for trash box */
|
||||||
@ -1112,7 +1116,11 @@ void MessagesDialog::insertMessages()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Subject
|
// Subject
|
||||||
|
if(it->msgflags & RS_MSG_ENCRYPTED)
|
||||||
|
text = tr("Encrypted message. Right-click to decrypt it.") ;
|
||||||
|
else
|
||||||
text = QString::fromStdWString(it->title);
|
text = QString::fromStdWString(it->title);
|
||||||
|
|
||||||
item[COLUMN_SUBJECT]->setText(text);
|
item[COLUMN_SUBJECT]->setText(text);
|
||||||
item[COLUMN_SUBJECT]->setData(text + dateString, ROLE_SORT);
|
item[COLUMN_SUBJECT]->setData(text + dateString, ROLE_SORT);
|
||||||
|
|
||||||
@ -1464,6 +1472,26 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index, bool bSetToRead)
|
|||||||
updateInterface();
|
updateInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesDialog::decryptSelectedMsg()
|
||||||
|
{
|
||||||
|
MessageInfo msgInfo;
|
||||||
|
|
||||||
|
if (!rsMsgs->getMessage(mCurrMsgId, msgInfo))
|
||||||
|
return ;
|
||||||
|
|
||||||
|
if(!msgInfo.msgflags & RS_MSG_ENCRYPTED)
|
||||||
|
{
|
||||||
|
std::cerr << "This message is not encrypted! Cannot decrypt!" << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rsMsgs->decryptMessage(mCurrMsgId) )
|
||||||
|
QMessageBox::warning(NULL,tr("Decryption failed!"),tr("This message could not be decrypted.")) ;
|
||||||
|
|
||||||
|
//setMsgAsReadUnread(currentIndex.row(), true);
|
||||||
|
updateMessageSummaryList();
|
||||||
|
}
|
||||||
|
|
||||||
bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid)
|
bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid)
|
||||||
{
|
{
|
||||||
QModelIndex currentIndex = ui.messagestreeView->currentIndex();
|
QModelIndex currentIndex = ui.messagestreeView->currentIndex();
|
||||||
|
@ -60,8 +60,9 @@ public slots:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
/** Create the context popup menu and it's submenus */
|
/** Create the context popup menu and it's submenus */
|
||||||
void messageslistWidgetCostumPopupMenu( QPoint point );
|
void messageslistWidgetCustomPopupMenu( QPoint point );
|
||||||
void folderlistWidgetCostumPopupMenu(QPoint);
|
void folderlistWidgetCustomPopupMenu(QPoint);
|
||||||
|
void decryptSelectedMsg() ;
|
||||||
|
|
||||||
void changeBox(int newrow);
|
void changeBox(int newrow);
|
||||||
void changeQuickView(int newrow);
|
void changeQuickView(int newrow);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user