1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-14 18:35:16 +01:00

Use Qt functions instead of custom pem -> der.

This commit is contained in:
John Maguire 2015-05-19 13:45:33 +01:00
parent f46454b197
commit fa90e72d24

View File

@ -33,6 +33,7 @@
#include <QMessageBox>
#include <QNetworkReply>
#include <QProgressDialog>
#include <QSslKey>
#ifdef Q_OS_UNIX
#include <unistd.h>
@ -43,11 +44,6 @@
#include <cryptopp/rsa.h>
#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";
SpotifyBlobDownloader::SpotifyBlobDownloader(const QString& version,
@ -189,7 +185,7 @@ bool SpotifyBlobDownloader::CheckSignature(
#ifdef HAVE_CRYPTOPP
QFile public_key_file(":/clementine-spotify-public.pem");
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 {
CryptoPP::ByteQueue bytes;
@ -232,12 +228,9 @@ bool SpotifyBlobDownloader::CheckSignature(
}
QByteArray SpotifyBlobDownloader::ConvertPEMToDER(const QByteArray& pem) {
// Ensure we used char[] not char*
static_assert(sizeof(PEM_HEADER) > sizeof(char*), "PEM_HEADER mis-declared");
static_assert(sizeof(PEM_FOOTER) > sizeof(char*), "PEM_FOOTER mis-declared");
int start = pem.indexOf(PEM_HEADER) + arraysize(PEM_HEADER) - 1;
int length = pem.indexOf(PEM_FOOTER) - start;
return QByteArray::fromBase64(pem.mid(start, length));
QSslKey key(pem, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey);
Q_ASSERT(!key.isNull());
return key.toDer();
}
void SpotifyBlobDownloader::ReplyProgress() {