summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
authorSarper Akdemir <sarper.akdemir@allotropia.de>2024-09-10 11:19:08 +0200
committerSarper Akdemir <sarper.akdemir@allotropia.de>2024-09-12 16:42:20 +0200
commit4b399dbfc4c3081174be1703a0c98fec1afd761f (patch)
treeade6f4e19c6df00c2af4d25e6c36920214e52e4a /sfx2/source
parentd4c0bb0ce626fa24eddb886e3bf6444da292df25 (diff)
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.akdemir@allotropia.de> Tested-by: Jenkins
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx30
-rw-r--r--sfx2/source/doc/guisaveas.cxx16
2 files changed, 16 insertions, 30 deletions
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
};