mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-29 16:50:11 +02:00
* Intercept and handle SSL errors for JS resolvers.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
#include "ScriptCollection.h"
|
#include "ScriptCollection.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
|
#include "TomahawkSettings.h"
|
||||||
|
|
||||||
#include "accounts/AccountConfigWidget.h"
|
#include "accounts/AccountConfigWidget.h"
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QMetaProperty>
|
#include <QMetaProperty>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
#include <QSslError>
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
@@ -384,16 +386,6 @@ QtScriptResolverHelper::returnStreamUrl( const QString& streamUrl, boost::functi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )
|
|
||||||
{
|
|
||||||
tLog() << "JAVASCRIPT:" << m_scriptPath << message << lineNumber << sourceID;
|
|
||||||
#ifndef DEBUG_BUILD
|
|
||||||
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Script Resolver Error: %1 %2 %3 %4" ).arg( m_scriptPath ).arg( message ).arg( lineNumber ).arg( sourceID ) ) );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QtScriptResolver::QtScriptResolver( const QString& scriptPath, const QStringList& additionalScriptPaths )
|
QtScriptResolver::QtScriptResolver( const QString& scriptPath, const QStringList& additionalScriptPaths )
|
||||||
: Tomahawk::ExternalResolverGui( scriptPath )
|
: Tomahawk::ExternalResolverGui( scriptPath )
|
||||||
, m_ready( false )
|
, m_ready( false )
|
||||||
@@ -924,7 +916,7 @@ QVariantMap
|
|||||||
QtScriptResolver::loadDataFromWidgets()
|
QtScriptResolver::loadDataFromWidgets()
|
||||||
{
|
{
|
||||||
QVariantMap saveData;
|
QVariantMap saveData;
|
||||||
foreach(const QVariant& dataWidget, m_dataWidgets)
|
foreach( const QVariant& dataWidget, m_dataWidgets )
|
||||||
{
|
{
|
||||||
QVariantMap data = dataWidget.toMap();
|
QVariantMap data = dataWidget.toMap();
|
||||||
|
|
||||||
@@ -1099,3 +1091,96 @@ QtScriptResolver::resolverCollections()
|
|||||||
// + data.
|
// + data.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ScriptEngine::ScriptEngine( QtScriptResolver* parent )
|
||||||
|
: QWebPage( (QObject*) parent )
|
||||||
|
, m_parent( parent )
|
||||||
|
{
|
||||||
|
settings()->setAttribute( QWebSettings::OfflineStorageDatabaseEnabled, true );
|
||||||
|
settings()->setOfflineStoragePath( TomahawkUtils::appDataDir().path() );
|
||||||
|
settings()->setAttribute(QWebSettings::LocalStorageEnabled, true );
|
||||||
|
settings()->setLocalStoragePath( TomahawkUtils::appDataDir().path() );
|
||||||
|
settings()->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true );
|
||||||
|
settings()->setAttribute( QWebSettings::LocalContentCanAccessFileUrls, true );
|
||||||
|
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
|
||||||
|
|
||||||
|
// Tomahawk is not a user agent
|
||||||
|
m_header = QWebPage::userAgentForUrl( QUrl() ).replace( QString( "%1/%2" )
|
||||||
|
.arg( TOMAHAWK_APPLICATION_NAME )
|
||||||
|
.arg( TOMAHAWK_VERSION )
|
||||||
|
,"");
|
||||||
|
tLog( LOGVERBOSE ) << "QtScriptResolver Using header" << m_header;
|
||||||
|
|
||||||
|
connect( networkAccessManager(), SIGNAL( sslErrors( QNetworkReply*, QList<QSslError> ) ),
|
||||||
|
SLOT( sslErrorHandler( QNetworkReply*, QList<QSslError> ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )
|
||||||
|
{
|
||||||
|
tLog() << "JAVASCRIPT:" << m_scriptPath << message << lineNumber << sourceID;
|
||||||
|
#ifndef DEBUG_BUILD
|
||||||
|
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Script Resolver Error: %1 %2 %3 %4" ).arg( m_scriptPath ).arg( message ).arg( lineNumber ).arg( sourceID ) ) );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptEngine::sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist )
|
||||||
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
QByteArray digest = errlist.first().certificate().digest();
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
if ( !TomahawkSettings::instance()->isSslCertKnown( digest ) )
|
||||||
|
{
|
||||||
|
foreach ( const QSslError& err, errlist )
|
||||||
|
tDebug() << Q_FUNC_INFO << "SSL error:" << err;
|
||||||
|
|
||||||
|
QMessageBox question( TomahawkUtils::tomahawkWindow() );
|
||||||
|
question.setWindowTitle( tr( "SSL Error" ) );
|
||||||
|
question.setText( tr( "You have asked Tomahawk to connect securely to <b>%1</b>, but we can't confirm that your connection is secure:<br><br>"
|
||||||
|
"<b>%2</b><br><br>"
|
||||||
|
"Do you want to trust this connection?" )
|
||||||
|
.arg( qnr->url().host() )
|
||||||
|
.arg( errlist.first().errorString() ) );
|
||||||
|
|
||||||
|
question.setStandardButtons( QMessageBox::No );
|
||||||
|
question.addButton( tr( "Trust certificate" ), QMessageBox::AcceptRole );
|
||||||
|
|
||||||
|
result = question.exec();
|
||||||
|
|
||||||
|
//FIXME: discuss whether we want to store rejects, too (needs settings management to remove the decision?)
|
||||||
|
if ( result == QMessageBox::AcceptRole )
|
||||||
|
TomahawkSettings::instance()->setSslCertTrusted( digest, result == QMessageBox::AcceptRole );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( TomahawkSettings::instance()->isSslCertTrusted( digest ) )
|
||||||
|
{
|
||||||
|
qnr->ignoreSslErrors();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
ScriptEngine::userAgentForUrl( const QUrl& url ) const
|
||||||
|
{
|
||||||
|
Q_UNUSED( url );
|
||||||
|
return m_header;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptEngine::setScriptPath( const QString& scriptPath )
|
||||||
|
{
|
||||||
|
m_scriptPath = scriptPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ScriptEngine::shouldInterruptJavaScript()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@@ -99,46 +99,20 @@ class DLLEXPORT ScriptEngine : public QWebPage
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ScriptEngine( QtScriptResolver* parent )
|
explicit ScriptEngine( QtScriptResolver* parent );
|
||||||
: QWebPage( (QObject*) parent )
|
|
||||||
, m_parent( parent )
|
|
||||||
{
|
|
||||||
settings()->setAttribute( QWebSettings::OfflineStorageDatabaseEnabled, true );
|
|
||||||
settings()->setOfflineStoragePath( TomahawkUtils::appDataDir().path() );
|
|
||||||
settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
|
|
||||||
settings()->setLocalStoragePath( TomahawkUtils::appDataDir().path() );
|
|
||||||
settings()->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true );
|
|
||||||
settings()->setAttribute( QWebSettings::LocalContentCanAccessFileUrls, true );
|
|
||||||
settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
|
|
||||||
|
|
||||||
// Tomahawk is not a user agent
|
QString userAgentForUrl( const QUrl& url ) const;
|
||||||
m_header = QWebPage::userAgentForUrl( QUrl() ).replace( QString( "%1/%2" )
|
void setScriptPath( const QString& scriptPath );
|
||||||
.arg( TOMAHAWK_APPLICATION_NAME )
|
|
||||||
.arg( TOMAHAWK_VERSION )
|
|
||||||
,"");
|
|
||||||
tLog() << "QtScriptResolver Using header" << m_header;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString userAgentForUrl ( const QUrl & url ) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(url);
|
|
||||||
return m_header;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setScriptPath( const QString& scriptPath )
|
|
||||||
{
|
|
||||||
m_scriptPath = scriptPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool shouldInterruptJavaScript()
|
bool shouldInterruptJavaScript();
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID );
|
virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void sslErrorHandler( QNetworkReply* qnr, const QList<QSslError>& errlist );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QtScriptResolver* m_parent;
|
QtScriptResolver* m_parent;
|
||||||
QString m_scriptPath;
|
QString m_scriptPath;
|
||||||
|
Reference in New Issue
Block a user