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

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