From 10877c3ec0184e6c2a07b8775d32c8efc38a29a3 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 21 Jun 2018 12:16:00 +0200 Subject: Enable client certificate store Creates the default client cerficate store for the platform and when given a choice of client certificates forwards to the choice to the application. Only a Widgets API for now. Task-number: QTBUG-54877 Change-Id: Ie15152398d5769579fa0c07e3e3035c2374e9940 Reviewed-by: Michal Klocek --- .../api/qwebengineclientcertselection.cpp | 123 +++++++++++++++++++++ .../api/qwebengineclientcertselection.h | 80 ++++++++++++++ src/webenginewidgets/api/qwebenginepage.cpp | 31 ++++++ src/webenginewidgets/api/qwebenginepage.h | 7 +- src/webenginewidgets/api/qwebenginepage_p.h | 1 + 5 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/webenginewidgets/api/qwebengineclientcertselection.cpp create mode 100644 src/webenginewidgets/api/qwebengineclientcertselection.h (limited to 'src/webenginewidgets/api') diff --git a/src/webenginewidgets/api/qwebengineclientcertselection.cpp b/src/webenginewidgets/api/qwebengineclientcertselection.cpp new file mode 100644 index 000000000..de1e101f6 --- /dev/null +++ b/src/webenginewidgets/api/qwebengineclientcertselection.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebengineclientcertselection.h" + +#if QT_CONFIG(ssl) + +#include "client_cert_select_controller.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QWebEngineClientCertSelection + \brief The QWebEngineClientCertSelection class wraps a client certificate selection. + \since 5.12 + \inmodule QtWebEngineWidgets + + Provides access to the certicates to choose from, and a method for selecting one. + + The selection is asynchronous. If no certificate is selected and no copy of the + object is kept alive, loading will continue without a certificate. +*/ + +/*! \internal +*/ +QWebEngineClientCertSelection::QWebEngineClientCertSelection(QSharedPointer selectController) + : d_ptr(selectController) +{} + +QWebEngineClientCertSelection::QWebEngineClientCertSelection(const QWebEngineClientCertSelection &other) + : d_ptr(other.d_ptr) +{} + +QWebEngineClientCertSelection &QWebEngineClientCertSelection::operator=(const QWebEngineClientCertSelection &other) +{ + d_ptr = other.d_ptr; + return *this; +} + +QWebEngineClientCertSelection::~QWebEngineClientCertSelection() +{ +} + +/*! + Returns the client certificates available to choose from. + + \sa select() +*/ +QVector QWebEngineClientCertSelection::certificates() const +{ + return d_ptr->certificates(); +} + +/*! + Selects the client certificate \a certificate. The certificate must be one + of those offered in certificates(). + + \sa certificates(), selectNone() +*/ +void QWebEngineClientCertSelection::select(const QSslCertificate &certificate) +{ + d_ptr->select(certificate); +} + +/*! + Continue without using any of the offered certificates. This is the same + action as taken when destroying the last copy of this object if no + selection has been made. + + \sa select() +*/ +void QWebEngineClientCertSelection::selectNone() +{ + d_ptr->selectNone(); +} + +/*! + Returns the host and port of the server requesting the client certificate. +*/ +QUrl QWebEngineClientCertSelection::host() const +{ + return d_ptr->hostAndPort(); +} + +QT_END_NAMESPACE + +#endif // QT_CONFIG(ssl) diff --git a/src/webenginewidgets/api/qwebengineclientcertselection.h b/src/webenginewidgets/api/qwebengineclientcertselection.h new file mode 100644 index 000000000..84de56a67 --- /dev/null +++ b/src/webenginewidgets/api/qwebengineclientcertselection.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBENGINECLIENTCERTSELECTION_H +#define QWEBENGINECLIENTCERTSELECTION_H + +#include +#include + +#if QT_CONFIG(ssl) + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class ClientCertSelectController; + +class QWEBENGINEWIDGETS_EXPORT QWebEngineClientCertSelection { +public: + QWebEngineClientCertSelection(const QWebEngineClientCertSelection &); + ~QWebEngineClientCertSelection(); + + QWebEngineClientCertSelection &operator=(const QWebEngineClientCertSelection &); + + QUrl host() const; + + void select(const QSslCertificate &certificate); + void selectNone(); + QVector certificates() const; + +private: + friend class QWebEnginePagePrivate; + + QWebEngineClientCertSelection(QSharedPointer); + + QSharedPointer d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QT_CONFIG(ssl) + +#endif // QWEBENGINECLIENTCERTSELECTION_H diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 2bb19361a..885ad7a69 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -50,6 +50,7 @@ #if QT_CONFIG(webengine_printing_and_pdf) #include "printing/pdfium_document_wrapper_qt.h" #endif +#include "qwebenginecertificateerror.h" #include "qwebenginefullscreenrequest.h" #include "qwebenginehistory.h" #include "qwebenginehistory_p.h" @@ -1632,6 +1633,36 @@ void QWebEnginePagePrivate::allowCertificateError(const QSharedPointeraccept(accepted); } +void QWebEnginePagePrivate::selectClientCert(const QSharedPointer &controller) +{ +#if QT_CONFIG(ssl) + Q_Q(QWebEnginePage); + QWebEngineClientCertSelection certSelection(controller); + + Q_EMIT q->selectClientCertificate(certSelection); +#else + Q_UNUSED(controller); +#endif +} + +#if QT_CONFIG(ssl) +/*! + \fn void QWebEnginePage::selectClientCertificate(QWebEngineClientCertSelection clientCertSelection) + \since 5.12 + + This signal is emitted when a web site requests an SSL client certificate, and one or more were + found in system's client certificate store. + + Handling the signal is asynchronous, and loading will be waiting until a certificate is selected, + or the last copy of \a clientCertSelection is destroyed. + + If the signal is not handled, \a clientCertSelection is automatically destroyed, and loading + will continue without a client certificate. + + \sa QWebEngineClientCertSelection +*/ +#endif + void QWebEnginePagePrivate::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID) { Q_Q(QWebEnginePage); diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 3edfb96d0..6de31d9d5 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -41,7 +41,7 @@ #define QWEBENGINEPAGE_H #include -#include +#include #include #include #include @@ -59,6 +59,8 @@ class QPrinter; class QContextMenuBuilder; class QWebChannel; +class QWebEngineCertificateError; +class QWebEngineClientCertSelection; class QWebEngineContextMenuData; class QWebEngineFullScreenRequest; class QWebEngineHistory; @@ -318,6 +320,9 @@ Q_SIGNALS: void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); void quotaRequested(QWebEngineQuotaRequest quotaRequest); void registerProtocolHandlerRequested(QWebEngineRegisterProtocolHandlerRequest request); +#if QT_CONFIG(ssl) + void selectClientCertificate(QWebEngineClientCertSelection clientCertSelection); +#endif void authenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator); void proxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator, const QString &proxyHost); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 831879127..e5657c1b6 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -136,6 +136,7 @@ public: QObject *accessibilityParentObject() override; QtWebEngineCore::WebEngineSettings *webEngineSettings() const override; void allowCertificateError(const QSharedPointer &controller) override; + void selectClientCert(const QSharedPointer &controller) override; void renderProcessTerminated(RenderProcessTerminationStatus terminationStatus, int exitCode) override; void requestGeometryChange(const QRect &geometry, const QRect &frameGeometry) override; void updateScrollPosition(const QPointF &position) override; -- cgit v1.2.3