[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - 4 commits - configure.ac include/sfx2 sc/source sfx2/source xmlsecurity/CppunitTest_xmlsecurity_signing.mk xmlsecurity/qa
Thorsten Behrens (via logerrit)
logerrit at kemper.freedesktop.org
Tue Oct 1 15:18:02 UTC 2019
Rebased ref, commits from common ancestor:
commit f71c998384c290fffb5feb5f6f999cd42354e3f2
Author: Thorsten Behrens <Thorsten.Behrens at CIB.de>
AuthorDate: Mon Sep 30 09:30:07 2019 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Oct 1 17:14:39 2019 +0200
Bump version to 6.1.7.6
Change-Id: I110764d39edae9cc5d6f3e63f2a33aba1d680578
diff --git a/configure.ac b/configure.ac
index c159c4048da6..4f15ac04d00e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,7 +9,7 @@ dnl in order to create a configure script.
# several non-alphanumeric characters, those are split off and used only for the
# ABOUTBOXPRODUCTVERSIONSUFFIX in openoffice.lst. Why that is necessary, no idea.
-AC_INIT([LibreOffice powered by CIB],[6.1.7.5],[],[],[https://libreoffice.cib.eu/])
+AC_INIT([LibreOffice powered by CIB],[6.1.7.6],[],[],[https://libreoffice.cib.eu/])
AC_PREREQ([2.59])
commit 59369a56e3a09a0838ffe5b87f8e4e3dbb9ed5b4
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Mon Sep 30 16:02:02 2019 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Oct 1 17:14:38 2019 +0200
tdf#127306 Fix crash when closing LO after deleting a chart
This crash was introduced with b58aa94f1f365c746135470bceb97cc182c289bc
This patch basically reverts that patch and implements a different fix.
Reviewed-on: https://gerrit.libreoffice.org/79865
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
(cherry picked from commit e6e14b2cafd24179f8675350749878da77a31443)
Change-Id: I394a2f6490d3ee0769c0f78bb8a3980167719893
Reviewed-on: https://gerrit.libreoffice.org/79919
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx
index 33cdfc395200..1e14f5a11695 100644
--- a/include/sfx2/sidebar/SidebarController.hxx
+++ b/include/sfx2/sidebar/SidebarController.hxx
@@ -166,6 +166,8 @@ public:
tools::Rectangle GetDeckDragArea() const;
+ void saveDeckState();
+
private:
SidebarController(
SidebarDockingWindow* pParentWindow,
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index 301bcf43bb3c..516648f145e0 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -181,6 +181,9 @@ void SidebarController::registerSidebarForFrame(SidebarController* pController,
void SidebarController::unregisterSidebarForFrame(SidebarController* pController, const css::uno::Reference<css::frame::XController>& xController)
{
+ pController->saveDeckState();
+ pController->disposeDecks();
+
css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
css::ui::ContextChangeEventMultiplexer::get(
::comphelper::getProcessComponentContext()));
@@ -204,19 +207,25 @@ void SAL_CALL SidebarController::disposing()
maFocusManager.Clear();
mpTabBar.disposeAndClear();
- // save decks settings
- // Impress shutdown : context (frame) is disposed before sidebar disposing
- // calc writer : context (frame) is disposed after sidebar disposing
- // so need to test if GetCurrentContext is still valid regarding msApplication
+ saveDeckState();
- if (GetCurrentContext().msApplication != "none")
+ // clear decks
+ ResourceManager::DeckContextDescriptorContainer aDecks;
+
+ mpResourceManager->GetMatchingDecks (
+ aDecks,
+ GetCurrentContext(),
+ IsDocumentReadOnly(),
+ mxFrame->getController());
+
+ for (const auto& rDeck : aDecks)
{
- mpResourceManager->SaveDecksSettings(GetCurrentContext());
- mpResourceManager->SaveLastActiveDeck(GetCurrentContext(), msCurrentDeckId);
- }
+ std::shared_ptr<DeckDescriptor> deckDesc = mpResourceManager->GetDeckDescriptor(rDeck.msId);
- // clear decks
- disposeDecks();
+ VclPtr<Deck> aDeck = deckDesc->mpDeck;
+ if (aDeck)
+ aDeck.disposeAndClear();
+ }
uno::Reference<css::frame::XController> xController = mxFrame->getController();
if (!xController.is())
@@ -1351,6 +1360,18 @@ void SidebarController::frameAction(const css::frame::FrameActionEvent& rEvent)
}
}
+void SidebarController::saveDeckState()
+{
+ // Impress shutdown : context (frame) is disposed before sidebar disposing
+ // calc writer : context (frame) is disposed after sidebar disposing
+ // so need to test if GetCurrentContext is still valid regarding msApplication
+ if (GetCurrentContext().msApplication != "none")
+ {
+ mpResourceManager->SaveDecksSettings(GetCurrentContext());
+ mpResourceManager->SaveLastActiveDeck(GetCurrentContext(), msCurrentDeckId);
+ }
+}
+
} } // end of namespace sfx2::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 37fcbc3374afad789b73cc1127b16088357f7701
Author: Eike Rathke <erack at redhat.com>
AuthorDate: Fri Aug 16 15:36:15 2019 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Oct 1 17:13:26 2019 +0200
Resolves: tdf#126928 allow link updates in an intermediate linked document
... if link updates are allowed in the current document and that
intermediate document resides in a trusted location.
This works with both, the "Always (from trusted locations)" and
the "On request" settings under Tools -> Options -> Calc ->
General. It can't work with documents residing in a non-trusted
location as there is no way to allow updates on demand for a such
loaded document (hidden via formulas).
Reviewed-on: https://gerrit.libreoffice.org/77588
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Jenkins
(cherry picked from commit 54bf84746a2a9a2e2aaf0df9e429b0cfd538f640)
Reviewed-on: https://gerrit.libreoffice.org/77604
Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
(cherry picked from commit 14825a8b7f00ee4c148f2583856e5102312cabbd)
Change-Id: Ie483f7743db7c6d5cf947dc16a9c3660855f3423
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 3d3e6473cd43..cb7b1d89368b 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -618,15 +618,22 @@ bool ScDocShell::Load( SfxMedium& rMedium )
bool bRet = SfxObjectShell::Load(rMedium);
if (bRet)
{
- comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
- rEmbeddedObjectContainer.setUserAllowsLinkUpdate(false);
-
if (GetMedium())
{
const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
m_nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
}
+ // GetLinkUpdateModeState() evaluates m_nCanUpdate so that must have
+ // been set first. Do not override an already forbidden LinkUpdate (the
+ // default is allow).
+ comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
+ if (rEmbeddedObjectContainer.getUserAllowsLinkUpdate())
+ {
+ // For anything else than LM_ALWAYS we need user confirmation.
+ rEmbeddedObjectContainer.setUserAllowsLinkUpdate( GetLinkUpdateModeState() == LM_ALWAYS);
+ }
+
{
// prepare a valid document for XML filter
// (for ConvertFrom, InitNew is called before)
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 1d4ad1830372..853de4150c5b 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -149,6 +149,41 @@ IMPL_LINK_NOARG( ScDocShell, ReloadAllLinksHdl, Button*, void )
SAL_WARN_IF(!pViewFrame, "sc", "expected there to be a ViewFrame");
}
+ScLkUpdMode ScDocShell::GetLinkUpdateModeState() const
+{
+ const ScDocument& rDoc = GetDocument();
+
+ ScLkUpdMode nSet = rDoc.GetLinkMode();
+
+ if (nSet == LM_UNKNOWN)
+ {
+ ScAppOptions aAppOptions = SC_MOD()->GetAppOptions();
+ nSet = aAppOptions.GetLinkMode();
+ }
+
+ if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
+ nSet = LM_NEVER;
+ else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
+ nSet = LM_ALWAYS;
+
+ if (nSet == LM_ALWAYS
+ && !(SvtSecurityOptions().isTrustedLocationUriForUpdatingLinks(
+ GetMedium() == nullptr ? OUString() : GetMedium()->GetName())
+ || (IsDocShared()
+ && SvtSecurityOptions().isTrustedLocationUriForUpdatingLinks(
+ GetSharedFileURL()))))
+ {
+ nSet = LM_ON_DEMAND;
+ }
+ if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
+ && nSet == LM_ON_DEMAND)
+ {
+ nSet = LM_NEVER;
+ }
+
+ return nSet;
+}
+
void ScDocShell::Execute( SfxRequest& rReq )
{
const SfxItemSet* pReqArgs = rReq.GetArgs();
@@ -448,34 +483,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
break;
case SID_UPDATETABLINKS:
{
- ScDocument& rDoc = GetDocument();
-
- ScLkUpdMode nSet = rDoc.GetLinkMode();
-
- if(nSet==LM_UNKNOWN)
- {
- ScAppOptions aAppOptions=SC_MOD()->GetAppOptions();
- nSet=aAppOptions.GetLinkMode();
- }
-
- if (m_nCanUpdate == css::document::UpdateDocMode::NO_UPDATE)
- nSet = LM_NEVER;
- else if (m_nCanUpdate == css::document::UpdateDocMode::FULL_UPDATE)
- nSet = LM_ALWAYS;
-
- if (nSet == LM_ALWAYS
- && !(SvtSecurityOptions()
- .isTrustedLocationUriForUpdatingLinks(
- GetMedium() == nullptr
- ? OUString() : GetMedium()->GetName())))
- {
- nSet = LM_ON_DEMAND;
- }
- if (m_nCanUpdate == css::document::UpdateDocMode::QUIET_UPDATE
- && nSet == LM_ON_DEMAND)
- {
- nSet = LM_NEVER;
- }
+ ScLkUpdMode nSet = GetLinkUpdateModeState();
if (nSet == LM_ALWAYS)
{
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 153647a2813b..1b72ac4707ef 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -59,6 +59,8 @@
#include <columnspanset.hxx>
#include <column.hxx>
#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/UpdateDocMode.hpp>
+#include <sal/log.hxx>
#include <memory>
#include <algorithm>
@@ -2529,6 +2531,11 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
// If the current document is allowed to execute macros then the referenced
// document may execute macros according to the security configuration.
+ // Similar for UpdateDocMode to update links, just that if we reach here
+ // the user already allowed updates and intermediate documents are expected
+ // to update as well. When loading the document ScDocShell::Load() will
+ // check through ScDocShell::GetLinkUpdateModeState() if its location is
+ // trusted.
SfxObjectShell* pShell = mpDoc->GetDocumentShell();
if (pShell)
{
@@ -2540,6 +2547,8 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
static_cast<const SfxUInt16Item*>(pItem)->GetValue() != css::document::MacroExecMode::NEVER_EXECUTE)
pSet->Put( SfxUInt16Item( SID_MACROEXECMODE, css::document::MacroExecMode::USE_CONFIG));
}
+
+ pSet->Put( SfxUInt16Item( SID_UPDATEDOCMODE, css::document::UpdateDocMode::FULL_UPDATE));
}
unique_ptr<SfxMedium> pMedium(new SfxMedium(aFile, StreamMode::STD_READ, pFilter, pSet));
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index d5b05cb96e31..5b990f24e6a6 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -221,6 +221,7 @@ public:
void GetDocStat( ScDocStat& rDocStat );
+ const ScDocument& GetDocument() const { return m_aDocument; }
ScDocument& GetDocument() { return m_aDocument; }
ScDocFunc& GetDocFunc() { return *m_pDocFunc; }
@@ -303,6 +304,7 @@ public:
void UpdateLinks() override;
void ReloadAllLinks();
void ReloadTabLinks();
+ ScLkUpdMode GetLinkUpdateModeState() const;
void SetFormulaOptions( const ScFormulaOptions& rOpt, bool bForLoading = false );
/**
commit 9850e0b0d725de00fde34f4bbcffc8fd65b81331
Author: Jan-Marek Glogowski <jan-marek.glogowski at extern.cib.de>
AuthorDate: Fri Jul 19 15:28:45 2019 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Tue Oct 1 17:13:25 2019 +0200
tdf#42316 preserve macro signature of templates
When comparing the filter of the current and the target document
we have to strip the '_template' from the filter name.
Still this won't preserve the signature of the document attached
to tdf#42316, as this is a ODF 1.0 OTT, which doesn't have a
valid signature in ODF 1.2, as the signature doesn't match the ODF
1.2 namespace for signatures and the default LO ODF version is ODF
1.2 extended.
In theory the signature itself could even be converted most times,
but that can be done in an additional patch, if needed.
Since the code literally saves a template to an internal document,
SfxObjectShell::DoSaveCompleted must keep the signature of the
template. Eventually it'll be dropped on save of the template as
a document later.
The signing tests check "OTT 1.0 => ODT 1.0: preserve", "OTT 1.2
=> ODT 1.2: preserve" and "OTT 1.0 => ODT 1.2: drop".
Reviewed-on: https://gerrit.libreoffice.org/75958
Tested-by: Jenkins
Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
(cherry picked from commit c3a1c83ff5af05d34f433ac808adbe85f47e8c18)
Reviewed-on: https://gerrit.libreoffice.org/77112
Conflicts:
xmlsecurity/qa/unit/signing/signing.cxx
Change-Id: I2263093687f5a0568ea781ce3ac9b114c9599add
Reviewed-on: https://gerrit.libreoffice.org/79371
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 716455cda9ae..fa08ceb42a4a 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1160,10 +1160,18 @@ bool SfxObjectShell::SaveTo_Impl
{}
// preserve only if the same filter has been used
- bTryToPreserveScriptSignature = pMedium->GetFilter() && pFilter && pMedium->GetFilter()->GetFilterName() == pFilter->GetFilterName();
-
+ // for templates, strip the _template from the filter name for comparison
+ OUString aMediumFilter = pMedium->GetFilter()->GetFilterName();
+ if (aMediumFilter.endsWith("_template"))
+ aMediumFilter = aMediumFilter.copy(0, aMediumFilter.getLength() - 9);
+ bTryToPreserveScriptSignature = pMedium->GetFilter() && pFilter && aMediumFilter == pFilter->GetFilterName();
+
+ // signatures were specified in ODF 1.2 but were used since much longer.
+ // LO will still correctly validate an old style signature on an ODF 1.2
+ // document, but technically this is not correct, so this prevents old
+ // signatures to be copied over to a version 1.2 document
bNoPreserveForOasis = (
- (aODFVersion == ODFVER_012_TEXT && nVersion == SvtSaveOptions::ODFVER_011) ||
+ (aODFVersion == ODFVER_012_TEXT && nVersion < SvtSaveOptions::ODFVER_012) ||
(aODFVersion.isEmpty() && nVersion >= SvtSaveOptions::ODFVER_012)
);
}
@@ -2026,13 +2034,21 @@ bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed, bool bRegisterRecent )
{}
}
+ const SfxBoolItem* pTemplateItem = SfxItemSet::GetItem<SfxBoolItem>(pMedium->GetItemSet(), SID_TEMPLATE, false);
+ bool bTemplate = pTemplateItem && pTemplateItem->GetValue();
+
// before the title regenerated the document must lose the signatures
pImpl->nDocumentSignatureState = SignatureState::NOSIGNATURES;
- pImpl->nScriptingSignatureState = pNewMed->GetCachedSignatureState_Impl();
- OSL_ENSURE( pImpl->nScriptingSignatureState != SignatureState::BROKEN, "The signature must not be broken at this place" );
+ if (!bTemplate)
+ {
+ pImpl->nScriptingSignatureState = pNewMed->GetCachedSignatureState_Impl();
+ OSL_ENSURE( pImpl->nScriptingSignatureState != SignatureState::BROKEN, "The signature must not be broken at this place" );
- // TODO/LATER: in future the medium must control own signature state, not the document
- pNewMed->SetCachedSignatureState_Impl( SignatureState::NOSIGNATURES ); // set the default value back
+ // TODO/LATER: in future the medium must control own signature state, not the document
+ pNewMed->SetCachedSignatureState_Impl( SignatureState::NOSIGNATURES ); // set the default value back
+ }
+ else
+ pNewMed->SetCachedSignatureState_Impl( pImpl->nScriptingSignatureState );
// Set new title
if (!pNewMed->GetName().isEmpty() && SfxObjectCreateMode::EMBEDDED != eCreateMode)
diff --git a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
index 2f3ed41e2dfb..60a21f3944e1 100644
--- a/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
+++ b/xmlsecurity/CppunitTest_xmlsecurity_signing.mk
@@ -71,4 +71,8 @@ $(call gb_CppunitTest_get_target,xmlsecurity_signing): \
endif
endif
+$(eval $(call gb_CppunitTest_use_custom_headers,xmlsecurity_signing,\
+ officecfg/registry \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/xmlsecurity/qa/unit/signing/data/tdf42316.ott b/xmlsecurity/qa/unit/signing/data/tdf42316.ott
new file mode 100644
index 000000000000..95162a627176
Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/tdf42316.ott differ
diff --git a/xmlsecurity/qa/unit/signing/data/tdf42316_odt12.ott b/xmlsecurity/qa/unit/signing/data/tdf42316_odt12.ott
new file mode 100644
index 000000000000..ecff48709109
Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/tdf42316_odt12.ott differ
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 6b124654a292..ccaf9416f69f 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -18,13 +18,15 @@
#include <unotest/macros_test.hxx>
#include <test/xmltesttools.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
-#include <com/sun/star/xml/crypto/SEInitializer.hpp>
#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <com/sun/star/xml/crypto/SEInitializer.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
@@ -36,12 +38,17 @@
#include <sfx2/objsh.hxx>
#include <osl/file.hxx>
#include <osl/process.h>
+#include <comphelper/sequence.hxx>
#include <comphelper/ofopxmlhelper.hxx>
#include <documentsignaturehelper.hxx>
#include <xmlsignaturehelper.hxx>
#include <documentsignaturemanager.hxx>
#include <certificate.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <officecfg/Office/Common.hxx>
+#include <comphelper/configuration.hxx>
using namespace com::sun::star;
@@ -113,6 +120,10 @@ public:
void testODFEncryptedGPG();
#endif
#endif
+ void testPreserveMacroTemplateSignature12();
+ void testDropMacroTemplateSignature();
+ void testPreserveMacroTemplateSignature10();
+
CPPUNIT_TEST_SUITE(SigningTest);
CPPUNIT_TEST(testDescription);
CPPUNIT_TEST(testECDSA);
@@ -145,12 +156,18 @@ public:
CPPUNIT_TEST(testODFEncryptedGPG);
#endif
#endif
+ CPPUNIT_TEST(testPreserveMacroTemplateSignature12);
+ CPPUNIT_TEST(testDropMacroTemplateSignature);
+ CPPUNIT_TEST(testPreserveMacroTemplateSignature10);
CPPUNIT_TEST_SUITE_END();
private:
void createDoc(const OUString& rURL);
void createCalc(const OUString& rURL);
uno::Reference<security::XCertificate> getCertificate(DocumentSignatureManager& rSignatureManager, svl::crypto::SignatureMethodAlgorithm eAlgo);
+ SfxObjectShell* assertDocument(const ::CppUnit::SourceLine aSrcLine,
+ const OUString& rFilterName, const SignatureState nDocSign,
+ const SignatureState nMacroSign, const OUString& sVersion);
};
SigningTest::SigningTest()
@@ -810,6 +827,239 @@ void SigningTest::testODFEncryptedGPG()
#endif
+SfxObjectShell* SigningTest::assertDocument(const ::CppUnit::SourceLine aSrcLine,
+ const OUString& rFilterName,
+ const SignatureState nDocSign,
+ const SignatureState nMacroSign,
+ const OUString& sVersion)
+{
+ std::string sPos = aSrcLine.fileName() + ":" + OString::number(aSrcLine.lineNumber()).getStr();
+
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT_MESSAGE(sPos, pBaseModel);
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT_MESSAGE(sPos, pObjectShell);
+
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sPos, rFilterName,
+ pObjectShell->GetMedium()->GetFilter()->GetFilterName());
+ SignatureState nActual = pObjectShell->GetDocumentSignatureState();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sPos, nDocSign, nActual);
+ nActual = pObjectShell->GetScriptingSignatureState();
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sPos, nMacroSign, nActual);
+
+ OUString aODFVersion;
+ uno::Reference<beans::XPropertySet> xPropSet(pObjectShell->GetStorage(), uno::UNO_QUERY_THROW);
+ xPropSet->getPropertyValue("Version") >>= aODFVersion;
+ CPPUNIT_ASSERT_EQUAL(sVersion, aODFVersion);
+
+ return pObjectShell;
+}
+
+/// Test if a macro signature from a OTT 1.2 template is preserved for ODT 1.2
+void SigningTest::testPreserveMacroTemplateSignature12()
+{
+ const OUString aURL(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf42316_odt12.ott");
+ const OUString sLoadMessage = "loading failed: " + aURL;
+
+ // load the template as-is to validate signatures
+ mxComponent = loadFromDesktop(
+ aURL, OUString(), comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // we are a template, and have a valid document and macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::OK, SignatureState::OK,
+ ODFVER_012_TEXT);
+ mxComponent->dispose();
+
+ // create new document from template
+ // we can't use createDoc / MacrosTest::loadFromDesktop, because ALWAYS_EXECUTE_NO_WARN
+ // won't verify the signature for templates, so the resulting document won't be able to
+ // preserve the templates signature.
+ mxComponent = mxDesktop->loadComponentFromURL(
+ aURL, "_default", 0,
+ comphelper::InitPropertySequence(
+ { { "MacroExecutionMode",
+ uno::Any(document::MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // we are somehow a template (?), and have just a valid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::OK, ODFVER_012_TEXT);
+
+ // save as new ODT document
+ utl::TempFile aTempFileSaveAs;
+ aTempFileSaveAs.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(
+ comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("writer8")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save ODT document");
+ }
+
+ // load saved document
+ createDoc(aTempFileSaveAs.GetURL());
+
+ // the loaded document is a ODT with a macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8", SignatureState::NOSIGNATURES,
+ SignatureState::OK, ODFVER_012_TEXT);
+}
+
+/// Test if a macro signature from an OTT 1.0 is dropped for ODT 1.2
+void SigningTest::testDropMacroTemplateSignature()
+{
+ const OUString aURL(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf42316.ott");
+ const OUString sLoadMessage = "loading failed: " + aURL;
+
+ // load the template as-is to validate signatures
+ mxComponent = loadFromDesktop(
+ aURL, OUString(), comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // we are a template, and have a valid document and macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
+ mxComponent->dispose();
+
+ // create new document from template
+ // we can't use createDoc / MacrosTest::loadFromDesktop, because ALWAYS_EXECUTE_NO_WARN
+ // won't verify the signature for templates, so the resulting document won't be able to
+ // preserve the templates signature.
+ mxComponent = mxDesktop->loadComponentFromURL(
+ aURL, "_default", 0,
+ comphelper::InitPropertySequence(
+ { { "MacroExecutionMode",
+ uno::Any(document::MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // we are somehow a template (?), and have just a valid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
+
+ // save as new ODT document
+ utl::TempFile aTempFileSaveAs;
+ aTempFileSaveAs.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(
+ comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("writer8")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save ODT document");
+ }
+
+ // load saved document
+ createDoc(aTempFileSaveAs.GetURL());
+
+ // the loaded document is a 1.2 ODT without any signatures
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8", SignatureState::NOSIGNATURES,
+ SignatureState::NOSIGNATURES, ODFVER_012_TEXT);
+}
+
+class Resetter
+{
+private:
+ std::function<void()> m_Func;
+
+public:
+ Resetter(std::function<void()> const& rFunc)
+ : m_Func(rFunc)
+ {
+ }
+ ~Resetter()
+ {
+ try
+ {
+ m_Func();
+ }
+ catch (...) // has to be reliable
+ {
+ fprintf(stderr, "resetter failed with exception\n");
+ abort();
+ }
+ }
+};
+
+/// Test if a macro signature from a OTT 1.0 template is preserved for ODT 1.0
+void SigningTest::testPreserveMacroTemplateSignature10()
+{
+ // set ODF version 1.0 / 1.1 as default
+ Resetter _([]() {
+ std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+ comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::Save::ODF::DefaultVersion::set(3, pBatch);
+ return pBatch->commit();
+ });
+ std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+ comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::Save::ODF::DefaultVersion::set(2, pBatch);
+ pBatch->commit();
+
+ const OUString aURL(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf42316.ott");
+ const OUString sLoadMessage = "loading failed: " + aURL;
+
+ // load the template as-is to validate signatures
+ mxComponent = loadFromDesktop(
+ aURL, OUString(), comphelper::InitPropertySequence({ { "AsTemplate", uno::Any(false) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // we are a template, and have a valid document and macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
+
+ mxComponent->dispose();
+
+ // create new document from template
+ // we can't use createDoc / MacrosTest::loadFromDesktop, because ALWAYS_EXECUTE_NO_WARN
+ // won't verify the signature for templates, so the resulting document won't be able to
+ // preserve the templates signature.
+ mxComponent = mxDesktop->loadComponentFromURL(
+ aURL, "_default", 0,
+ comphelper::InitPropertySequence(
+ { { "MacroExecutionMode",
+ uno::Any(document::MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN) } }));
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(sLoadMessage, RTL_TEXTENCODING_UTF8).getStr(),
+ mxComponent.is());
+
+ // we are somehow a template (?), and have just a valid macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8_template", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
+
+ // save as new ODT document
+ utl::TempFile aTempFileSaveAs;
+ aTempFileSaveAs.EnableKillingFile();
+ try
+ {
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> descSaveAs(
+ comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("writer8")) } }));
+ xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs);
+ }
+ catch (...)
+ {
+ CPPUNIT_FAIL("Failed to save ODT document");
+ }
+
+ // load saved document
+ createDoc(aTempFileSaveAs.GetURL());
+
+ // the loaded document is a ODT with a macro signature
+ assertDocument(CPPUNIT_SOURCELINE(), "writer8", SignatureState::NOSIGNATURES,
+ SignatureState::NOTVALIDATED, OUString());
+}
+
#endif
void SigningTest::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
More information about the Libreoffice-commits
mailing list