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"
|
2009-12-14 12:13:10 -05:00
|
|
|
#include "gui/settings/rsharesettings.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2010-01-18 17:02:40 -05:00
|
|
|
#include <QMovie>
|
2010-01-20 17:02:43 -05:00
|
|
|
#include <time.h>
|
2010-01-18 17:02:40 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2010-01-19 16:44:13 -05:00
|
|
|
connect(ui.new_gpg_key_checkbox, SIGNAL(clicked()), this, SLOT(newGPGKeyGenUiSetup()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2010-01-13 16:08:46 -05:00
|
|
|
/* 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;
|
2010-01-19 16:44:13 -05:00
|
|
|
bool foundGPGKeys = false;
|
2010-01-18 07:30:54 -05:00
|
|
|
if (RsInit::GetPGPLogins(pgpIds)) {
|
2010-01-13 16:08:46 -05:00
|
|
|
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;
|
2010-02-20 08:36:30 -05:00
|
|
|
QString gid = QString::fromStdString(*it).right(8) ;
|
|
|
|
ui.genPGPuser->addItem(QString::fromStdString(name + " <" + email + "> (")+gid+")", userData);
|
2010-01-18 07:30:54 -05:00
|
|
|
foundGPGKeys = true;
|
2010-01-13 16:08:46 -05:00
|
|
|
}
|
|
|
|
}
|
2009-08-04 19:37:01 -04:00
|
|
|
|
2010-01-18 07:30:54 -05:00
|
|
|
if (foundGPGKeys) {
|
|
|
|
ui.no_gpg_key_label->hide();
|
2010-01-19 16:44:13 -05:00
|
|
|
ui.new_gpg_key_checkbox->setChecked(false);
|
|
|
|
genNewGPGKey = false;
|
2010-01-18 07:30:54 -05:00
|
|
|
} else {
|
2010-01-19 16:44:13 -05:00
|
|
|
ui.no_gpg_key_label->show();
|
|
|
|
ui.new_gpg_key_checkbox->setChecked(true);
|
|
|
|
ui.new_gpg_key_checkbox->hide();
|
|
|
|
genNewGPGKey = true;
|
2010-01-18 07:30:54 -05:00
|
|
|
}
|
2010-01-19 16:44:13 -05:00
|
|
|
newGPGKeyGenUiSetup();
|
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();
|
|
|
|
}
|
|
|
|
|
2010-01-19 16:44:13 -05:00
|
|
|
void GenCertDialog::newGPGKeyGenUiSetup() {
|
|
|
|
if (ui.new_gpg_key_checkbox->isChecked()) {
|
|
|
|
genNewGPGKey = true;
|
|
|
|
ui.name_label->show();
|
|
|
|
ui.name_input->show();
|
|
|
|
ui.email_label->show();
|
|
|
|
ui.email_input->show();
|
|
|
|
ui.password_label->show();
|
|
|
|
ui.password_input->show();
|
|
|
|
ui.genPGPuserlabel->hide();
|
|
|
|
ui.genPGPuser->hide();
|
|
|
|
} else {
|
|
|
|
genNewGPGKey = false;
|
|
|
|
ui.name_label->hide();
|
|
|
|
ui.name_input->hide();
|
|
|
|
ui.email_label->hide();
|
|
|
|
ui.email_input->hide();
|
|
|
|
ui.password_label->hide();
|
|
|
|
ui.password_input->hide();
|
|
|
|
ui.genPGPuserlabel->show();
|
|
|
|
ui.genPGPuser->show();
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
void GenCertDialog::genPerson()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Check the data from the GUI. */
|
2010-02-14 07:04:44 -05:00
|
|
|
std::string genLoc = ui.location_input->text().toStdString();
|
2010-01-18 07:30:54 -05:00
|
|
|
std::string PGPId;
|
2009-08-04 19:37:01 -04:00
|
|
|
|
2010-01-19 16:44:13 -05:00
|
|
|
if (!genNewGPGKey) {
|
2010-02-14 07:04:44 -05:00
|
|
|
if (ui.location_input->text().length() < 3) {
|
|
|
|
/* Message Dialog */
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
tr("Generate GPG key Failure"),
|
|
|
|
tr("Location field is required with a minimum of 3 characters"),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-18 07:30:54 -05: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);
|
|
|
|
PGPId = (data.toString()).toStdString();
|
|
|
|
} else {
|
2010-02-14 07:04:44 -05:00
|
|
|
if (ui.password_input->text().length() < 3 || ui.name_input->text().length() < 3
|
|
|
|
|| ui.email_input->text().length() < 3 || ui.location_label->text().length() < 3) {
|
2010-01-24 17:15:02 -05:00
|
|
|
/* Message Dialog */
|
|
|
|
QMessageBox::StandardButton sb = QMessageBox::warning ( NULL,
|
|
|
|
tr("Generate GPG key Failure"),
|
2010-02-14 07:04:44 -05:00
|
|
|
tr("All fields are required with a minimum of 3 characters"),
|
2010-01-24 17:15:02 -05:00
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-18 07:30:54 -05:00
|
|
|
//generate a new gpg key
|
|
|
|
std::string err_string;
|
|
|
|
ui.no_gpg_key_label->setText(tr("Generating new GPG key, please be patient. Fill in your GPG password when asked."));
|
|
|
|
ui.no_gpg_key_label->show();
|
2010-02-09 09:11:34 -05:00
|
|
|
// QMovie *movie = new QMovie(":/images/loader/progress.gif");
|
|
|
|
// ui.progress_label->setMovie(movie);
|
|
|
|
// movie->start();
|
|
|
|
// movie->setSpeed(100); // 2x speed
|
2010-01-19 16:44:13 -05:00
|
|
|
ui.new_gpg_key_checkbox->hide();
|
2010-01-18 07:30:54 -05:00
|
|
|
ui.name_label->hide();
|
|
|
|
ui.name_input->hide();
|
|
|
|
ui.email_label->hide();
|
|
|
|
ui.email_input->hide();
|
|
|
|
ui.password_label->hide();
|
|
|
|
ui.password_input->hide();
|
|
|
|
ui.genPGPuserlabel->hide();
|
|
|
|
ui.genPGPuser->hide();
|
|
|
|
ui.location_label->hide();
|
2010-02-14 07:04:44 -05:00
|
|
|
ui.location_input->hide();
|
2010-01-18 07:30:54 -05:00
|
|
|
ui.infopushButton->hide();
|
|
|
|
ui.genButton->hide();
|
|
|
|
QMessageBox::StandardButton info = QMessageBox::information( NULL,
|
|
|
|
"Generating GPG key",
|
|
|
|
"This process can take some time, please be patient after pressing the OK button",
|
|
|
|
QMessageBox::Ok);
|
|
|
|
//info->
|
|
|
|
RsInit::GeneratePGPCertificate(ui.name_input->text().toStdString(), ui.email_input->text().toStdString(), ui.password_input->text().toStdString(), PGPId, err_string);
|
|
|
|
}
|
2009-08-04 19:37:01 -04:00
|
|
|
|
|
|
|
|
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);
|
2010-01-13 16:06:53 -05:00
|
|
|
//RsInit::LoadGPGPassword(PGPpasswd);
|
2009-08-04 19:37:01 -04:00
|
|
|
|
|
|
|
std::string sslId;
|
2010-01-27 17:31:25 -05:00
|
|
|
std::cerr << "GenCertDialog::genPerson() Generating SSL cert with gpg id : " << PGPId << std::endl;
|
2010-01-18 07:30:54 -05:00
|
|
|
std::string err;
|
|
|
|
bool okGen = RsInit::GenerateSSLCertificate(PGPId, "", genLoc, "", 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();
|
|
|
|
}
|