cool#9992 lok doc sign: convert the certificate chooser dialog to async

1) Move the try-catch around assing a signature inside the block that
   already got the response from the certificate chooser, it's unlikely
   that choosing the certificate (and not yet signing) would fail.

2) Convert the dialog to async and allow it to be a jsdialog.

3) Hide not relevant widgets for LOK: we have a single signing
   certificate, so the search entry is not useful.

   The refresh button has an unclear purpose, as it was initially added
   in commit fb9874231f (Caching
   Certificates in the CertificateChooser dialog session-wise, 2023-08-26),
   but later commit efe414c4a8 (Don't reuse
   CertificateChooser instances, 2024-02-07) disabled this chaching. In any
   case, the certificate won't change during the lifetime of a single LOK
   view, so hide that as well.

4) Invoke the inner certificate viewer in an async way, too.

Change-Id: Ibf618ea7632cf801d1d9180b9aa7dd193c45ffda
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174215
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Miklos Vajna
2024-09-30 13:13:32 +02:00
parent e7c4129a5c
commit ced420ca70
6 changed files with 66 additions and 34 deletions

View File

@@ -283,6 +283,7 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool bMobile)
|| rUIFile == u"xmlsec/ui/certgeneral.ui" || rUIFile == u"xmlsec/ui/certgeneral.ui"
|| rUIFile == u"xmlsec/ui/certpage.ui" || rUIFile == u"xmlsec/ui/certpage.ui"
|| rUIFile == u"xmlsec/ui/digitalsignaturesdialog.ui" || rUIFile == u"xmlsec/ui/digitalsignaturesdialog.ui"
|| rUIFile == u"xmlsec/ui/selectcertificatedialog.ui"
|| rUIFile == u"xmlsec/ui/viewcertdialog.ui" || rUIFile == u"xmlsec/ui/viewcertdialog.ui"
) )
{ {

View File

@@ -93,7 +93,7 @@ public:
CertificateChooserUserAction eAction); CertificateChooserUserAction eAction);
virtual ~CertificateChooser() override; virtual ~CertificateChooser() override;
static std::unique_ptr<CertificateChooser> getInstance(weld::Window* _pParent, static std::shared_ptr<CertificateChooser> getInstance(weld::Window* _pParent,
SfxViewShell* pViewShell, SfxViewShell* pViewShell,
std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts, std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > && rxSecurityContexts,
CertificateChooserUserAction eAction) { CertificateChooserUserAction eAction) {
@@ -105,9 +105,10 @@ public:
// in the Digital Signatures dialog // in the Digital Signatures dialog
// 2. File > Save As the document, check the "Encrypt with GPG key" // 2. File > Save As the document, check the "Encrypt with GPG key"
// checkbox, press Encrypt, and crash in Dialog::ImplStartExecute() // checkbox, press Encrypt, and crash in Dialog::ImplStartExecute()
return std::make_unique<CertificateChooser>(_pParent, pViewShell, std::move(rxSecurityContexts), eAction); return std::make_shared<CertificateChooser>(_pParent, pViewShell, std::move(rxSecurityContexts), eAction);
} }
void BeforeRun();
short run() override; short run() override;
css::uno::Sequence<css::uno::Reference< css::security::XCertificate > > GetSelectedCertificates(); css::uno::Sequence<css::uno::Reference< css::security::XCertificate > > GetSelectedCertificates();

View File

@@ -76,6 +76,7 @@ private:
DECL_LINK(ViewButtonHdl, weld::Button&, void); DECL_LINK(ViewButtonHdl, weld::Button&, void);
DECL_LINK(AddButtonHdl, weld::Button&, void); DECL_LINK(AddButtonHdl, weld::Button&, void);
void AddButtonHdlImpl();
DECL_LINK(RemoveButtonHdl, weld::Button&, void); DECL_LINK(RemoveButtonHdl, weld::Button&, void);
DECL_LINK(SignatureHighlightHdl, weld::TreeView&, void); DECL_LINK(SignatureHighlightHdl, weld::TreeView&, void);
DECL_LINK(SignatureSelectHdl, weld::TreeView&, bool); DECL_LINK(SignatureSelectHdl, weld::TreeView&, bool);

View File

@@ -651,7 +651,7 @@ DocumentDigitalSignatures::chooseCertificatesImpl(std::map<OUString, OUString>&
xSecContexts.push_back(aSignatureManager.getGpgSecurityContext()); xSecContexts.push_back(aSignatureManager.getGpgSecurityContext());
} }
std::unique_ptr<CertificateChooser> aChooser = CertificateChooser::getInstance(Application::GetFrameWeld(mxParentWindow), nullptr, std::move(xSecContexts), eAction); std::shared_ptr<CertificateChooser> aChooser = CertificateChooser::getInstance(Application::GetFrameWeld(mxParentWindow), nullptr, std::move(xSecContexts), eAction);
if (aChooser->run() != RET_OK) if (aChooser->run() != RET_OK)
return { Reference< css::security::XCertificate >(nullptr) }; return { Reference< css::security::XCertificate >(nullptr) };

View File

@@ -83,13 +83,21 @@ CertificateChooser::CertificateChooser(weld::Window* _pParent,
// disable buttons // disable buttons
CertificateHighlightHdl(*m_xCertLB); 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() CertificateChooser::~CertificateChooser()
{ {
} }
short CertificateChooser::run() void CertificateChooser::BeforeRun()
{ {
// #i48432# // #i48432#
// We can't check for personal certificates before raising this dialog, // We can't check for personal certificates before raising this dialog,
@@ -106,6 +114,11 @@ short CertificateChooser::run()
m_xDialog->show(); m_xDialog->show();
ImplInitialize(); ImplInitialize();
}
short CertificateChooser::run()
{
BeforeRun();
return GenericDialogController::run(); return GenericDialogController::run();
} }
@@ -435,8 +448,8 @@ void CertificateChooser::ImplShowCertificateDetails()
if (!userData->xSecurityEnvironment.is() || !userData->xCertificate.is()) if (!userData->xSecurityEnvironment.is() || !userData->xCertificate.is())
return; return;
CertificateViewer aViewer(m_xDialog.get(), userData->xSecurityEnvironment, userData->xCertificate, true, this); auto xViewer = std::make_shared<CertificateViewer>(m_xDialog.get(), userData->xSecurityEnvironment, userData->xCertificate, true, this);
aViewer.run(); weld::DialogController::runAsync(xViewer, [] (int) {});
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -482,27 +482,40 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void)
{ {
if( ! canAdd()) if( ! canAdd())
return; return;
try
{
std::vector<uno::Reference<xml::crypto::XXMLSecurityContext>> 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<CertificateChooser> aChooser = CertificateChooser::getInstance(m_xDialog.get(), m_pViewShell, std::move(xSecContexts), CertificateChooserUserAction::Sign); // Separate function, so the function can call itself when the certificate choosing was
while (aChooser->run() == RET_OK) // successful, but the actual signing was not.
AddButtonHdlImpl();
}
void DigitalSignaturesDialog::AddButtonHdlImpl()
{
std::vector<uno::Reference<xml::crypto::XXMLSecurityContext>> 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<CertificateChooser> 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; sal_Int32 nSecurityId;
if (moScriptSignatureManager) if (moScriptSignatureManager)
{ {
if (!moScriptSignatureManager->add(aChooser->GetSelectedCertificates()[0], if (!moScriptSignatureManager->add(aChooser->GetSelectedCertificates()[0],
aChooser->GetSelectedSecurityContext(), aChooser->GetSelectedSecurityContext(),
aChooser->GetDescription(), nSecurityId, aChooser->GetDescription(), nSecurityId,
m_bAdESCompliant)) m_bAdESCompliant))
{ {
return; return;
} }
@@ -514,7 +527,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void)
} }
if (!maSignatureManager.add(aChooser->GetSelectedCertificates()[0], aChooser->GetSelectedSecurityContext(), if (!maSignatureManager.add(aChooser->GetSelectedCertificates()[0], aChooser->GetSelectedSecurityContext(),
aChooser->GetDescription(), nSecurityId, m_bAdESCompliant)) aChooser->GetDescription(), nSecurityId, m_bAdESCompliant))
return; return;
mbSignaturesChanged = true; mbSignaturesChanged = true;
@@ -535,21 +548,24 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, weld::Button&, void)
mbVerifySignatures = true; mbVerifySignatures = true;
ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false);
ImplFillSignaturesBox(); ImplFillSignaturesBox();
break; }
else
{
AddButtonHdlImpl();
} }
} }
} catch ( uno::Exception& )
catch ( uno::Exception& ) {
{ TOOLS_WARN_EXCEPTION( "xmlsecurity.dialogs", "adding a signature!" );
TOOLS_WARN_EXCEPTION( "xmlsecurity.dialogs", "adding a signature!" ); std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Error, VclButtonsType::Ok,
VclMessageType::Error, VclButtonsType::Ok, XsResId(STR_XMLSECDLG_SIGNING_FAILED)));
XsResId(STR_XMLSECDLG_SIGNING_FAILED))); xBox->run();
xBox->run(); // Don't keep invalid entries...
// Don't keep invalid entries... ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false);
ImplGetSignatureInformations(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); ImplFillSignaturesBox();
ImplFillSignaturesBox(); }
} });
} }
IMPL_LINK_NOARG(DigitalSignaturesDialog, RemoveButtonHdl, weld::Button&, void) IMPL_LINK_NOARG(DigitalSignaturesDialog, RemoveButtonHdl, weld::Button&, void)