summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2018-05-17 11:10:34 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-11-08 13:58:57 +0100
commita266cfa742f6b03ea38da7dda6229b6d3db0e391 (patch)
treea6694a1344af04988f9322257364dea52b6513fa
parentf6c5c8b14bd47aa31a37801ca27294e156d92dbb (diff)
Refactor SfxObjectShell sign methods
for signature line signing Reviewed-on: https://gerrit.libreoffice.org/54473 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> (cherry picked from commit 0ca1659353cc9847f436280873e1047d2524395e) Conflicts: cui/source/dialogs/SignSignatureLineDialog.cxx sfx2/source/doc/objserv.cxx Change-Id: Iac4f3a248af53bdbf159e6e8d656e1dcbc3aacbf
-rw-r--r--comphelper/source/misc/storagehelper.cxx13
-rw-r--r--include/comphelper/storagehelper.hxx3
-rw-r--r--include/sfx2/objsh.hxx14
-rw-r--r--sfx2/source/doc/objserv.cxx116
-rw-r--r--sfx2/source/inc/objshimp.hxx1
5 files changed, 86 insertions, 61 deletions
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index 4551326b9b46..5905c7867aca 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -698,6 +698,19 @@ uno::Reference< io::XStream > OStorageHelper::GetStreamAtPackageURL(
return nullptr;
}
+OUString OStorageHelper::GetODFVersionFromStorage(uno::Reference<embed::XStorage> xStorage)
+{
+ OUString aODFVersion;
+ try
+ {
+ uno::Reference<beans::XPropertySet> xPropSet(xStorage, uno::UNO_QUERY_THROW);
+ xPropSet->getPropertyValue("Version") >>= aODFVersion;
+ }
+ catch (uno::Exception&)
+ {
+ }
+ return aODFVersion;
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/storagehelper.hxx b/include/comphelper/storagehelper.hxx
index 778fb1c8ea25..e8fcc0d11cb7 100644
--- a/include/comphelper/storagehelper.hxx
+++ b/include/comphelper/storagehelper.hxx
@@ -193,6 +193,9 @@ public:
const css::uno::Reference< css::embed::XStorage > &xStorage,
const OUString& rURL, sal_uInt32 const nOpenMode,
LifecycleProxy const & rNastiness );
+
+ static OUString
+ GetODFVersionFromStorage(css::uno::Reference<css::embed::XStorage> xStorage);
};
}
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 5208e1a58184..72ff66e22660 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -205,6 +205,7 @@ private:
// sal_False := new object
bool bIsInGenerateThumbnail; //optimize thumbnail generate and store procedure to improve odt saving performance, i120030
bool mbAvoidRecentDocs; ///< Avoid adding to the recent documents list, if not necessary.
+ bool m_bAllowModifiedBackAfterSigning;
enum TriState {undefined, yes, no};
TriState mbContinueImportOnFilterExceptions = undefined; // try to import as much as possible
@@ -356,11 +357,14 @@ public:
css::uno::Reference<css::text::XTextRange> const& xInsertPosition);
bool ExportTo( SfxMedium &rMedium );
- // xmlsec05, check with SFX team
+ /** Returns to if preparing was succesful, else false. */
+ bool PrepareForSigning();
+ void AfterSigning(bool bSignSuccess, bool bSignScriptingContent);
+ bool HasValidSignatures();
SignatureState GetDocumentSignatureState();
void SignDocumentContent();
- void SignDocumentContent(css::uno::Reference<css::security::XCertificate> xCert,
- const OUString& aSignatureLineId);
+ void SignSignatureLine(const OUString& aSignatureLineId,
+ const css::uno::Reference<css::security::XCertificate> xCert);
SignatureState GetScriptingSignatureState();
void SignScriptingContent();
DECL_LINK(SignDocumentHandler, Button*, void);
@@ -743,10 +747,6 @@ public:
const css::uno::Reference< css::security::XDocumentDigitalSignatures >& xSigner
= css::uno::Reference< css::security::XDocumentDigitalSignatures >() );
- SAL_DLLPRIVATE void ImplSign(const css::uno::Reference<css::security::XCertificate> xCert
- = css::uno::Reference<css::security::XCertificate>(),
- const OUString& aSignatureLineId = OUString(), bool bScriptingContent = false);
-
SAL_DLLPRIVATE bool QuerySaveSizeExceededModules_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler );
SAL_DLLPRIVATE bool QueryAllowExoticFormat_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
const OUString& rURL,
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index e4c6b18986f0..37f6758f0018 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -62,6 +62,7 @@
#include <unotools/saveopt.hxx>
#include <svtools/asynclink.hxx>
#include <comphelper/documentconstants.hxx>
+#include <comphelper/storagehelper.hxx>
#include <tools/link.hxx>
#include <sfx2/asyncfunc.hxx>
@@ -1360,8 +1361,7 @@ SignatureState SfxObjectShell::ImplGetSignatureState( bool bScriptingContent )
return *pState;
}
-void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, const OUString& aSignatureLineId,
- bool bScriptingContent)
+bool SfxObjectShell::PrepareForSigning()
{
// Check if it is stored in OASIS format...
if ( GetMedium()
@@ -1374,7 +1374,7 @@ void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, const OUString& aSi
{
// Only OASIS and OOo6.x formats will be handled further
ScopedVclPtrInstance<MessageDialog>( nullptr, SfxResId( STR_INFO_WRONGDOCFORMAT ), VclMessageType::Info )->Execute();
- return;
+ return false;
}
// check whether the document is signed
@@ -1396,19 +1396,7 @@ void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, const OUString& aSi
SvtSaveOptions::ODFDefaultVersion nVersion = aSaveOpt.GetODFDefaultVersion();
// the document is not new and is not modified
- OUString aODFVersion;
- try
- {
- // check the ODF version of the document
- // No idea what relevance this has if the document has not been loaded from ODF (or is not
- // being saved to ODF)
- uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
- xPropSet->getPropertyValue("Version") >>= aODFVersion;
- }
- catch( uno::Exception& )
- {}
-
- bool bNoSig = false;
+ OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage()));
if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty()
|| (aODFVersion != ODFVER_012_TEXT && !bHasSign) )
@@ -1436,7 +1424,7 @@ void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, const OUString& aSi
{
// Only OASIS format will be handled further
ScopedVclPtrInstance<MessageDialog>( nullptr, SfxResId( STR_INFO_WRONGDOCFORMAT ), VclMessageType::Info )->Execute();
- return;
+ return false;
}
}
else
@@ -1445,66 +1433,65 @@ void SfxObjectShell::ImplSign(Reference<XCertificate> xCert, const OUString& aSi
// digital signatures dialog
// If we have come here then the user denied to save.
if (!bHasSign)
- bNoSig = true;
+ return false;
}
}
else
{
ScopedVclPtrInstance<MessageDialog>(nullptr, SfxResId(STR_XMLSEC_ODF12_EXPECTED))->Execute();
- return;
+ return false;
}
if ( IsModified() || !GetMedium() || GetMedium()->GetName().isEmpty() )
- return;
+ return false;
}
// the document is not modified currently, so it can not become modified after signing
- bool bAllowModifiedBack = false;
+ pImpl->m_bAllowModifiedBackAfterSigning = false;
if ( IsEnableSetModified() )
{
EnableSetModified( false );
- bAllowModifiedBack = true;
+ pImpl->m_bAllowModifiedBackAfterSigning = true;
}
// we have to store to the original document, the original medium should be closed for this time
- if ( !bNoSig
- && ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
+ if ( ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
{
GetMedium()->CloseAndRelease();
+ return true;
+ }
+ return false;
+}
- bool bHasValidSignatures = pImpl->nDocumentSignatureState == SignatureState::OK
- || pImpl->nDocumentSignatureState == SignatureState::NOTVALIDATED
- || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK;
-
- bool bSignSuccess = GetMedium()->SignContents_Impl(
- xCert, aSignatureLineId, bScriptingContent, aODFVersion, bHasValidSignatures);
+void SfxObjectShell::AfterSigning(bool bSignSuccess, bool bSignScriptingContent)
+{
+ pImpl->m_bSavingForSigning = true;
+ DoSaveCompleted( GetMedium() );
+ pImpl->m_bSavingForSigning = false;
- pImpl->m_bSavingForSigning = true;
- DoSaveCompleted( GetMedium() );
- pImpl->m_bSavingForSigning = false;
+ if ( bSignSuccess )
+ {
+ if ( bSignScriptingContent )
+ pImpl->nScriptingSignatureState = SignatureState::UNKNOWN; // Re-Check
- if ( bSignSuccess )
- {
- if ( bScriptingContent )
- {
- pImpl->nScriptingSignatureState = SignatureState::UNKNOWN;// Re-Check
+ pImpl->nDocumentSignatureState = SignatureState::UNKNOWN; // Re-Check
- // adding of scripting signature removes existing document signature
- pImpl->nDocumentSignatureState = SignatureState::UNKNOWN;// Re-Check
- }
- else
- pImpl->nDocumentSignatureState = SignatureState::UNKNOWN;// Re-Check
-
- Invalidate( SID_SIGNATURE );
- Invalidate( SID_MACRO_SIGNATURE );
- Broadcast( SfxHint(SfxHintId::TitleChanged) );
- }
+ Invalidate( SID_SIGNATURE );
+ Invalidate( SID_MACRO_SIGNATURE );
+ Broadcast( SfxHint(SfxHintId::TitleChanged) );
}
- if ( bAllowModifiedBack )
+ if ( pImpl->m_bAllowModifiedBackAfterSigning )
EnableSetModified();
}
+bool SfxObjectShell::HasValidSignatures()
+{
+ return pImpl->nDocumentSignatureState == SignatureState::OK
+ || pImpl->nDocumentSignatureState == SignatureState::NOTVALIDATED
+ || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK;
+}
+
SignatureState SfxObjectShell::GetDocumentSignatureState()
{
return ImplGetSignatureState();
@@ -1512,13 +1499,27 @@ SignatureState SfxObjectShell::GetDocumentSignatureState()
void SfxObjectShell::SignDocumentContent()
{
- ImplSign();
+ if (!PrepareForSigning())
+ return;
+
+ OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage()));
+ bool bSignSuccess = GetMedium()->SignContents_Impl(
+ Reference<XCertificate>(), "", false, aODFVersion, HasValidSignatures());
+
+ AfterSigning(bSignSuccess, false);
}
-void SfxObjectShell::SignDocumentContent(const Reference<XCertificate> xCert,
- const OUString& aSignatureLineId)
+void SfxObjectShell::SignSignatureLine(const OUString& aSignatureLineId,
+ const Reference<XCertificate> xCert)
{
- ImplSign(xCert, aSignatureLineId);
+ if (!PrepareForSigning())
+ return;
+
+ OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage()));
+ bool bSignSuccess = GetMedium()->SignContents_Impl(
+ xCert, aSignatureLineId, false, aODFVersion, HasValidSignatures());
+
+ AfterSigning(bSignSuccess, false);
}
SignatureState SfxObjectShell::GetScriptingSignatureState()
@@ -1528,7 +1529,14 @@ SignatureState SfxObjectShell::GetScriptingSignatureState()
void SfxObjectShell::SignScriptingContent()
{
- ImplSign( Reference<XCertificate>(), OUString(), true );
+ if (!PrepareForSigning())
+ return;
+
+ OUString aODFVersion(comphelper::OStorageHelper::GetODFVersionFromStorage(GetStorage()));
+ bool bSignSuccess = GetMedium()->SignContents_Impl(
+ Reference<XCertificate>(), OUString(), true, aODFVersion, HasValidSignatures());
+
+ AfterSigning(bSignSuccess, true);
}
namespace
diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx
index b47a49260d46..67628d5dbdb0 100644
--- a/sfx2/source/inc/objshimp.hxx
+++ b/sfx2/source/inc/objshimp.hxx
@@ -129,6 +129,7 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess
bool m_bModifyPasswordEntered;
/// If true, then this is not a real save, just the signatures change.
bool m_bSavingForSigning;
+ bool m_bAllowModifiedBackAfterSigning;
SfxObjectShell_Impl( SfxObjectShell& _rDocShell );
virtual ~SfxObjectShell_Impl();