[Libreoffice-commits] core.git: Branch 'feature/cib_contract3756' - 213 commits - accessibility/source android/Bootstrap android/source avmedia/source basctl/source basic/inc basic/source bridges/source canvas/IwyuFilter_canvas.yaml canvas/source chart2/qa chart2/source chart2/uiconfig comphelper/source compilerplugins/clang configure.ac connectivity/Module_connectivity.mk connectivity/source cppu/source cui/source cui/uiconfig dbaccess/source desktop/qa desktop/source drawinglayer/source editeng/inc editeng/source embedserv/source extensions/source extensions/uiconfig filter/source fpicker/source framework/inc framework/source .gitreview helpcontent2 hwpfilter/source icon-themes/colibre icon-themes/colibre_svg icon-themes/karasa_jaga icon-themes/karasa_jaga_svg idl/source include/basegfx include/basic include/comphelper include/drawinglayer include/editeng include/filter include/o3tl include/oox include/sfx2 include/sot include/svl include/svtools include/svx include/toolkit include/typelib incl ude/vbahelper include/vcl include/xmloff libreofficekit/qa linguistic/inc linguistic/IwyuFilter_linguistic.yaml linguistic/source offapi/com offapi/UnoApi_offapi.mk officecfg/registry oox/source oox/util package/source postprocess/CustomTarget_registry.mk sc/CppunitTest_sc_parallelism.mk sc/inc sc/qa scripting/java scripting/Library_protocolhandler.mk scripting/source sc/source sdext/source sd/inc sd/qa sd/source sd/uiconfig sfx2/inc sfx2/IwyuFilter_sfx2.yaml sfx2/source sfx2/uiconfig solenv/bin solenv/clang-format solenv/flatpak-manifest.in soltools/cpp soltools/mkdepend svgio/source svl/qa svl/source svtools/source svx/qa svx/sdi svx/source svx/uiconfig sw/CppunitTest_sw_accessible_relation_set.mk sw/CppunitTest_sw_dialogs_test_2.mk sw/CppunitTest_sw_docbookexport.mk sw/CppunitTest_sw_fodfexport.mk sw/CppunitTest_sw_globalfilter.mk sw/CppunitTest_sw_htmlexport.mk sw/CppunitTest_sw_htmlimport.mk sw/CppunitTest_sw_layoutwriter.mk sw/CppunitTest_sw_mailmerge.mk sw/CppunitTest_sw_odfe xport.mk sw/CppunitTest_sw_odfimport.mk sw/CppunitTest_sw_ooxmlencryption.mk sw/CppunitTest_sw_ooxmlexport8.mk sw/CppunitTest_sw_ooxmlfieldexport.mk sw/CppunitTest_sw_ooxmlimport2.mk sw/CppunitTest_sw_ooxmlimport.mk sw/CppunitTest_sw_ooxmllinks.mk sw/CppunitTest_sw_ooxmlw14export.mk sw/CppunitTest_sw_rtfexport2.mk sw/CppunitTest_sw_rtfexport3.mk sw/CppunitTest_sw_rtfexport4.mk sw/CppunitTest_sw_rtfexport5.mk sw/CppunitTest_sw_rtfexport.mk sw/CppunitTest_sw_rtfimport.mk sw/CppunitTest_sw_tiledrendering.mk sw/CppunitTest_sw_txtexport.mk sw/CppunitTest_sw_uiwriter.mk sw/CppunitTest_sw_unowriter.mk sw/CppunitTest_sw_ww8export2.mk sw/CppunitTest_sw_ww8export3.mk sw/CppunitTest_sw_ww8export.mk sw/CppunitTest_sw_ww8import.mk sw/CppunitTest_sw_xhtmlexport.mk sw/inc sw/IwyuFilter_sw.yaml sw/ooxmlexport_setup.mk sw/qa sw/sdi sw/source sw/uiconfig toolkit/inc toolkit/source translations uitest/writer_tests unotools/source uui/source vbahelper/source vcl/CppunitTest_vcl_pdfexport.mk vcl/headles s vcl/inc vcl/Library_vcl.mk vcl/opengl vcl/qa vcl/README.vars vcl/source vcl/unx vcl/workben writerfilter/source xmloff/source xmlsecurity/inc

Serge Krot (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 8 22:27:05 UTC 2019


Rebased ref, commits from common ancestor:
commit 6afefb6bb8d7a5593a18325df58e47f7ba076777
Author:     Serge Krot <Serge.Krot at cib.de>
AuthorDate: Fri Nov 8 21:14:28 2019 +0100
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:10 2019 +0100

    Source code clean up: do not clean up EncryptionData during SaveAs
    
    Change-Id: I1213ec55d6dc42f062930467976de45c73152f0b
    Reviewed-on: https://gerrit.libreoffice.org/82326
    Reviewed-by: Serge Krot (CIB) <Serge.Krot at cib.de>
    Tested-by: Serge Krot (CIB) <Serge.Krot at cib.de>

diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index cf8df0b417cc..63178c7fec24 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -1748,27 +1748,9 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const
         // this property is only necessary to support raw passwords in storage API;
         // because of this support the storage has to operate with more than one key dependent on storage generation algorithm;
         // when this support is removed, the storage will get only one key from outside
-        uno::Sequence< beans::NamedValue > aKeys;
-        if ( !( aValue >>= aKeys ) )
+        if ( !( aValue >>= m_aStorageEncryptionKeys ) )
             throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
 
-/*        if ( aKeys.hasElements() )
-        {
-            bool bHasSHA256 = false;
-            bool bHasSHA1 = false;
-            for ( const auto& rKey : std::as_const(aKeys) )
-            {
-                if ( rKey.Name == PACKAGE_ENCRYPTIONDATA_SHA256UTF8 )
-                    bHasSHA256 = true;
-                if ( rKey.Name == PACKAGE_ENCRYPTIONDATA_SHA1UTF8 )
-                    bHasSHA1 = true;
-            }
-
-            if ( !bHasSHA256 && !bHasSHA1 )
-                throw IllegalArgumentException(THROW_WHERE "Expected keys are not provided!", uno::Reference< uno::XInterface >(), 2 );
-        }*/
-
-        m_aStorageEncryptionKeys = aKeys;
         m_aEncryptionKey.realloc( 0 );
     }
     else if ( aPropertyName == ENCRYPTION_ALGORITHMS_PROPERTY )
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index 545f520a7a1d..27e4284b258c 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1414,8 +1414,13 @@ ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList,
 
         // the password will be set in case user decide so
         rpSet->ClearItem( SID_PASSWORDINTERACTION );
-        rpSet->ClearItem( SID_PASSWORD );
-        //rpSet->ClearItem( SID_ENCRYPTIONDATA );
+        if (rpSet->HasItem( SID_PASSWORD ))
+        {
+            // As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for setting password together, we need to clear them both.
+            // Note: Do not remove SID_ENCRYPTIONDATA without SID_PASSWORD
+            rpSet->ClearItem( SID_PASSWORD );
+            rpSet->ClearItem( SID_ENCRYPTIONDATA );
+        }
         rpSet->ClearItem( SID_RECOMMENDREADONLY );
         rpSet->ClearItem( SID_MODIFYPASSWORDINFO );
 
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 9e386d8c5964..512fe81d6efd 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -809,22 +809,9 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                 }
 
 
-                bool bPreselectPassword = false;
                 const SfxStringItem* pOldPasswordItem = SfxItemSet::GetItem<SfxStringItem>(GetMedium()->GetItemSet(), SID_PASSWORD, false);
-                if (pOldPasswordItem)
-                {
-                    bPreselectPassword = true;
-                }
-                else
-                {
-                    const SfxUnoAnyItem* pOldEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(GetMedium()->GetItemSet(), SID_ENCRYPTIONDATA, false);
-                    if (pOldEncryptionDataItem)
-                    {
-                        uno::Sequence< beans::NamedValue > aEncryptionData;
-                        pOldEncryptionDataItem->GetValue() >>= aEncryptionData;
-
-                    }
-                }
+                const SfxUnoAnyItem* pOldEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(GetMedium()->GetItemSet(), SID_ENCRYPTIONDATA, false);
+                bool bPreselectPassword = (pOldPasswordItem && pOldEncryptionDataItem);
 
                 uno::Sequence< beans::PropertyValue > aDispatchArgs;
                 if ( rReq.GetArgs() )
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index ae58f9a88e97..174b06c761f3 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2764,11 +2764,13 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
     std::unique_ptr<SfxAllItemSet> pMergedParams(new SfxAllItemSet( *pMedium->GetItemSet() ));
 
     // in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
-    //pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
-    pMergedParams->ClearItem( SID_PASSWORD );
     // #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 )
-//    pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
+    if (pMergedParams->HasItem( SID_PASSWORD ))
+    {
+        pMergedParams->ClearItem( SID_PASSWORD );
+        pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
+    }
     pMergedParams->ClearItem( SID_DOCINFO_TITLE );
 
     pMergedParams->ClearItem( SID_INPUTSTREAM );
commit c43ac5c684ed19238e219b151492c87e3edae62d
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Nov 8 21:17:10 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:10 2019 +0100

    sd: support for DRM encryption during saving to ppt
    
    Change-Id: Id82f8b3fa7ea045b00d7d81e2c9ce5e130c8060c

diff --git a/sd/source/filter/sdpptwrp.cxx b/sd/source/filter/sdpptwrp.cxx
index bb42b9d4bc11..cc418fd7fc5a 100644
--- a/sd/source/filter/sdpptwrp.cxx
+++ b/sd/source/filter/sdpptwrp.cxx
@@ -219,8 +219,6 @@ bool SdPPTFilter::Export()
 
     if( mxModel.is() )
     {
-        tools::SvRef<SotStorage> xStorRef = new SotStorage( mrMedium.GetOutStream(), false );
-
 #ifdef DISABLE_DYNLOADING
         ExportPPTPointer PPTExport = ExportPPT;
 #else
@@ -228,7 +226,7 @@ bool SdPPTFilter::Export()
             SdFilter::GetLibrarySymbol(mrMedium.GetFilter()->GetUserData(), "ExportPPT"));
 #endif
 
-        if( PPTExport && xStorRef.is() )
+        if( PPTExport)
         {
             sal_uInt32          nCnvrtFlags = 0;
             const SvtFilterOptions& rFilterOptions = SvtFilterOptions::Get();
@@ -252,8 +250,105 @@ bool SdPPTFilter::Export()
             aProperty.Value <<= mrMedium.GetBaseURL( true );
             aProperties.push_back( aProperty );
 
-            bRet = PPTExport( aProperties, xStorRef, mxModel, mxStatusIndicator, pBas, nCnvrtFlags );
-            xStorRef->Commit();
+            SvStream * pOutputStrm = mrMedium.GetOutStream();
+
+            Sequence< NamedValue > aEncryptionData;
+            Reference< css::packages::XPackageEncryption > xPackageEncryption;
+            const SfxUnoAnyItem* pEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(mrMedium.GetItemSet(), SID_ENCRYPTIONDATA, false);
+            std::shared_ptr<SvStream> pMediaStrm;
+            if (pEncryptionDataItem && (pEncryptionDataItem->GetValue() >>= aEncryptionData))
+            {
+                ::comphelper::SequenceAsHashMap aHashData(aEncryptionData);
+                OUString sCryptoType = aHashData.getUnpackedValueOrDefault("CryptoType", OUString());
+
+                if (sCryptoType.getLength())
+                {
+                    Reference<XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+                    Sequence<Any> aArguments;
+                    xPackageEncryption.set(
+                        xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+                            "com.sun.star.comp.oox.crypto." + sCryptoType, aArguments, xComponentContext), UNO_QUERY);
+
+                    if (xPackageEncryption.is())
+                    {
+                        // We have an encryptor. Export document into memory stream and encrypt it later
+                        pMediaStrm.reset(new SvMemoryStream());
+                        pOutputStrm = pMediaStrm.get();
+
+                        // Temp removal of EncryptionData to avoid password protection triggering
+                        mrMedium.GetItemSet()->ClearItem(SID_ENCRYPTIONDATA);
+                    }
+                }
+            }
+
+            tools::SvRef<SotStorage> xStorRef = new SotStorage(pOutputStrm, false);
+
+            if (xStorRef.is())
+            {
+                bRet = PPTExport(aProperties, xStorRef, mxModel, mxStatusIndicator, pBas, nCnvrtFlags);
+                xStorRef->Commit();
+
+                if (xPackageEncryption.is())
+                {
+                    // Perform DRM encryption
+                    pOutputStrm->Seek(0);
+
+                    xPackageEncryption->setupEncryption(aEncryptionData);
+
+                    Reference<css::io::XInputStream > xInputStream(new utl::OSeekableInputStreamWrapper(pOutputStrm, false));
+                    Sequence<NamedValue> aStreams = xPackageEncryption->encrypt(xInputStream);
+
+                    tools::SvRef<SotStorage> xEncryptedRootStrg = new SotStorage(mrMedium.GetOutStream(), false);
+                    for (const NamedValue & aStreamData : aStreams)
+                    {
+                        // To avoid long paths split and open substorages recursively
+                        // Splitting paths manually, since comphelper::string::split is trimming special characters like \0x01, \0x09
+                        SotStorage * pStorage = xEncryptedRootStrg.get();
+                        OUString sFileName;
+                        sal_Int32 idx = 0;
+                        do
+                        {
+                            OUString sPathElem = aStreamData.Name.getToken(0, L'/', idx);
+                            if (!sPathElem.isEmpty())
+                            {
+                                if (idx < 0)
+                                {
+                                    sFileName = sPathElem;
+                                }
+                                else
+                                {
+                                    pStorage = pStorage->OpenSotStorage(sPathElem);
+                                }
+                            }
+                        } while (pStorage && idx >= 0);
+
+                        if (!pStorage)
+                        {
+                            bRet = false;
+                            break;
+                        }
+
+                        SotStorageStream* pStream = pStorage->OpenSotStream(sFileName);
+                        if (!pStream)
+                        {
+                            bRet = false;
+                            break;
+                        }
+                        Sequence<sal_Int8> aStreamContent;
+                        aStreamData.Value >>= aStreamContent;
+                        size_t nBytesWritten = pStream->WriteBytes(aStreamContent.getArray(), aStreamContent.getLength());
+                        if (nBytesWritten != aStreamContent.getLength())
+                        {
+                            bRet = false;
+                            break;
+                        }
+                    }
+                    xEncryptedRootStrg->Commit();
+
+                    // Restore encryption data
+                    mrMedium.GetItemSet()->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, makeAny(aEncryptionData)));
+                }
+            }
         }
     }
 
commit 909bb83a28c1ddb2e49022d920a72529d4560997
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Nov 8 21:00:12 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:10 2019 +0100

    sd: support of DRM encrypted ppt files reading
    
    Change-Id: Ib91538d53ee1f53a3cd14a44d47fd6f6136c0472

diff --git a/sd/source/filter/sdpptwrp.cxx b/sd/source/filter/sdpptwrp.cxx
index edc21c482d45..bb42b9d4bc11 100644
--- a/sd/source/filter/sdpptwrp.cxx
+++ b/sd/source/filter/sdpptwrp.cxx
@@ -23,6 +23,10 @@
 #include <svx/svxerr.hxx>
 #include <unotools/fltrcfg.hxx>
 #include <sot/storage.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+
+#include <com/sun/star/packages/XPackageEncryption.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
 
 #include <sdpptwrp.hxx>
 #include <DrawDocShell.hxx>
@@ -67,9 +71,101 @@ SdPPTFilter::~SdPPTFilter()
     delete pBas;    // deleting the compressed basic storage
 }
 
+static void lcl_getListOfStreams(SotStorage * pStorage, comphelper::SequenceAsHashMap& aStreamsData, const OUString& sPrefix)
+{
+    SvStorageInfoList aElements;
+    pStorage->FillInfoList(&aElements);
+    for (const auto & aElement : aElements)
+    {
+        OUString sStreamFullName = sPrefix.getLength() ? sPrefix + "/" + aElement.GetName() : aElement.GetName();
+        if (aElement.IsStorage())
+        {
+            SotStorage * pSubStorage = pStorage->OpenSotStorage(aElement.GetName(), StreamMode::STD_READ | StreamMode::SHARE_DENYALL);
+            lcl_getListOfStreams(pSubStorage, aStreamsData, sStreamFullName);
+        }
+        else
+        {
+            // Read stream
+            tools::SvRef<SotStorageStream> rStream = pStorage->OpenSotStream(aElement.GetName(), StreamMode::READ | StreamMode::SHARE_DENYALL);
+            assert(rStream.is());
+
+            sal_Int32 nStreamSize = rStream->GetSize();
+            Sequence< sal_Int8 > oData;
+            oData.realloc(nStreamSize);
+            sal_Int32 nReadBytes = rStream->ReadBytes(oData.getArray(), nStreamSize);
+            assert(nStreamSize == nReadBytes);
+            aStreamsData[sStreamFullName] <<= oData;
+        }
+    }
+}
+
+static tools::SvRef<SotStorage> lcl_DRMDecrypt(SfxMedium& rMedium, tools::SvRef<SotStorage>& rStorage, std::shared_ptr<SvStream>& rNewStorageStrm)
+{
+    tools::SvRef<SotStorage> aNewStorage;
+
+    // We have DRM encrypted storage. We should try to decrypt it first, if we can
+    Sequence< Any > aArguments;
+    Reference<XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+    Reference< css::packages::XPackageEncryption > xPackageEncryption(
+        xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+            "com.sun.star.comp.oox.crypto.DRMDataSpace", aArguments, xComponentContext), UNO_QUERY);
+
+    if (!xPackageEncryption.is())
+    {
+        // We do not know how to decrypt this
+        return aNewStorage;
+    }
+
+    std::vector<OUString> aStreamsList;
+    comphelper::SequenceAsHashMap aStreamsData;
+    lcl_getListOfStreams(rStorage.get(), aStreamsData, OUString(""));
+
+    try {
+        Sequence<NamedValue> aStreams = aStreamsData.getAsConstNamedValueList();
+        if (!xPackageEncryption->readEncryptionInfo(aStreams))
+        {
+            // We failed with decryption
+            return aNewStorage;
+        }
+
+        tools::SvRef<SotStorageStream> rContentStream = rStorage->OpenSotStream("\011DRMContent", StreamMode::READ | StreamMode::SHARE_DENYALL);
+        if (!rContentStream.is())
+        {
+            return aNewStorage;
+        }
+
+        rNewStorageStrm.reset(new SvMemoryStream());
+
+        Reference<css::io::XInputStream > xInputStream(new utl::OSeekableInputStreamWrapper(rContentStream.get(), false));
+        Reference<css::io::XOutputStream > xDecryptedStream(new utl::OSeekableOutputStreamWrapper(*rNewStorageStrm.get()));
+
+        if (!xPackageEncryption->decrypt(xInputStream, xDecryptedStream))
+        {
+            // We failed with decryption
+            return aNewStorage;
+        }
+
+        rNewStorageStrm->Seek(0);
+
+        // Further reading is done from new document
+        aNewStorage = new SotStorage(*rNewStorageStrm);
+
+        // Set the media descriptor data
+        Sequence<NamedValue> aEncryptionData = xPackageEncryption->createEncryptionData("");
+        rMedium.GetItemSet()->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, makeAny(aEncryptionData)));
+    }
+    catch (const std::exception&)
+    {
+        return aNewStorage;
+    }
+
+    return aNewStorage;
+}
+
 bool SdPPTFilter::Import()
 {
     bool bRet = false;
+    std::shared_ptr<SvStream> aDecryptedStorageStrm;
     tools::SvRef<SotStorage> pStorage = new SotStorage( mrMedium.GetInStream(), false );
     if( !pStorage->GetError() )
     {
@@ -82,6 +178,12 @@ bool SdPPTFilter::Import()
             xDualStorage = pStorage->OpenSotStorage( sDualStorage, StreamMode::STD_READ );
             pStorage = xDualStorage;
         }
+        OUString sDRMContent("\011DRMContent");
+        if (pStorage->IsContained(sDRMContent))
+        {
+            // Document is DRM encrypted
+            pStorage = lcl_DRMDecrypt(mrMedium, pStorage, aDecryptedStorageStrm);
+        }
         std::unique_ptr<SvStream> pDocStream(pStorage->OpenSotStream( "PowerPoint Document" , StreamMode::STD_READ ));
         if( pDocStream )
         {
commit 5bc628aa01bfd25dc1fe3e1ceaf29c4531ab0b42
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Nov 8 18:28:41 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:10 2019 +0100

    calc: support for writing DRM encrypted xls files
    
    Change-Id: I5faf885cf494becca2838c6493413bcc56e91826

diff --git a/sc/source/filter/excel/excel.cxx b/sc/source/filter/excel/excel.cxx
index 56adce29a061..2e4015e34569 100644
--- a/sc/source/filter/excel/excel.cxx
+++ b/sc/source/filter/excel/excel.cxx
@@ -24,7 +24,7 @@
 #include <sot/exchange.hxx>
 #include <filter/msfilter/classids.hxx>
 #include <tools/globname.hxx>
-#include <com/sun/star/packages/XPAckageEncryption.hpp>
+#include <com/sun/star/packages/XPackageEncryption.hpp>
 #include <com/sun/star/ucb/ContentCreationException.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <unotools/streamwrap.hxx>
@@ -248,6 +248,36 @@ ErrCode ScFormatFilterPluginImpl::ScImportExcel( SfxMedium& rMedium, ScDocument*
 static ErrCode lcl_ExportExcelBiff( SfxMedium& rMedium, ScDocument *pDocument,
         SvStream* pMedStrm, bool bBiff8, rtl_TextEncoding eNach )
 {
+    uno::Reference< packages::XPackageEncryption > xPackageEncryption;
+    uno::Sequence< beans::NamedValue > aEncryptionData;
+    const SfxUnoAnyItem* pEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(rMedium.GetItemSet(), SID_ENCRYPTIONDATA, false);
+    SvStream* pOriginalMediaStrm = pMedStrm;
+    std::shared_ptr<SvStream> pMediaStrm;
+    if (pEncryptionDataItem && (pEncryptionDataItem->GetValue() >>= aEncryptionData))
+    {
+        ::comphelper::SequenceAsHashMap aHashData(aEncryptionData);
+        OUString sCryptoType = aHashData.getUnpackedValueOrDefault("CryptoType", OUString());
+
+        if (sCryptoType.getLength())
+        {
+            uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+            uno::Sequence<uno::Any> aArguments;
+            xPackageEncryption.set(
+                xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+                    "com.sun.star.comp.oox.crypto." + sCryptoType, aArguments, xComponentContext), uno::UNO_QUERY);
+
+            if (xPackageEncryption.is())
+            {
+                // We have an encryptor. Export document into memory stream and encrypt it later
+                pMediaStrm.reset(new SvMemoryStream());
+                pMedStrm = pMediaStrm.get();
+
+                // Temp removal of EncryptionData to avoid password protection triggering
+                rMedium.GetItemSet()->ClearItem(SID_ENCRYPTIONDATA);
+            }
+        }
+    }
+
     // try to open an OLE storage
     tools::SvRef<SotStorage> xRootStrg = new SotStorage( pMedStrm, false );
     if( xRootStrg->GetError() ) return SCERR_IMPORT_OPEN;
@@ -296,6 +326,67 @@ static ErrCode lcl_ExportExcelBiff( SfxMedium& rMedium, ScDocument *pDocument,
     xStrgStrm->Commit();
     xRootStrg->Commit();
 
+    if (xPackageEncryption.is())
+    {
+        // Perform DRM encryption
+        pMedStrm->Seek(0);
+
+        xPackageEncryption->setupEncryption(aEncryptionData);
+
+        uno::Reference<io::XInputStream > xInputStream(new utl::OSeekableInputStreamWrapper(pMedStrm, false));
+        uno::Sequence<beans::NamedValue> aStreams = xPackageEncryption->encrypt(xInputStream);
+
+        tools::SvRef<SotStorage> xEncryptedRootStrg = new SotStorage(pOriginalMediaStrm, false);
+        for (const beans::NamedValue & aStreamData : aStreams)
+        {
+            // To avoid long paths split and open substorages recursively
+            // Splitting paths manually, since comphelper::string::split is trimming special characters like \0x01, \0x09
+            SotStorage * pStorage = xEncryptedRootStrg.get();
+            OUString sFileName;
+            sal_Int32 idx = 0;
+            do
+            {
+                OUString sPathElem = aStreamData.Name.getToken(0, L'/', idx);
+                if (!sPathElem.isEmpty())
+                {
+                    if (idx < 0)
+                    {
+                        sFileName = sPathElem;
+                    }
+                    else
+                    {
+                        pStorage = pStorage->OpenSotStorage(sPathElem);
+                    }
+                }
+            } while (pStorage && idx >= 0);
+
+            if (!pStorage)
+            {
+                eRet = ERRCODE_IO_GENERAL;
+                break;
+            }
+
+            SotStorageStream* pStream = pStorage->OpenSotStream(sFileName);
+            if (!pStream)
+            {
+                eRet = ERRCODE_IO_GENERAL;
+                break;
+            }
+            uno::Sequence<sal_Int8> aStreamContent;
+            aStreamData.Value >>= aStreamContent;
+            size_t nBytesWritten = pStream->WriteBytes(aStreamContent.getArray(), aStreamContent.getLength());
+            if (nBytesWritten != aStreamContent.getLength())
+            {
+                eRet = ERRCODE_IO_CANTWRITE;
+                break;
+            }
+        }
+        xEncryptedRootStrg->Commit();
+
+        // Restore encryption data
+        rMedium.GetItemSet()->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, uno::makeAny(aEncryptionData)));
+    }
+
     return eRet;
 }
 
commit 6ec44618b85c648364d306222760c325b940d366
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Nov 8 17:53:30 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:10 2019 +0100

    calc: support for reading DRM encrypted xls files
    
    DRM encryption is implemented as an optional service, so
    just use it when available.
    
    Change-Id: Ie580e5c12c48ccf99f9a932b1c66eb35866b7ef4

diff --git a/sc/source/filter/excel/excel.cxx b/sc/source/filter/excel/excel.cxx
index ca87efc2988c..56adce29a061 100644
--- a/sc/source/filter/excel/excel.cxx
+++ b/sc/source/filter/excel/excel.cxx
@@ -24,7 +24,9 @@
 #include <sot/exchange.hxx>
 #include <filter/msfilter/classids.hxx>
 #include <tools/globname.hxx>
+#include <com/sun/star/packages/XPAckageEncryption.hpp>
 #include <com/sun/star/ucb/ContentCreationException.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
 #include <unotools/streamwrap.hxx>
 #include <osl/diagnose.h>
 #include <filter.hxx>
@@ -32,6 +34,8 @@
 #include <xistream.hxx>
 #include <xltools.hxx>
 #include <docoptio.hxx>
+#include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/processfactory.hxx>
 
 #include <docsh.hxx>
 #include <scerrors.hxx>
@@ -42,6 +46,99 @@
 
 #include <memory>
 
+using namespace css;
+
+static void lcl_getListOfStreams(SotStorage * pStorage, comphelper::SequenceAsHashMap& aStreamsData, const OUString& sPrefix)
+{
+    SvStorageInfoList aElements;
+    pStorage->FillInfoList(&aElements);
+    for (const auto & aElement : aElements)
+    {
+        OUString sStreamFullName = sPrefix.getLength() ? sPrefix + "/" + aElement.GetName() : aElement.GetName();
+        if (aElement.IsStorage())
+        {
+            SotStorage * pSubStorage = pStorage->OpenSotStorage(aElement.GetName(), StreamMode::STD_READ | StreamMode::SHARE_DENYALL);
+            lcl_getListOfStreams(pSubStorage, aStreamsData, sStreamFullName);
+        }
+        else
+        {
+            // Read stream
+            tools::SvRef<SotStorageStream> rStream = pStorage->OpenSotStream(aElement.GetName(), StreamMode::READ | StreamMode::SHARE_DENYALL);
+            assert(rStream.is());
+
+            sal_Int32 nStreamSize = rStream->GetSize();
+            uno::Sequence< sal_Int8 > oData;
+            oData.realloc(nStreamSize);
+            sal_Int32 nReadBytes = rStream->ReadBytes(oData.getArray(), nStreamSize);
+            assert(nStreamSize == nReadBytes);
+            aStreamsData[sStreamFullName] <<= oData;
+        }
+    }
+}
+
+static tools::SvRef<SotStorage> lcl_DRMDecrypt(SfxMedium& rMedium, tools::SvRef<SotStorage>& rStorage, std::shared_ptr<SvStream>& rNewStorageStrm)
+{
+    tools::SvRef<SotStorage> aNewStorage;
+
+    // We have DRM encrypted storage. We should try to decrypt it first, if we can
+    uno::Sequence< uno::Any > aArguments;
+    uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+    uno::Reference< packages::XPackageEncryption > xPackageEncryption(
+        xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+            "com.sun.star.comp.oox.crypto.DRMDataSpace", aArguments, xComponentContext), uno::UNO_QUERY);
+
+    if (!xPackageEncryption.is())
+    {
+        // We do not know how to decrypt this
+        return aNewStorage;
+    }
+
+    std::vector<OUString> aStreamsList;
+    comphelper::SequenceAsHashMap aStreamsData;
+    lcl_getListOfStreams(rStorage.get(), aStreamsData, OUString(""));
+
+    try {
+        uno::Sequence<beans::NamedValue> aStreams = aStreamsData.getAsConstNamedValueList();
+        if (!xPackageEncryption->readEncryptionInfo(aStreams))
+        {
+            // We failed with decryption
+            return aNewStorage;
+        }
+
+        tools::SvRef<SotStorageStream> rContentStream = rStorage->OpenSotStream("\011DRMContent", StreamMode::READ | StreamMode::SHARE_DENYALL);
+        if (!rContentStream.is())
+        {
+            return aNewStorage;
+        }
+
+        rNewStorageStrm.reset(new SvMemoryStream());
+
+        uno::Reference<io::XInputStream > xInputStream(new utl::OSeekableInputStreamWrapper(rContentStream.get(), false));
+        uno::Reference<io::XOutputStream > xDecryptedStream(new utl::OSeekableOutputStreamWrapper(*rNewStorageStrm.get()));
+
+        if (!xPackageEncryption->decrypt(xInputStream, xDecryptedStream))
+        {
+            // We failed with decryption
+            return aNewStorage;
+        }
+
+        rNewStorageStrm->Seek(0);
+
+        // Further reading is done from new document
+        aNewStorage = new SotStorage(*rNewStorageStrm);
+
+        // Set the media descriptor data
+        uno::Sequence<beans::NamedValue> aEncryptionData = xPackageEncryption->createEncryptionData("");
+        rMedium.GetItemSet()->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, uno::makeAny(aEncryptionData)));
+    }
+    catch (const std::exception&)
+    {
+        return aNewStorage;
+    }
+
+    return aNewStorage;
+}
+
 ErrCode ScFormatFilterPluginImpl::ScImportExcel( SfxMedium& rMedium, ScDocument* pDocument, const EXCIMPFORMAT eFormat )
 {
     // check the passed Calc document
@@ -67,6 +164,7 @@ ErrCode ScFormatFilterPluginImpl::ScImportExcel( SfxMedium& rMedium, ScDocument*
     // try to open an OLE storage
     tools::SvRef<SotStorage> xRootStrg;
     tools::SvRef<SotStorageStream> xStrgStrm;
+    std::shared_ptr<SvStream> aNewStorageStrm;
     if( SotStorage::IsStorageFile( pMedStrm ) )
     {
         xRootStrg = new SotStorage( pMedStrm, false );
@@ -77,6 +175,13 @@ ErrCode ScFormatFilterPluginImpl::ScImportExcel( SfxMedium& rMedium, ScDocument*
     // try to open "Book" or "Workbook" stream in OLE storage
     if( xRootStrg.is() )
     {
+        // Check if there is DRM encryption in storage
+        tools::SvRef<SotStorageStream> xDRMStrm = ScfTools::OpenStorageStreamRead(xRootStrg, "\011DRMContent");
+        if (xDRMStrm.is())
+        {
+            xRootStrg = lcl_DRMDecrypt(rMedium, xRootStrg, aNewStorageStrm);
+        }
+
         // try to open the "Book" stream
         tools::SvRef<SotStorageStream> xBookStrm = ScfTools::OpenStorageStreamRead( xRootStrg, EXC_STREAM_BOOK );
         XclBiff eBookBiff = xBookStrm.is() ?  XclImpStream::DetectBiffVersion( *xBookStrm ) : EXC_BIFF_UNKNOWN;
commit bb5c37452e3484669783cbb0960f151c2cf8c0f7
Author:     Serge Krot <Serge.Krot at cib.de>
AuthorDate: Fri Nov 8 17:31:49 2019 +0100
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:10 2019 +0100

    Switch to read-only mode: do not force reload document if possible
    
    Change-Id: I5f83e7626e58cb4b558b54130b725b1041b7142f
    Reviewed-on: https://gerrit.libreoffice.org/82313
    Reviewed-by: Serge Krot (CIB) <Serge.Krot at cib.de>
    Tested-by: Serge Krot (CIB) <Serge.Krot at cib.de>

diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
old mode 100644
new mode 100755
index fafe5df417dc..e3f39e3aab40
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -459,6 +459,8 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
                  || pVersionItem )
             // <- tdf#82744
             {
+                bNeedsReload = true;
+
                 bool bOK = false;
                 bool bRetryIgnoringLock = false;
                 bool bOpenTemplate = false;
@@ -601,7 +603,7 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
                 }
             }
 
-            rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, true) );
+            rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, bNeedsReload) );
             rReq.AppendItem( SfxBoolItem( SID_SILENT, true ));
 
             [[fallthrough]]; //TODO ???
commit ff1ab5462906f8b664d7de267e694a806f45b639
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Thu Nov 7 11:13:49 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:09 2019 +0100

    ms doc: support for saving into binary doc with custom encryption
    
    if we have custome encryption data in media descriptor EncryptionData
    and corresponding service is available it will be used durng saving.
    
    Change-Id: I814e4a7f73979ff7a65831b99f77f1a9e85916de

diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index e908cab35162..5a9ea326b379 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -22,6 +22,8 @@
 
 #include <com/sun/star/embed/ElementModes.hpp>
 #include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/packages/XPackageEncryption.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
 #include <unotools/ucbstreamhelper.hxx>
 #include <algorithm>
 #include <map>
@@ -94,6 +96,7 @@
 #include "sprmids.hxx"
 
 #include <comphelper/sequenceashashmap.hxx>
+#include <comphelper/string.hxx>
 #include "writerhelper.hxx"
 #include "writerwordglue.hxx"
 #include "ww8attributeoutput.hxx"
@@ -3608,6 +3611,105 @@ void WW8Export::PrepareStorage()
 
 ErrCode SwWW8Writer::WriteStorage()
 {
+    tools::SvRef<SotStorage> pOrigStg;
+    uno::Reference< packages::XPackageEncryption > xPackageEncryption;
+    std::shared_ptr<SvStream> pSotStorageStream;
+    uno::Sequence< beans::NamedValue > aEncryptionData;
+    if (mpMedium)
+    {
+        // Check for specific encryption requests
+        const SfxUnoAnyItem* pEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(mpMedium->GetItemSet(), SID_ENCRYPTIONDATA, false);
+        if (pEncryptionDataItem && (pEncryptionDataItem->GetValue() >>= aEncryptionData))
+        {
+            ::comphelper::SequenceAsHashMap aHashData(aEncryptionData);
+            OUString sCryptoType = aHashData.getUnpackedValueOrDefault("CryptoType", OUString());
+
+            if (sCryptoType.getLength())
+            {
+                uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+                uno::Sequence<uno::Any> aArguments;
+                xPackageEncryption.set(
+                    xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+                        "com.sun.star.comp.oox.crypto." + sCryptoType, aArguments, xComponentContext), uno::UNO_QUERY);
+
+                if (xPackageEncryption.is())
+                {
+                    // We have an encryptor
+                    // Create new temporary storage for content
+                    pOrigStg = pStg;
+                    pSotStorageStream.reset(new SvMemoryStream());
+                    pStg = new SotStorage(*pSotStorageStream);
+                }
+            }
+        }
+    }
+
+    ErrCode nErrorCode = WriteStorageImpl();
+
+    if (xPackageEncryption.is())
+    {
+        pStg->Commit();
+        pSotStorageStream->Seek(0);
+
+        // Encrypt data written into temporary storage
+        xPackageEncryption->setupEncryption(aEncryptionData);
+
+        uno::Reference<io::XInputStream > xInputStream(new utl::OSeekableInputStreamWrapper(pSotStorageStream.get(), false));
+        uno::Sequence<beans::NamedValue> aStreams = xPackageEncryption->encrypt(xInputStream);
+
+        pStg = pOrigStg;
+        for (const beans::NamedValue & aStreamData : aStreams)
+        {
+            // To avoid long paths split and open substorages recursively
+            // Splitting paths manually, since comphelper::string::split is trimming special characters like \0x01, \0x09
+            SotStorage * pStorage = pStg.get();
+            OUString sFileName;
+            sal_Int32 idx = 0;
+            do
+            {
+                OUString sPathElem = aStreamData.Name.getToken(0, L'/', idx);
+                if (!sPathElem.isEmpty())
+                {
+                    if (idx < 0)
+                    {
+                        sFileName = sPathElem;
+                    }
+                    else
+                    {
+                        pStorage = pStorage->OpenSotStorage(sPathElem);
+                        if (!pStorage)
+                            break;
+                    }
+                }
+            } while (pStorage && idx >= 0);
+
+            if (!pStorage)
+            {
+                nErrorCode = ERRCODE_IO_GENERAL;
+                break;
+            }
+
+            SotStorageStream* pStream = pStorage->OpenSotStream(sFileName);
+            if (!pStream)
+            {
+                nErrorCode = ERRCODE_IO_GENERAL;
+                break;
+            }
+            uno::Sequence<sal_Int8> aStreamContent;
+            aStreamData.Value >>= aStreamContent;
+            size_t nBytesWritten = pStream->WriteBytes(aStreamContent.getArray(), aStreamContent.getLength());
+            if (nBytesWritten != aStreamContent.getLength())
+            {
+                nErrorCode = ERRCODE_IO_CANTWRITE;
+                break;
+            }
+        }
+    }
+
+    return nErrorCode;
+}
+ErrCode SwWW8Writer::WriteStorageImpl()
+{
     // #i34818# - update layout (if present), for SwWriteTable
     SwViewShell* pViewShell = m_pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
     if( pViewShell != nullptr )
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 9824f52b7d84..ee6297334dd7 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -936,7 +936,6 @@ friend void WW8_WrtRedlineAuthor::Write(Writer &rWrt);
 
     WW8Export *m_pExport;
     SfxMedium *mpMedium;
-
 public:
     SwWW8Writer(const OUString& rFltName, const OUString& rBaseURL);
     virtual ~SwWW8Writer() override;
@@ -981,6 +980,7 @@ public:
 private:
     SwWW8Writer(const SwWW8Writer&) = delete;
     SwWW8Writer& operator=(const SwWW8Writer&) = delete;
+    ErrCode WriteStorageImpl();
 };
 
 /// Exporter of the binary Word file formats.
commit 1fb6e25ebd3861cbb9698a4b6432d95c24bdd1e6
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Mon Oct 28 14:23:36 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:09 2019 +0100

    sw: support for DRM encryption for binary doc formats
    
    DRM encryption is implemented as a service and desrption
    will be called if we found corresponding streams inside
    binary OLE package.
    
    Change-Id: Ie1a5b0417e1e7851b24d410c8f41dc85dd9210f7
    Reviewed-on: https://gerrit.libreoffice.org/81600
    Reviewed-by: Vasily Melenchuk <vasily.melenchuk at cib.de>
    Tested-by: Vasily Melenchuk <vasily.melenchuk at cib.de>

diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 445744b2912a..a800b43644ba 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -25,12 +25,14 @@
 #include <com/sun/star/embed/Aspects.hpp>
 #include <com/sun/star/embed/ElementModes.hpp>
 #include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/packages/XPAckageEncryption.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 
 #include <i18nlangtag/languagetag.hxx>
 
 #include <unotools/configmgr.hxx>
 #include <unotools/ucbstreamhelper.hxx>
+#include <unotools/streamwrap.hxx>
 #include <rtl/random.h>
 #include <rtl/ustring.hxx>
 #include <rtl/ustrbuf.hxx>
@@ -6300,6 +6302,95 @@ ErrCode WW8Reader::OpenMainStream( tools::SvRef<SotStorageStream>& rRef, sal_uIn
     return nRet;
 }
 
+void lcl_getListOfStreams(SotStorage * pStorage, comphelper::SequenceAsHashMap& aStreamsData, const OUString& sPrefix)
+{
+    SvStorageInfoList aElements;
+    pStorage->FillInfoList(&aElements);
+    for (const auto & aElement : aElements)
+    {
+        OUString sStreamFullName = sPrefix.getLength() ? sPrefix + "/" + aElement.GetName() : aElement.GetName();
+        if (aElement.IsStorage())
+        {
+            SotStorage * pSubStorage = pStorage->OpenSotStorage(aElement.GetName(), StreamMode::STD_READ | StreamMode::SHARE_DENYALL);
+            lcl_getListOfStreams(pSubStorage, aStreamsData, sStreamFullName);
+        }
+        else
+        {
+            // Read stream
+            tools::SvRef<SotStorageStream> rStream = pStorage->OpenSotStream(aElement.GetName(), StreamMode::READ | StreamMode::SHARE_DENYALL);
+            assert(rStream.is());
+
+            sal_Int32 nStreamSize = rStream->GetSize();
+            css::uno::Sequence< sal_Int8 > oData;
+            oData.realloc(nStreamSize);
+            sal_Int32 nReadBytes = rStream->ReadBytes(oData.getArray(), nStreamSize);
+            assert(nStreamSize == nReadBytes);
+            aStreamsData[sStreamFullName] <<= oData;
+        }
+    }
+}
+
+ErrCode WW8Reader::DecryptDRMPackage()
+{
+    // We have DRM encrypted storage. We should try to decrypt it first, if we can
+    uno::Sequence< uno::Any > aArguments;
+    uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+    uno::Reference< packages::XPackageEncryption > xPackageEncryption(
+        xComponentContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+            "com.sun.star.comp.oox.crypto.DRMDataSpace", aArguments, xComponentContext), uno::UNO_QUERY);
+
+    if (!xPackageEncryption.is())
+    {
+        // We do not know how to decrypt this
+        return ERRCODE_IO_ACCESSDENIED;
+    }
+
+    std::vector<OUString> aStreamsList;
+    comphelper::SequenceAsHashMap aStreamsData;
+    lcl_getListOfStreams(m_pStorage.get(), aStreamsData, OUString(""));
+
+    try {
+        uno::Sequence<beans::NamedValue> aStreams = aStreamsData.getAsConstNamedValueList();
+        if (!xPackageEncryption->readEncryptionInfo(aStreams))
+        {
+            // We failed with decryption
+            return ERRCODE_IO_ACCESSDENIED;
+        }
+
+        tools::SvRef<SotStorageStream> rContentStream = m_pStorage->OpenSotStream("\011DRMContent", StreamMode::READ | StreamMode::SHARE_DENYALL);
+        if (!rContentStream.is())
+        {
+            return ERRCODE_IO_NOTEXISTS;
+        }
+
+        mDecodedStream.reset(new SvMemoryStream());
+
+        uno::Reference<io::XInputStream > xInputStream(new utl::OSeekableInputStreamWrapper(rContentStream.get(), false));
+        uno::Reference<io::XOutputStream > xDecryptedStream(new utl::OSeekableOutputStreamWrapper(*mDecodedStream.get()));
+
+        if (!xPackageEncryption->decrypt(xInputStream, xDecryptedStream))
+        {
+            // We failed with decryption
+            return ERRCODE_IO_ACCESSDENIED;
+        }
+
+        mDecodedStream->Seek(0);
+
+        // Further reading is done from new document
+        m_pStorage = new SotStorage(*mDecodedStream);
+
+        // Set the media descriptor data
+        uno::Sequence<beans::NamedValue> aEncryptionData = xPackageEncryption->createEncryptionData("");
+        m_pMedium->GetItemSet()->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, uno::makeAny(aEncryptionData)));
+    }
+    catch (const std::exception&)
+    {
+        return ERRCODE_IO_ACCESSDENIED;
+    }
+
+    return ERRCODE_NONE;
+}
+
 ErrCode WW8Reader::Read(SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, const OUString & /* FileName */)
 {
     sal_uInt16 nOldBuffSize = 32768;
@@ -6331,7 +6422,13 @@ ErrCode WW8Reader::Read(SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, cons
 
         if( m_pStorage.is() )
         {
-            nRet = OpenMainStream( refStrm, nOldBuffSize );
+            // Check if we have special encrypted content
+            tools::SvRef<SotStorageStream> rRef = m_pStorage->OpenSotStream("\006DataSpaces/DataSpaceInfo/\011DRMDataSpace", StreamMode::READ | StreamMode::SHARE_DENYALL);
+            if (rRef.is())
+            {
+                nRet = DecryptDRMPackage();
+            }
+            nRet = OpenMainStream(refStrm, nOldBuffSize);
             pIn = refStrm.get();
         }
         else
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 856923589c4b..fd5e4e87e441 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -131,9 +131,13 @@ struct WW8LFOInfo;
 
 class WW8Reader : public StgReader
 {
+    std::shared_ptr<SvStream> mDecodedStream;
     virtual ErrCode Read(SwDoc &, const OUString& rBaseURL, SwPaM &, const OUString &) override;
     ErrCode OpenMainStream( tools::SvRef<SotStorageStream>& rRef, sal_uInt16& rBuffSize );
+    ErrCode DecryptDRMPackage();
 public:
+    WW8Reader() {}
+    ~WW8Reader() {}
     virtual SwReaderType GetReaderType() override;
 
     virtual bool HasGlossaries() const override;
commit b4d4c28219cd639624f3e9aaab9aa6f3bf044e78
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Thu Oct 17 11:09:21 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:09 2019 +0100

    oox: fixed build error, more consts
    
    Change-Id: I06b9885ca304c30d6160f43558b309539d4202c0

diff --git a/include/oox/crypto/DocumentEncryption.hxx b/include/oox/crypto/DocumentEncryption.hxx
index d33450a3b791..c99cadc972f4 100644
--- a/include/oox/crypto/DocumentEncryption.hxx
+++ b/include/oox/crypto/DocumentEncryption.hxx
@@ -33,14 +33,14 @@ private:
     css::uno::Reference< css::io::XStream > mxDocumentStream;
     oox::ole::OleStorage& mrOleStorage;
     css::uno::Reference< css::packages::XPackageEncryption > mxPackageEncryption;
-    css::uno::Sequence< css::beans::NamedValue >& mMediaEncData;
+    const css::uno::Sequence< css::beans::NamedValue >& mMediaEncData;
     css::uno::Reference< css::uno::XComponentContext > mxContext;
 
 public:
     DocumentEncryption(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
         css::uno::Reference< css::io::XStream > const & xDocumentStream,
         oox::ole::OleStorage& rOleStorage,
-        css::uno::Sequence< css::beans::NamedValue >& rMediaEncData);
+        const css::uno::Sequence< css::beans::NamedValue >& rMediaEncData);
 
     bool encrypt();
 
diff --git a/oox/source/crypto/DocumentEncryption.cxx b/oox/source/crypto/DocumentEncryption.cxx
index 2f0457911aed..70b7f2a3a4e9 100644
--- a/oox/source/crypto/DocumentEncryption.cxx
+++ b/oox/source/crypto/DocumentEncryption.cxx
@@ -28,7 +28,7 @@ using namespace css::beans;
 DocumentEncryption::DocumentEncryption(const Reference< XComponentContext >& rxContext,
                                        Reference<XStream> const & xDocumentStream,
                                        oox::ole::OleStorage& rOleStorage,
-                                       Sequence<NamedValue>& rMediaEncData)
+                                       const Sequence<NamedValue>& rMediaEncData)
     : mxContext(rxContext)
     , mxDocumentStream(xDocumentStream)
     , mrOleStorage(rOleStorage)
commit b41375b26946a6bcfb0585a9fa1556c1643c704c
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Mon Oct 14 10:37:45 2019 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:09 2019 +0100

    .gitreview: Update default branch
    
    Change-Id: Ie7acdd15ee51f4d1e8d7a5b13ca107d64a360b61
    Reviewed-on: https://gerrit.libreoffice.org/80758
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/.gitreview b/.gitreview
index 199752b8b09e..0193cec971ff 100644
--- a/.gitreview
+++ b/.gitreview
@@ -3,5 +3,4 @@ host=gerrit.libreoffice.org
 port=29418
 project=core
 defaultremote=logerrit
-defaultbranch=master
-
+defaultbranch=feature/cib_contract3756
commit eb09a5b47efeb0f5f401cfc3a6a2aaa7fa863336
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Mon Oct 14 00:01:52 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:09 2019 +0100

    temporary: do not clean up EncryptionData during SaveAs
    
    This clean up can ruin sensetive encryption details saving document
    in plain mode which is not expected.
    
    Relaization is not final and requires more atention.
    
    Change-Id: I46b757af81e68ad4781e83b1a0e0b6da3a5e13e1

diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 7b2e705e45e5..cf8df0b417cc 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -1752,7 +1752,7 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const
         if ( !( aValue >>= aKeys ) )
             throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 2 );
 
-        if ( aKeys.hasElements() )
+/*        if ( aKeys.hasElements() )
         {
             bool bHasSHA256 = false;
             bool bHasSHA1 = false;
@@ -1766,7 +1766,7 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const
 
             if ( !bHasSHA256 && !bHasSHA1 )
                 throw IllegalArgumentException(THROW_WHERE "Expected keys are not provided!", uno::Reference< uno::XInterface >(), 2 );
-        }
+        }*/
 
         m_aStorageEncryptionKeys = aKeys;
         m_aEncryptionKey.realloc( 0 );
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index ee22ee327857..545f520a7a1d 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1415,7 +1415,7 @@ ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList,
         // the password will be set in case user decide so
         rpSet->ClearItem( SID_PASSWORDINTERACTION );
         rpSet->ClearItem( SID_PASSWORD );
-        rpSet->ClearItem( SID_ENCRYPTIONDATA );
+        //rpSet->ClearItem( SID_ENCRYPTIONDATA );
         rpSet->ClearItem( SID_RECOMMENDREADONLY );
         rpSet->ClearItem( SID_MODIFYPASSWORDINFO );
 
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 24cfa8afd294..9e386d8c5964 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -810,10 +810,21 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
 
 
                 bool bPreselectPassword = false;
-                const SfxUnoAnyItem* pOldEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(GetMedium()->GetItemSet(), SID_ENCRYPTIONDATA, false);
                 const SfxStringItem* pOldPasswordItem = SfxItemSet::GetItem<SfxStringItem>(GetMedium()->GetItemSet(), SID_PASSWORD, false);
-                if ( pOldEncryptionDataItem || pOldPasswordItem )
+                if (pOldPasswordItem)
+                {
                     bPreselectPassword = true;
+                }
+                else
+                {
+                    const SfxUnoAnyItem* pOldEncryptionDataItem = SfxItemSet::GetItem<SfxUnoAnyItem>(GetMedium()->GetItemSet(), SID_ENCRYPTIONDATA, false);
+                    if (pOldEncryptionDataItem)
+                    {
+                        uno::Sequence< beans::NamedValue > aEncryptionData;
+                        pOldEncryptionDataItem->GetValue() >>= aEncryptionData;
+
+                    }
+                }
 
                 uno::Sequence< beans::PropertyValue > aDispatchArgs;
                 if ( rReq.GetArgs() )
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index f162bd5dfa92..ae58f9a88e97 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2764,11 +2764,11 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
     std::unique_ptr<SfxAllItemSet> pMergedParams(new SfxAllItemSet( *pMedium->GetItemSet() ));
 
     // in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
-    pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
+    //pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
     pMergedParams->ClearItem( SID_PASSWORD );
     // #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 )
-    pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
+//    pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
     pMergedParams->ClearItem( SID_DOCINFO_TITLE );
 
     pMergedParams->ClearItem( SID_INPUTSTREAM );
commit c00728a8a2568bfc9023bf4b217ce0d1bbb7161f
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Sun Oct 13 23:56:39 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:09 2019 +0100

    oox: init OLE container if any encryption data is present
    
    Some encryption methods could use other than "OOXPassword"
    values. So we could rely just on "EncryptionData" exists and
    it is not empty
    
    Change-Id: Iece53601282a1bd30b592c998c77185c9dcbbe7c

diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index b6e44b56b416..b52e6a0d9a28 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -882,13 +882,7 @@ Reference<XStream> XmlFilterBase::implGetOutputStream( MediaDescriptor& rMediaDe
                                         MediaDescriptor::PROP_ENCRYPTIONDATA(),
                                         Sequence< NamedValue >() );
 
-    OUString aPassword;
-    auto pProp = std::find_if(aMediaEncData.begin(), aMediaEncData.end(),
-        [](const NamedValue& rProp) { return rProp.Name == "OOXPassword"; });
-    if (pProp != aMediaEncData.end())
-        pProp->Value >>= aPassword;
-
-    if (aPassword.isEmpty())
+    if (aMediaEncData.getLength() == 0)
     {
         return FilterBase::implGetOutputStream( rMediaDescriptor );
     }
commit 2ad1a9dc25d3b2075bad64c41815bf3b7d330f06
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Sun Oct 13 23:53:22 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:08 2019 +0100

    oox: XPackageEncryption interface simplification
    
    instead of two methods to write ecrypted data and encryption info
    just one is used.
    
    Change-Id: Ie31f363a0b76cfe5b67b15c1b98b0e556578b5c8

diff --git a/include/oox/crypto/AgileEngine.hxx b/include/oox/crypto/AgileEngine.hxx
index 1d85a5535b88..d82a2aacf641 100644
--- a/include/oox/crypto/AgileEngine.hxx
+++ b/include/oox/crypto/AgileEngine.hxx
@@ -128,6 +128,9 @@ private:
     void setupEncryptionParameters(AgileEncryptionParameters const & rAgileEncryptionParameters);
     bool setupEncryptionKey(OUString const & rPassword);
 
+    css::uno::Sequence<sal_Int8> writeEncryptionInfo();
+    css::uno::Sequence<sal_Int8> writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream>& rxInputStream);
+
 public:
     AgileEngine(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
 
@@ -143,10 +146,7 @@ public:
 
     // Encryption
 
-    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL writeEncryptionInfo() override;
-
-    virtual void SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
-                 css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
+    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream) override;
 
     virtual sal_Bool SAL_CALL setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
 
diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx
index a951bfeef26d..41a6591b0f04 100644
--- a/include/oox/crypto/Standard2007Engine.hxx
+++ b/include/oox/crypto/Standard2007Engine.hxx
@@ -37,6 +37,8 @@ class OOX_DLLPUBLIC Standard2007Engine final : public cppu::WeakImplHelper<css::
     bool calculateEncryptionKey(const OUString& rPassword);
 
     css::uno::Reference<css::io::XInputStream> getStream(const css::uno::Sequence<css::beans::NamedValue> & rStreams, const OUString sStreamName);
+    css::uno::Sequence<sal_Int8> writeEncryptionInfo();
+    css::uno::Sequence<sal_Int8> writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream>& rxInputStream);
 
 public:
     Standard2007Engine(const css::uno::Reference<css::uno::XComponentContext>& rxContext);
@@ -53,10 +55,7 @@ public:
 
     // Encryption
 
-    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL writeEncryptionInfo() override;
-
-    virtual void SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
-                 css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
+    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream) override;
 
     virtual sal_Bool SAL_CALL setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
 
diff --git a/offapi/com/sun/star/packages/XPackageEncryption.idl b/offapi/com/sun/star/packages/XPackageEncryption.idl
index 298a089af6c7..0fba1d9c3ba7 100644
--- a/offapi/com/sun/star/packages/XPackageEncryption.idl
+++ b/offapi/com/sun/star/packages/XPackageEncryption.idl
@@ -52,11 +52,6 @@ interface XPackageEncryption: com::sun::star::uno::XInterface
     /**
         TODO
      */
-    sequence<com::sun::star::beans::NamedValue> writeEncryptionInfo();
-
-    /**
-        TODO
-     */
     sequence<com::sun::star::beans::NamedValue> createEncryptionData([in] string rPassword);
 
     /**
@@ -67,8 +62,7 @@ interface XPackageEncryption: com::sun::star::uno::XInterface
     /**
         TODO
      */
-    void encrypt([in] com::sun::star::io::XInputStream rxInputStream,
-                 [out] com::sun::star::io::XOutputStream rxOutputStream);
+    sequence<com::sun::star::beans::NamedValue> encrypt([in] com::sun::star::io::XInputStream rxInputStream);
 
     /**
         TODO
diff --git a/oox/source/crypto/AgileEngine.cxx b/oox/source/crypto/AgileEngine.cxx
index 35104903d918..54dd841ef2bf 100644
--- a/oox/source/crypto/AgileEngine.cxx
+++ b/oox/source/crypto/AgileEngine.cxx
@@ -756,7 +756,7 @@ bool AgileEngine::setupEncryptionKey(OUString const & rPassword)
     return true;
 }
 
-css::uno::Sequence<css::beans::NamedValue> AgileEngine::writeEncryptionInfo()
+css::uno::Sequence<sal_Int8> AgileEngine::writeEncryptionInfo()
 {
     Reference<XOutputStream> aEncryptionInfoStream(
         mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
@@ -820,20 +820,19 @@ css::uno::Sequence<css::beans::NamedValue> AgileEngine::writeEncryptionInfo()
     rStream.close();
     aEncryptionInfoStream->flush();
 
-    // Store all streams into sequence and return back
-    comphelper::SequenceAsHashMap aStreams;
-
     Reference<XSequenceOutputStream> aEncryptionInfoSequenceStream(aEncryptionInfoStream, UNO_QUERY);
-    aStreams["EncryptionInfo"] <<= aEncryptionInfoSequenceStream->getWrittenBytes();
-    return aStreams.getAsConstNamedValueList();
+    return aEncryptionInfoSequenceStream->getWrittenBytes();
 }
 
-void AgileEngine::encrypt(const css::uno::Reference<css::io::XInputStream> &  rxInputStream,
-                          css::uno::Reference<css::io::XOutputStream> & rxOutputStream)
+css::uno::Sequence<sal_Int8> AgileEngine::writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream>& rxInputStream)
 {
     CryptoHash aCryptoHash(mInfo.hmacKey, cryptoHashTypeFromString(mInfo.hashAlgorithm));
 
-    BinaryXOutputStream aBinaryOutputStream(rxOutputStream, false);
+    Reference<XOutputStream> aOutputStream(
+        mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
+        UNO_QUERY);
+    BinaryXOutputStream aBinaryOutputStream(aOutputStream, false);
+
     BinaryXInputStream aBinaryInputStream(rxInputStream, false);
     Reference<XSeekable> xSeekable(rxInputStream, UNO_QUERY);
     sal_uInt32 nLength = xSeekable->getLength();
@@ -890,6 +889,18 @@ void AgileEngine::encrypt(const css::uno::Reference<css::io::XInputStream> &  rx
     }
     mInfo.hmacHash = aCryptoHash.finalize();
     encryptHmacValue();
+
+    Reference<XSequenceOutputStream> aSequenceStream(aOutputStream, UNO_QUERY);
+    return aSequenceStream->getWrittenBytes();
+}
+
+
+css::uno::Sequence<css::beans::NamedValue> AgileEngine::encrypt(const css::uno::Reference<css::io::XInputStream> &  rxInputStream)
+{
+    comphelper::SequenceAsHashMap aStreams;
+    aStreams["EncryptedPackage"] <<= writeEncryptedDocument(rxInputStream);
+    aStreams["EncryptionInfo"] <<= writeEncryptionInfo();
+    return aStreams.getAsConstNamedValueList();
 }
 
 } // namespace core
diff --git a/oox/source/crypto/DocumentEncryption.cxx b/oox/source/crypto/DocumentEncryption.cxx
index 2dba0f035df5..2f0457911aed 100644
--- a/oox/source/crypto/DocumentEncryption.cxx
+++ b/oox/source/crypto/DocumentEncryption.cxx
@@ -78,12 +78,7 @@ bool DocumentEncryption::encrypt()
 
     mxPackageEncryption->setupEncryption(mMediaEncData);
 
-    Reference<XOutputStream> xOutputStream(mrOleStorage.openOutputStream("EncryptedPackage"), UNO_SET_THROW);
-    mxPackageEncryption->encrypt(xInputStream, xOutputStream);
-    xOutputStream->flush();
-    xOutputStream->closeOutput();
-
-    Sequence<NamedValue> aStreams = mxPackageEncryption->writeEncryptionInfo();
+    Sequence<NamedValue> aStreams = mxPackageEncryption->encrypt(xInputStream);
 
     for (const NamedValue & aStream : aStreams)
     {
diff --git a/oox/source/crypto/Standard2007Engine.cxx b/oox/source/crypto/Standard2007Engine.cxx
index 50f23e2cf491..9ddde339b1d5 100644
--- a/oox/source/crypto/Standard2007Engine.cxx
+++ b/oox/source/crypto/Standard2007Engine.cxx
@@ -257,7 +257,7 @@ sal_Bool Standard2007Engine::setupEncryption(const css::uno::Sequence<css::beans
     return true;
 }
 
-css::uno::Sequence<css::beans::NamedValue> Standard2007Engine::writeEncryptionInfo()
+css::uno::Sequence<sal_Int8> Standard2007Engine::writeEncryptionInfo()
 {
     Reference<XOutputStream> aEncryptionInfoStream(
         mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
@@ -283,21 +283,17 @@ css::uno::Sequence<css::beans::NamedValue> Standard2007Engine::writeEncryptionIn
     rStream.close();
     aEncryptionInfoStream->flush();
 
-    // Store all streams into sequence and return back
-    comphelper::SequenceAsHashMap aStreams;
-
     Reference<XSequenceOutputStream> aEncryptionInfoSequenceStream(aEncryptionInfoStream, UNO_QUERY);
-    aStreams["EncryptionInfo"] <<= aEncryptionInfoSequenceStream->getWrittenBytes();
-    return aStreams.getAsConstNamedValueList();
+    return aEncryptionInfoSequenceStream->getWrittenBytes();
 }
 
-void Standard2007Engine::encrypt(const css::uno::Reference<css::io::XInputStream> &  rxInputStream,
-                                 css::uno::Reference<css::io::XOutputStream> & rxOutputStream)
+css::uno::Sequence<sal_Int8> Standard2007Engine::writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream> &  rxInputStream)
 {
-    if (mKey.empty())
-        return;
+    Reference<XOutputStream> aOutputStream(
+        mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
+        UNO_QUERY);
+    BinaryXOutputStream aBinaryOutputStream(aOutputStream, false);
 
-    BinaryXOutputStream aBinaryOutputStream(rxOutputStream, false);
     BinaryXInputStream aBinaryInputStream(rxInputStream, false);
     Reference<XSeekable> xSeekable(rxInputStream, UNO_QUERY);
 
@@ -321,6 +317,21 @@ void Standard2007Engine::encrypt(const css::uno::Reference<css::io::XInputStream
         outputLength = aEncryptor.update(outputBuffer, inputBuffer, inputLength);
         aBinaryOutputStream.writeMemory(outputBuffer.data(), outputLength);
     }
+
+    Reference<XSequenceOutputStream> aSequenceStream(aOutputStream, UNO_QUERY);
+    return aSequenceStream->getWrittenBytes();
+}
+
+css::uno::Sequence<css::beans::NamedValue> Standard2007Engine::encrypt(const css::uno::Reference<css::io::XInputStream> &  rxInputStream)
+{
+    if (mKey.empty())
+        return css::uno::Sequence<css::beans::NamedValue>();
+
+    comphelper::SequenceAsHashMap aStreams;
+
+    aStreams["EncryptedPackage"] <<= writeEncryptedDocument(rxInputStream);
+    aStreams["EncryptionInfo"] <<= writeEncryptionInfo();
+    return aStreams.getAsConstNamedValueList();
 }
 
 css::uno::Reference<css::io::XInputStream> Standard2007Engine::getStream(const css::uno::Sequence<css::beans::NamedValue> & rStreams, const OUString sStreamName)
commit 8c1c8b324f735c023bb7bb2236db6e4af682cd41
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Sun Oct 13 21:29:24 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:08 2019 +0100

    oox: avoid control freeze on exception
    
    If exception happens somewhere in exportDocument() or later,
    document controls could be remain locked and later cause crash
    due to missing exception handler.
    
    To avoid this simple lock guard was implemented releasing controls
    even on exception.
    
    Change-Id: I1ce4e487833ddc4b1f1b708f3a7e10bb299ef354

diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index c99c77ba870f..ca57d3920a0c 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -110,6 +110,23 @@ DocumentOpenedGuard::~DocumentOpenedGuard()
         rUrlPool.maUrls.erase( maUrl );
 }
 
+class ControllerLockGuard
+{
+public:
+    explicit ControllerLockGuard(const Reference< XModel > & xModel)
+        : mxModel (xModel)
+    {
+        mxModel->lockControllers();
+    }
+
+    ~ControllerLockGuard()
+    {
+        mxModel->unlockControllers();
+    }
+private:
+    const Reference< XModel > & mxModel;
+};
+
 } // namespace
 
 /** Specifies whether this filter is an import or export filter. */
@@ -159,8 +176,6 @@ struct FilterBaseImpl
 
     /// @throws IllegalArgumentException
     void                setDocumentModel( const Reference< XComponent >& rxComponent );
-
-    void                initializeFilter();
 };
 
 FilterBaseImpl::FilterBaseImpl( const Reference< XComponentContext >& rxContext ) :
@@ -185,18 +200,6 @@ void FilterBaseImpl::setDocumentModel( const Reference< XComponent >& rxComponen
     }
 }
 
-void FilterBaseImpl::initializeFilter()
-{
-    try
-    {
-        // lock the model controllers
-        mxModel->lockControllers();
-    }
-    catch( Exception& )
-    {
-    }
-}
-
 FilterBase::FilterBase( const Reference< XComponentContext >& rxContext ) :
     mxImpl( new FilterBaseImpl( rxContext ) )
 {
@@ -472,7 +475,8 @@ sal_Bool SAL_CALL FilterBase::filter( const Sequence< PropertyValue >& rMediaDes
     DocumentOpenedGuard aOpenedGuard( mxImpl->maFileUrl );
     if( aOpenedGuard.isValid() || mxImpl->maFileUrl.isEmpty() )
     {
-        mxImpl->initializeFilter();
+        ControllerLockGuard aCtrlLockGuard(mxImpl->mxModel);
+
         switch( mxImpl->meDirection )
         {
             case FILTERDIRECTION_UNKNOWN:
@@ -492,7 +496,6 @@ sal_Bool SAL_CALL FilterBase::filter( const Sequence< PropertyValue >& rMediaDes
                 }
             break;
         }
-        mxImpl->mxModel->unlockControllers();
     }
     return bRet;
 }
commit b33c9262a29694b8e70d4d08657114df627a1241
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Thu Oct 10 10:45:44 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:08 2019 +0100

    crypto: predefine classes for later usage in unittests
    
    Change-Id: I2835803eaa2670ca5cae5445049bbc95f303dd08

diff --git a/include/oox/crypto/AgileEngine.hxx b/include/oox/crypto/AgileEngine.hxx
index db2cd082b751..1d85a5535b88 100644
--- a/include/oox/crypto/AgileEngine.hxx
+++ b/include/oox/crypto/AgileEngine.hxx
@@ -24,6 +24,8 @@ namespace oox {
     class BinaryXOutputStream;
 }
 
+namespace com::sun::star::uno { class XComponentContext; }
+
 namespace oox {
 namespace core {
 
diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx
index 3a969f68e888..a951bfeef26d 100644
--- a/include/oox/crypto/Standard2007Engine.hxx
+++ b/include/oox/crypto/Standard2007Engine.hxx
@@ -22,6 +22,8 @@ namespace oox {
     class BinaryXOutputStream;
 }
 
+namespace com::sun::star::uno { class XComponentContext; }
+
 namespace oox {
 namespace core {
 
commit da9090c84a0ee9f07ab5c6ed3fd1c7a51ed571a7
Author:     Serge Krot <Serge.Krot at cib.de>
AuthorDate: Thu Oct 10 10:01:16 2019 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:08 2019 +0100

    Fix compilation: SAL_CALL is missing in method declaration
    
    Change-Id: I4fc5e2de894a523d2a222ad9e7e04e1f1c01b9c5
    Reviewed-on: https://gerrit.libreoffice.org/80590
    Reviewed-by: Serge Krot (CIB) <Serge.Krot at cib.de>
    Tested-by: Serge Krot (CIB) <Serge.Krot at cib.de>

diff --git a/include/oox/crypto/AgileEngine.hxx b/include/oox/crypto/AgileEngine.hxx
index 8dacdd0ab625..db2cd082b751 100644
--- a/include/oox/crypto/AgileEngine.hxx
+++ b/include/oox/crypto/AgileEngine.hxx
@@ -131,24 +131,24 @@ public:
 
     // Decryption
 
-    sal_Bool generateEncryptionKey(const OUString & rPassword) override;
-    sal_Bool readEncryptionInfo(const css::uno::Sequence<css::beans::NamedValue>& aStreams) override;
-    sal_Bool decrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
+    virtual sal_Bool SAL_CALL generateEncryptionKey(const OUString & rPassword) override;
+    virtual sal_Bool SAL_CALL readEncryptionInfo(const css::uno::Sequence<css::beans::NamedValue>& aStreams) override;
+    virtual sal_Bool SAL_CALL decrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
                  css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
 
 
-    sal_Bool checkDataIntegrity() override;
+    virtual sal_Bool SAL_CALL checkDataIntegrity() override;
 
     // Encryption
 
-    css::uno::Sequence<css::beans::NamedValue> writeEncryptionInfo() override;
+    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL writeEncryptionInfo() override;
 
-    void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
+    virtual void SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
                  css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
 
-    sal_Bool setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
+    virtual sal_Bool SAL_CALL setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
 
-    css::uno::Sequence<css::beans::NamedValue> createEncryptionData(const OUString& rPassword) override;
+    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL createEncryptionData(const OUString& rPassword) override;
 };
 
 } // namespace core
diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx
index dff03a5ea228..3a969f68e888 100644
--- a/include/oox/crypto/Standard2007Engine.hxx
+++ b/include/oox/crypto/Standard2007Engine.hxx
@@ -41,24 +41,24 @@ public:
 
     // Decryption
 
-    sal_Bool generateEncryptionKey(const OUString & rPassword) override;
-    sal_Bool readEncryptionInfo(const css::uno::Sequence<css::beans::NamedValue>& aStreams) override;
-    sal_Bool decrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
+    virtual sal_Bool SAL_CALL generateEncryptionKey(const OUString & rPassword) override;
+    virtual sal_Bool SAL_CALL readEncryptionInfo(const css::uno::Sequence<css::beans::NamedValue>& aStreams) override;
+    virtual sal_Bool SAL_CALL decrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
                  css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
 
 
-    sal_Bool checkDataIntegrity() override;
+    virtual sal_Bool SAL_CALL checkDataIntegrity() override;
 
     // Encryption
 
-    css::uno::Sequence<css::beans::NamedValue> writeEncryptionInfo() override;
+    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL writeEncryptionInfo() override;
 
-    void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
+    virtual void SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
                  css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
 
-    sal_Bool setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
+    virtual sal_Bool SAL_CALL setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
 
-    css::uno::Sequence<css::beans::NamedValue> createEncryptionData(const OUString& rPassword) override;
+    virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL createEncryptionData(const OUString& rPassword) override;
 };
 
 } // namespace core
commit 3bacf637a50df4de3d37a0b07153953bb8a8cb40
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Tue Oct 8 11:46:05 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:08 2019 +0100

    uno: XModel2->setArgs() now able to set "EncryptionData"
    
    setArgs is able to set only limited media descriptor parameters.
    Extending this list by one more.
    
    Change-Id: I179a1cfc2cdd7b04becba0d7dfe9740d920ae4ee
    Reviewed-on: https://gerrit.libreoffice.org/80432
    Reviewed-by: Vasily Melenchuk <vasily.melenchuk at cib.de>
    Tested-by: Vasily Melenchuk <vasily.melenchuk at cib.de>

diff --git a/offapi/com/sun/star/frame/XModel2.idl b/offapi/com/sun/star/frame/XModel2.idl
index 128d5ced20d6..bab2427a3617 100644
--- a/offapi/com/sun/star/frame/XModel2.idl
+++ b/offapi/com/sun/star/frame/XModel2.idl
@@ -146,7 +146,7 @@ interface XModel2 : com::sun::star::frame::XModel
                 <li>com::sun::star::document::MediaDescriptor::LockExport</li>
                 <li>com::sun::star::document::MediaDescriptor::LockPrint</li>
                 <li>com::sun::star::document::MediaDescriptor::LockSave</li>
-
+                <li>com::sun::star::document::MediaDescriptor::EncryptionData</li>
             </ul>
 
         @throws com::sun::star::lang::IllegalArgumentException When trying to set an unsupported property
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index b2bf405836d8..aebd3f19cbad 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -1094,6 +1094,10 @@ void SAL_CALL SfxBaseModel::setArgs(const Sequence<beans::PropertyValue>& aArgs)
             rArg.Value >>= bValue;
             pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_SAVE, bValue));
         }
+        else if (rArg.Name == "EncryptionData")
+        {
+            pMedium->GetItemSet()->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, rArg.Value));
+        }
         else
         {
             throw lang::IllegalArgumentException("Setting property not supported: " + rArg.Name,
commit cd7e74e57603ddf838feada4bec7b805061a681f
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Oct 4 11:23:30 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:08 2019 +0100

    IRM encryption implmentation is moved out of core
    
    Change-Id: I2e83bfaf9e8190fe4839e2d39fcc9325305e4dda

diff --git a/include/oox/crypto/IRMEngine.hxx b/include/oox/crypto/IRMEngine.hxx
deleted file mode 100644
index c8ae7b125d86..000000000000
--- a/include/oox/crypto/IRMEngine.hxx
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- */
-
-#ifndef INCLUDED_OOX_CRYPTO_IRMENGINE_HXX
-#define INCLUDED_OOX_CRYPTO_IRMENGINE_HXX
-
-#include <oox/dllapi.h>
-#include <com/sun/star/packages/XPackageEncryption.hpp>
-#include <rtl/ustring.hxx>
-#include <sal/types.h>
-
-namespace oox
-{
-namespace core
-{
-struct OOX_DLLPUBLIC IRMEncryptionInfo
-{
-    OString license;
-    bool bCanRead;
-};
-
-class OOX_DLLPUBLIC IRMEngine : public cppu::WeakImplHelper<css::packages::XPackageEncryption>
-{
-    IRMEncryptionInfo mInfo;
-    css::uno::Reference<css::uno::XComponentContext> mxContext;
-
-    css::uno::Reference<css::io::XInputStream>
-    getStream(const css::uno::Sequence<css::beans::NamedValue>& rStreams,
-              const OUString sStreamName);
-
-public:
-    IRMEngine(const css::uno::Reference<css::uno::XComponentContext>& rxContext);
-
-    // Decryption
-
-    sal_Bool generateEncryptionKey(const OUString& rPassword) override;
-    sal_Bool
-    readEncryptionInfo(const css::uno::Sequence<css::beans::NamedValue>& aStreams) override;
-    sal_Bool decrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
-                     css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
-
-    sal_Bool checkDataIntegrity() override;
-
-    // Encryption
-
-    css::uno::Sequence<css::beans::NamedValue> writeEncryptionInfo() override;
-
-    void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
-                 css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
-
-    sal_Bool
-    setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
-
-    css::uno::Sequence<css::beans::NamedValue>
-    createEncryptionData(const OUString& rPassword) override;
-};
-
-} // namespace core
-} // namespace oox
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index b54b9283cba5..cc235b87e360 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -16,19 +16,8 @@ $(eval $(call gb_Library_use_custom_headers,oox,oox/generated))
 $(eval $(call gb_Library_set_include,oox,\
     $$(INCLUDE) \
     -I$(SRCDIR)/oox/inc \
-	-I"C:\Program Files\Active Directory Rights Management Services SDK 2.1\inc"\
 ))
 
-$(eval $(call gb_Library_add_libs,oox,\
-	msipc_s.lib \
-	msipc.lib \
-))
-
-$(eval $(call gb_Library_add_ldflags,oox,\
-	-LIBPATH:"C:\Program Files\Active Directory Rights Management Services SDK 2.1\lib\x64"\
-))
-
-
 ifeq ($(COM)-$(OS)-$(CPUNAME),GCC-LINUX-IA64)
 # at least Debian Linux ia64 fails at compile time on
 # link libooxlo.so which is apparently too large
@@ -109,7 +98,6 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
     oox/source/core/relationshandler \
     oox/source/core/xmlfilterbase \
     oox/source/crypto/AgileEngine \
-    oox/source/crypto/IRMEngine \
     oox/source/crypto/CryptTools \
     oox/source/crypto/DocumentEncryption \
     oox/source/crypto/DocumentDecryption \
diff --git a/oox/source/crypto/IRMEngine.cxx b/oox/source/crypto/IRMEngine.cxx
deleted file mode 100644
index 95135722ee08..000000000000
--- a/oox/source/crypto/IRMEngine.cxx
+++ /dev/null
@@ -1,447 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- */
-
-#include <oox/crypto/IRMEngine.hxx>
-
-#include <oox/helper/binaryinputstream.hxx>
-#include <oox/helper/binaryoutputstream.hxx>
-
-#include <sax/tools/converter.hxx>
-
-#include <comphelper/hash.hxx>
-#include <comphelper/docpasswordhelper.hxx>
-#include <comphelper/random.hxx>
-#include <comphelper/processfactory.hxx>
-#include <comphelper/base64.hxx>
-#include <comphelper/sequence.hxx>
-#include <comphelper/sequenceashashmap.hxx>
-
-#include <filter/msfilter/mscodec.hxx>
-#include <tools/stream.hxx>
-#include <tools/XmlWriter.hxx>
-
-#include <com/sun/star/io/XSeekable.hpp>
-#include <com/sun/star/io/XStream.hpp>
-#include <com/sun/star/io/SequenceInputStream.hpp>
-#include <com/sun/star/io/XSequenceOutputStream.hpp>
-#include <com/sun/star/uno/XComponentContext.hpp>
-#include <com/sun/star/xml/sax/XFastParser.hpp>
-#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
-#include <com/sun/star/xml/sax/FastParser.hpp>
-#include <com/sun/star/xml/sax/FastToken.hpp>
-
-#include <msipc.h>
-
-using namespace css;
-using namespace css::beans;
-using namespace css::io;
-using namespace css::lang;
-using namespace css::uno;
-using namespace css::xml::sax;
-using namespace css::xml;
-
-namespace oox
-{
-namespace core
-{
-extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
-com_sun_star_comp_oox_crypto_DRMEncryptedDataSpace_get_implementation(
-    XComponentContext* pCtx, Sequence<Any> const& /*arguments*/)
-{
-    return cppu::acquire(new IRMEngine(pCtx /*, arguments*/));
-}
-
-IRMEngine::IRMEngine(const Reference<XComponentContext>& rxContext)
-    : mxContext(rxContext)
-{
-}
-
-sal_Bool IRMEngine::checkDataIntegrity() { return true; }
-
-sal_Bool IRMEngine::decrypt(const Reference<XInputStream>& rxInputStream,
-                            Reference<XOutputStream>& rxOutputStream)
-{
-    BinaryXInputStream aInputStream(rxInputStream, true);
-    BinaryXOutputStream aOutputStream(rxOutputStream, true);
-
-    aInputStream.readInt64(); // Skip stream size
-
-    HRESULT hr = IpcInitialize();
-    if (FAILED(hr) && hr != HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED))
-    {
-        // ERROR_ALREADY_INITIALIZED not an error
-        // TODO: some reaction?
-        return false;
-    }
-
-    // Get decryption key
-    IPC_BUFFER licenseBuffer;
-    IPC_KEY_HANDLE key;
-    licenseBuffer.pvBuffer = (void*)mInfo.license.getStr();
-    licenseBuffer.cbBuffer = mInfo.license.getLength();
-    hr = IpcGetKey(&licenseBuffer, 0, NULL, NULL, &key);
-    if (FAILED(hr))
-    {
-        // TODO: some reaction?
-        return false;
-    }
-
-    // Read rights
-    BOOL value;
-    hr = IpcAccessCheck(key, IPC_GENERIC_READ, &value);
-    if (FAILED(hr))
-    {
-        // TODO: some reaction?
-        return false;
-    }
-    mInfo.bCanRead = value;
-
-    // Get size of decrypt block
-    DWORD* blockSize;
-    hr = IpcGetKeyProperty(key, IPC_KI_BLOCK_SIZE, nullptr, (LPVOID*)&blockSize);
-    if (FAILED(hr))
-    {
-        // TODO: some reaction?
-        return false;
-    }
-
-    char* pEncryptedBuffer = new char[*blockSize];
-    char* pDecryptedBuffer = new char[*blockSize];
-    int blockNo = 0;
-    bool lastBlock = false;
-
-    do
-    {
-        sal_uInt32 readBytes = aInputStream.readArray(pEncryptedBuffer, *blockSize);
-        lastBlock = readBytes != *blockSize;
-        DWORD bytes = 0;
-        hr = IpcDecrypt(key, blockNo, lastBlock, (PBYTE)pEncryptedBuffer, *blockSize,
-                        (PBYTE)pDecryptedBuffer, *blockSize, &bytes);
-
-        if (FAILED(hr))
-        {
-            // TODO: some reaction?
-            return false;
-        }
-
-        aOutputStream.writeArray(pDecryptedBuffer, bytes);
-
-        blockNo++;
-    } while (!lastBlock);
-
-    delete[] pEncryptedBuffer;
-    delete[] pDecryptedBuffer;
-
-    rxOutputStream->flush();
-
-    return true;
-}
-
-uno::Sequence<beans::NamedValue> IRMEngine::createEncryptionData(const OUString& /*rPassword*/)
-{
-    css::uno::Sequence<sal_uInt8> seq;
-    seq.realloc(mInfo.license.getLength());
-    memcpy(seq.getArray(), mInfo.license.getStr(), mInfo.license.getLength());
-
-    comphelper::SequenceAsHashMap aEncryptionData;
-    aEncryptionData["LicenseKey"] <<= seq;
-    aEncryptionData["CryptoType"] <<= OUString("DRMEncryptedDataSpace");
-    aEncryptionData["OOXPassword"] <<= OUString("1");
-
-    return aEncryptionData.getAsConstNamedValueList();
-}
-
-uno::Reference<io::XInputStream> IRMEngine::getStream(const Sequence<NamedValue>& rStreams,
-                                                      const OUString sStreamName)
-{
-    for (const auto& aStream : rStreams)
-    {
-        if (aStream.Name == sStreamName)
-        {
-            css::uno::Sequence<sal_Int8> aSeq;
-            aStream.Value >>= aSeq;
-            Reference<XInputStream> aStream(
-                io::SequenceInputStream::createStreamFromSequence(mxContext, aSeq),
-                UNO_QUERY_THROW);
-            return aStream;
-        }
-    }
-    return nullptr;
-}
-
-sal_Bool IRMEngine::readEncryptionInfo(const uno::Sequence<beans::NamedValue>& aStreams)
-{
-    // Read TransformInfo storage for IRM ECMA documents (MS-OFFCRYPTO 2.2.4)
-    uno::Reference<io::XInputStream> xTransformInfoStream
-        = getStream(aStreams, "\006DataSpaces/TransformInfo/DRMEncryptedTransform/\006Primary");
-    SAL_WARN_IF(!xTransformInfoStream.is(), "oox", "TransormInfo stream is missing!");
-    BinaryXInputStream aBinaryStream(xTransformInfoStream, true);
-
-    // MS-OFFCRYPTO 2.1.8: TransformInfoHeader
-    aBinaryStream.readuInt32(); // TransformLength
-    aBinaryStream.readuInt32(); // TransformType
-    // TransformId
-    sal_uInt32 aStringLength = aBinaryStream.readuInt32();
-    OUString sTransformId = aBinaryStream.readUnicodeArray(aStringLength / 2);
-    aBinaryStream.skip((4 - (aStringLength & 3)) & 3); // Skip padding
-
-    // TransformName
-    aStringLength = aBinaryStream.readuInt32();
-    OUString sTransformName = aBinaryStream.readUnicodeArray(aStringLength / 2);
-    aBinaryStream.skip((4 - (aStringLength & 3)) & 3); // Skip padding
-
-    aBinaryStream.readuInt32(); // ReaderVersion
-    aBinaryStream.readuInt32(); // UpdaterVersion
-    aBinaryStream.readuInt32(); // WriterVersion
-
-    // MS-OFFCRYPTO 2.2.5: ExtensibilityHeader
-    aBinaryStream.readuInt32(); // ExtensibilityHeader
-
-    // MS-OFFCRYPTO 2.2.6: XrMLLicense
-    aStringLength = aBinaryStream.readuInt32();
-    mInfo.license = aBinaryStream.readCharArray(aStringLength);
-
-    if (mInfo.license.getLength()
-        && static_cast<sal_uChar>(mInfo.license[0]) != 0x0ef) // BOM is missing?
-    {
-        mInfo.license = "\x0ef\x0bb\x0bf" + mInfo.license;
-    }
-
-    // TODO: CHECK info data
-
-    return true;
-}
-
-sal_Bool IRMEngine::setupEncryption(const Sequence<NamedValue>& rMediaEncData)
-{
-    for (int i = 0; i < rMediaEncData.getLength(); i++)
-    {
-        if (rMediaEncData[i].Name == "LicenseKey")
-        {
-            css::uno::Sequence<sal_uInt8> seq;
-            rMediaEncData[i].Value >>= seq;
-            mInfo.license = OString(reinterpret_cast<sal_Char*>(seq.getArray()), seq.getLength());
-        }
-    }
-
-    return true;
-}
-
-Sequence<NamedValue> IRMEngine::writeEncryptionInfo()
-{
-    // Write 0x6DataSpaces/DataSpaceMap
-    Reference<XOutputStream> xDataSpaceMap(
-        mxContext->getServiceManager()->createInstanceWithContext(
-            "com.sun.star.io.SequenceOutputStream", mxContext),
-        UNO_QUERY);
-    BinaryXOutputStream aDataSpaceMapStream(xDataSpaceMap, false);
-
-    aDataSpaceMapStream.WriteInt32(8); // Header length
-    aDataSpaceMapStream.WriteInt32(1); // Entries count
-
-    // DataSpaceMapEntry (MS-OFFCRYPTO 2.1.6.1)
-    OUString sDataSpaceName("DRMEncryptedDataSpace");
-    OUString sReferenceComponent("EncryptedPackage");
-
-    aDataSpaceMapStream.WriteInt32(0x60); // Length
-    aDataSpaceMapStream.WriteInt32(1); // References count
-    aDataSpaceMapStream.WriteInt32(0); // References component type
-
-    aDataSpaceMapStream.WriteInt32(sReferenceComponent.getLength() * 2);
-    aDataSpaceMapStream.writeUnicodeArray(sReferenceComponent);
-    for (int i = 0; i < sReferenceComponent.getLength() * 2 % 4; i++) // Padding
-    {
-        aDataSpaceMapStream.writeValue<sal_Char>(0);
-    }
-
-    aDataSpaceMapStream.WriteInt32(sDataSpaceName.getLength() * 2);
-    aDataSpaceMapStream.writeUnicodeArray(sDataSpaceName);
-    for (int i = 0; i < sDataSpaceName.getLength() * 2 % 4; i++) // Padding
-    {
-        aDataSpaceMapStream.writeValue<sal_Char>(0);
-    }
-
-    aDataSpaceMapStream.close();
-    xDataSpaceMap->flush();
-
-    // Write 0x6DataSpaces/Version
-    Reference<XOutputStream> xVersion(mxContext->getServiceManager()->createInstanceWithContext(
-                                          "com.sun.star.io.SequenceOutputStream", mxContext),
-                                      UNO_QUERY);
-    BinaryXOutputStream aVersionStream(xVersion, false);
-
-    OUString sFeatureIdentifier("Microsoft.Container.DataSpaces");
-    aVersionStream.WriteInt32(sFeatureIdentifier.getLength() * 2);
-    aVersionStream.writeUnicodeArray(sFeatureIdentifier);
-    for (int i = 0; i < sFeatureIdentifier.getLength() * 2 % 4; i++) // Padding
-    {
-        aVersionStream.writeValue<sal_Char>(0);
-    }
-
-    aVersionStream.WriteInt32(1); // Reader version
-    aVersionStream.WriteInt32(1); // Updater version
-    aVersionStream.WriteInt32(1); // Writer version
-
-    aVersionStream.close();
-    xVersion->flush();
-
-    // Write 0x6DataSpaces/DataSpaceInfo/[dataspacename]
-    Reference<XOutputStream> xDataSpaceInfo(
-        mxContext->getServiceManager()->createInstanceWithContext(
-            "com.sun.star.io.SequenceOutputStream", mxContext),
-        UNO_QUERY);
-    BinaryXOutputStream aDataSpaceInfoStream(xDataSpaceInfo, false);
-
-    aDataSpaceInfoStream.WriteInt32(0x08); // Header length
-    aDataSpaceInfoStream.WriteInt32(1); // Entries count
-
-    OUString sTransformName("DRMEncryptedTransform");
-    aDataSpaceInfoStream.WriteInt32(sTransformName.getLength() * 2);
-    aDataSpaceInfoStream.writeUnicodeArray(sTransformName);
-    for (int i = 0; i < sTransformName.getLength() * 2 % 4; i++) // Padding
-    {
-        aDataSpaceInfoStream.writeValue<sal_Char>(0);
-    }
-
-    aDataSpaceInfoStream.close();
-    xDataSpaceInfo->flush();
-
-    // Write 0x6DataSpaces/TransformInfo/[transformname]
-    Reference<XOutputStream> xTransformInfo(
-        mxContext->getServiceManager()->createInstanceWithContext(
-            "com.sun.star.io.SequenceOutputStream", mxContext),
-        UNO_QUERY);
-    BinaryXOutputStream aTransformInfoStream(xTransformInfo, false);
-    OUString sTransformId("{C73DFACD-061F-43B0-8B64-0C620D2A8B50}");
-
-    // MS-OFFCRYPTO 2.1.8: TransformInfoHeader
-    sal_uInt32 nLength
-        = sTransformId.getLength() * 2 + ((4 - (sTransformId.getLength() & 3)) & 3) + 10;
-    aTransformInfoStream.WriteInt32(nLength); // TransformLength, will be written later
-    aTransformInfoStream.WriteInt32(1); // TransformType
-
-    // TransformId
-    aTransformInfoStream.WriteInt32(sTransformId.getLength() * 2);
-    aTransformInfoStream.writeUnicodeArray(sTransformId);
-    for (int i = 0; i < sTransformId.getLength() * 2 % 4; i++) // Padding
-    {
-        aTransformInfoStream.writeValue<sal_Char>(0);
-    }
-
-    // TransformName
-    OUString sTransformInfoName("Microsoft.Metadata.DRMTransform");
-    aTransformInfoStream.WriteInt32(sTransformInfoName.getLength() * 2);
-    aTransformInfoStream.writeUnicodeArray(sTransformInfoName);
-    for (int i = 0; i < sTransformInfoName.getLength() * 2 % 4; i++) // Padding
-    {
-        aTransformInfoStream.writeValue<sal_Char>(0);
-    }
-
-    aTransformInfoStream.WriteInt32(1); // ReaderVersion
-    aTransformInfoStream.WriteInt32(1); // UpdateVersion
-    aTransformInfoStream.WriteInt32(1); // WriterVersion
-
-    aTransformInfoStream.WriteInt32(4); // Extensibility Header
-
-    aTransformInfoStream.WriteInt32(mInfo.license.getLength() - 3); // LicenseLength - BOM
-    aTransformInfoStream.writeArray<sal_Char>(mInfo.license.getStr() + 3,
-                                              mInfo.license.getLength() - 3);
-    aTransformInfoStream.writeValue<sal_Char>(0);
-
-    aTransformInfoStream.close();
-    xTransformInfo->flush();
-
-    // Store all streams into sequence and return back
-    comphelper::SequenceAsHashMap aStreams;
-
-    Reference<XSequenceOutputStream> xDataSpaceMapSequence(xDataSpaceMap, UNO_QUERY);
-    aStreams["\006DataSpaces/DataSpaceMap"] <<= xDataSpaceMapSequence->getWrittenBytes();
-
-    Reference<XSequenceOutputStream> xVersionSequence(xVersion, UNO_QUERY);
-    aStreams["\006DataSpaces/Version"] <<= xVersionSequence->getWrittenBytes();
-
-    OUString sStreamName = "\006DataSpaces/DataSpaceInfo/" + sDataSpaceName;
-    Reference<XSequenceOutputStream> xDataSpaceInfoSequence(xDataSpaceInfo, UNO_QUERY);
-    aStreams[sStreamName] <<= xDataSpaceInfoSequence->getWrittenBytes();
-
-    sStreamName = "\006DataSpaces/TransformInfo/" + sTransformName + "/\006Primary";
-    Reference<XSequenceOutputStream> xTransformInfoSequence(xTransformInfo, UNO_QUERY);
-    aStreams[sStreamName] <<= xTransformInfoSequence->getWrittenBytes();
-
-    return aStreams.getAsConstNamedValueList();
-}
-
-void IRMEngine::encrypt(const Reference<XInputStream>& rxInputStream,
-                        Reference<XOutputStream>& rxOutputStream)
-{
-    HRESULT hr = IpcInitialize();
-
-    if (FAILED(hr) && hr != HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED))
-    {
-        // ERROR_ALREADY_INITIALIZED not an error
-        // TODO: some reaction?
-    }
-
-    BinaryXInputStream aInputStream(rxInputStream, false);
-    BinaryXOutputStream aOutputStream(rxOutputStream, false);
-    aOutputStream.WriteInt64(aInputStream.size()); // Stream size
-
-    // Get decryption key
-    IPC_BUFFER licenseBuffer;
-    IPC_KEY_HANDLE key;
-    licenseBuffer.pvBuffer = (void*)mInfo.license.getStr();
-    licenseBuffer.cbBuffer = mInfo.license.getLength();
-    hr = IpcGetKey(&licenseBuffer, 0, NULL, NULL, &key);
-    if (FAILED(hr))
-    {
-        // TODO: some reaction?
-    }
-
-    // Get size of encrypt block
-    DWORD* blockSize;
-    hr = IpcGetKeyProperty(key, IPC_KI_BLOCK_SIZE, nullptr, (LPVOID*)&blockSize);
-    if (FAILED(hr))
-    {
-        // TODO: some reaction?
-    }
-
-    char* pEncryptedBuffer = new char[*blockSize];
-    char* pDecryptedBuffer = new char[*blockSize];
-    int blockNo = 0;
-    bool lastBlock = false;
-
-    do
-    {
-        sal_uInt32 readBytes = aInputStream.readArray(pDecryptedBuffer, *blockSize);
-        lastBlock = readBytes != *blockSize;
-        DWORD bytes = 0;
-        hr = IpcEncrypt(key, blockNo, lastBlock, (PBYTE)pDecryptedBuffer, *blockSize,
-                        (PBYTE)pEncryptedBuffer, *blockSize, &bytes);
-
-        if (FAILED(hr))
-        {
-            // TODO: some reaction?
-        }
-
-        aOutputStream.writeArray(pEncryptedBuffer, bytes);
-
-        blockNo++;
-    } while (!lastBlock);
-
-    delete[] pEncryptedBuffer;
-    delete[] pDecryptedBuffer;
-}
-
-sal_Bool IRMEngine::generateEncryptionKey(const OUString& /*password*/) { return true; }
-
-} // namespace core
-} // namespace oox
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/util/oox.component b/oox/util/oox.component
index 0643a417bfa3..d7167545b2be 100644
--- a/oox/util/oox.component
+++ b/oox/util/oox.component
@@ -40,14 +40,6 @@
     constructor="com_sun_star_comp_oox_ShapeContextHandler_get_implementation">
     <service name="com.sun.star.xml.sax.FastShapeContextHandler"/>
   </implementation>
-  <implementation name="com.sun.star.comp.oox.crypto.DRMEncryptedDataSpace"
-    constructor="com_sun_star_comp_oox_crypto_DRMEncryptedDataSpace_get_implementation">
-    <service name="com.sun.star.packages.XPackageEncryption"/>
-  </implementation>
-  <implementation name="com.sun.star.comp.oox.crypto.DRMDataSpace"
-    constructor="com_sun_star_comp_oox_crypto_DRMDataSpace_get_implementation">
-    <service name="com.sun.star.packages.XPackageEncryption"/>
-  </implementation>
   <implementation name="com.sun.star.comp.oox.crypto.Standard2007Engine"
     constructor="com_sun_star_comp_oox_crypto_Standard2007_get_implementation">
     <service name="com.sun.star.packages.XPackageEncryption"/>
commit dd3d5ffaadd8e18d63b87a73c6e0acd939a20181
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Sep 27 11:56:00 2019 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri Nov 8 23:25:07 2019 +0100

    msdoc crypto: move crypto engines to service
    
    New interface XPackageEncryption was created. All existing
    crypto engines are refactored to be implmentations of this interface.
    
    Change-Id: Id063aca1474f76a926a2e47eecd4c12ebe79650f

diff --git a/include/oox/crypto/AgileEngine.hxx b/include/oox/crypto/AgileEngine.hxx
index 2918384f9d2a..8dacdd0ab625 100644
--- a/include/oox/crypto/AgileEngine.hxx
+++ b/include/oox/crypto/AgileEngine.hxx
@@ -15,9 +15,9 @@
 
 #include <oox/dllapi.h>
 #include <oox/crypto/CryptTools.hxx>
-#include <oox/crypto/CryptoEngine.hxx>
 #include <rtl/ustring.hxx>
 #include <sal/types.h>
+#include <com/sun/star/packages/XPackageEncryption.hpp>
 
 namespace oox {
     class BinaryXInputStream;
@@ -74,7 +74,7 @@ enum class AgileEncryptionPreset
     AES_256_SHA512,
 };
 
-class OOX_DLLPUBLIC AgileEngine final : public CryptoEngine
+class OOX_DLLPUBLIC AgileEngine final : public cppu::WeakImplHelper<css::packages::XPackageEncryption>
 {
 private:
     std::vector<sal_uInt8> mKey;
@@ -82,7 +82,7 @@ private:
     AgileEncryptionPreset meEncryptionPreset;
     css::uno::Reference< css::uno::XComponentContext > mxContext;
 
-    css::uno::Reference<css::io::XInputStream> getStream(css::uno::Sequence<css::beans::NamedValue> & rStreams, const OUString sStreamName);
+    css::uno::Reference<css::io::XInputStream> getStream(const css::uno::Sequence<css::beans::NamedValue> & rStreams, const OUString sStreamName);
 
     void calculateHashFinal(const OUString& rPassword, std::vector<sal_uInt8>& aHashFinal);
 
@@ -131,24 +131,24 @@ public:
 
     // Decryption
 
-    bool generateEncryptionKey(OUString const & rPassword) override;
-    bool readEncryptionInfo(css::uno::Sequence<css::beans::NamedValue> aStreams) override;
-    bool decrypt(BinaryXInputStream& aInputStream,
-                 BinaryXOutputStream& aOutputStream) override;
+    sal_Bool generateEncryptionKey(const OUString & rPassword) override;
+    sal_Bool readEncryptionInfo(const css::uno::Sequence<css::beans::NamedValue>& aStreams) override;
+    sal_Bool decrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
+                 css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
 
-    bool checkDataIntegrity() override;
+
+    sal_Bool checkDataIntegrity() override;
 
     // Encryption
 
-    void writeEncryptionInfo(oox::ole::OleStorage& rOleStorage) override;
+    css::uno::Sequence<css::beans::NamedValue> writeEncryptionInfo() override;
 
-    void encrypt(css::uno::Reference<css::io::XInputStream>&  rxInputStream,
-                 css::uno::Reference<css::io::XOutputStream>& rxOutputStream,
-                 sal_uInt32 nSize) override;
+    void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
+                 css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
 
-    bool setupEncryption(css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
+    sal_Bool setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
 
-    virtual void createEncryptionData(comphelper::SequenceAsHashMap & aEncryptionData, const OUString rPassword) override;
+    css::uno::Sequence<css::beans::NamedValue> createEncryptionData(const OUString& rPassword) override;
 };
 
 } // namespace core
diff --git a/include/oox/crypto/CryptoEngine.hxx b/include/oox/crypto/CryptoEngine.hxx
deleted file mode 100644
index f985f2d7fb45..000000000000
--- a/include/oox/crypto/CryptoEngine.hxx
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- */
-
-#ifndef INCLUDED_OOX_CRYPTO_CRYPTOENGINE_HXX
-#define INCLUDED_OOX_CRYPTO_CRYPTOENGINE_HXX
-
-#include <vector>
-
-#include <rtl/ustring.hxx>
-#include <sal/types.h>
-
-#include <com/sun/star/io/XInputStream.hpp>
-#include <com/sun/star/io/XOutputStream.hpp>
-#include <com/sun/star/uno/Sequence.hxx>
-
-namespace oox {
-    class BinaryXInputStream;
-    class BinaryXOutputStream;
-}
-
-namespace oox {
-namespace core {
-
-class CryptoEngine
-{
-public:
-    CryptoEngine()
-    {}
-
-    virtual ~CryptoEngine()
-    {}
-
-    // Decryption
-    virtual bool readEncryptionInfo(css::uno::Sequence<css::beans::NamedValue> aStreams) = 0;
-
-    virtual bool generateEncryptionKey(const OUString& rPassword) = 0;
-
-    virtual bool decrypt(

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list