Mercurial > trustbridge
annotate ui/createcertlistdialog.cpp @ 1390:f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 19 Jan 2015 15:42:20 +0100 |
parents | d009da9cfa10 |
children |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
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 |
1390
f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1317
diff
changeset
|
12 #include "pubkey.h" |
f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1317
diff
changeset
|
13 |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
14 #include <QDebug> |
454
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
15 #include <QMessageBox> |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 #include <QDir> |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 #include <QPushButton> |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
18 #include <QGroupBox> |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
19 #include <QHBoxLayout> |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 #include <QVBoxLayout> |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 #include <QLabel> |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 #include <QFileDialog> |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
23 #include <QStandardPaths> |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 |
454
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
25 #include <polarssl/pk.h> |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
26 |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
27 CreateCertListDialog::CreateCertListDialog(AdministratorWindow *parent) : |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
28 QDialog(parent), |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
29 mAdminWindow(parent), |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
30 mPk(NULL) |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 { |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
32 setWindowTitle(tr("Save certificate list")); |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 setupGUI(); |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
34 resize(500, 200); |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
35 mKeyFile->setText(mAdminWindow->settings()->value("LastKey", QString()).toString()); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
36 mSaveDir->setText(mAdminWindow->settings()->value("LastOutputDir", QString()).toString()); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
37 if (!mKeyFile->text().isEmpty()) { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
38 loadKeyFile(mKeyFile->text()); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
39 } |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 } |
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 void CreateCertListDialog::setupGUI() |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
43 { |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
44 /* Top level layout / widgets */ |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 QVBoxLayout *topLayout = new QVBoxLayout; |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
46 QVBoxLayout *headerLayout = new QVBoxLayout; |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
47 QHBoxLayout *headerSubLayout = new QHBoxLayout; |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
48 QHBoxLayout *centerLayout = new QHBoxLayout; |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 QHBoxLayout *bottomLayout = new QHBoxLayout; |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
50 QVBoxLayout *labelLayout = new QVBoxLayout; |
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
51 QVBoxLayout *fieldLayout = new QVBoxLayout; |
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
52 QVBoxLayout *buttonLayout = new QVBoxLayout; |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
54 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
|
55 QLabel *description = new QLabel( |
426
d7cda835abd6
Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents:
417
diff
changeset
|
56 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
|
57 headerSubLayout->insertSpacing(0, 40); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
58 headerSubLayout->addWidget(description); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
59 QFrame *headerSeparator = new QFrame(); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
60 headerSeparator->setFrameShape(QFrame::HLine); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
61 headerSeparator->setFrameShadow(QFrame::Sunken); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
62 headerLayout->addWidget(header); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
63 headerLayout->addLayout(headerSubLayout); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
64 headerLayout->addWidget(headerSeparator); |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
65 headerLayout->insertSpacing(3, 10); |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 |
522
c495dd026d61
Made label strings translatable in certificate list dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
473
diff
changeset
|
67 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
|
68 QLabel *saveLabel = new QLabel(tr("Select output folder:")); |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
69 labelLayout->addWidget(certLabel); |
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
70 labelLayout->addWidget(saveLabel); |
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
71 |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
72 mKeyFile = new QLineEdit(); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
73 mSaveDir = new QLineEdit(); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
74 fieldLayout->addWidget(mKeyFile); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
75 fieldLayout->addWidget(mSaveDir); |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
76 |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 QPushButton *certSelect = new QPushButton("..."); |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 certSelect->setFixedWidth(30); |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
79 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
|
80 QPushButton *saveSelect = new QPushButton("..."); |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 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
|
82 saveSelect->setFixedWidth(30); |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
83 buttonLayout->addWidget(certSelect); |
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
84 buttonLayout->addWidget(saveSelect); |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
85 |
426
d7cda835abd6
Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents:
417
diff
changeset
|
86 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
|
87 "automatically in the archive directory:\n"); |
426
d7cda835abd6
Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents:
417
diff
changeset
|
88 footerText.append(QStandardPaths::writableLocation( |
d7cda835abd6
Some wording and Layout in TrustBridge Administration.
Raimund Renkert <rrenkert@intevation.de>
parents:
417
diff
changeset
|
89 QStandardPaths::DataLocation)); |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
90 QLabel *footer = new QLabel(footerText); |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
92 centerLayout->addLayout(labelLayout); |
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
93 centerLayout->addLayout(fieldLayout); |
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
94 centerLayout->addLayout(buttonLayout); |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 |
1199
bd2cb6bdb1c5
(admin) Fixed translations and added whitespace between pushbutton icon and text.
Emanuel Schuetze <emanuel@intevation.de>
parents:
679
diff
changeset
|
96 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
|
97 connect(create, SIGNAL(clicked()), this, SLOT(createList())); |
1199
bd2cb6bdb1c5
(admin) Fixed translations and added whitespace between pushbutton icon and text.
Emanuel Schuetze <emanuel@intevation.de>
parents:
679
diff
changeset
|
98 QPushButton *cancel = new QPushButton(" " + tr("Cancel")); |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
99 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
|
100 bottomLayout->insertStretch(0, 10); |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 bottomLayout->addWidget(create); |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
102 bottomLayout->addWidget(cancel); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
103 |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
104 QFrame *bottomSeparator = new QFrame(); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
105 bottomSeparator->setFrameShape(QFrame::HLine); |
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
106 bottomSeparator->setFrameShadow(QFrame::Sunken); |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 topLayout->addLayout(headerLayout); |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 topLayout->addLayout(centerLayout); |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 topLayout->insertStretch(2, 10); |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
111 topLayout->addWidget(footer); |
428
d1819cd56dee
Updated dialog layout.
Raimund Renkert <rrenkert@intevation.de>
parents:
426
diff
changeset
|
112 topLayout->insertSpacing(4, 10); |
413
860affe19416
Wording und Layout in TrustBridge create certificate file dialog.
Raimund Renkert <rrenkert@intevation.de>
parents:
404
diff
changeset
|
113 topLayout->addWidget(bottomSeparator); |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 topLayout->addLayout(bottomLayout); |
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 setLayout(topLayout); |
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 return; |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 } |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 |
454
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
121 void CreateCertListDialog::showErrorMessage(const QString &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 QMessageBox::warning(this, tr("Error!"), msg); |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
124 } |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
125 |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
126 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
|
127 { |
454
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
128 if (mPk != NULL) { |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
129 pk_free(mPk); |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
130 delete mPk; |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
131 mPk = NULL; |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
132 } |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
133 |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
134 mPk = new pk_context; |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
135 pk_init(mPk); |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
136 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
|
137 |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
138 if (ret != 0) { |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
139 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
|
140 .arg(getPolarSSLErrorMsg(ret))); |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
141 pk_free(mPk); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
142 delete mPk; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
143 mPk = NULL; |
454
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
144 return; |
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
145 } |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
146 |
1390
f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1317
diff
changeset
|
147 /* Check that it is a RSA key of the specified size */ |
f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1317
diff
changeset
|
148 if (!mPk->pk_info || pk_get_size(mPk) != TRUSTBRIDGE_RSA_KEY_SIZE || |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
149 mPk->pk_info->type != POLARSSL_PK_RSA) { |
1390
f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1317
diff
changeset
|
150 showErrorMessage(tr("Only %1 bit RSA keys are supported by the current format.").arg( |
f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1317
diff
changeset
|
151 TRUSTBRIDGE_RSA_KEY_SIZE)); |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
152 pk_free(mPk); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
153 delete mPk; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
154 mPk = NULL; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
155 return; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
156 } |
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 |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
159 void CreateCertListDialog::openCertificateSelect() |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
160 { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
161 QString keyFile = QFileDialog::getOpenFileName( |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
162 this, tr("Select certificate"), mKeyFile->text().isEmpty() ? |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
163 QDir::homePath() : mKeyFile->text(), "*.pem"); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
164 mKeyFile->setText(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 mAdminWindow->settings()->setValue("LastKey", keyFile); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
167 loadKeyFile(keyFile); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
168 |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
169 return; |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
170 } |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
171 |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
172 void CreateCertListDialog::openSaveLocation() |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
173 { |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
174 QString saveDir = QFileDialog::getExistingDirectory( |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
175 this, tr("Select target location"), |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
176 mSaveDir->text().isEmpty() ? QDir::homePath() : mSaveDir->text()); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
177 mAdminWindow->settings()->setValue("LastOutputDir", saveDir); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
178 mSaveDir->setText(saveDir); |
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 |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
181 CreateCertListDialog::~CreateCertListDialog() |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
182 { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
183 if (mPk) { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
184 pk_free(mPk); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
185 delete mPk; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
186 mPk = NULL; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
187 } |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
188 } |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
189 |
466
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
190 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
|
191 const QString& filePath, |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
192 const QDateTime& listDate, |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
193 pk_context *pk) |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
194 { |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
195 /* Build up the list data */ |
473
9cd28df2c4ce
Fix D: prefix before the date
Andre Heinecke <aheinecke@intevation.de>
parents:
466
diff
changeset
|
196 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
|
197 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
|
198 |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
199 foreach (const Certificate& cert, certs) { |
473
9cd28df2c4ce
Fix D: prefix before the date
Andre Heinecke <aheinecke@intevation.de>
parents:
466
diff
changeset
|
200 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
|
201 } |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
202 |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
203 QByteArray signature = rsaSignSHA256Hash(sha256sum(listData), pk); |
1390
f3e2df6b49ba
(issue181) Fix hardcoded values for RSA codesigning key size.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1317
diff
changeset
|
204 if (signature.size() != TRUSTBRIDGE_RSA_KEY_SIZE / 8) { |
466
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
205 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
|
206 return false; |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
207 } |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
208 listData.prepend("\r\n"); |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
209 listData.prepend(signature.toBase64()); |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
210 listData.prepend("S:"); |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
211 |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
212 QFile outputFile(filePath); |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
213 |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
214 if (!outputFile.open(QIODevice::WriteOnly)) { |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
215 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
|
216 return false; |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
217 } |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
218 |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
219 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
|
220 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
|
221 outputFile.close(); |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
222 return false; |
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 outputFile.close(); |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
225 return true; |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
226 } |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
227 |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
228 void CreateCertListDialog::createList() |
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
229 { |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
230 if (!mPk) { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
231 showErrorMessage(tr("Please select a valid rsa key.")); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
232 } |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
233 if (mSaveDir->text().isEmpty()) { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
234 showErrorMessage(tr("Please select an output location first.")); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
235 } |
454
efd1bd85112f
Save selected certificate in settings and parse it.
Andre Heinecke <aheinecke@intevation.de>
parents:
428
diff
changeset
|
236 |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
237 QDateTime currentDateTimeUtc = QDateTime::currentDateTimeUtc(); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
238 |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
239 QString fileName = QString::fromLatin1("certificates-") |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
240 .append(currentDateTimeUtc.toString(("yyyyMMddHHmmss"))) |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
241 .append(".txt"); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
242 |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
243 QString filePath = mSaveDir->text().append("/").append(fileName); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
244 |
466
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
245 if (!writeList(mAdminWindow->certificates(), filePath, |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
246 currentDateTimeUtc, mPk)) { |
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
247 showErrorMessage(tr("Failed to write list to: %1").arg(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 |
466
0d71ce440bcc
Factor out list creation to make it more testable
Andre Heinecke <aheinecke@intevation.de>
parents:
465
diff
changeset
|
250 QFile outputFile(filePath); |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
251 |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
252 /* Archive the list */ |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
253 QDir archiveDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
254 if (!archiveDir.mkpath(archiveDir.path())) { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
255 showErrorMessage(tr("Failed to create archive location.")); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
256 return; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
257 } |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
258 |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
259 if (!outputFile.copy(archiveDir.filePath(fileName))) { |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
260 showErrorMessage(tr("Failed Archive a copy.")); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
261 return; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
262 } |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
263 |
515
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
264 QString curCerts = archiveDir.filePath("current_certificates.txt"); |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
265 |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
266 if (QFile::exists(curCerts)) { |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
267 if (!QFile::remove(curCerts)) { |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
268 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
|
269 return; |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
270 } |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
271 } |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
272 |
9d3880db6ba7
Improve error handlig and persist user decisions
Andre Heinecke <aheinecke@intevation.de>
parents:
473
diff
changeset
|
273 if (!outputFile.copy(curCerts)) { |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
274 showErrorMessage(tr("Failed to write current_certificates file.")); |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
275 return; |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
276 } |
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
277 |
679
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 QString keyFingerprint; |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
280 |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
281 { |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
282 /* 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
|
283 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
|
284 int ret; |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
285 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
|
286 if (ret <= 0) { |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
287 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
|
288 return; |
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 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
|
291 QByteArray fp = sha256sum(derKey); |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
292 |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
293 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
|
294 keyFingerprint += QString("%1").arg( |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
295 (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
|
296 if (i != fp.size() - 1) { |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
297 keyFingerprint += ":"; |
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 keyFingerprint = keyFingerprint.toUpper(); |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
301 } |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
302 |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
303 mAdminWindow->logChanges(curCerts, keyFingerprint); |
75cd2fbf9ac6
(Issue 9) Log key's sha256 fingerprint
Andre Heinecke <andre.heinecke@intevation.de>
parents:
562
diff
changeset
|
304 |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
305 QMessageBox::information(this, "", tr("Saved certificate list:\n%1").arg(fileName)); |
1317
d009da9cfa10
(issue157) Reload list after successful creation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1199
diff
changeset
|
306 emit creationSuccessful(); |
d009da9cfa10
(issue157) Reload list after successful creation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1199
diff
changeset
|
307 |
465
88dfe16a0bb9
Implement certificatelist saving
Andre Heinecke <aheinecke@intevation.de>
parents:
454
diff
changeset
|
308 close(); |
367
9491782a8f5a
Added dialog to create a signed certificate list file.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
309 } |