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>
|
2009-08-04 19:37:01 -04:00
|
|
|
#include <rsiface/rsinit.h>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "GenCertDialog.h"
|
2009-09-22 13:23:41 -04:00
|
|
|
#include "InfoDialog.h"
|
2008-09-03 13:07:29 -04:00
|
|
|
#include "gui/Preferences/rsharesettings.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <util/WidgetBackgroundImage.h>
|
|
|
|
|
|
|
|
/* Define the format used for displaying the date and time */
|
|
|
|
#define DATETIME_FMT "MMM dd hh:mm:ss"
|
|
|
|
|
|
|
|
|
|
|
|
/** Default constructor */
|
2009-02-08 09:30:28 -05:00
|
|
|
GenCertDialog::GenCertDialog(QWidget *parent, Qt::WFlags flags)
|
|
|
|
: QDialog(parent, flags)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
WidgetBackgroundImage::setBackgroundImage(ui.loginLabel, ":images/new-account.png", WidgetBackgroundImage::AdjustHeight);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.genButton, SIGNAL(clicked()), this, SLOT(genPerson()));
|
2009-09-22 13:23:41 -04:00
|
|
|
connect(ui.infopushButton,SIGNAL(clicked()), this, SLOT(infodlg()));
|
2009-08-04 19:37:01 -04:00
|
|
|
//connect(ui.selectButton, SIGNAL(clicked()), this, SLOT(selectFriend()));
|
|
|
|
//connect(ui.friendBox, SIGNAL(stateChanged(int)), this, SLOT(checkChanged(int)));
|
|
|
|
|
2009-08-18 08:44:17 -04:00
|
|
|
//ui.genName->setFocus(Qt::OtherFocusReason);
|
2009-08-04 19:37:01 -04:00
|
|
|
|
2009-10-30 17:26:51 -04:00
|
|
|
//the pgp password is now a GT box.
|
|
|
|
ui.genPGPpassword->hide();
|
|
|
|
ui.label_3->hide();
|
2009-10-27 16:47:46 -04:00
|
|
|
|
2009-08-04 19:37:01 -04:00
|
|
|
#ifdef RS_USE_PGPSSL
|
|
|
|
/* get all available pgp private certificates....
|
|
|
|
* mark last one as default.
|
|
|
|
*/
|
|
|
|
std::cerr << "Finding PGPUsers" << std::endl;
|
|
|
|
|
|
|
|
std::list<std::string> pgpIds;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
if (RsInit::GetPGPLogins(pgpIds))
|
|
|
|
{
|
|
|
|
for(it = pgpIds.begin(); it != pgpIds.end(); it++)
|
|
|
|
{
|
|
|
|
const QVariant & userData = QVariant(QString::fromStdString(*it));
|
|
|
|
std::string name, email;
|
|
|
|
RsInit::GetPGPLoginDetails(*it, name, email);
|
|
|
|
std::cerr << "Adding PGPUser: " << name << " id: " << *it << std::endl;
|
|
|
|
ui.genPGPuser->addItem(QString::fromStdString(name), userData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-08-04 19:37:01 -04:00
|
|
|
/** Destructor. */
|
|
|
|
//GenCertDialog::~GenCertDialog()
|
|
|
|
//{
|
|
|
|
//}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Overloads the default show() slot so we can set opacity*/
|
|
|
|
|
|
|
|
void GenCertDialog::show()
|
|
|
|
{
|
|
|
|
//loadSettings();
|
|
|
|
if(!this->isVisible()) {
|
|
|
|
QWidget::show();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenCertDialog::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
QDialog::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenCertDialog::closeinfodlg()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenCertDialog::genPerson()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Check the data from the GUI. */
|
|
|
|
std::string genName = ui.genName->text().toStdString();
|
|
|
|
std::string genOrg = ui.genOrg->text().toStdString();
|
|
|
|
std::string genLoc = ui.genLoc->text().toStdString();
|
|
|
|
std::string genCountry = ui.genCountry->text().toStdString();
|
|
|
|
std::string err;
|
2009-08-04 19:37:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef RS_USE_PGPSSL
|
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
std::string PGPpasswd = ui.genPGPpassword->text().toStdString();
|
2009-08-04 19:37:01 -04:00
|
|
|
int pgpidx = ui.genPGPuser->currentIndex();
|
|
|
|
if (pgpidx < 0)
|
|
|
|
{
|
|
|
|
/* Message Dialog */
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
"Generate ID Failure",
|
|
|
|
"Missing PGP Certificate",
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant data = ui.genPGPuser->itemData(pgpidx);
|
|
|
|
std::string PGPId = (data.toString()).toStdString();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
if (genName.length() >= 3)
|
|
|
|
{
|
|
|
|
/* name passes basic test */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Message Dialog */
|
2009-08-04 19:37:01 -04:00
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
"Generate ID Failure",
|
|
|
|
"Your Name is too short (3+ characters)",
|
|
|
|
QMessageBox::Ok);
|
2007-11-14 22:18:48 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-18 08:43:48 -04:00
|
|
|
//generate a random ssl password
|
|
|
|
std::cerr << " generating sslPasswd." << std::endl;
|
|
|
|
qsrand(time(NULL));
|
|
|
|
std::string sslPasswd = "";
|
|
|
|
for( int i = 0 ; i < 6 ; ++i )
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-08-18 08:43:48 -04:00
|
|
|
int iNumber;
|
|
|
|
iNumber = qrand()%25 + 65;
|
|
|
|
sslPasswd += (char)iNumber;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-08-04 19:37:01 -04:00
|
|
|
|
|
|
|
/* Initialise the PGP user first */
|
|
|
|
RsInit::SelectGPGAccount(PGPId);
|
|
|
|
RsInit::LoadGPGPassword(PGPpasswd);
|
|
|
|
|
|
|
|
std::string sslId;
|
2009-08-18 08:43:48 -04:00
|
|
|
bool okGen = RsInit::GenerateSSLCertificate(genName, genOrg, genLoc, genCountry, sslPasswd, sslId, err);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
if (okGen)
|
|
|
|
{
|
|
|
|
/* complete the process */
|
2009-08-18 08:43:48 -04:00
|
|
|
RsInit::LoadPassword(sslId, sslPasswd);
|
2007-11-14 22:18:48 -05:00
|
|
|
loadCertificates();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Message Dialog */
|
2009-08-04 19:37:01 -04:00
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
"Generate ID Failure",
|
2009-08-18 08:44:54 -04:00
|
|
|
"Failed to Generate your new Certificate, maybe PGP password is wrong !",
|
2009-08-04 19:37:01 -04:00
|
|
|
QMessageBox::Ok);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GenCertDialog::selectFriend()
|
|
|
|
{
|
2009-08-04 19:37:01 -04:00
|
|
|
|
|
|
|
#if 0
|
2007-11-14 22:18:48 -05:00
|
|
|
/* still need to find home (first) */
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Trusted Friend"), "",
|
|
|
|
tr("Certificates (*.pqi *.pem)"));
|
|
|
|
|
|
|
|
std::string fname, userName;
|
|
|
|
fname = fileName.toStdString();
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsInit::ValidateTrustedUser(fname, userName))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
ui.genFriend -> setText(QString::fromStdString(userName));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.genFriend -> setText("<Invalid Selected>");
|
|
|
|
}
|
2009-08-04 19:37:01 -04:00
|
|
|
#endif
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GenCertDialog::checkChanged(int i)
|
|
|
|
{
|
2009-08-04 19:37:01 -04:00
|
|
|
|
|
|
|
#if 0
|
2007-11-14 22:18:48 -05:00
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
selectFriend();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* invalidate selection */
|
|
|
|
std::string fname = "";
|
|
|
|
std::string userName = "";
|
2009-02-08 09:30:28 -05:00
|
|
|
RsInit::ValidateTrustedUser(fname, userName);
|
2007-11-14 22:18:48 -05:00
|
|
|
ui.genFriend -> setText("<None Selected>");
|
|
|
|
}
|
2009-08-04 19:37:01 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GenCertDialog::loadCertificates()
|
|
|
|
{
|
|
|
|
bool autoSave = false;
|
|
|
|
/* Final stage of loading */
|
|
|
|
if (RsInit::LoadCertificates(autoSave))
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* some error msg */
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
"Generate ID Failure",
|
|
|
|
"Failed to Load your new Certificate!",
|
|
|
|
QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:23:41 -04:00
|
|
|
void GenCertDialog::infodlg()
|
|
|
|
{
|
|
|
|
static InfoDialog *infodialog = new InfoDialog();
|
|
|
|
infodialog->show();
|
|
|
|
}
|