parent
06513a9d34
commit
768e910272
14 changed files with 574 additions and 6 deletions
@ -0,0 +1,133 @@ |
||||
/*! @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 |
@ -0,0 +1,59 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>Certificate</class> |
||||
<widget class="QWidget" name="Certificate"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>400</width> |
||||
<height>320</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Form</string> |
||||
</property> |
||||
<layout class="QGridLayout" name="gridLayout"> |
||||
<item row="0" column="0"> |
||||
<widget class="QTreeWidget" name="_cert"> |
||||
<property name="editTriggers"> |
||||
<set>QAbstractItemView::NoEditTriggers</set> |
||||
</property> |
||||
<property name="alternatingRowColors"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="rootIsDecorated"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="sortingEnabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="wordWrap"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<attribute name="headerVisible"> |
||||
<bool>false</bool> |
||||
</attribute> |
||||
<attribute name="headerCascadingSectionResizes"> |
||||
<bool>true</bool> |
||||
</attribute> |
||||
<attribute name="headerShowSortIndicator" stdset="0"> |
||||
<bool>false</bool> |
||||
</attribute> |
||||
<column> |
||||
<property name="text"> |
||||
<string>Attribute</string> |
||||
</property> |
||||
</column> |
||||
<column> |
||||
<property name="text"> |
||||
<string>Value</string> |
||||
</property> |
||||
</column> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
@ -0,0 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!DOCTYPE TS> |
||||
<TS version="2.1" language="de"> |
||||
</TS> |
@ -0,0 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!DOCTYPE TS> |
||||
<TS version="2.1" language="en"> |
||||
</TS> |
@ -0,0 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!DOCTYPE TS> |
||||
<TS version="2.1" language="fr"> |
||||
</TS> |
@ -0,0 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!DOCTYPE TS> |
||||
<TS version="2.1" language="it"> |
||||
</TS> |
@ -0,0 +1,73 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id$ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#ifndef OPENFROMURL_HXX |
||||
#define OPENFROMURL_HXX |
||||
|
||||
#include <ui_openfromurl.hxx> |
||||
#include <QDialog> |
||||
#include <QNetworkAccessManager> |
||||
#include <QNetworkReply> |
||||
|
||||
class OpenFromURL: public QDialog, public Ui::OpenFromURL { |
||||
Q_OBJECT; |
||||
public: |
||||
OpenFromURL(QWidget* p): QDialog(p) { |
||||
setupUi(this); |
||||
} |
||||
QString url() { |
||||
return _url->currentText(); |
||||
} |
||||
void read() { |
||||
QNetworkReply* reply |
||||
(_net.head(QNetworkRequest(QUrl("https://"+_url->currentText())))); |
||||
connect(reply, SIGNAL(finished()), SLOT(finished())); |
||||
connect(reply, SIGNAL(encrypted()), SLOT(encrypted())); |
||||
connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)), |
||||
SLOT(sslErrors(const QList<QSslError>&))); |
||||
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), |
||||
SLOT(error(QNetworkReply::NetworkError))); |
||||
} |
||||
signals: |
||||
void certificate(QUrl, QSslCertificate); |
||||
protected slots: |
||||
void on__buttons_accepted() { |
||||
_url->addItem(_url->currentText()); |
||||
} |
||||
void finished() { |
||||
qDebug()<<"finished"; |
||||
QNetworkReply* reply(dynamic_cast<QNetworkReply*>(sender())); |
||||
QList<QSslCertificate> certs(reply->sslConfiguration() |
||||
.peerCertificateChain()); |
||||
qDebug()<<"number of peer certificates: "<<certs.size(); |
||||
if (certs.size()) { |
||||
Q_FOREACH(QSslCertificate cert, certs) {
|
||||
certificate(reply->url(), cert);
|
||||
} |
||||
} else { |
||||
QSslCertificate cert(reply->sslConfiguration().peerCertificate()); |
||||
if (!cert.isNull()) { |
||||
certificate(reply->url(), cert); |
||||
} else { |
||||
qDebug()<<"no peer certificate found"; |
||||
} |
||||
} |
||||
} |
||||
void encrypted() { |
||||
qDebug()<<"encrypted"; |
||||
} |
||||
void sslErrors(const QList<QSslError>& errors) { |
||||
qDebug()<<"sslErrors"; |
||||
} |
||||
void error(QNetworkReply::NetworkError code) { |
||||
qDebug()<<"error"; |
||||
} |
||||
private: |
||||
QNetworkAccessManager _net; |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,101 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>OpenFromURL</class> |
||||
<widget class="QDialog" name="OpenFromURL"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>434</width> |
||||
<height>89</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Open Certificate From URL</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="label"> |
||||
<property name="text"> |
||||
<string>Hostname:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QComboBox" name="_url"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="editable"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<spacer name="verticalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Vertical</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>20</width> |
||||
<height>4</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="_buttons"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>_buttons</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>OpenFromURL</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>_buttons</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>OpenFromURL</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
Loading…
Reference in new issue