summaryrefslogtreecommitdiffstats
path: root/pica-client/dialogs
diff options
context:
space:
mode:
authorme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2013-09-03 20:17:25 +0000
committerme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2013-09-03 20:17:25 +0000
commitdbf009286f7d5018d01e20a328d79685cd676c46 (patch)
treec0baa6e65c71ada67d9072cba60829d0828a9cee /pica-client/dialogs
parentcceb1694414178a65adce52b76a137e7a31ee69a (diff)
downloadpica-pica-dbf009286f7d5018d01e20a328d79685cd676c46.tar.gz
pica-pica-dbf009286f7d5018d01e20a328d79685cd676c46.zip
implemented creating self-signed certificate in registeraccountdialog instead of sending CSR to certificate server
git-svn-id: svn://localhost/project_picapica/trunk@271 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'pica-client/dialogs')
-rw-r--r--pica-client/dialogs/registeraccountdialog.cpp150
-rw-r--r--pica-client/dialogs/registeraccountdialog.h19
2 files changed, 89 insertions, 80 deletions
diff --git a/pica-client/dialogs/registeraccountdialog.cpp b/pica-client/dialogs/registeraccountdialog.cpp
index 7daa6d3..ac0937f 100644
--- a/pica-client/dialogs/registeraccountdialog.cpp
+++ b/pica-client/dialogs/registeraccountdialog.cpp
@@ -11,10 +11,19 @@ RegisterAccountDialog::RegisterAccountDialog(QWidget *parent) :
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel *lbNickname = new QLabel(tr("Name:"));
+ QLabel *lbPassword = new QLabel(tr("Password:"));
+ QLabel *lbRepeatPassword = new QLabel(tr("Repeat password:"));
+
nickname = new QLineEdit();
- btRegister = new QPushButton(tr("Register"));
- lbStatus = new QLabel(tr("Enter your name and press\n \"Register\" to get certificate"));
- btOK = new QPushButton(tr("OK"));
+ btRegister = new QPushButton(tr("Create"));
+ cbSetPassword = new QCheckBox(tr("Set password for secret key"));
+ password = new QLineEdit();
+ repeatPassword = new QLineEdit();
+ lbStatus = new QLabel(tr("Enter your name and press\n \"Create\" to create new Pica Pica certificate"));
+ //btOK = new QPushButton(tr("OK"));
+
+ password->setEchoMode(QLineEdit::Password);
+ repeatPassword->setEchoMode(QLineEdit::Password);
{
QFont f;
@@ -25,31 +34,63 @@ RegisterAccountDialog::RegisterAccountDialog(QWidget *parent) :
layout->addWidget(lbNickname);
layout->addWidget(nickname);
+ layout->addWidget(cbSetPassword);
+ layout->addWidget(lbPassword);
+ layout->addWidget(password);
+ layout->addWidget(lbRepeatPassword);
+ layout->addWidget(repeatPassword);
layout->addWidget(btRegister);
layout->addWidget(lbStatus);
- layout->addWidget(btOK);
+ //layout->addWidget(btOK);
setLayout(layout);
vld = new QRegExpValidator(QRegExp("[^\\#\\$&\"\'=\\(\\)\\\\/\\|`!<>\\{\\}\\[\\]\\+]+"), this);
nickname->setValidator(vld);
- connect(btOK, SIGNAL(clicked()), this, SLOT(OK()));
+ //connect(btOK, SIGNAL(clicked()), this, SLOT(OK()));
connect(btRegister, SIGNAL(clicked()), this, SLOT(Register()));
+ connect(cbSetPassword, SIGNAL(clicked()), this, SLOT(setPasswordClick()));
+
+ setPasswordClick();
}
-void RegisterAccountDialog::OK()
+void RegisterAccountDialog::setPasswordClick()
{
+ if (cbSetPassword->isChecked())
+ {
+ password -> setDisabled(false);
+ repeatPassword -> setDisabled(false);
- done(0);
+ password->show();
+ repeatPassword->show();
+ layout()->itemAt(3)->widget()->show();
+ layout()->itemAt(5)->widget()->show();
+ }
+ else
+ {
+ password -> setDisabled(true);
+ repeatPassword -> setDisabled(true);
+
+ password->setHidden(true);
+ repeatPassword->setHidden(true);
+ layout()->itemAt(3)->widget()->hide();
+ layout()->itemAt(5)->widget()->hide();
+ }
}
+//void RegisterAccountDialog::OK()
+//{
+
+// done(0);
+//}
+
void RegisterAccountDialog::Register()
{
//check name
QString name = nickname->text();
- if (name.toUtf8().size() > 52) //64bytes -field size in x509 certificate, - 10 for number, -1 for #, 1 for terminating zero
+ if (name.toUtf8().size() > 63) //64 bytes - CN length in X509 certificate
{
QMessageBox mbx;
mbx.setText(tr("Name is too long"));
@@ -57,16 +98,36 @@ void RegisterAccountDialog::Register()
return;
}
+ if (name.isEmpty())
+ {
+ QMessageBox mbx;
+ mbx.setText(tr("You must enter name for account"));
+ mbx.exec();
+ return;
+ }
+
+ if (cbSetPassword->isChecked())
+ {
+ if (password->text() != repeatPassword->text())
+ {
+ QMessageBox mbx;
+ mbx.setText(tr("Passwords do not match"));
+ mbx.exec();
+ return;
+ }
+ }
+
//1
lbStatus->setText(tr("1) generating RSA keypair..."));
nickname->setEnabled(false);
btRegister->setEnabled(false);
- ost.GenRSAKeySignal(4096, config_dir + QDir::separator() + "privkey.pem", this, SLOT(stageGenCSR(int, QProcess::ExitStatus)));
+ ost.GenRSAKeySignal(4096, config_dir + QDir::separator() + "privkey.pem", cbSetPassword->isChecked(),
+ password->text(), this, SLOT(stageSignCert(int,QProcess::ExitStatus)));
}
-void RegisterAccountDialog::stageGenCSR(int retval, QProcess::ExitStatus)
+void RegisterAccountDialog::stageSignCert(int retval,QProcess::ExitStatus)
{
if (retval != 0)
{
@@ -74,71 +135,26 @@ void RegisterAccountDialog::stageGenCSR(int retval, QProcess::ExitStatus)
return;
}
- lbStatus->setText(tr("2) Generating CSR..."));
+ lbStatus->setText(tr("2) Signing certificate..."));
- ost.GenCSRSignal(config_dir + QDir::separator() + "csr.pem",
- config_dir + QDir::separator() + "privkey.pem",
- nickname->text(),
- this,
- SLOT(stageConnect(int,QProcess::ExitStatus)));
+ ost.GenCertSignal(config_dir + QDir::separator() + "cert.pem",
+ config_dir + QDir::separator() + "privkey.pem",
+ password->text(),nickname->text(),
+ this,SLOT(stageFinished(int,QProcess::ExitStatus)));
}
-void RegisterAccountDialog::stageConnect(int retval,QProcess::ExitStatus)
+void RegisterAccountDialog::stageFinished(int retval, QProcess::ExitStatus)
{
- static const char *registrar_hosts[] = {"registrar.picapica.im","registrar.picapica.ge"};
- static unsigned char registrar_index;
-
if (retval != 0)
{
lbStatus->setText(tr("Error:\n") + ost.ReadStdErr());
return;
}
- lbStatus->setText(tr("3) Connecting to server..."));
-
- connect(&sock, SIGNAL(connected()), this, SLOT(stageGetCert()));
- connect(&sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(showError()));
+ CertFilename_ = config_dir + QDir::separator() + "cert.pem";
+ PkeyFilename_ = config_dir + QDir::separator() + "privkey.pem";
- sock.connectToHost(registrar_hosts[(registrar_index++)%(sizeof(registrar_hosts)/sizeof(char*))], 2288);
-}
-
-void RegisterAccountDialog::stageGetCert()
-{
- lbStatus->setText(tr("4) Connected. Waiting for certificate..."));
-
- QFile csr(config_dir + QDir::separator() + "csr.pem");
- csr.open(QIODevice::ReadOnly);
-
- QByteArray buf;
-
- buf = csr.readAll();
-
- sock.write(buf.data(), buf.size());
- connect(&sock, SIGNAL(readyRead()), this, SLOT(stageReadCert()));
-
- cert_buf.clear();
-}
-
-void RegisterAccountDialog::stageReadCert()
-{
- cert_buf.append(sock.readAll());
-
- if (cert_buf.contains("-----END CERTIFICATE-----") || cert_buf.contains("-----END X509 CERTIFICATE-----"))
- {
- disconnect(&sock, SIGNAL(error(QAbstractSocket::SocketError)), 0, 0);
-
- QFile cert(config_dir + QDir::separator() + "cert.pem");
- cert.open(QIODevice::WriteOnly | QIODevice::Truncate);
- cert.write(cert_buf.data(),cert_buf.size());
- cert.close();
-
- QFile::remove(config_dir + QDir::separator() + "csr.pem");
-
- CertFilename_ = config_dir + QDir::separator() + "cert.pem";
- PkeyFilename_ = config_dir + QDir::separator() + "privkey.pem";
-
- done(1);
- }
+ done(1);
}
QString RegisterAccountDialog::GetCertFilename()
@@ -151,9 +167,3 @@ QString RegisterAccountDialog::GetPkeyFilename()
return PkeyFilename_;
}
-void RegisterAccountDialog::showError()
-{
- QMessageBox mbx;
- mbx.setText(sock.errorString());
- mbx.exec();
-}
diff --git a/pica-client/dialogs/registeraccountdialog.h b/pica-client/dialogs/registeraccountdialog.h
index 82330e1..5c445d6 100644
--- a/pica-client/dialogs/registeraccountdialog.h
+++ b/pica-client/dialogs/registeraccountdialog.h
@@ -5,9 +5,8 @@
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
+#include <QCheckBox>
#include <QRegExpValidator>
-#include <QtNetwork>
-#include <QTcpSocket>
#include "../openssltool.h"
class RegisterAccountDialog : public QDialog
@@ -19,14 +18,16 @@ public:
QString GetPkeyFilename();
private:
- QPushButton *btOK;
+ //QPushButton *btOK;
QPushButton *btRegister;
QLineEdit *nickname;
QLabel *lbStatus;
+ QCheckBox *cbSetPassword;
+ QLineEdit *password;
+ QLineEdit *repeatPassword;
QRegExpValidator *vld;
OpenSSLTool ost;
- QTcpSocket sock;
QByteArray cert_buf;
QString CertFilename_;
@@ -34,14 +35,12 @@ private:
signals:
public slots:
- void OK();
+ //void OK();
void Register();
+ void setPasswordClick();
- void stageGenCSR(int,QProcess::ExitStatus);
- void stageConnect(int,QProcess::ExitStatus);
- void stageGetCert();
- void stageReadCert();
- void showError();
+ void stageSignCert(int retval, QProcess::ExitStatus);
+ void stageFinished(int retval, QProcess::ExitStatus);
};
#endif // REGISTERACCOUNTDIALOG_H