sfx2/source/doc/objstor.cxx |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

New commits:
commit 0de0b1b64a1c122254bb821ea0eb9b038875e8d4
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Sat Oct 17 10:00:04 2020 +0300
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sat Oct 17 20:57:54 2020 +0200

    tdf#133771: remove encryption data during SaveAs
    
    If document was password protected but during SaveAs it wasn't
    selected to use a password we should remove EcnryptionData.
    
    But we should not do this unconditionally: in general case we should
    try to keep all encryption metadata.
    
    Change-Id: Id91a88790deccd7377fb5d394b36395d13748c31
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104454
    Tested-by: Thorsten Behrens <thorsten.behr...@cib.de>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de>
    (cherry picked from commit dd4670b976b00d643f335516fe5fd0c880d58025)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104345
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 308ab1dfd0d4..fd405517265f 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2787,11 +2787,38 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& 
rFileName, const OUString&
     // in "SaveAs" title and password will be cleared ( maybe the new itemset 
contains new values, otherwise they will be empty )
     // #i119366# - As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for 
setting password together, we need to clear them both.
     // Also, ( maybe the new itemset contains new values, otherwise they will 
be empty )
-    if (xMergedParams->HasItem( SID_PASSWORD ))
+    if (xMergedParams->HasItem(SID_ENCRYPTIONDATA))
     {
-        xMergedParams->ClearItem( SID_PASSWORD );
-        xMergedParams->ClearItem( SID_ENCRYPTIONDATA );
+        bool bPasswordProtected = true;
+        const SfxUnoAnyItem* pEncryptionDataItem
+            = xMergedParams->GetItem<SfxUnoAnyItem>(SID_ENCRYPTIONDATA, false);
+        if (pEncryptionDataItem)
+        {
+            uno::Sequence<beans::NamedValue> aEncryptionData;
+            pEncryptionDataItem->GetValue() >>= aEncryptionData;
+            for (const auto& rItem : std::as_const(aEncryptionData))
+            {
+                if (rItem.Name == "CryptoType")
+                {
+                    OUString aValue;
+                    rItem.Value >>= aValue;
+                    if (aValue != "StrongEncryptionDataSpace")
+                    {
+                        // This is not just a password protected document. 
Let's keep encryption data as is.
+                        bPasswordProtected = false;
+                    }
+                    break;
+                }
+            }
+        }
+        if (bPasswordProtected)
+        {
+            // For password protected documents remove encryption data during 
"Save as..."
+            xMergedParams->ClearItem(SID_PASSWORD);
+            xMergedParams->ClearItem(SID_ENCRYPTIONDATA);
+        }
     }
+
     xMergedParams->ClearItem( SID_DOCINFO_TITLE );
 
     xMergedParams->ClearItem( SID_INPUTSTREAM );
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to