From acad08fb9884541431030a851d587c25d7e9acf0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 9 Jul 2011 17:54:28 +0200 Subject: Improving SSL Widget and Dialog While the widget "copies" and "rethink" Google Chrome actual one, the dialog has been implemented starting from the comparison between the ones we have in KDE, Google Chrome's and Firefox's. I have to start from somewhere... --- src/CMakeLists.txt | 2 + src/sslinfo.ui | 283 +++++++++++++++++++++++++++++++++++++++++++++++ src/sslinfodialog.cpp | 122 ++++++++++++++++++++ src/sslinfodialog.h | 71 ++++++++++++ src/sslinfodialog_p.h | 107 ------------------ src/urlbar/sslwidget.cpp | 40 ++++++- src/urlbar/sslwidget.h | 5 + 7 files changed, 520 insertions(+), 110 deletions(-) create mode 100644 src/sslinfo.ui create mode 100644 src/sslinfodialog.cpp create mode 100644 src/sslinfodialog.h delete mode 100644 src/sslinfodialog_p.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 10d5b92b..fd946168 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ SET( rekonq_KDEINIT_SRCS previewselectorbar.cpp protocolhandler.cpp sessionmanager.cpp + sslinfodialog.cpp tabpreviewpopup.cpp tabbar.cpp tabhighlighteffect.cpp @@ -99,6 +100,7 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS settings/settings_webkit.ui settings/settings_adblock.ui cleardata.ui + sslinfo.ui useragent/useragentsettings.ui ) diff --git a/src/sslinfo.ui b/src/sslinfo.ui new file mode 100644 index 00000000..97ca69d0 --- /dev/null +++ b/src/sslinfo.ui @@ -0,0 +1,283 @@ + + + SslInfo + + + + 0 + 0 + 460 + 432 + + + + Form + + + + + + + 0 + 0 + + + + <h2>Certificate Information</h2> + + + + + + + + + + + + + + + + <h4>Issued To:</h4> + + + + + + + + + Common Name (CN): + + + + + + + TextLabel + + + + + + + Organization (O): + + + + + + + TextLabel + + + + + + + Organizational Unit (OU): + + + + + + + TextLabel + + + + + + + Serial Number: + + + + + + + TextLabel + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + <h4>Issued By:</h4> + + + + + + + + + Common Name (CN): + + + + + + + TextLabel + + + + + + + Organization (O): + + + + + + + Organizational Unit (OU): + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + <h4>Validity Period:</h4> + + + + + + + + + Issued on: + + + + + + + TextLabel + + + + + + + Expires on: + + + + + + + TextLabel + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + <h4>FingerPrints:</h4> + + + + + + + + + SHA-256 FingerPrints: + + + + + + + TextLabel + + + + + + + SHA-1 FingerPrints: + + + + + + + TextLabel + + + + + + + + + + + + + diff --git a/src/sslinfodialog.cpp b/src/sslinfodialog.cpp new file mode 100644 index 00000000..67fc753d --- /dev/null +++ b/src/sslinfodialog.cpp @@ -0,0 +1,122 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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, see . +* +* ============================================================ */ + + +// Self Includes +#include "sslinfodialog.h" +#include "sslinfodialog.moc" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + + +SslInfoDialog::SslInfoDialog(const QString &host, const WebSslInfo &info, QWidget *parent) + : KDialog(parent) + , m_host(host) + , m_info(info) +{ + setCaption(i18n("Rekonq SSL Information")); + setAttribute(Qt::WA_DeleteOnClose); + + setMinimumWidth(300); + + setButtons(KDialog::User1 | KDialog::Close); + + setButtonGuiItem(User1, KGuiItem(i18n("Export"), "view-certificate-export") ); + connect(this, SIGNAL(user1Clicked()), this, SLOT(exportCert())); + + ui.setupUi(mainWidget()); + + // ------------------------------------------------ + QList caList = m_info.certificateChain(); + + Q_FOREACH(const QSslCertificate &cert, caList) + { + ui.comboBox->addItem( cert.subjectInfo(QSslCertificate::CommonName) ); + } + connect(ui.comboBox, SIGNAL(activated(int)), this, SLOT(displayFromChain(int))); + + QSslCertificate subjectCert = caList.first(); + + showCertificateInfo(subjectCert); +} + + +void SslInfoDialog::showCertificateInfo(QSslCertificate subjectCert) +{ + ui.subjectCN->setText( subjectCert.subjectInfo(QSslCertificate::CommonName) ); + ui.subjectO->setText( subjectCert.subjectInfo(QSslCertificate::Organization) ); + ui.subjectOU->setText( subjectCert.subjectInfo(QSslCertificate::OrganizationalUnitName) ); + ui.subjectSN->setText( subjectCert.serialNumber().toHex() ); + + ui.issuerCN->setText( subjectCert.issuerInfo(QSslCertificate::CommonName) ); + ui.issuerO->setText( subjectCert.issuerInfo(QSslCertificate::Organization) ); + ui.issuerOU->setText( subjectCert.issuerInfo(QSslCertificate::OrganizationalUnitName) ); + + ui.issuedOn->setText( subjectCert.effectiveDate().date().toString(Qt::SystemLocaleShortDate) ); + ui.expiresOn->setText( subjectCert.expiryDate().date().toString(Qt::SystemLocaleShortDate) ); + ui.sha256->setText( subjectCert.digest(QCryptographicHash::Md5).toHex() ); + ui.sha1->setText( subjectCert.digest(QCryptographicHash::Sha1).toHex() ); + +} + + +void SslInfoDialog::displayFromChain(int i) +{ + QList caList = m_info.certificateChain(); + QSslCertificate cert = caList.at(i); + showCertificateInfo(cert); +} + + +void SslInfoDialog::exportCert() +{ + QSslCertificate cert = m_info.certificateChain().at( ui.comboBox->currentIndex() ); + + QString name = cert.subjectInfo(QSslCertificate::CommonName) + QL1S(".pem"); + + QString certPath = KFileDialog::getSaveFileName(name, QString(), this); + + kDebug() << certPath; + + QFile file(certPath); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + + QTextStream out(&file); + out << cert.toPem(); +} diff --git a/src/sslinfodialog.h b/src/sslinfodialog.h new file mode 100644 index 00000000..c9b4c106 --- /dev/null +++ b/src/sslinfodialog.h @@ -0,0 +1,71 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2011 by Andrea Diamantini +* +* +* 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 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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, see . +* +* ============================================================ */ + + +#ifndef SSL_INFO_DIALOG_H +#define SSL_INFO_DIALOG_H + +#include "rekonq_defines.h" + +#include "websslinfo.h" + +// Ui Includes +#include "ui_sslinfo.h" + +#include + +#include + +class QSslCertificate; +class QString; + +/** + * Rekonq SSL Information Dialog + * + * This class creates a dialog that can be used to display information about + * an SSL session. + * + */ +class SslInfoDialog : public KDialog +{ + Q_OBJECT + +public: + explicit SslInfoDialog(const QString &host, const WebSslInfo &info, QWidget *parent = 0); + +private Q_SLOTS: + void displayFromChain(int); + void exportCert(); + +private: + void showCertificateInfo(QSslCertificate); + + QString m_host; + WebSslInfo m_info; + + Ui::SslInfo ui; +}; + +#endif // SSL_INFO_DIALOG_H diff --git a/src/sslinfodialog_p.h b/src/sslinfodialog_p.h deleted file mode 100644 index 72f16791..00000000 --- a/src/sslinfodialog_p.h +++ /dev/null @@ -1,107 +0,0 @@ -/* This file is part of the KDE project - * - * Copyright (C) 2000-2003 George Staikos - * Copyright (C) 2000 Malte Starostik - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - - -#ifndef SSLINFODIALOG_P_H -#define SSLINFODIALOG_P_H - -#include - -#include -#include - -// NOTE: We need a copy of this header file is needed here because it -// is never installed by default by KIO. - -/** - * KDE SSL Information Dialog - * - * This class creates a dialog that can be used to display information about - * an SSL session. - * - * There are NO GUARANTEES that KSslInfoDialog will remain binary compatible/ - * Contact staikos@kde.org for details if needed. - * - * @author George Staikos - * @see KSSL - * @short KDE SSL Information Dialog - */ -class KDE_EXPORT KSslInfoDialog : public KDialog -{ - Q_OBJECT - -public: - /** - * Construct a KSSL Information Dialog - * - * @param parent the parent widget - */ - explicit KSslInfoDialog(QWidget *parent = 0); - - /** - * Destroy this dialog - */ - virtual ~KSslInfoDialog(); - - /** - * Tell the dialog if the connection has portions that may not be - * secure (ie. a mixture of secure and insecure frames) - * - * @param isIt true if security is in question - */ - void setSecurityInQuestion(bool isIt); - - /** - * Set information to display about the SSL connection. - * - * @param certificateChain the certificate chain leading from the certificate - * authority to the peer. - * @param ip the ip of the remote host - * @param host the remote hostname - * @param sslProtocol the version of SSL in use (SSLv2, SSLv3, TLSv1) - * @param cipher the cipher in use - * @param usedBits the used bits of the key - * @param bits the key size of the cipher in use - * @param validationErrors errors validating the certificates, if any - */ - void setSslInfo(const QList &certificateChain, - const QString &ip, const QString &host, - const QString &sslProtocol, const QString &cipher, - int usedBits, int bits, - const QList > &validationErrors); - - void setMainPartEncrypted(bool); - void setAuxiliaryPartsEncrypted(bool); - - static QList > errorsFromString(const QString &s); - -private Q_SLOTS: - void launchConfig(); - void displayFromChain(int); - -private: - void updateWhichPartsEncrypted(); - - class KSslInfoDialogPrivate; - KSslInfoDialogPrivate* const d; -}; - -#endif // SSLINFODIALOG_P_H diff --git a/src/urlbar/sslwidget.cpp b/src/urlbar/sslwidget.cpp index 79194c6f..40532cb3 100644 --- a/src/urlbar/sslwidget.cpp +++ b/src/urlbar/sslwidget.cpp @@ -31,6 +31,7 @@ // Local includes #include "application.h" #include "historymanager.h" +#include "sslinfodialog.h" // KDE Includes @@ -43,6 +44,8 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) : QMenu(parent) + , m_url(url) + , m_info(info) { setAttribute(Qt::WA_DeleteOnClose); setMinimumWidth(400); @@ -54,8 +57,9 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) QLabel *label; + // ------------------------------------------------------------------------------------------------------------------ label = new QLabel(this); - label->setText( QL1S("

") + url.host() + QL1S("

") ); + label->setText( i18n("

Identity

") ); layout->addRow(label); if (firstCA.isNull()) @@ -81,7 +85,13 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) } label = new QLabel(this); - label->setText( QL1S("

") + i18n("Issued to") + QL1S("

") ); // ----------------------------------------------- // + label->setText("Certificate Information"); + connect(label, SIGNAL(linkActivated(const QString &)), this, SLOT(showMoreSslInfos(const QString &))); + layout->addRow(label); + + // ------------------------------------------------------------------------------------------------------------------ + label = new QLabel(this); + label->setText( QL1S("

Encryption

") ); // ----------------------------------------------- // layout->addRow(label); label = new QLabel(this); @@ -145,7 +155,7 @@ SSLWidget::SSLWidget(const QUrl &url, const WebSslInfo &info, QWidget *parent) // ------------------------------------------------------------------------------------------------------------------ label = new QLabel(this); - label->setText( QL1S("

") + i18n("Site Information") + QL1S("

") ); + label->setText( i18n("

Site Information

") ); layout->addRow(label); label = new QLabel(this); @@ -180,3 +190,27 @@ void SSLWidget::accept() close(); } + + +void SSLWidget::showMoreSslInfos(const QString &) +{ + // FIXME: show it every time??? + if (m_info.isValid()) + { + QPointer dlg = new SslInfoDialog(m_url.host(), m_info, this); +// dlg->setSslInfo(m_info.certificateChain(), +// m_info.peerAddress().toString(), +// m_host, +// m_info.protocol(), +// m_info.ciphers(), +// m_info.usedChiperBits(), +// m_info.supportedChiperBits() +// ); + + dlg->exec(); + delete dlg; + + return; + } + +} diff --git a/src/urlbar/sslwidget.h b/src/urlbar/sslwidget.h index 4e36d364..00478f59 100644 --- a/src/urlbar/sslwidget.h +++ b/src/urlbar/sslwidget.h @@ -46,7 +46,12 @@ public: void showAt(const QPoint &pos); private Q_SLOTS: + void showMoreSslInfos(const QString &); void accept(); + +private: + QUrl m_url; + WebSslInfo m_info; }; #endif // SSL_WIDGET_H -- cgit v1.2.1