2011-07-11 11:53:41 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2008 Robert Fernie
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QDateTime>
# include <QTimer>
2011-08-21 18:28:19 -04:00
# include <QMessageBox>
2011-07-11 11:53:41 -04:00
# include "SecurityItem.h"
# include "FeedHolder.h"
2012-02-19 10:03:07 -05:00
# include "retroshare-gui/RsAutoUpdatePage.h"
2011-07-11 11:53:41 -04:00
# include "gui/msgs/MessageComposer.h"
# include "gui/common/StatusDefs.h"
2011-08-21 18:28:19 -04:00
# include "gui/connect/ConfCertDialog.h"
2012-08-28 19:39:11 -04:00
# include "gui/connect/ConnectFriendWizard.h"
2011-09-02 06:22:44 -04:00
# include "gui/common/AvatarDefs.h"
2012-11-15 16:35:37 -05:00
# include "util/DateTime.h"
2011-07-11 11:53:41 -04:00
# include "gui/notifyqt.h"
# include <retroshare/rsmsgs.h>
# include <retroshare/rspeers.h>
/*****
* # define DEBUG_ITEM 1
* * * */
/** Constructor */
2014-11-15 12:24:49 -05:00
SecurityItem : : SecurityItem ( FeedHolder * parent , uint32_t feedId , const RsPgpId & gpgId , const RsPeerId & sslId , const std : : string & sslCn , const std : : string & ip_address , uint32_t type , bool isHome ) :
FeedItem ( NULL ) , mParent ( parent ) , mFeedId ( feedId ) ,
mGpgId ( gpgId ) , mSslId ( sslId ) , mSslCn ( sslCn ) , mIP ( ip_address ) , mType ( type ) , mIsHome ( isHome )
2011-07-11 11:53:41 -04:00
{
2014-11-15 12:24:49 -05:00
/* Invoke the Qt Designer generated object setup routine */
setupUi ( this ) ;
2011-07-11 11:53:41 -04:00
2015-01-23 11:35:06 -05:00
//quickmsgButton->hide();
2014-11-15 12:24:49 -05:00
chatButton - > hide ( ) ;
removeFriendButton - > setEnabled ( false ) ;
removeFriendButton - > hide ( ) ;
peerDetailsButton - > setEnabled ( false ) ;
friendRequesttoolButton - > hide ( ) ;
requestLabel - > hide ( ) ;
2011-07-11 11:53:41 -04:00
2014-11-15 12:24:49 -05:00
/* general ones */
connect ( expandButton , SIGNAL ( clicked ( void ) ) , this , SLOT ( toggle ( void ) ) ) ;
connect ( clearButton , SIGNAL ( clicked ( void ) ) , this , SLOT ( removeItem ( void ) ) ) ;
2013-08-08 11:09:20 -04:00
2014-11-15 12:24:49 -05:00
/* specific ones */
connect ( chatButton , SIGNAL ( clicked ( void ) ) , this , SLOT ( openChat ( void ) ) ) ;
2011-07-11 11:53:41 -04:00
2015-01-23 11:35:06 -05:00
//connect( quickmsgButton, SIGNAL( clicked( ) ), this, SLOT( sendMsg() ) );
2011-07-11 11:53:41 -04:00
2014-11-15 12:24:49 -05:00
connect ( removeFriendButton , SIGNAL ( clicked ( ) ) , this , SLOT ( removeFriend ( ) ) ) ;
connect ( peerDetailsButton , SIGNAL ( clicked ( ) ) , this , SLOT ( peerDetails ( ) ) ) ;
connect ( friendRequesttoolButton , SIGNAL ( clicked ( ) ) , this , SLOT ( friendRequest ( ) ) ) ;
2011-08-21 18:28:19 -04:00
2014-11-15 12:24:49 -05:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( friendsChanged ( ) ) , this , SLOT ( updateItem ( ) ) ) ;
2011-07-11 11:53:41 -04:00
2014-11-15 12:24:49 -05:00
avatar - > setId ( mSslId ) ;
2011-09-05 17:19:07 -04:00
2014-11-15 12:24:49 -05:00
expandFrame - > hide ( ) ;
2012-11-10 13:59:58 -05:00
2014-11-15 12:24:49 -05:00
updateItemStatic ( ) ;
updateItem ( ) ;
2011-07-11 11:53:41 -04:00
}
2014-03-17 16:56:06 -04:00
bool SecurityItem : : isSame ( const RsPeerId & sslId , uint32_t type )
2011-07-11 11:53:41 -04:00
{
if ( ( mSslId = = sslId ) & & ( mType = = type ) )
{
return true ;
}
return false ;
}
void SecurityItem : : updateItemStatic ( )
{
if ( ! rsPeers )
return ;
/* fill in */
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::updateItemStatic() " ;
std : : cerr < < std : : endl ;
# endif
QString title ;
switch ( mType )
{
2014-01-15 15:19:17 -05:00
case RS_FEED_ITEM_SEC_CONNECT_ATTEMPT :
2011-07-11 11:53:41 -04:00
title = tr ( " Connect Attempt " ) ;
2012-09-07 13:30:23 -04:00
requestLabel - > show ( ) ;
2012-03-30 05:30:52 -04:00
avatar - > setDefaultAvatar ( " :images/avatar_request.png " ) ;
2011-07-11 11:53:41 -04:00
break ;
2014-01-15 15:19:17 -05:00
case RS_FEED_ITEM_SEC_AUTH_DENIED :
2013-02-22 16:42:27 -05:00
title = tr ( " Connection refused by remote peer " ) ;
2012-09-07 13:30:23 -04:00
requestLabel - > hide ( ) ;
2013-06-21 07:45:11 -04:00
avatar - > setDefaultAvatar ( " :images/avatar_refused.png " ) ;
2011-07-11 11:53:41 -04:00
break ;
2014-01-15 15:19:17 -05:00
case RS_FEED_ITEM_SEC_UNKNOWN_IN :
2011-07-11 11:53:41 -04:00
title = tr ( " Unknown (Incoming) Connect Attempt " ) ;
2012-09-07 13:30:23 -04:00
requestLabel - > hide ( ) ;
2012-03-30 05:30:52 -04:00
avatar - > setDefaultAvatar ( " :images/avatar_request_unknown.png " ) ;
2011-07-11 11:53:41 -04:00
break ;
2014-01-15 15:19:17 -05:00
case RS_FEED_ITEM_SEC_UNKNOWN_OUT :
2011-07-11 11:53:41 -04:00
title = tr ( " Unknown (Outgoing) Connect Attempt " ) ;
2012-09-07 13:30:23 -04:00
requestLabel - > hide ( ) ;
2011-07-11 11:53:41 -04:00
break ;
2014-01-15 15:19:17 -05:00
case RS_FEED_ITEM_SEC_WRONG_SIGNATURE :
2014-01-16 15:51:13 -05:00
title = tr ( " Certificate has wrong signature!! This peer is not who he claims to be. " ) ;
2014-01-15 15:19:17 -05:00
requestLabel - > hide ( ) ;
break ;
2014-01-28 16:33:17 -05:00
case RS_FEED_ITEM_SEC_MISSING_CERTIFICATE :
2014-12-30 06:11:08 -05:00
title = tr ( " Peer/node not in friendlist (PGP id= " ) + QString : : fromStdString ( mGpgId . toStdString ( ) ) + " ) " ;
2014-01-28 16:33:17 -05:00
avatar - > setDefaultAvatar ( " :images/avatar_request_unknown.png " ) ;
requestLabel - > show ( ) ;
break ;
2014-01-15 15:19:17 -05:00
case RS_FEED_ITEM_SEC_BAD_CERTIFICATE :
2014-01-16 15:20:17 -05:00
{
RsPeerDetails details ;
2014-03-17 16:56:06 -04:00
if ( rsPeers - > getGPGDetails ( mGpgId , details ) )
title = tr ( " Missing/Damaged SSL certificate for key " ) + QString : : fromStdString ( mGpgId . toStdString ( ) ) ;
2014-01-16 15:20:17 -05:00
else
title = tr ( " Missing/Damaged certificate. Not a real Retroshare user. " ) ;
2014-01-15 15:19:17 -05:00
requestLabel - > hide ( ) ;
2014-01-16 15:20:17 -05:00
}
2014-01-15 15:19:17 -05:00
break ;
case RS_FEED_ITEM_SEC_INTERNAL_ERROR :
title = tr ( " Certificate caused an internal error. " ) ;
requestLabel - > hide ( ) ;
break ;
2011-07-11 11:53:41 -04:00
default :
title = tr ( " Unknown Security Issue " ) ;
2012-09-07 13:30:23 -04:00
requestLabel - > hide ( ) ;
2011-07-11 11:53:41 -04:00
break ;
}
titleLabel - > setText ( title ) ;
2011-08-22 05:32:03 -04:00
QDateTime currentTime = QDateTime : : currentDateTime ( ) ;
2012-11-15 16:35:37 -05:00
timeLabel - > setText ( DateTime : : formatLongDateTime ( currentTime . toTime_t ( ) ) ) ;
2011-08-22 05:32:03 -04:00
2011-07-11 11:53:41 -04:00
if ( mIsHome )
{
/* disable buttons */
clearButton - > setEnabled ( false ) ;
2011-08-21 18:28:19 -04:00
/* hide buttons */
2011-07-11 11:53:41 -04:00
clearButton - > hide ( ) ;
}
}
void SecurityItem : : updateItem ( )
{
if ( ! rsPeers )
return ;
/* fill in */
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::updateItem() " ;
std : : cerr < < std : : endl ;
# endif
2011-08-21 18:28:19 -04:00
2011-07-11 11:53:41 -04:00
if ( ! RsAutoUpdatePage : : eventsLocked ( ) ) {
RsPeerDetails details ;
2011-08-21 18:28:19 -04:00
/* first try sslid */
if ( ! rsPeers - > getPeerDetails ( mSslId , details ) )
2011-07-11 11:53:41 -04:00
{
2011-08-21 18:28:19 -04:00
/* then gpgid */
2014-03-17 16:56:06 -04:00
if ( ! rsPeers - > getGPGDetails ( mGpgId , details ) )
2011-08-21 18:28:19 -04:00
{
/* it is very likely that we will end up here for some of the
* Unknown peer cases . . . . so allow them here
*/
/* set peer name */
2013-01-19 14:24:08 -05:00
peerNameLabel - > setText ( QString ( " %1 (%2) " ) . arg ( tr ( " Unknown Peer " ) , QString : : fromUtf8 ( mSslCn . c_str ( ) ) ) ) ;
2011-08-21 18:28:19 -04:00
2014-03-17 16:56:06 -04:00
nameLabel - > setText ( QString : : fromUtf8 ( mSslCn . c_str ( ) ) + " ( " + QString : : fromStdString ( mGpgId . toStdString ( ) ) + " ) " ) ;
idLabel - > setText ( QString : : fromStdString ( mSslId . toStdString ( ) ) ) ;
2011-08-21 18:28:19 -04:00
statusLabel - > setText ( tr ( " Unknown Peer " ) ) ;
trustLabel - > setText ( tr ( " Unknown Peer " ) ) ;
locLabel - > setText ( tr ( " Unknown Peer " ) ) ;
2012-09-09 16:25:39 -04:00
ipLabel - > setText ( QString : : fromStdString ( mIP ) ) ; //tr("Unknown Peer"));
2011-08-21 18:28:19 -04:00
connLabel - > setText ( tr ( " Unknown Peer " ) ) ;
2012-03-31 19:05:30 -04:00
chatButton - > hide ( ) ;
2015-01-23 11:35:06 -05:00
//quickmsgButton->hide();
2012-10-08 19:06:34 -04:00
requestLabel - > hide ( ) ;
2012-10-08 08:48:38 -04:00
2013-08-08 11:09:20 -04:00
removeFriendButton - > setEnabled ( false ) ;
removeFriendButton - > hide ( ) ;
peerDetailsButton - > setEnabled ( false ) ;
2011-08-21 18:28:19 -04:00
return ;
}
2011-07-11 11:53:41 -04:00
}
2011-08-21 18:28:19 -04:00
/* set peer name */
2012-09-07 13:30:23 -04:00
peerNameLabel - > setText ( QString : : fromUtf8 ( details . name . c_str ( ) ) ) ;
2011-08-21 18:28:19 -04:00
/* expanded Info */
2014-03-17 16:56:06 -04:00
nameLabel - > setText ( QString : : fromUtf8 ( details . name . c_str ( ) ) + " ( " + QString : : fromStdString ( mGpgId . toStdString ( ) ) + " ) " ) ;
2012-09-09 16:25:39 -04:00
//idLabel->setText(QString::fromStdString(details.id));
2014-03-17 16:56:06 -04:00
idLabel - > setText ( QString : : fromStdString ( mSslId . toStdString ( ) ) ) ;
2011-08-21 18:28:19 -04:00
locLabel - > setText ( QString : : fromUtf8 ( details . location . c_str ( ) ) ) ;
2011-07-11 11:53:41 -04:00
/* top Level info */
QString status = StatusDefs : : peerStateString ( details . state ) ;
#if 0
/* Append additional status info from status service */
StatusInfo statusInfo ;
if ( ( rsStatus ) & & ( rsStatus - > getStatus ( * it , statusInfo ) ) )
{
status . append ( QString : : fromStdString ( " / " + RsStatusString ( statusInfo . status ) ) ) ;
}
# endif
statusLabel - > setText ( status ) ;
2011-08-21 18:28:19 -04:00
trustLabel - > setText ( QString : : fromStdString ( RsPeerTrustString ( details . trustLvl ) ) ) ;
2011-07-11 11:53:41 -04:00
2012-09-09 16:25:39 -04:00
ipLabel - > setText ( QString : : fromStdString ( mIP ) ) ; //QString("%1:%2/%3:%4").arg(QString::fromStdString(details.localAddr)).arg(details.localPort).arg(QString::fromStdString(details.extAddr)).arg(details.extPort));
2011-07-11 11:53:41 -04:00
connLabel - > setText ( StatusDefs : : connectStateString ( details ) ) ;
/* do buttons */
2011-08-21 18:28:19 -04:00
peerDetailsButton - > setEnabled ( true ) ;
2012-03-31 19:05:30 -04:00
if ( details . state & RS_PEER_STATE_CONNECTED )
{
chatButton - > show ( ) ;
}
else
{
chatButton - > hide ( ) ;
}
2011-08-21 18:28:19 -04:00
if ( details . accept_connection )
{
2012-04-04 11:44:35 -04:00
friendRequesttoolButton - > hide ( ) ;
2012-09-22 08:25:47 -04:00
requestLabel - > hide ( ) ;
2011-08-21 18:28:19 -04:00
removeFriendButton - > setEnabled ( true ) ;
removeFriendButton - > show ( ) ;
}
else
{
2012-04-04 11:44:35 -04:00
friendRequesttoolButton - > show ( ) ;
2012-09-22 08:25:47 -04:00
requestLabel - > show ( ) ;
2011-08-21 18:28:19 -04:00
removeFriendButton - > setEnabled ( false ) ;
removeFriendButton - > hide ( ) ;
}
2015-01-23 11:35:06 -05:00
//quickmsgButton->show();
2011-07-11 11:53:41 -04:00
}
/* slow Tick */
int msec_rate = 10129 ;
2011-08-21 18:28:19 -04:00
2011-07-11 11:53:41 -04:00
QTimer : : singleShot ( msec_rate , this , SLOT ( updateItem ( void ) ) ) ;
return ;
}
void SecurityItem : : toggle ( )
{
2014-11-15 12:24:49 -05:00
expand ( expandFrame - > isHidden ( ) ) ;
}
void SecurityItem : : expand ( bool open )
{
if ( mParent ) {
mParent - > lockLayout ( this , true ) ;
}
2012-10-08 19:06:34 -04:00
2014-11-15 12:24:49 -05:00
if ( open )
2011-07-11 11:53:41 -04:00
{
expandFrame - > show ( ) ;
expandButton - > setIcon ( QIcon ( QString ( " :/images/edit_remove24.png " ) ) ) ;
2011-08-21 18:28:19 -04:00
expandButton - > setToolTip ( tr ( " Hide " ) ) ;
2011-07-11 11:53:41 -04:00
}
else
{
expandFrame - > hide ( ) ;
expandButton - > setIcon ( QIcon ( QString ( " :/images/edit_add24.png " ) ) ) ;
2011-08-21 18:28:19 -04:00
expandButton - > setToolTip ( tr ( " Expand " ) ) ;
2011-07-11 11:53:41 -04:00
}
2012-10-08 19:06:34 -04:00
2014-11-15 12:24:49 -05:00
emit sizeChanged ( this ) ;
if ( mParent ) {
mParent - > lockLayout ( this , false ) ;
}
2011-07-11 11:53:41 -04:00
}
void SecurityItem : : removeItem ( )
{
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::removeItem() " ;
std : : cerr < < std : : endl ;
# endif
2012-10-08 19:06:34 -04:00
mParent - > lockLayout ( this , true ) ;
2011-07-11 11:53:41 -04:00
hide ( ) ;
2012-10-08 19:06:34 -04:00
mParent - > lockLayout ( this , false ) ;
2011-07-11 11:53:41 -04:00
if ( mParent )
{
mParent - > deleteFeedItem ( this , mFeedId ) ;
}
}
/*********** SPECIFIC FUNCTIOSN ***********************/
void SecurityItem : : removeFriend ( )
{
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::removeFriend() " ;
std : : cerr < < std : : endl ;
# endif
2011-08-21 18:28:19 -04:00
if ( ( QMessageBox : : question ( this , " RetroShare " , tr ( " Do you want to remove this Friend? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes )
{
rsPeers - > removeFriend ( mGpgId ) ;
}
2011-07-11 11:53:41 -04:00
}
2012-04-04 11:44:35 -04:00
void SecurityItem : : friendRequest ( )
{
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::friendReguest() " ;
std : : cerr < < std : : endl ;
# endif
2013-04-19 07:54:39 -04:00
ConnectFriendWizard * connectFriendWizard = new ConnectFriendWizard ;
2012-08-29 18:40:16 -04:00
connectFriendWizard - > setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
2013-09-01 18:18:39 -04:00
connectFriendWizard - > setGpgId ( mGpgId , mSslId , true ) ;
2013-04-19 07:54:39 -04:00
connectFriendWizard - > show ( ) ;
2012-04-04 11:44:35 -04:00
}
2013-04-19 07:54:39 -04:00
2011-08-21 18:28:19 -04:00
void SecurityItem : : peerDetails ( )
{
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::peerDetails() " ;
std : : cerr < < std : : endl ;
# endif
RsPeerDetails details ;
/* first try sslid */
if ( rsPeers - > getPeerDetails ( mSslId , details ) )
{
ConfCertDialog : : showIt ( mSslId , ConfCertDialog : : PageDetails ) ;
return ;
}
2011-07-11 11:53:41 -04:00
2011-08-21 18:28:19 -04:00
/* then gpgid */
2014-03-17 16:56:06 -04:00
if ( rsPeers - > getGPGDetails ( mGpgId , details ) )
2011-08-21 18:28:19 -04:00
{
ConfCertDialog : : showIt ( mGpgId , ConfCertDialog : : PageDetails ) ;
}
}
2011-07-11 11:53:41 -04:00
void SecurityItem : : sendMsg ( )
{
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::sendMsg() " ;
std : : cerr < < std : : endl ;
# endif
2014-03-29 10:18:05 -04:00
std : : cerr < < __PRETTY_FUNCTION__ < < " : suspended for now. " < < std : : endl ;
# ifdef SUSPENDED
2011-08-21 18:28:19 -04:00
MessageComposer * nMsgDialog = MessageComposer : : newMsg ( ) ;
if ( nMsgDialog = = NULL ) {
return ;
}
2011-07-11 11:53:41 -04:00
2014-03-17 16:56:06 -04:00
RsPeerId peerId ;
2013-08-08 11:09:20 -04:00
2014-03-17 16:56:06 -04:00
if ( rsMsgs - > getDistantMessagePeerId ( mGpgId , peerId ) )
2013-08-08 11:09:20 -04:00
{
2014-03-17 16:56:06 -04:00
nMsgDialog - > addRecipient ( MessageComposer : : TO , peerId , mGpgId ) ;
2013-08-08 11:09:20 -04:00
nMsgDialog - > show ( ) ;
nMsgDialog - > activateWindow ( ) ;
}
2011-07-11 11:53:41 -04:00
2014-03-29 10:18:05 -04:00
/* window will destroy itself! */
# endif
2011-07-11 11:53:41 -04:00
}
void SecurityItem : : openChat ( )
{
# ifdef DEBUG_ITEM
std : : cerr < < " SecurityItem::openChat() " ;
std : : cerr < < std : : endl ;
# endif
if ( mParent )
{
2014-03-17 16:56:06 -04:00
mParent - > openChat ( mSslId ) ;
2011-07-11 11:53:41 -04:00
}
}