Skip to content

Commit 0de0b1b

Browse files
bzzzilCaolán McNamara
authored andcommitted
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.Behrens@CIB.de> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> (cherry picked from commit dd4670b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104345 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
1 parent 5dda71e commit 0de0b1b

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

sfx2/source/doc/objstor.cxx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,11 +2787,38 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
27872787
// in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
27882788
// #i119366# - As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for setting password together, we need to clear them both.
27892789
// Also, ( maybe the new itemset contains new values, otherwise they will be empty )
2790-
if (xMergedParams->HasItem( SID_PASSWORD ))
2790+
if (xMergedParams->HasItem(SID_ENCRYPTIONDATA))
27912791
{
2792-
xMergedParams->ClearItem( SID_PASSWORD );
2793-
xMergedParams->ClearItem( SID_ENCRYPTIONDATA );
2792+
bool bPasswordProtected = true;
2793+
const SfxUnoAnyItem* pEncryptionDataItem
2794+
= xMergedParams->GetItem<SfxUnoAnyItem>(SID_ENCRYPTIONDATA, false);
2795+
if (pEncryptionDataItem)
2796+
{
2797+
uno::Sequence<beans::NamedValue> aEncryptionData;
2798+
pEncryptionDataItem->GetValue() >>= aEncryptionData;
2799+
for (const auto& rItem : std::as_const(aEncryptionData))
2800+
{
2801+
if (rItem.Name == "CryptoType")
2802+
{
2803+
OUString aValue;
2804+
rItem.Value >>= aValue;
2805+
if (aValue != "StrongEncryptionDataSpace")
2806+
{
2807+
// This is not just a password protected document. Let's keep encryption data as is.
2808+
bPasswordProtected = false;
2809+
}
2810+
break;
2811+
}
2812+
}
2813+
}
2814+
if (bPasswordProtected)
2815+
{
2816+
// For password protected documents remove encryption data during "Save as..."
2817+
xMergedParams->ClearItem(SID_PASSWORD);
2818+
xMergedParams->ClearItem(SID_ENCRYPTIONDATA);
2819+
}
27942820
}
2821+
27952822
xMergedParams->ClearItem( SID_DOCINFO_TITLE );
27962823

27972824
xMergedParams->ClearItem( SID_INPUTSTREAM );

0 commit comments

Comments
 (0)