include/sfx2/filedlghelper.hxx       |    4 +++-
 include/sfx2/strings.hrc             |    1 +
 sfx2/inc/guisaveas.hxx               |    3 ++-
 sfx2/source/dialog/filedlghelper.cxx |   28 ++++++++++++++++++++++++----
 sfx2/source/dialog/filedlgimpl.hxx   |    3 ++-
 sfx2/source/doc/guisaveas.cxx        |   13 ++++++++-----
 sfx2/source/doc/objserv.cxx          |    3 ++-
 sfx2/source/view/ipclient.cxx        |    3 ++-
 8 files changed, 44 insertions(+), 14 deletions(-)

New commits:
commit 558c6a83c210a4d9d7a699616c6f254fb23d7cf4
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Tue Apr 29 20:01:40 2025 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Apr 29 20:01:40 2025 +0200

    sfx2: warn user before saving doc with scripting signature encrypted
    
    The pre-ODF 1.5 encryption necessarily destroys macro signatures, but
    the user would learn this only when re-loading the encrypted document.
    
    Change-Id: Ic8a0190205412f484f47a4b8d864b280eea0d23c

diff --git a/include/sfx2/filedlghelper.hxx b/include/sfx2/filedlghelper.hxx
index 42d6b53c0cfb..2f8b6cb32c07 100644
--- a/include/sfx2/filedlghelper.hxx
+++ b/include/sfx2/filedlghelper.hxx
@@ -56,6 +56,7 @@ namespace com::sun::star::awt { class XWindow; }
 namespace com::sun::star::uno { template <typename > class Reference; }
 namespace weld { class Window; }
 
+enum class SignatureState;
 class Graphic;
 class SfxFilter;
 class SfxItemSet;
@@ -236,7 +237,8 @@ public:
                                      OUString&         rFilter,
                                      const OUString&   rDirPath );
    ErrCode                  Execute( std::unique_ptr<SfxItemSet>& rpSet,
-                                     OUString&         rFilter );
+                                     OUString&         rFilter,
+                                     SignatureState nScriptingSignatureState);
 };
 
 #define SFX2_IMPL_DIALOG_CONFIG 0
diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index 29950ba68ca1..189f1a406154 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -148,6 +148,7 @@
 #define STR_SECURITY_WARNING_NO_HYPERLINKS      
NC_("STR_SECURITY_WARNING_NO_HYPERLINKS", "For security reasons, the hyperlink 
cannot be executed.
The stated address will not be opened.")
 #define RID_SECURITY_WARNING_TITLE                  
NC_("RID_SECURITY_WARNING_TITLE", "Security Warning")
 #define RID_SVXSTR_XMLSEC_QUERY_LOSINGSIGNATURE 
NC_("RID_SVXSTR_XMLSEC_QUERY_LOSINGSIGNATURE", "Saving will remove all existing 
signatures.
Do you want to continue saving the document?")
+#define RID_SVXSTR_XMLSEC_QUERY_LOSINGSCRIPTINGSIGNATURE 
NC_("RID_SVXSTR_XMLSEC_QUERY_LOSINGSCRIPTINGSIGNATURE", "Saving with password 
will remove all existing scripting signatures, and (depending on macro security 
settings) macros in the document may no longer be runnable.
Do you want to continue saving the document with password?")
 #define RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN  
NC_("RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN", "The document has to be saved 
before it can be signed.
Do you want to save the document?")
 #define STR_QUERY_CANCELCHECKOUT                
NC_("STR_QUERY_CANCELCHECKOUT", "This will discard all changes on the server 
since check-out.
Do you want to proceed?")
 #define STR_INFO_WRONGDOCFORMAT                 NC_("STR_INFO_WRONGDOCFORMAT", 
"This document must be saved in OpenDocument file format before it can be 
digitally signed.")
diff --git a/sfx2/inc/guisaveas.hxx b/sfx2/inc/guisaveas.hxx
index 5e7355709680..f09ed4e00321 100644
--- a/sfx2/inc/guisaveas.hxx
+++ b/sfx2/inc/guisaveas.hxx
@@ -61,7 +61,8 @@ public:
                     const OUString& aSlotName,
                     css::uno::Sequence< css::beans::PropertyValue >& 
aArgsSequence,
                     bool bPreselectPassword,
-                    SignatureState nDocumentSignatureState );
+                    SignatureState nDocumentSignatureState,
+                    SignatureState nScriptingSignatureState);
 
     static bool CheckFilterOptionsAppearance(
                     const css::uno::Reference< css::container::XNameAccess >& 
xFilterCFG,
diff --git a/sfx2/source/dialog/filedlghelper.cxx 
b/sfx2/source/dialog/filedlghelper.cxx
index 9063c33a09d1..94973e8f69f9 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1383,7 +1383,8 @@ void FileDialogHelper_Impl::implGetAndCacheFiles(const 
uno::Reference< XInterfac
 
 ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList,
                                         std::unique_ptr<SfxItemSet>& rpSet,
-                                        OUString&       rFilter )
+                                        OUString&       rFilter,
+                                        SignatureState const 
nScriptingSignatureState)
 {
     // rFilter is a pure output parameter, it shouldn't be used for anything 
else
     // changing this would surely break code
@@ -1510,6 +1511,24 @@ ErrCode FileDialogHelper_Impl::execute( 
std::vector<OUString>& rpURLList,
                 Any aValue = xCtrlAccess->getValue( 
ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
                 bool bPassWord = false;
                 if ( ( aValue >>= bPassWord ) && bPassWord )
+                {
+                    if (  SignatureState::OK == nScriptingSignatureState
+                       || SignatureState::INVALID == nScriptingSignatureState
+                       || SignatureState::NOTVALIDATED == 
nScriptingSignatureState
+                       || SignatureState::PARTIAL_OK == 
nScriptingSignatureState)
+                    {
+                        std::unique_ptr<weld::MessageDialog> xBox(
+                            Application::CreateMessageDialog(mpFrameWeld,
+                                VclMessageType::Question, 
VclButtonsType::YesNo,
+                                
SfxResId(RID_SVXSTR_XMLSEC_QUERY_LOSINGSCRIPTINGSIGNATURE)));
+                        if (xBox->run() == RET_NO)
+                        {
+                            bPassWord = false;
+                        }
+                    }
+                }
+
+                if (bPassWord)
                 {
                     // ask for a password
                     OUString aDocName(rpURLList[0]);
@@ -2370,7 +2389,7 @@ ErrCode FileDialogHelper::Execute( std::vector<OUString>& 
rpURLList,
                                    const OUString& rDirPath )
 {
     SetDisplayFolder( rDirPath );
-    return mpImpl->execute( rpURLList, rpSet, rFilter );
+    return mpImpl->execute(rpURLList, rpSet, rFilter, SignatureState::UNKNOWN);
 }
 
 
@@ -2380,11 +2399,12 @@ ErrCode FileDialogHelper::Execute()
 }
 
 ErrCode FileDialogHelper::Execute( std::unique_ptr<SfxItemSet>& rpSet,
-                                   OUString&       rFilter )
+                                   OUString&       rFilter,
+                                   SignatureState const 
nScriptingSignatureState)
 {
     ErrCode nRet;
     std::vector<OUString> rURLList;
-    nRet = mpImpl->execute(rURLList, rpSet, rFilter);
+    nRet = mpImpl->execute(rURLList, rpSet, rFilter, nScriptingSignatureState);
     return nRet;
 }
 
diff --git a/sfx2/source/dialog/filedlgimpl.hxx 
b/sfx2/source/dialog/filedlgimpl.hxx
index cdc8189692fb..597aeb9765a8 100644
--- a/sfx2/source/dialog/filedlgimpl.hxx
+++ b/sfx2/source/dialog/filedlgimpl.hxx
@@ -179,7 +179,8 @@ namespace sfx2
 
         ErrCode                 execute( std::vector<OUString>& rpURLList,
                                          std::unique_ptr<SfxItemSet>& rpSet,
-                                         OUString&       rFilter );
+                                         OUString&       rFilter,
+                                         SignatureState 
nScriptingSignatureState);
         ErrCode                 execute();
 
         void                    setFilter( const OUString& rFilter );
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index 6a9012f63c1f..1284dea7bf23 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -338,7 +338,8 @@ public:
                                 OUString& aSuggestedDir,
                                 sal_Int16 nDialog,
                                 const OUString& rStandardDir,
-                                const css::uno::Sequence< OUString >& 
rBlackList
+                                const css::uno::Sequence< OUString >& 
rBlackList,
+                                SignatureState const nScriptingSignatureState
                                 );
 
     bool ShowDocumentInfoDialog(const std::function< void () >&);
@@ -790,7 +791,8 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 nStoreMode,
                                             OUString& aSuggestedDir,
                                             sal_Int16 nDialog,
                                             const OUString& rStandardDir,
-                                            const css::uno::Sequence< OUString 
>& rBlackList)
+                                            const css::uno::Sequence< OUString 
>& rBlackList,
+                                            SignatureState const 
nScriptingSignatureState)
 {
     if ( nStoreMode == SAVEASREMOTE_REQUESTED )
         nStoreMode = SAVEAS_REQUESTED;
@@ -971,7 +973,7 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 nStoreMode,
 
     // aFilterName is a pure output parameter, pDialogParams is an in/out 
parameter
     OUString aFilterName;
-    if ( pFileDlg->Execute( pDialogParams, aFilterName ) != ERRCODE_NONE )
+    if (pFileDlg->Execute(pDialogParams, aFilterName, 
nScriptingSignatureState) != ERRCODE_NONE)
     {
         throw task::ErrorCodeIOException(
             "ModelData_Impl::OutputFileDialog: ERRCODE_IO_ABORT",
@@ -1300,7 +1302,8 @@ bool SfxStoringHelper::GUIStoreModel( const 
uno::Reference< frame::XModel >& xMo
                                             const OUString& aSlotName,
                                             uno::Sequence< 
beans::PropertyValue >& aArgsSequence,
                                             bool bPreselectPassword,
-                                            SignatureState 
nDocumentSignatureState )
+                                            SignatureState const 
nDocumentSignatureState,
+                                            SignatureState const 
nScriptingSignatureState)
 {
     ModelData_Impl aModelData( *this, xModel, aArgsSequence );
 
@@ -1520,7 +1523,7 @@ bool SfxStoringHelper::GUIStoreModel( const 
uno::Reference< frame::XModel >& xMo
         for (;;)
         {
             // in case the dialog is opened a second time the folder should be 
the same as previously navigated to by the user, not what was handed over by 
initial parameters
-            bUseFilterOptions = aModelData.OutputFileDialog( nStoreMode, 
aFilterProps, bSetStandardName, aSuggestedName, bPreselectPassword, 
aSuggestedDir, nDialog, sStandardDir, aBlackList );
+            bUseFilterOptions = aModelData.OutputFileDialog(nStoreMode, 
aFilterProps, bSetStandardName, aSuggestedName, bPreselectPassword, 
aSuggestedDir, nDialog, sStandardDir, aBlackList, nScriptingSignatureState);
             if ( nStoreMode == SAVEAS_REQUESTED )
             {
                 // in case of saving check filter for possible alien warning
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 9e06c74bcc70..76aac73a4fcc 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -840,7 +840,8 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                                        OUString::createFromAscii( 
pSlot->GetUnoName() ),
                                        aDispatchArgs,
                                        bPreselectPassword,
-                                       GetDocumentSignatureState() );
+                                       GetDocumentSignatureState(),
+                                       GetScriptingSignatureState());
 
 
                 // merge aDispatchArgs to the request
diff --git a/sfx2/source/view/ipclient.cxx b/sfx2/source/view/ipclient.cxx
index be9b43cd9035..8f832b225665 100644
--- a/sfx2/source/view/ipclient.cxx
+++ b/sfx2/source/view/ipclient.cxx
@@ -904,7 +904,8 @@ ErrCode SfxInPlaceClient::DoVerb( long nVerb )
                                             "SaveAs",
                                             aDispatchArgs,
                                             false,
-                                            SignatureState::NOSIGNATURES );
+                                            SignatureState::NOSIGNATURES,
+                                            SignatureState::NOSIGNATURES);
                 }
                 catch( const task::ErrorCodeIOException& aErrorEx )
                 {

Reply via email to