2007-11-14 22:18:48 -05:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* 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 <rshare.h>
2011-01-29 09:27:16 -05:00
# include <util/rsrandom.h>
2010-08-06 05:40:23 -04:00
# include <retroshare/rsinit.h>
2015-05-16 05:33:06 -04:00
# include <rsserver/rsaccounts.h>
2007-11-14 22:18:48 -05:00
# include "GenCertDialog.h"
2010-05-01 11:17:23 -04:00
# include <QAbstractEventDispatcher>
2007-11-14 22:18:48 -05:00
# include <QFileDialog>
2013-09-23 16:55:34 -04:00
# include <QGraphicsOpacityEffect>
# include <QTimer>
2007-11-14 22:18:48 -05:00
# include <QMessageBox>
2013-09-23 16:55:34 -04:00
# include <QMouseEvent>
# include <QTextBrowser>
# include <QProgressBar>
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
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 ( )
{
static int last_x = 0 ;
static int last_y = 0 ;
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 ) ;
2015-04-19 14:30:07 -04:00
if ( ui . entropy_bar - > value ( ) < 20 )
{
ui . genButton2 - > setEnabled ( false ) ;
ui . genButton2 - > setIcon ( QIcon ( " :/images/delete.png " ) ) ;
ui . genButton2 - > setToolTip ( tr ( " Currently disabled. Please move your mouse around until you reach at least 20% " ) ) ;
}
else
{
ui . genButton2 - > setEnabled ( true ) ;
ui . genButton2 - > setIcon ( QIcon ( " :/images/resume.png " ) ) ;
2015-05-14 09:18:58 -04:00
ui . genButton2 - > setToolTip ( tr ( " Click to create your node and/or profile " ) ) ;
2015-04-19 14:30:07 -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 )
: QDialog ( parent , Qt : : WindowSystemMenuHint | Qt : : WindowTitleHint | Qt : : WindowCloseButtonHint ) , mOnlyGenerateIdentity ( onlyGenerateIdentity )
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
ui . headerFrame - > setHeaderImage ( QPixmap ( " :/images/contact_new128.png " ) ) ;
2015-05-14 09:18:58 -04:00
ui . headerFrame - > setHeaderText ( tr ( " Create a new profile " ) ) ;
2012-10-31 21:07:36 -04:00
connect ( ui . new_gpg_key_checkbox , SIGNAL ( clicked ( ) ) , this , SLOT ( newGPGKeyGenUiSetup ( ) ) ) ;
2015-04-13 18:07:55 -04:00
connect ( ui . adv_checkbox , SIGNAL ( clicked ( ) ) , this , SLOT ( updateUiSetup ( ) ) ) ;
connect ( ui . hidden_checkbox , SIGNAL ( clicked ( ) ) , this , SLOT ( updateUiSetup ( ) ) ) ;
2012-10-31 21:07:36 -04:00
2015-04-19 14:30:07 -04:00
connect ( ui . genButton2 , 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 ( ) ) ) ;
//ui.genName->setFocus(Qt::OtherFocusReason);
2013-09-23 16:55:34 -04:00
// QObject *obj = QCoreApplication::eventFilter() ;
// std::cerr << "Event filter : " << obj << std::endl;
// QCoreApplication::instance()->setEventFilter(MyEventFilter) ;
entropy_timer = new QTimer ;
entropy_timer - > start ( 20 ) ;
QObject : : connect ( entropy_timer , SIGNAL ( timeout ( ) ) , this , SLOT ( grabMouse ( ) ) ) ;
// EntropyCollectorWidget *ecw = new EntropyCollectorWidget(ui.entropy_bar,this) ;
// ecw->resize(size()) ;
// ecw->move(0,0) ;
//
// QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect ;
// effect->setOpacity(0.2) ;
// ecw->setGraphicsEffect(effect) ;
//ecw->setBackgroundColor(QColor::fromRGB(1,1,1)) ;
// ecw->show() ;
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!
2015-05-15 06:19:57 -04:00
ui . keylength_comboBox - > addItem ( " default (2048 bits, recommended) " , QVariant ( 2048 ) ) ;
ui . keylength_comboBox - > addItem ( " high (3072 bits) " , QVariant ( 3072 ) ) ;
ui . keylength_comboBox - > addItem ( " insane (4096 bits) " , QVariant ( 4096 ) ) ;
2015-01-12 17:02:43 -05:00
2012-03-18 08:26:15 -04:00
# if QT_VERSION >= 0x040700
2012-10-31 21:07:36 -04:00
ui . email_input - > setPlaceholderText ( tr ( " [Optional] Visible to your friends, and friends of friends. " ) ) ;
2015-04-21 17:21:31 -04:00
ui . node_input - > setPlaceholderText ( tr ( " [Required] Examples: Home, Laptop,... " ) ) ;
ui . hiddenaddr_input - > setPlaceholderText ( tr ( " [Required] Examples: xa76giaf6ifda7ri63i263.onion (obtained by you from TOR) " ) ) ;
ui . name_input - > setPlaceholderText ( tr ( " [Required] Visible to your friends, and friends of friends. " ) ) ;
2015-05-14 09:18:58 -04:00
ui . password_input - > setPlaceholderText ( tr ( " [Required] This password protects your private PGP key. " ) ) ;
2013-09-23 16:55:34 -04:00
ui . password_input_2 - > setPlaceholderText ( tr ( " [Required] Type the same password again here. " ) ) ;
2012-03-18 08:26:15 -04:00
# endif
2013-07-04 16:22:09 -04:00
2015-05-14 09:18:58 -04:00
ui . node_input - > setToolTip ( tr ( " Enter a meaningful node description. e.g. : home, laptop, etc. \n This field will be used to differentiate different installations with \n the same profile (PGP key pair). " ) ) ;
2013-09-23 16:55:34 -04:00
2013-07-04 16:22:09 -04:00
ui . email_input - > hide ( ) ;
ui . email_label - > hide ( ) ;
2012-10-31 21:07:36 -04:00
/* get all available pgp private certificates....
* mark last one as default .
*/
2012-08-07 15:16:17 -04:00
2012-10-31 21:07:36 -04:00
init ( ) ;
2012-08-07 15:16:17 -04:00
}
2013-09-23 16:55:34 -04:00
GenCertDialog : : ~ GenCertDialog ( )
{
entropy_timer - > stop ( ) ;
}
2012-08-07 15:16:17 -04:00
void GenCertDialog : : init ( )
{
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 ;
# ifdef TO_REMOVE
/* replace with true/false below */
2012-10-31 21:07:36 -04:00
if ( ! mOnlyGenerateIdentity ) {
2015-05-21 05:03:58 -04:00
# endif
2014-01-17 21:35:06 -05:00
if ( RsAccounts : : GetPGPLogins ( pgpIds ) ) {
2014-10-21 18:33:02 -04:00
for ( it = pgpIds . begin ( ) ; it ! = pgpIds . end ( ) ; + + it )
2012-10-31 21:07:36 -04:00
{
2014-03-17 16:56:06 -04:00
QVariant userData ( QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) ;
2012-10-31 21:07:36 -04:00
std : : string name , email ;
2014-01-17 21:35:06 -05:00
RsAccounts : : GetPGPLoginDetails ( * it , name , email ) ;
2012-10-31 21:07:36 -04:00
std : : cerr < < " Adding PGPUser: " < < name < < " id: " < < * it < < std : : endl ;
2014-03-17 16:56:06 -04:00
QString gid = QString : : fromStdString ( ( * it ) . toStdString ( ) ) . right ( 8 ) ;
2012-10-31 21:07:36 -04:00
ui . genPGPuser - > addItem ( QString : : fromUtf8 ( name . c_str ( ) ) + " < " + QString : : fromUtf8 ( email . c_str ( ) ) + " > ( " + gid + " ) " , userData ) ;
2015-05-21 05:03:58 -04:00
haveGPGKeys = true ;
2012-10-31 21:07:36 -04:00
}
}
2015-05-21 05:03:58 -04:00
# ifdef TO_REMOVE
2012-10-31 21:07:36 -04:00
}
2015-05-21 05:03:58 -04:00
# endif
if ( haveGPGKeys ) {
2012-10-31 21:07:36 -04:00
ui . no_gpg_key_label - > hide ( ) ;
2015-05-21 05:03:58 -04:00
ui . header_label - > show ( ) ;
2012-10-31 21:07:36 -04:00
ui . new_gpg_key_checkbox - > setChecked ( false ) ;
2014-12-30 06:11:08 -05:00
setWindowTitle ( tr ( " Create new node " ) ) ;
2015-04-19 14:30:07 -04:00
ui . genButton2 - > setText ( tr ( " Generate new node " ) ) ;
2014-12-30 06:11:08 -05:00
ui . headerFrame - > setHeaderText ( tr ( " Create a new node " ) ) ;
2012-10-31 21:07:36 -04:00
genNewGPGKey = false ;
} else {
ui . no_gpg_key_label - > setVisible ( ! mOnlyGenerateIdentity ) ;
2015-05-21 05:03:58 -04:00
ui . header_label - > setVisible ( mOnlyGenerateIdentity ) ;
2012-10-31 21:07:36 -04:00
ui . new_gpg_key_checkbox - > setChecked ( true ) ;
2013-03-19 17:18:49 -04:00
ui . new_gpg_key_checkbox - > setEnabled ( true ) ;
2015-05-14 09:18:58 -04:00
setWindowTitle ( tr ( " Create new profile " ) ) ;
ui . genButton2 - > setText ( tr ( " Generate new profile and node " ) ) ;
ui . headerFrame - > setHeaderText ( tr ( " Create a new profile and node " ) ) ;
2012-10-31 21:07:36 -04:00
genNewGPGKey = true ;
}
2015-05-21 05:03:58 -04:00
# ifdef TO_REMOVE
2015-03-28 16:34:16 -04:00
QString text ; /*= ui.header_label->text() + "\n";*/
2015-05-14 09:18:58 -04:00
text + = tr ( " You can create a new profile with this form. " ) ;
2012-10-31 21:07:36 -04:00
if ( mOnlyGenerateIdentity ) {
ui . new_gpg_key_checkbox - > setChecked ( true ) ;
ui . new_gpg_key_checkbox - > hide ( ) ;
2015-05-21 05:03:58 -04:00
# endif
2013-09-13 13:19:34 -04:00
ui . genprofileinfo_label - > hide ( ) ;
2015-05-21 05:03:58 -04:00
# ifdef TO_REMOVE
2012-10-31 21:07:36 -04:00
} else {
2014-12-30 06:11:08 -05:00
text + = " \n " ;
2015-05-14 09:18:58 -04:00
text + = tr ( " Alternatively you can use an existing profile. Just uncheck \" Create a new profile \" " ) ;
2012-10-31 21:07:36 -04:00
}
2013-09-13 13:19:34 -04:00
ui . header_label - > setText ( text ) ;
2015-05-21 05:03:58 -04:00
# endif
2012-10-31 21:07:36 -04:00
newGPGKeyGenUiSetup ( ) ;
2015-05-14 09:18:58 -04:00
//updateUiSetup();
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 ) ;
}
2010-01-19 16:44:13 -05:00
void GenCertDialog : : newGPGKeyGenUiSetup ( ) {
2015-05-14 09:18:58 -04:00
bool adv_state = ui . adv_checkbox - > isChecked ( ) ;
bool hidden_state = ui . hidden_checkbox - > isChecked ( ) ;
2015-05-16 05:33:06 -04:00
ui . no_node_label - > setVisible ( false ) ;
2010-06-04 20:44:43 -04:00
2012-10-31 21:07:36 -04:00
if ( ui . new_gpg_key_checkbox - > isChecked ( ) ) {
genNewGPGKey = true ;
ui . name_label - > show ( ) ;
ui . name_input - > show ( ) ;
2013-07-04 16:22:09 -04:00
// ui.email_label->show();
// ui.email_input->show();
2012-10-31 21:07:36 -04:00
ui . password_label - > show ( ) ;
2013-09-23 16:55:34 -04:00
ui . password_label_2 - > show ( ) ;
2012-10-31 21:07:36 -04:00
ui . password_input - > show ( ) ;
2013-09-23 16:55:34 -04:00
ui . password_input_2 - > show ( ) ;
2012-10-31 21:07:36 -04:00
ui . genPGPuserlabel - > hide ( ) ;
ui . genPGPuser - > hide ( ) ;
ui . importIdentity_PB - > hide ( ) ;
ui . exportIdentity_PB - > hide ( ) ;
2015-05-14 09:18:58 -04:00
setWindowTitle ( tr ( " Create new profile " ) ) ;
ui . genButton2 - > setText ( tr ( " Generate new profile and node " ) ) ;
ui . headerFrame - > setHeaderText ( tr ( " Create a new profile and node " ) ) ;
2015-05-21 05:03:58 -04:00
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. \n Alternatively you can import a (previously exported) profile. Just uncheck \" Create a new profile \" " ) ) ;
2015-05-14 09:18:58 -04:00
ui . genButton2 - > setVisible ( true ) ;
ui . adv_checkbox - > setVisible ( true ) ;
ui . node_label - > setVisible ( true ) ;
ui . node_input - > setVisible ( true ) ;
ui . entropy_label - > setVisible ( true ) ;
ui . entropy_bar - > setVisible ( true ) ;
2015-05-21 05:03:58 -04:00
ui . genprofileinfo_label - > setVisible ( false ) ;
if ( ! mOnlyGenerateIdentity ) {
ui . header_label - > setVisible ( haveGPGKeys ) ;
}
2015-03-29 09:41:29 -04:00
//ui.keylength_label->show();
//ui.keylength_comboBox->show();
2012-10-31 21:07:36 -04:00
} else {
2015-05-21 05:03:58 -04:00
//haveGPGKeys = (ui.genPGPuser->count() != 0)?true:false;
if ( haveGPGKeys ) {
2015-05-16 05:33:06 -04:00
QVariant data = ui . genPGPuser - > itemData ( ui . genPGPuser - > currentIndex ( ) ) ;
if ( ! rsAccounts - > selectAccountByString ( data . toString ( ) . toStdString ( ) ) ) {
ui . no_node_label - > setText ( tr ( " No node is associated with the profile named " ) + " " + ui . genPGPuser - > currentText ( ) + " . " + tr ( " Please create a node for it by providing a node name. " ) ) ;
ui . no_node_label - > setVisible ( true ) ;
2015-05-21 05:03:58 -04:00
} else {
ui . genprofileinfo_label - > show ( ) ;
2015-05-16 05:33:06 -04:00
}
}
2012-10-31 21:07:36 -04:00
genNewGPGKey = false ;
ui . name_label - > hide ( ) ;
ui . name_input - > hide ( ) ;
2013-07-04 16:22:09 -04:00
// ui.email_label->hide();
// ui.email_input->hide();
2012-10-31 21:07:36 -04:00
ui . password_label - > hide ( ) ;
2013-09-23 16:55:34 -04:00
ui . password_label_2 - > hide ( ) ;
2012-10-31 21:07:36 -04:00
ui . password_input - > hide ( ) ;
2013-09-23 16:55:34 -04:00
ui . password_input_2 - > hide ( ) ;
2012-10-31 21:07:36 -04:00
ui . genPGPuserlabel - > show ( ) ;
ui . genPGPuser - > show ( ) ;
ui . importIdentity_PB - > setVisible ( ! mOnlyGenerateIdentity ) ;
2015-05-21 05:03:58 -04:00
ui . exportIdentity_PB - > setVisible ( haveGPGKeys ) ;
ui . exportIdentity_PB - > setEnabled ( haveGPGKeys ) ;
2014-12-30 06:11:08 -05:00
setWindowTitle ( tr ( " Create new node " ) ) ;
2015-04-19 14:30:07 -04:00
ui . genButton2 - > setText ( tr ( " Generate new node " ) ) ;
2014-12-30 06:11:08 -05:00
ui . headerFrame - > setHeaderText ( tr ( " Create a new node " ) ) ;
2015-05-21 05:03:58 -04:00
ui . no_gpg_key_label - > setText ( tr ( " Welcome to Retroshare. Before you can proceed you need to import a profile and after that associate a node with it. " ) ) ;
ui . genButton2 - > setVisible ( haveGPGKeys ) ;
ui . adv_checkbox - > setVisible ( haveGPGKeys ) ;
ui . adv_checkbox - > setChecked ( haveGPGKeys & & adv_state ) ;
ui . genPGPuser - > setVisible ( haveGPGKeys ) ;
ui . genPGPuserlabel - > setVisible ( haveGPGKeys ) ;
ui . node_label - > setVisible ( haveGPGKeys ) ;
ui . node_input - > setVisible ( haveGPGKeys ) ;
ui . entropy_label - > setVisible ( haveGPGKeys ) ;
ui . entropy_bar - > setVisible ( haveGPGKeys ) ;
//ui.genprofileinfo_label->show();
ui . header_label - > setVisible ( false ) ;
2015-01-12 17:02:43 -05:00
ui . keylength_label - > hide ( ) ;
ui . keylength_comboBox - > hide ( ) ;
2012-10-31 21:07:36 -04:00
}
2015-05-14 09:18:58 -04:00
updateUiSetup ( ) ;
ui . adv_checkbox - > setChecked ( adv_state ) ;
ui . hidden_checkbox - > setChecked ( hidden_state ) ;
2010-01-19 16:44:13 -05:00
}
2011-08-12 16:02:00 -04:00
2015-04-13 18:07:55 -04:00
void GenCertDialog : : updateUiSetup ( )
2013-09-08 22:11:43 -04:00
{
2015-04-13 18:07:55 -04:00
if ( ui . adv_checkbox - > isChecked ( ) )
{
ui . hidden_checkbox - > show ( ) ;
2015-05-15 06:19:57 -04:00
if ( ui . new_gpg_key_checkbox - > isChecked ( ) )
{
// key length is only for pgp key creation
ui . keylength_label - > show ( ) ;
ui . keylength_comboBox - > show ( ) ;
}
else
{
ui . keylength_label - > hide ( ) ;
ui . keylength_comboBox - > hide ( ) ;
}
2015-04-13 18:07:55 -04:00
if ( ui . hidden_checkbox - > isChecked ( ) )
{
ui . hiddenaddr_input - > show ( ) ;
ui . hiddenaddr_label - > show ( ) ;
ui . label_hiddenaddr2 - > show ( ) ;
ui . hiddenport_label - > show ( ) ;
ui . hiddenport_spinBox - > show ( ) ;
}
else
{
ui . hiddenaddr_input - > hide ( ) ;
ui . hiddenaddr_label - > hide ( ) ;
ui . label_hiddenaddr2 - > hide ( ) ;
ui . hiddenport_label - > hide ( ) ;
ui . hiddenport_spinBox - > hide ( ) ;
}
}
else
{
ui . hiddenaddr_input - > hide ( ) ;
ui . hiddenaddr_label - > hide ( ) ;
ui . label_hiddenaddr2 - > hide ( ) ;
ui . hiddenport_label - > hide ( ) ;
ui . hiddenport_spinBox - > hide ( ) ;
ui . hidden_checkbox - > hide ( ) ;
ui . keylength_label - > hide ( ) ;
ui . keylength_comboBox - > hide ( ) ;
if ( ui . hidden_checkbox - > isChecked ( ) )
ui . hidden_checkbox - > setChecked ( false ) ;
}
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
if ( fname . isNull ( ) )
return ;
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
2012-07-10 17:40:53 -04:00
void GenCertDialog : : importIdentity ( )
{
2015-05-14 09:18:58 -04:00
QString fname = QFileDialog : : getOpenFileName ( this , tr ( " Import profile " ) , " " , tr ( " RetroShare profile files (*.asc) " ) ) ;
2012-07-10 17:40:53 -04:00
if ( fname . isNull ( ) )
return ;
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 ) ) ;
2012-07-10 17:40:53 -04:00
return ;
}
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
2015-05-14 09:18:58 -04:00
QMessageBox : : information ( this , tr ( " New profile imported " ) , tr ( " Your profile was imported successfully: " ) + " \n " + " \n Name : " + QString : : fromStdString ( name ) + " \n email: " + QString : : fromStdString ( email ) + " \n Key ID: " + QString : : fromStdString ( gpg_id . toStdString ( ) ) + " \n \n " + tr ( " You can use it now to create a new node. " ) ) ;
2012-08-07 15:16:17 -04:00
}
2012-07-10 17:40:53 -04:00
2012-08-07 15:16:17 -04:00
init ( ) ;
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 ;
2014-01-17 21:35:06 -05:00
bool isHiddenLoc = false ;
2012-10-31 21:07:36 -04:00
2015-04-13 18:07:55 -04:00
if ( ui . hidden_checkbox - > isChecked ( ) )
2013-09-08 22:11:43 -04:00
{
std : : string hl = ui . hiddenaddr_input - > text ( ) . toStdString ( ) ;
uint16_t port = ui . hiddenport_spinBox - > value ( ) ;
if ( ! RsInit : : SetHiddenLocation ( hl , port ) ) /* parses it */
{
/* Message Dialog */
QMessageBox : : warning ( this ,
2014-12-30 06:11:08 -05:00
tr ( " Invalid hidden node " ) ,
tr ( " Please enter a valid address of the form: 31769173498.onion:7800 " ) ,
2013-09-08 22:11:43 -04:00
QMessageBox : : Ok ) ;
return ;
}
2014-01-17 21:35:06 -05:00
isHiddenLoc = true ;
2013-09-08 22:11:43 -04:00
}
2012-10-31 21:07:36 -04:00
if ( ! genNewGPGKey ) {
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
if ( ui . password_input - > text ( ) ! = ui . password_input_2 - > text ( ) )
{
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 ;
2015-05-14 09:18:58 -04:00
ui . no_gpg_key_label - > setText ( tr ( " Generating new PGP key pair, please be patient: this process needs generating large prime numbers, and can take some minutes on slow computers. \n \n Fill in your PGP password when asked, to sign your new key. " ) ) ;
2012-10-31 21:07:36 -04:00
ui . no_gpg_key_label - > show ( ) ;
ui . new_gpg_key_checkbox - > hide ( ) ;
ui . name_label - > hide ( ) ;
ui . name_input - > hide ( ) ;
2013-07-04 16:22:09 -04:00
// ui.email_label->hide();
// ui.email_input->hide();
2013-09-23 16:55:34 -04:00
ui . password_label_2 - > hide ( ) ;
ui . password_input_2 - > hide ( ) ;
2012-10-31 21:07:36 -04:00
ui . password_label - > hide ( ) ;
ui . password_input - > hide ( ) ;
ui . genPGPuserlabel - > hide ( ) ;
ui . genPGPuser - > hide ( ) ;
2014-12-30 06:11:08 -05:00
ui . node_label - > hide ( ) ;
ui . node_input - > hide ( ) ;
2015-04-19 14:30:07 -04:00
ui . genButton2 - > hide ( ) ;
2012-10-31 21:07:36 -04:00
ui . importIdentity_PB - > hide ( ) ;
2013-09-13 13:19:34 -04:00
ui . genprofileinfo_label - > hide ( ) ;
2015-04-13 18:07:55 -04:00
ui . hidden_checkbox - > hide ( ) ;
ui . adv_checkbox - > hide ( ) ;
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 ( ) ;
while ( QAbstractEventDispatcher : : instance ( ) - > processEvents ( QEventLoop : : AllEvents ) ) ;
2013-07-04 16:22:09 -04:00
std : : string email_str = " " ;
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 ) ;
}
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 ;
2014-01-17 21:35:06 -05:00
bool okGen = RsAccounts : : GenerateSSLCertificate ( PGPId , " " , genLoc , " " , isHiddenLoc , 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 ) ) {
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 ( ) ;
}
}