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

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