You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.4 KiB
133 lines
4.4 KiB
/*! @file |
|
|
|
@id $Id$ |
|
*/ |
|
// 1 2 3 4 5 6 7 8 |
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890 |
|
|
|
#ifndef CERTIFICATE_HXX |
|
#define CERTIFICATE_HXX |
|
|
|
#include <ui_certificate.hxx> |
|
#include <QtCore/QDateTime> |
|
#include <QTreeWidget> |
|
#include <QTreeWidgetItem> |
|
#include <QtNetwork/QSslCertificate> |
|
#include <QMdiSubWindow> |
|
|
|
#include <QtCore/QDebug> |
|
|
|
#if QT_VERSION >= 0x050000 |
|
namespace QSsl { |
|
typedef AlternativeNameEntryType AlternateNameEntryType; |
|
} |
|
#endif |
|
|
|
class Certificate: public QWidget, protected Ui::Certificate { |
|
Q_OBJECT; |
|
public: |
|
Certificate(QWidget * parent = 0): QWidget(parent) { |
|
setupUi(this); |
|
} |
|
Certificate& certificate(const QSslCertificate& cert) { |
|
_certificate = cert; |
|
_cert->clear(); |
|
#if QT_VERSION < 0x050000 |
|
if (!cert.isValid()) return *this; |
|
#endif |
|
_cert->addTopLevelItem |
|
((new QTreeWidgetItem |
|
(QStringList()<<tr("Valid Since") |
|
<<cert.effectiveDate().toString(Qt::SystemLocaleLongDate)))); |
|
_cert->addTopLevelItem |
|
((new QTreeWidgetItem |
|
(QStringList()<<tr("Valid Until") |
|
<<cert.expiryDate().toString(Qt::SystemLocaleLongDate)))); |
|
if (!cert.subjectInfo(QByteArray("serialNumber")).isEmpty()) { |
|
_cert->addTopLevelItem |
|
((new QTreeWidgetItem |
|
(QStringList()<<tr("SuisseID Number") |
|
<<cert.subjectInfo(QByteArray("serialNumber"))))); |
|
} |
|
_cert->addTopLevelItem |
|
((new QTreeWidgetItem |
|
(QStringList()<<tr("Certificate Serial Number") |
|
<<cert.serialNumber()))); |
|
// _cert->addTopLevelItem |
|
// ((new QTreeWidgetItem |
|
// (QStringList()<<tr("Version") |
|
// <<cert.version()))); |
|
QTreeWidgetItem *it(0); |
|
_cert->addTopLevelItem |
|
((it = new QTreeWidgetItem(QStringList()<<tr("Subject Info")<<""))); |
|
for (QSslCertificate::SubjectInfo |
|
si(QSslCertificate::StateOrProvinceName); |
|
si>=QSslCertificate::Organization; |
|
si=(QSslCertificate::SubjectInfo)((int)si-1)) |
|
if (!cert.subjectInfo(si).isEmpty()) |
|
it->addChild |
|
((new QTreeWidgetItem |
|
(QStringList()<<subjectInfo(si)<<cert.subjectInfo(si)))); |
|
QTreeWidgetItem *it2(0); |
|
it->addChild |
|
((it2 = new QTreeWidgetItem |
|
(QStringList()<<tr("Alternate Subject")<<""))); |
|
QMultiMap<QSsl::AlternateNameEntryType, QString> |
|
#if QT_VERSION <0x050000 |
|
asns(cert.alternateSubjectNames()) |
|
#else |
|
asns(cert.subjectAlternativeNames()) |
|
#endif |
|
; |
|
for (QMultiMap<QSsl::AlternateNameEntryType, QString>::iterator |
|
asn(asns.begin()); asn!=asns.end(); ++asn) |
|
it2->addChild |
|
((new QTreeWidgetItem |
|
(QStringList()<<alternateName(asn.key())<<asn.value()))); |
|
_cert->addTopLevelItem |
|
((it = new QTreeWidgetItem(QStringList()<<tr("Issuer Info")<<""))); |
|
for (QSslCertificate::SubjectInfo |
|
si(QSslCertificate::StateOrProvinceName); |
|
si>=QSslCertificate::Organization; |
|
si=(QSslCertificate::SubjectInfo)((int)si-1)) |
|
if (!cert.issuerInfo(si).isEmpty()) |
|
it->addChild |
|
((new QTreeWidgetItem |
|
(QStringList()<<subjectInfo(si)<<cert.issuerInfo(si)))); |
|
_cert->expandAll(); |
|
_cert->resizeColumnToContents(0); |
|
_cert->resizeColumnToContents(1); |
|
return *this; |
|
} |
|
QSslCertificate certificate() { |
|
return _certificate; |
|
} |
|
QString alternateName(QSsl::AlternateNameEntryType an) { |
|
switch (an) { |
|
case QSsl::EmailEntry: return tr("E-Mail"); |
|
case QSsl::DnsEntry: return tr("URL"); |
|
} |
|
return tr("error", "unknown certificate subject alternate name"); |
|
} |
|
QString subjectInfo(QSslCertificate::SubjectInfo si) { |
|
switch (si) { |
|
case QSslCertificate::Organization: |
|
return tr("Organization"); |
|
case QSslCertificate::CommonName: |
|
return tr("Common Name"); |
|
case QSslCertificate::LocalityName: |
|
return tr("Locality"); |
|
case QSslCertificate::OrganizationalUnitName: |
|
return tr("Organizational Unit"); |
|
case QSslCertificate::CountryName: |
|
return tr("Country"); |
|
case QSslCertificate::StateOrProvinceName: |
|
return tr("State or Province"); |
|
} |
|
return tr("error", "unknown certificate subject info"); |
|
} |
|
protected: |
|
QSslCertificate _certificate; |
|
}; |
|
|
|
#endif
|
|
|