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

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