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

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