QCA

certviewdlg.cpp
1/*
2 Copyright (C) 2007 Justin Karneges <justin@affinix.com>
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20*/
21
22#include "certviewdlg.h"
23
24#include "ui_certview.h"
25#include <QtCore>
26#include <QtCrypto>
27#include <QtGui>
28
29// from qcatool
30class InfoType
31{
32public:
34 QString varname;
35 QString shortname;
36 QString name;
37 QString desc;
38
39 InfoType()
40 {
41 }
42
43 InfoType(QCA::CertificateInfoType _type,
44 const QString &_varname,
45 const QString &_shortname,
46 const QString &_name,
47 const QString &_desc)
48 : type(_type)
49 , varname(_varname)
50 , shortname(_shortname)
51 , name(_name)
52 , desc(_desc)
53 {
54 }
55};
56
57static QList<InfoType> makeInfoTypeList(bool legacyEmail = false)
58{
60 out += InfoType(
61 QCA::CommonName, "CommonName", "CN", CertViewDlg::tr("Common Name (CN)"), "Full name, domain, anything");
62 out += InfoType(QCA::Email, "Email", "", CertViewDlg::tr("Email Address"), "");
63 if (legacyEmail)
64 out += InfoType(QCA::EmailLegacy, "EmailLegacy", "", CertViewDlg::tr("PKCS#9 Email Address"), "");
65 out += InfoType(QCA::Organization, "Organization", "O", CertViewDlg::tr("Organization (O)"), "Company, group, etc");
66 out += InfoType(QCA::OrganizationalUnit,
67 "OrganizationalUnit",
68 "OU",
69 CertViewDlg::tr("Organizational Unit (OU)"),
70 "Division/branch of organization");
71 out += InfoType(QCA::Locality, "Locality", "", CertViewDlg::tr("Locality (L)"), "City, shire, part of a state");
72 out += InfoType(QCA::State, "State", "", CertViewDlg::tr("State (ST)"), "State within the country");
73 out += InfoType(QCA::Country, "Country", "C", CertViewDlg::tr("Country Code (C)"), "2-letter code");
74 out += InfoType(QCA::IncorporationLocality,
75 "IncorporationLocality",
76 "",
77 CertViewDlg::tr("Incorporation Locality"),
78 "For EV certificates");
79 out += InfoType(QCA::IncorporationState,
80 "IncorporationState",
81 "",
82 CertViewDlg::tr("Incorporation State"),
83 "For EV certificates");
84 out += InfoType(QCA::IncorporationCountry,
85 "IncorporationCountry",
86 "",
87 CertViewDlg::tr("Incorporation Country"),
88 "For EV certificates");
89 out += InfoType(QCA::URI, "URI", "", CertViewDlg::tr("URI"), "");
90 out += InfoType(QCA::DNS, "DNS", "", CertViewDlg::tr("Domain Name"), "Domain (dnsName)");
91 out += InfoType(QCA::IPAddress, "IPAddress", "", CertViewDlg::tr("IP Adddress"), "");
92 out += InfoType(QCA::XMPP, "XMPP", "", CertViewDlg::tr("XMPP Address (JID)"), "From RFC 3920 (id-on-xmppAddr)");
93 return out;
94}
95
96static QString try_print_info(const QString &name, const QStringList &values)
97{
98 QString out;
99 if (!values.isEmpty()) {
100 QString value = values.join(", ");
101 out = QString(" ") + CertViewDlg::tr("%1: %2").arg(name, value) + '\n';
102 }
103 return out;
104}
105
106static QString print_info(const QString &title, const QCA::CertificateInfo &info)
107{
108 QString out;
109 QList<InfoType> list = makeInfoTypeList();
110 out += title + '\n';
111 foreach (const InfoType &t, list)
112 out += try_print_info(t.name, info.values(t.type));
113 return out;
114}
115
116static QString cert_info_string(const QCA::Certificate &cert)
117{
118 QString out;
119 out += CertViewDlg::tr("Serial Number: %1").arg(cert.serialNumber().toString()) + '\n';
120 out += print_info(CertViewDlg::tr("Subject"), cert.subjectInfo());
121 out += print_info(CertViewDlg::tr("Issuer"), cert.issuerInfo());
122 out += CertViewDlg::tr("Validity") + '\n';
123 out += QString(" ") + CertViewDlg::tr("Not before: %1").arg(cert.notValidBefore().toString()) + '\n';
124 out += QString(" ") + CertViewDlg::tr("Not after: %1").arg(cert.notValidAfter().toString()) + '\n';
125 return out;
126}
127
128class CertViewDlg::Private : public QObject
129{
131public:
132 CertViewDlg *q;
133 Ui_CertView ui;
135
136 Private(CertViewDlg *_q)
137 : QObject(_q)
138 , q(_q)
139 {
140 ui.setupUi(q);
141 connect(ui.cb_chain, SIGNAL(activated(int)), SLOT(cb_activated(int)));
142 ui.lb_info->setTextInteractionFlags(Qt::TextSelectableByMouse);
143 }
144
145 void update()
146 {
147 QStringList names = QCA::makeFriendlyNames(chain);
148 ui.cb_chain->clear();
149 foreach (const QString &s, names)
150 ui.cb_chain->insertItem(ui.cb_chain->count(), s);
151 updateInfo();
152 }
153
154 void updateInfo()
155 {
156 int x = ui.cb_chain->currentIndex();
157 if (x == -1) {
158 ui.lb_info->setText("");
159 return;
160 }
161
162 ui.lb_info->setText(cert_info_string(chain[x]));
163 }
164
165private Q_SLOTS:
166 void cb_activated(int)
167 {
168 updateInfo();
169 }
170};
171
172CertViewDlg::CertViewDlg(const QCA::CertificateChain &chain, QWidget *parent)
173 : QDialog(parent)
174{
175 d = new Private(this);
176 d->chain = chain;
177 d->update();
178}
179
180CertViewDlg::~CertViewDlg()
181{
182 delete d;
183}
184
185#include "certviewdlg.moc"
QString toString() const
A chain of related Certificates.
Definition qca_cert.h:1226
Certificate information type.
Definition qca_cert.h:120
Public Key (X.509) certificate.
Definition qca_cert.h:857
QDateTime notValidBefore() const
The earliest date that the certificate is valid.
BigInteger serialNumber() const
The serial number of the certificate.
QDateTime notValidAfter() const
The latest date that the certificate is valid.
CertificateInfo subjectInfo() const
CertificateInfo issuerInfo() const
Properties of the issuer of the certificate.
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
@ IncorporationCountry
The country of incorporation (EV certificates), id = "1.3.6.1.4.1.311.60.2.1.3".
Definition qca_cert.h:76
@ CommonName
The common name (eg person), id = "2.5.4.3".
Definition qca_cert.h:66
@ Country
The country, id = "2.5.4.6".
Definition qca_cert.h:75
@ XMPP
XMPP address (see http://www.ietf.org/rfc/rfc3920.txt), id = "1.3.6.1.5.5.7.8.5".
Definition qca_cert.h:80
@ Locality
The locality (eg city, a shire, or part of a state), id = "2.5.4.7".
Definition qca_cert.h:71
@ State
The state within the country, id = "2.5.4.8".
Definition qca_cert.h:73
@ Email
Email address, id = "GeneralName.rfc822Name".
Definition qca_cert.h:67
@ IPAddress
IP address, id = "GeneralName.iPAddress".
Definition qca_cert.h:79
@ IncorporationLocality
The locality of incorporation (EV certificates), id = "1.3.6.1.4.1.311.60.2.1.1".
Definition qca_cert.h:72
@ Organization
An organisation (eg company), id = "2.5.4.10".
Definition qca_cert.h:69
@ DNS
DNS name, id = "GeneralName.dNSName".
Definition qca_cert.h:78
@ EmailLegacy
PKCS#9 Email field, id = "1.2.840.113549.1.9.1".
Definition qca_cert.h:68
@ URI
Uniform Resource Identifier, id = "GeneralName.uniformResourceIdentifier".
Definition qca_cert.h:77
@ IncorporationState
The state of incorporation (EV certificates), id = "1.3.6.1.4.1.311.60.2.1.2".
Definition qca_cert.h:74
@ OrganizationalUnit
An part of an organisation (eg a division or branch), id = "2.5.4.11".
Definition qca_cert.h:70
QCA_EXPORT QStringList makeFriendlyNames(const QList< Certificate > &list)
Create a list of unique friendly names among a list of certificates.
QString toString(QStringView format, QCalendar cal) const const
bool isEmpty() const const
QList< T > values() const const
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QString join(QChar separator) const const
TextSelectableByMouse
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:52:37 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.