1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#include "registeraccountdialog.h"
#include "../globals.h"
#include <QVBoxLayout>
#include <QDir>
#include <QMessageBox>
RegisterAccountDialog::RegisterAccountDialog(QWidget *parent) :
QDialog(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("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;
f= lbStatus->font();
f.setBold(true);
lbStatus->setFont(f);
}
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);
setLayout(layout);
vld = new QRegExpValidator(QRegExp("[^\\#\\$&\"\'=\\(\\)\\\\/\\|`!<>\\{\\}\\[\\]\\+]+"), this);
nickname->setValidator(vld);
//connect(btOK, SIGNAL(clicked()), this, SLOT(OK()));
connect(btRegister, SIGNAL(clicked()), this, SLOT(Register()));
connect(cbSetPassword, SIGNAL(clicked()), this, SLOT(setPasswordClick()));
setPasswordClick();
}
void RegisterAccountDialog::setPasswordClick()
{
if (cbSetPassword->isChecked())
{
password -> setDisabled(false);
repeatPassword -> setDisabled(false);
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() > 63) //64 bytes - CN length in X509 certificate
{
QMessageBox mbx;
mbx.setText(tr("Name is too long"));
mbx.exec();
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", cbSetPassword->isChecked(),
password->text(), this, SLOT(stageSignCert(int,QProcess::ExitStatus)));
}
void RegisterAccountDialog::stageSignCert(int retval,QProcess::ExitStatus)
{
if (retval != 0)
{
lbStatus->setText(tr("Error:\n") + ost.ReadStdErr());
return;
}
lbStatus->setText(tr("2) Signing certificate..."));
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::stageFinished(int retval, QProcess::ExitStatus)
{
if (retval != 0)
{
lbStatus->setText(tr("Error:\n") + ost.ReadStdErr());
return;
}
CertFilename_ = config_dir + QDir::separator() + "cert.pem";
PkeyFilename_ = config_dir + QDir::separator() + "privkey.pem";
done(1);
}
QString RegisterAccountDialog::GetCertFilename()
{
return CertFilename_;
}
QString RegisterAccountDialog::GetPkeyFilename()
{
return PkeyFilename_;
}
|