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:
parent
65e51944c2
commit
6bf471ff13
@ -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})
|
||||
|
@ -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() )
|
||||
|
53
src/tomahawk/web/Api2HttpsServerConnector.cpp
Normal file
53
src/tomahawk/web/Api2HttpsServerConnector.cpp
Normal 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 );
|
||||
}
|
42
src/tomahawk/web/Api2HttpsServerConnector.h
Normal file
42
src/tomahawk/web/Api2HttpsServerConnector.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user