diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx index 25305d5b412d..e29fe6137886 100644 --- a/vcl/jsdialog/enabled.cxx +++ b/vcl/jsdialog/enabled.cxx @@ -283,6 +283,7 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool bMobile) || rUIFile == u"xmlsec/ui/certgeneral.ui" || rUIFile == u"xmlsec/ui/certpage.ui" || rUIFile == u"xmlsec/ui/digitalsignaturesdialog.ui" + || rUIFile == u"xmlsec/ui/selectcertificatedialog.ui" || rUIFile == u"xmlsec/ui/viewcertdialog.ui" ) { diff --git a/xmlsecurity/inc/certificatechooser.hxx b/xmlsecurity/inc/certificatechooser.hxx index dbed2ce5c225..8af33458e7c9 100644 --- a/xmlsecurity/inc/certificatechooser.hxx +++ b/xmlsecurity/inc/certificatechooser.hxx @@ -93,7 +93,7 @@ public: CertificateChooserUserAction eAction); virtual ~CertificateChooser() override; - static std::unique_ptr getInstance(weld::Window* _pParent, + static std::shared_ptr getInstance(weld::Window* _pParent, SfxViewShell* pViewShell, std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts, CertificateChooserUserAction eAction) { @@ -105,9 +105,10 @@ 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(_pParent, pViewShell, std::move(rxSecurityContexts), eAction); + return std::make_shared(_pParent, pViewShell, std::move(rxSecurityContexts), eAction); } + void BeforeRun(); short run() override; css::uno::Sequence > GetSelectedCertificates(); diff --git a/xmlsecurity/inc/digitalsignaturesdialog.hxx b/xmlsecurity/inc/digitalsignaturesdialog.hxx index ad0db53720f8..82a27a1c3fe7 100644 --- a/xmlsecurity/inc/digitalsignaturesdialog.hxx +++ b/xmlsecurity/inc/digitalsignaturesdialog.hxx @@ -76,6 +76,7 @@ private: DECL_LINK(ViewButtonHdl, weld::Button&, void); DECL_LINK(AddButtonHdl, weld::Button&, void); + void AddButtonHdlImpl(); DECL_LINK(RemoveButtonHdl, weld::Button&, void); DECL_LINK(SignatureHighlightHdl, weld::TreeView&, void); DECL_LINK(SignatureSelectHdl, weld::TreeView&, bool); diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 3e6ed32bf493..a44b496aa52d 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -651,7 +651,7 @@ DocumentDigitalSignatures::chooseCertificatesImpl(std::map& xSecContexts.push_back(aSignatureManager.getGpgSecurityContext()); } - std::unique_ptr aChooser = CertificateChooser::getInstance(Application::GetFrameWeld(mxParentWindow), nullptr, std::move(xSecContexts), eAction); + std::shared_ptr 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 74ee62475fc0..d19a3ca62a93 100644 --- a/xmlsecurity/source/dialogs/certificatechooser.cxx +++ b/xmlsecurity/source/dialogs/certificatechooser.cxx @@ -83,13 +83,21 @@ CertificateChooser::CertificateChooser(weld::Window* _pParent, // disable buttons CertificateHighlightHdl(*m_xCertLB); + + if (comphelper::LibreOfficeKit::isActive()) + { + // Single certificate doesn't change during the lifetime of a LOK view: no need to search or + // reload it. + m_xSearchBox->hide(); + m_xReloadBtn->hide(); + } } CertificateChooser::~CertificateChooser() { } -short CertificateChooser::run() +void CertificateChooser::BeforeRun() { // #i48432# // We can't check for personal certificates before raising this dialog, @@ -106,6 +114,11 @@ short CertificateChooser::run() m_xDialog->show(); ImplInitialize(); +} + +short CertificateChooser::run() +{ + BeforeRun(); return GenericDialogController::run(); } @@ -435,8 +448,8 @@ void CertificateChooser::ImplShowCertificateDetails() if (!userData->xSecurityEnvironment.is() || !userData->xCertificate.is()) return; - CertificateViewer aViewer(m_xDialog.get(), userData->xSecurityEnvironment, userData->xCertificate, true, this); - aViewer.run(); + auto xViewer = std::make_shared(m_xDialog.get(), userData->xSecurityEnvironment, userData->xCertificate, true, this); + weld::DialogController::runAsync(xViewer, [] (int) {}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index ba6c5343ead7..2442ab51a7c1 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -482,27 +482,40 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void) { if( ! canAdd()) return; - try - { - std::vector> xSecContexts - { - maSignatureManager.getSecurityContext() - }; - // Gpg signing is only possible with ODF >= 1.2 documents - if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.getStore(), m_sODFVersion)) - xSecContexts.push_back(maSignatureManager.getGpgSecurityContext()); - std::unique_ptr aChooser = CertificateChooser::getInstance(m_xDialog.get(), m_pViewShell, std::move(xSecContexts), CertificateChooserUserAction::Sign); - while (aChooser->run() == RET_OK) + // Separate function, so the function can call itself when the certificate choosing was + // successful, but the actual signing was not. + AddButtonHdlImpl(); +} + +void DigitalSignaturesDialog::AddButtonHdlImpl() +{ + std::vector> xSecContexts + { + maSignatureManager.getSecurityContext() + }; + // Gpg signing is only possible with ODF >= 1.2 documents + if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.getStore(), m_sODFVersion)) + xSecContexts.push_back(maSignatureManager.getGpgSecurityContext()); + + std::shared_ptr aChooser = CertificateChooser::getInstance(m_xDialog.get(), m_pViewShell, std::move(xSecContexts), CertificateChooserUserAction::Sign); + aChooser->BeforeRun(); + weld::DialogController::runAsync(aChooser, [this, aChooser](sal_Int32 nRet) { + if (nRet != RET_OK) + { + return; + } + + try { sal_Int32 nSecurityId; if (moScriptSignatureManager) { if (!moScriptSignatureManager->add(aChooser->GetSelectedCertificates()[0], - aChooser->GetSelectedSecurityContext(), - aChooser->GetDescription(), nSecurityId, - m_bAdESCompliant)) + aChooser->GetSelectedSecurityContext(), + aChooser->GetDescription(), nSecurityId, + m_bAdESCompliant)) { return; } @@ -514,7 +527,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void) } if (!maSignatureManager.add(aChooser->GetSelectedCertificates()[0], aChooser->GetSelectedSecurityContext(), - aChooser->GetDescription(), nSecurityId, m_bAdESCompliant)) + aChooser->GetDescription(), nSecurityId, m_bAdESCompliant)) return; mbSignaturesChanged = true; @@ -535,21 +548,24 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void) mbVerifySignatures = true; ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); ImplFillSignaturesBox(); - break; + } + else + { + AddButtonHdlImpl(); } } - } - catch ( uno::Exception& ) - { - TOOLS_WARN_EXCEPTION( "xmlsecurity.dialogs", "adding a signature!" ); - std::unique_ptr xBox(Application::CreateMessageDialog(m_xDialog.get(), - VclMessageType::Error, VclButtonsType::Ok, - XsResId(STR_XMLSECDLG_SIGNING_FAILED))); - xBox->run(); - // Don't keep invalid entries... - ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); - ImplFillSignaturesBox(); - } + catch ( uno::Exception& ) + { + TOOLS_WARN_EXCEPTION( "xmlsecurity.dialogs", "adding a signature!" ); + std::unique_ptr xBox(Application::CreateMessageDialog(m_xDialog.get(), + VclMessageType::Error, VclButtonsType::Ok, + XsResId(STR_XMLSECDLG_SIGNING_FAILED))); + xBox->run(); + // Don't keep invalid entries... + ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); + ImplFillSignaturesBox(); + } + }); } IMPL_LINK_NOARG(DigitalSignaturesDialog, RemoveButtonHdl, weld::Button&, void)