OSDN Git Service

okular: use QCryptographicHash for hashing
authorIvailo Monev <xakepa10@gmail.com>
Wed, 10 Mar 2021 22:37:42 +0000 (00:37 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Wed, 10 Mar 2021 23:41:14 +0000 (01:41 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
okular/generators/ooo/CMakeLists.txt
okular/generators/ooo/manifest.cpp

index 04c7f7e..8d76e08 100644 (file)
@@ -23,7 +23,13 @@ set(okularGenerator_ooo_PART_SRCS
 
 kde4_add_plugin(okularGenerator_ooo ${okularGenerator_ooo_PART_SRCS})
 
-target_link_libraries(okularGenerator_ooo okularcore ${KDE4_KIO_LIBS} ${MATH_LIB} ${QT_QTXML_LIBRARY})
+target_link_libraries(okularGenerator_ooo
+    ${KDE4_KIO_LIBS}
+    ${MATH_LIB}
+    ${QT_QTXML_LIBRARY}
+    ${QT_QTNETWORK_LIBRARY}
+    okularcore
+)
 if (QCA2_FOUND)
     target_link_libraries(okularGenerator_ooo okularcore ${QCA2_LIBRARIES})
 endif (QCA2_FOUND)
index 9a05498..b2e226b 100644 (file)
@@ -11,6 +11,7 @@
 #include "debug.h"
 
 #include <QBuffer>
+#include <QCryptographicHash>
 #include <qxmlstream.h>
 
 #include <KFilterDev>
@@ -232,10 +233,11 @@ bool Manifest::testIfEncrypted( const QString &filename )
 void Manifest::checkPassword( ManifestEntry *entry, const QByteArray &fileData, QByteArray *decryptedData )
 {
 #ifdef QCA2
-  QCA::SymmetricKey key = QCA::PBKDF2( "sha1" ).makeKey( QCA::Hash( "sha1" ).hash( m_password.toLocal8Bit() ),
-                                                        QCA::InitializationVector( entry->salt() ),
-                                                        16, //128 bit key
-                                                        entry->iterationCount() );
+  const QByteArray passhash = QCryptographicHash::hash(m_password.toLocal8Bit(), QCryptographicHash::Sha1 );
+  QCA::SymmetricKey key = QCA::PBKDF2( "sha1" ).makeKey( passhash,
+                                                         QCA::InitializationVector( entry->salt() ),
+                                                         16, //128 bit key
+                                                         entry->iterationCount() );
 
   QCA::Cipher decoder( "blowfish", QCA::Cipher::CFB, QCA::Cipher::DefaultPadding,
                       QCA::Decode, key, QCA::InitializationVector( entry->initialisationVector() ) );
@@ -244,9 +246,9 @@ void Manifest::checkPassword( ManifestEntry *entry, const QByteArray &fileData,
 
   QByteArray csum;
   if ( entry->checksumType() == "SHA1/1K" ) {
-    csum = QCA::Hash( "sha1").hash( decryptedData->left(1024) ).toByteArray();
+    csum = QCryptographicHash::hash( decryptedData->left(1024), QCryptographicHash::Sha1 );
   } else if ( entry->checksumType() == "SHA1" ) {
-    csum = QCA::Hash( "sha1").hash( *decryptedData ).toByteArray();
+    csum = QCryptographicHash::hash( *decryptedData, QCryptographicHash::Sha1 );
   } else {
     kDebug(OooDebug) << "unknown checksum type: " << entry->checksumType();
     // we can only assume it will be OK.
@@ -266,6 +268,8 @@ void Manifest::checkPassword( ManifestEntry *entry, const QByteArray &fileData,
 
 QByteArray Manifest::decryptFile( const QString &filename, const QByteArray &fileData )
 {
+  // TODO: SHA-256 checksum type support:
+  // http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part3.html#__RefHeading__752847_826425813
 #ifdef QCA2
   ManifestEntry *entry = entryByName( filename );