oox/qa/unit/CryptoTest.cxx |   51 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

New commits:
commit 89a4dff62ea9b571bbc37dad8e2e65846118994a
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Thu Apr 24 21:04:38 2025 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Apr 28 14:49:26 2025 +0200

    Related tdf#166241: add QA test in oox/qa/unit/CryptoTest.cxx for AES_192
    
    Change-Id: I283474a0a1bda243f7077b09376da2c2e6966949
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184593
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Tested-by: Jenkins

diff --git a/oox/qa/unit/CryptoTest.cxx b/oox/qa/unit/CryptoTest.cxx
index 88e71173a00d..dd3ff5c3fe12 100644
--- a/oox/qa/unit/CryptoTest.cxx
+++ b/oox/qa/unit/CryptoTest.cxx
@@ -155,6 +155,13 @@ void CryptoTest::testAgileEncryptionVerifier()
     CPPUNIT_ASSERT_EQUAL(false, 
aEngine.decryptAndCheckVerifierHash(u"Wrong"_ustr));
     CPPUNIT_ASSERT_EQUAL(true, aEngine.decryptAndCheckVerifierHash(aPassword));
 
+    aEngine.setupEncryptionParameters(
+        { 100000, 16, 192, 48, 16, u"AES"_ustr, u"ChainingModeCBC"_ustr, 
u"SHA384"_ustr });
+
+    CPPUNIT_ASSERT_EQUAL(true, 
aEngine.generateAndEncryptVerifierHash(aPassword));
+    CPPUNIT_ASSERT_EQUAL(false, 
aEngine.decryptAndCheckVerifierHash(u"Wrong"_ustr));
+    CPPUNIT_ASSERT_EQUAL(true, aEngine.decryptAndCheckVerifierHash(aPassword));
+
     aEngine.setupEncryptionParameters(
         { 100000, 16, 256, 64, 16, u"AES"_ustr, u"ChainingModeCBC"_ustr, 
u"SHA512"_ustr });
 
@@ -259,7 +266,51 @@ void CryptoTest::testAgileEncryptionInfoWritingAndParsing()
             CPPUNIT_ASSERT_EQUAL(true, 
aEngine.decryptAndCheckVerifierHash(aPassword));
         }
     }
+    { // Preset AES192 - SHA384
+        SvMemoryStream aEncryptionInfo;
+        {
+            oox::crypto::AgileEngine aEngine;
+
+            
aEngine.setPreset(oox::crypto::AgileEncryptionPreset::AES_192_SHA384);
+            aEngine.setupEncryption(aPassword);
+            aKeyDataSalt = aEngine.getInfo().keyDataSalt;
+
+            oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream(
+                new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), true);
+
+            aEngine.writeEncryptionInfo(aBinaryEncryptionInfoOutputStream);
+            aBinaryEncryptionInfoOutputStream.close();
+
+            CPPUNIT_ASSERT_EQUAL(sal_uInt64(1048), aEncryptionInfo.GetSize());
+        }
+
+        aEncryptionInfo.Seek(STREAM_SEEK_TO_BEGIN);
+
+        {
+            oox::crypto::AgileEngine aEngine;
+
+            uno::Reference<io::XInputStream> xInputStream(
+                new utl::OSeekableInputStreamWrapper(aEncryptionInfo));
+
+            xInputStream->skipBytes(4); // Encryption type -> Agile
+
+            CPPUNIT_ASSERT(aEngine.readEncryptionInfo(xInputStream));
 
+            oox::crypto::AgileEncryptionInfo& rInfo = aEngine.getInfo();
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(100000), rInfo.spinCount);
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rInfo.saltSize);
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(192), rInfo.keyBits);
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(48), rInfo.hashSize);
+            CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rInfo.blockSize);
+            CPPUNIT_ASSERT_EQUAL(u"AES"_ustr, rInfo.cipherAlgorithm);
+            CPPUNIT_ASSERT_EQUAL(u"ChainingModeCBC"_ustr, 
rInfo.cipherChaining);
+            CPPUNIT_ASSERT_EQUAL(u"SHA384"_ustr, rInfo.hashAlgorithm);
+            CPPUNIT_ASSERT_EQUAL(toString(aKeyDataSalt), 
toString(rInfo.keyDataSalt));
+
+            CPPUNIT_ASSERT_EQUAL(false, 
aEngine.decryptAndCheckVerifierHash(u"Wrong"_ustr));
+            CPPUNIT_ASSERT_EQUAL(true, 
aEngine.decryptAndCheckVerifierHash(aPassword));
+        }
+    }
     { // Preset AES256 - SHA512
         SvMemoryStream aEncryptionInfo;
         {
  • core.git: oox/qa Miklos Vajna (via logerrit)
    • core.git: oox/qa Julien Nabet (via logerrit)

Reply via email to