xmlsecurity/inc/certificatechooser.hxx                     |    7 +++-
 xmlsecurity/inc/digitalsignaturesdialog.hxx                |    2 +
 xmlsecurity/source/component/documentdigitalsignatures.cxx |    2 -
 xmlsecurity/source/dialogs/certificatechooser.cxx          |   20 ++++++++++++-
 xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx     |    3 +
 5 files changed, 30 insertions(+), 4 deletions(-)

New commits:
commit e32687c45e2bc272ca7e040909ceac5cf67b2e7c
Author:     Miklos Vajna <[email protected]>
AuthorDate: Fri Sep 27 08:12:04 2024 +0200
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Sep 30 09:37:26 2024 +0200

    cool#9992 lok doc sign: only take sign cert from the view in the cert 
chooser
    
    Have two views, in case both of them haver sign certs configured in the
    NSS database, then the cert chooser would present both, which is not
    wanted.
    
    The problem is that the NSS database contains sign certs from all views,
    so working from the database is not what we want for the LOK case.
    
    Fix the problem by passing the SfxViewShell from the sign dialog to the
    certificate chooser dialog, and then the chooser can work from the view
    in LOK mode.
    
    Searching for other uses of getPersonalCertificates(), the comphelper/
    one is not relevant for the LOK case (gpg is disabled there); the PDF
    case is only for the UNO API, so those don't necessarily need adjusting.
    
    (cherry picked from commit a581dbf9829d8407a611907c35c8af632b1397b5)
    
    Conflicts:
            xmlsecurity/inc/certificatechooser.hxx
            xmlsecurity/source/dialogs/certificatechooser.cxx
            xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
    
    Change-Id: Ic7027b8d218b2bde3c8bf134a4b11c14fd9c3570
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174216
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/xmlsecurity/inc/certificatechooser.hxx 
b/xmlsecurity/inc/certificatechooser.hxx
index b0cf7c7cdcc4..344a9d48f3c2 100644
--- a/xmlsecurity/inc/certificatechooser.hxx
+++ b/xmlsecurity/inc/certificatechooser.hxx
@@ -34,6 +34,8 @@ namespace com::sun::star {
 
 namespace com::sun::star::xml::crypto { class XXMLSecurityContext; }
 
+class SfxViewShell;
+
 struct UserData
 {
     css::uno::Reference<css::security::XCertificate> xCertificate;
@@ -56,6 +58,7 @@ private:
 
     bool                    mbInitialized;
     UserAction const        meAction;
+    SfxViewShell* m_pViewShell;
     OUString                msPreferredKey;
     css::uno::Reference<css::security::XCertificate> mxEncryptToSelf;
 
@@ -85,11 +88,13 @@ private:
 
 public:
     CertificateChooser(weld::Window* pParent,
+                       SfxViewShell* pViewShell,
                        std::vector< css::uno::Reference< 
css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts,
                        UserAction eAction);
     virtual ~CertificateChooser() override;
 
     static std::unique_ptr<CertificateChooser> getInstance(weld::Window* 
_pParent,
+                        SfxViewShell* pViewShell,
                         std::vector< css::uno::Reference< 
css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts,
                         UserAction eAction) {
         // Don't reuse CertificateChooser instances
@@ -100,7 +105,7 @@ public:
         //    in the Digital Signatures dialog
         // 2. File > Save As the document, check the "Encrypt with GPG key"
         //    checkbox, press Encrypt, and crash in Dialog::ImplStartExecute()
-        return std::make_unique<CertificateChooser>(_pParent, 
std::move(rxSecurityContexts), eAction);
+        return std::make_unique<CertificateChooser>(_pParent, pViewShell, 
std::move(rxSecurityContexts), eAction);
     }
 
     short run() override;
diff --git a/xmlsecurity/inc/digitalsignaturesdialog.hxx 
b/xmlsecurity/inc/digitalsignaturesdialog.hxx
index 73c3b80dd1a3..30fb63282be0 100644
--- a/xmlsecurity/inc/digitalsignaturesdialog.hxx
+++ b/xmlsecurity/inc/digitalsignaturesdialog.hxx
@@ -56,6 +56,8 @@ private:
 
     bool m_bAdESCompliant = true;
 
+    SfxViewShell* m_pViewShell;
+
     std::unique_ptr<weld::Label>       m_xHintDocFT;
     std::unique_ptr<weld::Label>       m_xHintBasicFT;
     std::unique_ptr<weld::Label>       m_xHintPackageFT;
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx 
b/xmlsecurity/source/component/documentdigitalsignatures.cxx
index 05feb96e3776..5168ca46855c 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -722,7 +722,7 @@ 
DocumentDigitalSignatures::chooseCertificatesImpl(std::map<OUString, OUString>&
             xSecContexts.push_back(aSignatureManager.getGpgSecurityContext());
     }
 
-    std::unique_ptr<CertificateChooser> aChooser = 
CertificateChooser::getInstance(Application::GetFrameWeld(mxParentWindow), 
std::move(xSecContexts), eAction);
+    std::unique_ptr<CertificateChooser> aChooser = 
CertificateChooser::getInstance(Application::GetFrameWeld(mxParentWindow), 
nullptr, std::move(xSecContexts), eAction);
 
     if (aChooser->run() != RET_OK)
         return { Reference< css::security::XCertificate >(nullptr) };
diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx 
b/xmlsecurity/source/dialogs/certificatechooser.cxx
index 4bdb4bcc3e07..de106c408ac8 100644
--- a/xmlsecurity/source/dialogs/certificatechooser.cxx
+++ b/xmlsecurity/source/dialogs/certificatechooser.cxx
@@ -24,6 +24,8 @@
 #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
 #include <comphelper/sequence.hxx>
 #include <comphelper/xmlsechelper.hxx>
+#include <comphelper/lok.hxx>
+#include <sfx2/viewsh.hxx>
 
 #include <com/sun/star/security/NoPasswordException.hpp>
 #include <com/sun/star/security/CertificateCharacters.hpp>
@@ -40,10 +42,12 @@ using namespace comphelper;
 using namespace css;
 
 CertificateChooser::CertificateChooser(weld::Window* _pParent,
+                                       SfxViewShell* pViewShell,
                                        std::vector< css::uno::Reference< 
css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts,
                                        UserAction eAction)
     : GenericDialogController(_pParent, 
"xmlsec/ui/selectcertificatedialog.ui", "SelectCertificateDialog")
     , meAction(eAction)
+    , m_pViewShell(pViewShell)
     , m_xFTSign(m_xBuilder->weld_label("sign"))
     , m_xFTEncrypt(m_xBuilder->weld_label("encrypt"))
     , m_xCertLB(m_xBuilder->weld_tree_view("signatures"))
@@ -196,7 +200,21 @@ void CertificateChooser::ImplInitialize(bool mbSearch)
             else
             {
                 if (meAction == UserAction::Sign || meAction == 
UserAction::SelectSign)
-                    xCerts = secEnvironment->getPersonalCertificates();
+                {
+                    if (comphelper::LibreOfficeKit::isActive())
+                    {
+                        // The LOK case takes the signing certificate from the 
view.
+                        if (m_pViewShell && 
m_pViewShell->GetSigningCertificate().is())
+                        {
+                            xCerts = { m_pViewShell->GetSigningCertificate() };
+                        }
+                    }
+                    else
+                    {
+                        // Otherwise working from the system cert store is OK.
+                        xCerts = secEnvironment->getPersonalCertificates();
+                    }
+                }
                 else
                     xCerts = secEnvironment->getAllCertificates();
 
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx 
b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 61f5d315b02e..e3f0a42f8881 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -243,6 +243,7 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
     , m_sODFVersion (std::move(sODFVersion))
     , m_bHasDocumentSignature(bHasDocumentSignature)
     , m_bWarningShowSignMacro(false)
+    , m_pViewShell(pViewShell)
     , m_xHintDocFT(m_xBuilder->weld_label("dochint"))
     , m_xHintBasicFT(m_xBuilder->weld_label("macrohint"))
     , m_xHintPackageFT(m_xBuilder->weld_label("packagehint"))
@@ -539,7 +540,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, 
weld::Button&, void)
         if 
(DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.getStore(), 
m_sODFVersion))
             xSecContexts.push_back(maSignatureManager.getGpgSecurityContext());
 
-        std::unique_ptr<CertificateChooser> aChooser = 
CertificateChooser::getInstance(m_xDialog.get(), std::move(xSecContexts), 
UserAction::Sign);
+        std::unique_ptr<CertificateChooser> aChooser = 
CertificateChooser::getInstance(m_xDialog.get(), m_pViewShell, 
std::move(xSecContexts), UserAction::Sign);
         if (aChooser->run() == RET_OK)
         {
             sal_Int32 nSecurityId;

Reply via email to