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.
113 lines
4.0 KiB
113 lines
4.0 KiB
14 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
|
#ifndef CERTIFICATE_HXX
|
||
|
#define CERTIFICATE_HXX
|
||
|
|
||
|
#include <ui_certificate.h>
|
||
|
#include <QtCore/QDateTime>
|
||
|
#include <QtGui/QTreeWidget>
|
||
|
#include <QtGui/QTreeWidgetItem>
|
||
|
#include <QtNetwork/QSslCertificate>
|
||
|
|
||
13 years ago
|
#include <QtCore/QDebug>
|
||
|
|
||
14 years ago
|
class Certificate: public QWidget, protected Ui::Certificate {
|
||
14 years ago
|
public:
|
||
14 years ago
|
Certificate(QWidget* p): QWidget(p) {
|
||
14 years ago
|
setupUi(this);
|
||
|
}
|
||
|
Certificate& certificate(const QSslCertificate& cert) {
|
||
|
_cert->clear();
|
||
|
if (!cert.isValid()) return *this;
|
||
|
_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))));
|
||
13 years ago
|
if (!cert.subjectInfo(QByteArray("serialNumber")).isEmpty()) {
|
||
|
_cert->addTopLevelItem
|
||
|
((new QTreeWidgetItem
|
||
|
(QStringList()<<tr("SuisseID Number")
|
||
|
<<cert.subjectInfo(QByteArray("serialNumber")))));
|
||
|
}
|
||
14 years ago
|
_cert->addTopLevelItem
|
||
|
((new QTreeWidgetItem
|
||
13 years ago
|
(QStringList()<<tr("Certificate Serial Number")
|
||
14 years ago
|
<<cert.serialNumber())));
|
||
13 years ago
|
// _cert->addTopLevelItem
|
||
|
// ((new QTreeWidgetItem
|
||
|
// (QStringList()<<tr("Version")
|
||
|
// <<cert.version())));
|
||
14 years ago
|
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>
|
||
|
asns(cert.alternateSubjectNames());
|
||
|
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;
|
||
|
}
|
||
|
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");
|
||
|
}
|
||
|
};
|
||
|
|
||
|
#endif
|