annotate ui/createcertlistdialog.cpp @ 465:88dfe16a0bb9

Implement certificatelist saving
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 23 Apr 2014 15:34:53 +0000
parents efd1bd85112f
children 0d71ce440bcc
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 367
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 367
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 367
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 367
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 367
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 367
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 367
diff changeset
7 */
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 #include "createcertlistdialog.h"
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
9 #include "sslhelp.h"
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
10 #include "administratorwindow.h"
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
11
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 #include <QDebug>
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
13 #include <QMessageBox>
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 #include <QDir>
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 #include <QPushButton>
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 #include <QGroupBox>
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 #include <QHBoxLayout>
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 #include <QVBoxLayout>
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 #include <QLabel>
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 #include <QFileDialog>
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
21 #include <QStandardPaths>
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
23 #include <polarssl/pk.h>
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
24
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
25 CreateCertListDialog::CreateCertListDialog(AdministratorWindow *parent) :
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
26 QDialog(parent),
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
27 mAdminWindow(parent),
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
28 mPk(NULL)
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 {
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
30 setWindowTitle(tr("Save certificate list"));
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 setupGUI();
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
32 resize(500, 200);
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
33 mKeyFile->setText(mAdminWindow->settings()->value("LastKey", QString()).toString());
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
34 mSaveDir->setText(mAdminWindow->settings()->value("LastOutputDir", QString()).toString());
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
35 if (!mKeyFile->text().isEmpty()) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
36 loadKeyFile(mKeyFile->text());
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
37 }
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 }
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 void CreateCertListDialog::setupGUI()
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 {
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 /* Top level layout / widgets */
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 QVBoxLayout *topLayout = new QVBoxLayout;
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
44 QVBoxLayout *headerLayout = new QVBoxLayout;
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
45 QHBoxLayout *headerSubLayout = new QHBoxLayout;
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
46 QHBoxLayout *centerLayout = new QHBoxLayout;
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 QHBoxLayout *bottomLayout = new QHBoxLayout;
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
48 QVBoxLayout *labelLayout = new QVBoxLayout;
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
49 QVBoxLayout *fieldLayout = new QVBoxLayout;
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
50 QVBoxLayout *buttonLayout = new QVBoxLayout;
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
52 QLabel *header = new QLabel("<h3>" + tr("Save certificate list") + "</h3>");
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
53 QLabel *description = new QLabel(
426
d7cda835abd6 Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents: 417
diff changeset
54 tr("Save all managed root certificates in a new, signed certificate list."));
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
55 headerSubLayout->insertSpacing(0, 40);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
56 headerSubLayout->addWidget(description);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
57 QFrame *headerSeparator = new QFrame();
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
58 headerSeparator->setFrameShape(QFrame::HLine);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
59 headerSeparator->setFrameShadow(QFrame::Sunken);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
60 headerLayout->addWidget(header);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
61 headerLayout->addLayout(headerSubLayout);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
62 headerLayout->addWidget(headerSeparator);
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
63 headerLayout->insertSpacing(3, 10);
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
65 QLabel *certLabel = new QLabel("Select signing key:");
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
66 QLabel *saveLabel = new QLabel("Select output folder:");
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
67 labelLayout->addWidget(certLabel);
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
68 labelLayout->addWidget(saveLabel);
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
69
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
70 mKeyFile = new QLineEdit();
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
71 mSaveDir = new QLineEdit();
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
72 fieldLayout->addWidget(mKeyFile);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
73 fieldLayout->addWidget(mSaveDir);
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
74
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 QPushButton *certSelect = new QPushButton("...");
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 certSelect->setFixedWidth(30);
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
77 connect(certSelect, SIGNAL(clicked()), this, SLOT(openCertificateSelect()));
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 QPushButton *saveSelect = new QPushButton("...");
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 connect(saveSelect, SIGNAL(clicked()), this, SLOT(openSaveLocation()));
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 saveSelect->setFixedWidth(30);
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
81 buttonLayout->addWidget(certSelect);
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
82 buttonLayout->addWidget(saveSelect);
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
83
426
d7cda835abd6 Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents: 417
diff changeset
84 QString footerText = tr("In addition, each certificate list will be saved "
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
85 "automatically in the archive directory:\n");
426
d7cda835abd6 Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents: 417
diff changeset
86 footerText.append(QStandardPaths::writableLocation(
d7cda835abd6 Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents: 417
diff changeset
87 QStandardPaths::DataLocation));
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
88 QLabel *footer = new QLabel(footerText);
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
90 centerLayout->addLayout(labelLayout);
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
91 centerLayout->addLayout(fieldLayout);
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
92 centerLayout->addLayout(buttonLayout);
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
94 QPushButton *create = new QPushButton(tr("Save list"));
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 connect(create, SIGNAL(clicked()), this, SLOT(createList()));
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
96 QPushButton *cancel = new QPushButton(tr("Cancel"));
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
97 connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 bottomLayout->insertStretch(0, 10);
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 bottomLayout->addWidget(create);
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
100 bottomLayout->addWidget(cancel);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
101
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
102 QFrame *bottomSeparator = new QFrame();
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
103 bottomSeparator->setFrameShape(QFrame::HLine);
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
104 bottomSeparator->setFrameShadow(QFrame::Sunken);
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 topLayout->addLayout(headerLayout);
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 topLayout->addLayout(centerLayout);
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 topLayout->insertStretch(2, 10);
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
109 topLayout->addWidget(footer);
428
d1819cd56dee Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents: 426
diff changeset
110 topLayout->insertSpacing(4, 10);
413
860affe19416 Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
111 topLayout->addWidget(bottomSeparator);
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 topLayout->addLayout(bottomLayout);
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 setLayout(topLayout);
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 return;
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 }
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
119 void CreateCertListDialog::showErrorMessage(const QString &msg)
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
120 {
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
121 QMessageBox::warning(this, tr("Error!"), msg);
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
122 }
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
123
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
124 void CreateCertListDialog::loadKeyFile(const QString& fileName)
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 {
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
126 if (mPk != NULL) {
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
127 pk_free(mPk);
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
128 delete mPk;
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
129 mPk = NULL;
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
130 }
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
131
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
132 mPk = new pk_context;
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
133 pk_init(mPk);
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
134 int ret = pk_parse_keyfile(mPk, mKeyFile->text().toLocal8Bit().constData(), "");
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
135
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
136 if (ret != 0) {
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
137 showErrorMessage(tr("Failed to load certificate: %1")
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
138 .arg(getPolarSSLErrorMsg(ret)));
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
139 pk_free(mPk);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
140 delete mPk;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
141 mPk = NULL;
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
142 return;
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
143 }
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
144
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
145 /* Check that it is a 3072 bit RSA key as specified */
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
146 if (!mPk->pk_info || pk_get_size(mPk) != 3072 ||
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
147 mPk->pk_info->type != POLARSSL_PK_RSA) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
148 showErrorMessage(tr("Only 3072 bit RSA keys are supported by the current format."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
149 pk_free(mPk);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
150 delete mPk;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
151 mPk = NULL;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
152 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
153 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
154 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
155
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
156 void CreateCertListDialog::openCertificateSelect()
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
157 {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
158 QString keyFile = QFileDialog::getOpenFileName(
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
159 this, tr("Select certificate"), mKeyFile->text().isEmpty() ?
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
160 QDir::homePath() : mKeyFile->text(), "*.pem");
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
161 mKeyFile->setText(keyFile);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
162
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
163 mAdminWindow->settings()->setValue("LastKey", keyFile);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
164 loadKeyFile(keyFile);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
165
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
166 return;
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
167 }
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
168
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
169 void CreateCertListDialog::openSaveLocation()
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
170 {
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
171 QString saveDir = QFileDialog::getExistingDirectory(
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
172 this, tr("Select target location"),
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
173 mSaveDir->text().isEmpty() ? QDir::homePath() : mSaveDir->text());
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
174 mAdminWindow->settings()->setValue("LastOutputDir", saveDir);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
175 mSaveDir->setText(saveDir);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
176 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
177
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
178 CreateCertListDialog::~CreateCertListDialog()
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
179 {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
180 if (mPk) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
181 pk_free(mPk);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
182 delete mPk;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
183 mPk = NULL;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
184 }
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
185 }
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
186
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
187 void CreateCertListDialog::createList()
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
188 {
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
189 if (!mPk) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
190 showErrorMessage(tr("Please select a valid rsa key."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
191 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
192 if (mSaveDir->text().isEmpty()) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
193 showErrorMessage(tr("Please select an output location first."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
194 }
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
195
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
196 QDateTime currentDateTimeUtc = QDateTime::currentDateTimeUtc();
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
197
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
198 /* Build up the list data */
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
199 QByteArray listData("F:1\r\n");
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
200 listData.append(currentDateTimeUtc.toString(Qt::ISODate) + "\r\n");
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
201
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
202 foreach (const Certificate& cert, mAdminWindow->certificates()) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
203 listData.append(QString::fromLatin1("D:") + cert.base64Line() + "\r\n");
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
204 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
205
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
206 QByteArray signature = rsaSignSHA256Hash(sha256sum(listData), mPk);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
207 listData.prepend("\r\n");
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
208 listData.prepend(signature.toBase64());
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
209 listData.prepend("S:");
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
210
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
211 QString fileName = QString::fromLatin1("certificates-")
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
212 .append(currentDateTimeUtc.toString(("yyyyMMddHHmmss")))
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
213 .append(".txt");
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
214
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
215 QString filePath = mSaveDir->text().append("/").append(fileName);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
216
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
217 QFile outputFile(filePath);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
218
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
219 if (!outputFile.open(QIODevice::WriteOnly)) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
220 showErrorMessage(tr("Failed to open output file %1").arg(filePath));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
221 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
222 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
223
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
224 if (outputFile.write(listData) != listData.size()) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
225 showErrorMessage(tr("Failed to write certificate list."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
226 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
227 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
228
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
229 /* Archive the list */
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
230 QDir archiveDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
231 if (!archiveDir.mkpath(archiveDir.path())) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
232 showErrorMessage(tr("Failed to create archive location."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
233 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
234 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
235
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
236 if (!outputFile.copy(archiveDir.filePath(fileName))) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
237 showErrorMessage(tr("Failed Archive a copy."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
238 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
239 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
240
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
241 if (!outputFile.copy(archiveDir.filePath("current_certificates.txt"))) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
242 showErrorMessage(tr("Failed to write current_certificates file."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
243 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
244 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
245
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
246 QMessageBox::information(this, "", tr("Saved certificate list:\n%1").arg(fileName));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
247 close();
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
248 }

http://wald.intevation.org/projects/trustbridge/