From 7ad1d7abc365fada5fff7b2a3f29b7da0a32c401 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 18 Jan 2014 18:33:49 +0100 Subject: [PATCH] Remote: Use sha1 instead of md5 for file hashing. --- src/core/utilities.cpp | 4 ++-- src/core/utilities.h | 2 +- src/networkremote/outgoingdatacreator.cpp | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 22658896b..cf0ed3ad1 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -457,9 +457,9 @@ QByteArray Sha256(const QByteArray& data) { } // File must not be open and will be closed afterwards! -QByteArray Md5File(QFile &file) { +QByteArray Sha1File(QFile &file) { file.open(QIODevice::ReadOnly); - QCryptographicHash hash(QCryptographicHash::Md5); + QCryptographicHash hash(QCryptographicHash::Sha1); QByteArray data; while(!file.atEnd()) { diff --git a/src/core/utilities.h b/src/core/utilities.h index a64f74610..bf3c31426 100644 --- a/src/core/utilities.h +++ b/src/core/utilities.h @@ -67,7 +67,7 @@ namespace Utilities { QByteArray HmacSha256(const QByteArray& key, const QByteArray& data); QByteArray HmacSha1(const QByteArray& key, const QByteArray& data); QByteArray Sha256(const QByteArray& data); - QByteArray Md5File(QFile& file); + QByteArray Sha1File(QFile& file); QByteArray Sha1CoverHash(const QString& artist, const QString& album); diff --git a/src/networkremote/outgoingdatacreator.cpp b/src/networkremote/outgoingdatacreator.cpp index f17620cb1..c99fe0c2c 100644 --- a/src/networkremote/outgoingdatacreator.cpp +++ b/src/networkremote/outgoingdatacreator.cpp @@ -642,9 +642,9 @@ void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song, // Open the file QFile file(song.url().toLocalFile()); - // Get md5 for file - QByteArray md5 = Utilities::Md5File(file).toHex(); - qLog(Debug) << "md5 for file" << song.url().toLocalFile() << "=" << md5; + // Get sha1 for file + QByteArray sha1 = Utilities::Sha1File(file).toHex(); + qLog(Debug) << "sha1 for file" << song.url().toLocalFile() << "=" << sha1; file.open(QIODevice::ReadOnly); @@ -670,7 +670,7 @@ void OutgoingDataCreator::SendSingleSong(RemoteClient* client, const Song &song, chunk->set_file_number(song_no); chunk->set_size(file.size()); chunk->set_data(data.data(), data.size()); - chunk->set_file_hash(md5.data(), md5.size()); + chunk->set_file_hash(sha1.data(), sha1.size()); // On the first chunk send the metadata, so the client knows // what file it receives. @@ -753,9 +753,9 @@ void OutgoingDataCreator::SendLibrary(RemoteClient *client) { // Open the file QFile file(temp_file_name); - // Get the md5 hash - QByteArray md5 = Utilities::Md5File(file).toHex(); - qLog(Debug) << "Library md5" << md5; + // Get the sha1 hash + QByteArray sha1 = Utilities::Sha1File(file).toHex(); + qLog(Debug) << "Library sha1" << sha1; file.open(QIODevice::ReadOnly); @@ -777,7 +777,7 @@ void OutgoingDataCreator::SendLibrary(RemoteClient *client) { chunk->set_chunk_number(chunk_number); chunk->set_size(file.size()); chunk->set_data(data.data(), data.size()); - chunk->set_file_hash(md5.data(), md5.size()); + chunk->set_file_hash(sha1.data(), sha1.size()); // Send data directly to the client client->SendData(&msg);