Blame SOURCES/0002-Related-rhbz-1618703-Properly-handle-failure-encodin.patch

55db36
From 0df85fe6a19d90d73397f8006c62d61e96976817 Mon Sep 17 00:00:00 2001
55db36
From: Stephan Bergmann <sbergman@redhat.com>
55db36
Date: Thu, 23 Aug 2018 16:55:40 +0200
55db36
Subject: [PATCH 2/5] Related rhbz#1618703: Properly handle failure encoding
55db36
 zip file
55db36
MIME-Version: 1.0
55db36
Content-Type: text/plain; charset=UTF-8
55db36
Content-Transfer-Encoding: 8bit
55db36
55db36
...when e.g. FIPS mode makes ZipFile::StaticGetCipher fail by throwing an
55db36
exception which would be caught by ZipPackageStream::saveChild (in
55db36
package/source/zippackage/ZipPackageStream.cxx) alright (and translated into
55db36
bSuccess = false), if ZipFile::StaticGetCipher didn't unhelpfully swallow and
55db36
ignore all exceptions in an outer try-catch.
55db36
55db36
Change-Id: I14376128515df1dd4bdac921edd8ab94cc9b7617
55db36
Reviewed-on: https://gerrit.libreoffice.org/59514
55db36
Tested-by: Jenkins
55db36
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
55db36
(cherry picked from commit 3cc6d3611ac8cbbfb9803f3a084d02edde470ad3)
55db36
Reviewed-on: https://gerrit.libreoffice.org/59569
55db36
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
55db36
Tested-by: Caolán McNamara <caolanm@redhat.com>
55db36
(cherry picked from commit 2b5ff36afab8888cdbc879ae2f34903ede190c04)
55db36
---
55db36
 package/source/zipapi/ZipFile.cxx | 75 ++++++++++++++-----------------
55db36
 1 file changed, 34 insertions(+), 41 deletions(-)
55db36
55db36
diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx
55db36
index 1ef81bf582a5..8126ebba305b 100644
55db36
--- a/package/source/zipapi/ZipFile.cxx
55db36
+++ b/package/source/zipapi/ZipFile.cxx
55db36
@@ -162,54 +162,47 @@ uno::Reference< xml::crypto::XCipherContext > ZipFile::StaticGetCipher( const un
55db36
 {
55db36
     uno::Reference< xml::crypto::XCipherContext > xResult;
55db36
 
55db36
-    try
55db36
+    if (xEncryptionData->m_nDerivedKeySize < 0)
55db36
     {
55db36
-        if (xEncryptionData->m_nDerivedKeySize < 0)
55db36
-        {
55db36
-            throw ZipIOException("Invalid derived key length!" );
55db36
-        }
55db36
+        throw ZipIOException("Invalid derived key length!" );
55db36
+    }
55db36
 
55db36
-        uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize );
55db36
-        if ( !xEncryptionData->m_nIterationCount &&
55db36
-             xEncryptionData->m_nDerivedKeySize == xEncryptionData->m_aKey.getLength() )
55db36
-        {
55db36
-            // gpg4libre: no need to derive key, m_aKey is already
55db36
-            // usable as symmetric session key
55db36
-            aDerivedKey = xEncryptionData->m_aKey;
55db36
-        }
55db36
-        else if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ),
55db36
-                            aDerivedKey.getLength(),
55db36
-                            reinterpret_cast< const sal_uInt8 * > (xEncryptionData->m_aKey.getConstArray() ),
55db36
-                            xEncryptionData->m_aKey.getLength(),
55db36
-                            reinterpret_cast< const sal_uInt8 * > ( xEncryptionData->m_aSalt.getConstArray() ),
55db36
-                            xEncryptionData->m_aSalt.getLength(),
55db36
-                            xEncryptionData->m_nIterationCount ) )
55db36
-        {
55db36
-            throw ZipIOException("Can not create derived key!" );
55db36
-        }
55db36
+    uno::Sequence< sal_Int8 > aDerivedKey( xEncryptionData->m_nDerivedKeySize );
55db36
+    if ( !xEncryptionData->m_nIterationCount &&
55db36
+         xEncryptionData->m_nDerivedKeySize == xEncryptionData->m_aKey.getLength() )
55db36
+    {
55db36
+        // gpg4libre: no need to derive key, m_aKey is already
55db36
+        // usable as symmetric session key
55db36
+        aDerivedKey = xEncryptionData->m_aKey;
55db36
+    }
55db36
+    else if ( rtl_Digest_E_None != rtl_digest_PBKDF2( reinterpret_cast< sal_uInt8* >( aDerivedKey.getArray() ),
55db36
+                        aDerivedKey.getLength(),
55db36
+                        reinterpret_cast< const sal_uInt8 * > (xEncryptionData->m_aKey.getConstArray() ),
55db36
+                        xEncryptionData->m_aKey.getLength(),
55db36
+                        reinterpret_cast< const sal_uInt8 * > ( xEncryptionData->m_aSalt.getConstArray() ),
55db36
+                        xEncryptionData->m_aSalt.getLength(),
55db36
+                        xEncryptionData->m_nIterationCount ) )
55db36
+    {
55db36
+        throw ZipIOException("Can not create derived key!" );
55db36
+    }
55db36
 
55db36
-        if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING )
55db36
-        {
55db36
-            uno::Reference< uno::XComponentContext > xContext = xArgContext;
55db36
-            if ( !xContext.is() )
55db36
-                xContext = comphelper::getProcessComponentContext();
55db36
+    if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::AES_CBC_W3C_PADDING )
55db36
+    {
55db36
+        uno::Reference< uno::XComponentContext > xContext = xArgContext;
55db36
+        if ( !xContext.is() )
55db36
+            xContext = comphelper::getProcessComponentContext();
55db36
 
55db36
-            uno::Reference< xml::crypto::XNSSInitializer > xCipherContextSupplier = xml::crypto::NSSInitializer::create( xContext );
55db36
+        uno::Reference< xml::crypto::XNSSInitializer > xCipherContextSupplier = xml::crypto::NSSInitializer::create( xContext );
55db36
 
55db36
-            xResult = xCipherContextSupplier->getCipherContext( xEncryptionData->m_nEncAlg, aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt, uno::Sequence< beans::NamedValue >() );
55db36
-        }
55db36
-        else if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::BLOWFISH_CFB_8 )
55db36
-        {
55db36
-            xResult = BlowfishCFB8CipherContext::Create( aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt );
55db36
-        }
55db36
-        else
55db36
-        {
55db36
-            throw ZipIOException("Unknown cipher algorithm is requested!" );
55db36
-        }
55db36
+        xResult = xCipherContextSupplier->getCipherContext( xEncryptionData->m_nEncAlg, aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt, uno::Sequence< beans::NamedValue >() );
55db36
     }
55db36
-    catch( ... )
55db36
+    else if ( xEncryptionData->m_nEncAlg == xml::crypto::CipherID::BLOWFISH_CFB_8 )
55db36
+    {
55db36
+        xResult = BlowfishCFB8CipherContext::Create( aDerivedKey, xEncryptionData->m_aInitVector, bEncrypt );
55db36
+    }
55db36
+    else
55db36
     {
55db36
-        OSL_ENSURE( false, "Can not create cipher context!" );
55db36
+        throw ZipIOException("Unknown cipher algorithm is requested!" );
55db36
     }
55db36
 
55db36
     return xResult;
55db36
-- 
55db36
2.17.1
55db36