annotate ui/createcertlistdialog.cpp @ 950:b2763af94c82

(Auto) Update translations
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 27 Aug 2014 10:40:56 +0200
parents 75cd2fbf9ac6
children bd2cb6bdb1c5
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
522
c495dd026d61 Made label strings translatable in certificate list dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 473
diff changeset
65 QLabel *certLabel = new QLabel(tr("Select signing key:"));
c495dd026d61 Made label strings translatable in certificate list dialog.
Raimund Renkert <rrenkert@intevation.de>
parents: 473
diff changeset
66 QLabel *saveLabel = new QLabel(tr("Select output folder:"));
428
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
466
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
187 bool CreateCertListDialog::writeList(const QList<Certificate>& certs,
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
188 const QString& filePath,
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
189 const QDateTime& listDate,
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
190 pk_context *pk)
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
191 {
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
192 /* Build up the list data */
473
9cd28df2c4ce Fix D: prefix before the date
Andre Heinecke <aheinecke@intevation.de>
parents: 466
diff changeset
193 QByteArray listData("F:1\r\nD:");
466
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
194 listData.append(listDate.toString(Qt::ISODate) + "\r\n");
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
195
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
196 foreach (const Certificate& cert, certs) {
473
9cd28df2c4ce Fix D: prefix before the date
Andre Heinecke <aheinecke@intevation.de>
parents: 466
diff changeset
197 listData.append(cert.base64Line() + "\r\n");
466
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
198 }
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
199
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
200 QByteArray signature = rsaSignSHA256Hash(sha256sum(listData), pk);
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
201 if (signature.size() != 3072 / 8) {
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
202 qDebug() << "Signature creation returned signature of invalid size.";
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
203 return false;
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
204 }
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
205 listData.prepend("\r\n");
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
206 listData.prepend(signature.toBase64());
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
207 listData.prepend("S:");
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
208
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
209 QFile outputFile(filePath);
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
210
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
211 if (!outputFile.open(QIODevice::WriteOnly)) {
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
212 qDebug() << "Failed to open output file: " << filePath;
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
213 return false;
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
214 }
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
215
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
216 if (outputFile.write(listData) != listData.size()) {
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
217 qDebug() << "Failed to write list: " << filePath;
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
218 outputFile.close();
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
219 return false;
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
220 }
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
221 outputFile.close();
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
222 return true;
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
223 }
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
224
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
225 void CreateCertListDialog::createList()
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
226 {
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
227 if (!mPk) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
228 showErrorMessage(tr("Please select a valid rsa key."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
229 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
230 if (mSaveDir->text().isEmpty()) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
231 showErrorMessage(tr("Please select an output location first."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
232 }
454
efd1bd85112f Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents: 428
diff changeset
233
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
234 QDateTime currentDateTimeUtc = QDateTime::currentDateTimeUtc();
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 QString fileName = QString::fromLatin1("certificates-")
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
237 .append(currentDateTimeUtc.toString(("yyyyMMddHHmmss")))
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
238 .append(".txt");
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 QString filePath = mSaveDir->text().append("/").append(fileName);
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
241
466
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
242 if (!writeList(mAdminWindow->certificates(), filePath,
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
243 currentDateTimeUtc, mPk)) {
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
244 showErrorMessage(tr("Failed to write list to: %1").arg(filePath));
465
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
466
0d71ce440bcc Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents: 465
diff changeset
247 QFile outputFile(filePath);
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
248
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
249 /* Archive the list */
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
250 QDir archiveDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
251 if (!archiveDir.mkpath(archiveDir.path())) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
252 showErrorMessage(tr("Failed to create archive location."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
253 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
254 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
255
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
256 if (!outputFile.copy(archiveDir.filePath(fileName))) {
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
257 showErrorMessage(tr("Failed Archive a copy."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
258 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
259 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
260
515
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
261 QString curCerts = archiveDir.filePath("current_certificates.txt");
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
262
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
263 if (QFile::exists(curCerts)) {
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
264 if (!QFile::remove(curCerts)) {
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
265 showErrorMessage(tr("Failed to update current_certificates.txt"));
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
266 return;
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
267 }
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
268 }
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
269
9d3880db6ba7 Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents: 473
diff changeset
270 if (!outputFile.copy(curCerts)) {
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
271 showErrorMessage(tr("Failed to write current_certificates file."));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
272 return;
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
273 }
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
274
679
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
275
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
276 QString keyFingerprint;
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
277
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
278 {
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
279 /* Calculate sha256 sum of the der key */
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
280 unsigned char output_buf[16000]; /* Buf size taken from examples */
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
281 int ret;
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
282 ret = pk_write_key_der (mPk, output_buf, 16000);
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
283 if (ret <= 0) {
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
284 showErrorMessage(tr("Failed to calculate key hash."));
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
285 return;
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
286 }
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
287 QByteArray derKey((const char*)output_buf, ret);
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
288 QByteArray fp = sha256sum(derKey);
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
289
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
290 for (int i=0; i < fp.size(); i++) {
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
291 keyFingerprint += QString("%1").arg(
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
292 (unsigned char)(fp[i]), 0, 16).rightJustified(2, '0');
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
293 if (i != fp.size() - 1) {
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
294 keyFingerprint += ":";
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
295 }
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
296 }
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
297 keyFingerprint = keyFingerprint.toUpper();
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
298 }
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
299
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
300 mAdminWindow->logChanges(curCerts, keyFingerprint);
75cd2fbf9ac6 (Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents: 562
diff changeset
301
465
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
302 QMessageBox::information(this, "", tr("Saved certificate list:\n%1").arg(fileName));
88dfe16a0bb9 Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents: 454
diff changeset
303 close();
367
9491782a8f5a Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
304 }

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