1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Copyright (C) Fabian Müller <fmueller@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "tlserrordialog.h"
#include "common/utility.h"
#include "ui_tlserrordialog.h"
#include <QAbstractButton>
#include <QPushButton>
namespace OCC {
TlsErrorDialog::TlsErrorDialog(const QList<QSslError> &sslErrors, const QString &host, QWidget *parent)
: QDialog(parent)
, _ui(new Ui::TlsErrorDialog)
{
_ui->setupUi(this);
_ui->hostnameLabel->setText(tr("Cannot connect securely to %1").arg(host));
QStringList errorStrings;
for (const auto &error : sslErrors) {
errorStrings << error.errorString() << describeCertificateHtml(error.certificate());
}
_ui->textBrowser->setHtml(errorStrings.join("\n"));
// FIXME: add checkbox for second confirmation
connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, [this]() {
accept();
});
connect(_ui->buttonBox, &QDialogButtonBox::rejected, this, [this]() {
reject();
});
// of course, we require an answer from the user, they may not proceed with anything else
setModal(true);
}
TlsErrorDialog::~TlsErrorDialog()
{
delete _ui;
}
QString TlsErrorDialog::describeCertificateHtml(const QSslCertificate &certificate)
{
auto formatFingerprint = [certificate](QCryptographicHash::Algorithm algorithm) {
return Utility::escape(certificate.digest(algorithm).toHex());
};
auto formatInfo = [](const QStringList &stringList) {
return Utility::escape(stringList.join(", "));
};
auto escapeValueOrNotSpecified = [&](const QStringList &stringList) {
if (stringList.isEmpty()) {
return tr("<not specified>");
} else {
return formatInfo(stringList);
}
};
QString msg = tr(
"<div id=\"cert\">"
"<h3>with Certificate %1</h3>"
"<div id=\"ccert\">"
"<p>"
"Organization: %2<br/>"
"Unit: %3<br/>"
"Country: %4"
"</p>"
"<p>"
"Fingerprint (MD5): <tt>%5</tt><br/>"
"Fingerprint (SHA1): <tt>%6</tt><br/>"
"<br/>"
"Effective Date: %7"
"Expiration Date: %8"
"</div>"
"<h3>Issuer: %9</h3>"
"<div id=\"issuer\">"
"<p>"
"Organization: %10<br/>"
"Unit: %11<br/>"
"Country: %12"
"</p>"
"</div>"
"</div>")
.arg(
formatInfo(certificate.subjectInfo(QSslCertificate::CommonName)),
escapeValueOrNotSpecified(certificate.subjectInfo(QSslCertificate::Organization)),
escapeValueOrNotSpecified(certificate.subjectInfo(QSslCertificate::OrganizationalUnitName)),
escapeValueOrNotSpecified(certificate.subjectInfo(QSslCertificate::CountryName)),
formatFingerprint(QCryptographicHash::Md5),
formatFingerprint(QCryptographicHash::Sha1),
certificate.effectiveDate().toString(),
certificate.expiryDate().toString(),
formatInfo(certificate.issuerInfo(QSslCertificate::CommonName)),
escapeValueOrNotSpecified(certificate.issuerInfo(QSslCertificate::Organization)),
escapeValueOrNotSpecified(certificate.issuerInfo(QSslCertificate::OrganizationalUnitName)),
escapeValueOrNotSpecified(certificate.issuerInfo(QSslCertificate::CountryName)));
return msg;
}
} // OCC
|