include/sfx2/strings.hrc | 1 + sfx2/source/dialog/filedlghelper.cxx | 30 ++---------------------------- sfx2/source/doc/guisaveas.cxx | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 30 deletions(-)
New commits: commit 4b399dbfc4c3081174be1703a0c98fec1afd761f Author: Sarper Akdemir <sarper.akde...@allotropia.de> AuthorDate: Tue Sep 10 11:19:08 2024 +0200 Commit: Sarper Akdemir <sarper.akde...@allotropia.de> CommitDate: Thu Sep 12 16:42:20 2024 +0200 tdf#162405: check if there's a matching singing cert only when saving previously Save as dialog's "Sign with default certificate" checkbox's senstivity was decided depending on if there was a matching key. Doing that forces a dialog pop-up for password protected NSS databases. Now if there's a value in "/org.openoffice.UserProfile/Data/signingkey", the checkbox is sensitive. Matching key is checked during save, and reported if it isn't found & signing failed. Change-Id: Ia714b70ce6456752200088cc5382ab6374af9587 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173129 Reviewed-by: Sarper Akdemir <sarper.akde...@allotropia.de> Tested-by: Jenkins diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc index d8e1de9ae66c..d44b05bd2049 100644 --- a/include/sfx2/strings.hrc +++ b/include/sfx2/strings.hrc @@ -143,6 +143,7 @@ #define RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN NC_("RID_SVXSTR_XMLSEC_QUERY_SAVEBEFORESIGN", "The document has to be saved before it can be signed. Do you want to save the document?") #define STR_QUERY_CANCELCHECKOUT NC_("STR_QUERY_CANCELCHECKOUT", "This will discard all changes on the server since check-out. Do you want to proceed?") #define STR_QUERY_REMEMBERSIGNATURE NC_("STR_QUERY_REMEMBERSIGNATURE", "Do you want to remember that signature for each save?") +#define STR_ERROR_NOMATCHINGDEFUALTCERT NC_("STR_ERROR_NOMATCHINGDEFUALTCERT", "Couldn't find a matching signing key. The document won't be signed. Please update the signing key in Options.") #define STR_INFO_WRONGDOCFORMAT NC_("STR_INFO_WRONGDOCFORMAT", "This document must be saved in OpenDocument file format before it can be digitally signed.") #define RID_XMLSEC_DOCUMENTSIGNED NC_("RID_XMLSEC_DOCUMENTSIGNED", " (Signed)") #define STR_EMBEDDED_TITLE NC_("STR_EMBEDDED_TITLE", " (Embedded document)") diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index b2376a2b7e5d..e80075e86010 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -524,34 +524,8 @@ void FileDialogHelper_Impl::updateSignByDefault() if (!mbHasSignByDefault) return; - auto HaveMatchingUserSigningKey = []() -> bool - { - auto aSigningKey = SvtUserOptions{}.GetSigningKey(); - if (aSigningKey.isEmpty()) - return false; - - std::vector<uno::Reference<xml::crypto::XXMLSecurityContext>> xSecurityContexts{ - xml::crypto::SEInitializer::create(comphelper::getProcessComponentContext()) - ->createSecurityContext({}), - xml::crypto::GPGSEInitializer::create(comphelper::getProcessComponentContext()) - ->createSecurityContext({}), - }; - - for (const auto& xSecurityContext : xSecurityContexts) - { - if (xSecurityContext.is()) - { - css::uno::Reference<css::security::XCertificate> xCert - = comphelper::xmlsec::FindCertInContext(xSecurityContext, aSigningKey); - if (xCert.is()) - return true; - } - } - return false; - }; - - updateExtendedControl(ExtendedFilePickerElementIds::CHECKBOX_GPGSIGN, - HaveMatchingUserSigningKey()); + OUString aSigningKey = SvtUserOptions{}.GetSigningKey(); + updateExtendedControl(ExtendedFilePickerElementIds::CHECKBOX_GPGSIGN, !aSigningKey.isEmpty()); #endif } diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index a1a127a18ff6..add52df2bc44 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -1904,12 +1904,13 @@ bool SfxStoringHelper::FinishGUIStoreModel(::comphelper::SequenceAsHashMap::cons return; std::vector<uno::Reference<xml::crypto::XXMLSecurityContext>> xSecurityContexts{ - xml::crypto::SEInitializer::create(comphelper::getProcessComponentContext()) - ->createSecurityContext({}), xml::crypto::GPGSEInitializer::create(comphelper::getProcessComponentContext()) ->createSecurityContext({}), + xml::crypto::SEInitializer::create(comphelper::getProcessComponentContext()) + ->createSecurityContext({}), }; + bool bFoundCert = false; for (const auto& xSecurityContext : xSecurityContexts) { if (xSecurityContext.is()) @@ -1919,6 +1920,7 @@ bool SfxStoringHelper::FinishGUIStoreModel(::comphelper::SequenceAsHashMap::cons if (xCert.is() && SfxViewShell::Current()) { + bFoundCert = true; SfxObjectShell* pDocShell = SfxViewShell::Current()->GetObjectShell(); bool bSigned = pDocShell->SignDocumentContentUsingCertificate(xCert); if (bSigned && pDocShell->HasValidSignatures()) @@ -1934,6 +1936,16 @@ bool SfxStoringHelper::FinishGUIStoreModel(::comphelper::SequenceAsHashMap::cons } } } + if (!bFoundCert) + { + // couldn't find the specified default signing certificate! + // alert the user the document won't be singed + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( + SfxStoringHelper::GetModelWindow(aModelData.GetModel()), + VclMessageType::Error, VclButtonsType::Ok, + SfxResId(STR_ERROR_NOMATCHINGDEFUALTCERT))); + xBox->run(); + } return; #endif };