Blame SOURCES/0004-CVE-2022-2630-6-7-add-infobar-to-prompt-to-refresh-t.patch

0c03dd
From 0aac66b96fcfa7f8c2c265afec59eb4b3f51c131 Mon Sep 17 00:00:00 2001
0c03dd
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
0c03dd
Date: Wed, 23 Mar 2022 13:03:30 +0000
0c03dd
Subject: [PATCH 4/5] CVE-2022-2630[6|7] add infobar to prompt to refresh to
0c03dd
 replace old format
0c03dd
0c03dd
Change-Id: Id99cbf2b50a4ebf289dae6fc67e22e20afcda35b
0c03dd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131976
0c03dd
Tested-by: Jenkins
0c03dd
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
0c03dd
(cherry picked from commit bbd196ff82bda9f66b4ba32a412f10cefe6da60e)
0c03dd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132307
0c03dd
Reviewed-by: Sophie Gautier <sophi@libreoffice.org>
0c03dd
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
0c03dd
(cherry picked from commit c5d01b11db3c83cb4a89d3b388d78e20dd3990b5)
0c03dd
---
0c03dd
 include/sfx2/strings.hrc     |  2 ++
0c03dd
 include/sfx2/viewfrm.hxx     |  1 +
0c03dd
 sfx2/source/view/viewfrm.cxx | 39 +++++++++++++++++++++++++++++++++++-
0c03dd
 3 files changed, 41 insertions(+), 1 deletion(-)
0c03dd
0c03dd
diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
0c03dd
index cb627807d8c8..317dd88061df 100644
0c03dd
--- a/include/sfx2/strings.hrc
0c03dd
+++ b/include/sfx2/strings.hrc
0c03dd
@@ -292,6 +292,8 @@
0c03dd
 #define STR_SIGNATURE_NOTVALIDATED_PARTIAL_OK   NC_("STR_SIGNATURE_NOTVALIDATED_PARTIAL_OK", "The certificate could not be validated and the document is only partially signed.")
0c03dd
 #define STR_SIGNATURE_OK                        NC_("STR_SIGNATURE_OK", "This document is digitally signed and the signature is valid.")
0c03dd
 #define STR_SIGNATURE_SHOW                      NC_("STR_SIGNATURE_SHOW", "Show Signatures")
0c03dd
+#define STR_REFRESH_MASTER_PASSWORD             NC_("STR_REFRESH_MASTER_PASSWORD", "The master password is stored in an outdated format, you should refresh it")
0c03dd
+#define STR_REFRESH_PASSWORD                    NC_("STR_REFRESH_PASSWORD", "Refresh Password")
0c03dd
 
0c03dd
 #define STR_CLOSE_PANE                          NC_("STR_CLOSE_PANE", "Close Pane")
0c03dd
 
0c03dd
diff --git a/include/sfx2/viewfrm.hxx b/include/sfx2/viewfrm.hxx
0c03dd
index aedd362f8781..dc01c088f1f7 100644
0c03dd
--- a/include/sfx2/viewfrm.hxx
0c03dd
+++ b/include/sfx2/viewfrm.hxx
0c03dd
@@ -64,6 +64,7 @@ protected:
0c03dd
     DECL_LINK(WhatsNewHandler, weld::Button&, void);
0c03dd
     DECL_LINK(SwitchReadOnlyHandler, weld::Button&, void);
0c03dd
     DECL_LINK(SignDocumentHandler, weld::Button&, void);
0c03dd
+    DECL_DLLPRIVATE_LINK(RefreshMasterPasswordHdl, weld::Button&, void);
0c03dd
     SAL_DLLPRIVATE void KillDispatcher_Impl();
0c03dd
 
0c03dd
     virtual                 ~SfxViewFrame() override;
0c03dd
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
0c03dd
index 46a7c4d9dc42..0f90af8bfb34 100644
0c03dd
--- a/sfx2/source/view/viewfrm.cxx
0c03dd
+++ b/sfx2/source/view/viewfrm.cxx
0c03dd
@@ -32,7 +32,7 @@
0c03dd
 #include <com/sun/star/frame/XLoadable.hpp>
0c03dd
 #include <com/sun/star/frame/XLayoutManager.hpp>
0c03dd
 #include <com/sun/star/frame/XComponentLoader.hpp>
0c03dd
-#include <com/sun/star/drawing/XShapes.hpp>
0c03dd
+#include <com/sun/star/task/PasswordContainer.hpp>
0c03dd
 #include <officecfg/Office/Common.hxx>
0c03dd
 #include <officecfg/Setup.hxx>
0c03dd
 #include <toolkit/helper/vclunohelper.hxx>
0c03dd
@@ -1413,6 +1413,22 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
0c03dd
                     batch->commit();
0c03dd
                 }
0c03dd
 
0c03dd
+                if (officecfg::Office::Common::Passwords::HasMaster::get() &&
0c03dd
+                    officecfg::Office::Common::Passwords::StorageVersion::get() == 0)
0c03dd
+                {
0c03dd
+                    // master password stored in deprecated format
0c03dd
+                    VclPtr<SfxInfoBarWindow> pOldMasterPasswordInfoBar =
0c03dd
+                        AppendInfoBar("oldmasterpassword", "",
0c03dd
+                                      SfxResId(STR_REFRESH_MASTER_PASSWORD), InfobarType::DANGER, false);
0c03dd
+                    if (pOldMasterPasswordInfoBar)
0c03dd
+                    {
0c03dd
+                        weld::Button& rButton = pOldMasterPasswordInfoBar->addButton();
0c03dd
+                        rButton.set_label(SfxResId(STR_REFRESH_PASSWORD));
0c03dd
+                        rButton.connect_clicked(LINK(this,
0c03dd
+                                                   SfxViewFrame, RefreshMasterPasswordHdl));
0c03dd
+                    }
0c03dd
+                }
0c03dd
+
0c03dd
                 // read-only infobar if necessary
0c03dd
                 const SfxViewShell *pVSh;
0c03dd
                 const SfxShell *pFSh;
0c03dd
@@ -1561,6 +1577,27 @@ IMPL_LINK_NOARG(SfxViewFrame, SignDocumentHandler, weld::Button&, void)
0c03dd
     GetDispatcher()->Execute(SID_SIGNATURE);
0c03dd
 }
0c03dd
 
0c03dd
+IMPL_LINK_NOARG(SfxViewFrame, RefreshMasterPasswordHdl, weld::Button&, void)
0c03dd
+{
0c03dd
+    bool bChanged = false;
0c03dd
+    try
0c03dd
+    {
0c03dd
+        Reference< task::XPasswordContainer2 > xMasterPasswd(
0c03dd
+            task::PasswordContainer::create(comphelper::getProcessComponentContext()));
0c03dd
+
0c03dd
+        css::uno::Reference<css::frame::XFrame> xFrame = GetFrame().GetFrameInterface();
0c03dd
+        css::uno::Reference<css::awt::XWindow> xContainerWindow = xFrame->getContainerWindow();
0c03dd
+
0c03dd
+        uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
0c03dd
+                                                              xContainerWindow));
0c03dd
+        bChanged = xMasterPasswd->changeMasterPassword(xTmpHandler);
0c03dd
+    }
0c03dd
+    catch (const Exception&)
0c03dd
+    {}
0c03dd
+    if (bChanged)
0c03dd
+        RemoveInfoBar(u"oldmasterpassword");
0c03dd
+}
0c03dd
+
0c03dd
 void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
0c03dd
 {
0c03dd
     m_pImpl->bResizeInToOut = true;
0c03dd
-- 
0c03dd
2.37.3
0c03dd