1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 00:12:06 +02:00

Allow the usage of self-signed certificates for accessing the API

This commit is contained in:
Uwe L. Korn 2013-06-23 01:24:26 +02:00
parent 65e51944c2
commit 6bf471ff13
4 changed files with 99 additions and 2 deletions

View File

@ -111,6 +111,7 @@ IF( QXTWEB_FOUND )
web/Api_v1.cpp
web/Api_v2.cpp
web/Api_v2_0.cpp
web/Api2HttpsServerConnector.cpp
)
LIST(APPEND LINK_LIBRARIES ${QXTWEB_LIBRARIES})
INCLUDE_DIRECTORIES(${QXTWEB_INCLUDE_DIRS})

View File

@ -40,6 +40,7 @@
#include "network/DbSyncConnection.h"
#include "web/Api_v1.h"
#include "web/Api_v2.h"
#include "web/Api2HttpsServerConnector.h"
#include "SourceList.h"
#include "ViewManager.h"
#include "ShortcutHandler.h"
@ -540,8 +541,8 @@ TomahawkApp::initHTTP()
}
else
{
m_httpv2_session = QPointer< QxtHttpSessionManager >( new QxtHttpSessionManager() );
m_httpv2_connector = QPointer< QxtHttpsServerConnector >( new QxtHttpsServerConnector );
m_httpv2_session = QPointer< QxtHttpSessionManager >( new QxtHttpSessionManager( this ) );
m_httpv2_connector = QPointer< QxtHttpsServerConnector >( new Api2HttpsServerConnector( this ) );
if ( m_httpv2_session.isNull() || m_httpv2_connector.isNull() )
{
if ( !m_httpv2_session.isNull() )

View File

@ -0,0 +1,53 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Api2HttpsServerConnector.h"
#include "utils/Logger.h"
#include <QSslSocket>
Api2HttpsServerConnector::Api2HttpsServerConnector( QObject *parent )
: QxtHttpsServerConnector( parent )
{
}
void
Api2HttpsServerConnector::sslErrors( const QList<QSslError>& errors )
{
QList<QSslError> toIgnore;
QSslSocket* socket = static_cast<QSslSocket*>( sender() );
foreach ( QSslError error, errors )
{
if ( error.error() == QSslError::SelfSignedCertificate )
{
toIgnore.append( error );
}
else if ( error.error() == QSslError::CertificateUntrusted )
{
toIgnore.append( error );
}
else
{
tLog() << Q_FUNC_INFO << "Not ignoring SSL error" << error << error.error();
}
}
socket->ignoreSslErrors( toIgnore );
}

View File

@ -0,0 +1,42 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef API2HTTPSSERVERCONNECTOR_H
#define API2HTTPSSERVERCONNECTOR_H
#include <QxtWeb/QxtHttpServerConnector>
class Api2HttpsServerConnector : public QxtHttpsServerConnector
{
Q_OBJECT
public:
Api2HttpsServerConnector( QObject* parent );
protected:
/**
* We want to handle ourselves which SSL certificates are trusted.
*
* Ignore errors about untrusted and self-signed certificates.
*
* Already a slot in QxtHttpsServerConnector
*/
void sslErrors( const QList<QSslError>& errors );
};
#endif // API2HTTPSSERVERCONNECTOR_H