1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-30 19:00:12 +02:00

Add QCA2 as an optional dep to tomahawk as well for HMAC signature generation for resolvers

Also add a helper JS function
This commit is contained in:
Leo Franchi
2011-08-29 00:10:30 -04:00
parent 5c5042769b
commit 8ed476ccf6
5 changed files with 42 additions and 1 deletions

View File

@@ -102,7 +102,8 @@ check_taglib_filename( COMPLEX_TAGLIB_FILENAME )
macro_optional_find_package(Boost)
macro_log_feature(Boost_FOUND "Boost" "Provides free peer-reviewed portable C++ source libraries" "http://www.boost.org" TRUE "" "") #FIXME: give useful explaination
macro_optional_find_package(QCA2)
macro_log_feature(QCA2_FOUND "QCA2" "Provides encryption and signing functions required for Grooveshark resolver" "http://delta.affinix.com/qca/" TRUE "" "")
# required
#While we distribute our own liblastfm2, don't need to look for it

View File

@@ -91,6 +91,11 @@ var TomahawkResolver = {
var configJson = JSON.stringify( config );
window.localStorage[ this.scriptPath() ] = configJson;
this.newConfigSaved();
},
newConfigSaved: function()
{
},
resolve: function( qid, artist, album, title )
{

View File

@@ -163,6 +163,7 @@ INCLUDE_DIRECTORIES(
${QJSON_INCLUDE_DIR}
${LIBECHONEST_INCLUDE_DIR}
${LIBECHONEST_INCLUDE_DIR}/..
${QCA2_INCLUDE_DIR}
)
SET( OS_SPECIFIC_LINK_LIBRARIES "" )
@@ -245,6 +246,7 @@ TARGET_LINK_LIBRARIES( tomahawk
${QXTWEB_LIBRARIES}
${QJSON_LIBRARIES}
${TAGLIB_LIBRARIES}
${QCA2_LIBRARIES}
)

View File

@@ -25,6 +25,7 @@
#include "utils/tomahawkutils.h"
#include <QMetaProperty>
#include <QCryptographicHash>
#include "utils/logger.h"
@@ -119,6 +120,32 @@ QtScriptResolverHelper::setResolverConfig( const QVariantMap& config )
m_resolverConfig = config;
}
QString
QtScriptResolverHelper::hmac( const QByteArray& key, const QByteArray &input )
{
if ( !QCA::isSupported( "hmac(md5)" ) )
{
tLog() << "HMAC(md5) not supported with qca-ossl plugin, or qca-ossl plugin is not installed! Unable to generate signature!";
return QByteArray();
}
QCA::MessageAuthenticationCode md5hmac1( "hmac(md5)", QCA::SecureArray() );
QCA::SymmetricKey keyObject( key );
md5hmac1.setup( keyObject );
md5hmac1.update( QCA::SecureArray( input ) );
QCA::SecureArray resultArray = md5hmac1.final();
QString result = QCA::arrayToHex( resultArray.toByteArray() );
return result.toUtf8();
}
QString
QtScriptResolverHelper::md5( const QByteArray& input )
{
QByteArray const digest = QCryptographicHash::hash( input, QCryptographicHash::Md5 );
return QString::fromLatin1( digest.toHex() );
}
void
ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID )

View File

@@ -30,6 +30,7 @@
#include <QThread>
#include <QtWebKit/QWebPage>
#include <QtWebKit/QWebFrame>
#include <QtCrypto>
class QtScriptResolver;
@@ -41,6 +42,10 @@ public:
QtScriptResolverHelper( const QString& scriptPath, QtScriptResolver* parent );
void setResolverConfig( const QVariantMap& config );
// Return a HMAC (md5) signature of the input text with the desired key
Q_INVOKABLE QString hmac( const QByteArray& key, const QByteArray& input );
Q_INVOKABLE QString md5( const QByteArray& input );
public slots:
QByteArray readRaw( const QString& fileName );
QString readBase64( const QString& fileName );
@@ -58,6 +63,7 @@ private:
QString m_scriptPath;
QVariantMap m_resolverConfig;
QtScriptResolver* m_resolver;
QCA::Initializer m_qcaInit;
};
class ScriptEngine : public QWebPage