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
170
171
172
173
174
175
176
|
#include "certificatemanagementdialog.hpp"
#include "ui_certificatemanagementdialog.h"
#include "kristall.hpp"
#include "newidentitiydialog.hpp"
#include <QCryptographicHash>
#include <QMessageBox>
CertificateManagementDialog::CertificateManagementDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CertificateManagementDialog),
selected_identity { nullptr }
{
ui->setupUi(this);
this->ui->certificates->setModel(&global_identities);
this->ui->certificates->expandAll();
connect(
this->ui->certificates->selectionModel(),
&QItemSelectionModel::currentChanged,
this,
&CertificateManagementDialog::on_certificates_selected
);
on_certificates_selected(QModelIndex { }, QModelIndex { });
}
CertificateManagementDialog::~CertificateManagementDialog()
{
delete ui;
}
void CertificateManagementDialog::on_certificates_selected(QModelIndex const& index, QModelIndex const & previous)
{
Q_UNUSED(previous);
selected_identity = global_identities.getMutableIdentity(index);
this->ui->export_cert_button->setEnabled(selected_identity != nullptr);
if(selected_identity != nullptr)
{
auto & cert = *selected_identity;
this->ui->groupBox->setEnabled(true);
this->ui->cert_display_name->setText(cert.display_name);
this->ui->cert_common_name->setText(cert.certificate.subjectInfo(QSslCertificate::CommonName).join(", "));
this->ui->cert_expiration_date->setDateTime(cert.certificate.expiryDate());
this->ui->cert_livetime->setText(QString("%1 days").arg(QDateTime::currentDateTime().daysTo(cert.certificate.expiryDate())));
this->ui->cert_fingerprint->setPlainText(
QCryptographicHash::hash(cert.certificate.toDer(), QCryptographicHash::Sha256).toHex(':')
);
this->ui->cert_notes->setPlainText(cert.user_notes);
this->ui->cert_host_filter->setText(cert.host_filter);
this->ui->cert_auto_enable->setEnabled(not cert.host_filter.isEmpty());
this->ui->cert_auto_enable->setChecked(cert.auto_enable);
this->ui->delete_cert_button->setEnabled(true);
}
else
{
this->ui->groupBox->setEnabled(false);
this->ui->cert_display_name->setText("");
this->ui->cert_common_name->setText("");
this->ui->cert_expiration_date->setDateTime(QDateTime { });
this->ui->cert_livetime->setText("");
this->ui->cert_fingerprint->setPlainText("");
this->ui->cert_host_filter->setText("");
this->ui->cert_auto_enable->setChecked(false);
if(auto group_name = global_identities.group(index); not group_name.isEmpty()) {
this->ui->delete_cert_button->setEnabled(global_identities.canDeleteGroup(group_name));
} else {
this->ui->delete_cert_button->setEnabled(false);
}
}
}
void CertificateManagementDialog::on_cert_notes_textChanged()
{
if(this->selected_identity != nullptr) {
this->selected_identity->user_notes = this->ui->cert_notes->toPlainText();
}
}
void CertificateManagementDialog::on_cert_display_name_textChanged(const QString &arg1)
{
Q_UNUSED(arg1)
if(this->selected_identity != nullptr) {
this->selected_identity->display_name = this->ui->cert_display_name->text();
}
}
void CertificateManagementDialog::on_delete_cert_button_clicked()
{
auto index = this->ui->certificates->currentIndex();
if(global_identities.getMutableIdentity(index) != nullptr)
{
auto answer = QMessageBox::question(
this,
"Kristall",
"Do you really want to delete this certificate?\r\n\r\nYou will not be able to restore the identity after this!",
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No
);
if(answer != QMessageBox::Yes)
return;
if(not global_identities.destroyIdentity(index)) {
QMessageBox::warning(this, "Kristall", "Could not destroy identity!");
}
}
else if(auto group_name = global_identities.group(index); not group_name.isEmpty()) {
auto answer = QMessageBox::question(
this,
"Kristall",
QString("Do you want to delete the group '%1'").arg(group_name)
);
if(answer != QMessageBox::Yes)
return;
if(not global_identities.deleteGroup(group_name)) {
QMessageBox::warning(this, "Kristall", "Could not delete group!");
}
}
}
void CertificateManagementDialog::on_export_cert_button_clicked()
{
}
void CertificateManagementDialog::on_import_cert_button_clicked()
{
}
void CertificateManagementDialog::on_create_cert_button_clicked()
{
NewIdentitiyDialog dialog { this };
dialog.setGroupName(global_identities.group(this->ui->certificates->currentIndex()));
if(dialog.exec() != QDialog::Accepted)
return;
auto id = dialog.createIdentity();
if(not id.isValid())
return;
id.is_persistent = true;
global_identities.addCertificate(
dialog.groupName(),
id);
}
void CertificateManagementDialog::on_cert_host_filter_textChanged(const QString &host_filter)
{
if(this->selected_identity != nullptr) {
this->ui->cert_auto_enable->setEnabled(not host_filter.isEmpty());
this->selected_identity->host_filter = host_filter;
} else {
this->ui->cert_auto_enable->setEnabled(false);
}
}
void CertificateManagementDialog::on_cert_auto_enable_clicked(bool checked)
{
if(this->selected_identity != nullptr) {
this->selected_identity->auto_enable = checked;
}
}
|