3
* Copyright (C) 2003 Justin Karneges
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include <QPushButton>
26
#include "iconwidget.h"
29
#include "sslcertdlg.h"
32
SSLCertDlg::SSLCertDlg(QWidget *parent)
37
setWindowTitle(CAP(caption()));
39
connect(ui_.pb_close, SIGNAL(clicked()), SLOT(close()));
40
ui_.pb_close->setDefault(true);
41
ui_.pb_close->setFocus();
44
QString SSLCertDlg::makePropTable(const QString &heading, const QCA::CertificateInfo &list)
47
str += "<tr><td><i>" + heading + "</i><br>";
49
str += makePropEntry(QCA::Organization, tr("Organization:"), list);
50
str += makePropEntry(QCA::OrganizationalUnit, tr("Organizational unit:"), list);
51
str += makePropEntry(QCA::Locality, tr("Locality:"), list);
52
str += makePropEntry(QCA::State, tr("State:"), list);
53
str += makePropEntry(QCA::Country, tr("Country:"), list);
54
str += makePropEntry(QCA::CommonName, tr("Common name:"), list);
55
str += makePropEntry(QCA::DNS, tr("Domain name:"), list);
56
str += makePropEntry(QCA::XMPP, tr("XMPP name:"), list);
57
str += makePropEntry(QCA::Email, tr("Email:"), list);
58
str += "</table></td></tr>";
62
void SSLCertDlg::setCert(const QCA::Certificate &cert, int result, QCA::Validity validity)
67
if(result == QCA::TLS::Valid) {
68
ui_.lb_valid->setText(tr("The certificate is valid."));
69
setLabelStatus(*ui_.lb_valid,true);
72
ui_.lb_valid->setText(tr("The certificate is NOT valid!") + "\n" + QString(tr("Reason: %1.")).arg(CertUtil::resultToString(result, validity)));
73
setLabelStatus(*ui_.lb_valid,false);
76
QDateTime now = QDateTime::currentDateTime();
77
QDateTime notBefore = cert.notValidBefore();
78
QDateTime notAfter = cert.notValidAfter();
79
ui_.lb_notBefore->setText(cert.notValidBefore().toString());
80
setLabelStatus(*ui_.lb_notBefore, now > notBefore);
81
ui_.lb_notAfter->setText(cert.notValidAfter().toString());
82
setLabelStatus(*ui_.lb_notAfter, now < notAfter);
84
ui_.lb_sn->setText(cert.serialNumber().toString());
88
str += makePropTable(tr("Subject Details:"), cert.subjectInfo());
89
str += makePropTable(tr("Issuer Details:"), cert.issuerInfo());
91
for (int i=0; i < 2; i++) {
92
QString hashstr = QCA::Hash(i == 0 ? "md5" : "sha1").hashToString(cert.toDER())
93
.toUpper().replace(QRegExp("(..)"), ":\\1").mid(1);
94
str += QString("Fingerprint(%1): %2<br>").arg(i == 0 ? "MD5" : "SHA-1").arg(hashstr);
96
ui_.tb_cert->setText(str);
99
void SSLCertDlg::showCert(const QCA::Certificate &certificate, int result, QCA::Validity validity)
101
SSLCertDlg *w = new SSLCertDlg(0);
102
w->setCert(certificate, result, validity);
107
void SSLCertDlg::setLabelStatus(QLabel& l, bool ok)
109
l.setPaletteForegroundColor(ok ? QColor("#2A993B") : QColor("#810000"));
112
QString SSLCertDlg::makePropEntry(QCA::CertificateInfoType var, const QString &name, const QCA::CertificateInfo &list)
115
QList<QString> values = list.values(var);
116
for (int i = 0; i < values.size(); ++i)
117
val += values.at(i) + "<br>";
122
return QString("<tr><td><nobr><b>") + name + "</b></nobr></td><td>" + val + "</td></tr>";