From e052c6532456d818b804ce726c8a6e66c81ad8a0 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sat, 28 Nov 2009 20:37:26 +0100 Subject: [PATCH 1/1] Add SslInfoDlg as a nice way to show information about an SSL connection --- src/common/util.cpp | 12 +- src/qtui/CMakeLists.txt | 6 + src/qtui/sslinfodlg.cpp | 81 ++++++ src/qtui/sslinfodlg.h | 51 ++++ src/qtui/ui/sslinfodlg.ui | 516 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 660 insertions(+), 6 deletions(-) create mode 100644 src/qtui/sslinfodlg.cpp create mode 100644 src/qtui/sslinfodlg.h create mode 100644 src/qtui/ui/sslinfodlg.ui diff --git a/src/common/util.cpp b/src/common/util.cpp index 817790f8..8b9231e1 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -108,14 +108,14 @@ uint editingDistance(const QString &s1, const QString &s2) { uint insertChar = matrix[i][j-1] + 1; if(deleteChar < insertChar) - min = deleteChar; + min = deleteChar; else - min = insertChar; + min = insertChar; if(s1[i-1] == s2[j-1]) { - uint inheritChar = matrix[i-1][j-1]; - if(inheritChar < min) - min = inheritChar; + uint inheritChar = matrix[i-1][j-1]; + if(inheritChar < min) + min = inheritChar; } matrix[i][j] = min; @@ -144,7 +144,7 @@ QString secondsToString(int timeInSeconds) { } QByteArray prettyDigest(const QByteArray &digest) { - QByteArray hexDigest = digest.toHex(); + QByteArray hexDigest = digest.toHex().toUpper(); QByteArray prettyDigest; prettyDigest.fill(':', hexDigest.count() + (hexDigest.count() / 2) - 1); diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index 28e1b68a..3e7e0670 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -151,6 +151,12 @@ else(HAVE_KDE) endif(HAVE_PHONON) endif(HAVE_KDE) +if(HAVE_SSL) + set(SOURCES ${SOURCES} sslinfodlg.cpp) + set(MOC_HDRS ${MOC_HDRS} sslinfodlg.h) + set(FORMS ${FORMS} sslinfodlg.ui) +endif(HAVE_SSL) + if(INDICATEQT_FOUND) set(SOURCES ${SOURCES} indicatornotificationbackend.cpp) set(MOC_HDRS ${MOC_HDRS} indicatornotificationbackend.h) diff --git a/src/qtui/sslinfodlg.cpp b/src/qtui/sslinfodlg.cpp new file mode 100644 index 00000000..b636f161 --- /dev/null +++ b/src/qtui/sslinfodlg.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2009 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include + +#include "sslinfodlg.h" +#include "util.h" + +// ======================================== +// SslInfoDlg +// ======================================== + +SslInfoDlg::SslInfoDlg(const QSslSocket *socket, QWidget *parent) + : QDialog(parent), + _socket(socket) +{ + ui.setupUi(this); + + QSslCipher cipher = socket->sessionCipher(); + + ui.hostname->setText(socket->peerName()); + ui.address->setText(socket->peerAddress().toString()); + ui.encryption->setText(cipher.name()); + ui.protocol->setText(cipher.protocolString()); + + connect(ui.certificateChain, SIGNAL(currentIndexChanged(int)), SLOT(setCurrentCert(int))); + foreach(const QSslCertificate &cert, socket->peerCertificateChain()) { + ui.certificateChain->addItem(cert.subjectInfo(QSslCertificate::CommonName)); + } +} + +void SslInfoDlg::setCurrentCert(int index) { + QSslCertificate cert = socket()->peerCertificateChain().at(index); + ui.subjectCommonName->setText(cert.subjectInfo(QSslCertificate::CommonName)); + ui.subjectOrganization->setText(cert.subjectInfo(QSslCertificate::Organization)); + ui.subjectOrganizationalUnit->setText(cert.subjectInfo(QSslCertificate::OrganizationalUnitName)); + ui.subjectCountry->setText(cert.subjectInfo(QSslCertificate::CountryName)); + ui.subjectState->setText(cert.subjectInfo(QSslCertificate::StateOrProvinceName)); + ui.subjectCity->setText(cert.subjectInfo(QSslCertificate::LocalityName)); + + ui.issuerCommonName->setText(cert.issuerInfo(QSslCertificate::CommonName)); + ui.issuerOrganization->setText(cert.issuerInfo(QSslCertificate::Organization)); + ui.issuerOrganizationalUnit->setText(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)); + ui.issuerCountry->setText(cert.issuerInfo(QSslCertificate::CountryName)); + ui.issuerState->setText(cert.issuerInfo(QSslCertificate::StateOrProvinceName)); + ui.issuerCity->setText(cert.issuerInfo(QSslCertificate::LocalityName)); + + if(socket()->sslErrors().isEmpty()) + ui.trusted->setText(tr("Yes")); + else { + QString errorString = tr("No, for the following reasons:
    "); + foreach(const QSslError &error, socket()->sslErrors()) + errorString += "
  • " + error.errorString() + "
  • "; + errorString += "
"; + ui.trusted->setText(errorString); + } + + ui.validity->setText(tr("%1 to %2").arg(cert.effectiveDate().date().toString(Qt::ISODate), cert.expiryDate().date().toString(Qt::ISODate))); + ui.md5Digest->setText(prettyDigest(cert.digest(QCryptographicHash::Md5))); + ui.sha1Digest->setText(prettyDigest(cert.digest(QCryptographicHash::Sha1))); +} diff --git a/src/qtui/sslinfodlg.h b/src/qtui/sslinfodlg.h new file mode 100644 index 00000000..d7660215 --- /dev/null +++ b/src/qtui/sslinfodlg.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2009 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef SSLINFODLG_H +#define SSLINFODLG_H + +#include + +#include "ui_sslinfodlg.h" + +class QSslSocket; + +// ======================================== +// SslInfoDialog +// ======================================== + +class QSslCertificate; + +class SslInfoDlg : public QDialog { + Q_OBJECT + +public: + SslInfoDlg(const QSslSocket *socket, QWidget *parent = 0); + inline const QSslSocket *socket() const { return _socket; } + +private slots: + void setCurrentCert(int index); + +private: + Ui::SslInfoDlg ui; + const QSslSocket *_socket; +}; + +#endif diff --git a/src/qtui/ui/sslinfodlg.ui b/src/qtui/ui/sslinfodlg.ui new file mode 100644 index 00000000..6daa17c7 --- /dev/null +++ b/src/qtui/ui/sslinfodlg.ui @@ -0,0 +1,516 @@ + + + SslInfoDlg + + + + 0 + 0 + 555 + 449 + + + + Security Information + + + + + + + + <b>Hostname:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + n/a + + + + + + + <b>IP address:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + n/a + + + + + + + <b>Encryption:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + n/a + + + + + + + <b>Protocol:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + n/a + + + + + + + <b>Certificate chain:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + 0 + + + + Subject + + + + + + <b>Common name:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Common Name + + + + + + + <b>Organization:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Organization + + + + + + + <b>Organizational unit:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Organizational Unit + + + + + + + <b>Country:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Country + + + + + + + <b>State or province:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + State + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + City + + + + + + + <b>Locality:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + Issuer + + + + + + <b>Common name:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Common Name + + + + + + + <b>Organization:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Organization + + + + + + + <b>Organizational unit:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Organizational Unit + + + + + + + <b>Country:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Country + + + + + + + <b>State or province:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + State + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + City + + + + + + + <b>Locality:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + <b>Validity period:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + n/a + + + + + + + <b>MD5 digest:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + n/a + + + + + + + <b>SHA1 digest:</b> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + n/a + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + <b>Trusted:</b> + + + Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing + + + + + + + + 0 + 0 + + + + n/a + + + false + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + SslInfoDlg + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SslInfoDlg + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- 2.20.1