From dd86f5e200bd6b8ec1d6bbafd7d80facb02fba91 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Thu, 12 Mar 2020 13:33:41 +0100 Subject: [PATCH] tdf#97694 WIP Split sfx::SignaturesHandler from SfxObjectShell. Change-Id: I85059159a10a7dfaaa454a5a68a7c147de0da1c9 --- basctl/source/basicide/docsignature.cxx | 2 +- dbaccess/source/core/dataaccess/ModelImpl.cxx | 37 ++ .../core/dataaccess/databasedocument.cxx | 8 + .../source/{core => }/inc/ContentHelper.hxx | 0 dbaccess/source/{core => }/inc/ModelImpl.hxx | 12 + .../dataaccess => inc}/databasedocument.hxx | 9 +- .../documenteventnotifier.hxx | 0 .../source/{core => }/inc/documentevents.hxx | 0 dbaccess/source/ui/app/AppController.cxx | 9 + desktop/source/lib/init.cxx | 2 +- include/sfx2/SignaturesHandler.hxx | 135 +++++ include/sfx2/objsh.hxx | 42 +- sfx2/Library_sfx.mk | 1 + sfx2/source/doc/SignaturesHandler.cxx | 557 ++++++++++++++++++ sfx2/source/doc/objmisc.cxx | 6 +- sfx2/source/doc/objserv.cxx | 494 +--------------- sfx2/source/doc/objstor.cxx | 26 +- sfx2/source/doc/objxtor.cxx | 2 - sfx2/source/doc/sfxbasemodel.cxx | 4 +- sfx2/source/inc/objshimp.hxx | 2 - solenv/clang-format/blacklist | 10 +- xmlsecurity/qa/unit/signing/signing.cxx | 34 +- 22 files changed, 844 insertions(+), 548 deletions(-) rename dbaccess/source/{core => }/inc/ContentHelper.hxx (100%) rename dbaccess/source/{core => }/inc/ModelImpl.hxx (97%) rename dbaccess/source/{core/dataaccess => inc}/databasedocument.hxx (98%) rename dbaccess/source/{core/dataaccess => inc}/documenteventnotifier.hxx (100%) rename dbaccess/source/{core => }/inc/documentevents.hxx (100%) create mode 100644 include/sfx2/SignaturesHandler.hxx create mode 100644 sfx2/source/doc/SignaturesHandler.cxx diff --git a/basctl/source/basicide/docsignature.cxx b/basctl/source/basicide/docsignature.cxx index 251e0eb06508..f5e3622d094c 100644 --- a/basctl/source/basicide/docsignature.cxx +++ b/basctl/source/basicide/docsignature.cxx @@ -79,7 +79,7 @@ namespace basctl SignatureState DocumentSignature::getScriptingSignatureState() const { if ( m_pImpl->pShell ) - return m_pImpl->pShell->GetScriptingSignatureState(); + return m_pImpl->pShell->scriptingSignatureState(); return SignatureState::NOSIGNATURES; } diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 2accd7cae25d..52bd100e83cc 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -1296,6 +1296,43 @@ void ODatabaseModelImpl::storageIsModified() setModified( true ); } +SfxMedium* ODatabaseModelImpl::GetMedium() const +{ + return nullptr; +} + +css::uno::Reference const& ODatabaseModelImpl::GetStorage() +{ + static css::uno::Reference aDummy; + return aDummy; +} + +void ODatabaseModelImpl::ImplDoSave() +{ +} + +void ODatabaseModelImpl::ImplDoSaveCompleted() +{ +} + +void ODatabaseModelImpl::Invalidate(sal_uInt16) +{ +} + +void ODatabaseModelImpl::SetModified(bool bModified) +{ +} + +bool ODatabaseModelImpl::IsModified() const +{ + return false; +} + +bool ODatabaseModelImpl::documentHasMacros() const +{ + return false; +} + ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model ) :m_pImpl( _model ) { diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index 3b0058a51c82..29750fd4cd36 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -77,6 +77,7 @@ #include #include +#include #include #include #include @@ -196,6 +197,13 @@ ODatabaseDocument::~ODatabaseDocument() } } +UNO3_GETIMPLEMENTATION_IMPL(ODatabaseDocument) + +bool ODatabaseDocument::documentStorageHasMacros() const +{ + return m_pImpl->documentStorageHasMacros(); +} + Any SAL_CALL ODatabaseDocument::queryInterface( const Type& _rType ) { // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report diff --git a/dbaccess/source/core/inc/ContentHelper.hxx b/dbaccess/source/inc/ContentHelper.hxx similarity index 100% rename from dbaccess/source/core/inc/ContentHelper.hxx rename to dbaccess/source/inc/ContentHelper.hxx diff --git a/dbaccess/source/core/inc/ModelImpl.hxx b/dbaccess/source/inc/ModelImpl.hxx similarity index 97% rename from dbaccess/source/core/inc/ModelImpl.hxx rename to dbaccess/source/inc/ModelImpl.hxx index d86ac74ef7fc..5b85904e6dbc 100644 --- a/dbaccess/source/core/inc/ModelImpl.hxx +++ b/dbaccess/source/inc/ModelImpl.hxx @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,7 @@ class ODatabaseContext; class DocumentStorageAccess; class OSharedConnectionManager; class ODatabaseModelImpl :public ::sfx2::IMacroDocumentAccess + ,public ::sfx2::SignaturesHandler ,public ::sfx2::IModifiableDocument { public: @@ -427,6 +429,16 @@ public: weld::Window* GetFrameWeld(); + // sfx2::SignaturesHandler + SfxMedium* GetMedium() const override; + css::uno::Reference const& GetStorage() override; + void ImplDoSave() override; + void ImplDoSaveCompleted() override; + void Invalidate(sal_uInt16) override; + void SetModified(bool bModified = true) override; + bool IsModified() const override; + bool documentHasMacros() const override; + private: void impl_construct_nothrow(); css::uno::Reference< css::embed::XStorage > const & diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/inc/databasedocument.hxx similarity index 98% rename from dbaccess/source/core/dataaccess/databasedocument.hxx rename to dbaccess/source/inc/databasedocument.hxx index 8adb30c541a1..c38a412435f1 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.hxx +++ b/dbaccess/source/inc/databasedocument.hxx @@ -59,6 +59,7 @@ #include #include +#include #include #include @@ -148,6 +149,7 @@ typedef cppu::PartialWeakComponentImplHelper< css::frame::XModel2 , css::document::XEventsSupplier , css::frame::XLoadable , css::document::XDocumentRecovery + , css::lang::XUnoTunnel > ODatabaseDocument_OfficeDocument; typedef ::cppu::ImplHelper3< css::frame::XTitle @@ -155,7 +157,7 @@ typedef ::cppu::ImplHelper3< css::frame::XTitle , css::frame::XUntitledNumbers > ODatabaseDocument_Title; -class ODatabaseDocument :public ModelDependentComponent // ModelDependentComponent must be first! +class SAL_DLLPUBLIC_EXPORT ODatabaseDocument :public ModelDependentComponent // ModelDependentComponent must be first! ,public ODatabaseDocument_OfficeDocument ,public ODatabaseDocument_Title { @@ -292,6 +294,11 @@ public: return new ODatabaseDocument( _pImpl ); } + // XUnoTunnel + UNO3_GETIMPLEMENTATION_DECL(ODatabaseDocument) + + bool documentStorageHasMacros() const; + // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) override; virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; diff --git a/dbaccess/source/core/dataaccess/documenteventnotifier.hxx b/dbaccess/source/inc/documenteventnotifier.hxx similarity index 100% rename from dbaccess/source/core/dataaccess/documenteventnotifier.hxx rename to dbaccess/source/inc/documenteventnotifier.hxx diff --git a/dbaccess/source/core/inc/documentevents.hxx b/dbaccess/source/inc/documentevents.hxx similarity index 100% rename from dbaccess/source/core/inc/documentevents.hxx rename to dbaccess/source/inc/documentevents.hxx diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 58393e84d0bb..f5b5f4f283c5 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -119,6 +119,7 @@ #include #include #include +#include #include @@ -916,6 +917,12 @@ FeatureState OApplicationController::GetState(sal_uInt16 _nId) const aReturn.sTitle = sHostName; } break; + case SID_MACRO_SIGNATURE: + { + auto pImpl = comphelper::getUnoTunnelImplementation(m_xModel); + aReturn.bEnabled = pImpl->documentStorageHasMacros(); + break; + } default: aReturn = OGenericUnoController::GetState(_nId); } @@ -1472,6 +1479,8 @@ void OApplicationController::describeSupportedFeatures() implDescribeSupportedFeature( ".uno:DBStatusDBName", SID_DB_APP_STATUS_DBNAME); implDescribeSupportedFeature( ".uno:DBStatusUserName", SID_DB_APP_STATUS_USERNAME); implDescribeSupportedFeature( ".uno:DBStatusHostName", SID_DB_APP_STATUS_HOSTNAME); + + implDescribeSupportedFeature(".uno:MacroSignature", SID_MACRO_SIGNATURE, CommandGroup::DOCUMENT); } OApplicationView* OApplicationController::getContainer() const diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index da2a29c3f7d4..f23f353c1ef8 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5376,7 +5376,7 @@ static int doc_getSignatureState(LibreOfficeKitDocument* pThis) pObjectShell->RecheckSignature(false); - return int(pObjectShell->GetDocumentSignatureState()); + return int(pObjectShell->documentSignatureState()); } static void doc_resizeWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, diff --git a/include/sfx2/SignaturesHandler.hxx b/include/sfx2/SignaturesHandler.hxx new file mode 100644 index 000000000000..3f0617ac7c90 --- /dev/null +++ b/include/sfx2/SignaturesHandler.hxx @@ -0,0 +1,135 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +class SfxViewFrame; +class SfxMedium; +class SfxObjectFactory; +class SfxBaseModel; +class Button; + +namespace com::sun::star::embed +{ +class XStorage; +} +namespace com::sun::star::graphic +{ +class XGraphic; +} +namespace com::sun::star::security +{ +class XCertificate; +class XDocumentDigitalSignatures; +struct DocumentSignatureInformation; +} +namespace weld +{ +class Window; +} + +namespace sfx2 +{ +class SFX2_DLLPUBLIC SignaturesHandler +{ + SignatureState m_nDocumentSignatureState; + SignatureState m_nScriptingSignatureState; + + SignatureState ImplGetSignatureState(bool bScriptingContent); + +public: + SignaturesHandler(); + virtual ~SignaturesHandler(); + + inline SignatureState documentSignatureState(); + inline void setDocumentSignatureState(SignatureState nState); + void SignDocumentContent(weld::Window* pDialogParent); + + inline SignatureState scriptingSignatureState(); + inline void setScriptingSignatureState(SignatureState nState); + void SignScriptingContent(weld::Window* pDialogParent); + + SAL_DLLPRIVATE static SignatureState ImplCheckSignaturesInformation( + const css::uno::Sequence& aInfos); + + SAL_DLLPRIVATE bool ExecFile_Impl(sal_uInt16 nId, weld::Window* pDialogParent = nullptr); + SAL_DLLPRIVATE bool GetState_Impl(sal_uInt16 nId, SfxItemSet& rSet, + SfxViewFrame* pFrame = nullptr, + const Link* pLink = nullptr); + + static bool HasSignatureStream(const css::uno::Reference& xStorage); + static bool IsOwnStorageFormat(const SfxMedium&); + bool CheckIsReadonly(bool bSignScriptingContent); + void RecheckSignature(bool bAlsoRecheckScriptingSignature); + bool HasValidSignatures() const; + css::uno::Sequence GetDocumentSignatureInformation( + bool bScriptingContent, + const css::uno::Reference& xSigner + = css::uno::Reference()); + void SignSignatureLine(weld::Window* pDialogParent, const OUString& aSignatureLineId, + const css::uno::Reference& xCert, + const css::uno::Reference& xValidGraphic, + const css::uno::Reference& xInvalidGraphic, + const OUString& aComment); + + bool SignDocumentContentUsingCertificate( + const css::uno::Reference& xCertificate); + + virtual void AfterSigning(bool bSignSuccess, bool bSignScriptingContent); + virtual bool PrepareForSigning(weld::Window* pDialogParent); + + virtual void ImplDoSave() = 0; + virtual void ImplDoSaveCompleted() = 0; + virtual css::uno::Reference const& GetStorage() = 0; + virtual void Invalidate(sal_uInt16) = 0; + virtual SfxMedium* GetMedium() const = 0; + virtual bool documentHasMacros() const = 0; + + virtual void SetModified(bool bModified = true) = 0; + virtual bool IsModified() const = 0; +}; + +SignatureState SignaturesHandler::documentSignatureState() { return ImplGetSignatureState(false); } + +void SignaturesHandler::setDocumentSignatureState(SignatureState nState) +{ + m_nDocumentSignatureState = nState; +} + +SignatureState SignaturesHandler::scriptingSignatureState() { return ImplGetSignatureState(true); } + +void SignaturesHandler::setScriptingSignatureState(SignatureState nState) +{ + m_nScriptingSignatureState = nState; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 083ad2dc667d..18d406701008 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -40,6 +40,7 @@ #include #include #include +#include class SbxValue; class SbxArray; @@ -177,7 +178,8 @@ template bool checkSfxObjectShell(const SfxObjectShell* pShell) class SFX2_DLLPUBLIC SfxObjectShell : public SfxShell, virtual public SotObject, - public ::comphelper::IEmbeddedHelper + public ::comphelper::IEmbeddedHelper, + public sfx2::SignaturesHandler { friend struct ModifyBlocker_Impl; friend class SfxObjectShellLock; @@ -217,6 +219,11 @@ protected: // helper method void AddToRecentlyUsedList(); + void ImplDoSave() override; + void ImplDoSaveCompleted() override; + void AfterSigning(bool bSignSuccess, bool bSignScriptingContent) override; + bool documentHasMacros() const override; + public: SFX_DECL_INTERFACE(SFX_INTERFACE_SFXDOCSH) @@ -330,6 +337,8 @@ public: bool bForceNonModified = false ); bool SaveCompletedChildren(); + bool PrepareForSigning(weld::Window* pDialogParent) override; + /** a very special case to insert at a position in Writer from UNO, via OwnSubFilterService */ virtual bool InsertGeneratedStream(SfxMedium& rMedium, @@ -338,28 +347,11 @@ public: css::uno::Reference const& xInsertPosition); bool ExportTo( SfxMedium &rMedium ); - /** Returns to if preparing was successful, else false. */ - bool PrepareForSigning(weld::Window* pDialogParent); - bool CheckIsReadonly(bool bSignScriptingContent); - void RecheckSignature(bool bAlsoRecheckScriptingSignature); - void AfterSigning(bool bSignSuccess, bool bSignScriptingContent); - bool HasValidSignatures() const; - SignatureState GetDocumentSignatureState(); - void SignDocumentContent(weld::Window* pDialogParent); - css::uno::Sequence GetDocumentSignatureInformation( - bool bScriptingContent, - const css::uno::Reference& xSigner - = css::uno::Reference()); - - bool SignDocumentContentUsingCertificate(const css::uno::Reference& xCertificate); - void SignSignatureLine(weld::Window* pDialogParent, const OUString& aSignatureLineId, const css::uno::Reference& xCert, const css::uno::Reference& xValidGraphic, const css::uno::Reference& xInvalidGraphic, const OUString& aComment); - SignatureState GetScriptingSignatureState(); - void SignScriptingContent(weld::Window* pDialogParent); DECL_LINK(SignDocumentHandler, Button*, void); virtual std::unique_ptr CreateDocumentInfoDialog(weld::Window* pParent, const SfxItemSet& rItemSet); @@ -586,10 +578,10 @@ public: const css::uno::Sequence& rExceptions = css::uno::Sequence()); // The functions from SvPersist - void EnableSetModified( bool bEnable = true ); - bool IsEnableSetModified() const; - virtual void SetModified( bool bModified = true ); - bool IsModified() const; + void EnableSetModified(bool bEnable = true); + bool IsEnableSetModified() const; + void SetModified(bool bModified = true) override; + bool IsModified() const override; /** * @param bChart true if the file is a chart doc and FillClass should not be called @@ -657,8 +649,6 @@ public: virtual void SetProtectionPassword( const OUString &rPassword ); virtual bool GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ); - static bool IsOwnStorageFormat(const SfxMedium &); - /** Append Infobar once the frame is ready. Useful when you want to register an Infobar before the doc/frame is fully loaded. */ void AppendInfoBarWhenReady(const OUString& sId, const OUString& sPrimaryMessage, @@ -670,7 +660,7 @@ public: SAL_DLLPRIVATE static bool IsPackageStorageFormat_Impl(const SfxMedium &); - SAL_DLLPRIVATE bool ConnectTmpStorage_Impl( const css::uno::Reference< css::embed::XStorage >& xStorage, SfxMedium* pMedium ); + SAL_DLLPRIVATE bool ConnectTmpStorage_Impl(const css::uno::Reference< css::embed::XStorage >& xStorage, SfxMedium* pMedium); SAL_DLLPRIVATE bool DisconnectStorage_Impl( SfxMedium& rSrcMedium, SfxMedium& rTargetMedium ); SAL_DLLPRIVATE bool PutURLContentsToVersionStream_Impl( @@ -685,8 +675,6 @@ public: SAL_DLLPRIVATE void BreakMacroSign_Impl( bool bBreakMacroSing ); SAL_DLLPRIVATE void CheckSecurityOnLoading_Impl(); SAL_DLLPRIVATE void CheckForBrokenDocSignatures_Impl(); - SAL_DLLPRIVATE static SignatureState ImplCheckSignaturesInformation( - const css::uno::Sequence< css::security::DocumentSignatureInformation >& aInfos ); SAL_DLLPRIVATE void CheckEncryption_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler ); SAL_DLLPRIVATE void SetModifyPasswordEntered( bool bEntered = true ); SAL_DLLPRIVATE bool IsModifyPasswordEntered() const; diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index bcd9aa26528c..e98579906148 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -200,6 +200,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/doc/Metadatable \ sfx2/source/doc/QuerySaveDocument \ sfx2/source/doc/SfxDocumentMetaData \ + sfx2/source/doc/SignaturesHandler \ sfx2/source/doc/autoredactdialog \ sfx2/source/doc/docfac \ sfx2/source/doc/docfile \ diff --git a/sfx2/source/doc/SignaturesHandler.cxx b/sfx2/source/doc/SignaturesHandler.cxx new file mode 100644 index 000000000000..62cace364d24 --- /dev/null +++ b/sfx2/source/doc/SignaturesHandler.cxx @@ -0,0 +1,557 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace sfx2 +{ +SignaturesHandler::SignaturesHandler() + : m_nDocumentSignatureState(SignatureState::UNKNOWN) + , m_nScriptingSignatureState(SignatureState::UNKNOWN) +{ +} + +SignaturesHandler::~SignaturesHandler() {} + +bool SignaturesHandler::ExecFile_Impl(sal_uInt16 nId, weld::Window* pDialogParent) +{ + switch (nId) + { + case SID_SIGNATURE: + SignDocumentContent(pDialogParent); + return true; + case SID_MACRO_SIGNATURE: + SignScriptingContent(pDialogParent); + return true; + default: + return false; + } +} + +bool SignaturesHandler::GetState_Impl(sal_uInt16 nId, SfxItemSet& rSet, SfxViewFrame* pFrame, + const Link* pLink) +{ + switch (nId) + { + case SID_SIGNATURE: + { + if (pFrame) + { + assert(pLink); + SignatureState eState = documentSignatureState(); + InfobarType aInfobarType(InfobarType::INFO); + OUString sMessage(""); + + switch (eState) + { + case SignatureState::BROKEN: + sMessage = SfxResId(STR_SIGNATURE_BROKEN); + aInfobarType = InfobarType::DANGER; + break; + case SignatureState::INVALID: + sMessage = SfxResId(STR_SIGNATURE_INVALID); + // Warning only, I've tried Danger and it looked too scary + aInfobarType = InfobarType::WARNING; + break; + case SignatureState::NOTVALIDATED: + sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED); + aInfobarType = InfobarType::WARNING; + break; + case SignatureState::PARTIAL_OK: + sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK); + aInfobarType = InfobarType::WARNING; + break; + case SignatureState::OK: + sMessage = SfxResId(STR_SIGNATURE_OK); + aInfobarType = InfobarType::INFO; + break; + case SignatureState::NOTVALIDATED_PARTIAL_OK: + sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED_PARTIAL_OK); + aInfobarType = InfobarType::WARNING; + break; + //FIXME SignatureState::Unknown, own message? + default: + break; + } + + // new info bar + if (!pFrame->HasInfoBarWithID("signature")) + { + if (!sMessage.isEmpty()) + { + auto pInfoBar + = pFrame->AppendInfoBar("signature", "", sMessage, aInfobarType); + if (pInfoBar == nullptr || pInfoBar->IsDisposed()) + return true; + VclPtrInstance xBtn(&(pFrame->GetWindow())); + xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW)); + xBtn->SetSizePixel(xBtn->GetOptimalSize()); + xBtn->SetClickHdl(*pLink); + pInfoBar->addButton(xBtn); + } + } + else // info bar exists already + { + if (eState == SignatureState::NOSIGNATURES) + pFrame->RemoveInfoBar("signature"); + else + pFrame->UpdateInfoBar("signature", "", sMessage, aInfobarType); + } + } + + rSet.Put( + SfxUInt16Item(SID_SIGNATURE, static_cast(documentSignatureState()))); + return true; + } + case SID_MACRO_SIGNATURE: + { + // the slot makes sense only if there is a macro in the document + if (documentHasMacros()) + rSet.Put(SfxUInt16Item(SID_MACRO_SIGNATURE, + static_cast(scriptingSignatureState()))); + else + rSet.DisableItem(nId); + return true; + } + default: + return false; + } +} + +bool SignaturesHandler::IsOwnStorageFormat(const SfxMedium& rMedium) +{ + return !rMedium.GetFilter() || // Embedded + (rMedium.GetFilter()->IsOwnFormat() && rMedium.GetFilter()->UsesStorage() + && rMedium.GetFilter()->GetVersion() >= SOFFICE_FILEFORMAT_60); +} + +SignatureState SignaturesHandler::ImplCheckSignaturesInformation( + const uno::Sequence& aInfos) +{ + bool bCertValid = true; + SignatureState nResult = SignatureState::NOSIGNATURES; + bool bCompleteSignature = true; + if (aInfos.hasElements()) + { + nResult = SignatureState::OK; + for (const auto& rInfo : aInfos) + { + if (bCertValid) + { + sal_Int32 nCertStat = rInfo.CertificateStatus; + bCertValid = nCertStat == security::CertificateValidity::VALID; + } + + if (!rInfo.SignatureIsValid) + { + nResult = SignatureState::BROKEN; + break; // we know enough + } + bCompleteSignature &= !rInfo.PartialDocumentSignature; + } + } + + if (nResult == SignatureState::OK && !bCertValid && !bCompleteSignature) + nResult = SignatureState::NOTVALIDATED_PARTIAL_OK; + else if (nResult == SignatureState::OK && !bCertValid) + nResult = SignatureState::NOTVALIDATED; + else if (nResult == SignatureState::OK && bCertValid && !bCompleteSignature) + nResult = SignatureState::PARTIAL_OK; + + // this code must not check whether the document is modified + // it should only check the provided info + + return nResult; +} + +bool SignaturesHandler::HasSignatureStream(const uno::Reference& xStorage) +{ + if (!xStorage.is()) + return false; + + if (xStorage->hasByName("META-INF")) + { + // ODF case. + try + { + uno::Reference xMetaInf + = xStorage->openStorageElement("META-INF", embed::ElementModes::READ); + if (xMetaInf.is()) + { + return xMetaInf->hasByName("documentsignatures.xml") + || xMetaInf->hasByName("macrosignatures.xml") + || xMetaInf->hasByName("packagesignatures.xml"); + } + } + catch (const css::io::IOException& rException) + { + SAL_WARN("sfx.doc", + "HasSignatureStream: failed to open META-INF: " << rException.Message); + } + } + + // OOXML case. + return xStorage->hasByName("_xmlsignatures"); +} + +uno::Sequence +SignaturesHandler::GetDocumentSignatureInformation( + bool bScriptingContent, const uno::Reference& xSigner) +{ + uno::Sequence aResult; + uno::Reference xLocSigner = xSigner; + + bool bSupportsSigning + = GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->GetSupportsSigning(); + if (GetMedium() && !GetMedium()->GetName().isEmpty() + && ((IsOwnStorageFormat(*GetMedium()) && GetMedium()->GetStorage().is()) + || bSupportsSigning)) + { + try + { + if (!xLocSigner.is()) + { + OUString aVersion; + try + { + uno::Reference xPropSet(GetStorage(), + uno::UNO_QUERY_THROW); + xPropSet->getPropertyValue("Version") >>= aVersion; + } + catch (uno::Exception&) + { + } + + xLocSigner.set(security::DocumentDigitalSignatures::createWithVersion( + comphelper::getProcessComponentContext(), aVersion)); + } + + if (bScriptingContent) + aResult = xLocSigner->verifyScriptingContentSignatures( + GetMedium()->GetZipStorageToSign_Impl(), uno::Reference()); + else + { + if (GetMedium()->GetStorage(false).is()) + { + // Something ZIP-based. + // Only call into xmlsecurity if we see a signature stream, + // as libxmlsec init is expensive. + if (HasSignatureStream(GetMedium()->GetZipStorageToSign_Impl())) + aResult = xLocSigner->verifyDocumentContentSignatures( + GetMedium()->GetZipStorageToSign_Impl(), + uno::Reference()); + } + else + { + // Not ZIP-based, e.g. PDF. + std::unique_ptr pStream(utl::UcbStreamHelper::CreateStream( + GetMedium()->GetName(), StreamMode::READ)); + uno::Reference xStream(new utl::OStreamWrapper(*pStream)); + uno::Reference xInputStream(xStream, uno::UNO_QUERY); + aResult = xLocSigner->verifyDocumentContentSignatures( + uno::Reference(), xInputStream); + } + } + } + catch (css::uno::Exception&) + { + } + } + + return aResult; +} + +SignatureState SignaturesHandler::ImplGetSignatureState(bool bScriptingContent) +{ + SignatureState* pState + = bScriptingContent ? &m_nScriptingSignatureState : &m_nDocumentSignatureState; + + if (*pState == SignatureState::UNKNOWN) + { + *pState = SignatureState::NOSIGNATURES; + + uno::Sequence aInfos + = GetDocumentSignatureInformation(bScriptingContent); + *pState = ImplCheckSignaturesInformation(aInfos); + } + + if (*pState == SignatureState::OK || *pState == SignatureState::NOTVALIDATED + || *pState == SignatureState::PARTIAL_OK) + { + if (IsModified()) + *pState = SignatureState::INVALID; + } + + return *pState; +} + +bool SignaturesHandler::PrepareForSigning(weld::Window* pDialogParent) +{ + // check whether the document is signed + const SignatureState nDocumentSignatureState = documentSignatureState(); + const SignatureState nScriptingSignatureState = scriptingSignatureState(); + const bool bHasSign = (nScriptingSignatureState != SignatureState::NOSIGNATURES + || nDocumentSignatureState != SignatureState::NOSIGNATURES); + + // the target ODF version on saving (only valid when signing ODF of course) + SvtSaveOptions aSaveOpt; + SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion(); + + // the document is not new and is not modified + OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); + + if (IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() + || (GetMedium()->GetFilter()->IsOwnFormat() && aODFVersion != ODFVER_012_TEXT && !bHasSign)) + { + // the document might need saving ( new, modified or in ODF1.1 format without signature ) + if (nVersion >= SvtSaveOptions::ODFVER_012) + { + std::unique_ptr xQuestion; + if (pDialogParent) + { + OUString sQuestion(bHasSign ? SfxResId(STR_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN) + : SfxResId(RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN)); + xQuestion.reset(Application::CreateMessageDialog( + pDialogParent, VclMessageType::Question, VclButtonsType::YesNo, sQuestion)); + } + + if (!pDialogParent || (xQuestion->run() == RET_YES)) + { + // ToDo: Review. We needed to call SetModified, otherwise the document would not be saved. + SetModified(); + ImplDoSave(); + + auto aFilter = GetMedium() ? GetMedium()->GetFilter() : nullptr; + // Check if it is stored a format which supports signing + if (aFilter && !GetMedium()->GetName().isEmpty() + && ((!aFilter->IsOwnFormat() && !aFilter->GetSupportsSigning()) + || (aFilter->IsOwnFormat() && !GetMedium()->HasStorage_Impl()))) + { + if (pDialogParent) + { + std::unique_ptr xBox(Application::CreateMessageDialog( + pDialogParent, VclMessageType::Info, VclButtonsType::Ok, + SfxResId(STR_INFO_WRONGDOCFORMAT))); + xBox->run(); + } + return false; + } + } + else + { + // When the document is modified then we must not show the + // digital signatures dialog + // If we have come here then the user denied to save. + if (!bHasSign) + return false; + } + } + else + { + if (pDialogParent) + { + std::unique_ptr xBox(Application::CreateMessageDialog( + pDialogParent, VclMessageType::Warning, VclButtonsType::Ok, + SfxResId(STR_XMLSEC_ODF12_EXPECTED))); + xBox->run(); + } + return false; + } + + if (IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty()) + return false; + } + + return true; +} + +void SignaturesHandler::RecheckSignature(bool bAlsoRecheckScriptingSignature) +{ + if (bAlsoRecheckScriptingSignature) + m_nScriptingSignatureState = SignatureState::UNKNOWN; // Re-Check + m_nDocumentSignatureState = SignatureState::UNKNOWN; // Re-Check + Invalidate(SID_SIGNATURE); + Invalidate(SID_MACRO_SIGNATURE); +} + +void SignaturesHandler::AfterSigning(bool bSignSuccess, bool bSignScriptingContent) +{ + ImplDoSaveCompleted(); + + if (bSignSuccess) + RecheckSignature(bSignScriptingContent); +} + +bool SignaturesHandler::CheckIsReadonly(bool bSignScriptingContent) +{ + if (GetMedium()->IsOriginallyReadOnly()) + { + // If the file is physically read-only, we just show the existing signatures + try + { + OUString aODFVersion( + comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); + uno::Reference xSigner( + security::DocumentDigitalSignatures::createWithVersionAndValidSignature( + comphelper::getProcessComponentContext(), aODFVersion, HasValidSignatures())); + if (bSignScriptingContent) + xSigner->showScriptingContentSignatures(GetMedium()->GetZipStorageToSign_Impl(), + uno::Reference()); + else + { + uno::Reference xStorage = GetMedium()->GetZipStorageToSign_Impl(); + if (xStorage.is()) + xSigner->showDocumentContentSignatures(xStorage, + uno::Reference()); + else + { + std::unique_ptr pStream(utl::UcbStreamHelper::CreateStream( + GetMedium()->GetName(), StreamMode::READ)); + uno::Reference xStream(new utl::OStreamWrapper(*pStream)); + xSigner->showDocumentContentSignatures(uno::Reference(), + xStream); + } + } + } + catch (const uno::Exception&) + { + SAL_WARN("sfx.doc", "Couldn't use signing functionality!"); + } + return true; + } + return false; +} + +bool SignaturesHandler::HasValidSignatures() const +{ + return m_nDocumentSignatureState == SignatureState::OK + || m_nDocumentSignatureState == SignatureState::NOTVALIDATED + || m_nDocumentSignatureState == SignatureState::PARTIAL_OK; +} + +void SignaturesHandler::SignDocumentContent(weld::Window* pDialogParent) +{ + if (!PrepareForSigning(pDialogParent)) + return; + + if (CheckIsReadonly(false)) + return; + + bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures()); + + AfterSigning(bSignSuccess, false); +} + +bool SignaturesHandler::SignDocumentContentUsingCertificate( + const uno::Reference& xCertificate) +{ + if (!PrepareForSigning(nullptr)) + return false; + + if (GetMedium()->IsOriginallyReadOnly()) + return false; + + bool bSignSuccess + = GetMedium()->SignDocumentContentUsingCertificate(HasValidSignatures(), xCertificate); + + AfterSigning(bSignSuccess, false); + + return true; +} + +void SignaturesHandler::SignSignatureLine(weld::Window* pDialogParent, + const OUString& aSignatureLineId, + const uno::Reference& xCert, + const uno::Reference& xValidGraphic, + const uno::Reference& xInvalidGraphic, + const OUString& aComment) +{ + if (!PrepareForSigning(pDialogParent)) + return; + + if (CheckIsReadonly(false)) + return; + + bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures(), + aSignatureLineId, xCert, xValidGraphic, + xInvalidGraphic, aComment); + + AfterSigning(bSignSuccess, false); +} + +void SignaturesHandler::SignScriptingContent(weld::Window* pDialogParent) +{ + if (!PrepareForSigning(pDialogParent)) + return; + + if (CheckIsReadonly(true)) + return; + + bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures()); + + AfterSigning(bSignSuccess, true); +} + +#if 0 +SignatureState SignaturesHandler::getScriptingSignatureState() +{ + SignatureState nSignatureState( rDocShell.scriptingSignatureState() ); + + if ( nSignatureState != SignatureState::NOSIGNATURES && m_bMacroSignBroken ) + { + // if there is a macro signature it must be handled as broken + nSignatureState = SignatureState::BROKEN; + } + + return nSignatureState; +} +#endif +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 0f155cc7e4f9..a013f3e8fc08 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -75,6 +75,7 @@ #include #include #include +#include #include #include @@ -983,7 +984,7 @@ void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteract void SfxObjectShell::CheckForBrokenDocSignatures_Impl() { - SignatureState nSignatureState = GetDocumentSignatureState(); + SignatureState nSignatureState = documentSignatureState(); bool bSignatureBroken = ( nSignatureState == SignatureState::BROKEN ); if ( !bSignatureBroken ) return; @@ -1769,7 +1770,7 @@ Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() SignatureState SfxObjectShell_Impl::getScriptingSignatureState() { - SignatureState nSignatureState( rDocShell.GetScriptingSignatureState() ); + SignatureState nSignatureState(rDocShell.scriptingSignatureState()); if ( nSignatureState != SignatureState::NOSIGNATURES && m_bMacroSignBroken ) { @@ -1798,6 +1799,7 @@ bool SfxObjectShell_Impl::hasTrustedScriptingSignature( bool bAllowUIToAddAuthor uno::Reference< security::XDocumentDigitalSignatures > xSigner( security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), aVersion) ); + SignatureState nScriptingSignatureState(rDocShell.scriptingSignatureState()); if ( nScriptingSignatureState == SignatureState::UNKNOWN || nScriptingSignatureState == SignatureState::OK || nScriptingSignatureState == SignatureState::NOTVALIDATED ) diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index a4e4381ab179..21ab86d2ea0b 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -410,7 +410,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) if( SID_SIGNATURE == nId || SID_MACRO_SIGNATURE == nId ) { if ( QueryHiddenInformation( HiddenWarningFact::WhenSigning, nullptr ) == RET_YES ) - ( SID_SIGNATURE == nId ) ? SignDocumentContent(pDialogParent) : SignScriptingContent(pDialogParent); + SignaturesHandler::ExecFile_Impl(nId, pDialogParent); return; } @@ -820,7 +820,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) OUString::createFromAscii( pSlot->GetUnoName() ), aDispatchArgs, bPreselectPassword, - GetDocumentSignatureState() ); + documentSignatureState() ); // merge aDispatchArgs to the request @@ -1276,79 +1276,13 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) } case SID_SIGNATURE: { - SfxViewFrame *pFrame = SfxViewFrame::GetFirst(this); - if ( pFrame ) - { - SignatureState eState = GetDocumentSignatureState(); - InfobarType aInfobarType(InfobarType::INFO); - OUString sMessage(""); - - switch (eState) - { - case SignatureState::BROKEN: - sMessage = SfxResId(STR_SIGNATURE_BROKEN); - aInfobarType = InfobarType::DANGER; - break; - case SignatureState::INVALID: - sMessage = SfxResId(STR_SIGNATURE_INVALID); - // Warning only, I've tried Danger and it looked too scary - aInfobarType = InfobarType::WARNING; - break; - case SignatureState::NOTVALIDATED: - sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED); - aInfobarType = InfobarType::WARNING; - break; - case SignatureState::PARTIAL_OK: - sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK); - aInfobarType = InfobarType::WARNING; - break; - case SignatureState::OK: - sMessage = SfxResId(STR_SIGNATURE_OK); - aInfobarType = InfobarType::INFO; - break; - case SignatureState::NOTVALIDATED_PARTIAL_OK: - sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED_PARTIAL_OK); - aInfobarType = InfobarType::WARNING; - break; - //FIXME SignatureState::Unknown, own message? - default: - break; - } - - // new info bar - if ( !pFrame->HasInfoBarWithID("signature") ) - { - if ( !sMessage.isEmpty() ) - { - auto pInfoBar = pFrame->AppendInfoBar("signature", "", sMessage, aInfobarType); - if (pInfoBar == nullptr || pInfoBar->IsDisposed()) - return; - VclPtrInstance xBtn(&(pFrame->GetWindow())); - xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW)); - xBtn->SetSizePixel(xBtn->GetOptimalSize()); - xBtn->SetClickHdl(LINK(this, SfxObjectShell, SignDocumentHandler)); - pInfoBar->addButton(xBtn); - } - } - else // info bar exists already - { - if ( eState == SignatureState::NOSIGNATURES ) - pFrame->RemoveInfoBar("signature"); - else - pFrame->UpdateInfoBar("signature", "", sMessage, aInfobarType); - } - } - - rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast(GetDocumentSignatureState()) ) ); + Link aLink(LINK(this, SfxObjectShell, SignDocumentHandler)); + SignaturesHandler::GetState_Impl(nWhich, rSet, SfxViewFrame::GetFirst(this), &aLink); break; } case SID_MACRO_SIGNATURE: { - // the slot makes sense only if there is a macro in the document - if ( pImpl->documentStorageHasMacros() || pImpl->aMacroMode.hasMacroLibrary() ) - rSet.Put( SfxUInt16Item( SID_MACRO_SIGNATURE, static_cast(GetScriptingSignatureState()) ) ); - else - rSet.DisableItem( nWhich ); + SignaturesHandler::GetState_Impl(nWhich, rSet); break; } case SID_DOC_REPAIR: @@ -1501,226 +1435,28 @@ void SfxObjectShell::StateView_Impl(SfxItemSet& /*rSet*/) { } -SignatureState SfxObjectShell::ImplCheckSignaturesInformation( const uno::Sequence< security::DocumentSignatureInformation >& aInfos ) +void SfxObjectShell::ImplDoSave() { - bool bCertValid = true; - SignatureState nResult = SignatureState::NOSIGNATURES; - bool bCompleteSignature = true; - if( aInfos.hasElements() ) - { - nResult = SignatureState::OK; - for ( const auto& rInfo : aInfos ) - { - if ( bCertValid ) - { - sal_Int32 nCertStat = rInfo.CertificateStatus; - bCertValid = nCertStat == security::CertificateValidity::VALID; - } - - if ( !rInfo.SignatureIsValid ) - { - nResult = SignatureState::BROKEN; - break; // we know enough - } - bCompleteSignature &= !rInfo.PartialDocumentSignature; - } - } - - if (nResult == SignatureState::OK && !bCertValid && !bCompleteSignature) - nResult = SignatureState::NOTVALIDATED_PARTIAL_OK; - else if (nResult == SignatureState::OK && !bCertValid) - nResult = SignatureState::NOTVALIDATED; - else if ( nResult == SignatureState::OK && bCertValid && !bCompleteSignature) - nResult = SignatureState::PARTIAL_OK; - - // this code must not check whether the document is modified - // it should only check the provided info - - return nResult; + sal_uInt16 nId = SID_SAVEDOC; + if (!GetMedium() || GetMedium()->GetName().isEmpty()) + nId = SID_SAVEASDOC; + SfxRequest aSaveRequest(nId, SfxCallMode::SLOT, GetPool()); + // ToDo: Review. We needed to call SetModified, otherwise the document would not be saved. + SetModified(); + ExecFile_Impl(aSaveRequest); } -/// Does this ZIP storage have a signature stream? -static bool HasSignatureStream(const uno::Reference& xStorage) +void SfxObjectShell::ImplDoSaveCompleted() { - if (!xStorage.is()) - return false; - - if (xStorage->hasByName("META-INF")) - { - // ODF case. - try - { - uno::Reference xMetaInf - = xStorage->openStorageElement("META-INF", embed::ElementModes::READ); - if (xMetaInf.is()) - { - return xMetaInf->hasByName("documentsignatures.xml") - || xMetaInf->hasByName("macrosignatures.xml") - || xMetaInf->hasByName("packagesignatures.xml"); - } - } - catch (const css::io::IOException& rException) - { - SAL_WARN("sfx.doc", "HasSignatureStream: failed to open META-INF: " << rException.Message); - } - } - - // OOXML case. - return xStorage->hasByName("_xmlsignatures"); -} - -uno::Sequence< security::DocumentSignatureInformation > SfxObjectShell::GetDocumentSignatureInformation( bool bScriptingContent, const uno::Reference< security::XDocumentDigitalSignatures >& xSigner ) -{ - uno::Sequence< security::DocumentSignatureInformation > aResult; - uno::Reference< security::XDocumentDigitalSignatures > xLocSigner = xSigner; - - bool bSupportsSigning = GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->GetSupportsSigning(); - if (GetMedium() && !GetMedium()->GetName().isEmpty() && ((IsOwnStorageFormat(*GetMedium()) && GetMedium()->GetStorage().is()) || bSupportsSigning)) - { - try - { - if ( !xLocSigner.is() ) - { - OUString aVersion; - try - { - uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue("Version") >>= aVersion; - } - catch( uno::Exception& ) - { - } - - xLocSigner.set( security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), aVersion) ); - - } - - if ( bScriptingContent ) - aResult = xLocSigner->verifyScriptingContentSignatures( GetMedium()->GetZipStorageToSign_Impl(), - uno::Reference< io::XInputStream >() ); - else - { - if (GetMedium()->GetStorage(false).is()) - { - // Something ZIP-based. - // Only call into xmlsecurity if we see a signature stream, - // as libxmlsec init is expensive. - if (HasSignatureStream(GetMedium()->GetZipStorageToSign_Impl())) - aResult = xLocSigner->verifyDocumentContentSignatures( GetMedium()->GetZipStorageToSign_Impl(), - uno::Reference< io::XInputStream >() ); - } - else - { - // Not ZIP-based, e.g. PDF. - std::unique_ptr pStream(utl::UcbStreamHelper::CreateStream(GetMedium()->GetName(), StreamMode::READ)); - uno::Reference xStream(new utl::OStreamWrapper(*pStream)); - uno::Reference xInputStream(xStream, uno::UNO_QUERY); - aResult = xLocSigner->verifyDocumentContentSignatures(uno::Reference(), xInputStream); - } - } - } - catch( css::uno::Exception& ) - { - } - } - - return aResult; -} - -SignatureState SfxObjectShell::ImplGetSignatureState( bool bScriptingContent ) -{ - SignatureState* pState = bScriptingContent ? &pImpl->nScriptingSignatureState : &pImpl->nDocumentSignatureState; - - if ( *pState == SignatureState::UNKNOWN ) - { - *pState = SignatureState::NOSIGNATURES; - - uno::Sequence< security::DocumentSignatureInformation > aInfos = GetDocumentSignatureInformation( bScriptingContent ); - *pState = ImplCheckSignaturesInformation( aInfos ); - } - - if ( *pState == SignatureState::OK || *pState == SignatureState::NOTVALIDATED - || *pState == SignatureState::PARTIAL_OK) - { - if ( IsModified() ) - *pState = SignatureState::INVALID; - } - - return *pState; + pImpl->m_bSavingForSigning = true; + DoSaveCompleted(GetMedium()); + pImpl->m_bSavingForSigning = false; } bool SfxObjectShell::PrepareForSigning(weld::Window* pDialogParent) { - // check whether the document is signed - ImplGetSignatureState(); // document signature - if (GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->IsOwnFormat()) - ImplGetSignatureState( true ); // script signature - bool bHasSign = ( pImpl->nScriptingSignatureState != SignatureState::NOSIGNATURES || pImpl->nDocumentSignatureState != SignatureState::NOSIGNATURES ); - - // the target ODF version on saving (only valid when signing ODF of course) - SvtSaveOptions aSaveOpt; - SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion(); - - // the document is not new and is not modified - OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); - - if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() - || (GetMedium()->GetFilter()->IsOwnFormat() && aODFVersion != ODFVER_012_TEXT && !bHasSign) ) - { - // the document might need saving ( new, modified or in ODF1.1 format without signature ) - - if ( nVersion >= SvtSaveOptions::ODFVER_012 ) - { - OUString sQuestion(bHasSign ? SfxResId(STR_XMLSEC_QUERY_SAVESIGNEDBEFORESIGN) : SfxResId(RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN)); - std::unique_ptr xQuestion(Application::CreateMessageDialog(pDialogParent, - VclMessageType::Question, VclButtonsType::YesNo, sQuestion)); - - - if (xQuestion->run() == RET_YES) - { - sal_uInt16 nId = SID_SAVEDOC; - if ( !GetMedium() || GetMedium()->GetName().isEmpty() ) - nId = SID_SAVEASDOC; - SfxRequest aSaveRequest( nId, SfxCallMode::SLOT, GetPool() ); - //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved. - SetModified(); - ExecFile_Impl( aSaveRequest ); - - // Check if it is stored a format which supports signing - if (GetMedium() && GetMedium()->GetFilter() && !GetMedium()->GetName().isEmpty() - && ((!GetMedium()->GetFilter()->IsOwnFormat() - && !GetMedium()->GetFilter()->GetSupportsSigning()) - || (GetMedium()->GetFilter()->IsOwnFormat() - && !GetMedium()->HasStorage_Impl()))) - { - std::unique_ptr xBox(Application::CreateMessageDialog( - pDialogParent, VclMessageType::Info, VclButtonsType::Ok, - SfxResId(STR_INFO_WRONGDOCFORMAT))); - - xBox->run(); - return false; - } - } - else - { - // When the document is modified then we must not show the - // digital signatures dialog - // If we have come here then the user denied to save. - if (!bHasSign) - return false; - } - } - else - { - std::unique_ptr xBox(Application::CreateMessageDialog(pDialogParent, - VclMessageType::Warning, VclButtonsType::Ok, SfxResId(STR_XMLSEC_ODF12_EXPECTED))); - xBox->run(); - return false; - } - - if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() ) - return false; - } + if (!SignaturesHandler::PrepareForSigning(pDialogParent)) + return false; // the document is not modified currently, so it can not become modified after signing pImpl->m_bAllowModifiedBackAfterSigning = false; @@ -1739,172 +1475,17 @@ bool SfxObjectShell::PrepareForSigning(weld::Window* pDialogParent) return false; } -void SfxObjectShell::RecheckSignature(bool bAlsoRecheckScriptingSignature) -{ - if (bAlsoRecheckScriptingSignature) - pImpl->nScriptingSignatureState = SignatureState::UNKNOWN; // Re-Check - - pImpl->nDocumentSignatureState = SignatureState::UNKNOWN; // Re-Check - - Invalidate(SID_SIGNATURE); - Invalidate(SID_MACRO_SIGNATURE); - Broadcast(SfxHint(SfxHintId::TitleChanged)); -} - void SfxObjectShell::AfterSigning(bool bSignSuccess, bool bSignScriptingContent) { - pImpl->m_bSavingForSigning = true; - DoSaveCompleted( GetMedium() ); - pImpl->m_bSavingForSigning = false; + SignaturesHandler::AfterSigning(bSignSuccess, bSignScriptingContent); - if ( bSignSuccess ) - RecheckSignature(bSignScriptingContent); - - if ( pImpl->m_bAllowModifiedBackAfterSigning ) + if (pImpl->m_bAllowModifiedBackAfterSigning) EnableSetModified(); } -bool SfxObjectShell::CheckIsReadonly(bool bSignScriptingContent) +bool SfxObjectShell::documentHasMacros() const { - if (GetMedium()->IsOriginallyReadOnly()) - { - // If the file is physically read-only, we just show the existing signatures - try - { - OUString aODFVersion( - comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); - uno::Reference xSigner( - security::DocumentDigitalSignatures::createWithVersionAndValidSignature( - comphelper::getProcessComponentContext(), aODFVersion, HasValidSignatures())); - if (bSignScriptingContent) - xSigner->showScriptingContentSignatures(GetMedium()->GetZipStorageToSign_Impl(), - uno::Reference()); - else - { - uno::Reference xStorage = GetMedium()->GetZipStorageToSign_Impl(); - if (xStorage.is()) - xSigner->showDocumentContentSignatures(xStorage, - uno::Reference()); - else - { - std::unique_ptr pStream( - utl::UcbStreamHelper::CreateStream(GetName(), StreamMode::READ)); - uno::Reference xStream(new utl::OStreamWrapper(*pStream)); - xSigner->showDocumentContentSignatures(uno::Reference(), - xStream); - } - } - } - catch (const uno::Exception&) - { - SAL_WARN("sfx.doc", "Couldn't use signing functionality!"); - } - return true; - } - return false; -} - -bool SfxObjectShell::HasValidSignatures() const -{ - return pImpl->nDocumentSignatureState == SignatureState::OK - || pImpl->nDocumentSignatureState == SignatureState::NOTVALIDATED - || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK; -} - -SignatureState SfxObjectShell::GetDocumentSignatureState() -{ - return ImplGetSignatureState(); -} - -void SfxObjectShell::SignDocumentContent(weld::Window* pDialogParent) -{ - if (!PrepareForSigning(pDialogParent)) - return; - - if (CheckIsReadonly(false)) - return; - - bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, false, HasValidSignatures()); - - AfterSigning(bSignSuccess, false); -} - -bool SfxObjectShell::SignDocumentContentUsingCertificate(const Reference& xCertificate) -{ - // 1. PrepareForSigning - - // check whether the document is signed - ImplGetSignatureState(false); // document signature - if (GetMedium() && GetMedium()->GetFilter() && GetMedium()->GetFilter()->IsOwnFormat()) - ImplGetSignatureState( true ); // script signature - bool bHasSign = ( pImpl->nScriptingSignatureState != SignatureState::NOSIGNATURES || pImpl->nDocumentSignatureState != SignatureState::NOSIGNATURES ); - - // the target ODF version on saving (only valid when signing ODF of course) - SvtSaveOptions aSaveOpt; - SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion(); - - // the document is not new and is not modified - OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage())); - - if (IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() - || (GetMedium()->GetFilter()->IsOwnFormat() && aODFVersion != ODFVER_012_TEXT && !bHasSign)) - { - if ( nVersion >= SvtSaveOptions::ODFVER_012 ) - { - sal_uInt16 nId = SID_SAVEDOC; - if ( !GetMedium() || GetMedium()->GetName().isEmpty() ) - nId = SID_SAVEASDOC; - SfxRequest aSaveRequest( nId, SfxCallMode::SLOT, GetPool() ); - //ToDo: Review. We needed to call SetModified, otherwise the document would not be saved. - SetModified(); - ExecFile_Impl( aSaveRequest ); - - // Check if it is stored a format which supports signing - if (GetMedium() && GetMedium()->GetFilter() && !GetMedium()->GetName().isEmpty() - && ((!GetMedium()->GetFilter()->IsOwnFormat() - && !GetMedium()->GetFilter()->GetSupportsSigning()) - || (GetMedium()->GetFilter()->IsOwnFormat() - && !GetMedium()->HasStorage_Impl()))) - { - return false; - } - } - else - { - return false; - } - - if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() ) - return false; - } - - // the document is not modified currently, so it can not become modified after signing - pImpl->m_bAllowModifiedBackAfterSigning = false; - if ( IsEnableSetModified() ) - { - EnableSetModified( false ); - pImpl->m_bAllowModifiedBackAfterSigning = true; - } - - // we have to store to the original document, the original medium should be closed for this time - bool bResult = ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium); - - if (!bResult) - return false; - - GetMedium()->CloseAndRelease(); - - // 2. Check Read-Only - if (GetMedium()->IsOriginallyReadOnly()) - return false; - - // 3. Sign - bool bSignSuccess = GetMedium()->SignDocumentContentUsingCertificate(HasValidSignatures(), xCertificate); - - // 4. AfterSigning - AfterSigning(bSignSuccess, false); - - return true; + return pImpl->documentStorageHasMacros() || pImpl->aMacroMode.hasMacroLibrary(); } void SfxObjectShell::SignSignatureLine(weld::Window* pDialogParent, @@ -1914,16 +1495,7 @@ void SfxObjectShell::SignSignatureLine(weld::Window* pDialogParent, const Reference& xInvalidGraphic, const OUString& aComment) { - if (!PrepareForSigning(pDialogParent)) - return; - - if (CheckIsReadonly(false)) - return; - - bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, - false, HasValidSignatures(), aSignatureLineId, xCert, xValidGraphic, xInvalidGraphic, aComment); - - AfterSigning(bSignSuccess, false); + sfx2::SignaturesHandler::SignSignatureLine(pDialogParent, aSignatureLineId, xCert, xValidGraphic, xInvalidGraphic, aComment); // Reload the document to get the updated graphic // FIXME: Update just the signature line graphic instead of reloading the document @@ -1932,24 +1504,6 @@ void SfxObjectShell::SignSignatureLine(weld::Window* pDialogParent, pFrame->GetDispatcher()->Execute(SID_RELOAD); } -SignatureState SfxObjectShell::GetScriptingSignatureState() -{ - return ImplGetSignatureState( true ); -} - -void SfxObjectShell::SignScriptingContent(weld::Window* pDialogParent) -{ - if (!PrepareForSigning(pDialogParent)) - return; - - if (CheckIsReadonly(true)) - return; - - bool bSignSuccess = GetMedium()->SignContents_Impl(pDialogParent, true, HasValidSignatures()); - - AfterSigning(bSignSuccess, true); -} - namespace { class theSfxObjectShellUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSfxObjectShellUnoTunnelId > {}; diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 56b8fdde8e0a..7db3fae0f1ae 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -933,16 +933,6 @@ ErrCode SfxObjectShell::HandleFilter( SfxMedium* pMedium, SfxObjectShell const * return nError; } - -bool SfxObjectShell::IsOwnStorageFormat(const SfxMedium &rMedium) -{ - return !rMedium.GetFilter() || // Embedded - ( rMedium.GetFilter()->IsOwnFormat() && - rMedium.GetFilter()->UsesStorage() && - rMedium.GetFilter()->GetVersion() >= SOFFICE_FILEFORMAT_60 ); -} - - bool SfxObjectShell::IsPackageStorageFormat_Impl(const SfxMedium &rMedium) { return !rMedium.GetFilter() || // Embedded @@ -950,7 +940,6 @@ bool SfxObjectShell::IsPackageStorageFormat_Impl(const SfxMedium &rMedium) rMedium.GetFilter()->GetVersion() >= SOFFICE_FILEFORMAT_60 ); } - bool SfxObjectShell::DoSave() // DoSave is only invoked for OLE. Save your own documents in the SFX through // DoSave_Impl order to allow for the creation of backups. @@ -1129,10 +1118,11 @@ bool SfxObjectShell::SaveTo_Impl bool bTryToPreserveScriptSignature = false; // no way to detect whether a filter is oasis format, have to wait for saving process bool bNoPreserveForOasis = false; + SignatureState nScriptingSignatureState = scriptingSignatureState(); if ( bOwnSource && bOwnTarget - && ( pImpl->nScriptingSignatureState == SignatureState::OK - || pImpl->nScriptingSignatureState == SignatureState::NOTVALIDATED - || pImpl->nScriptingSignatureState == SignatureState::INVALID ) ) + && ( nScriptingSignatureState == SignatureState::OK + || nScriptingSignatureState == SignatureState::NOTVALIDATED + || nScriptingSignatureState == SignatureState::INVALID ) ) { // the checking of the library modified state iterates over the libraries, should be done only when required // currently the check is commented out since it is broken, we have to check the signature every time we save @@ -2014,17 +2004,17 @@ bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed, bool bRegisterRecent ) bool bTemplate = pTemplateItem && pTemplateItem->GetValue(); // before the title regenerated the document must lose the signatures - pImpl->nDocumentSignatureState = SignatureState::NOSIGNATURES; + setDocumentSignatureState(SignatureState::NOSIGNATURES); if (!bTemplate) { - pImpl->nScriptingSignatureState = pNewMed->GetCachedSignatureState_Impl(); - OSL_ENSURE( pImpl->nScriptingSignatureState != SignatureState::BROKEN, "The signature must not be broken at this place" ); + setScriptingSignatureState(pNewMed->GetCachedSignatureState_Impl()); + OSL_ENSURE(scriptingSignatureState() != 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 } else - pNewMed->SetCachedSignatureState_Impl( pImpl->nScriptingSignatureState ); + pNewMed->SetCachedSignatureState_Impl(scriptingSignatureState()); // Set new title if (!pNewMed->GetName().isEmpty() && SfxObjectCreateMode::EMBEDDED != eCreateMode) diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index fd8fc433c3b2..effb1f02184b 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -185,8 +185,6 @@ SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell ) ,pProgress( nullptr) ,nTime( DateTime::SYSTEM ) ,nVisualDocumentNumber( USHRT_MAX) - ,nDocumentSignatureState( SignatureState::UNKNOWN ) - ,nScriptingSignatureState( SignatureState::UNKNOWN ) ,bClosing( false) ,bIsSaving( false) ,bIsNamedVisible( false) diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index ddc5d050da23..6cd1049f80dd 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -3454,7 +3454,7 @@ bool SfxBaseModel::hasValidSignatures() const { SolarMutexGuard aGuard; if ( m_pData->m_pObjectShell.is() ) - return ( m_pData->m_pObjectShell->ImplGetSignatureState() == SignatureState::OK ); + return ( m_pData->m_pObjectShell->documentSignatureState() == SignatureState::OK ); return false; } @@ -3953,7 +3953,7 @@ OUString SAL_CALL SfxBaseModel::getTitle() else if ( m_pData->m_pObjectShell->IsDocShared() ) aResult += SfxResId(STR_SHARED); - if ( m_pData->m_pObjectShell->GetDocumentSignatureState() == SignatureState::OK ) + if ( m_pData->m_pObjectShell->documentSignatureState() == SignatureState::OK ) aResult += SfxResId(RID_XMLSEC_DOCUMENTSIGNED); } diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index 9ffb447bd272..370c218ebc39 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -64,8 +64,6 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess OUString aTempName; DateTime nTime; sal_uInt16 nVisualDocumentNumber; - SignatureState nDocumentSignatureState; - SignatureState nScriptingSignatureState; bool bClosing:1, // sal_True while Close(), to prevent recurrences Notification bIsSaving:1, bIsNamedVisible:1, diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist index 2792a6d284b0..f6325d824023 100644 --- a/solenv/clang-format/blacklist +++ b/solenv/clang-format/blacklist @@ -2943,7 +2943,7 @@ dbaccess/source/core/dataaccess/connection.hxx dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx dbaccess/source/core/dataaccess/databasecontext.cxx dbaccess/source/core/dataaccess/databasedocument.cxx -dbaccess/source/core/dataaccess/databasedocument.hxx +dbaccess/source/inc/databasedocument.hxx dbaccess/source/core/dataaccess/databaseregistrations.cxx dbaccess/source/core/dataaccess/databaseregistrations.hxx dbaccess/source/core/dataaccess/datasource.cxx @@ -2956,7 +2956,7 @@ dbaccess/source/core/dataaccess/documentdefinition.hxx dbaccess/source/core/dataaccess/documenteventexecutor.cxx dbaccess/source/core/dataaccess/documenteventexecutor.hxx dbaccess/source/core/dataaccess/documenteventnotifier.cxx -dbaccess/source/core/dataaccess/documenteventnotifier.hxx +dbaccess/source/inc/documenteventnotifier.hxx dbaccess/source/core/dataaccess/documentevents.cxx dbaccess/source/core/dataaccess/intercept.cxx dbaccess/source/core/dataaccess/intercept.hxx @@ -2965,10 +2965,10 @@ dbaccess/source/core/dataaccess/myucp_datasupplier.hxx dbaccess/source/core/dataaccess/myucp_resultset.cxx dbaccess/source/core/dataaccess/myucp_resultset.hxx dbaccess/source/core/inc/ContainerMediator.hxx -dbaccess/source/core/inc/ContentHelper.hxx +dbaccess/source/inc/ContentHelper.hxx dbaccess/source/core/inc/DatabaseDataProvider.hxx dbaccess/source/core/inc/FilteredContainer.hxx -dbaccess/source/core/inc/ModelImpl.hxx +dbaccess/source/inc/ModelImpl.hxx dbaccess/source/core/inc/PropertyForward.hxx dbaccess/source/core/inc/RefreshListener.hxx dbaccess/source/core/inc/SingleSelectQueryComposer.hxx @@ -2985,7 +2985,7 @@ dbaccess/source/core/inc/databasecontext.hxx dbaccess/source/core/inc/datasettings.hxx dbaccess/source/core/inc/definitioncolumn.hxx dbaccess/source/core/inc/definitioncontainer.hxx -dbaccess/source/core/inc/documentevents.hxx +dbaccess/source/inc/documentevents.hxx dbaccess/source/core/inc/objectnameapproval.hxx dbaccess/source/core/inc/preparedstatement.hxx dbaccess/source/core/inc/querycomposer.hxx diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index 5a3cdb55f608..9f7c094e9776 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -526,7 +526,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGood) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both. - SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + SignatureState nActual = pObjectShell->documentSignatureState(); CPPUNIT_ASSERT_MESSAGE( (OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK)); @@ -541,7 +541,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFBroken) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), - static_cast(pObjectShell->GetDocumentSignatureState())); + static_cast(pObjectShell->documentSignatureState())); } // Document has a signature stream, but no actual signatures. @@ -553,7 +553,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFNo) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::NOSIGNATURES), - static_cast(pObjectShell->GetDocumentSignatureState())); + static_cast(pObjectShell->documentSignatureState())); } /// Test a typical OOXML where a number of (but not all) streams are signed. @@ -567,7 +567,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLPartial) // This was SignatureState::BROKEN due to missing RelationshipTransform and SHA-256 support. // We expect NOTVALIDATED_PARTIAL_OK in case the root CA is not imported on the system, and PARTIAL_OK otherwise, so accept both. // But reject NOTVALIDATED, hiding incompleteness is not OK. - SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + SignatureState nActual = pObjectShell->documentSignatureState(); CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), (nActual == SignatureState::NOTVALIDATED_PARTIAL_OK || nActual == SignatureState::PARTIAL_OK)); @@ -583,7 +583,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLBroken) CPPUNIT_ASSERT(pObjectShell); // This was SignatureState::NOTVALIDATED/PARTIAL_OK as we did not validate manifest references. CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), - static_cast(pObjectShell->GetDocumentSignatureState())); + static_cast(pObjectShell->documentSignatureState())); } #if HAVE_FEATURE_PDFIMPORT @@ -597,7 +597,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFGood) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both. - SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + SignatureState nActual = pObjectShell->documentSignatureState(); CPPUNIT_ASSERT_MESSAGE( (OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK)); @@ -612,7 +612,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFBad) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), - static_cast(pObjectShell->GetDocumentSignatureState())); + static_cast(pObjectShell->documentSignatureState())); } /// Test a typical PDF which is not signed. @@ -624,7 +624,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testPDFNo) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::NOSIGNATURES), - static_cast(pObjectShell->GetDocumentSignatureState())); + static_cast(pObjectShell->documentSignatureState())); } #endif @@ -638,7 +638,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Calc) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pObjectShell); - SignatureState nActual = pObjectShell->GetScriptingSignatureState(); + SignatureState nActual = pObjectShell->scriptingSignatureState(); CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), (nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::INVALID)); @@ -675,7 +675,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, test96097Doc) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); - SignatureState nActual = pObjectShell->GetScriptingSignatureState(); + SignatureState nActual = pObjectShell->scriptingSignatureState(); CPPUNIT_ASSERT_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), (nActual == SignatureState::OK || nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::INVALID)); @@ -835,7 +835,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdESGood) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); // We expect NOTVALIDATED in case the root CA is not imported on the system, and OK otherwise, so accept both. - SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + SignatureState nActual = pObjectShell->documentSignatureState(); CPPUNIT_ASSERT_MESSAGE( (OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), (nActual == SignatureState::NOTVALIDATED || nActual == SignatureState::OK)); @@ -897,7 +897,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFGoodGPG) CPPUNIT_ASSERT(pObjectShell); // Our local gpg config fully trusts the signing cert, so in // contrast to the X509 test we can fail on NOTVALIDATED here - SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + SignatureState nActual = pObjectShell->documentSignatureState(); CPPUNIT_ASSERT_EQUAL_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), SignatureState::OK, nActual); } @@ -913,7 +913,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFUntrustedGoodGPG) // Our local gpg config does _not_ trust the signing cert, so in // contrast to the X509 test we can fail everything but // NOTVALIDATED here - SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + SignatureState nActual = pObjectShell->documentSignatureState(); CPPUNIT_ASSERT_EQUAL_MESSAGE((OString::number(o3tl::underlyingEnumValue(nActual)).getStr()), SignatureState::NOTVALIDATED, nActual); } @@ -927,7 +927,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFBrokenStreamGPG) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), - static_cast(pObjectShell->GetDocumentSignatureState())); + static_cast(pObjectShell->documentSignatureState())); } /// Test a typical broken ODF signature where the XML dsig hash is corrupted. @@ -939,7 +939,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testODFBrokenDsigGPG) SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); CPPUNIT_ASSERT(pObjectShell); CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), - static_cast(pObjectShell->GetDocumentSignatureState())); + static_cast(pObjectShell->documentSignatureState())); } #if HAVE_GPGCONF_SOCKETDIR @@ -979,9 +979,9 @@ SfxObjectShell* SigningTest::assertDocument(const ::CppUnit::SourceLine aSrcLine CPPUNIT_ASSERT_EQUAL_MESSAGE(sPos, rFilterName, pObjectShell->GetMedium()->GetFilter()->GetFilterName()); - SignatureState nActual = pObjectShell->GetDocumentSignatureState(); + SignatureState nActual = pObjectShell->documentSignatureState(); CPPUNIT_ASSERT_EQUAL_MESSAGE(sPos, nDocSign, nActual); - nActual = pObjectShell->GetScriptingSignatureState(); + nActual = pObjectShell->scriptingSignatureState(); CPPUNIT_ASSERT_EQUAL_MESSAGE(sPos, nMacroSign, nActual); OUString aODFVersion; -- 2.20.1