mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
klipper: use Katie's hash algorithm for history verification
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
09a2ce391f
commit
7b9d61e7ac
2 changed files with 16 additions and 11 deletions
|
@ -28,7 +28,7 @@ set(klipper_SRCS ${libklipper_common_SRCS} main.cpp tray.cpp)
|
|||
|
||||
add_executable(klipper ${klipper_SRCS})
|
||||
|
||||
target_link_libraries(klipper ${KDE4_KDEUI_LIBS} ${X11_LIBRARIES} ${ZLIB_LIBRARY})
|
||||
target_link_libraries(klipper ${KDE4_KDEUI_LIBS} ${X11_LIBRARIES} ${QT_QTNETWORK_LIBRARY})
|
||||
if (X11_Xfixes_FOUND)
|
||||
target_link_libraries(klipper ${X11_Xfixes_LIB})
|
||||
endif (X11_Xfixes_FOUND)
|
||||
|
|
|
@ -23,10 +23,9 @@
|
|||
|
||||
#include "klipper.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtNetwork/QCryptographicHash>
|
||||
|
||||
#include <KAboutData>
|
||||
#include <KLocale>
|
||||
|
@ -64,6 +63,12 @@
|
|||
|
||||
//#define NOISY_KLIPPER
|
||||
|
||||
#if QT_VERSION >= 0x041200
|
||||
static const QCryptographicHash::Algorithm KlipperHashAlhorithm = QCryptographicHash::KAT;
|
||||
#else
|
||||
static const QCryptographicHash::Algorithm KlipperHashAlhorithm = QCryptographicHash::Sha1;
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Use this when manipulating the clipboard
|
||||
|
@ -368,7 +373,7 @@ bool Klipper::loadHistory() {
|
|||
static const char* const failed_load_warning =
|
||||
"Failed to load history resource. Clipboard history cannot be read.";
|
||||
// don't use "appdata", klipper is also a kicker applet
|
||||
QString history_file_name = KStandardDirs::locateLocal( "data", "klipper/history2.lst" );
|
||||
QString history_file_name = KStandardDirs::locateLocal( "data", "klipper/history3.lst" );
|
||||
QFile history_file( history_file_name );
|
||||
if ( !history_file.exists() ) {
|
||||
kWarning() << failed_load_warning << ": " << "History file does not exist" ;
|
||||
|
@ -384,10 +389,10 @@ bool Klipper::loadHistory() {
|
|||
return false;
|
||||
}
|
||||
QByteArray data;
|
||||
quint32 crc;
|
||||
file_stream >> crc >> data;
|
||||
if( crc32( 0, reinterpret_cast<unsigned char *>( data.data() ), data.size() ) != crc ) {
|
||||
kWarning() << failed_load_warning << ": " << "CRC checksum does not match" ;
|
||||
QByteArray hash;
|
||||
file_stream >> hash >> data;
|
||||
if( QCryptographicHash::hash( data, KlipperHashAlhorithm ).toHex() != hash ) {
|
||||
kWarning() << failed_load_warning << ": " << "Hash does not match" ;
|
||||
return false;
|
||||
}
|
||||
QDataStream history_stream( &data, QIODevice::ReadOnly );
|
||||
|
@ -428,7 +433,7 @@ void Klipper::saveHistory(bool empty) {
|
|||
static const char* const failed_save_warning =
|
||||
"Failed to save history. Clipboard history cannot be saved.";
|
||||
// don't use "appdata", klipper is also a kicker applet
|
||||
QString history_file_name( KStandardDirs::locateLocal( "data", "klipper/history2.lst" ) );
|
||||
QString history_file_name( KStandardDirs::locateLocal( "data", "klipper/history3.lst" ) );
|
||||
if ( history_file_name.isNull() || history_file_name.isEmpty() ) {
|
||||
kWarning() << failed_save_warning ;
|
||||
return;
|
||||
|
@ -452,9 +457,9 @@ void Klipper::saveHistory(bool empty) {
|
|||
}
|
||||
}
|
||||
|
||||
quint32 crc = crc32( 0, reinterpret_cast<unsigned char *>( data.data() ), data.size() );
|
||||
QByteArray hash = QCryptographicHash::hash( data, KlipperHashAlhorithm ).toHex();
|
||||
QDataStream ds ( &history_file );
|
||||
ds << crc << data;
|
||||
ds << hash << data;
|
||||
}
|
||||
|
||||
// save session on shutdown. Don't simply use the c'tor, as that may not be called.
|
||||
|
|
Loading…
Add table
Reference in a new issue