summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2013-10-11 20:53:36 +0000
committerme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2013-10-11 20:53:36 +0000
commitb09a0605693b0a350f4ee1a08896d638ebdd23ef (patch)
tree372199dad42e5245370dfd0a01909c5326ec81b7
parent56c1e5aacaaec79b24453d406e7c2b218fa0cc9f (diff)
downloadpica-pica-b09a0605693b0a350f4ee1a08896d638ebdd23ef.tar.gz
pica-pica-b09a0605693b0a350f4ee1a08896d638ebdd23ef.zip
better handling of DH parameter generation - added new class DHParam, default DH param file dhparam4096.pem
git-svn-id: svn://localhost/project_picapica/trunk@277 fb96df88-216d-11de-830c-f3023f12d8ac
-rw-r--r--Makefile.am5
-rw-r--r--dhparam4096.pem13
-rw-r--r--pica-client/dhparam.cpp95
-rw-r--r--pica-client/dhparam.h35
-rw-r--r--pica-client/globals.h2
-rw-r--r--pica-client/main.cpp39
-rw-r--r--pica-client/nodethread.cpp3
-rw-r--r--pica-client/openssltool.cpp9
-rw-r--r--pica-client/openssltool.h2
-rw-r--r--pica-client/pica-client.pro6
10 files changed, 196 insertions, 13 deletions
diff --git a/Makefile.am b/Makefile.am
index 3b287ef..534c0f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -84,6 +84,8 @@ pica-client/skynet.cpp \
pica-client/skynet.h \
pica-client/history.h \
pica-client/history.cpp \
+pica-client/dhparam.h \
+pica-client/dhparam.cpp \
\
pica-client/dialogs/addaccountdialog.cpp \
pica-client/dialogs/addaccountdialog.h \
@@ -115,6 +117,7 @@ moc_picasystray.cpp \
moc_registeraccountdialog.cpp \
moc_skynet.cpp \
moc_viewcertdialog.cpp \
+moc_dhparam.cpp \
ui_mainwindow.h
moc_%.cpp: pica-client/%.h
@@ -136,7 +139,7 @@ pica_client_pica_client_CPPFLAGS = -DPICA_INSTALLPREFIX=\"$(prefix)\" $(QT_DEPEN
pica_client_pica_client_LDADD = $(QT_DEPENDENCIES_LIBS)
pkgpicaclientdir = ${datarootdir}/pica-client
-dist_pkgpicaclient_DATA = CA.pem pica-client/picapica-icon-fly.png pica-client/picapica-icon-sit.png
+dist_pkgpicaclient_DATA = CA.pem dhparam4096.pem pica-client/picapica-icon-fly.png pica-client/picapica-icon-sit.png
#$(filter moc_%.cpp,$(pica_client_SOURCES))
CLEANFILES += moc_*.cpp ui_*.h
diff --git a/dhparam4096.pem b/dhparam4096.pem
new file mode 100644
index 0000000..a9dafd3
--- /dev/null
+++ b/dhparam4096.pem
@@ -0,0 +1,13 @@
+-----BEGIN DH PARAMETERS-----
+MIICCAKCAgEAz7K5ZgMrhgVWNZ6uuiylOReHT3r1Z0pW9pn0nAsLR0XK14chhNHe
+kl8PZcjHHj/9v81o9w439LTRT6/dBrR+6jWiqOAqX0FN39cUuvrttcxMgKQ8Ypkk
+54sh6fnfL0t2fvS7SojkGQM5pU9+ERHwbr0PUThiEE+Qv4rBBp/QicCiZ3/FBoCE
+jlU90P5re52hjBifiwN+A5kZyJWeIV83ESyCKMzS0KGeNFzW4yFBruHneVSJwt03
+Qg5a/FJoPXV2s3paaw+8Aokpemg0o8h+SLNR74MznUKq61w9VuF6LFdNslxVLtnz
+NMGREfzQXGbiDjn2dPFdq7HdIc0skRfrfBKUt5cSijDF5mvYQPgHoTwOuAiQQMnD
+smb7lXvD7mwtMbXwWKMy3A08Z1OqGBK2m1jj5jpG8yh93R2AbcBoaSei+iy2iWqH
+zncsC9yYo4pXem7d46qnYs1LVlMFzwdtSmRfP28jGBF81Im+RW/nSoOsclTpL9mF
+KxXLLTzq5p5I/6rezBm6R6rpk/CIpRpCQds7ajdlhIaI/xMp1korqaOcsAqtsiQQ
+vVPE1Cy20UfgsS0O1y36z/oHnXrjqJWo/1ODo1iVVASL45IssJ+DM+2L/jG5NJUA
+eI0f1p4YbTYxmySqwwXo4yJBY8QbuLm8g7S1ocz3UqXoHzRMqNYUMCsCAQU=
+-----END DH PARAMETERS-----
diff --git a/pica-client/dhparam.cpp b/pica-client/dhparam.cpp
new file mode 100644
index 0000000..0c3af31
--- /dev/null
+++ b/pica-client/dhparam.cpp
@@ -0,0 +1,95 @@
+#include "dhparam.h"
+#include <QFile>
+#include <QDir>
+
+
+DHParam *DHParam::dhparamgenerator = NULL;
+QString DHParam::current_dhparam_file;
+
+DHParam::DHParam(QObject *parent) :
+ QObject(parent)
+{
+}
+
+
+bool DHParam::VerifyDefault(QString *errormsg)
+{
+ if (!QFile::exists(config_defaultDHParam))
+ {
+ if (errormsg)
+ *errormsg =
+ QString(tr("Diffie-Hellman parameters file \"%1\" does not exist"))
+ .arg(config_defaultDHParam);
+
+ return false;
+ }
+
+ return true;
+}
+
+bool DHParam::VerifyGenerated(QString *errormsg)
+{
+ if (!QFile::exists(config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE))
+ return false;
+
+ return true;
+}
+
+bool DHParam::UseDefault()
+{
+ return QFile::copy(config_defaultDHParam, config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE);
+}
+
+bool DHParam::StartNewDHParamGeneration(QString *errormsg)
+{
+ if (dhparamgenerator)
+ {
+ if (errormsg)
+ *errormsg = QString(tr("Diffie-Hellman parameter generation process is already running"));
+ return false;
+ }
+
+ dhparamgenerator = new DHParam();
+
+ if (!dhparamgenerator)
+ return false;
+
+ QString tempdhfile = config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE + ".temp";
+
+ if (QFile::exists(tempdhfile))
+ QFile::remove(tempdhfile);
+
+ return dhparamgenerator -> osslt.GenDHParamSignal(PICA_CLIENT_DHPARAMBITS,
+ tempdhfile, dhparamgenerator, SLOT(DHParamGenFinished(int,QProcess::ExitStatus)));
+}
+
+QString DHParam::GetDHParamFilename()
+{
+ if (current_dhparam_file.isEmpty())
+ {
+ if (QFile::exists(config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE))
+ current_dhparam_file = config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE;
+ else
+ current_dhparam_file = config_defaultDHParam;
+ }
+
+ return current_dhparam_file;
+}
+
+void DHParam::DHParamGenFinished(int retval, QProcess::ExitStatus)
+{
+ if (retval == 0)
+ {
+ if (QFile::exists(config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE))
+ QFile::remove(config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE);
+
+ QFile::rename(config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE + ".temp",
+ config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE);
+
+ current_dhparam_file = config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE;
+
+ delete dhparamgenerator;
+
+ dhparamgenerator = NULL;
+ }
+}
diff --git a/pica-client/dhparam.h b/pica-client/dhparam.h
new file mode 100644
index 0000000..74d5309
--- /dev/null
+++ b/pica-client/dhparam.h
@@ -0,0 +1,35 @@
+#ifndef DHPARAM_H
+#define DHPARAM_H
+
+#include <QObject>
+#include <QString>
+#include "globals.h"
+#include "openssltool.h"
+
+class DHParam : public QObject
+{
+ Q_OBJECT
+public:
+ explicit DHParam(QObject *parent = 0);
+ static bool VerifyDefault(QString *errormsg);
+ static bool VerifyGenerated(QString *errormsg);
+ static bool UseDefault();
+ static bool StartNewDHParamGeneration(QString *errormsg);
+
+ static QString GetDHParamFilename();
+
+signals:
+
+public slots:
+
+private:
+ static DHParam *dhparamgenerator;
+ static QString current_dhparam_file;
+
+ OpenSSLTool osslt;
+
+private slots:
+ void DHParamGenFinished(int retval, QProcess::ExitStatus);
+};
+
+#endif // DHPARAM_H
diff --git a/pica-client/globals.h b/pica-client/globals.h
index dcc4f8d..f60f568 100644
--- a/pica-client/globals.h
+++ b/pica-client/globals.h
@@ -4,6 +4,7 @@
#define PICA_CLIENT_STORAGEDB "pica-client.sqlite"
#define PICA_CLIENT_CONFIGDIR ".pica-client"
#define PICA_CLIENT_DHPARAMFILE "dhparam4096.pem"
+#define PICA_CLIENT_DHPARAMBITS 4096
#ifndef PICA_INSTALLPREFIX
@@ -17,6 +18,7 @@
extern class QString config_dir;
extern class QString config_dbname;
extern class QString config_defaultCA;
+extern class QString config_defaultDHParam;
extern class SkyNet *skynet;
extern class MainWindow *mainwindow;
extern class AskPassword *askpassword;
diff --git a/pica-client/main.cpp b/pica-client/main.cpp
index ecca274..5fbd0af 100644
--- a/pica-client/main.cpp
+++ b/pica-client/main.cpp
@@ -11,8 +11,8 @@
#include <QMessageBox>
#include <QString>
#include <QIcon>
-#include "openssltool.h"
#include "../PICA_client.h"
+#include "dhparam.h"
//globals
QString config_dir;
@@ -32,8 +32,10 @@ class PicaSysTray *systray;
//QString config_defaultCA("/home/root_jr/files/projects/picapica_wc/localhost/project_picapica/trunk/tests/trusted_CA.pem");
#ifndef WIN32
QString config_defaultCA(PICA_INSTALLPREFIX"/share/pica-client/CA.pem");
+QString config_defaultDHParam(PICA_INSTALLPREFIX"/share/pica-client/"PICA_CLIENT_DHPARAMFILE);
#else
QString config_defaultCA("share\\CA.pem");
+QString config_defaultDHParam("share\\pica-client\\"PICA_CLIENT_DHPARAMFILE);
#endif
static bool create_database()
@@ -390,7 +392,7 @@ static bool create_config_dir()
else
update_database();
- if (!QFile::exists(config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE))
+ /*if (!QFile::exists(config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE))
{
OpenSSLTool osslt;
msgBox.setText(QString(QObject::tr("Diffie-Hellman parameters will be generated. Please wait. This process can take several minutes...")));
@@ -402,6 +404,39 @@ static bool create_config_dir()
msgBox.exec();
return false;
}
+ }*/
+
+ QString dh_error_message;
+
+ if (!DHParam::VerifyGenerated(NULL))
+ {
+ QMessageBox dhmsgBox;
+ dhmsgBox.setText(QObject::tr("Do you want to generate new Diffie-Hellman parameter file?"));
+ dhmsgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ dhmsgBox.setDefaultButton(QMessageBox::No);
+ dhmsgBox.setInformativeText(QObject::tr("If you press \"Yes\", new Diffie-Hellman parameter generation will be started. It is a CPU intensive process and can take undetermined amount of time (1 - 20 minutes on modern computers). Default DH parameter file will be used for starting secure communications until the new DH parameter generation is finished.\nIf you press \"No\", default DH parameter file distributed with Pica Pica Messenger will be used for every communication session."));
+ switch (dhmsgBox.exec())
+ {
+ case QMessageBox::No:
+
+ DHParam::UseDefault();
+
+ break;
+
+ case QMessageBox::Yes:
+
+ DHParam::StartNewDHParamGeneration(&dh_error_message);
+
+ break;
+ }
+
+ if (!DHParam::VerifyDefault(&dh_error_message))
+ {
+ msgBox.setText(dh_error_message);
+ msgBox.setIcon(QMessageBox::Warning);
+ msgBox.setStandardButtons(QMessageBox::Ok);
+ msgBox.exec();
+ }
}
return true;
diff --git a/pica-client/nodethread.cpp b/pica-client/nodethread.cpp
index 4065e79..393c156 100644
--- a/pica-client/nodethread.cpp
+++ b/pica-client/nodethread.cpp
@@ -2,6 +2,7 @@
#include "mainwindow.h"
#include "../PICA_proto.h"
#include "globals.h"
+#include "dhparam.h"
QMutex NodeThread::finished_mutex;
@@ -27,7 +28,7 @@ void NodeThread::run()
user_account.CA_file.toUtf8().constData(),
user_account.cert_file.toUtf8().constData(),
user_account.pkey_file.toUtf8().constData(),
- (config_dir + QDir::separator() + PICA_CLIENT_DHPARAMFILE).toUtf8().constData(),
+ DHParam::GetDHParamFilename().toUtf8().constData(),
AskPassword::ask_password_cb,
&ci);
diff --git a/pica-client/openssltool.cpp b/pica-client/openssltool.cpp
index 25640ca..b9bf6d9 100644
--- a/pica-client/openssltool.cpp
+++ b/pica-client/openssltool.cpp
@@ -158,7 +158,7 @@ QString OpenSSLTool::ReadStdOut()
return QString::fromUtf8(openssl_.readAllStandardOutput().constData());
}
-bool OpenSSLTool::GenDHParam(quint32 numbits, QString output_file)
+bool OpenSSLTool::GenDHParamSignal(quint32 numbits, QString output_file, QObject *receiver, const char *finished_slot)
{//openssl dhparam -5 4096
openssl_.start("openssl",
QStringList()
@@ -170,11 +170,8 @@ bool OpenSSLTool::GenDHParam(quint32 numbits, QString output_file)
if (!openssl_.waitForStarted())
return false;
- if (!openssl_.waitForFinished(-1))
- return false;
-
- if (openssl_.exitCode() != 0)
- return false;
+ openssl_.disconnect(&openssl_, SIGNAL(finished(int,QProcess::ExitStatus)), 0, 0);
+ openssl_.connect(&openssl_, SIGNAL(finished(int,QProcess::ExitStatus)), receiver, finished_slot);
return true;
}
diff --git a/pica-client/openssltool.h b/pica-client/openssltool.h
index cafc291..f4a017f 100644
--- a/pica-client/openssltool.h
+++ b/pica-client/openssltool.h
@@ -17,7 +17,7 @@ public:
QString password, QObject *receiver, const char *finished_slot);
bool GenCertSignal(QString cert_file, QString keyfile, QString keypassword, QString subject, QObject *receiver, const char *finished_slot);
- bool GenDHParam(quint32 numbits, QString output_file);
+ bool GenDHParamSignal(quint32 numbits, QString output_file, QObject *receiver, const char *finished_slot);
QString ReadStdErr();
QString ReadStdOut();
diff --git a/pica-client/pica-client.pro b/pica-client/pica-client.pro
index a480bd3..e74cd1d 100644
--- a/pica-client/pica-client.pro
+++ b/pica-client/pica-client.pro
@@ -32,7 +32,8 @@ SOURCES += main.cpp\
dialogs/registeraccountdialog.cpp \
openssltool.cpp \
history.cpp \
- ../PICA_id.c
+ ../PICA_id.c \
+ dhparam.cpp
HEADERS += mainwindow.h \
chatwindow.h \
@@ -58,7 +59,8 @@ HEADERS += mainwindow.h \
dialogs/registeraccountdialog.h \
openssltool.h \
history.h \
- ../PICA_id.h
+ ../PICA_id.h \
+ dhparam.h
DEFINES = PICA_MULTITHREADED