Qobuz: Add option for base64 app secret
This commit is contained in:
@@ -230,6 +230,8 @@ void QobuzService::ReloadSettings() {
|
||||
app_id_ = s.value("app_id").toString();
|
||||
app_secret_ = s.value("app_secret").toString();
|
||||
|
||||
const bool base64_secret = s.value("base64secret", false).toBool();;
|
||||
|
||||
username_ = s.value("username").toString();
|
||||
QByteArray password = s.value("password").toByteArray();
|
||||
if (password.isEmpty()) password_.clear();
|
||||
@@ -248,6 +250,29 @@ void QobuzService::ReloadSettings() {
|
||||
|
||||
s.endGroup();
|
||||
|
||||
if (base64_secret) {
|
||||
app_secret_ = DecodeAppSecret(app_secret_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString QobuzService::DecodeAppSecret(const QString &app_secret_base64) {
|
||||
|
||||
const QByteArray appid = app_id().toUtf8();
|
||||
const QByteArray app_secret_binary = QByteArray::fromBase64(app_secret_base64.toUtf8());
|
||||
QString app_secret_decoded;
|
||||
|
||||
for (int x = 0, y = 0; x < app_secret_binary.length(); ++x , ++y) {
|
||||
if (y == appid.length()) y = 0;
|
||||
const uint rc = app_secret_binary[x] ^ appid[y];
|
||||
if (rc > 0xFFFF) {
|
||||
return app_secret_base64;
|
||||
}
|
||||
app_secret_decoded.append(QChar(rc));
|
||||
}
|
||||
|
||||
return app_secret_decoded;
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::SendLogin() {
|
||||
|
||||
@@ -145,6 +145,7 @@ class QobuzService : public InternetService {
|
||||
using Param = QPair<QString, QString>;
|
||||
using ParamList = QList<Param>;
|
||||
|
||||
QString DecodeAppSecret(const QString &app_secret_encoded);
|
||||
void SendSearch();
|
||||
void LoginError(const QString &error = QString(), const QVariant &debug = QVariant());
|
||||
|
||||
|
||||
@@ -112,17 +112,6 @@ void QobuzStreamURLRequest::GetStreamURL() {
|
||||
reply_->deleteLater();
|
||||
}
|
||||
|
||||
#if 0
|
||||
QByteArray appid = app_id().toUtf8();
|
||||
QByteArray secret_decoded = QByteArray::fromBase64(app_secret().toUtf8());
|
||||
QString secret;
|
||||
for (int x = 0, y = 0; x < secret_decoded.length(); ++x , ++y) {
|
||||
if (y == appid.length()) y = 0;
|
||||
secret.append(QChar(secret_decoded[x] ^ appid[y]));
|
||||
}
|
||||
#endif
|
||||
|
||||
QString secret = app_secret();
|
||||
quint64 timestamp = QDateTime::currentDateTime().toSecsSinceEpoch();
|
||||
|
||||
ParamList params_to_sign = ParamList() << Param("format_id", QString::number(format()))
|
||||
@@ -136,7 +125,7 @@ void QobuzStreamURLRequest::GetStreamURL() {
|
||||
data_to_sign += param.first + param.second;
|
||||
}
|
||||
data_to_sign += QString::number(timestamp);
|
||||
data_to_sign += secret.toUtf8();
|
||||
data_to_sign += app_secret().toUtf8();
|
||||
|
||||
QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5);
|
||||
QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, '0').toLower();
|
||||
|
||||
Reference in New Issue
Block a user