2018-12-25 15:34:59 -05:00
/*******************************************************************************
* gui / GenCertDialog . cpp *
* *
* Copyright ( C ) 2006 Crypton < retroshare . project @ gmail . com > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 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 Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-14 22:18:48 -05:00
# include "GenCertDialog.h"
2016-08-06 11:15:56 -04:00
2010-05-01 11:17:23 -04:00
# include <QAbstractEventDispatcher>
2017-04-27 11:03:53 -04:00
# include <QLineEdit>
2007-11-14 22:18:48 -05:00
# include <QFileDialog>
2013-09-23 16:55:34 -04:00
# include <QGraphicsOpacityEffect>
2007-11-14 22:18:48 -05:00
# include <QMessageBox>
2017-04-23 19:23:05 -04:00
# include <QMenu>
2013-09-23 16:55:34 -04:00
# include <QMouseEvent>
# include <QTextBrowser>
2016-08-06 11:15:56 -04:00
# include <QTimer>
2013-09-23 16:55:34 -04:00
# include <QProgressBar>
2016-08-06 11:15:56 -04:00
# include <rshare.h>
# include "gui/settings/rsharesettings.h"
2018-07-27 06:33:06 -04:00
# include "TorControl/TorManager.h"
2016-08-06 11:15:56 -04:00
# include "util/misc.h"
# include <retroshare/rsidentity.h>
# include <retroshare/rsinit.h>
2017-02-12 09:27:13 -05:00
# include <retroshare/rsnotify.h>
2016-08-06 11:15:56 -04:00
# include <rsserver/rsaccounts.h>
# include <util/rsrandom.h>
2010-01-20 17:02:43 -05:00
# include <time.h>
2013-09-23 16:55:34 -04:00
# include <math.h>
2012-10-31 21:07:36 -04:00
# include <iostream>
2007-11-14 22:18:48 -05:00
2017-02-12 15:45:22 -05:00
# define IMAGE_GOOD ": / images / accepted16.png"
2017-04-23 19:23:05 -04:00
# define IMAGE_BAD ": / images / cancel.png"
2017-02-12 15:45:22 -05:00
2013-09-23 16:55:34 -04:00
class EntropyCollectorWidget : public QTextBrowser
{
public :
EntropyCollectorWidget ( QProgressBar * pr , QWidget * p = NULL )
: QTextBrowser ( p )
{
progress = pr ;
setMouseTracking ( true ) ;
entropy_values_collected = 0 ;
}
virtual void mouseMoveEvent ( QMouseEvent * e )
{
std : : cerr < < " Mouse moved: " < < e - > x ( ) < < " , " < < e - > y ( ) < < std : : endl ;
+ + entropy_values_collected ;
progress - > setValue ( entropy_values_collected * 100 / 4096 ) ;
}
int entropy_values_collected ;
QProgressBar * progress ;
} ;
class MyFilter : public QObject
{
public :
virtual bool eventFilter ( QObject * obj , QEvent * event )
{
if ( event - > type ( ) = = QEvent : : MouseMove )
std : : cerr < < " Mouse moved ! " < < std : : endl ;
return QObject : : eventFilter ( obj , event ) ;
}
} ;
void GenCertDialog : : grabMouse ( )
{
2015-12-28 07:45:22 -05:00
static uint32_t last_x = 0 ;
static uint32_t last_y = 0 ;
2013-09-23 16:55:34 -04:00
static uint32_t count = 0 ;
uint32_t x = QCursor : : pos ( ) . x ( ) ;
uint32_t y = QCursor : : pos ( ) . y ( ) ;
if ( last_x = = x & & last_y = = y )
return ;
last_x = x ;
last_y = y ;
// Let's do some shuffle with mouse coordinates. Does not need to be cryptographically random,
// since the random number generator will shuffle this appropriately in openssl.
//
uint32_t E = ( ( count * x * 86243 + y * y * 15641 ) & 0xffff ) ^ 0xb374 ;
uint32_t F = ( ( x * 44497 * y * count + x * x ) & 0xffff ) ^ 0x395b ;
+ + count ;
// std::cerr << "Mouse grabed at " << x << " " << y << ". Adding entropy E=" << std::hex << E << ", F=" << F << ", digit =" << E + (F << 16) << std::dec << std::endl;
ui . entropy_bar - > setValue ( count * 100 / 2048 ) ;
2017-02-12 17:35:43 -05:00
if ( ! mEntropyOk & & ui . entropy_bar - > value ( ) > = 20 )
2016-08-06 11:15:56 -04:00
{
2017-02-12 17:35:43 -05:00
mEntropyOk = true ;
updateCheckLabels ( ) ;
2016-08-06 11:15:56 -04:00
}
2013-09-23 16:55:34 -04:00
RsInit : : collectEntropy ( E + ( F < < 16 ) ) ;
}
2013-10-19 09:25:06 -04:00
//static bool MyEventFilter(void *message, long *result)
//{
// std::cerr << "Event called " << message << std::endl;
// return false ;
//}
2007-11-14 22:18:48 -05:00
/** Default constructor */
2012-11-06 18:26:47 -05:00
GenCertDialog : : GenCertDialog ( bool onlyGenerateIdentity , QWidget * parent )
2016-08-06 11:15:56 -04:00
: QDialog ( parent , Qt : : WindowSystemMenuHint | Qt : : WindowTitleHint | Qt : : WindowCloseButtonHint )
, mOnlyGenerateIdentity ( onlyGenerateIdentity )
, mGXSNickname ( " " )
2007-11-14 22:18:48 -05:00
{
2012-10-31 21:07:36 -04:00
/* Invoke Qt Designer generated QObject setup routine */
ui . setupUi ( this ) ;
2013-09-13 13:19:34 -04:00
2019-01-19 16:36:19 -05:00
//ui.headerFrame->setHeaderImage(QPixmap(":/icons/svg/profile.svg"));
//ui.headerFrame->setHeaderText(tr("Create a new profile"));
2017-04-23 19:23:05 -04:00
connect ( ui . reuse_existing_node_CB , SIGNAL ( triggered ( ) ) , this , SLOT ( switchReuseExistingNode ( ) ) ) ;
2018-07-26 13:25:30 -04:00
connect ( ui . adv_checkbox , SIGNAL ( toggled ( bool ) ) , this , SLOT ( setupState ( ) ) ) ;
2017-02-01 15:55:06 -05:00
connect ( ui . nodeType_CB , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( setupState ( ) ) ) ;
2012-10-31 21:07:36 -04:00
2016-08-06 11:15:56 -04:00
connect ( ui . genButton , SIGNAL ( clicked ( ) ) , this , SLOT ( genPerson ( ) ) ) ;
2012-10-31 21:07:36 -04:00
connect ( ui . importIdentity_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( importIdentity ( ) ) ) ;
connect ( ui . exportIdentity_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( exportIdentity ( ) ) ) ;
2017-02-12 15:45:22 -05:00
connect ( ui . password_input , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( updateCheckLabels ( ) ) ) ;
2017-08-20 07:17:28 -04:00
connect ( ui . password2_input , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( updateCheckLabels ( ) ) ) ;
2017-02-12 15:45:22 -05:00
connect ( ui . name_input , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( updateCheckLabels ( ) ) ) ;
connect ( ui . node_input , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( updateCheckLabels ( ) ) ) ;
2017-02-15 13:17:41 -05:00
connect ( ui . reuse_existing_node_CB , SIGNAL ( toggled ( bool ) ) , this , SLOT ( updateCheckLabels ( ) ) ) ;
2017-02-12 15:45:22 -05:00
2016-10-09 08:32:52 -04:00
connect ( ui . cbUseBob , SIGNAL ( clicked ( bool ) ) , this , SLOT ( useBobChecked ( bool ) ) ) ; ;
2013-09-23 16:55:34 -04:00
entropy_timer = new QTimer ;
entropy_timer - > start ( 20 ) ;
QObject : : connect ( entropy_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( grabMouse ( ) ) ) ;
ui . entropy_bar - > setValue ( 0 ) ;
2015-01-12 17:02:43 -05:00
// make sure that QVariant always takes an 'int' otherwise the program will crash!
2017-02-01 15:55:06 -05:00
ui . keylength_comboBox - > addItem ( " Default (2048 bits, recommended) " , QVariant ( 2048 ) ) ;
ui . keylength_comboBox - > addItem ( " High (3072 bits) " , QVariant ( 3072 ) ) ;
ui . keylength_comboBox - > addItem ( " Very high (4096 bits) " , QVariant ( 4096 ) ) ;
2015-01-12 17:02:43 -05:00
2017-07-30 08:31:52 -04:00
// Default value.
ui . node_input - > setText ( " My computer " ) ;
2012-03-18 08:26:15 -04:00
# if QT_VERSION >= 0x040700
2017-05-20 09:14:43 -04:00
ui . node_input - > setPlaceholderText ( tr ( " Node name " ) ) ;
ui . hiddenaddr_input - > setPlaceholderText ( tr ( " Tor/I2P address " ) ) ;
2017-07-30 19:10:01 -04:00
ui . name_input - > setPlaceholderText ( tr ( " Username " ) ) ;
2017-07-28 12:41:34 -04:00
ui . nickname_input - > setPlaceholderText ( tr ( " Chat name " ) ) ;
2017-05-20 09:14:43 -04:00
ui . password_input - > setPlaceholderText ( tr ( " Password " ) ) ;
2017-08-20 07:17:28 -04:00
ui . password2_input - > setPlaceholderText ( tr ( " Password again " ) ) ;
2012-03-18 08:26:15 -04:00
# endif
2013-07-04 16:22:09 -04:00
2016-08-06 11:15:56 -04:00
ui . nickname_input - > setMaxLength ( RSID_MAXIMUM_NICKNAME_SIZE ) ;
2012-10-31 21:07:36 -04:00
/* get all available pgp private certificates....
* mark last one as default .
*/
2017-04-23 19:23:05 -04:00
2018-07-26 13:25:30 -04:00
//QMenu *menu = new QMenu(tr("Advanced options"));
//menu->addAction(ui.adv_checkbox);
//menu->addAction(ui.reuse_existing_node_CB);
// ui.optionsButton->setMenu(menu);
2012-08-07 15:16:17 -04:00
2017-02-12 17:35:43 -05:00
mAllFieldsOk = false ;
mEntropyOk = false ;
2017-08-20 07:17:28 -04:00
# ifdef RS_ONLYHIDDENNODE
ui . adv_checkbox - > setChecked ( true ) ;
ui . adv_checkbox - > setVisible ( false ) ;
ui . nodeType_CB - > setCurrentIndex ( 1 ) ;
ui . nodeType_CB - > setEnabled ( false ) ;
# endif
2018-07-25 05:37:40 -04:00
//#ifdef RETROTOR
// ui.adv_checkbox->setChecked(false);
// ui.adv_checkbox->setVisible(true);
//#endif
2017-08-20 07:17:28 -04:00
2017-02-01 17:08:57 -05:00
initKeyList ( ) ;
setupState ( ) ;
2017-02-15 13:17:41 -05:00
updateCheckLabels ( ) ;
2012-08-07 15:16:17 -04:00
}
2013-09-23 16:55:34 -04:00
GenCertDialog : : ~ GenCertDialog ( )
{
entropy_timer - > stop ( ) ;
}
2017-02-01 17:08:57 -05:00
void GenCertDialog : : switchReuseExistingNode ( )
{
if ( ui . reuse_existing_node_CB - > isChecked ( ) )
{
// import an existing identity if needed. If none is available, keep the box unchecked.
if ( ! haveGPGKeys & & ! importIdentity ( ) )
ui . reuse_existing_node_CB - > setChecked ( false ) ;
}
initKeyList ( ) ;
setupState ( ) ;
}
void GenCertDialog : : initKeyList ( )
2012-08-07 15:16:17 -04:00
{
2012-10-31 21:07:36 -04:00
std : : cerr < < " Finding PGPUsers " < < std : : endl ;
ui . genPGPuser - > clear ( ) ;
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > pgpIds ;
std : : list < RsPgpId > : : iterator it ;
2015-05-21 05:03:58 -04:00
haveGPGKeys = false ;
2012-10-31 21:07:36 -04:00
2017-02-01 17:08:57 -05:00
if ( RsAccounts : : GetPGPLogins ( pgpIds ) ) {
for ( it = pgpIds . begin ( ) ; it ! = pgpIds . end ( ) ; + + it )
{
QVariant userData ( QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) ;
std : : string name , email ;
RsAccounts : : GetPGPLoginDetails ( * it , name , email ) ;
std : : cerr < < " Adding PGPUser: " < < name < < " id: " < < * it < < std : : endl ;
QString gid = QString : : fromStdString ( ( * it ) . toStdString ( ) ) . right ( 8 ) ;
2019-12-24 05:48:50 -05:00
ui . genPGPuser - > addItem ( QString : : fromUtf8 ( name . c_str ( ) ) + " ( " + gid + " ) " , userData ) ;
2017-02-01 17:08:57 -05:00
haveGPGKeys = true ;
}
2012-10-31 21:07:36 -04:00
}
2007-11-14 22:18:48 -05:00
}
2013-09-23 16:55:34 -04:00
void GenCertDialog : : mouseMoveEvent ( QMouseEvent * e )
{
std : : cerr < < " Mouse : " < < e - > x ( ) < < " , " < < e - > y ( ) < < std : : endl ;
QDialog : : mouseMoveEvent ( e ) ;
}
2017-02-01 15:55:06 -05:00
void GenCertDialog : : setupState ( )
{
2016-10-09 08:32:52 -04:00
bool adv_state = ui . adv_checkbox - > isChecked ( ) ;
2018-01-01 09:49:49 -05:00
2017-02-01 17:08:57 -05:00
if ( ! adv_state )
{
ui . reuse_existing_node_CB - > setChecked ( false ) ;
ui . keylength_comboBox - > setCurrentIndex ( 0 ) ;
2018-07-26 13:25:30 -04:00
// ui.nodeType_CB->setCurrentIndex(0);
2017-02-01 17:08:57 -05:00
}
2018-07-26 13:25:30 -04:00
ui . reuse_existing_node_CB - > setVisible ( adv_state ) ;
// ui.nodeType_CB->setVisible(adv_state) ;
// ui.nodeType_LB->setVisible(adv_state) ;
// ui.nodeTypeExplanation_TE->setVisible(adv_state) ;
2018-07-26 03:39:26 -04:00
bool hidden_state = ui . nodeType_CB - > currentIndex ( ) = = 1 | | ui . nodeType_CB - > currentIndex ( ) = = 2 ;
2017-02-01 15:55:06 -05:00
bool generate_new = ! ui . reuse_existing_node_CB - > isChecked ( ) ;
2018-07-26 03:39:26 -04:00
bool tor_auto = ui . nodeType_CB - > currentIndex ( ) = = 1 ;
2017-02-01 15:55:06 -05:00
genNewGPGKey = generate_new ;
2018-07-26 03:39:26 -04:00
switch ( ui . nodeType_CB - > currentIndex ( ) )
{
2018-07-26 13:25:30 -04:00
case 0 : ui . nodeTypeExplanation_TE - > setText ( tr ( " <b>Your IP is visible to trusted nodes only. You can also connect to hidden nodes if running Tor on your machine. Best choice for sharing with trusted friends.</b> " ) ) ;
2018-07-26 03:39:26 -04:00
break ;
case 1 : ui . nodeTypeExplanation_TE - > setText ( tr ( " <b>Your IP is hidden. All traffic happens over the Tor network. Best choice if you cannot trust friend nodes with your own IP.</b> " ) ) ;
break ;
2018-07-26 13:25:30 -04:00
case 2 : ui . nodeTypeExplanation_TE - > setText ( tr ( " <b>Hidden node for advanced users only. Allows to use other proxy solutions such as I2P.</b> " ) ) ;
2018-07-26 03:39:26 -04:00
break ;
}
2017-04-23 19:23:05 -04:00
//ui.no_node_label->setVisible(false);
2010-06-04 20:44:43 -04:00
2017-02-02 16:05:28 -05:00
setWindowTitle ( generate_new ? tr ( " Create new profile and new Retroshare node " ) : tr ( " Create new Retroshare node " ) ) ;
2019-01-19 16:36:19 -05:00
//ui.headerFrame->setHeaderText(generate_new?tr("Create a new profile and node"):tr("Create a new node"));
2016-08-06 11:15:56 -04:00
2017-04-23 19:23:05 -04:00
ui . reuse_existing_node_CB - > setEnabled ( adv_state ) ;
2017-02-01 17:08:57 -05:00
ui . importIdentity_PB - > setVisible ( adv_state & & ! generate_new ) ;
2019-12-24 05:48:50 -05:00
//ui.exportIdentity_PB->setVisible(adv_state && !generate_new) ;
ui . exportIdentity_PB - > setVisible ( false ) ; // not useful, and probably confusing
2016-08-06 11:15:56 -04:00
2017-02-01 17:08:57 -05:00
ui . genPGPuser - > setVisible ( adv_state & & haveGPGKeys & & ! generate_new ) ;
2016-08-06 11:15:56 -04:00
2017-04-23 19:23:05 -04:00
//ui.genprofileinfo_label->setVisible(false);
//ui.no_gpg_key_label->setText(tr("Welcome to Retroshare. Before you can proceed you need to create a profile and associate a node with it. To do so please fill out this form.\nAlternatively you can import a (previously exported) profile. Just uncheck \"Create a new profile\""));
//no_gpg_key_label->setVisible(false);
2016-08-06 11:15:56 -04:00
2017-02-01 17:08:57 -05:00
ui . name_label - > setVisible ( true ) ;
ui . name_input - > setVisible ( generate_new ) ;
2017-04-23 19:23:05 -04:00
//ui.header_label->setVisible(false) ;
2016-08-06 11:15:56 -04:00
2017-02-01 15:55:06 -05:00
ui . nickname_label - > setVisible ( adv_state & & ! mOnlyGenerateIdentity ) ;
ui . nickname_input - > setVisible ( adv_state & & ! mOnlyGenerateIdentity ) ;
2016-08-06 11:15:56 -04:00
2017-07-30 08:31:52 -04:00
ui . node_name_check_LB - > setVisible ( adv_state ) ;
ui . node_label - > setVisible ( adv_state ) ;
ui . node_input - > setVisible ( adv_state ) ;
2016-08-06 11:15:56 -04:00
2017-02-01 15:55:06 -05:00
ui . password_input - > setVisible ( true ) ;
2017-02-12 15:45:22 -05:00
ui . password_label - > setVisible ( true ) ;
2019-12-24 05:48:50 -05:00
if ( generate_new )
ui . password_input - > setToolTip ( tr ( " <html><p>Put a strong password here. This password will be required to start your Retroshare node and protects all your data.</p></html> " ) ) ;
else
ui . password_input - > setToolTip ( tr ( " <html><p>Please supply the existing password for the selected profile above.</p></html> " ) ) ;
2017-02-15 13:17:41 -05:00
ui . password2_check_LB - > setVisible ( generate_new ) ;
2017-08-20 07:17:28 -04:00
ui . password2_input - > setVisible ( generate_new ) ;
ui . password2_label - > setVisible ( generate_new ) ;
2016-08-06 11:15:56 -04:00
2017-02-01 15:55:06 -05:00
ui . keylength_label - > setVisible ( adv_state ) ;
ui . keylength_comboBox - > setVisible ( adv_state ) ;
2013-09-08 22:11:43 -04:00
2017-02-01 15:55:06 -05:00
ui . entropy_bar - > setVisible ( true ) ;
ui . genButton - > setVisible ( true ) ;
2018-07-26 03:39:26 -04:00
ui . hiddenaddr_input - > setVisible ( hidden_state & & ! tor_auto ) ;
ui . hiddenaddr_label - > setVisible ( hidden_state & & ! tor_auto ) ;
2017-07-30 08:31:52 -04:00
2018-07-26 03:39:26 -04:00
ui . hiddenport_label - > setVisible ( hidden_state & & ! tor_auto ) ;
ui . hiddenport_spinBox - > setVisible ( hidden_state & & ! tor_auto ) ;
2017-07-30 08:31:52 -04:00
2018-07-26 03:39:26 -04:00
ui . cbUseBob - > setVisible ( hidden_state & & ! tor_auto ) ;
2017-02-12 15:45:22 -05:00
2017-07-29 17:39:48 -04:00
if ( ! mAllFieldsOk )
{
ui . genButton - > setToolTip ( tr ( " <p>Node creation is disabled until all fields correctly set.</p> " ) ) ;
2017-07-30 08:31:52 -04:00
ui . genButton - > setVisible ( false ) ;
ui . generate_label - > setVisible ( false ) ;
2019-09-30 16:38:15 -04:00
ui . info_label - > setText ( " Please choose a profile name and password... " ) ;
2017-07-30 08:31:52 -04:00
ui . info_label - > setVisible ( true ) ;
2017-07-29 17:39:48 -04:00
}
else if ( ! mEntropyOk )
{
ui . genButton - > setToolTip ( tr ( " <p>Node creation is disabled until enough randomness is collected. Please mouve your mouse around until you reach at least 20%.</p> " ) ) ;
2017-07-30 08:31:52 -04:00
ui . genButton - > setVisible ( false ) ;
ui . generate_label - > setVisible ( false ) ;
2017-09-09 08:54:30 -04:00
ui . info_label - > setText ( " Please move your mouse randomly to generate enough random data to create your profile. " ) ;
2017-07-30 08:31:52 -04:00
ui . info_label - > setVisible ( true ) ;
2017-07-29 17:39:48 -04:00
}
else
2017-02-12 17:35:43 -05:00
{
ui . genButton - > setEnabled ( true ) ;
2017-04-23 19:23:05 -04:00
//ui.genButton->setIcon(QIcon(IMAGE_GOOD)) ;
2017-02-12 17:35:43 -05:00
ui . genButton - > setToolTip ( tr ( " Click to create your node and/or profile " ) ) ;
2017-07-30 08:31:52 -04:00
ui . genButton - > setVisible ( true ) ;
ui . generate_label - > setVisible ( false ) ;
ui . info_label - > setVisible ( false ) ;
2017-02-12 17:35:43 -05:00
}
2013-09-08 22:11:43 -04:00
}
2012-07-10 17:40:53 -04:00
void GenCertDialog : : exportIdentity ( )
{
2015-05-14 09:18:58 -04:00
QString fname = QFileDialog : : getSaveFileName ( this , tr ( " Export profile " ) , " " , tr ( " RetroShare profile files (*.asc) " ) ) ;
2012-07-10 17:40:53 -04:00
2016-07-31 15:03:45 -04:00
if ( fname . isNull ( ) ) return ;
if ( fname . right ( 4 ) . toUpper ( ) ! = " .ASC " ) fname + = " .asc " ;
2012-07-10 17:40:53 -04:00
QVariant data = ui . genPGPuser - > itemData ( ui . genPGPuser - > currentIndex ( ) ) ;
2014-03-17 16:56:06 -04:00
RsPgpId gpg_id ( data . toString ( ) . toStdString ( ) ) ;
2012-07-10 17:40:53 -04:00
2014-01-17 21:35:06 -05:00
if ( RsAccounts : : ExportIdentity ( fname . toStdString ( ) , gpg_id ) )
2015-05-14 09:18:58 -04:00
QMessageBox : : information ( this , tr ( " Profile saved " ) , tr ( " Your profile was successfully saved \n It is encrypted \n \n You can now copy it to another computer \n and use the import button to load it " ) ) ;
2012-07-10 17:40:53 -04:00
else
2015-05-14 09:18:58 -04:00
QMessageBox : : information ( this , tr ( " Profile not saved " ) , tr ( " Your profile was not saved. An error occurred. " ) ) ;
2012-07-10 17:40:53 -04:00
}
2012-10-31 21:07:36 -04:00
2017-02-12 15:45:22 -05:00
void GenCertDialog : : updateCheckLabels ( )
{
QPixmap good ( IMAGE_GOOD ) ;
QPixmap bad ( IMAGE_BAD ) ;
2017-02-15 13:17:41 -05:00
bool generate_new = ! ui . reuse_existing_node_CB - > isChecked ( ) ;
2017-02-12 17:35:43 -05:00
mAllFieldsOk = true ;
2017-02-28 04:07:45 -05:00
if ( ui . node_input - > text ( ) . length ( ) > = 3 )
2017-02-12 17:35:43 -05:00
ui . node_name_check_LB - > setPixmap ( good ) ;
else
{
mAllFieldsOk = false ;
ui . node_name_check_LB - > setPixmap ( bad ) ;
}
2017-02-28 04:07:45 -05:00
if ( ! generate_new | | ui . name_input - > text ( ) . length ( ) > = 3 )
2017-02-12 17:35:43 -05:00
ui . profile_name_check_LB - > setPixmap ( good ) ;
else
{
mAllFieldsOk = false ;
ui . profile_name_check_LB - > setPixmap ( bad ) ;
}
2017-02-28 04:07:45 -05:00
if ( ui . password_input - > text ( ) . length ( ) > = 3 )
2017-02-12 17:35:43 -05:00
ui . password_check_LB - > setPixmap ( good ) ;
else
{
mAllFieldsOk = false ;
ui . password_check_LB - > setPixmap ( bad ) ;
}
2017-08-20 07:17:28 -04:00
if ( ui . password_input - > text ( ) . length ( ) > = 3 & & ui . password_input - > text ( ) = = ui . password2_input - > text ( ) )
2017-02-12 17:35:43 -05:00
ui . password2_check_LB - > setPixmap ( good ) ;
else
{
2017-02-15 13:17:41 -05:00
if ( generate_new )
mAllFieldsOk = false ;
2017-02-12 17:35:43 -05:00
ui . password2_check_LB - > setPixmap ( bad ) ;
}
if ( mEntropyOk )
ui . randomness_check_LB - > setPixmap ( QPixmap ( IMAGE_GOOD ) ) ;
else
ui . randomness_check_LB - > setPixmap ( QPixmap ( IMAGE_BAD ) ) ;
2016-10-09 08:32:52 -04:00
setupState ( ) ;
}
void GenCertDialog : : useBobChecked ( bool checked )
{
if ( checked ) {
ui . hiddenaddr_input - > setPlaceholderText ( tr ( " I2P instance address with BOB enabled " ) ) ;
ui . hiddenaddr_label - > setText ( tr ( " I2P instance address " ) ) ;
ui . hiddenport_spinBox - > setEnabled ( false ) ;
} else {
ui . hiddenaddr_input - > setPlaceholderText ( tr ( " hidden service address " ) ) ;
ui . hiddenaddr_label - > setText ( tr ( " hidden address " ) ) ;
ui . hiddenport_spinBox - > setEnabled ( true ) ;
}
2017-02-12 15:45:22 -05:00
}
2017-02-01 17:08:57 -05:00
bool GenCertDialog : : importIdentity ( )
2012-07-10 17:40:53 -04:00
{
2016-08-06 11:15:56 -04:00
QString fname ;
if ( ! misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_CERT , tr ( " Import profile " ) , tr ( " RetroShare profile files (*.asc);;All files (*) " ) , fname ) )
2017-02-01 17:08:57 -05:00
return false ;
2012-07-10 17:40:53 -04:00
if ( fname . isNull ( ) )
2017-02-01 17:08:57 -05:00
return false ;
2012-07-10 17:40:53 -04:00
2014-03-17 16:56:06 -04:00
RsPgpId gpg_id ;
2012-07-12 15:20:31 -04:00
std : : string err_string ;
2012-07-10 17:40:53 -04:00
2014-01-17 21:35:06 -05:00
if ( ! RsAccounts : : ImportIdentity ( fname . toStdString ( ) , gpg_id , err_string ) )
2012-07-10 17:40:53 -04:00
{
2015-05-14 09:18:58 -04:00
QMessageBox : : information ( this , tr ( " Profile not loaded " ) , tr ( " Your profile was not loaded properly: " ) + " \n " + QString : : fromStdString ( err_string ) ) ;
2017-02-01 17:08:57 -05:00
return false ;
2012-07-10 17:40:53 -04:00
}
2012-08-07 15:16:17 -04:00
else
{
std : : string name , email ;
2014-01-17 21:35:06 -05:00
RsAccounts : : GetPGPLoginDetails ( gpg_id , name , email ) ;
2012-08-07 15:16:17 -04:00
std : : cerr < < " Adding PGPUser: " < < name < < " id: " < < gpg_id < < std : : endl ;
2012-07-10 17:40:53 -04:00
2019-12-24 05:48:50 -05:00
QMessageBox : : information ( this , tr ( " New profile imported " ) , tr ( " Your profile was imported successfully: " ) + " \n " + " \n Name : " + QString : : fromStdString ( name ) + " \n Key ID: " + QString : : fromStdString ( gpg_id . toStdString ( ) ) + " \n \n " + tr ( " You can use it now to create a new node. " ) ) ;
initKeyList ( ) ;
setupState ( ) ;
2012-07-10 17:40:53 -04:00
2017-02-01 17:08:57 -05:00
return true ;
}
2012-07-10 17:40:53 -04:00
}
2007-11-14 22:18:48 -05:00
void GenCertDialog : : genPerson ( )
{
/* Check the data from the GUI. */
2014-12-30 06:11:08 -05:00
std : : string genLoc = ui . node_input - > text ( ) . toUtf8 ( ) . constData ( ) ;
2014-03-17 16:56:06 -04:00
RsPgpId PGPId ;
2012-10-31 21:07:36 -04:00
2017-04-27 11:03:53 -04:00
if ( ui . nickname_input - > isVisible ( ) )
{
mGXSNickname = ui . nickname_input - > text ( ) ;
}
else
{
2017-07-29 15:48:12 -04:00
mGXSNickname = ui . name_input - > text ( ) ;
2017-04-27 11:03:53 -04:00
}
2016-08-06 11:15:56 -04:00
if ( ! mGXSNickname . isEmpty ( ) )
{
if ( mGXSNickname . size ( ) < RSID_MINIMUM_NICKNAME_SIZE )
{
std : : cerr < < " GenCertDialog::genPerson() GXS Nickname too short (min " < < RSID_MINIMUM_NICKNAME_SIZE < < " chars) " ;
std : : cerr < < std : : endl ;
QMessageBox : : warning ( this , " " , tr ( " The GXS nickname is too short. Please input at least %1 characters. " ) . arg ( RSID_MINIMUM_NICKNAME_SIZE ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
mGXSNickname = " " ;
return ;
}
if ( mGXSNickname . size ( ) > RSID_MAXIMUM_NICKNAME_SIZE )
{
std : : cerr < < " GenCertDialog::genPerson() GXS Nickname too long (max " < < RSID_MAXIMUM_NICKNAME_SIZE < < " chars) " ;
std : : cerr < < std : : endl ;
QMessageBox : : warning ( this , " " , tr ( " The GXS nickname is too long. Please reduce the length to %1 characters. " ) . arg ( RSID_MAXIMUM_NICKNAME_SIZE ) , QMessageBox : : Ok , QMessageBox : : Ok ) ;
mGXSNickname = " " ;
return ;
}
}
2018-07-27 06:33:06 -04:00
bool isHiddenLoc = ( ui . nodeType_CB - > currentIndex ( ) > 0 ) ;
bool isAutoTor = ( ui . nodeType_CB - > currentIndex ( ) = = 1 ) ;
if ( isAutoTor & & ! Tor : : TorManager : : isTorAvailable ( ) )
{
QMessageBox : : critical ( this , tr ( " Tor is not available " ) , tr ( " No Tor executable has been found on your system. You need to install Tor before creating a hidden identity. " ) ) ;
return ;
}
if ( isHiddenLoc )
2013-09-08 22:11:43 -04:00
{
std : : string hl = ui . hiddenaddr_input - > text ( ) . toStdString ( ) ;
uint16_t port = ui . hiddenport_spinBox - > value ( ) ;
2018-07-27 06:33:06 -04:00
2016-10-09 08:32:52 -04:00
bool useBob = ui . cbUseBob - > isChecked ( ) ;
if ( useBob & & hl . empty ( ) )
hl = " 127.0.0.1 " ;
RsInit : : SetHiddenLocation ( hl , port , useBob ) ; /* parses it */
2013-09-08 22:11:43 -04:00
}
2012-10-31 21:07:36 -04:00
2017-02-12 15:45:22 -05:00
if ( ! genNewGPGKey )
{
2012-10-31 21:07:36 -04:00
if ( genLoc . length ( ) < 3 ) {
/* Message Dialog */
QMessageBox : : warning ( this ,
2015-05-14 09:18:58 -04:00
tr ( " PGP key pair generation failure " ) ,
2014-12-30 06:11:08 -05:00
tr ( " Node field is required with a minimum of 3 characters " ) ,
2012-10-31 21:07:36 -04:00
QMessageBox : : Ok ) ;
return ;
}
int pgpidx = ui . genPGPuser - > currentIndex ( ) ;
if ( pgpidx < 0 )
{
/* Message Dialog */
QMessageBox : : warning ( this ,
2015-05-14 09:18:58 -04:00
tr ( " Profile generation failure " ) ,
tr ( " Missing PGP certificate " ) ,
2012-10-31 21:07:36 -04:00
QMessageBox : : Ok ) ;
return ;
}
QVariant data = ui . genPGPuser - > itemData ( pgpidx ) ;
2014-03-17 16:56:06 -04:00
PGPId = RsPgpId ( ( data . toString ( ) ) . toStdString ( ) ) ;
2012-10-31 21:07:36 -04:00
} else {
2012-12-04 06:42:34 -05:00
if ( ui . password_input - > text ( ) . length ( ) < 3 | | ui . name_input - > text ( ) . length ( ) < 3 | | genLoc . length ( ) < 3 ) {
2012-10-31 21:07:36 -04:00
/* Message Dialog */
QMessageBox : : warning ( this ,
2015-05-14 09:18:58 -04:00
tr ( " PGP key pair generation failure " ) ,
2012-10-31 21:07:36 -04:00
tr ( " All fields are required with a minimum of 3 characters " ) ,
QMessageBox : : Ok ) ;
return ;
}
2013-09-23 16:55:34 -04:00
2017-08-20 07:17:28 -04:00
if ( ui . password_input - > text ( ) ! = ui . password2_input - > text ( ) )
2013-09-23 16:55:34 -04:00
{
QMessageBox : : warning ( this ,
2015-05-14 09:18:58 -04:00
tr ( " PGP key pair generation failure " ) ,
2013-10-13 11:31:34 -04:00
tr ( " Passwords do not match " ) ,
2013-09-23 16:55:34 -04:00
QMessageBox : : Ok ) ;
return ;
}
2012-10-31 21:07:36 -04:00
//generate a new gpg key
std : : string err_string ;
2017-04-23 19:23:05 -04:00
//_key_label->setText(tr("Generating new node key, please be patient: this process needs generating large prime numbers, and can take some minutes on slow computers. \n\nFill in your password when asked, to sign your new key."));
//ui.no_gpg_key_label->show();
//ui.reuse_existing_node_CB->hide();
2012-10-31 21:07:36 -04:00
ui . name_label - > hide ( ) ;
ui . name_input - > hide ( ) ;
2016-08-06 11:15:56 -04:00
ui . nickname_label - > hide ( ) ;
ui . nickname_input - > hide ( ) ;
2017-08-20 07:17:28 -04:00
ui . password2_label - > hide ( ) ;
ui . password2_input - > hide ( ) ;
2017-02-15 13:17:41 -05:00
ui . password2_check_LB - > hide ( ) ;
ui . password_check_LB - > hide ( ) ;
2012-10-31 21:07:36 -04:00
ui . password_label - > hide ( ) ;
ui . password_input - > hide ( ) ;
2017-02-01 15:55:06 -05:00
//ui.genPGPuserlabel->hide();
2012-10-31 21:07:36 -04:00
ui . genPGPuser - > hide ( ) ;
2014-12-30 06:11:08 -05:00
ui . node_label - > hide ( ) ;
ui . node_input - > hide ( ) ;
2016-08-06 11:15:56 -04:00
ui . genButton - > hide ( ) ;
2012-10-31 21:07:36 -04:00
ui . importIdentity_PB - > hide ( ) ;
2017-04-23 19:23:05 -04:00
//ui.genprofileinfo_label->hide();
2017-02-01 15:55:06 -05:00
ui . nodeType_CB - > hide ( ) ;
2017-04-23 19:23:05 -04:00
//ui.adv_checkbox->hide();
2016-08-06 11:15:56 -04:00
ui . keylength_label - > hide ( ) ;
2015-01-12 17:02:43 -05:00
ui . keylength_comboBox - > hide ( ) ;
2012-10-31 21:07:36 -04:00
setCursor ( Qt : : WaitCursor ) ;
QCoreApplication : : processEvents ( ) ;
2016-02-12 11:54:35 -05:00
QAbstractEventDispatcher * ed = QAbstractEventDispatcher : : instance ( ) ;
2016-07-16 17:10:00 -04:00
std : : cout < < " Waiting ed->processEvents() " < < std : : endl ;
time_t waitEnd = time ( NULL ) + 10 ; //Wait no more than 10 sec to processEvents
2016-02-12 11:54:35 -05:00
if ( ed - > hasPendingEvents ( ) )
2016-07-16 17:10:00 -04:00
while ( ed - > processEvents ( QEventLoop : : AllEvents ) & & ( time ( NULL ) < waitEnd ) ) ;
2012-10-31 21:07:36 -04:00
2013-07-04 16:22:09 -04:00
std : : string email_str = " " ;
2016-07-16 17:10:00 -04:00
std : : cout < < " RsAccounts::GeneratePGPCertificate " < < std : : endl ;
2015-01-12 17:02:43 -05:00
RsAccounts : : GeneratePGPCertificate (
ui . name_input - > text ( ) . toUtf8 ( ) . constData ( ) ,
email_str . c_str ( ) ,
ui . password_input - > text ( ) . toUtf8 ( ) . constData ( ) ,
PGPId ,
ui . keylength_comboBox - > itemData ( ui . keylength_comboBox - > currentIndex ( ) ) . toInt ( ) ,
err_string ) ;
2012-10-31 21:07:36 -04:00
setCursor ( Qt : : ArrowCursor ) ;
}
2017-02-12 15:45:22 -05:00
// now cache the PGP password so that it's not asked again for immediately signing the key
rsNotify - > cachePgpPassphrase ( ui . password_input - > text ( ) . toUtf8 ( ) . constData ( ) ) ;
2009-08-04 19:37:01 -04:00
2009-08-18 08:43:48 -04:00
//generate a random ssl password
2011-01-29 09:27:16 -05:00
std : : string sslPasswd = RSRandom : : random_alphaNumericString ( RsInit : : getSslPwdLen ( ) ) ;
2011-01-29 09:31:44 -05:00
2014-01-17 21:35:06 -05:00
/* GenerateSSLCertificate - selects the PGP Account */
//RsInit::SelectGPGAccount(PGPId);
2009-08-04 19:37:01 -04:00
2014-03-17 16:56:06 -04:00
RsPeerId sslId ;
2011-08-12 16:02:00 -04:00
std : : cerr < < " GenCertDialog::genPerson() Generating SSL cert with gpg id : " < < PGPId < < std : : endl ;
std : : string err ;
2015-12-28 07:45:22 -05:00
this - > hide ( ) ; //To show dialog asking password PGP Key.
2016-07-16 17:10:00 -04:00
std : : cout < < " RsAccounts::GenerateSSLCertificate " < < std : : endl ;
2018-07-27 06:33:06 -04:00
bool okGen = RsAccounts : : createNewAccount ( PGPId , " " , genLoc , " " , isHiddenLoc , isAutoTor , sslPasswd , sslId , err ) ;
2007-11-14 22:18:48 -05:00
if ( okGen )
{
/* complete the process */
2014-01-17 21:35:06 -05:00
RsInit : : LoadPassword ( sslPasswd ) ;
if ( Rshare : : loadCertificate ( sslId , false ) ) {
2016-08-06 11:15:56 -04:00
2012-10-31 21:07:36 -04:00
accept ( ) ;
}
2007-11-14 22:18:48 -05:00
}
else
{
/* Message Dialog */
2012-02-21 14:17:38 -05:00
QMessageBox : : warning ( this ,
2015-05-14 09:18:58 -04:00
tr ( " Profile generation failure " ) ,
2014-12-30 06:11:08 -05:00
tr ( " Failed to generate your new certificate, maybe PGP password is wrong! " ) ,
QMessageBox : : Ok ) ;
reject ( ) ;
}
}