Use Qt functions instead of custom pem -> der.
This commit is contained in:
parent
f46454b197
commit
fa90e72d24
@ -33,6 +33,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
#include <QSslKey>
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -43,11 +44,6 @@
|
|||||||
#include <cryptopp/rsa.h>
|
#include <cryptopp/rsa.h>
|
||||||
#endif // HAVE_CRYPTOPP
|
#endif // HAVE_CRYPTOPP
|
||||||
|
|
||||||
namespace {
|
|
||||||
static const char PEM_HEADER[] = "-----BEGIN PUBLIC KEY-----\n";
|
|
||||||
static const char PEM_FOOTER[] = "\n-----END PUBLIC KEY-----";
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* SpotifyBlobDownloader::kSignatureSuffix = ".sha512";
|
const char* SpotifyBlobDownloader::kSignatureSuffix = ".sha512";
|
||||||
|
|
||||||
SpotifyBlobDownloader::SpotifyBlobDownloader(const QString& version,
|
SpotifyBlobDownloader::SpotifyBlobDownloader(const QString& version,
|
||||||
@ -189,7 +185,7 @@ bool SpotifyBlobDownloader::CheckSignature(
|
|||||||
#ifdef HAVE_CRYPTOPP
|
#ifdef HAVE_CRYPTOPP
|
||||||
QFile public_key_file(":/clementine-spotify-public.pem");
|
QFile public_key_file(":/clementine-spotify-public.pem");
|
||||||
public_key_file.open(QIODevice::ReadOnly);
|
public_key_file.open(QIODevice::ReadOnly);
|
||||||
QByteArray public_key_data = ConvertPEMToDER(public_key_file.readAll());
|
const QByteArray public_key_data = ConvertPEMToDER(public_key_file.readAll());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CryptoPP::ByteQueue bytes;
|
CryptoPP::ByteQueue bytes;
|
||||||
@ -232,12 +228,9 @@ bool SpotifyBlobDownloader::CheckSignature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
QByteArray SpotifyBlobDownloader::ConvertPEMToDER(const QByteArray& pem) {
|
QByteArray SpotifyBlobDownloader::ConvertPEMToDER(const QByteArray& pem) {
|
||||||
// Ensure we used char[] not char*
|
QSslKey key(pem, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey);
|
||||||
static_assert(sizeof(PEM_HEADER) > sizeof(char*), "PEM_HEADER mis-declared");
|
Q_ASSERT(!key.isNull());
|
||||||
static_assert(sizeof(PEM_FOOTER) > sizeof(char*), "PEM_FOOTER mis-declared");
|
return key.toDer();
|
||||||
int start = pem.indexOf(PEM_HEADER) + arraysize(PEM_HEADER) - 1;
|
|
||||||
int length = pem.indexOf(PEM_FOOTER) - start;
|
|
||||||
return QByteArray::fromBase64(pem.mid(start, length));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpotifyBlobDownloader::ReplyProgress() {
|
void SpotifyBlobDownloader::ReplyProgress() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user