summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/objmisc.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/source/doc/objmisc.cxx')
-rw-r--r--sfx2/source/doc/objmisc.cxx137
1 files changed, 122 insertions, 15 deletions
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 3b03a9d4ff..847ae205cb 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -87,6 +87,8 @@
#include <comphelper/configurationhelper.hxx>
#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <com/sun/star/task/DocumentMacroConfirmationRequest2.hpp>
+#include <com/sun/star/task/InteractionClassification.hpp>
#include <com/sun/star/frame/XModel.hpp>
using namespace ::com::sun::star;
@@ -120,6 +122,7 @@ using namespace ::com::sun::star::container;
#include <vcl/svapp.hxx>
#include <framework/interaction.hxx>
#include <comphelper/storagehelper.hxx>
+#include <comphelper/documentconstants.hxx>
#include <sfx2/signaturestate.hxx>
#include <sfx2/app.hxx>
@@ -285,8 +288,6 @@ sal_uInt32 SfxObjectShell::GetErrorCode() const
sal_uInt32 lError=pImp->lErr;
if(!lError && GetMedium())
lError=GetMedium()->GetErrorCode();
-//REMOVE if(!lError && HasStorage())
-//REMOVE lError= GetStorage()->GetErrorCode();
return lError;
}
@@ -301,9 +302,6 @@ void SfxObjectShell::ResetError()
SfxMedium * pMed = GetMedium();
if( pMed )
pMed->ResetError();
-//REMOVE SvStorage *pStor= HasStorage() ? GetStorage() : 0;
-//REMOVE if( pStor )
-//REMOVE pStor->ResetError();
}
//-------------------------------------------------------------------------
@@ -1234,10 +1232,52 @@ void SfxObjectShell::CheckSecurityOnLoading_Impl()
if ( GetMedium() )
xInteraction = GetMedium()->GetInteractionHandler();
- // check macro security
- pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
// check if there is a broken signature...
CheckForBrokenDocSignatures_Impl( xInteraction );
+
+ CheckEncryption_Impl( xInteraction );
+
+ // check macro security
+ pImp->aMacroMode.checkMacrosOnLoading( xInteraction );
+}
+
+//-------------------------------------------------------------------------
+void SfxObjectShell::CheckEncryption_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
+{
+ ::rtl::OUString aVersion;
+ sal_Bool bIsEncrypted = sal_False;
+ sal_Bool bHasNonEncrypted = sal_False;
+
+ try
+ {
+ uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion;
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasEncryptedEntries" ) ) ) >>= bIsEncrypted;
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasNonEncryptedEntries" ) ) ) >>= bHasNonEncrypted;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ if ( aVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
+ {
+ // this is ODF1.2 or later
+ if ( bIsEncrypted && bHasNonEncrypted )
+ {
+ if ( !pImp->m_bIncomplEncrWarnShown )
+ {
+ // this is an encrypted document with nonencrypted streams inside, show the warning
+ ::com::sun::star::task::ErrorCodeRequest aErrorCode;
+ aErrorCode.ErrCode = ERRCODE_SFX_INCOMPLETE_ENCRYPTION;
+
+ SfxMedium::CallApproveHandler( xHandler, uno::makeAny( aErrorCode ), sal_False );
+ pImp->m_bIncomplEncrWarnShown = sal_True;
+ }
+
+ // broken signatures imply no macro execution at all
+ pImp->aMacroMode.disallowMacroExecution();
+ }
+ }
}
//-------------------------------------------------------------------------
@@ -1476,7 +1516,7 @@ void SfxObjectShell::TemplateDisconnectionAfterLoad()
{
// some further initializations for templates
SetTemplate_Impl( aName, aTemplateName, this );
- pTmpMedium->CreateTempFile();
+ pTmpMedium->CreateTempFile( sal_True );
}
// templates are never readonly
@@ -2086,14 +2126,16 @@ void SfxObjectShell::Invalidate( USHORT nId )
Invalidate_Impl( pFrame->GetBindings(), nId );
}
-bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool _bSuppressUI )
+bool SfxObjectShell::AdjustMacroMode( const String& /*rScriptType*/, bool bSuppressUI )
{
uno::Reference< task::XInteractionHandler > xInteraction;
- if ( pMedium && !_bSuppressUI )
+ if ( pMedium && !bSuppressUI )
xInteraction = pMedium->GetInteractionHandler();
CheckForBrokenDocSignatures_Impl( xInteraction );
+ CheckEncryption_Impl( xInteraction );
+
return pImp->aMacroMode.adjustMacroMode( xInteraction );
}
@@ -2325,16 +2367,15 @@ sal_Bool SfxObjectShell_Impl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
return sLocation;
}
-uno::Reference< embed::XStorage > SfxObjectShell_Impl::getLastCommitDocumentStorage()
+uno::Reference< embed::XStorage > SfxObjectShell_Impl::getZipStorageToSign()
{
Reference < embed::XStorage > xStore;
SfxMedium* pMedium( rDocShell.GetMedium() );
OSL_PRECOND( pMedium, "SfxObjectShell_Impl::getLastCommitDocumentStorage: no medium!" );
if ( pMedium )
- {
- xStore = pMedium->GetLastCommitReadStorage_Impl();
- }
+ xStore = pMedium->GetZipStorageToSign_Impl();
+
return xStore;
}
@@ -2348,7 +2389,7 @@ Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts()
return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY );
}
-sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState() const
+sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState()
{
sal_Int16 nSignatureState( rDocShell.GetScriptingSignatureState() );
@@ -2361,6 +2402,72 @@ sal_Int16 SfxObjectShell_Impl::getScriptingSignatureState() const
return nSignatureState;
}
+sal_Bool SfxObjectShell_Impl::hasTrustedScriptingSignature( sal_Bool bAllowUIToAddAuthor )
+{
+ sal_Bool bResult = sal_False;
+
+ try
+ {
+ ::rtl::OUString aVersion;
+ try
+ {
+ uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
+ xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= aVersion;
+ }
+ catch( uno::Exception& )
+ {
+ }
+ uno::Sequence< uno::Any > aArgs( 1 );
+ aArgs[0] <<= aVersion;
+
+ uno::Reference< security::XDocumentDigitalSignatures > xSigner( comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), aArgs ), uno::UNO_QUERY_THROW );
+
+ if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN
+ || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
+ || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
+ {
+ uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.ImplAnalyzeSignature( sal_True, xSigner );
+
+ if ( aInfo.getLength() )
+ {
+ if ( nScriptingSignatureState == SIGNATURESTATE_UNKNOWN )
+ nScriptingSignatureState = rDocShell.ImplCheckSignaturesInformation( aInfo );
+
+ if ( nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_OK
+ || nScriptingSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
+ {
+ for ( sal_Int32 nInd = 0; !bResult && nInd < aInfo.getLength(); nInd++ )
+ {
+ bResult = xSigner->isAuthorTrusted( aInfo[nInd].Signer );
+ }
+
+ if ( !bResult && bAllowUIToAddAuthor )
+ {
+ uno::Reference< task::XInteractionHandler > xInteraction;
+ if ( rDocShell.GetMedium() )
+ xInteraction = rDocShell.GetMedium()->GetInteractionHandler();
+
+ if ( xInteraction.is() )
+ {
+ task::DocumentMacroConfirmationRequest2 aRequest;
+ aRequest.DocumentURL = getDocumentLocation();
+ aRequest.DocumentZipStorage = rDocShell.GetMedium()->GetZipStorageToSign_Impl();
+ aRequest.DocumentSignatureInformation = aInfo;
+ aRequest.DocumentVersion = aVersion;
+ aRequest.Classification = task::InteractionClassification_QUERY;
+ bResult = SfxMedium::CallApproveHandler( xInteraction, uno::makeAny( aRequest ), sal_True );
+ }
+ }
+ }
+ }
+ }
+ }
+ catch( uno::Exception& )
+ {}
+
+ return bResult;
+}
+
void SfxObjectShell_Impl::showBrokenSignatureWarning( const uno::Reference< task::XInteractionHandler >& _rxInteraction ) const
{
if ( !bSignatureErrorIsShown )